From ed62d0821c60777a8d6982fb86f33912a975b181 Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Wed, 20 Nov 2024 22:54:52 +0100 Subject: [PATCH] Remove from codegen --- .codegen.json | 3 +- .codegen/lookup.go.tmpl | 134 ------------------------------- .gitattributes | 1 - bundle/config/variable/lookup.go | 3 - 4 files changed, 1 insertion(+), 140 deletions(-) delete mode 100644 .codegen/lookup.go.tmpl diff --git a/.codegen.json b/.codegen.json index 4524ab55d..73ab8c2a4 100644 --- a/.codegen.json +++ b/.codegen.json @@ -5,8 +5,7 @@ }, "batch": { ".codegen/cmds-workspace.go.tmpl": "cmd/workspace/cmd.go", - ".codegen/cmds-account.go.tmpl": "cmd/account/cmd.go", - ".codegen/lookup.go.tmpl": "bundle/config/variable/lookup.go" + ".codegen/cmds-account.go.tmpl": "cmd/account/cmd.go" }, "toolchain": { "required": ["go"], diff --git a/.codegen/lookup.go.tmpl b/.codegen/lookup.go.tmpl deleted file mode 100644 index 124b629d0..000000000 --- a/.codegen/lookup.go.tmpl +++ /dev/null @@ -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 -} diff --git a/.gitattributes b/.gitattributes index ecb5669ef..2755c02d7 100755 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,3 @@ -bundle/config/variable/lookup.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/budgets/budgets.go linguist-generated=true diff --git a/bundle/config/variable/lookup.go b/bundle/config/variable/lookup.go index 111bc6ac5..f08c1d8dd 100755 --- a/bundle/config/variable/lookup.go +++ b/bundle/config/variable/lookup.go @@ -1,11 +1,8 @@ -// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. - package variable import ( "context" "fmt" - "strings" "github.com/databricks/databricks-sdk-go" )