mirror of https://github.com/databricks/cli.git
Compare commits
2 Commits
3e91d3c8cb
...
373508425f
Author | SHA1 | Date |
---|---|---|
shreyas-goenka | 373508425f | |
Shreyas Goenka | be2d802d13 |
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/databricks/cli/libs/dbr"
|
||||
"github.com/databricks/cli/libs/diag"
|
||||
"github.com/databricks/cli/libs/dyn"
|
||||
"github.com/databricks/cli/libs/log"
|
||||
"github.com/databricks/cli/libs/textutil"
|
||||
"github.com/databricks/databricks-sdk-go/service/catalog"
|
||||
"github.com/databricks/databricks-sdk-go/service/jobs"
|
||||
|
@ -189,6 +190,14 @@ func (m *applyPresets) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnos
|
|||
diags = diags.Extend(diag.Errorf("schema %s is not defined", key))
|
||||
continue
|
||||
}
|
||||
|
||||
// If the catalog is already namespaced to the current user, we don't need
|
||||
// to prefix the schema name since it already falls under the user's namespace.
|
||||
if containsUserIdentity(s.CatalogName, b.Config.Workspace.CurrentUser) {
|
||||
log.Debugf(ctx, "Skipping schema %s since catalog %s already contains the user's identity", s.Name, s.CatalogName)
|
||||
continue
|
||||
}
|
||||
|
||||
s.Name = normalizePrefix(prefix) + s.Name
|
||||
// HTTP API for schemas doesn't yet support tags. It's only supported in
|
||||
// the Databricks UI and via the SQL API.
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/databricks/cli/bundle/config/resources"
|
||||
"github.com/databricks/cli/libs/dbr"
|
||||
"github.com/databricks/databricks-sdk-go/service/catalog"
|
||||
"github.com/databricks/databricks-sdk-go/service/iam"
|
||||
"github.com/databricks/databricks-sdk-go/service/jobs"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -98,12 +99,53 @@ func TestApplyPresetsPrefixForUcSchema(t *testing.T) {
|
|||
},
|
||||
want: "schema1",
|
||||
},
|
||||
{
|
||||
name: "skip prefix because catalog contains short name",
|
||||
prefix: "[prefix]",
|
||||
schema: &resources.Schema{
|
||||
CreateSchema: &catalog.CreateSchema{
|
||||
Name: "schema1",
|
||||
CatalogName: "dev_john_smith_test_catalog",
|
||||
},
|
||||
},
|
||||
want: "schema1",
|
||||
},
|
||||
{
|
||||
name: "skip prefix because catalog contains email",
|
||||
prefix: "[prefix]",
|
||||
schema: &resources.Schema{
|
||||
CreateSchema: &catalog.CreateSchema{
|
||||
Name: "schema1",
|
||||
CatalogName: "dev_john.smith@databricks.com_test_catalog",
|
||||
},
|
||||
},
|
||||
want: "schema1",
|
||||
},
|
||||
{
|
||||
name: "add prefix because catalog is not namespaced to user",
|
||||
prefix: "[prefix]",
|
||||
schema: &resources.Schema{
|
||||
CreateSchema: &catalog.CreateSchema{
|
||||
Name: "schema1",
|
||||
CatalogName: "test_catalog",
|
||||
},
|
||||
},
|
||||
want: "prefix_schema1",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
b := &bundle.Bundle{
|
||||
Config: config.Root{
|
||||
Workspace: config.Workspace{
|
||||
CurrentUser: &config.User{
|
||||
ShortName: "john_smith",
|
||||
User: &iam.User{
|
||||
UserName: "john.smith@databricks.com",
|
||||
},
|
||||
},
|
||||
},
|
||||
Resources: config.Resources{
|
||||
Schemas: map[string]*resources.Schema{
|
||||
"schema1": tt.schema,
|
||||
|
|
|
@ -72,6 +72,10 @@ func transformDevelopmentMode(ctx context.Context, b *bundle.Bundle) {
|
|||
}
|
||||
}
|
||||
|
||||
func containsUserIdentity(s string, u *config.User) bool {
|
||||
return strings.Contains(s, u.ShortName) || strings.Contains(s, u.UserName)
|
||||
}
|
||||
|
||||
func validateDevelopmentMode(b *bundle.Bundle) diag.Diagnostics {
|
||||
var diags diag.Diagnostics
|
||||
p := b.Config.Presets
|
||||
|
@ -101,7 +105,7 @@ func validateDevelopmentMode(b *bundle.Bundle) diag.Diagnostics {
|
|||
diags = diags.Extend(diag.Errorf("%s must start with '~/' or contain the current username to ensure uniqueness when using 'mode: development'", path))
|
||||
}
|
||||
}
|
||||
if p.NamePrefix != "" && !strings.Contains(p.NamePrefix, u.ShortName) && !strings.Contains(p.NamePrefix, u.UserName) {
|
||||
if p.NamePrefix != "" && !containsUserIdentity(p.NamePrefix, u) {
|
||||
// Resources such as pipelines require a unique name, e.g. '[dev steve] my_pipeline'.
|
||||
// For this reason we require the name prefix to contain the current username;
|
||||
// it's a pitfall for users if they don't include it and later find out that
|
||||
|
|
Loading…
Reference in New Issue