File tree Expand file tree Collapse file tree 2 files changed +38
-13
lines changed
main/java/com/databricks/sdk/core
test/java/com/databricks/sdk/core Expand file tree Collapse file tree 2 files changed +38
-13
lines changed Original file line number Diff line number Diff line change @@ -631,6 +631,25 @@ public DatabricksEnvironment getDatabricksEnvironment() {
631631 return DatabricksEnvironment .getEnvironmentFromHostname (this .host );
632632 }
633633
634+ private DatabricksConfig clone (Set <String > fieldsToSkip ) {
635+ DatabricksConfig newConfig = new DatabricksConfig ();
636+ for (Field f : DatabricksConfig .class .getDeclaredFields ()) {
637+ if (fieldsToSkip .contains (f .getName ())) {
638+ continue ;
639+ }
640+ try {
641+ f .set (newConfig , f .get (this ));
642+ } catch (IllegalAccessException e ) {
643+ throw new RuntimeException (e );
644+ }
645+ }
646+ return newConfig ;
647+ }
648+
649+ public DatabricksConfig clone () {
650+ return clone (new HashSet <>());
651+ }
652+
634653 public DatabricksConfig newWithWorkspaceHost (String host ) {
635654 Set <String > fieldsToSkip =
636655 new HashSet <>(
@@ -645,18 +664,6 @@ public DatabricksConfig newWithWorkspaceHost(String host) {
645664 // don't cache the
646665 // header factory.
647666 "headerFactory" ));
648- DatabricksConfig newConfig = new DatabricksConfig ();
649- for (Field f : DatabricksConfig .class .getDeclaredFields ()) {
650- if (fieldsToSkip .contains (f .getName ())) {
651- continue ;
652- }
653- try {
654- f .set (newConfig , f .get (this ));
655- } catch (IllegalAccessException e ) {
656- throw new RuntimeException (e );
657- }
658- }
659- newConfig .setHost (host );
660- return newConfig ;
667+ return clone (fieldsToSkip ).setHost (host );
661668 }
662669}
Original file line number Diff line number Diff line change @@ -177,4 +177,22 @@ public void testNewWithWorkspaceHost() {
177177 assert newWorkspaceConfig .getClientId ().equals ("my-client-id" );
178178 assert newWorkspaceConfig .getClientSecret ().equals ("my-client-secret" );
179179 }
180+
181+ @ Test
182+ public void testClone () {
183+ DatabricksConfig config =
184+ new DatabricksConfig ()
185+ .setAuthType ("oauth-m2m" )
186+ .setClientId ("my-client-id" )
187+ .setClientSecret ("my-client-secret" )
188+ .setAccountId ("account-id" )
189+ .setHost ("https://account.cloud.databricks.com" );
190+
191+ DatabricksConfig newWorkspaceConfig = config .clone ();
192+
193+ assert newWorkspaceConfig .getHost ().equals ("https://account.cloud.databricks.com" );
194+ assert newWorkspaceConfig .getAuthType ().equals ("oauth-m2m" );
195+ assert newWorkspaceConfig .getClientId ().equals ("my-client-id" );
196+ assert newWorkspaceConfig .getClientSecret ().equals ("my-client-secret" );
197+ }
180198}
You can’t perform that action at this time.
0 commit comments