databricks-cli/bundle/config/mutator/validate_workspace_host.go

31 lines
706 B
Go
Raw Normal View History

2024-07-18 07:04:16 +00:00
package mutator
import (
"context"
"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/env"
"github.com/databricks/cli/libs/diag"
)
type validateWorkspaceHost struct{}
func ValidateWorkspaceHost() *validateWorkspaceHost {
return &validateWorkspaceHost{}
}
func (m *validateWorkspaceHost) Name() string {
return "ValidateWorkspaceHost"
}
func (m *validateWorkspaceHost) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
env_host, _ := env.Host(ctx)
target_host := b.Config.Workspace.Host
if env_host != "" && target_host != "" && env_host != target_host {
return diag.Errorf("Target host and DATABRICKS_HOST environment variable mismatch")
}
return nil
}