mirror of https://github.com/databricks/cli.git
Address reviewer comments
This commit is contained in:
parent
1325fd867a
commit
189d40b1fa
|
@ -10,7 +10,7 @@ import (
|
||||||
"github.com/databricks/cli/libs/diag"
|
"github.com/databricks/cli/libs/diag"
|
||||||
)
|
)
|
||||||
|
|
||||||
type initializeUrls struct {
|
type initializeURLs struct {
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,30 +19,25 @@ type initializeUrls struct {
|
||||||
// latency. As such, it should only be used when needed.
|
// latency. As such, it should only be used when needed.
|
||||||
// This URL field is used for the output of the 'bundle summary' CLI command.
|
// This URL field is used for the output of the 'bundle summary' CLI command.
|
||||||
func InitializeURLs() bundle.Mutator {
|
func InitializeURLs() bundle.Mutator {
|
||||||
return &initializeUrls{}
|
return &initializeURLs{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *initializeUrls) Name() string {
|
func (m *initializeURLs) Name() string {
|
||||||
return fmt.Sprintf("ConfigureURLs(%s)", m.name)
|
return fmt.Sprintf("InitializeURLs(%s)", m.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *initializeUrls) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
|
func (m *initializeURLs) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
|
||||||
workspaceId, err := b.WorkspaceClient().CurrentWorkspaceID(ctx)
|
workspaceId, err := b.WorkspaceClient().CurrentWorkspaceID(ctx)
|
||||||
orgId := strconv.FormatInt(workspaceId, 10)
|
orgId := strconv.FormatInt(workspaceId, 10)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
configureForOrgId(b, orgId)
|
urlPrefix := b.WorkspaceClient().Config.CanonicalHostName() + "/"
|
||||||
|
initializeForWorkspace(b, orgId, urlPrefix)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func configureForOrgId(b *bundle.Bundle, orgId string) {
|
func initializeForWorkspace(b *bundle.Bundle, orgId string, urlPrefix string) {
|
||||||
urlPrefix := b.Config.Workspace.Host
|
|
||||||
if !strings.HasSuffix(urlPrefix, "/") {
|
|
||||||
urlPrefix += "/"
|
|
||||||
}
|
|
||||||
urlSuffix := ""
|
|
||||||
|
|
||||||
// Add ?o=<workspace id> only if <workspace id> wasn't in the subdomain already.
|
// Add ?o=<workspace id> only if <workspace id> wasn't in the subdomain already.
|
||||||
// The ?o= is needed when vanity URLs / legacy workspace URLs are used.
|
// The ?o= is needed when vanity URLs / legacy workspace URLs are used.
|
||||||
// If it's not needed we prefer to leave it out since these URLs are rather
|
// If it's not needed we prefer to leave it out since these URLs are rather
|
||||||
|
@ -50,6 +45,7 @@ func configureForOrgId(b *bundle.Bundle, orgId string) {
|
||||||
//
|
//
|
||||||
// See https://docs.databricks.com/en/workspace/workspace-details.html for
|
// See https://docs.databricks.com/en/workspace/workspace-details.html for
|
||||||
// further reading about the '?o=' suffix.
|
// further reading about the '?o=' suffix.
|
||||||
|
urlSuffix := ""
|
||||||
if !strings.Contains(urlPrefix, orgId) {
|
if !strings.Contains(urlPrefix, orgId) {
|
||||||
urlSuffix = "?o=" + orgId
|
urlSuffix = "?o=" + orgId
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ func TestInitializeURLs(t *testing.T) {
|
||||||
"schema1": "https://mycompany.databricks.com/explore/data/catalog/schema?o=123456",
|
"schema1": "https://mycompany.databricks.com/explore/data/catalog/schema?o=123456",
|
||||||
}
|
}
|
||||||
|
|
||||||
configureForOrgId(b, "123456")
|
initializeForWorkspace(b, "123456", "https://mycompany.databricks.com/")
|
||||||
|
|
||||||
for _, rs := range b.Config.Resources.AllResources() {
|
for _, rs := range b.Config.Resources.AllResources() {
|
||||||
for key, r := range rs {
|
for key, r := range rs {
|
||||||
|
@ -103,10 +103,6 @@ func TestInitializeURLs(t *testing.T) {
|
||||||
func URLs_NoOrgId(t *testing.T) {
|
func URLs_NoOrgId(t *testing.T) {
|
||||||
b := &bundle.Bundle{
|
b := &bundle.Bundle{
|
||||||
Config: config.Root{
|
Config: config.Root{
|
||||||
Workspace: config.Workspace{
|
|
||||||
// Hostname with org id in URL and no trailing /
|
|
||||||
Host: "https://adb-123456.azuredatabricks.net",
|
|
||||||
},
|
|
||||||
Resources: config.Resources{
|
Resources: config.Resources{
|
||||||
Jobs: map[string]*resources.Job{
|
Jobs: map[string]*resources.Job{
|
||||||
"job1": {
|
"job1": {
|
||||||
|
@ -118,7 +114,7 @@ func URLs_NoOrgId(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
configureForOrgId(b, "123456")
|
initializeForWorkspace(b, "123456", "https://adb-123456.azuredatabricks.net/")
|
||||||
|
|
||||||
require.Equal(t, "https://adb-123456.azuredatabricks.net/jobs/1", b.Config.Resources.Jobs["job1"].URL)
|
require.Equal(t, "https://adb-123456.azuredatabricks.net/jobs/1", b.Config.Resources.Jobs["job1"].URL)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue