Add workspace host mismatch check

This commit is contained in:
Anders Rex 2024-07-18 10:04:16 +03:00
parent 61cb0f2695
commit 153510bfbf
No known key found for this signature in database
GPG Key ID: 06A88681C237F740
3 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,30 @@
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
}

11
bundle/env/host.go vendored Normal file
View File

@ -0,0 +1,11 @@
package env
import "context"
const HostVariable = "DATABRICKS_HOST"
func Host(ctx context.Context) (string, bool) {
return get(ctx, []string{
HostVariable,
})
}

View File

@ -25,6 +25,7 @@ func Deploy() bundle.Mutator {
bundle.Seq( bundle.Seq(
terraform.StatePull(), terraform.StatePull(),
deploy.StatePull(), deploy.StatePull(),
mutator.ValidateWorkspaceHost(),
mutator.ValidateGitDetails(), mutator.ValidateGitDetails(),
libraries.ValidateLocalLibrariesExist(), libraries.ValidateLocalLibrariesExist(),
artifacts.CleanUp(), artifacts.CleanUp(),