@@ -133,6 +133,15 @@ depends on the existing profiles you have set in your configuration file
133133 if err != nil {
134134 return err
135135 }
136+
137+ // Load unified host flags from the profile if not explicitly set via CLI flag
138+ if ! cmd .Flag ("experimental-is-unified-host" ).Changed && existingProfile != nil {
139+ authArguments .IsUnifiedHost = existingProfile .IsUnifiedHost
140+ }
141+ if ! cmd .Flag ("workspace-id" ).Changed && existingProfile != nil {
142+ authArguments .WorkspaceId = existingProfile .WorkspaceId
143+ }
144+
136145 err = setHostAndAccountId (ctx , existingProfile , authArguments , args )
137146 if err != nil {
138147 return err
@@ -155,9 +164,11 @@ depends on the existing profiles you have set in your configuration file
155164 // We need the config without the profile before it's used to initialise new workspace client below.
156165 // Otherwise it will complain about non existing profile because it was not yet saved.
157166 cfg := config.Config {
158- Host : authArguments .Host ,
159- AccountID : authArguments .AccountID ,
160- AuthType : "databricks-cli" ,
167+ Host : authArguments .Host ,
168+ AccountID : authArguments .AccountID ,
169+ WorkspaceId : authArguments .WorkspaceId ,
170+ Experimental_IsUnifiedHost : authArguments .IsUnifiedHost ,
171+ AuthType : "databricks-cli" ,
161172 }
162173 databricksCfgFile := os .Getenv ("DATABRICKS_CONFIG_FILE" )
163174 if databricksCfgFile != "" {
@@ -202,13 +213,15 @@ depends on the existing profiles you have set in your configuration file
202213
203214 if profileName != "" {
204215 err = databrickscfg .SaveToProfile (ctx , & config.Config {
205- Profile : profileName ,
206- Host : cfg .Host ,
207- AuthType : cfg .AuthType ,
208- AccountID : cfg .AccountID ,
209- ClusterID : cfg .ClusterID ,
210- ConfigFile : cfg .ConfigFile ,
211- ServerlessComputeID : cfg .ServerlessComputeID ,
216+ Profile : profileName ,
217+ Host : cfg .Host ,
218+ AuthType : cfg .AuthType ,
219+ AccountID : cfg .AccountID ,
220+ WorkspaceId : authArguments .WorkspaceId ,
221+ Experimental_IsUnifiedHost : authArguments .IsUnifiedHost ,
222+ ClusterID : cfg .ClusterID ,
223+ ConfigFile : cfg .ConfigFile ,
224+ ServerlessComputeID : cfg .ServerlessComputeID ,
212225 })
213226 if err != nil {
214227 return err
@@ -260,24 +273,65 @@ func setHostAndAccountId(ctx context.Context, existingProfile *profile.Profile,
260273 }
261274 }
262275
263- // If the account-id was not provided as a cmd line flag, try to read it from
264- // the specified profile.
265- //nolint:staticcheck // SA1019: IsAccountClient is deprecated but is still used here to avoid breaking changes
266- isAccountClient := (& config.Config {Host : authArguments .Host }).IsAccountClient ()
267- accountID := authArguments .AccountID
268- if isAccountClient && accountID == "" {
269- if existingProfile != nil && existingProfile .AccountID != "" {
270- authArguments .AccountID = existingProfile .AccountID
271- } else {
272- // Prompt user for the account-id if it we could not get it from a
273- // profile.
274- accountId , err := promptForAccountID (ctx )
275- if err != nil {
276- return err
276+ // Determine the host type and handle account ID / workspace ID accordingly
277+ cfg := & config.Config {
278+ Host : authArguments .Host ,
279+ AccountID : authArguments .AccountID ,
280+ WorkspaceId : authArguments .WorkspaceId ,
281+ Experimental_IsUnifiedHost : authArguments .IsUnifiedHost ,
282+ }
283+
284+ switch cfg .HostType () {
285+ case config .AccountHost :
286+ // Account host - prompt for account ID if not provided
287+ if authArguments .AccountID == "" {
288+ if existingProfile != nil && existingProfile .AccountID != "" {
289+ authArguments .AccountID = existingProfile .AccountID
290+ } else {
291+ accountId , err := promptForAccountID (ctx )
292+ if err != nil {
293+ return err
294+ }
295+ authArguments .AccountID = accountId
296+ }
297+ }
298+ case config .UnifiedHost :
299+ // Unified host requires an account ID for OAuth URL construction
300+ if authArguments .AccountID == "" {
301+ if existingProfile != nil && existingProfile .AccountID != "" {
302+ authArguments .AccountID = existingProfile .AccountID
303+ } else {
304+ accountId , err := promptForAccountID (ctx )
305+ if err != nil {
306+ return err
307+ }
308+ authArguments .AccountID = accountId
309+ }
310+ }
311+
312+ // Workspace ID is optional and determines API access level:
313+ // - With workspace ID: workspace-level APIs
314+ // - Without workspace ID: account-level APIs
315+ // If neither is provided via flags, prompt for workspace ID (most common case)
316+ hasWorkspaceID := authArguments .WorkspaceId != ""
317+ if ! hasWorkspaceID {
318+ if existingProfile != nil && existingProfile .WorkspaceId != "" {
319+ authArguments .WorkspaceId = existingProfile .WorkspaceId
320+ } else {
321+ // Prompt for workspace ID for workspace-level access
322+ workspaceId , err := promptForWorkspaceID (ctx )
323+ if err != nil {
324+ return err
325+ }
326+ authArguments .WorkspaceId = workspaceId
277327 }
278- authArguments .AccountID = accountId
279328 }
329+ case config .WorkspaceHost :
330+ // Workspace host - no additional prompts needed
331+ default :
332+ return fmt .Errorf ("unknown host type: %v" , cfg .HostType ())
280333 }
334+
281335 return nil
282336}
283337
0 commit comments