@@ -505,6 +505,82 @@ namespace {
505
505
}
506
506
}
507
507
}
508
+
509
+ bool ParseAsyncReplicationSettings (
510
+ TReplicationSettings& dstSettings, const TCoNameValueTupleList& srcSettings, TExprContext& ctx, TPositionHandle pos
511
+ ) {
512
+ for (auto setting : srcSettings) {
513
+ auto name = setting.Name ().Value ();
514
+ if (name == " connection_string" ) {
515
+ dstSettings.ConnectionString = setting.Value ().Cast <TCoDataCtor>().Literal ().Cast <TCoAtom>().Value ();
516
+ } else if (name == " endpoint" ) {
517
+ dstSettings.Endpoint = setting.Value ().Cast <TCoDataCtor>().Literal ().Cast <TCoAtom>().Value ();
518
+ } else if (name == " database" ) {
519
+ dstSettings.Database = setting.Value ().Cast <TCoDataCtor>().Literal ().Cast <TCoAtom>().Value ();
520
+ } else if (name == " token" ) {
521
+ dstSettings.EnsureOAuthToken ().Token =
522
+ setting.Value ().Cast <TCoDataCtor>().Literal ().Cast <TCoAtom>().Value ();
523
+ } else if (name == " token_secret_name" ) {
524
+ dstSettings.EnsureOAuthToken ().TokenSecretName =
525
+ setting.Value ().Cast <TCoDataCtor>().Literal ().Cast <TCoAtom>().Value ();
526
+ } else if (name == " user" ) {
527
+ dstSettings.EnsureStaticCredentials ().UserName =
528
+ setting.Value ().Cast <TCoDataCtor>().Literal ().Cast <TCoAtom>().Value ();
529
+ } else if (name == " password" ) {
530
+ dstSettings.EnsureStaticCredentials ().Password =
531
+ setting.Value ().Cast <TCoDataCtor>().Literal ().Cast <TCoAtom>().Value ();
532
+ } else if (name == " password_secret_name" ) {
533
+ dstSettings.EnsureStaticCredentials ().PasswordSecretName =
534
+ setting.Value ().Cast <TCoDataCtor>().Literal ().Cast <TCoAtom>().Value ();
535
+ } else if (name == " state" ) {
536
+ auto value = ToString (setting.Value ().Cast <TCoDataCtor>().Literal ().Cast <TCoAtom>().Value ());
537
+ if (to_lower (value) == " done" ) {
538
+ dstSettings.EnsureStateDone ();
539
+ } else {
540
+ ctx.AddError (TIssue (ctx.GetPosition (setting.Name ().Pos ()),
541
+ TStringBuilder () << " Unknown replication state: " << value));
542
+ return false ;
543
+ }
544
+ } else if (name == " failover_mode" ) {
545
+ auto value = ToString (setting.Value ().Cast <TCoDataCtor>().Literal ().Cast <TCoAtom>().Value ());
546
+ if (to_lower (value) == " consistent" ) {
547
+ dstSettings.EnsureStateDone (TReplicationSettings::EFailoverMode::Consistent);
548
+ } else if (to_lower (value) == " force" ) {
549
+ dstSettings.EnsureStateDone (TReplicationSettings::EFailoverMode::Force);
550
+ } else {
551
+ ctx.AddError (TIssue (ctx.GetPosition (setting.Name ().Pos ()),
552
+ TStringBuilder () << " Unknown failover mode: " << value));
553
+ return false ;
554
+ }
555
+ }
556
+ }
557
+
558
+ if (dstSettings.ConnectionString && (dstSettings.Endpoint || dstSettings.Database )) {
559
+ ctx.AddError (TIssue (ctx.GetPosition (pos),
560
+ TStringBuilder () << " Connection string and Endpoint/Database are mutually exclusive" ));
561
+ return false ;
562
+ }
563
+
564
+ if (dstSettings.OAuthToken && dstSettings.StaticCredentials ) {
565
+ ctx.AddError (TIssue (ctx.GetPosition (pos),
566
+ TStringBuilder () << " Token and User/Password are mutually exclusive" ));
567
+ return false ;
568
+ }
569
+
570
+ if (const auto & x = dstSettings.OAuthToken ; x && x->Token && x->TokenSecretName ) {
571
+ ctx.AddError (TIssue (ctx.GetPosition (pos),
572
+ TStringBuilder () << " TOKEN and TOKEN_SECRET_NAME are mutually exclusive" ));
573
+ return false ;
574
+ }
575
+
576
+ if (const auto & x = dstSettings.StaticCredentials ; x && x->Password && x->PasswordSecretName ) {
577
+ ctx.AddError (TIssue (ctx.GetPosition (pos),
578
+ TStringBuilder () << " PASSWORD and PASSWORD_SECRET_NAME are mutually exclusive" ));
579
+ return false ;
580
+ }
581
+
582
+ return true ;
583
+ }
508
584
}
509
585
510
586
class TKiSinkPlanInfoTransformer : public TGraphTransformerBase {
@@ -1842,35 +1918,7 @@ class TKiSinkCallableExecutionTransformer : public TAsyncCallbackTransformer<TKi
1842
1918
);
1843
1919
}
1844
1920
1845
- for (auto setting : createReplication.ReplicationSettings ()) {
1846
- auto name = setting.Name ().Value ();
1847
- if (name == " connection_string" ) {
1848
- settings.Settings .ConnectionString = setting.Value ().Cast <TCoDataCtor>().Literal ().Cast <TCoAtom>().Value ();
1849
- } else if (name == " endpoint" ) {
1850
- settings.Settings .Endpoint = setting.Value ().Cast <TCoDataCtor>().Literal ().Cast <TCoAtom>().Value ();
1851
- } else if (name == " database" ) {
1852
- settings.Settings .Database = setting.Value ().Cast <TCoDataCtor>().Literal ().Cast <TCoAtom>().Value ();
1853
- } else if (name == " token" ) {
1854
- settings.Settings .EnsureOAuthToken ().Token =
1855
- setting.Value ().Cast <TCoDataCtor>().Literal ().Cast <TCoAtom>().Value ();
1856
- } else if (name == " token_secret_name" ) {
1857
- settings.Settings .EnsureOAuthToken ().TokenSecretName =
1858
- setting.Value ().Cast <TCoDataCtor>().Literal ().Cast <TCoAtom>().Value ();
1859
- } else if (name == " user" ) {
1860
- settings.Settings .EnsureStaticCredentials ().UserName =
1861
- setting.Value ().Cast <TCoDataCtor>().Literal ().Cast <TCoAtom>().Value ();
1862
- } else if (name == " password" ) {
1863
- settings.Settings .EnsureStaticCredentials ().Password =
1864
- setting.Value ().Cast <TCoDataCtor>().Literal ().Cast <TCoAtom>().Value ();
1865
- } else if (name == " password_secret_name" ) {
1866
- settings.Settings .EnsureStaticCredentials ().PasswordSecretName =
1867
- setting.Value ().Cast <TCoDataCtor>().Literal ().Cast <TCoAtom>().Value ();
1868
- }
1869
- }
1870
-
1871
- if (settings.Settings .ConnectionString && (settings.Settings .Endpoint || settings.Settings .Database )) {
1872
- ctx.AddError (TIssue (ctx.GetPosition (createReplication.Pos ()),
1873
- TStringBuilder () << " Connection string and Endpoint/Database are mutually exclusive" ));
1921
+ if (!ParseAsyncReplicationSettings (settings.Settings , createReplication.ReplicationSettings (), ctx, createReplication.Pos ())) {
1874
1922
return SyncError ();
1875
1923
}
1876
1924
@@ -1880,30 +1928,12 @@ class TKiSinkCallableExecutionTransformer : public TAsyncCallbackTransformer<TKi
1880
1928
return SyncError ();
1881
1929
}
1882
1930
1883
- if (settings.Settings .OAuthToken && settings.Settings .StaticCredentials ) {
1884
- ctx.AddError (TIssue (ctx.GetPosition (createReplication.Pos ()),
1885
- TStringBuilder () << " Token and User/Password are mutually exclusive" ));
1886
- return SyncError ();
1887
- }
1888
-
1889
1931
if (!settings.Settings .OAuthToken && !settings.Settings .StaticCredentials ) {
1890
1932
ctx.AddError (TIssue (ctx.GetPosition (createReplication.Pos ()),
1891
1933
TStringBuilder () << " Neither Token nor User/Password are provided" ));
1892
1934
return SyncError ();
1893
1935
}
1894
1936
1895
- if (const auto & x = settings.Settings .OAuthToken ; x && x->Token && x->TokenSecretName ) {
1896
- ctx.AddError (TIssue (ctx.GetPosition (createReplication.Pos ()),
1897
- TStringBuilder () << " TOKEN and TOKEN_SECRET_NAME are mutually exclusive" ));
1898
- return SyncError ();
1899
- }
1900
-
1901
- if (const auto & x = settings.Settings .StaticCredentials ; x && x->Password && x->PasswordSecretName ) {
1902
- ctx.AddError (TIssue (ctx.GetPosition (createReplication.Pos ()),
1903
- TStringBuilder () << " PASSWORD and PASSWORD_SECRET_NAME are mutually exclusive" ));
1904
- return SyncError ();
1905
- }
1906
-
1907
1937
if (const auto & x = settings.Settings .StaticCredentials ; x && (!x->UserName && x->Password || !x->UserName && x->PasswordSecretName )) {
1908
1938
ctx.AddError (TIssue (ctx.GetPosition (createReplication.Pos ()),
1909
1939
TStringBuilder () << " USER for PASSWORD or PASSWORD_SECRET_NAME are not provided" ));
@@ -1932,73 +1962,7 @@ class TKiSinkCallableExecutionTransformer : public TAsyncCallbackTransformer<TKi
1932
1962
TAlterReplicationSettings settings;
1933
1963
settings.Name = TString (alterReplication.Replication ());
1934
1964
1935
- for (auto setting : alterReplication.ReplicationSettings ()) {
1936
- auto name = setting.Name ().Value ();
1937
- if (name == " connection_string" ) {
1938
- settings.Settings .ConnectionString = setting.Value ().Cast <TCoDataCtor>().Literal ().Cast <TCoAtom>().Value ();
1939
- } else if (name == " endpoint" ) {
1940
- settings.Settings .Endpoint = setting.Value ().Cast <TCoDataCtor>().Literal ().Cast <TCoAtom>().Value ();
1941
- } else if (name == " database" ) {
1942
- settings.Settings .Database = setting.Value ().Cast <TCoDataCtor>().Literal ().Cast <TCoAtom>().Value ();
1943
- } else if (name == " token" ) {
1944
- settings.Settings .EnsureOAuthToken ().Token =
1945
- setting.Value ().Cast <TCoDataCtor>().Literal ().Cast <TCoAtom>().Value ();
1946
- } else if (name == " token_secret_name" ) {
1947
- settings.Settings .EnsureOAuthToken ().TokenSecretName =
1948
- setting.Value ().Cast <TCoDataCtor>().Literal ().Cast <TCoAtom>().Value ();
1949
- } else if (name == " user" ) {
1950
- settings.Settings .EnsureStaticCredentials ().UserName =
1951
- setting.Value ().Cast <TCoDataCtor>().Literal ().Cast <TCoAtom>().Value ();
1952
- } else if (name == " password" ) {
1953
- settings.Settings .EnsureStaticCredentials ().Password =
1954
- setting.Value ().Cast <TCoDataCtor>().Literal ().Cast <TCoAtom>().Value ();
1955
- } else if (name == " password_secret_name" ) {
1956
- settings.Settings .EnsureStaticCredentials ().PasswordSecretName =
1957
- setting.Value ().Cast <TCoDataCtor>().Literal ().Cast <TCoAtom>().Value ();
1958
- } else if (name == " state" ) {
1959
- auto value = ToString (setting.Value ().Cast <TCoDataCtor>().Literal ().Cast <TCoAtom>().Value ());
1960
- if (to_lower (value) == " done" ) {
1961
- settings.Settings .EnsureStateDone ();
1962
- } else {
1963
- ctx.AddError (TIssue (ctx.GetPosition (setting.Name ().Pos ()),
1964
- TStringBuilder () << " Unknown replication state: " << value));
1965
- return SyncError ();
1966
- }
1967
- } else if (name == " failover_mode" ) {
1968
- auto value = ToString (setting.Value ().Cast <TCoDataCtor>().Literal ().Cast <TCoAtom>().Value ());
1969
- if (to_lower (value) == " consistent" ) {
1970
- settings.Settings .EnsureStateDone (TReplicationSettings::EFailoverMode::Consistent);
1971
- } else if (to_lower (value) == " force" ) {
1972
- settings.Settings .EnsureStateDone (TReplicationSettings::EFailoverMode::Force);
1973
- } else {
1974
- ctx.AddError (TIssue (ctx.GetPosition (setting.Name ().Pos ()),
1975
- TStringBuilder () << " Unknown failover mode: " << value));
1976
- return SyncError ();
1977
- }
1978
- }
1979
- }
1980
-
1981
- if (settings.Settings .ConnectionString && (settings.Settings .Endpoint || settings.Settings .Database )) {
1982
- ctx.AddError (TIssue (ctx.GetPosition (alterReplication.Pos ()),
1983
- TStringBuilder () << " Connection string and Endpoint/Database are mutually exclusive" ));
1984
- return SyncError ();
1985
- }
1986
-
1987
- if (settings.Settings .OAuthToken && settings.Settings .StaticCredentials ) {
1988
- ctx.AddError (TIssue (ctx.GetPosition (alterReplication.Pos ()),
1989
- TStringBuilder () << " Token and User/Password are mutually exclusive" ));
1990
- return SyncError ();
1991
- }
1992
-
1993
- if (const auto & x = settings.Settings .OAuthToken ; x && x->Token && x->TokenSecretName ) {
1994
- ctx.AddError (TIssue (ctx.GetPosition (alterReplication.Pos ()),
1995
- TStringBuilder () << " TOKEN and TOKEN_SECRET_NAME are mutually exclusive" ));
1996
- return SyncError ();
1997
- }
1998
-
1999
- if (const auto & x = settings.Settings .StaticCredentials ; x && x->Password && x->PasswordSecretName ) {
2000
- ctx.AddError (TIssue (ctx.GetPosition (alterReplication.Pos ()),
2001
- TStringBuilder () << " PASSWORD and PASSWORD_SECRET_NAME are mutually exclusive" ));
1965
+ if (!ParseAsyncReplicationSettings (settings.Settings , alterReplication.ReplicationSettings (), ctx, alterReplication.Pos ())) {
2002
1966
return SyncError ();
2003
1967
}
2004
1968
0 commit comments