mirror of https://github.com/databricks/cli.git
Remove from codegen
This commit is contained in:
parent
488a1fbb67
commit
ed62d0821c
|
@ -5,8 +5,7 @@
|
||||||
},
|
},
|
||||||
"batch": {
|
"batch": {
|
||||||
".codegen/cmds-workspace.go.tmpl": "cmd/workspace/cmd.go",
|
".codegen/cmds-workspace.go.tmpl": "cmd/workspace/cmd.go",
|
||||||
".codegen/cmds-account.go.tmpl": "cmd/account/cmd.go",
|
".codegen/cmds-account.go.tmpl": "cmd/account/cmd.go"
|
||||||
".codegen/lookup.go.tmpl": "bundle/config/variable/lookup.go"
|
|
||||||
},
|
},
|
||||||
"toolchain": {
|
"toolchain": {
|
||||||
"required": ["go"],
|
"required": ["go"],
|
||||||
|
|
|
@ -1,134 +0,0 @@
|
||||||
// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT.
|
|
||||||
|
|
||||||
package variable
|
|
||||||
|
|
||||||
{{ $allowlist :=
|
|
||||||
list
|
|
||||||
"alerts"
|
|
||||||
"clusters"
|
|
||||||
"cluster-policies"
|
|
||||||
"clusters"
|
|
||||||
"dashboards"
|
|
||||||
"instance-pools"
|
|
||||||
"jobs"
|
|
||||||
"metastores"
|
|
||||||
"pipelines"
|
|
||||||
"service-principals"
|
|
||||||
"queries"
|
|
||||||
"warehouses"
|
|
||||||
}}
|
|
||||||
|
|
||||||
{{ $customField :=
|
|
||||||
dict
|
|
||||||
"service-principals" "ApplicationId"
|
|
||||||
}}
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/databricks/databricks-sdk-go"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Lookup struct {
|
|
||||||
{{range .Services -}}
|
|
||||||
{{- if in $allowlist .KebabName -}}
|
|
||||||
{{.Singular.PascalName}} string `json:"{{.Singular.SnakeName}},omitempty"`
|
|
||||||
|
|
||||||
{{end}}
|
|
||||||
{{- end}}
|
|
||||||
}
|
|
||||||
|
|
||||||
func LookupFromMap(m map[string]any) *Lookup {
|
|
||||||
l := &Lookup{}
|
|
||||||
{{range .Services -}}
|
|
||||||
{{- if in $allowlist .KebabName -}}
|
|
||||||
if v, ok := m["{{.Singular.SnakeName}}"]; ok {
|
|
||||||
l.{{.Singular.PascalName}} = v.(string)
|
|
||||||
}
|
|
||||||
{{end -}}
|
|
||||||
{{- end}}
|
|
||||||
return l
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *Lookup) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
|
||||||
if err := l.validate(); err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
r := allResolvers()
|
|
||||||
{{range .Services -}}
|
|
||||||
{{- if in $allowlist .KebabName -}}
|
|
||||||
if l.{{.Singular.PascalName}} != "" {
|
|
||||||
return r.{{.Singular.PascalName}}(ctx, w, l.{{.Singular.PascalName}})
|
|
||||||
}
|
|
||||||
{{end -}}
|
|
||||||
{{- end}}
|
|
||||||
|
|
||||||
return "", fmt.Errorf("no valid lookup fields provided")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *Lookup) String() string {
|
|
||||||
{{range .Services -}}
|
|
||||||
{{- if in $allowlist .KebabName -}}
|
|
||||||
if l.{{.Singular.PascalName}} != "" {
|
|
||||||
return fmt.Sprintf("{{.Singular.KebabName}}: %s", l.{{.Singular.PascalName}})
|
|
||||||
}
|
|
||||||
{{end -}}
|
|
||||||
{{- end}}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *Lookup) validate() error {
|
|
||||||
// Validate that only one field is set
|
|
||||||
count := 0
|
|
||||||
{{range .Services -}}
|
|
||||||
{{- if in $allowlist .KebabName -}}
|
|
||||||
if l.{{.Singular.PascalName}} != "" {
|
|
||||||
count++
|
|
||||||
}
|
|
||||||
{{end -}}
|
|
||||||
{{- end}}
|
|
||||||
|
|
||||||
if count != 1 {
|
|
||||||
return fmt.Errorf("exactly one lookup field must be provided")
|
|
||||||
}
|
|
||||||
|
|
||||||
if strings.Contains(l.String(), "${var") {
|
|
||||||
return fmt.Errorf("lookup fields cannot contain variable references")
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
type resolverFunc func(ctx context.Context, w *databricks.WorkspaceClient, name string) (string, error)
|
|
||||||
type resolvers struct {
|
|
||||||
{{range .Services -}}
|
|
||||||
{{- if in $allowlist .KebabName -}}
|
|
||||||
{{.Singular.PascalName}} resolverFunc
|
|
||||||
{{end -}}
|
|
||||||
{{- end}}
|
|
||||||
}
|
|
||||||
|
|
||||||
func allResolvers() *resolvers {
|
|
||||||
r := &resolvers{}
|
|
||||||
{{range .Services -}}
|
|
||||||
{{- if in $allowlist .KebabName -}}
|
|
||||||
r.{{.Singular.PascalName}} = func(ctx context.Context, w *databricks.WorkspaceClient, name string) (string, error) {
|
|
||||||
fn, ok := lookupOverrides["{{.Singular.PascalName}}"]
|
|
||||||
if ok {
|
|
||||||
return fn(ctx, w, name)
|
|
||||||
}
|
|
||||||
entity, err := w.{{.PascalName}}.GetBy{{range .NamedIdMap.NamePath}}{{.PascalName}}{{end}}(ctx, name)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Sprint(entity.{{ getOrDefault $customField .KebabName ((index .NamedIdMap.IdPath 0).PascalName) }}), nil
|
|
||||||
}
|
|
||||||
{{end -}}
|
|
||||||
{{- end}}
|
|
||||||
|
|
||||||
return r
|
|
||||||
}
|
|
|
@ -1,4 +1,3 @@
|
||||||
bundle/config/variable/lookup.go linguist-generated=true
|
|
||||||
cmd/account/access-control/access-control.go linguist-generated=true
|
cmd/account/access-control/access-control.go linguist-generated=true
|
||||||
cmd/account/billable-usage/billable-usage.go linguist-generated=true
|
cmd/account/billable-usage/billable-usage.go linguist-generated=true
|
||||||
cmd/account/budgets/budgets.go linguist-generated=true
|
cmd/account/budgets/budgets.go linguist-generated=true
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT.
|
|
||||||
|
|
||||||
package variable
|
package variable
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/databricks/databricks-sdk-go"
|
"github.com/databricks/databricks-sdk-go"
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue