diff --git a/.codegen.json b/.codegen.json index daf9925a..91b22e87 100644 --- a/.codegen.json +++ b/.codegen.json @@ -1,25 +1,6 @@ { - "formatter": "go fmt ./... && go run golang.org/x/tools/cmd/goimports@latest -w $FILENAMES", + "mode": "go_v0", "changelog_config": ".codegen/changelog_config.yml", - "packages": { - ".codegen/api.go.tmpl": "service/{{.Name}}/api.go", - ".codegen/impl.go.tmpl": "service/{{.Name}}/impl.go", - ".codegen/interface.go.tmpl": "service/{{.Name}}/interface.go", - ".codegen/model.go.tmpl": "service/{{.Name}}/model.go" - }, - "batch": { - ".codegen/workspaces.go.tmpl": "workspace_client.go", - ".codegen/accounts.go.tmpl": "account_client.go", - ".codegen/service-pkg.go.tmpl": "service/pkg.go", - ".codegen/error_mapping.go.tmpl": "apierr/error_mapping.go", - ".codegen/error_overrides.go.tmpl": "apierr/error_overrides.go", - ".codegen/error_alias.go.tmpl": "error_alias.go", - ".codegen/mock_workspace_client.go.tmpl": "experimental/mocks/mock_workspace_client.go", - ".codegen/mock_account_client.go.tmpl": "experimental/mocks/mock_account_client.go" - }, - "examples": { - ".codegen/examples_test.go.tmpl": "service/{{.Package}}/{{.SnakeName}}_usage_test.go" - }, "version": { "version/version.go": "const Version = \"$VERSION\"" }, @@ -28,6 +9,7 @@ "go" ], "post_generate": [ + "make fmt", "go run github.com/vektra/mockery/v2@0229bd4bb4357cd09af7ac15ecab85022d296b12" ] } diff --git a/.codegen/accounts.go.tmpl b/.codegen/accounts.go.tmpl deleted file mode 100644 index 28fb92e6..00000000 --- a/.codegen/accounts.go.tmpl +++ /dev/null @@ -1,62 +0,0 @@ -// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. - -package databricks - -import ( - "github.com/databricks/databricks-sdk-go/client" - {{range .Packages}} - "github.com/databricks/databricks-sdk-go/service/{{.Name}}" - {{- end}} -) - -type AccountClient struct { - Config *config.Config - - {{range .Services}}{{if and .IsAccounts (not .HasParent)}} - {{.Comment " // " 80}} - {{(.TrimPrefix "account").PascalName}} {{.Package.Name}}.{{.PascalName}}Interface - {{end}}{{end}} -} - -var ErrNotAccountClient = errors.New("invalid Databricks Account configuration") - -// NewAccountClient creates new Databricks SDK client for Accounts or returns -// error in case configuration is wrong -func NewAccountClient(c ...*Config) (*AccountClient, error) { - var cfg *config.Config - if len(c) == 1 { - // first config - cfg = (*config.Config)(c[0]) - } else { - // default config - cfg = &config.Config{} - } - err := cfg.EnsureResolved() - if err != nil { - return nil, err - } - if cfg.AccountID == "" || !cfg.IsAccountClient() { - return nil, ErrNotAccountClient - } - apiClient, err := client.New(cfg) - if err != nil { - return nil, err - } - {{range .Services}}{{if and .IsAccounts (not .HasParent) .HasDataPlaneAPI}} - {{.CamelName}} := {{.Package.Name}}.New{{.PascalName}}(apiClient) - {{- end}}{{end}} - return &AccountClient{ - Config: cfg, - {{range .Services}} - {{- if and .IsAccounts (not .HasParent)}} - {{- if .HasDataPlaneAPI}} - {{(.TrimPrefix "account").PascalName}}: {{.CamelName}}, - {{- else if .IsDataPlane}} - {{(.TrimPrefix "account").PascalName}}: {{.Package.Name}}.New{{.PascalName}}(apiClient, {{.ControlPlaneService.CamelName}}), - {{- else }} - {{(.TrimPrefix "account").PascalName}}: {{.Package.Name}}.New{{.PascalName}}(apiClient), - {{- end -}} - {{- end -}} - {{end}} - }, nil -} diff --git a/.codegen/api.go.tmpl b/.codegen/api.go.tmpl deleted file mode 100644 index dff6829c..00000000 --- a/.codegen/api.go.tmpl +++ /dev/null @@ -1,416 +0,0 @@ -// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. - -// {{if .Description}}{{.Description}}{{else}}These APIs allow you to manage {{range .Services}}{{.TitleName}}, {{end}}etc.{{end}} -package {{.Name}} - -import ( - "context" - "fmt" - "time" - "github.com/databricks/databricks-sdk-go/retries" - "github.com/databricks/databricks-sdk-go/client" - "github.com/databricks/databricks-sdk-go/listing" - "github.com/databricks/databricks-sdk-go/useragent" -) -{{ $extendedInterface := - list - "Clusters" - "CommandExecution" - "Dbfs" - "Libraries" - "StatementExecution" - "Workspace" -}} -{{range .Services}} - -type {{.PascalName}}Interface interface { - {{if (in $extendedInterface .PascalName) }} - {{.CamelName}}APIUtilities - {{end -}} - - {{range .Subservices}} - {{.Comment " // " 80}} - {{.PascalName}}() {{.PascalName}}Interface - {{end}} - - {{range .Waits}} - // {{.PascalName}} repeatedly calls [{{.Method.Service.PascalName}}API.{{.Poll.PascalName}}] and waits to reach {{range $i, $e := .Success}}{{if $i}} or {{end}}{{.Content}}{{end}} state - {{.PascalName}}(ctx context.Context{{range .Binding}}, {{.PollField.CamelName}} {{template "type" .PollField.Entity}}{{end}}, - timeout time.Duration, callback func(*{{.Poll.Response.PascalName}})) (*{{.Poll.Response.PascalName}}, error) - {{end}} - - {{range .Methods}} - {{- $hasWaiter := and .Wait (and (not .IsCrudRead) (not (eq .SnakeName "get_run"))) -}} - {{if not .Pagination}}{{.Comment "// " 80}} - {{.PascalName}}(ctx context.Context{{if .Request}}, {{if $hasWaiter}}{{.Request.CamelName}}{{else}}request{{end}} {{.Request.PascalName}}{{end}}) {{if $hasWaiter}}{{ template "wait-response-type" . }}{{else}}{{ template "response-type" .}}{{end}} - {{end}} - - {{if $hasWaiter}} - // Calls [{{.Service.PascalName}}APIInterface.{{.PascalName}}] and waits to reach {{range $i, $e := .Wait.Success}}{{if $i}} or {{end}}{{.Content}}{{end}} state - // - // You can override the default timeout of {{.Wait.Timeout}} minutes by calling adding - // retries.Timeout[{{.Wait.Poll.Response.PascalName}}](60*time.Minute) functional option. - // - // Deprecated: use [{{.Service.PascalName}}APIInterface.{{.PascalName}}].Get() or [{{.Service.PascalName}}APIInterface.{{.Wait.PascalName}}] - {{.PascalName}}AndWait(ctx context.Context{{if .Request}}, {{.Request.CamelName}} {{.Request.PascalName}}{{end}}, options ...retries.Option[{{.Wait.Poll.Response.PascalName}}]) (*{{.Wait.Poll.Response.PascalName}}, error) - - {{end}}{{if .Pagination}} - {{.Comment "// " 80}} - // - // This method is generated by Databricks SDK Code Generator. - {{.PascalName}}(ctx context.Context{{if .Request}}, request {{.Request.PascalName}}{{end}}) {{ template "paginated-return-type" . }} - - {{.Comment "// " 80}} - // - // This method is generated by Databricks SDK Code Generator. - {{.PascalName}}All(ctx context.Context{{if .Request}}, request {{.Request.PascalName}}{{end}}) ([]{{ template "type" .Pagination.Entity }}, error) - - {{end}}{{if .NamedIdMap}} - // {{.NamedIdMap.PascalName}} calls [{{.Service.PascalName}}API.{{.PascalName}}{{if not .NamedIdMap.Direct}}All{{end -}}] and creates a map of results with [{{.NamedIdMap.Entity.PascalName}}]{{ template "field-path" .NamedIdMap.NamePath }} as key and [{{.NamedIdMap.Entity.PascalName}}]{{ template "field-path" .NamedIdMap.IdPath}} as value. - // - // Returns an error if there's more than one [{{.NamedIdMap.Entity.PascalName}}] with the same {{ template "field-path" .NamedIdMap.NamePath }}. - // - // Note: All [{{.NamedIdMap.Entity.PascalName}}] instances are loaded into memory before creating a map. - // - // This method is generated by Databricks SDK Code Generator. - {{.NamedIdMap.PascalName}}(ctx context.Context{{if .Request}}, request {{.Request.PascalName}}{{end}}) (map[string]{{template "type" .NamedIdMap.Id.Entity}}, error) - - {{end}}{{if .GetByName}} - // GetBy{{range .NamedIdMap.NamePath}}{{.PascalName}}{{end}} calls [{{.Service.PascalName}}API.{{.NamedIdMap.Entity.PascalName}}{{range .NamedIdMap.NamePath}}{{.PascalName}}{{end}}To{{.NamedIdMap.Id.PascalName}}Map] and returns a single [{{.GetByName.PascalName}}]. - // - // Returns an error if there's more than one [{{.NamedIdMap.Entity.PascalName}}] with the same {{ template "field-path" .NamedIdMap.NamePath }}. - // - // Note: All [{{.NamedIdMap.Entity.PascalName}}] instances are loaded into memory before returning matching by name. - // - // This method is generated by Databricks SDK Code Generator. - GetBy{{range .NamedIdMap.NamePath}}{{.PascalName}}{{end}}(ctx context.Context, name string) (*{{template "type" .GetByName}}, error) - - {{end}}{{if .Shortcut}} - {{.Comment "// " 80}} - {{.Shortcut.PascalName}}(ctx context.Context{{range .Shortcut.Params}}, {{.CamelName}} {{template "type" .Entity}}{{end}}) {{ template "response-type" . }} - - {{end}}{{if and .Shortcut $hasWaiter}} - {{.Shortcut.PascalName}}AndWait(ctx context.Context{{range .Shortcut.Params}}, {{.CamelName}} {{template "type" .Entity}}{{end}}, options ...retries.Option[{{.Wait.Poll.Response.PascalName}}]) (*{{.Wait.Poll.Response.PascalName}}, error) - - {{end}} -{{end -}} -} - -func New{{.PascalName}}(client *client.DatabricksClient, -{{- if .IsDataPlane}} -controlPlane *{{.ControlPlaneService.PascalName}}API, -{{end -}} -) *{{.PascalName}}API { - return &{{.PascalName}}API{ - {{.CamelName}}Impl: {{.CamelName}}Impl{ - client: client, - {{- if .IsDataPlane}} - dataPlaneService: oauth2.NewDataPlaneService(), - controlPlane: controlPlane, - {{end}} - }, - {{range .Subservices}} - {{.CamelName}}: New{{.PascalName}}(client), - {{end}} - } -} - -{{.Comment "// " 80}} -type {{.PascalName}}API struct { - {{.CamelName}}Impl - - {{range .Subservices}} - {{.Comment " // " 80}} - {{.CamelName}} {{.PascalName}}Interface - {{end}} -} - -{{range .Subservices}} -func (a *{{.ParentService.PascalName}}API) {{.PascalName}}() {{.PascalName}}Interface { - return a.{{.CamelName}} -} -{{end}} - -{{range .Waits}} -// {{.PascalName}} repeatedly calls [{{.Method.Service.PascalName}}API.{{.Poll.PascalName}}] and waits to reach {{range $i, $e := .Success}}{{if $i}} or {{end}}{{.Content}}{{end}} state -func (a *{{.Method.Service.PascalName}}API) {{.PascalName}}(ctx context.Context{{range .Binding}}, {{.PollField.CamelName}} {{template "type" .PollField.Entity}}{{end}}, - timeout time.Duration, callback func(*{{.Poll.Response.PascalName}})) (*{{.Poll.Response.PascalName}}, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "long-running") - return retries.Poll[{{.Poll.Response.PascalName}}](ctx, timeout, func() (*{{.Poll.Response.PascalName}}, *retries.Err) { - {{.Poll.Response.CamelName}}, err := a.{{.Poll.PascalName}}(ctx, {{.Poll.Request.PascalName}}{ {{range .Binding}} - {{.PollField.PascalName}}: {{.PollField.CamelName}},{{end}} - }) - if err != nil { - return nil, retries.Halt(err) - } - if callback != nil { - callback({{.Poll.Response.CamelName}}) - } - status := {{.Poll.Response.CamelName}}{{range .StatusPath}}.{{.PascalName}}{{end}} - {{if .MessagePath -}} - {{if .ComplexMessagePath -}} - statusMessage := fmt.Sprintf("current status: %s", status) - if ({{.Poll.Response.CamelName}}.{{.MessagePathHead.PascalName}} != nil) { - statusMessage = {{.Poll.Response.CamelName}}{{range .MessagePath}}.{{.PascalName}}{{end}} - } - {{- else -}} - statusMessage := {{.Poll.Response.CamelName}}{{range .MessagePath}}.{{.PascalName}}{{end}} - {{- end}} - {{- else -}} - statusMessage := fmt.Sprintf("current status: %s", status) - {{- end}} - switch status { - case {{range $i, $e := .Success}}{{if $i}}, {{end}}{{$e.Entity.PascalName}}{{$e.PascalName}}{{end}}: // target state - return {{.Poll.Response.CamelName}}, nil - {{if .Failure}}case {{range $i, $e := .Failure}}{{if $i}}, {{end}}{{$e.Entity.PascalName}}{{$e.PascalName}}{{end}}: - err := fmt.Errorf("failed to reach {{range $i, $e := .Success}}{{if $i}} or {{end}}%s{{end}}, got %s: %s", - {{range $i, $e := .Success}}{{if $i}}, {{end}}{{$e.Entity.PascalName}}{{$e.PascalName}}{{end}}, status, statusMessage) - return nil, retries.Halt(err) - {{end}}default: - return nil, retries.Continues(statusMessage) - } - }) -} - -// {{.PascalName}} is a wrapper that calls [{{.Method.Service.PascalName}}API.{{.PascalName}}] and waits to reach {{range $i, $e := .Success}}{{if $i}} or {{end}}{{.Content}}{{end}} state. -type {{.PascalName}}[R any] struct { - Response *R{{range .Binding}} - {{.PollField.PascalName}} {{template "type" .PollField.Entity}} `json:"{{.PollField.Name}}"`{{end}} - Poll func(time.Duration, func(*{{.Poll.Response.PascalName}})) (*{{.Poll.Response.PascalName}}, error) - callback func(*{{.Poll.Response.PascalName}}) - timeout time.Duration -} - -// OnProgress invokes a callback every time it polls for the status update. -func (w *{{.PascalName}}[R]) OnProgress(callback func(*{{.Poll.Response.PascalName}})) *{{.PascalName}}[R] { - w.callback = callback - return w -} - -// Get the {{.Poll.Response.PascalName}} with the default timeout of {{.Timeout}} minutes. -func (w *{{.PascalName}}[R]) Get() (*{{.Poll.Response.PascalName}}, error) { - return w.Poll(w.timeout, w.callback) -} - -// Get the {{.Poll.Response.PascalName}} with custom timeout. -func (w *{{.PascalName}}[R]) GetWithTimeout(timeout time.Duration) (*{{.Poll.Response.PascalName}}, error) { - return w.Poll(timeout, w.callback) -} -{{end}} - -{{range .Methods}} -{{- $hasWaiter := and .Wait (and (not .IsCrudRead) (not (eq .SnakeName "get_run"))) -}} -{{if not .Pagination}} - -{{/* -Function with no waiter are ignored as the API struct automatically inherits -methods from the nested service interface. -*/}} -{{if $hasWaiter -}} -{{.Comment "// " 80}} -func (a *{{.Service.PascalName}}API) {{.PascalName}}(ctx context.Context{{if .Request}}, {{.Request.CamelName}} {{.Request.PascalName}}{{end}}) {{ template "wait-response-type" . }} { - {{if not .Response.IsEmpty }}{{.Response.CamelName}}, {{end}}err := a.{{.Service.CamelName}}Impl.{{.PascalName}}(ctx{{if .Request}}, {{.Request.CamelName}}{{end}}) - if err != nil { - return nil, err - } - return &{{.Wait.PascalName}}[{{with .Response}}{{if .IsEmpty}}struct{}{{else}}{{.PascalName}}{{end}}{{end}}]{ - {{with .Response}}{{if not .IsEmpty}}Response: {{.CamelName}},{{end}} - {{- end}}{{range .Wait.Binding}} - {{.PollField.PascalName}}: {{.Bind.Of.CamelName}}.{{.Bind.PascalName}},{{end}} - Poll: func(timeout time.Duration, callback func(*{{.Wait.Poll.Response.PascalName}})) (*{{.Wait.Poll.Response.PascalName}}, error) { - return a.{{.Wait.PascalName}}(ctx{{range .Wait.Binding}}, {{.Bind.Of.CamelName}}.{{.Bind.PascalName}}{{end}}, timeout, callback) - }, - timeout: {{.Wait.Timeout}}*time.Minute, - callback: nil, - }, nil -} -{{- end}} -{{end}} {{/* end of {{if not .Pagination}} */}} - -{{if $hasWaiter}} -// Calls [{{.Service.PascalName}}API.{{.PascalName}}] and waits to reach {{range $i, $e := .Wait.Success}}{{if $i}} or {{end}}{{.Content}}{{end}} state -// -// You can override the default timeout of {{.Wait.Timeout}} minutes by calling adding -// retries.Timeout[{{.Wait.Poll.Response.PascalName}}](60*time.Minute) functional option. -// -// Deprecated: use [{{.Service.PascalName}}API.{{.PascalName}}].Get() or [{{.Service.PascalName}}API.{{.Wait.PascalName}}] -func (a *{{.Service.PascalName}}API) {{.PascalName}}AndWait(ctx context.Context{{if .Request}}, {{.Request.CamelName}} {{.Request.PascalName}}{{end}}, options ...retries.Option[{{.Wait.Poll.Response.PascalName}}]) (*{{.Wait.Poll.Response.PascalName}}, error) { - wait, err := a.{{.PascalName}}(ctx{{if .Request}}, {{.Request.CamelName}}{{end}}) - if err != nil { - return nil, err - } - tmp := &retries.Info[{{.Wait.Poll.Response.PascalName}}]{Timeout: {{.Wait.Timeout}}*time.Minute} - for _, o := range options { - o(tmp) - } - wait.timeout = tmp.Timeout - wait.callback = func(info *{{.Wait.Poll.Response.PascalName}}) { - for _, o := range options { - o(&retries.Info[{{.Wait.Poll.Response.PascalName}}]{ - Info: info, - Timeout: wait.timeout, - }) - } - } - return wait.Get() -} -{{end}}{{if .Pagination}} -{{.Comment "// " 80}} -// -// This method is generated by Databricks SDK Code Generator. -func (a *{{.Service.PascalName}}API) {{.PascalName}}(ctx context.Context{{if .Request}}, request {{.Request.PascalName}}{{end}}) {{ template "paginated-return-type" . }} { - {{ if not .Request }}request := struct{}{}{{end}} - {{if eq .Pagination.Increment 1 -}} - request.{{.Pagination.Offset.PascalName}} = 1 // start iterating from the first page - {{else if contains .Path "/scim/v2/" -}} - request.{{.Pagination.Offset.PascalName}} = 1 // SCIM offset starts from 1 - {{end}}{{if and .Pagination.Limit (contains .Path "/scim/v2/") -}} - if request.{{.Pagination.Limit.PascalName}} == 0 { - request.{{.Pagination.Limit.PascalName}} = 100 - } - {{- end}} - getNextPage := func(ctx context.Context, req {{ template "paginated-request-type" . }}) (*{{ .Response.PascalName }}, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.{{.Service.CamelName}}Impl.{{.PascalName}}(ctx{{if .Request}}, req{{end}}) - } - getItems := func(resp *{{ .Response.PascalName }}) []{{ template "type" .Pagination.Entity }} { - return {{if .Pagination.Results}}resp.{{.Pagination.Results.PascalName}}{{else}}resp{{end}} - } - {{if .Pagination.MultiRequest -}} - getNextReq := func(resp *{{ .Response.PascalName }}) *{{.Request.PascalName}} { - {{if .Pagination.Token -}} - if resp.{{.Pagination.Token.Bind.PascalName}} == "" { - return nil - } - request.{{.Pagination.Token.PollField.PascalName}} = resp.{{.Pagination.Token.Bind.PascalName}} - {{- else if eq .Path "/api/2.1/clusters/events" -}} - if resp.NextPage == nil { - return nil - } - request = *resp.NextPage - {{ else -}} - if len(getItems(resp)) == 0 { - return nil - } - {{ if eq .Pagination.Increment 1 -}} - request.{{.Pagination.Offset.PascalName}} = resp.{{.Pagination.Offset.PascalName}} + 1 - {{- else -}} - request.{{.Pagination.Offset.PascalName}} = resp.{{.Pagination.Offset.PascalName}} + {{template "type" .Pagination.Offset.Entity}}(len(resp.{{.Pagination.Results.PascalName}})) - {{- end}}{{ end }} - return &request - } - {{- end}} - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - {{if .Pagination.MultiRequest}}getNextReq{{else}}nil{{end}}) - {{ if .NeedsOffsetDedupe -}} - dedupedIterator := listing.NewDedupeIterator[{{ template "type" .Pagination.Entity }}, {{ template "type" .IdentifierField.Entity }}]( - iterator, - func(item {{ template "type" .Pagination.Entity }}) {{ template "type" .IdentifierField.Entity }} { - return item{{ template "field-path" .IdFieldPath }} - }) - return dedupedIterator - {{- else -}} - return iterator - {{- end }} -} - -{{.Comment "// " 80}} -// -// This method is generated by Databricks SDK Code Generator. -func (a *{{.Service.PascalName}}API) {{.PascalName}}All(ctx context.Context{{if .Request}}, request {{.Request.PascalName}}{{end}}) ([]{{ template "type" .Pagination.Entity }}, error) { - iterator := a.{{.PascalName}}(ctx{{if .Request}}, request{{end}}) - {{ if .Pagination.Limit -}} - return listing.ToSliceN[{{ template "type" .Pagination.Entity }}, {{ template "type" .Pagination.Limit.Entity }}](ctx, iterator, request.{{.Pagination.Limit.PascalName}}) - {{ else -}} - return listing.ToSlice[{{ template "type" .Pagination.Entity }}](ctx, iterator) - {{- end }} -} -{{end}}{{if .NamedIdMap}} -// {{.NamedIdMap.PascalName}} calls [{{.Service.PascalName}}API.{{.PascalName}}{{if not .NamedIdMap.Direct}}All{{end -}}] and creates a map of results with [{{.NamedIdMap.Entity.PascalName}}]{{ template "field-path" .NamedIdMap.NamePath }} as key and [{{.NamedIdMap.Entity.PascalName}}]{{ template "field-path" .NamedIdMap.IdPath}} as value. -// -// Returns an error if there's more than one [{{.NamedIdMap.Entity.PascalName}}] with the same {{ template "field-path" .NamedIdMap.NamePath }}. -// -// Note: All [{{.NamedIdMap.Entity.PascalName}}] instances are loaded into memory before creating a map. -// -// This method is generated by Databricks SDK Code Generator. -func (a *{{.Service.PascalName}}API) {{.NamedIdMap.PascalName}}(ctx context.Context{{if .Request}}, request {{.Request.PascalName}}{{end}}) (map[string]{{template "type" .NamedIdMap.Id.Entity}}, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "name-to-id") - mapping := map[string]{{template "type" .NamedIdMap.Id.Entity}}{} - result, err := a.{{.PascalName}}{{if not .NamedIdMap.Direct}}All{{end}}(ctx{{if .Request}}, request{{end}}) - if err != nil { - return nil, err - } - for _, v := range result { - key := v{{ template "field-path" .NamedIdMap.NamePath }} - _, duplicate := mapping[key] - if duplicate { - return nil, fmt.Errorf("duplicate {{ template "field-path" .NamedIdMap.NamePath }}: %s", key) - } - mapping[key] = v{{ template "field-path" .NamedIdMap.IdPath }} - } - return mapping, nil -} -{{end}}{{if .GetByName}} -// GetBy{{range .NamedIdMap.NamePath}}{{.PascalName}}{{end}} calls [{{.Service.PascalName}}API.{{.NamedIdMap.Entity.PascalName}}{{range .NamedIdMap.NamePath}}{{.PascalName}}{{end}}To{{.NamedIdMap.Id.PascalName}}Map] and returns a single [{{.GetByName.PascalName}}]. -// -// Returns an error if there's more than one [{{.NamedIdMap.Entity.PascalName}}] with the same {{ template "field-path" .NamedIdMap.NamePath }}. -// -// Note: All [{{.NamedIdMap.Entity.PascalName}}] instances are loaded into memory before returning matching by name. -// -// This method is generated by Databricks SDK Code Generator. -func (a *{{.Service.PascalName}}API) GetBy{{range .NamedIdMap.NamePath}}{{.PascalName}}{{end}}(ctx context.Context, name string) (*{{template "type" .GetByName}}, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "get-by-name") - result, err := a.{{.PascalName}}{{if not .NamedIdMap.Direct}}All{{end}}(ctx{{if .Request}}, {{.Request.PascalName}}{}{{end}}) - if err != nil { - return nil, err - } - tmp := map[string][]{{.GetByName.PascalName}}{} - for _, v := range result { - key := v{{ template "field-path" .NamedIdMap.NamePath }} - tmp[key] = append(tmp[key], v) - } - alternatives, ok := tmp[name] - if !ok || len(alternatives) == 0 { - return nil, fmt.Errorf("{{.GetByName.PascalName}} named '%s' does not exist", name) - } - if len(alternatives) > 1 { - return nil, fmt.Errorf("there are %d instances of {{.GetByName.PascalName}} named '%s'", len(alternatives), name) - } - return &alternatives[0], nil -} -{{end}}{{if .Shortcut}} -{{.Comment "// " 80}} -func (a *{{.Service.PascalName}}API) {{.Shortcut.PascalName}}(ctx context.Context{{range .Shortcut.Params}}, {{.CamelName}} {{template "type" .Entity}}{{end}}) {{ template "response-type" . }} { - return a.{{.Service.CamelName}}Impl.{{.PascalName}}(ctx, {{.Request.PascalName}}{ - {{- range .Shortcut.Params}} - {{.PascalName}}: {{.CamelName}},{{end}} - }) -} -{{end}}{{if and .Shortcut $hasWaiter}} -func (a *{{.Service.PascalName}}API) {{.Shortcut.PascalName}}AndWait(ctx context.Context{{range .Shortcut.Params}}, {{.CamelName}} {{template "type" .Entity}}{{end}}, options ...retries.Option[{{.Wait.Poll.Response.PascalName}}]) (*{{.Wait.Poll.Response.PascalName}}, error) { - return a.{{.PascalName}}AndWait(ctx, {{.Request.PascalName}}{ - {{- range .Shortcut.Params}} - {{.PascalName}}: {{.CamelName}},{{end}} - }, options...) -} -{{end}} -{{end -}} -{{- end}} -{{- define "field-path" -}} - {{- range .}}.{{.PascalName}}{{end}} -{{- end -}} -{{- define "paginated-request-type" -}} - {{if .Request}}{{.Request.PascalName}}{{else}}struct{}{{end}} -{{- end -}} - -{{/* Note: we return the interface to make it possible to mock list responses more easily. */}} -{{- define "paginated-return-type" -}} - listing.Iterator[{{ template "type" .Pagination.Entity }}] -{{- end -}} - -{{- define "wait-response-type" -}} -(*{{.Wait.PascalName}}[{{with .Response}}{{if .IsEmpty}}struct{}{{else}}{{.PascalName}}{{end}}{{end}}], error) -{{- end -}} \ No newline at end of file diff --git a/.codegen/error_alias.go.tmpl b/.codegen/error_alias.go.tmpl deleted file mode 100644 index dde6db96..00000000 --- a/.codegen/error_alias.go.tmpl +++ /dev/null @@ -1,11 +0,0 @@ -// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. - -package databricks - -import "github.com/databricks/databricks-sdk-go/apierr" - -var ({{range .ExceptionTypes}} - // {{.Description}} - Err{{.PascalName}} = apierr.Err{{.PascalName}} -{{- end}} -) diff --git a/.codegen/error_mapping.go.tmpl b/.codegen/error_mapping.go.tmpl deleted file mode 100644 index c303e039..00000000 --- a/.codegen/error_mapping.go.tmpl +++ /dev/null @@ -1,25 +0,0 @@ -// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. - -package apierr - -import ( - "errors" -) - -var ({{range .ExceptionTypes}} - Err{{.PascalName}} = {{if .Inherit -}} - inheritErr(Err{{.Inherit.PascalName}}, - {{- else -}} - errors.New( - {{- end}}"{{.Description}}") -{{- end}} - - statusCodeMapping = map[int]error{ {{range .ErrorStatusCodeMapping}} - {{.StatusCode}}: Err{{.PascalName}},{{- end}} - } - - errorCodeMapping = map[string]error{ {{range .ErrorCodeMapping}} - "{{.ErrorCode}}": Err{{.PascalName}},{{- end}} - } -) - diff --git a/.codegen/error_overrides.go.tmpl b/.codegen/error_overrides.go.tmpl deleted file mode 100644 index ba587b07..00000000 --- a/.codegen/error_overrides.go.tmpl +++ /dev/null @@ -1,27 +0,0 @@ -// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. - -package apierr - -import ( - "regexp" -) - -var allOverrides = []errorOverride{ - {{ range .ErrorOverrides -}} - { - debugName: "{{.Name}}", - pathRegex: regexp.MustCompile(`{{.PathRegex}}`), - verb: "{{.Verb}}", - statusCodeMatcher: regexp.MustCompile(`{{.StatusCodeMatcher}}`), - errorCodeMatcher: regexp.MustCompile(`{{.ErrorCodeMatcher}}`), - messageMatcher: regexp.MustCompile(`{{.MessageMatcher}}`), - customError: Err{{.OverrideErrorCode.PascalName}}, - }, -{{- end }} -} - -var allTransientErrors = []*regexp.Regexp{ - {{ range .TransientErrorRegexes -}} - regexp.MustCompile(`{{.}}`), - {{ end }} -} \ No newline at end of file diff --git a/.codegen/examples_test.go.tmpl b/.codegen/examples_test.go.tmpl deleted file mode 100644 index 2d84966a..00000000 --- a/.codegen/examples_test.go.tmpl +++ /dev/null @@ -1,141 +0,0 @@ -// Code generated from Databricks SDK for Go integration tests by openapi.roll.TestRegenerateExamples. DO NOT EDIT. - -package {{.Package}}_test - -import ( - "context" - "fmt" - "math/rand" - "strings" - "time" - "os" - - "github.com/databricks/databricks-sdk-go" - "github.com/databricks/databricks-sdk-go/logger" - - {{range .Suite.ServiceToPackage}} - "github.com/databricks/databricks-sdk-go/service/{{.}}"{{end}} -) - -{{if eq (len .Samples) 0}}{{skipThisFile}}{{end}} - -{{range .Samples}}{{- $example := . -}} -func Example{{.Service.PascalName}}API_{{.Method.PascalName}}{{if eq .Method.PascalName "List"}}All{{end}}_{{.CamelName}}() { - ctx := context.Background() - {{if .IsAccount}}a{{else}}w{{end}}, err := databricks.New{{if .IsAccount}}Account{{else}}Workspace{{end}}Client() - if err != nil { - panic(err) - } - - {{range .Init}} - {{.CamelName}} := {{template "expr" .Value}} - {{end}} - - {{range .Calls}} - {{if .Service -}} - {{with .Assign}}{{.CamelName}}, err {{if not (eq .Name "_")}}:{{end}}= {{else}}err = {{end}}{{if $example.IsAccount}}a{{else}}w{{end}}.{{.Service.PascalName}}.{{.PascalName}}(ctx{{range .Args}}, {{template "expr" .}}{{end}}) - if err != nil { - panic(err) - } - {{with .Assign}}{{if not (eq .Name "_")}}logger.Infof(ctx, "found %v", {{.CamelName}}){{end}}{{end -}} - {{- else -}} - {{with .Assign}}{{.CamelName}} := {{end}}{{template "expr" .}} - {{- end}} - {{end}} - - {{with .Cleanup}} - // cleanup - {{range .}} - {{with .Assign}}{{.CamelName}}, {{end}}err = {{if $example.IsAccount}}a{{else}}w{{end}}.{{.Service.PascalName}}.{{.PascalName}}(ctx{{range .Args}}, {{template "expr" .}}{{end}}) - if err != nil { - panic(err) - }{{end}} - {{end}} -} - -{{end}} - -{{define "expr" -}} -{{- if eq .Type "binary" -}} - {{template "expr" .Left}} {{.Op}} {{template "expr" .Right}} -{{- else if eq .Type "index" -}} - {{template "expr" .Left}}[{{template "expr" .Right}}] -{{- else if eq .Type "boolean" -}} - {{if .Value}}true{{else}}false{{end}} -{{- else if eq .Type "heredoc" -}} - `{{.Value}}` -{{- else if eq .Type "literal" -}} - {{.Value}} -{{- else if eq .Type "enum" -}} - {{.Package}}.{{.Entity.PascalName}}{{.PascalName}} -{{- else if eq .Type "lookup" -}} - {{template "expr" .X}}.{{.Field.PascalName}} -{{- else if eq .Type "variable" -}} - {{.CamelName}} -{{- else if eq .Type "entity" -}} - {{if .IsPointer}}&{{end}}{{.Package}}.{{.PascalName}}{ {{range .FieldValues}} - {{.PascalName}}: {{template "expr" .Value}},{{end}} - } -{{- else if eq .Type "call" -}} - {{template "call" .}} -{{- else if eq .Type "map" -}} - map[{{.KeyType}}]{{.ValueType}}{ {{range .Pairs}}{{template "expr" .Key}}: {{template "expr" .Value}},{{end}} } -{{- else if eq .Type "array" -}} - []{{if .Package}}{{.Package}}.{{.PascalName}}{{else}}{{.Name}}{{end}}{ {{range $i, $x := .Values}}{{if $i}}, {{end}}{{template "expr" .}}{{end}} } -{{- else -}} - /* UNKNOWN: {{.Type}} */ -{{- end -}} -{{- end}} - -{{define "bypass-args" -}} -{{range $i, $x := .Args}}{{if $i}}, {{end}}{{template "expr" .}}{{end}} -{{- end}} - -{{define "call" -}} -{{- if eq .PascalName "GetEnvOrSkipTest" -}} -os.Getenv({{template "bypass-args" .}}) -{{- else if eq .PascalName "Dir" -}} -filepath.Dir({{template "bypass-args" .}}) -{{- else if eq .PascalName "Sprintf" -}} -fmt.Sprintf({{template "bypass-args" .}}) -{{- else if eq .PascalName "MustParseInt64" -}} -func(v string) int64 { - i, err := strconv.ParseInt(v, 10, 64) - if err != nil { - panic(fmt.Sprintf("`%s` is not int64: %s", v, err)) - } - return i -}({{template "bypass-args" .}}) -{{- else if eq .PascalName "RandomEmail" -}} -fmt.Sprintf("sdk-%x@example.com", time.Now().UnixNano()) -{{- else if eq .PascalName "RandomName" -}} -fmt.Sprintf("sdk-%x", time.Now().UnixNano()) -{{- else if eq .PascalName "RandomHex" -}} -fmt.Sprintf( "%x", time.Now().UnixNano()) -{{- else if eq .PascalName "EncodeToString" -}} -base64.StdEncoding.EncodeToString([]byte({{template "bypass-args" .}})) -{{- else if eq .PascalName "CanonicalHostName" -}} -w.Config.CanonicalHostName() -{{- else if eq .PascalName "SharedRunningCluster" -}} -func() string { - clusterId := os.Getenv("DATABRICKS_CLUSTER_ID") - err := w.Clusters.EnsureClusterIsRunning(ctx, clusterId) - if err != nil { - panic(err) - } - return clusterId -}() -{{- else if eq .PascalName "DltNotebook" -}} -"CREATE LIVE TABLE dlt_sample AS SELECT 1" -{{- else if eq .PascalName "MyNotebookPath" -}} -func() string { - me, err := w.CurrentUser.Me(ctx) - if err != nil { - panic(err) - } - return filepath.Join("/Users", me.UserName, fmt.Sprintf("sdk-%x", time.Now().UnixNano())) -}() -{{- else -}} -{{.PascalName}}({{range $i, $x := .Args}}{{if $i}}, {{end}}{{template "expr" .}}{{end}}) -{{- end -}} -{{- end}} \ No newline at end of file diff --git a/.codegen/impl.go.tmpl b/.codegen/impl.go.tmpl deleted file mode 100644 index 97986703..00000000 --- a/.codegen/impl.go.tmpl +++ /dev/null @@ -1,130 +0,0 @@ -// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. - -package {{.Name}} - -import ( - "context" - "errors" - "fmt" - goauth "golang.org/x/oauth2" - "time" - "io" - "net/http" - "github.com/databricks/databricks-sdk-go/client" - "github.com/databricks/databricks-sdk-go/httpclient" - {{range .ImportedPackages}} - "github.com/databricks/databricks-sdk-go/service/{{.}}"{{end}} -) -{{range .Services}} -// unexported type that holds implementations of just {{.Name}} API methods -type {{.CamelName}}Impl struct { - {{- if .IsDataPlane}} - dataPlaneService oauth2.DataPlaneService - controlPlane *{{.ControlPlaneService.PascalName}}API - {{end -}} - client *client.DatabricksClient -} - -{{range .Methods}} -{{if .Service.IsDataPlane}} -func (a *{{.Service.CamelName}}Impl) {{.PascalName}}(ctx context.Context{{if .Request}}, request {{.Request.PascalName}}{{end}}) {{ template "response-type" . }} { - getRequest := {{.Service.DataPlaneInfoMethod.Request.PascalName}}{ - {{- range .Service.DataPlaneInfoMethod.Request.Fields}} - {{.PascalName}}: request.{{.PascalName}}, - {{end}} - } - token, err := a.client.Config.GetToken() - if err != nil { - return nil, err - } - infoGetter := func() (*oauth2.DataPlaneInfo, error) { - response, err := a.controlPlane.{{.Service.DataPlaneInfoMethod.PascalName}}(ctx, getRequest) - if err != nil { - return nil, err - } - if response.{{(index .DataPlaneInfoFields 0).PascalName}} == nil { - return nil, errors.New("resource does not support direct Data Plane access") - } - return response{{range .DataPlaneInfoFields}}.{{.PascalName}}{{end}}, nil - } - refresh := func(info *oauth2.DataPlaneInfo) (*goauth.Token, error) { - return a.client.GetOAuthToken(ctx, info.AuthorizationDetails, token) - } - getParams := []string{ - {{- range .Service.DataPlaneInfoMethod.Request.Fields}} - request.{{.PascalName}}, - {{end -}} - } - endpointUrl, dataPlaneToken, err := a.dataPlaneService.GetDataPlaneDetails("{{.PascalName}}", getParams, refresh, infoGetter) - if err != nil { - return nil, err - } - {{ template "make-header" . }} - opts := []httpclient.DoOption{} - opts = append(opts, httpclient.WithRequestHeaders(headers)) - {{- template "response-var" . }} - {{if .Request}}opts = append(opts, httpclient.WithRequestData(request)){{end}} - {{if .Response}}opts = append(opts, httpclient.WithResponseUnmarshal(&{{.Response.CamelName}})){{end}} - opts = append(opts, httpclient.WithToken(dataPlaneToken)) - err = a.client.ApiClient().Do(ctx, http.Method{{.TitleVerb}}, endpointUrl, opts...) - return {{ template "response" . }} -} - -{{else}} -func (a *{{.Service.CamelName}}Impl) {{.PascalName}}(ctx context.Context{{if .Request}}, request {{.Request.PascalName}}{{end}}) {{ template "response-type" . }} { - {{- template "response-var" . }} - path := {{ template "path" . }} - {{ template "make-header" . }} - err := a.client.Do(ctx, http.Method{{.TitleVerb}}, path, headers, {{ template "request-param" . }}, {{if .Response}}&{{.Response.CamelName}}{{else}}nil{{end}}) - return {{ template "response" . }} -} -{{end}} -{{end -}} -{{end}} - -{{- define "path" -}} -{{- if .PathParts -}} - fmt.Sprintf("{{range .PathParts -}} - {{.Prefix}}{{if or .Field .IsAccountId}}%v{{end}}{{ end }}" - {{- range .PathParts -}} - {{- if and .Field .Field.IsPathMultiSegment}}, httpclient.EncodeMultiSegmentPathParameter(request.{{.Field.PascalName}}) - {{- else if .Field}}, request.{{.Field.PascalName}} - {{- else if .IsAccountId }}, a.client.ConfiguredAccountID() - {{- end -}} - {{- end -}}) -{{- else -}} - "{{.Path}}" -{{- end -}} -{{- end -}} - -{{ define "request-param" -}} - {{ if or (and .Request (or (eq .Verb "GET") (eq .Verb "DELETE") (eq .Verb "HEAD"))) (and .Operation .Operation.RequestBody) -}} - request{{ if .RequestBodyField }}.{{.RequestBodyField.PascalName}}{{end}} - {{- else }}nil - {{- end }} -{{- end }} - -{{ define "response-var" -}} -{{ if .Response }} - var {{ .Response.CamelName }} {{ template "type" .Response }} -{{- end }} -{{- end }} - -{{ define "response-type" -}} - {{ if not .Response.IsEmpty }}( - {{- if not .Response.ArrayValue }}*{{end}}{{ template "type" .Response }}, error) - {{- else }}error - {{- end }} -{{- end }} - -{{ define "response" -}} - {{ if not .Response.IsEmpty -}} - {{ if not .Response.ArrayValue }}&{{end}}{{.Response.CamelName}}, {{end}}err -{{- end }} - -{{ define "make-header" -}} - headers := make(map[string]string) - {{- range $k, $v := .FixedRequestHeaders }} - headers["{{$k}}"] = "{{$v}}" - {{- end }} -{{- end }} \ No newline at end of file diff --git a/.codegen/interface.go.tmpl b/.codegen/interface.go.tmpl deleted file mode 100644 index 06b2b11d..00000000 --- a/.codegen/interface.go.tmpl +++ /dev/null @@ -1,26 +0,0 @@ -// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. - -package {{.Name}} - -import ( - "context" - "io" - "github.com/databricks/databricks-sdk-go/retries" -) - -{{range .Services}} -{{.Comment "// " 80}} -type {{.PascalName}}Service interface { - {{range .Methods}} - {{.Comment " // " 80}} - {{- if .Pagination}} - // - // Use {{.PascalName}}All() to get all {{.Pagination.Entity.PascalName}} instances{{if .Pagination.MultiRequest}}, which will iterate over every result page.{{end}} - {{- end}} - {{.PascalName}}(ctx context.Context{{if .Request}}, request {{.Request.PascalName}}{{end}}) {{ template "response-type" . }} - {{end}} -} - - - -{{end}} diff --git a/.codegen/mock_account_client.go.tmpl b/.codegen/mock_account_client.go.tmpl deleted file mode 100644 index 64b79c2c..00000000 --- a/.codegen/mock_account_client.go.tmpl +++ /dev/null @@ -1,69 +0,0 @@ -// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. - -package mocks - -import ( - "fmt" - "github.com/databricks/databricks-sdk-go" - {{range .Packages}} - "github.com/databricks/databricks-sdk-go/experimental/mocks/service/{{.Name}}"{{end}} -) - -type MockAccountClient struct { - AccountClient *databricks.AccountClient -} - -// NewMockAccountClient creates new mocked version of Databricks SDK client for Accounts -// which can be used for testing. -func NewMockAccountClient(t interface { - mock.TestingT - Cleanup(func()) -}) (*MockAccountClient) { - cli := &MockAccountClient { - AccountClient: &databricks.AccountClient{ - Config: nil, - {{range .Services}}{{if and .IsAccounts (not .HasParent) }} - {{(.TrimPrefix "account").PascalName}}: {{ template "mock-interface-constructor" . }}(t), - {{- end}}{{end}} - }, - } - {{range .ServicesSortedByParent}} {{if and .IsAccounts }} - {{if .HasSubservices}} - mock{{.PascalName}}API := cli.GetMock{{.PascalName}}API() - {{end}} - {{if .HasParent}} - mock{{.PascalName}} := {{ template "mock-interface-constructor" . }}(t) - mock{{.ParentService.PascalName}}API.On("{{.PascalName}}").Return(mock{{.PascalName}}).Maybe() - {{end}} - {{end}} - {{end}} - return cli -} - -{{range .Services}}{{if and .IsAccounts .HasParent }} -func(m *MockAccountClient) GetMock{{.PascalName}}API() *{{ template "mock-interface-name" . }} { - api, ok := m.GetMock{{.ParentService.PascalName}}API().{{.PascalName}}().(*{{ template "mock-interface-name" . }}) - if !ok { - panic(fmt.Sprintf("expected {{.PascalName}} to be *{{ template "mock-interface-name" . }}, actual was %T", m.GetMock{{.ParentService.Name}}API().{{.PascalName}}())) - } - return api -} -{{end}}{{end}} - -{{range .Services}}{{if and .IsAccounts (not .HasParent) }} -func(m *MockAccountClient) GetMock{{.Name}}API() *{{ template "mock-interface-name" . }} { - api, ok := m.AccountClient.{{(.TrimPrefix "account").PascalName}}.(*{{ template "mock-interface-name" . }}) - if !ok { - panic(fmt.Sprintf("expected {{(.TrimPrefix "account").PascalName}} to be *{{ template "mock-interface-name" . }}, actual was %T", m.AccountClient.{{(.TrimPrefix "account").PascalName}})) - } - return api -} - -{{end}}{{end}} - -{{define "mock-interface-constructor" -}} - {{.Package.Name}}.NewMock{{.PascalName}}Interface -{{- end}} -{{ define "mock-interface-name" -}} - {{.Package.Name}}.Mock{{.PascalName}}Interface -{{- end}} \ No newline at end of file diff --git a/.codegen/mock_workspace_client.go.tmpl b/.codegen/mock_workspace_client.go.tmpl deleted file mode 100644 index b4810313..00000000 --- a/.codegen/mock_workspace_client.go.tmpl +++ /dev/null @@ -1,63 +0,0 @@ -// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. - -package mocks - -import ( - "fmt" - "github.com/databricks/databricks-sdk-go" - {{range .Packages}} - "github.com/databricks/databricks-sdk-go/experimental/mocks/service/{{.Name}}"{{end}} -) - -type MockWorkspaceClient struct { - WorkspaceClient *databricks.WorkspaceClient -} - -// NewMockWorkspaceClient creates new mocked version of Databricks SDK client for Workspaces -// which can be used for testing. -func NewMockWorkspaceClient(t interface { - mock.TestingT - Cleanup(func()) -}) (*MockWorkspaceClient) { - cli := &MockWorkspaceClient{ - WorkspaceClient: &databricks.WorkspaceClient{ - Config: nil, - {{range .Services}}{{if and (not .IsAccounts) (not .HasParent) }} - {{.Name}}: {{ template "mock-interface-constructor" . }}(t), - {{- end}}{{end}} - }, - } - {{range .ServicesSortedByParent}} {{if and (not .IsAccounts) }} - {{if .HasSubservices}} - mock{{.CamelName}}API := cli.GetMock{{.PascalName}}API() - {{end}} - {{if .HasParent}} - mock{{.CamelName}} := {{ template "mock-interface-constructor" . }}(t) - mock{{.ParentService.CamelName}}API.On("{{.PascalName}}").Return(mock{{.CamelName}}).Maybe() - {{end}} - {{end}} - {{end}} - return cli -} - -{{range .Services}}{{if and (not .IsAccounts) .HasParent }} -func(m *MockWorkspaceClient) GetMock{{.PascalName}}API() *{{ template "mock-interface-name" . }} { - api, ok := m.GetMock{{.ParentService.Name}}API().{{.PascalName}}().(*{{ template "mock-interface-name" . }}) - if !ok { - panic(fmt.Sprintf("expected {{.PascalName}} to be *{{ template "mock-interface-name" . }}, actual was %T", m.GetMock{{.ParentService.Name}}API().{{.PascalName}}())) - } - return api -} - -{{end}}{{end}} - -{{range .Services}}{{if and (not .IsAccounts) (not .HasParent) }} -func(m *MockWorkspaceClient) GetMock{{.Name}}API() *{{ template "mock-interface-name" . }} { - api, ok := m.WorkspaceClient.{{.Name}}.(*{{ template "mock-interface-name" . }}) - if !ok { - panic(fmt.Sprintf("expected {{.Name}} to be *{{ template "mock-interface-name" . }}, actual was %T", m.WorkspaceClient.{{.Name}})) - } - return api -} - -{{end}}{{end}} \ No newline at end of file diff --git a/.codegen/model.go.tmpl b/.codegen/model.go.tmpl deleted file mode 100644 index 473b082a..00000000 --- a/.codegen/model.go.tmpl +++ /dev/null @@ -1,86 +0,0 @@ -// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. - -package {{.Name}} - -import ( - {{range .ImportedPackages}} - "github.com/databricks/databricks-sdk-go/service/{{.}}"{{end}} - "io" - "github.com/databricks/databricks-sdk-go/marshal" -) -{{range .Types}} -{{- if or .Fields .IsEmpty}} -{{.Comment "// " 80}} -type {{.PascalName}} struct { - {{- range .Fields}} - {{.Comment " // " 80}} - {{.PascalName}} {{if .IsOptionalObject}}*{{end}}{{template "type" .Entity}} `{{template "field-tag" . }}`{{end}} - - {{if .ShouldIncludeForceSendFields}} ForceSendFields []string `json:"-"` {{end}} -} - -{{if .ShouldIncludeForceSendFields}} -func (s *{{.PascalName}}) UnmarshalJSON(b []byte) error { - return marshal.Unmarshal(b, s) -} - -func (s {{.PascalName}}) MarshalJSON() ([]byte, error) { - return marshal.Marshal(s) -} -{{end}} -{{else if .MapValue}}{{.Comment "// " 80}} -type {{.PascalName}} {{template "type" .}} -{{else if .Enum}}{{.Comment "// " 80}} -type {{.PascalName}} string -{{range .Enum }} -{{.Comment "// " 80}} -const {{.Entity.PascalName}}{{.PascalName}} {{.Entity.PascalName}} = `{{.Content}}`{{end}} - -// String representation for [fmt.Print] -func (f *{{.PascalName}}) String() string { - return string(*f) -} - -// Set raw string value and validate it against allowed values -func (f *{{.PascalName}}) Set(v string) error { - switch v { - case {{range $i, $e := .Enum }}{{if $i}}, {{end}}`{{.Content}}`{{end}}: - *f = {{.PascalName}}(v) - return nil - default: - return fmt.Errorf(`value "%s" is not one of {{range $i, $e := .Enum }}{{if $i}}, {{end}}"{{.Content}}"{{end}}`, v) - } -} - -// Type always returns {{.PascalName}} to satisfy [pflag.Value] interface -func (f *{{.PascalName}}) Type() string { - return "{{.PascalName}}" -} -{{end}} -{{end}} - -{{- define "field-tag" -}} - {{if .IsJson}}json:"{{.Name}}{{if not .Required}},omitempty{{end}}"{{else}}json:"-"{{end -}} - {{if .IsPath}} url:"-"{{end -}} - {{if .IsHeader}} url:"-" header:"{{.Name}}{{if not .Required}},omitempty{{end}}"{{end -}} - {{if .IsQuery}} url:"{{.Name}}{{if not .Required}},omitempty{{end}}"{{end -}} -{{- end -}} - -{{- define "type" -}} - {{- if not . }}any /* ERROR */ - {{- else if .IsExternal }}{{.Package.Name}}.{{.PascalName}} - {{- else if .IsAny}}any - {{- else if .IsEmpty}}{{.PascalName}} - {{- else if .IsString}}string - {{- else if .IsBool}}bool - {{- else if .IsInt64}}int64 - {{- else if .IsFloat64}}float64 - {{- else if .IsInt}}int - {{- else if .IsByteStream}}io.ReadCloser - {{- else if .ArrayValue }}[]{{template "type" .ArrayValue}} - {{- else if .MapValue }}map[string]{{template "type" .MapValue}} - {{- else if .IsObject }}{{.PascalName}} - {{- else if .Enum }}{{.PascalName}} - {{- else}}any /* MISSING TYPE */ - {{- end -}} -{{- end -}} diff --git a/.codegen/service-pkg.go.tmpl b/.codegen/service-pkg.go.tmpl deleted file mode 100644 index 80b5cf29..00000000 --- a/.codegen/service-pkg.go.tmpl +++ /dev/null @@ -1,20 +0,0 @@ -// Databricks SDK for Go APIs -// -//{{range .Services}}{{if and .Description }} - [{{.Package.Name}}.{{.PascalName}}API]: {{.Summary}} -// -//{{end}}{{end}} -package service - -import ( -{{range .Packages}}"github.com/databricks/databricks-sdk-go/service/{{.Name}}" -{{end}} -) - -// adding this trick for godoc to use it as relative import, so that we have -// a clear index of all services in this package at Go package docs: -// https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service -// See: https://pkg.go.dev/golang.org/x/tools/internal/imports#ImportPathToAssumedName -var ( -{{range .Services}} _ *{{.Package.Name}}.{{.PascalName}}API = nil -{{end}} -) \ No newline at end of file diff --git a/.codegen/workspaces.go.tmpl b/.codegen/workspaces.go.tmpl deleted file mode 100644 index 444a2730..00000000 --- a/.codegen/workspaces.go.tmpl +++ /dev/null @@ -1,69 +0,0 @@ -// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. - -package databricks - -import ( - "context" - - "github.com/databricks/databricks-sdk-go/client" - {{range .Packages}} - "github.com/databricks/databricks-sdk-go/service/{{.Name}}"{{end}} -) - -type WorkspaceClient struct { - Config *config.Config - apiClient *httpclient.ApiClient - - {{range .Services}}{{if and (not .IsAccounts) (not .HasParent) }} - {{.Comment " // " 80}} - {{.PascalName}} {{.Package.Name}}.{{.PascalName}}Interface - {{end}}{{end}} -} - -var ErrNotWorkspaceClient = errors.New("invalid Databricks Workspace configuration") - -// NewWorkspaceClient creates new Databricks SDK client for Workspaces or -// returns error in case configuration is wrong -func NewWorkspaceClient(c ...*Config) (*WorkspaceClient, error) { - var cfg *config.Config - if len(c) == 1 { - // first config - cfg = (*config.Config)(c[0]) - } else { - // default config - cfg = &config.Config{} - } - err := cfg.EnsureResolved() - if err != nil { - return nil, err - } - if cfg.IsAccountClient() { - return nil, ErrNotWorkspaceClient - } - apiClient, err := cfg.NewApiClient() - if err != nil { - return nil, err - } - databricksClient, err := client.NewWithClient(cfg, apiClient) - if err != nil { - return nil, err - } - {{range .Services}}{{if and (not .IsAccounts) (not .HasParent) .HasDataPlaneAPI}} - {{.CamelName}} := {{.Package.Name}}.New{{.PascalName}}(databricksClient) - {{- end}}{{end}} - return &WorkspaceClient{ - Config: cfg, - apiClient: apiClient, - {{range .Services}} - {{- if and (not .IsAccounts) (not .HasParent)}} - {{- if .HasDataPlaneAPI}} - {{.Name}}: {{.CamelName}}, - {{- else if .IsDataPlane}} - {{.Name}}: {{.Package.Name}}.New{{.PascalName}}(databricksClient, {{.ControlPlaneService.CamelName}}), - {{- else }} - {{.Name}}: {{.Package.Name}}.New{{.PascalName}}(databricksClient), - {{- end -}} - {{- end -}} - {{end}} - }, nil -}