diff --git a/README.md b/README.md index de538ecf2..f7214280c 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ During the Beta period, you must clone and then reference this repository locall ) func init() { - databricks.WithProduct("your-product", "0.0.1") + databricks.WithProduct("awesome-product", "0.0.1") } func main() { @@ -191,7 +191,7 @@ import ( ) func init() { - databricks.WithProduct("your-product", "0.0.1") + databricks.WithProduct("awesome-product", "0.0.1") } func main() { @@ -274,7 +274,7 @@ import ( ) func init() { - databricks.WithProduct("your-product", "0.0.1") + databricks.WithProduct("awesome-product", "0.0.1") } func main() { @@ -357,7 +357,7 @@ import ( ) func init() { - databricks.WithProduct("your-product", "0.0.1") + databricks.WithProduct("awesome-product", "0.0.1") } func main() { @@ -426,7 +426,7 @@ import ( ) func init() { - databricks.WithProduct("your-product", "0.0.1") + databricks.WithProduct("awesome-product", "0.0.1") } func main() { @@ -470,7 +470,7 @@ import ( ) func init() { - databricks.WithProduct("your-product", "0.0.1") + databricks.WithProduct("awesome-product", "0.0.1") } func main() { diff --git a/accounts/client.go b/accounts/client.go index fa31e576d..b219ad78b 100644 --- a/accounts/client.go +++ b/accounts/client.go @@ -1,8 +1,11 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + package accounts import ( "github.com/databricks/databricks-sdk-go/databricks" "github.com/databricks/databricks-sdk-go/databricks/client" + "github.com/databricks/databricks-sdk-go/service/billing" "github.com/databricks/databricks-sdk-go/service/deployment" "github.com/databricks/databricks-sdk-go/service/permissions" @@ -10,21 +13,192 @@ import ( ) type AccountsClient struct { - Config *databricks.Config - Budgets billing.BudgetsService - Credentials deployment.CredentialConfigurationsService - Groups scim.AccountGroupsService - CustomerManagedKeys deployment.KeyConfigurationsService - LogDelivery billing.LogDeliveryService - Networks deployment.NetworkConfigurationsService - PrivateAccessSettings deployment.PrivateAccessSettingsService - ServicePrincipals scim.AccountServicePrincipalsService - StorageConfigurations deployment.StorageConfigurationsService - UsageDownload billing.BillableUsageDownloadService - Users scim.AccountUsersService - VpcEndpoints deployment.VpcEndpointsService - WorkspaceAssignment permissions.WorkspaceAssignmentService - Workspaces deployment.WorkspacesService + Config *databricks.Config + + // This API allows you to download billable usage logs for the specified + // account and date range. This feature works with all account types. + BillableUsageDownload *billing.BillableUsageDownloadAPI + + // These APIs manage budget configuration including notifications for + // exceeding a budget for a period. They can also retrieve the status of + // each budget. + Budgets *billing.BudgetsAPI + + // These APIs manage credential configurations for this workspace. + // Databricks needs access to a cross-account service IAM role in your AWS + // account so that Databricks can deploy clusters in the appropriate VPC for + // the new workspace. A credential configuration encapsulates this role + // information, and its ID is used when creating a new workspace. + CredentialConfigurations *deployment.CredentialConfigurationsAPI + + // Groups simplify identity management, making it easier to assign access to + // Databricks Account, data, and other securable objects. + // + // It is best practice to assign access to workspaces and access-control + // policies in Unity Catalog to groups, instead of to users individually. + // All Databricks Account identities can be assigned as members of groups, + // and members inherit permissions that are assigned to their group. + Groups *scim.AccountGroupsAPI + + // These APIs manage encryption key configurations for this workspace + // (optional). A key configuration encapsulates the AWS KMS key information + // and some information about how the key configuration can be used. There + // are two possible uses for key configurations: + // + // * Managed services: A key configuration can be used to encrypt a + // workspace's notebook and secret data in the control plane, as well as + // Databricks SQL queries and query history. * Storage: A key configuration + // can be used to encrypt a workspace's DBFS and EBS data in the data plane. + // + // In both of these cases, the key configuration's ID is used when creating + // a new workspace. This Preview feature is available if your account is on + // the E2 version of the platform. Updating a running workspace with + // workspace storage encryption requires that the workspace is on the E2 + // version of the platform. If you have an older workspace, it might not be + // on the E2 version of the platform. If you are not sure, contact your + // Databricks reprsentative. + KeyConfigurations *deployment.KeyConfigurationsAPI + + // These APIs manage log delivery configurations for this account. The two + // supported log types for this API are _billable usage logs_ and _audit + // logs_. This feature is in Public Preview. This feature works with all + // account ID types. + // + // Log delivery works with all account types. However, if your account is on + // the E2 version of the platform or on a select custom plan that allows + // multiple workspaces per account, you can optionally configure different + // storage destinations for each workspace. Log delivery status is also + // provided to know the latest status of log delivery attempts. The + // high-level flow of billable usage delivery: + // + // 1. **Create storage**: In AWS, [create a new AWS S3 + // bucket](https://docs.databricks.com/administration-guide/account-api/aws-storage.html) + // with a specific bucket policy. Using Databricks APIs, call the Account + // API to create a [storage configuration + // object](#operation/create-storage-config) that uses the bucket name. 2. + // **Create credentials**: In AWS, create the appropriate AWS IAM role. For + // full details, including the required IAM role policies and trust + // relationship, see [Billable usage log + // delivery](https://docs.databricks.com/administration-guide/account-settings/billable-usage-delivery.html). + // Using Databricks APIs, call the Account API to create a [credential + // configuration object](#operation/create-credential-config) that uses the + // IAM role's ARN. 3. **Create log delivery configuration**: Using + // Databricks APIs, call the Account API to [create a log delivery + // configuration](#operation/create-log-delivery-config) that uses the + // credential and storage configuration objects from previous steps. You can + // specify if the logs should include all events of that log type in your + // account (_Account level_ delivery) or only events for a specific set of + // workspaces (_workspace level_ delivery). Account level log delivery + // applies to all current and future workspaces plus account level logs, + // while workspace level log delivery solely delivers logs related to the + // specified workspaces. You can create multiple types of delivery + // configurations per account. + // + // For billable usage delivery: * For more information about billable usage + // logs, see [Billable usage log + // delivery](https://docs.databricks.com/administration-guide/account-settings/billable-usage-delivery.html). + // For the CSV schema, see the [Usage + // page](https://docs.databricks.com/administration-guide/account-settings/usage.html). + // * The delivery location is `//billable-usage/csv/`, + // where `` is the name of the optional delivery path prefix you set + // up during log delivery configuration. Files are named + // `workspaceId=-usageMonth=.csv`. * All billable usage + // logs apply to specific workspaces (_workspace level_ logs). You can + // aggregate usage for your entire account by creating an _account level_ + // delivery configuration that delivers logs for all current and future + // workspaces in your account. * The files are delivered daily by + // overwriting the month's CSV file for each workspace. + // + // For audit log delivery: * For more information about about audit log + // delivery, see [Audit log + // delivery](https://docs.databricks.com/administration-guide/account-settings/audit-logs.html), + // which includes information about the used JSON schema. * The delivery + // location is + // `//workspaceId=/date=/auditlogs_.json`. + // Files may get overwritten with the same content multiple times to achieve + // exactly-once delivery. * If the audit log delivery configuration included + // specific workspace IDs, only _workspace-level_ audit logs for those + // workspaces are delivered. If the log delivery configuration applies to + // the entire account (_account level_ delivery configuration), the audit + // log delivery includes workspace-level audit logs for all workspaces in + // the account as well as account-level audit logs. See [Audit log + // delivery](https://docs.databricks.com/administration-guide/account-settings/audit-logs.html) + // for details. * Auditable events are typically available in logs within 15 + // minutes. + LogDelivery *billing.LogDeliveryAPI + + // These APIs manage network configurations for customer-managed VPCs + // (optional). A network configuration encapsulates the IDs for AWS VPCs, + // subnets, and security groups. Its ID is used when creating a new + // workspace if you use customer-managed VPCs. + NetworkConfigurations *deployment.NetworkConfigurationsAPI + + // These APIs manage private access settings for this account. A private + // access settings object specifies how your workspace is accessed using AWS + // PrivateLink. Each workspace that has any PrivateLink connections must + // include the ID for a private access settings object is in its workspace + // configuration object. Your account must be enabled for PrivateLink to use + // these APIs. Before configuring PrivateLink, it is important to read the + // [Databricks article about + // PrivateLink](https://docs.databricks.com/administration-guide/cloud-configurations/aws/privatelink.html). + PrivateAccessSettings *deployment.PrivateAccessSettingsAPI + + // Identities for use with jobs, automated tools, and systems such as + // scripts, apps, and CI/CD platforms. Databricks recommends creating + // service principals to run production jobs or modify production data. If + // all processes that act on production data run with service principals, + // interactive users do not need any write, delete, or modify privileges in + // production. This eliminates the risk of a user overwriting production + // data by accident. + ServicePrincipals *scim.AccountServicePrincipalsAPI + + // These APIs manage storage configurations for this workspace. A root + // storage S3 bucket in your account is required to store objects like + // cluster logs, notebook revisions, and job results. You can also use the + // root storage S3 bucket for storage of non-production DBFS data. A storage + // configuration encapsulates this bucket information, and its ID is used + // when creating a new workspace. + StorageConfigurations *deployment.StorageConfigurationsAPI + + // User identities recognized by Databricks and represented by email + // addresses. + // + // Databricks recommends using SCIM provisioning to sync users and groups + // automatically from your identity provider to your Databricks Account. + // SCIM streamlines onboarding a new employee or team by using your identity + // provider to create users and groups in Databricks Account and give them + // the proper level of access. When a user leaves your organization or no + // longer needs access to Databricks Account, admins can terminate the user + // in your identity provider and that user’s account will also be removed + // from Databricks Account. This ensures a consistent offboarding process + // and prevents unauthorized users from accessing sensitive data. + Users *scim.AccountUsersAPI + + // These APIs manage VPC endpoint configurations for this account. This + // object registers an AWS VPC endpoint in your Databricks account so your + // workspace can use it with AWS PrivateLink. Your VPC endpoint connects to + // one of two VPC endpoint services -- one for workspace (both for front-end + // connection and for back-end connection to REST APIs) and one for the + // back-end secure cluster connectivity relay from the data plane. Your + // account must be enabled for PrivateLink to use these APIs. Before + // configuring PrivateLink, it is important to read the [Databricks article + // about + // PrivateLink](https://docs.databricks.com/administration-guide/cloud-configurations/aws/privatelink.html). + VpcEndpoints *deployment.VpcEndpointsAPI + + // Databricks Workspace Assignment REST API + WorkspaceAssignment *permissions.WorkspaceAssignmentAPI + + // These APIs manage workspaces for this account. A Databricks workspace is + // an environment for accessing all of your Databricks assets. The workspace + // organizes objects (notebooks, libraries, and experiments) into folders, + // and provides access to data and computational resources such as clusters + // and jobs. + // + // These endpoints are available if your account is on the E2 version of the + // platform or on a select custom plan that allows multiple workspaces per + // account. + Workspaces *deployment.WorkspacesAPI } func New(c ...*databricks.Config) *AccountsClient { @@ -48,20 +222,21 @@ func New(c ...*databricks.Config) *AccountsClient { panic(err) } return &AccountsClient{ - Config: cfg, - Budgets: billing.NewBudgets(apiClient), - Credentials: deployment.NewCredentialConfigurations(apiClient), - CustomerManagedKeys: deployment.NewKeyConfigurations(apiClient), - Groups: scim.NewAccountGroups(apiClient), - LogDelivery: billing.NewLogDelivery(apiClient), - Networks: deployment.NewNetworkConfigurations(apiClient), - PrivateAccessSettings: deployment.NewPrivateAccessSettings(apiClient), - ServicePrincipals: scim.NewAccountServicePrincipals(apiClient), - StorageConfigurations: deployment.NewStorageConfigurations(apiClient), - UsageDownload: billing.NewBillableUsageDownload(apiClient), - Users: scim.NewAccountUsers(apiClient), - VpcEndpoints: deployment.NewVpcEndpoints(apiClient), - WorkspaceAssignment: permissions.NewWorkspaceAssignment(apiClient), - Workspaces: deployment.NewWorkspaces(apiClient), + Config: cfg, + + BillableUsageDownload: billing.NewBillableUsageDownload(apiClient), + Budgets: billing.NewBudgets(apiClient), + CredentialConfigurations: deployment.NewCredentialConfigurations(apiClient), + Groups: scim.NewAccountGroups(apiClient), + KeyConfigurations: deployment.NewKeyConfigurations(apiClient), + LogDelivery: billing.NewLogDelivery(apiClient), + NetworkConfigurations: deployment.NewNetworkConfigurations(apiClient), + PrivateAccessSettings: deployment.NewPrivateAccessSettings(apiClient), + ServicePrincipals: scim.NewAccountServicePrincipals(apiClient), + StorageConfigurations: deployment.NewStorageConfigurations(apiClient), + Users: scim.NewAccountUsers(apiClient), + VpcEndpoints: deployment.NewVpcEndpoints(apiClient), + WorkspaceAssignment: permissions.NewWorkspaceAssignment(apiClient), + Workspaces: deployment.NewWorkspaces(apiClient), } } diff --git a/databricks/mock.go b/databricks/mock.go index 8b4cdfc13..bd087ab64 100644 --- a/databricks/mock.go +++ b/databricks/mock.go @@ -3,6 +3,11 @@ package databricks import "net/http" func NewMockConfig(auth func(r *http.Request) error) *Config { + if auth == nil { + auth = func(r *http.Request) error { + return nil + } + } return &Config{ AuthType: "mock", auth: auth, diff --git a/databricks/openapi/code/load.go b/databricks/openapi/code/load.go index bc25848b6..9b5aa9b5b 100644 --- a/databricks/openapi/code/load.go +++ b/databricks/openapi/code/load.go @@ -3,13 +3,14 @@ package code import ( "fmt" "os" + "strings" "github.com/databricks/databricks-sdk-go/databricks/openapi" "golang.org/x/exp/slices" ) type Batch struct { - Packages map[string]*Package + packages map[string]*Package } // NewFromFile loads OpenAPI specification from file @@ -24,13 +25,13 @@ func NewFromFile(name string, includeTags []string) (*Batch, error) { return nil, fmt.Errorf("spec from %s: %w", name, err) } batch := Batch{ - Packages: map[string]*Package{}, + packages: map[string]*Package{}, } for _, tag := range spec.Tags { if len(includeTags) != 0 && !slices.Contains(includeTags, tag.Name) { continue } - pkg, ok := batch.Packages[tag.Package] + pkg, ok := batch.packages[tag.Package] if !ok { pkg = &Package{ Named: Named{tag.Package, tag.Description}, @@ -38,7 +39,7 @@ func NewFromFile(name string, includeTags []string) (*Batch, error) { services: map[string]*Service{}, types: map[string]*Entity{}, } - batch.Packages[tag.Package] = pkg + batch.packages[tag.Package] = pkg } err := pkg.Load(spec, &tag) if err != nil { @@ -48,12 +49,17 @@ func NewFromFile(name string, includeTags []string) (*Batch, error) { return &batch, nil } -// Pkgs returns sorted slice of packages -func (b *Batch) Pkgs() (pkgs []*Package) { - for _, pkg := range b.Packages { +func (b *Batch) FullName() string { + return "all" +} + +// Packages returns sorted slice of packages +func (b *Batch) Packages() (pkgs []*Package) { + for _, pkg := range b.packages { pkgs = append(pkgs, pkg) } - // add some determinism into code generation + // add some determinism into code generation for globally stable order in + // files like for workspaces/accounts clinets. slices.SortFunc(pkgs, func(a, b *Package) bool { return a.FullName() < b.FullName() }) @@ -62,10 +68,11 @@ func (b *Batch) Pkgs() (pkgs []*Package) { // Pkgs returns sorted slice of packages func (b *Batch) Types() (types []*Entity) { - for _, pkg := range b.Packages { + for _, pkg := range b.packages { types = append(types, pkg.Types()...) } - // add some determinism into code generation + // add some determinism into code generation for globally stable order in + // files like api.go and/or {{.Package.Name}}.py and clients. slices.SortFunc(types, func(a, b *Entity) bool { return a.FullName() < b.FullName() }) @@ -74,12 +81,33 @@ func (b *Batch) Types() (types []*Entity) { // Pkgs returns sorted slice of packages func (b *Batch) Services() (services []*Service) { - for _, pkg := range b.Packages { + for _, pkg := range b.packages { services = append(services, pkg.Services()...) } - // add some determinism into code generation + // we'll have more and more account level equivalents of APIs that are + // currently workspace-level. In the AccountsClient we're striping + // the `Account` prefix, so that naming and ordering is more logical. + // this requires us to do the proper sorting of services. E.g. + // + // - Groups: scim.NewAccountGroups(apiClient), + // - ServicePrincipals: scim.NewAccountServicePrincipals(apiClient), + // - Users: scim.NewAccountUsers(apiClient), + // + // more services may follow this pattern in the future. + norm := func(name string) string { + if !strings.HasPrefix(name, "Account") { + return name + } + // sorting-only rename: AccountGroups -> GroupsAccount + return name[7:] + "Account" + } + // add some determinism into code generation for globally stable order in + // files like api.go and/or {{.Package.Name}}.py and clients. slices.SortFunc(services, func(a, b *Service) bool { - return a.FullName() < b.FullName() + // not using .FullName() here, as in "batch" context + // services have to be sorted globally, not only within a package. + // alternatively we may think on adding .ReverseFullName() to sort on. + return norm(a.Name) < norm(b.Name) }) return services } diff --git a/databricks/openapi/code/load_test.go b/databricks/openapi/code/load_test.go index 77e952e50..2c0b98126 100644 --- a/databricks/openapi/code/load_test.go +++ b/databricks/openapi/code/load_test.go @@ -15,10 +15,10 @@ func TestBasic(t *testing.T) { batch, err := NewFromFile("../testdata/spec.json", []string{}) require.NoError(t, err) - require.Len(t, batch.Pkgs(), 1) + require.Len(t, batch.Packages(), 1) require.Len(t, batch.Services(), 1) require.Len(t, batch.Types(), 14) - commands, ok := batch.Packages["commands"] + commands, ok := batch.packages["commands"] require.True(t, ok) assert.Equal(t, "commands", commands.FullName()) @@ -73,7 +73,7 @@ func TestMethodsReport(t *testing.T) { "universe/bazel-bin/openapi/all-internal.json"), []string{}) assert.NoError(t, err) - for _, pkg := range batch.Pkgs() { + for _, pkg := range batch.Packages() { for _, svc := range pkg.Services() { singleService := strings.EqualFold(pkg.PascalName(), svc.PascalName()) serviceSingularKebab := svc.Singular().KebabName() @@ -107,5 +107,5 @@ func TestMethodsReport(t *testing.T) { } } - assert.Equal(t, len(batch.Packages), 1) + assert.Equal(t, len(batch.packages), 1) } diff --git a/databricks/openapi/code/tmpl_util_funcs.go b/databricks/openapi/code/tmpl_util_funcs.go index ec79d820d..16692f7a8 100644 --- a/databricks/openapi/code/tmpl_util_funcs.go +++ b/databricks/openapi/code/tmpl_util_funcs.go @@ -2,6 +2,7 @@ package code import ( "reflect" + "strings" "text/template" ) @@ -9,4 +10,7 @@ var HelperFuncs = template.FuncMap{ "notLast": func(idx int, a interface{}) bool { return idx+1 != reflect.ValueOf(a).Len() }, + "trim_prefix": func(left, right string) string { + return strings.TrimPrefix(left, right) + }, } diff --git a/databricks/openapi/gen/main.go b/databricks/openapi/gen/main.go index 187fd4b67..f069a21f5 100644 --- a/databricks/openapi/gen/main.go +++ b/databricks/openapi/gen/main.go @@ -79,13 +79,22 @@ type Render struct { Packages map[string]string `json:"packages,omitempty"` Types map[string]string `json:"types,omitempty"` Services map[string]string `json:"services,omitempty"` + Batch map[string]string `json:"batch,omitempty"` IncludeTags []string `json:"includeTags,omitempty"` } func (r *Render) Run() error { var filenames []string + if r.Batch != nil { + pass := newPass([]named{r.batch}, r.Batch) + err := pass.Run() + if err != nil { + return fmt.Errorf("batch: %w", err) + } + filenames = append(filenames, pass.filenames...) + } if r.Packages != nil { - pass := newPass(r.batch.Pkgs(), r.Packages) + pass := newPass(r.batch.Packages(), r.Packages) err := pass.Run() if err != nil { return fmt.Errorf("packages: %w", err) diff --git a/examples/mocking/.gitignore b/examples/mocking/.gitignore new file mode 100644 index 000000000..8915b6bcf --- /dev/null +++ b/examples/mocking/.gitignore @@ -0,0 +1,4 @@ +go.sum +vendor +mocks +mocks/* \ No newline at end of file diff --git a/examples/mocking/README.md b/examples/mocking/README.md new file mode 100644 index 000000000..aee79709c --- /dev/null +++ b/examples/mocking/README.md @@ -0,0 +1,56 @@ +# Interoperability with `gomock` + +When developing large applications, you find yourself in need of mocking APIs. For Go, there's [`gomock`](https://github.com/golang/mock) framework for code generating testing mocks. In this small example, we'll show how to use `gomock` with Databricks SDK for Go. + +Please read through [`dbfs_test.go`](dbfs_test.go) test example. + +## Declaring which mocks to generate + +```go +//go:generate go run github.com/golang/mock/mockgen@latest -package=mocks -destination=mocks/dbfs.go github.com/databricks/databricks-sdk-go/service/dbfs DbfsService +``` + +* `go run github.com/golang/mock/mockgen@latest` downloads and executes the latest version of `mockgen` command +* `-package=mocks` instructs to generate mocks in the `mocks` package +* `-destination=mocks/dbfs.go` instructs to create `dbfs.go` file with mock stubs. +* `github.com/databricks/databricks-sdk-go/service/dbfs` tells which Databricks package to look services in. +* `DbfsService` tells which services to generate mocks for. + +## Initializing `gomock` + +Every test needs the following preamble: + +```go +ctrl := gomock.NewController(t) +defer ctrl.Finish() +``` + +## Mocking individual methods with `gomock` + +Every actual method call must be mocked for the test to pass: + +```go +mockDbfs := mocks.NewMockDbfsService(ctrl) +mockDbfs.EXPECT().Create(gomock.Any(), gomock.Eq(dbfs.Create{ + Path: "/a/b/c", + Overwrite: true, +})).Return(&dbfs.CreateResponse{ + Handle: 123, +}, nil) +``` + +## Testing idioms with Databricks SDK for Go + +You can stub out the auth with the `databricks.NewMockConfig(nil)` helper function. Every service has a public `WithImpl()` method, that you can use to set the stubs for every service that is called in the unit tests. + +```go +w := workspaces.New(databricks.NewMockConfig(nil)) +w.Dbfs.WithImpl(mockDbfs) +``` + +## Running this example + +1. Run `go mod tidy` in this folder to create `go.sum` file to pick dependency versions. +2. Run `go mod vendor` to download dependencies into `vendor/` directory. +3. Run `go generate ./...` to create `mocks/` directory. +4. Run `go test ./...` to invoke tests with mocks. \ No newline at end of file diff --git a/examples/mocking/dbfs_test.go b/examples/mocking/dbfs_test.go new file mode 100644 index 000000000..d318a4473 --- /dev/null +++ b/examples/mocking/dbfs_test.go @@ -0,0 +1,46 @@ +package mocking + +import ( + "context" + "mocking/mocks" + "strings" + "testing" + + "github.com/golang/mock/gomock" + _ "github.com/golang/mock/mockgen/model" + "github.com/stretchr/testify/assert" + + "github.com/databricks/databricks-sdk-go/databricks" + "github.com/databricks/databricks-sdk-go/service/dbfs" + "github.com/databricks/databricks-sdk-go/workspaces" +) + +//go:generate go run github.com/golang/mock/mockgen@latest -package=mocks -destination=mocks/dbfs.go github.com/databricks/databricks-sdk-go/service/dbfs DbfsService + +func TestDbfsHighLevelAPI(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + mockDbfs := mocks.NewMockDbfsService(ctrl) + + ctx := context.Background() + mockDbfs.EXPECT().Create(gomock.Any(), gomock.Eq(dbfs.Create{ + Path: "/a/b/c", + Overwrite: true, + })).Return(&dbfs.CreateResponse{ + Handle: 123, + }, nil) + mockDbfs.EXPECT().AddBlock(gomock.Any(), gomock.Eq(dbfs.AddBlock{ + Handle: 123, + Data: "YWJj", + })) + mockDbfs.EXPECT().Close(gomock.Any(), gomock.Eq(dbfs.Close{ + Handle: 123, + })) + + w := workspaces.New(databricks.NewMockConfig(nil)) + w.Dbfs.WithImpl(mockDbfs) + + err := w.Dbfs.Overwrite(ctx, "/a/b/c", strings.NewReader("abc")) + assert.NoError(t, err) +} diff --git a/examples/mocking/go.mod b/examples/mocking/go.mod new file mode 100644 index 000000000..c2366a257 --- /dev/null +++ b/examples/mocking/go.mod @@ -0,0 +1,11 @@ +module mocking + +go 1.18 + +require ( + github.com/databricks/databricks-sdk-go v0.0.0 + github.com/golang/mock v1.6.0 + github.com/stretchr/testify v1.8.1 +) + +replace github.com/databricks/databricks-sdk-go v0.0.0 => ../.. diff --git a/internal/clusters_test.go b/internal/clusters_test.go index 01bacb121..69fa750f2 100644 --- a/internal/clusters_test.go +++ b/internal/clusters_test.go @@ -149,18 +149,18 @@ func TestAccClustersApiIntegration(t *testing.T) { require.NoError(t, err) // Get events for the cluster and assert its non empty - getEventsResponse, err := w.Clusters.Events(ctx, clusters.GetEvents{ + events, err := w.Clusters.EventsAll(ctx, clusters.GetEvents{ ClusterId: clstr.ClusterId, }) require.NoError(t, err) - assert.True(t, len(getEventsResponse.Events) > 0) + assert.True(t, len(events) > 0) // List clusters in workspace - listClustersResponse, err := w.Clusters.List(ctx, clusters.ListRequest{}) + clusters, err := w.Clusters.ListAll(ctx, clusters.ListRequest{}) require.NoError(t, err) var seen int - for _, clusterInfo := range listClustersResponse.Clusters { + for _, clusterInfo := range clusters { if clusterInfo.ClusterId == clstr.ClusterId { seen++ } diff --git a/internal/dbsql_test.go b/internal/dbsql_test.go index 3ef364f04..e4ce94cfa 100644 --- a/internal/dbsql_test.go +++ b/internal/dbsql_test.go @@ -85,7 +85,7 @@ func TestAccQueriesList(t *testing.T) { } var qs1, qs2, qs3 []dbsql.Query { - result, err := w.Queries.ListQueries(ctx, dbsql.ListQueriesRequest{PageSize: 10}) + result, err := w.Queries.Impl().ListQueries(ctx, dbsql.ListQueriesRequest{PageSize: 10}) require.NoError(t, err) qs1 = result.Results } diff --git a/internal/deployment_test.go b/internal/deployment_test.go index eaf8f21b9..51e844985 100644 --- a/internal/deployment_test.go +++ b/internal/deployment_test.go @@ -53,7 +53,7 @@ func TestMwsAccNetworks(t *testing.T) { if !a.Config.IsAccountsClient() || !a.Config.IsAws() { t.SkipNow() } - netw, err := a.Networks.CreateNetworkConfig(ctx, deployment.CreateNetworkRequest{ + netw, err := a.NetworkConfigurations.CreateNetworkConfig(ctx, deployment.CreateNetworkRequest{ NetworkName: RandomName("sdk-"), VpcId: RandomHex("vpc-", 17), SubnetIds: []string{RandomHex("subnet-", 17), RandomHex("subnet-", 17)}, @@ -61,14 +61,14 @@ func TestMwsAccNetworks(t *testing.T) { }) require.NoError(t, err) defer func() { - err = a.Networks.DeleteNetworkConfigByNetworkId(ctx, netw.NetworkId) + err = a.NetworkConfigurations.DeleteNetworkConfigByNetworkId(ctx, netw.NetworkId) require.NoError(t, err) }() - _, err = a.Networks.GetNetworkConfigByNetworkId(ctx, netw.NetworkId) + _, err = a.NetworkConfigurations.GetNetworkConfigByNetworkId(ctx, netw.NetworkId) require.NoError(t, err) - configs, err := a.Networks.ListNetworkConfigs(ctx) + configs, err := a.NetworkConfigurations.ListNetworkConfigs(ctx) require.NoError(t, err) assert.True(t, len(configs) > 0) } @@ -83,7 +83,7 @@ func TestMwsAccCredentials(t *testing.T) { if !a.Config.IsAccountsClient() || !a.Config.IsAws() { t.SkipNow() } - role, err := a.Credentials.CreateCredentialConfig(ctx, deployment.CreateCredentialRequest{ + role, err := a.CredentialConfigurations.CreateCredentialConfig(ctx, deployment.CreateCredentialRequest{ CredentialsName: RandomName("sdk-"), AwsCredentials: deployment.AwsCredentials{ StsRole: &deployment.StsRole{ @@ -94,14 +94,14 @@ func TestMwsAccCredentials(t *testing.T) { require.NoError(t, err) defer func() { - err = a.Credentials.DeleteCredentialConfigByCredentialsId(ctx, role.CredentialsId) + err = a.CredentialConfigurations.DeleteCredentialConfigByCredentialsId(ctx, role.CredentialsId) require.NoError(t, err) }() - _, err = a.Credentials.GetCredentialConfigByCredentialsId(ctx, role.CredentialsId) + _, err = a.CredentialConfigurations.GetCredentialConfigByCredentialsId(ctx, role.CredentialsId) require.NoError(t, err) - configs, err := a.Credentials.ListCredentials(ctx) + configs, err := a.CredentialConfigurations.ListCredentials(ctx) require.NoError(t, err) assert.True(t, len(configs) > 0) } diff --git a/internal/git_credentials_test.go b/internal/git_credentials_test.go index 1a090d704..26b8bef85 100644 --- a/internal/git_credentials_test.go +++ b/internal/git_credentials_test.go @@ -19,9 +19,9 @@ func TestAccGitCredentials(t *testing.T) { t.SkipNow() } - list, err := w.GitCredentials.List(ctx) + list, err := w.GitCredentials.ListAll(ctx) require.NoError(t, err) - for _, v := range list.Credentials { + for _, v := range list { err = w.GitCredentials.DeleteByCredentialId(ctx, v.CredentialId) require.NoError(t, err) } diff --git a/internal/jobs_test.go b/internal/jobs_test.go index cc7c2f6ee..6b9fe227e 100644 --- a/internal/jobs_test.go +++ b/internal/jobs_test.go @@ -167,13 +167,13 @@ func TestAccJobsApiFullIntegration(t *testing.T) { require.NoError(t, err) assert.Equal(t, byId.Settings.Name, newName) - jobList, err := w.Jobs.List(ctx, jobs.ListRequest{ + jobList, err := w.Jobs.ListAll(ctx, jobs.ListRequest{ ExpandTasks: false, }) require.NoError(t, err) var jobsIdList []int64 - for _, job := range jobList.Jobs { + for _, job := range jobList { jobsIdList = append(jobsIdList, job.JobId) } assert.Contains(t, jobsIdList, createdJob.JobId) @@ -181,9 +181,9 @@ func TestAccJobsApiFullIntegration(t *testing.T) { err = w.Jobs.DeleteByJobId(ctx, createdJob.JobId) require.NoError(t, err) - jobList, err = w.Jobs.List(ctx, jobs.ListRequest{}) + jobList, err = w.Jobs.ListAll(ctx, jobs.ListRequest{}) require.NoError(t, err) - for _, job := range jobList.Jobs { + for _, job := range jobList { // TODO: change assertion to by-name assert.NotEqual(t, job.JobId, createdJob.JobId) } diff --git a/internal/scim_test.go b/internal/scim_test.go index 9f9a1b888..8d6fbece3 100644 --- a/internal/scim_test.go +++ b/internal/scim_test.go @@ -50,7 +50,7 @@ func TestAccUsers(t *testing.T) { assert.Equal(t, user.DisplayName, fetch.DisplayName) // list all users - allUsers, err := w.Users.ListUsers(ctx, scim.ListUsersRequest{ + allUsers, err := w.Users.ListUsersAll(ctx, scim.ListUsersRequest{ Attributes: "id,userName", SortBy: "userName", SortOrder: scim.ListUsersSortOrderDescending, @@ -59,7 +59,7 @@ func TestAccUsers(t *testing.T) { // verify that the user we've creates is in the list namesToIds := map[string]string{} - for _, u := range allUsers.Resources { + for _, u := range allUsers { namesToIds[u.UserName] = u.Id } assert.Equal(t, user.Id, namesToIds[user.UserName]) @@ -95,7 +95,7 @@ func TestAccGroups(t *testing.T) { assert.Equal(t, group.DisplayName, fetch.DisplayName) // list all groups that start with `go-sdk-` - allGroups, err := w.Groups.ListGroups(ctx, scim.ListGroupsRequest{ + allGroups, err := w.Groups.ListGroupsAll(ctx, scim.ListGroupsRequest{ SortOrder: scim.ListGroupsSortOrderDescending, Filter: "displayName sw 'go-sdk-'", }) @@ -103,7 +103,7 @@ func TestAccGroups(t *testing.T) { // verify that the group we've creates is in the list namesToIds := map[string]string{} - for _, u := range allGroups.Resources { + for _, u := range allGroups { namesToIds[u.DisplayName] = u.Id } assert.Equal(t, group.Id, namesToIds[group.DisplayName]) diff --git a/internal/secrets_test.go b/internal/secrets_test.go index b78095beb..927e8985e 100644 --- a/internal/secrets_test.go +++ b/internal/secrets_test.go @@ -29,9 +29,9 @@ func TestAccSecrets(t *testing.T) { err = w.Secrets.DeleteScopeByScope(ctx, scope.Scope) require.NoError(t, err) }) - scopes, err := w.Secrets.ListScopes(ctx) + scopes, err := w.Secrets.ListScopesAll(ctx) require.NoError(t, err) - assert.True(t, len(scopes.Scopes) >= 1) + assert.True(t, len(scopes) >= 1) put := secrets.PutSecret{ Scope: scope.Scope, diff --git a/internal/workspace_test.go b/internal/workspace_test.go index 11e8ef8cb..f79229e7f 100644 --- a/internal/workspace_test.go +++ b/internal/workspace_test.go @@ -63,12 +63,12 @@ func TestAccListWorkspaceIntegration(t *testing.T) { assert.True(t, exportResponse.Content == base64.StdEncoding.EncodeToString([]byte("# Databricks notebook source\nprint('hello from job')"))) // Assert the test notebook is present in test dir using list api - listReponse, err := w.Workspace.List(ctx, workspace.ListRequest{ + objects, err := w.Workspace.ListAll(ctx, workspace.ListRequest{ Path: testDirPath, }) require.NoError(t, err) foundTestNotebook := false - for _, objectInfo := range listReponse.Objects { + for _, objectInfo := range objects { if objectInfo.Path == filepath.Join(testDirPath, testFileName) { foundTestNotebook = true } diff --git a/service/.codegen.json b/service/.codegen.json index a184c35d0..950e19912 100644 --- a/service/.codegen.json +++ b/service/.codegen.json @@ -1,8 +1,13 @@ { - "formatter": "go fmt ./... && goimports -w $FILENAMES", + "formatter": "go fmt ./... && go run golang.org/x/tools/cmd/goimports@latest -w $FILENAMES", "packages": { ".codegen/api.go.tmpl": "{{.Name}}/api.go", + ".codegen/impl.go.tmpl": "{{.Name}}/impl.go", ".codegen/interface.go.tmpl": "{{.Name}}/interface.go", ".codegen/model.go.tmpl": "{{.Name}}/model.go" + }, + "batch": { + ".codegen/workspaces.go.tmpl": "../workspaces/client.go", + ".codegen/accounts.go.tmpl": "../accounts/client.go" } } \ No newline at end of file diff --git a/service/.codegen/accounts.go.tmpl b/service/.codegen/accounts.go.tmpl new file mode 100644 index 000000000..313f92534 --- /dev/null +++ b/service/.codegen/accounts.go.tmpl @@ -0,0 +1,51 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package accounts + +import ( + "github.com/databricks/databricks-sdk-go/databricks" + "github.com/databricks/databricks-sdk-go/databricks/client" + {{range .Packages}} + "github.com/databricks/databricks-sdk-go/service/{{.Name}}" + {{- end}} +) + +type AccountsClient struct { + Config *databricks.Config + + {{range .Services}}{{if .IsAccounts}} + {{.Comment " // " 80}} + {{if eq .Package.Name "scim" -}} + {{trim_prefix .Name "Account"}} + {{- else}}{{.Name}}{{end}} *{{.Package.Name}}.{{.Name}}API + {{end}}{{end}} +} + +func New(c ...*databricks.Config) *AccountsClient { + var cfg *databricks.Config + if len(c) == 1 { + // first config + cfg = c[0] + } else { + // default config + cfg = &databricks.Config{} + } + err := cfg.EnsureResolved() + if err != nil { + panic(err) + } + if cfg.AccountID == "" { + panic("AccountID is not specified on config") + } + apiClient, err := client.New(cfg) + if err != nil { + panic(err) + } + return &AccountsClient{ + Config: cfg, + {{range .Services}}{{if .IsAccounts}} + {{if eq .Package.Name "scim" -}} + {{trim_prefix .Name "Account"}} + {{- else}}{{.Name}}{{end}}: {{.Package.Name}}.New{{.Name}}(apiClient),{{end}}{{end}} + } +} diff --git a/service/.codegen/api.go.tmpl b/service/.codegen/api.go.tmpl index 32fcb8a80..ddf6fd3bd 100644 --- a/service/.codegen/api.go.tmpl +++ b/service/.codegen/api.go.tmpl @@ -11,32 +11,41 @@ import ( "github.com/databricks/databricks-sdk-go/databricks/useragent" ) {{range .Services}} -func New{{.PascalName}}(client *client.DatabricksClient) {{.PascalName}}Service { +func New{{.PascalName}}(client *client.DatabricksClient) *{{.PascalName}}API { return &{{.PascalName}}API{ - client: client, + impl: &{{.CamelName}}Impl{ + client: client, + }, } } +{{.Comment "// " 80}} type {{.PascalName}}API struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl({{.PascalName}}Service) + impl {{.PascalName}}Service } -{{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}} -func (a *{{.Service.Name}}API) {{.PascalName}}(ctx context.Context{{if .Request}}, request {{.Request.PascalName}}{{end}}) {{if .Response}}({{if .Response.ArrayValue}}[]{{.Response.ArrayValue.PascalName}}{{else}}*{{.Response.PascalName}}{{end}}, error){{else}}error{{end}} { - {{if .Response}}var {{.Response.CamelName}} {{if .Response.ArrayValue}}[]{{.Response.ArrayValue.PascalName}}{{else}}{{.Response.PascalName}}{{end}} - {{end -}} - path := {{if .PathParts -}} - fmt.Sprintf("{{range .PathParts}}{{.Prefix}}{{if or .Field .IsAccountId}}%v{{end}}{{ end }}"{{ range .PathParts }}{{if .Field}}, request.{{.Field.PascalName}}{{ else if .IsAccountId }}, a.client.Config.AccountID{{end}}{{ end }}) - {{- else}}"{{.Path}}"{{end}} - err := a.client.{{.TitleVerb}}(ctx, path, {{if .Request}}request{{else}}nil{{end}}{{if .Response}}, &{{.Response.CamelName}}{{else if .CanHaveResponseBody}}, nil{{end}}) - return {{if .Response}}{{if not .Response.ArrayValue}}&{{end}}{{.Response.CamelName}}, {{end}}err +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *{{.PascalName}}API) WithImpl(impl {{.PascalName}}Service) *{{.PascalName}}API { + a.impl = impl + return a +} + +// Impl returns low-level {{.PascalName}} API implementation +func (a *{{.PascalName}}API) Impl() {{.PascalName}}Service { + return a.impl +} + +{{range .Methods}}{{if not .Pagination}}{{.Comment "// " 80}} +func (a *{{.Service.PascalName}}API) {{.PascalName}}(ctx context.Context{{if .Request}}, request {{.Request.PascalName}}{{end}}) {{if .Response}}({{if .Response.ArrayValue}}[]{{.Response.ArrayValue.PascalName}}{{else}}*{{.Response.PascalName}}{{end}}, error){{else}}error{{end}} { + return a.impl.{{.PascalName}}(ctx{{if .Request}}, request{{end}}) } +{{end}} + {{if .Wait}} -// {{.PascalName}} and wait to reach {{range $i, $e := .Wait.Success}}{{if $i}} or {{end}}{{.Content}}{{end}} state +// Calls [{{.Service.Name}}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. @@ -78,7 +87,7 @@ func (a *{{.Service.Name}}API) {{.PascalName}}AndWait(ctx context.Context{{if .R }) } {{end}}{{if .Pagination}} -// {{.PascalName}}All returns all {{.Pagination.Entity.PascalName}} instances{{if .Pagination.MultiRequest}} by calling {{.PascalName}} for every result page{{else}}. This method exists for consistency purposes.{{end}} +{{.Comment "// " 80}} // // This method is generated by Databricks SDK Code Generator. func (a *{{.Service.Name}}API) {{.PascalName}}All(ctx context.Context{{if .Request}}, request {{.Request.PascalName}}{{end}}) ([]{{.Pagination.Entity.PascalName}}, error) { @@ -87,7 +96,7 @@ func (a *{{.Service.Name}}API) {{.PascalName}}All(ctx context.Context{{if .Reque {{if eq .Pagination.Increment 1 -}} request.{{.Pagination.Offset.PascalName}} = 1 // start iterating from the first page {{end}}for { - response, err := a.{{.PascalName}}(ctx{{if .Request}}, request{{end}}) + response, err := a.impl.{{.PascalName}}(ctx{{if .Request}}, request{{end}}) if err != nil { return nil, err } @@ -108,11 +117,11 @@ func (a *{{.Service.Name}}API) {{.PascalName}}All(ctx context.Context{{if .Reque request.{{.Pagination.Offset.PascalName}} += {{template "type" .Pagination.Offset.Entity}}(len(response.{{.Pagination.Results.PascalName}})) {{- end}} } - return results, nil{{else if .Pagination.Results}}response, err := a.{{.PascalName}}(ctx{{if .Request}}, request{{end}}) + return results, nil{{else if .Pagination.Results}}response, err := a.impl.{{.PascalName}}(ctx{{if .Request}}, request{{end}}) if err != nil { return nil, err } - return response.{{.Pagination.Results.PascalName}}, nil{{else}}return a.{{.PascalName}}(ctx, request){{end}} + return response.{{.Pagination.Results.PascalName}}, nil{{else}}return a.impl.{{.PascalName}}(ctx, request){{end}} } {{end}}{{if .NamedIdMap}} func (a *{{.Service.Name}}API) {{.NamedIdMap.Entity.PascalName}}{{.NamedIdMap.Name.PascalName}}To{{.NamedIdMap.Id.PascalName}}Map(ctx context.Context{{if .Request}}, request {{.Request.PascalName}}{{end}}) (map[string]{{template "type" .NamedIdMap.Id.Entity}}, error) { @@ -143,7 +152,7 @@ func (a *{{.Service.Name}}API) Get{{.NamedIdMap.Entity.PascalName}}By{{.NamedIdM {{end}}{{if .Shortcut}} {{.Comment "// " 80}} func (a *{{.Service.Name}}API) {{.Shortcut.PascalName}}(ctx context.Context{{range .Shortcut.Params}}, {{.CamelName}} {{template "type" .Entity}}{{end}}) {{if .Response}}({{if .Response.ArrayValue}}[]{{.Response.ArrayValue.PascalName}}{{else}}*{{.Response.PascalName}}{{end}}, error){{else}}error{{end}} { - return a.{{.PascalName}}(ctx, {{.Request.PascalName}}{ + return a.impl.{{.PascalName}}(ctx, {{.Request.PascalName}}{ {{- range .Shortcut.Params}} {{.PascalName}}: {{.CamelName}},{{end}} }) @@ -157,4 +166,5 @@ func (a *{{.Service.Name}}API) {{.Shortcut.PascalName}}AndWait(ctx context.Conte } {{end}} {{end -}} + {{- end}} \ No newline at end of file diff --git a/service/.codegen/impl.go.tmpl b/service/.codegen/impl.go.tmpl new file mode 100644 index 000000000..62e188f54 --- /dev/null +++ b/service/.codegen/impl.go.tmpl @@ -0,0 +1,30 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package {{.Name}} + +import ( + "context" + "fmt" + "time" + "github.com/databricks/databricks-sdk-go/databricks/retries" + "github.com/databricks/databricks-sdk-go/databricks/client" + "github.com/databricks/databricks-sdk-go/databricks/useragent" +) +{{range .Services}} +// unexported type that holds implementations of just {{.Name}} API methods +type {{.CamelName}}Impl struct { + client *client.DatabricksClient +} + +{{range .Methods}} +func (a *{{.Service.CamelName}}Impl) {{.PascalName}}(ctx context.Context{{if .Request}}, request {{.Request.PascalName}}{{end}}) {{if .Response}}({{if .Response.ArrayValue}}[]{{.Response.ArrayValue.PascalName}}{{else}}*{{.Response.PascalName}}{{end}}, error){{else}}error{{end}} { + {{if .Response}}var {{.Response.CamelName}} {{if .Response.ArrayValue}}[]{{.Response.ArrayValue.PascalName}}{{else}}{{.Response.PascalName}}{{end}} + {{end -}} + path := {{if .PathParts -}} + fmt.Sprintf("{{range .PathParts}}{{.Prefix}}{{if or .Field .IsAccountId}}%v{{end}}{{ end }}"{{ range .PathParts }}{{if .Field}}, request.{{.Field.PascalName}}{{ else if .IsAccountId }}, a.client.Config.AccountID{{end}}{{ end }}) + {{- else}}"{{.Path}}"{{end}} + err := a.client.{{.TitleVerb}}(ctx, path, {{if .Request}}request{{else}}nil{{end}}{{if .Response}}, &{{.Response.CamelName}}{{else if .CanHaveResponseBody}}, nil{{end}}) + return {{if .Response}}{{if not .Response.ArrayValue}}&{{end}}{{.Response.CamelName}}, {{end}}err +} +{{end -}} +{{end}} \ No newline at end of file diff --git a/service/.codegen/interface.go.tmpl b/service/.codegen/interface.go.tmpl index c28e407d9..110ab0aa2 100644 --- a/service/.codegen/interface.go.tmpl +++ b/service/.codegen/interface.go.tmpl @@ -10,10 +10,6 @@ import ( {{range .Services}} {{.Comment "// " 80}} -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type {{.PascalName}}Service interface { {{range .Methods}} {{.Comment " // " 80}} @@ -22,52 +18,7 @@ type {{.PascalName}}Service interface { // 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}}) {{if .Response}}({{if .Response.ArrayValue}}[]{{.Response.ArrayValue.PascalName}}{{else}}*{{.Response.PascalName}}{{end}}, error){{else}}error{{end}} - {{if .Wait}} - // {{.PascalName}}AndWait calls {{.PascalName}}() and waits to reach {{range $i, $e := .Wait.Success}}{{if $i}} or {{end}}{{.Content}}{{end}} state - // - // This method is generated by Databricks SDK Code Generator. - {{.PascalName}}AndWait(ctx context.Context{{if .Request}}, request {{.Request.PascalName}}{{end}}, options ...retries.Option[{{.Wait.Poll.Response.PascalName}}]) (*{{.Wait.Poll.Response.PascalName}}, error){{end}} - {{- if .Shortcut}} - // {{.Shortcut.PascalName}} calls {{.PascalName}}, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - {{.Shortcut.PascalName}}(ctx context.Context{{range .Shortcut.Params}}, {{.CamelName}} {{template "type" .Entity}}{{end}}) {{if .Response}}({{if .Response.ArrayValue}}[]{{.Response.ArrayValue.PascalName}}{{else}}*{{.Response.PascalName}}{{end}}, error){{else}}error{{end}}{{end}} - {{- if .Pagination}} - // {{.PascalName}}All calls {{.PascalName}}() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - {{.PascalName}}All(ctx context.Context{{if .Request}}, request {{.Request.PascalName}}{{end}}) ([]{{.Pagination.Entity.PascalName}}, error){{end}} - {{if .NamedIdMap}} - // {{.NamedIdMap.Entity.PascalName}}{{.NamedIdMap.Name.PascalName}}To{{.NamedIdMap.Id.PascalName}}Map retrieves a mapping to access ID by name - // - // This method is generated by Databricks SDK Code Generator. - {{.NamedIdMap.Entity.PascalName}}{{.NamedIdMap.Name.PascalName}}To{{.NamedIdMap.Id.PascalName}}Map(ctx context.Context{{if .Request}}, request {{.Request.PascalName}}{{end}}) (map[string]{{template "type" .NamedIdMap.Id.Entity}}, error){{end}} - {{if .GetByName}} - // Get{{.NamedIdMap.Entity.PascalName}}By{{.NamedIdMap.Name.PascalName}} retrieves {{.GetByName.PascalName}} by name. - // - // This method is generated by Databricks SDK Code Generator. - Get{{.NamedIdMap.Entity.PascalName}}By{{.NamedIdMap.Name.PascalName}}(ctx context.Context, name string) (*{{.GetByName.PascalName}}, error){{end}} - {{- if and .Shortcut .Wait}} - // {{.Shortcut.PascalName}}AndWait calls {{.Shortcut.PascalName}} and waits until {{.Wait.Poll.Response.PascalName}} is in desired state. - // - // This method is generated by Databricks SDK Code Generator. - {{.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}} - {{if eq .PascalName "Clusters"}}// GetOrCreateRunningCluster creates an autoterminating cluster if it doesn't exist - GetOrCreateRunningCluster(ctx context.Context, name string, custom ...CreateCluster) (c *ClusterInfo, err error) - {{end}} - {{if eq .PascalName "Dbfs"}}// Overwrite uploads a file from supplied `io.Reader` - Overwrite(ctx context.Context, path string, r io.Reader) error - // Open returns `io.Reader` to download file in chunks - Open(ctx context.Context, path string) (*FileReader, error) - {{end}} - {{if eq .PascalName "Libraries"}}// UpdateAndWait installs or uninstalls specified libraries - // and waits until they are in a usable state - UpdateAndWait(ctx context.Context, update Update, options ...retries.Option[ClusterLibraryStatuses]) error - // Wait returns only once the libraries are in the usable state - Wait(ctx context.Context, wait Wait, options ...retries.Option[ClusterLibraryStatuses]) (*ClusterLibraryStatuses, error) - {{end}} - + {{end -}} } + {{end}} \ No newline at end of file diff --git a/service/.codegen/workspaces.go.tmpl b/service/.codegen/workspaces.go.tmpl new file mode 100644 index 000000000..516b1019b --- /dev/null +++ b/service/.codegen/workspaces.go.tmpl @@ -0,0 +1,48 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package workspaces + +import ( + "github.com/databricks/databricks-sdk-go/databricks" + "github.com/databricks/databricks-sdk-go/databricks/client" + {{range .Packages}} + "github.com/databricks/databricks-sdk-go/service/{{.Name}}"{{end}} +) + +type WorkspacesClient struct { + Config *databricks.Config + + {{range .Services}}{{if not .IsAccounts}} + {{- if eq .Name "CommandExecution" -}} + // This API allows executing commands on running clusters. + CommandExecutor commands.CommandExecutor + + {{else}}{{.Comment " // " 80}} + {{.Name}} *{{.Package.Name}}.{{.Name}}API + + {{end}}{{end}}{{end}} +} + +func New(c ...*databricks.Config) *WorkspacesClient { + var cfg *databricks.Config + if len(c) == 1 { + // first config + cfg = c[0] + } else { + // default config + cfg = &databricks.Config{} + } + apiClient, err := client.New(cfg) + if err != nil { + panic(err) + } + return &WorkspacesClient{ + Config: cfg, + {{range .Services}}{{if not .IsAccounts}} + {{- if eq .Name "CommandExecution" -}} + CommandExecutor: commands.NewCommandExecutor(apiClient), + {{else -}} + {{.Name}}: {{.Package.Name}}.New{{.Name}}(apiClient), + {{end -}}{{end}}{{end}} + } +} diff --git a/service/billing/api.go b/service/billing/api.go index a11101cda..a1da6eb7d 100755 --- a/service/billing/api.go +++ b/service/billing/api.go @@ -4,19 +4,36 @@ package billing import ( "context" - "fmt" "github.com/databricks/databricks-sdk-go/databricks/client" ) -func NewBillableUsageDownload(client *client.DatabricksClient) BillableUsageDownloadService { +func NewBillableUsageDownload(client *client.DatabricksClient) *BillableUsageDownloadAPI { return &BillableUsageDownloadAPI{ - client: client, + impl: &billableUsageDownloadImpl{ + client: client, + }, } } +// This API allows you to download billable usage logs for the specified account +// and date range. This feature works with all account types. type BillableUsageDownloadAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(BillableUsageDownloadService) + impl BillableUsageDownloadService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *BillableUsageDownloadAPI) WithImpl(impl BillableUsageDownloadService) *BillableUsageDownloadAPI { + a.impl = impl + return a +} + +// Impl returns low-level BillableUsageDownload API implementation +func (a *BillableUsageDownloadAPI) Impl() BillableUsageDownloadService { + return a.impl } // Return billable usage logs @@ -26,45 +43,56 @@ type BillableUsageDownloadAPI struct { // schema](https://docs.databricks.com/administration-guide/account-settings/usage-analysis.html#schema). // Note that this method might take multiple seconds to complete. func (a *BillableUsageDownloadAPI) DownloadBillableUsage(ctx context.Context, request DownloadBillableUsageRequest) error { - path := fmt.Sprintf("/api/2.0/accounts/%v/usage/download", a.client.Config.AccountID) - err := a.client.Get(ctx, path, request, nil) - return err + return a.impl.DownloadBillableUsage(ctx, request) } -func NewBudgets(client *client.DatabricksClient) BudgetsService { +func NewBudgets(client *client.DatabricksClient) *BudgetsAPI { return &BudgetsAPI{ - client: client, + impl: &budgetsImpl{ + client: client, + }, } } +// These APIs manage budget configuration including notifications for exceeding +// a budget for a period. They can also retrieve the status of each budget. type BudgetsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(BudgetsService) + impl BudgetsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *BudgetsAPI) WithImpl(impl BudgetsService) *BudgetsAPI { + a.impl = impl + return a +} + +// Impl returns low-level Budgets API implementation +func (a *BudgetsAPI) Impl() BudgetsService { + return a.impl } // Create a new budget // // Creates a new budget in the specified account. func (a *BudgetsAPI) CreateBudget(ctx context.Context, request CreateBudgetRequest) (*BudgetWithStatus, error) { - var budgetWithStatus BudgetWithStatus - path := fmt.Sprintf("/api/2.0/accounts/%v/budget", a.client.Config.AccountID) - err := a.client.Post(ctx, path, request, &budgetWithStatus) - return &budgetWithStatus, err + return a.impl.CreateBudget(ctx, request) } // Delete budget // // Deletes the budget specified by its UUID. func (a *BudgetsAPI) DeleteBudget(ctx context.Context, request DeleteBudgetRequest) error { - path := fmt.Sprintf("/api/2.0/accounts/%v/budget/%v", a.client.Config.AccountID, request.BudgetId) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteBudget(ctx, request) } // Delete budget // // Deletes the budget specified by its UUID. func (a *BudgetsAPI) DeleteBudgetByBudgetId(ctx context.Context, budgetId string) error { - return a.DeleteBudget(ctx, DeleteBudgetRequest{ + return a.impl.DeleteBudget(ctx, DeleteBudgetRequest{ BudgetId: budgetId, }) } @@ -74,10 +102,7 @@ func (a *BudgetsAPI) DeleteBudgetByBudgetId(ctx context.Context, budgetId string // Gets the budget specified by its UUID, including noncumulative status for // each day that the budget is configured to include. func (a *BudgetsAPI) GetBudget(ctx context.Context, request GetBudgetRequest) (*BudgetWithStatus, error) { - var budgetWithStatus BudgetWithStatus - path := fmt.Sprintf("/api/2.0/accounts/%v/budget/%v", a.client.Config.AccountID, request.BudgetId) - err := a.client.Get(ctx, path, request, &budgetWithStatus) - return &budgetWithStatus, err + return a.impl.GetBudget(ctx, request) } // Get budget and its status @@ -85,7 +110,7 @@ func (a *BudgetsAPI) GetBudget(ctx context.Context, request GetBudgetRequest) (* // Gets the budget specified by its UUID, including noncumulative status for // each day that the budget is configured to include. func (a *BudgetsAPI) GetBudgetByBudgetId(ctx context.Context, budgetId string) (*BudgetWithStatus, error) { - return a.GetBudget(ctx, GetBudgetRequest{ + return a.impl.GetBudget(ctx, GetBudgetRequest{ BudgetId: budgetId, }) } @@ -95,19 +120,9 @@ func (a *BudgetsAPI) GetBudgetByBudgetId(ctx context.Context, budgetId string) ( // Gets all budgets associated with this account, including noncumulative status // for each day that the budget is configured to include. // -// Use ListBudgetsAll() to get all BudgetWithStatus instances -func (a *BudgetsAPI) ListBudgets(ctx context.Context) (*BudgetList, error) { - var budgetList BudgetList - path := fmt.Sprintf("/api/2.0/accounts/%v/budget", a.client.Config.AccountID) - err := a.client.Get(ctx, path, nil, &budgetList) - return &budgetList, err -} - -// ListBudgetsAll returns all BudgetWithStatus instances. This method exists for consistency purposes. -// // This method is generated by Databricks SDK Code Generator. func (a *BudgetsAPI) ListBudgetsAll(ctx context.Context) ([]BudgetWithStatus, error) { - response, err := a.ListBudgets(ctx) + response, err := a.impl.ListBudgets(ctx) if err != nil { return nil, err } @@ -119,19 +134,97 @@ func (a *BudgetsAPI) ListBudgetsAll(ctx context.Context) ([]BudgetWithStatus, er // Modifies a budget in this account. Budget properties are completely // overwritten. func (a *BudgetsAPI) UpdateBudget(ctx context.Context, request UpdateBudgetRequest) error { - path := fmt.Sprintf("/api/2.0/accounts/%v/budget/%v", a.client.Config.AccountID, request.BudgetId) - err := a.client.Patch(ctx, path, request) - return err + return a.impl.UpdateBudget(ctx, request) } -func NewLogDelivery(client *client.DatabricksClient) LogDeliveryService { +func NewLogDelivery(client *client.DatabricksClient) *LogDeliveryAPI { return &LogDeliveryAPI{ - client: client, + impl: &logDeliveryImpl{ + client: client, + }, } } +// These APIs manage log delivery configurations for this account. The two +// supported log types for this API are _billable usage logs_ and _audit logs_. +// This feature is in Public Preview. This feature works with all account ID +// types. +// +// Log delivery works with all account types. However, if your account is on the +// E2 version of the platform or on a select custom plan that allows multiple +// workspaces per account, you can optionally configure different storage +// destinations for each workspace. Log delivery status is also provided to know +// the latest status of log delivery attempts. The high-level flow of billable +// usage delivery: +// +// 1. **Create storage**: In AWS, [create a new AWS S3 +// bucket](https://docs.databricks.com/administration-guide/account-api/aws-storage.html) +// with a specific bucket policy. Using Databricks APIs, call the Account API to +// create a [storage configuration object](#operation/create-storage-config) +// that uses the bucket name. 2. **Create credentials**: In AWS, create the +// appropriate AWS IAM role. For full details, including the required IAM role +// policies and trust relationship, see [Billable usage log +// delivery](https://docs.databricks.com/administration-guide/account-settings/billable-usage-delivery.html). +// Using Databricks APIs, call the Account API to create a [credential +// configuration object](#operation/create-credential-config) that uses the IAM +// role's ARN. 3. **Create log delivery configuration**: Using Databricks APIs, +// call the Account API to [create a log delivery +// configuration](#operation/create-log-delivery-config) that uses the +// credential and storage configuration objects from previous steps. You can +// specify if the logs should include all events of that log type in your +// account (_Account level_ delivery) or only events for a specific set of +// workspaces (_workspace level_ delivery). Account level log delivery applies +// to all current and future workspaces plus account level logs, while workspace +// level log delivery solely delivers logs related to the specified workspaces. +// You can create multiple types of delivery configurations per account. +// +// For billable usage delivery: * For more information about billable usage +// logs, see [Billable usage log +// delivery](https://docs.databricks.com/administration-guide/account-settings/billable-usage-delivery.html). +// For the CSV schema, see the [Usage +// page](https://docs.databricks.com/administration-guide/account-settings/usage.html). +// * The delivery location is `//billable-usage/csv/`, +// where `` is the name of the optional delivery path prefix you set up +// during log delivery configuration. Files are named +// `workspaceId=-usageMonth=.csv`. * All billable usage +// logs apply to specific workspaces (_workspace level_ logs). You can aggregate +// usage for your entire account by creating an _account level_ delivery +// configuration that delivers logs for all current and future workspaces in +// your account. * The files are delivered daily by overwriting the month's CSV +// file for each workspace. +// +// For audit log delivery: * For more information about about audit log +// delivery, see [Audit log +// delivery](https://docs.databricks.com/administration-guide/account-settings/audit-logs.html), +// which includes information about the used JSON schema. * The delivery +// location is +// `//workspaceId=/date=/auditlogs_.json`. +// Files may get overwritten with the same content multiple times to achieve +// exactly-once delivery. * If the audit log delivery configuration included +// specific workspace IDs, only _workspace-level_ audit logs for those +// workspaces are delivered. If the log delivery configuration applies to the +// entire account (_account level_ delivery configuration), the audit log +// delivery includes workspace-level audit logs for all workspaces in the +// account as well as account-level audit logs. See [Audit log +// delivery](https://docs.databricks.com/administration-guide/account-settings/audit-logs.html) +// for details. * Auditable events are typically available in logs within 15 +// minutes. type LogDeliveryAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(LogDeliveryService) + impl LogDeliveryService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *LogDeliveryAPI) WithImpl(impl LogDeliveryService) *LogDeliveryAPI { + a.impl = impl + return a +} + +// Impl returns low-level LogDelivery API implementation +func (a *LogDeliveryAPI) Impl() LogDeliveryService { + return a.impl } // Create a new log delivery configuration @@ -162,10 +255,7 @@ type LogDeliveryAPI struct { // [Enable or disable log delivery // configuration](#operation/patch-log-delivery-config-status)). func (a *LogDeliveryAPI) CreateLogDeliveryConfig(ctx context.Context, request WrappedCreateLogDeliveryConfiguration) (*WrappedLogDeliveryConfiguration, error) { - var wrappedLogDeliveryConfiguration WrappedLogDeliveryConfiguration - path := fmt.Sprintf("/api/2.0/accounts/%v/log-delivery", a.client.Config.AccountID) - err := a.client.Post(ctx, path, request, &wrappedLogDeliveryConfiguration) - return &wrappedLogDeliveryConfiguration, err + return a.impl.CreateLogDeliveryConfig(ctx, request) } // Get log delivery configuration @@ -173,10 +263,7 @@ func (a *LogDeliveryAPI) CreateLogDeliveryConfig(ctx context.Context, request Wr // Gets a Databricks log delivery configuration object for an account, both // specified by ID. func (a *LogDeliveryAPI) GetLogDeliveryConfig(ctx context.Context, request GetLogDeliveryConfigRequest) (*WrappedLogDeliveryConfiguration, error) { - var wrappedLogDeliveryConfiguration WrappedLogDeliveryConfiguration - path := fmt.Sprintf("/api/2.0/accounts/%v/log-delivery/%v", a.client.Config.AccountID, request.LogDeliveryConfigurationId) - err := a.client.Get(ctx, path, request, &wrappedLogDeliveryConfiguration) - return &wrappedLogDeliveryConfiguration, err + return a.impl.GetLogDeliveryConfig(ctx, request) } // Get log delivery configuration @@ -184,7 +271,7 @@ func (a *LogDeliveryAPI) GetLogDeliveryConfig(ctx context.Context, request GetLo // Gets a Databricks log delivery configuration object for an account, both // specified by ID. func (a *LogDeliveryAPI) GetLogDeliveryConfigByLogDeliveryConfigurationId(ctx context.Context, logDeliveryConfigurationId string) (*WrappedLogDeliveryConfiguration, error) { - return a.GetLogDeliveryConfig(ctx, GetLogDeliveryConfigRequest{ + return a.impl.GetLogDeliveryConfig(ctx, GetLogDeliveryConfigRequest{ LogDeliveryConfigurationId: logDeliveryConfigurationId, }) } @@ -194,19 +281,9 @@ func (a *LogDeliveryAPI) GetLogDeliveryConfigByLogDeliveryConfigurationId(ctx co // Gets all Databricks log delivery configurations associated with an account // specified by ID. // -// Use ListLogDeliveryConfigsAll() to get all LogDeliveryConfiguration instances -func (a *LogDeliveryAPI) ListLogDeliveryConfigs(ctx context.Context, request ListLogDeliveryConfigsRequest) (*WrappedLogDeliveryConfigurations, error) { - var wrappedLogDeliveryConfigurations WrappedLogDeliveryConfigurations - path := fmt.Sprintf("/api/2.0/accounts/%v/log-delivery", a.client.Config.AccountID) - err := a.client.Get(ctx, path, request, &wrappedLogDeliveryConfigurations) - return &wrappedLogDeliveryConfigurations, err -} - -// ListLogDeliveryConfigsAll returns all LogDeliveryConfiguration instances. This method exists for consistency purposes. -// // This method is generated by Databricks SDK Code Generator. func (a *LogDeliveryAPI) ListLogDeliveryConfigsAll(ctx context.Context, request ListLogDeliveryConfigsRequest) ([]LogDeliveryConfiguration, error) { - response, err := a.ListLogDeliveryConfigs(ctx, request) + response, err := a.impl.ListLogDeliveryConfigs(ctx, request) if err != nil { return nil, err } @@ -221,7 +298,5 @@ func (a *LogDeliveryAPI) ListLogDeliveryConfigsAll(ctx context.Context, request // if this would violate the delivery configuration limits described under // [Create log delivery](#operation/create-log-delivery-config). func (a *LogDeliveryAPI) PatchLogDeliveryConfigStatus(ctx context.Context, request UpdateLogDeliveryConfigurationStatusRequest) error { - path := fmt.Sprintf("/api/2.0/accounts/%v/log-delivery/%v", a.client.Config.AccountID, request.LogDeliveryConfigurationId) - err := a.client.Patch(ctx, path, request) - return err + return a.impl.PatchLogDeliveryConfigStatus(ctx, request) } diff --git a/service/billing/impl.go b/service/billing/impl.go new file mode 100755 index 000000000..613d6c4be --- /dev/null +++ b/service/billing/impl.go @@ -0,0 +1,91 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package billing + +import ( + "context" + "fmt" + + "github.com/databricks/databricks-sdk-go/databricks/client" +) + +// unexported type that holds implementations of just BillableUsageDownload API methods +type billableUsageDownloadImpl struct { + client *client.DatabricksClient +} + +func (a *billableUsageDownloadImpl) DownloadBillableUsage(ctx context.Context, request DownloadBillableUsageRequest) error { + path := fmt.Sprintf("/api/2.0/accounts/%v/usage/download", a.client.Config.AccountID) + err := a.client.Get(ctx, path, request, nil) + return err +} + +// unexported type that holds implementations of just Budgets API methods +type budgetsImpl struct { + client *client.DatabricksClient +} + +func (a *budgetsImpl) CreateBudget(ctx context.Context, request CreateBudgetRequest) (*BudgetWithStatus, error) { + var budgetWithStatus BudgetWithStatus + path := fmt.Sprintf("/api/2.0/accounts/%v/budget", a.client.Config.AccountID) + err := a.client.Post(ctx, path, request, &budgetWithStatus) + return &budgetWithStatus, err +} + +func (a *budgetsImpl) DeleteBudget(ctx context.Context, request DeleteBudgetRequest) error { + path := fmt.Sprintf("/api/2.0/accounts/%v/budget/%v", a.client.Config.AccountID, request.BudgetId) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *budgetsImpl) GetBudget(ctx context.Context, request GetBudgetRequest) (*BudgetWithStatus, error) { + var budgetWithStatus BudgetWithStatus + path := fmt.Sprintf("/api/2.0/accounts/%v/budget/%v", a.client.Config.AccountID, request.BudgetId) + err := a.client.Get(ctx, path, request, &budgetWithStatus) + return &budgetWithStatus, err +} + +func (a *budgetsImpl) ListBudgets(ctx context.Context) (*BudgetList, error) { + var budgetList BudgetList + path := fmt.Sprintf("/api/2.0/accounts/%v/budget", a.client.Config.AccountID) + err := a.client.Get(ctx, path, nil, &budgetList) + return &budgetList, err +} + +func (a *budgetsImpl) UpdateBudget(ctx context.Context, request UpdateBudgetRequest) error { + path := fmt.Sprintf("/api/2.0/accounts/%v/budget/%v", a.client.Config.AccountID, request.BudgetId) + err := a.client.Patch(ctx, path, request) + return err +} + +// unexported type that holds implementations of just LogDelivery API methods +type logDeliveryImpl struct { + client *client.DatabricksClient +} + +func (a *logDeliveryImpl) CreateLogDeliveryConfig(ctx context.Context, request WrappedCreateLogDeliveryConfiguration) (*WrappedLogDeliveryConfiguration, error) { + var wrappedLogDeliveryConfiguration WrappedLogDeliveryConfiguration + path := fmt.Sprintf("/api/2.0/accounts/%v/log-delivery", a.client.Config.AccountID) + err := a.client.Post(ctx, path, request, &wrappedLogDeliveryConfiguration) + return &wrappedLogDeliveryConfiguration, err +} + +func (a *logDeliveryImpl) GetLogDeliveryConfig(ctx context.Context, request GetLogDeliveryConfigRequest) (*WrappedLogDeliveryConfiguration, error) { + var wrappedLogDeliveryConfiguration WrappedLogDeliveryConfiguration + path := fmt.Sprintf("/api/2.0/accounts/%v/log-delivery/%v", a.client.Config.AccountID, request.LogDeliveryConfigurationId) + err := a.client.Get(ctx, path, request, &wrappedLogDeliveryConfiguration) + return &wrappedLogDeliveryConfiguration, err +} + +func (a *logDeliveryImpl) ListLogDeliveryConfigs(ctx context.Context, request ListLogDeliveryConfigsRequest) (*WrappedLogDeliveryConfigurations, error) { + var wrappedLogDeliveryConfigurations WrappedLogDeliveryConfigurations + path := fmt.Sprintf("/api/2.0/accounts/%v/log-delivery", a.client.Config.AccountID) + err := a.client.Get(ctx, path, request, &wrappedLogDeliveryConfigurations) + return &wrappedLogDeliveryConfigurations, err +} + +func (a *logDeliveryImpl) PatchLogDeliveryConfigStatus(ctx context.Context, request UpdateLogDeliveryConfigurationStatusRequest) error { + path := fmt.Sprintf("/api/2.0/accounts/%v/log-delivery/%v", a.client.Config.AccountID, request.LogDeliveryConfigurationId) + err := a.client.Patch(ctx, path, request) + return err +} diff --git a/service/billing/interface.go b/service/billing/interface.go index af08f8948..07cc2d964 100755 --- a/service/billing/interface.go +++ b/service/billing/interface.go @@ -8,10 +8,6 @@ import ( // This API allows you to download billable usage logs for the specified account // and date range. This feature works with all account types. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type BillableUsageDownloadService interface { // Return billable usage logs @@ -25,10 +21,6 @@ type BillableUsageDownloadService interface { // These APIs manage budget configuration including notifications for exceeding // a budget for a period. They can also retrieve the status of each budget. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type BudgetsService interface { // Create a new budget @@ -41,24 +33,12 @@ type BudgetsService interface { // Deletes the budget specified by its UUID. DeleteBudget(ctx context.Context, request DeleteBudgetRequest) error - // DeleteBudgetByBudgetId calls DeleteBudget, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteBudgetByBudgetId(ctx context.Context, budgetId string) error - // Get budget and its status // // Gets the budget specified by its UUID, including noncumulative status for // each day that the budget is configured to include. GetBudget(ctx context.Context, request GetBudgetRequest) (*BudgetWithStatus, error) - // GetBudgetByBudgetId calls GetBudget, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetBudgetByBudgetId(ctx context.Context, budgetId string) (*BudgetWithStatus, error) - // Get all budgets // // Gets all budgets associated with this account, including noncumulative @@ -67,11 +47,6 @@ type BudgetsService interface { // Use ListBudgetsAll() to get all BudgetWithStatus instances ListBudgets(ctx context.Context) (*BudgetList, error) - // ListBudgetsAll calls ListBudgets() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListBudgetsAll(ctx context.Context) ([]BudgetWithStatus, error) - // Modify budget // // Modifies a budget in this account. Budget properties are completely @@ -143,10 +118,6 @@ type BudgetsService interface { // delivery](https://docs.databricks.com/administration-guide/account-settings/audit-logs.html) // for details. * Auditable events are typically available in logs within 15 // minutes. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type LogDeliveryService interface { // Create a new log delivery configuration @@ -185,12 +156,6 @@ type LogDeliveryService interface { // specified by ID. GetLogDeliveryConfig(ctx context.Context, request GetLogDeliveryConfigRequest) (*WrappedLogDeliveryConfiguration, error) - // GetLogDeliveryConfigByLogDeliveryConfigurationId calls GetLogDeliveryConfig, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetLogDeliveryConfigByLogDeliveryConfigurationId(ctx context.Context, logDeliveryConfigurationId string) (*WrappedLogDeliveryConfiguration, error) - // Get all log delivery configurations // // Gets all Databricks log delivery configurations associated with an @@ -199,11 +164,6 @@ type LogDeliveryService interface { // Use ListLogDeliveryConfigsAll() to get all LogDeliveryConfiguration instances ListLogDeliveryConfigs(ctx context.Context, request ListLogDeliveryConfigsRequest) (*WrappedLogDeliveryConfigurations, error) - // ListLogDeliveryConfigsAll calls ListLogDeliveryConfigs() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListLogDeliveryConfigsAll(ctx context.Context, request ListLogDeliveryConfigsRequest) ([]LogDeliveryConfiguration, error) - // Enable or disable log delivery configuration // // Enables or disables a log delivery configuration. Deletion of delivery diff --git a/service/clusterpolicies/api.go b/service/clusterpolicies/api.go index 4418ad519..949568542 100755 --- a/service/clusterpolicies/api.go +++ b/service/clusterpolicies/api.go @@ -8,24 +8,61 @@ import ( "github.com/databricks/databricks-sdk-go/databricks/client" ) -func NewClusterPolicies(client *client.DatabricksClient) ClusterPoliciesService { +func NewClusterPolicies(client *client.DatabricksClient) *ClusterPoliciesAPI { return &ClusterPoliciesAPI{ - client: client, + impl: &clusterPoliciesImpl{ + client: client, + }, } } +// Cluster policy limits the ability to configure clusters based on a set of +// rules. The policy rules limit the attributes or attribute values available +// for cluster creation. Cluster policies have ACLs that limit their use to +// specific users and groups. +// +// Cluster policies let you limit users to create clusters with prescribed +// settings, simplify the user interface and enable more users to create their +// own clusters (by fixing and hiding some values), control cost by limiting per +// cluster maximum cost (by setting limits on attributes whose values contribute +// to hourly price). +// +// Cluster policy permissions limit which policies a user can select in the +// Policy drop-down when the user creates a cluster: - A user who has cluster +// create permission can select the Unrestricted policy and create +// fully-configurable clusters. - A user who has both cluster create permission +// and access to cluster policies can select the Unrestricted policy and +// policies they have access to. - A user that has access to only cluster +// policies, can select the policies they have access to. +// +// If no policies have been created in the workspace, the Policy drop-down does +// not display. +// +// Only admin users can create, edit, and delete policies. Admin users also have +// access to all policies. type ClusterPoliciesAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(ClusterPoliciesService) + impl ClusterPoliciesService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *ClusterPoliciesAPI) WithImpl(impl ClusterPoliciesService) *ClusterPoliciesAPI { + a.impl = impl + return a +} + +// Impl returns low-level ClusterPolicies API implementation +func (a *ClusterPoliciesAPI) Impl() ClusterPoliciesService { + return a.impl } // Create a new policy // // Creates a new policy with prescribed settings. func (a *ClusterPoliciesAPI) Create(ctx context.Context, request CreatePolicy) (*CreatePolicyResponse, error) { - var createPolicyResponse CreatePolicyResponse - path := "/api/2.0/policies/clusters/create" - err := a.client.Post(ctx, path, request, &createPolicyResponse) - return &createPolicyResponse, err + return a.impl.Create(ctx, request) } // Delete a cluster policy @@ -33,9 +70,7 @@ func (a *ClusterPoliciesAPI) Create(ctx context.Context, request CreatePolicy) ( // Delete a policy for a cluster. Clusters governed by this policy can still // run, but cannot be edited. func (a *ClusterPoliciesAPI) Delete(ctx context.Context, request DeletePolicy) error { - path := "/api/2.0/policies/clusters/delete" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.Delete(ctx, request) } // Delete a cluster policy @@ -43,7 +78,7 @@ func (a *ClusterPoliciesAPI) Delete(ctx context.Context, request DeletePolicy) e // Delete a policy for a cluster. Clusters governed by this policy can still // run, but cannot be edited. func (a *ClusterPoliciesAPI) DeleteByPolicyId(ctx context.Context, policyId string) error { - return a.Delete(ctx, DeletePolicy{ + return a.impl.Delete(ctx, DeletePolicy{ PolicyId: policyId, }) } @@ -53,9 +88,7 @@ func (a *ClusterPoliciesAPI) DeleteByPolicyId(ctx context.Context, policyId stri // Update an existing policy for cluster. This operation may make some clusters // governed by the previous policy invalid. func (a *ClusterPoliciesAPI) Edit(ctx context.Context, request EditPolicy) error { - path := "/api/2.0/policies/clusters/edit" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.Edit(ctx, request) } // Get entity @@ -63,10 +96,7 @@ func (a *ClusterPoliciesAPI) Edit(ctx context.Context, request EditPolicy) error // Get a cluster policy entity. Creation and editing is available to admins // only. func (a *ClusterPoliciesAPI) Get(ctx context.Context, request GetRequest) (*Policy, error) { - var policy Policy - path := "/api/2.0/policies/clusters/get" - err := a.client.Get(ctx, path, request, &policy) - return &policy, err + return a.impl.Get(ctx, request) } // Get entity @@ -74,7 +104,7 @@ func (a *ClusterPoliciesAPI) Get(ctx context.Context, request GetRequest) (*Poli // Get a cluster policy entity. Creation and editing is available to admins // only. func (a *ClusterPoliciesAPI) GetByPolicyId(ctx context.Context, policyId string) (*Policy, error) { - return a.Get(ctx, GetRequest{ + return a.impl.Get(ctx, GetRequest{ PolicyId: policyId, }) } @@ -83,19 +113,9 @@ func (a *ClusterPoliciesAPI) GetByPolicyId(ctx context.Context, policyId string) // // Returns a list of policies accessible by the requesting user. // -// Use ListAll() to get all Policy instances -func (a *ClusterPoliciesAPI) List(ctx context.Context) (*ListPoliciesResponse, error) { - var listPoliciesResponse ListPoliciesResponse - path := "/api/2.0/policies/clusters/list" - err := a.client.Get(ctx, path, nil, &listPoliciesResponse) - return &listPoliciesResponse, err -} - -// ListAll returns all Policy instances. This method exists for consistency purposes. -// // This method is generated by Databricks SDK Code Generator. func (a *ClusterPoliciesAPI) ListAll(ctx context.Context) ([]Policy, error) { - response, err := a.List(ctx) + response, err := a.impl.List(ctx) if err != nil { return nil, err } diff --git a/service/clusterpolicies/impl.go b/service/clusterpolicies/impl.go new file mode 100755 index 000000000..233c1c924 --- /dev/null +++ b/service/clusterpolicies/impl.go @@ -0,0 +1,47 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package clusterpolicies + +import ( + "context" + + "github.com/databricks/databricks-sdk-go/databricks/client" +) + +// unexported type that holds implementations of just ClusterPolicies API methods +type clusterPoliciesImpl struct { + client *client.DatabricksClient +} + +func (a *clusterPoliciesImpl) Create(ctx context.Context, request CreatePolicy) (*CreatePolicyResponse, error) { + var createPolicyResponse CreatePolicyResponse + path := "/api/2.0/policies/clusters/create" + err := a.client.Post(ctx, path, request, &createPolicyResponse) + return &createPolicyResponse, err +} + +func (a *clusterPoliciesImpl) Delete(ctx context.Context, request DeletePolicy) error { + path := "/api/2.0/policies/clusters/delete" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *clusterPoliciesImpl) Edit(ctx context.Context, request EditPolicy) error { + path := "/api/2.0/policies/clusters/edit" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *clusterPoliciesImpl) Get(ctx context.Context, request GetRequest) (*Policy, error) { + var policy Policy + path := "/api/2.0/policies/clusters/get" + err := a.client.Get(ctx, path, request, &policy) + return &policy, err +} + +func (a *clusterPoliciesImpl) List(ctx context.Context) (*ListPoliciesResponse, error) { + var listPoliciesResponse ListPoliciesResponse + path := "/api/2.0/policies/clusters/list" + err := a.client.Get(ctx, path, nil, &listPoliciesResponse) + return &listPoliciesResponse, err +} diff --git a/service/clusterpolicies/interface.go b/service/clusterpolicies/interface.go index 4b8b73342..04b534ad1 100755 --- a/service/clusterpolicies/interface.go +++ b/service/clusterpolicies/interface.go @@ -30,10 +30,6 @@ import ( // // Only admin users can create, edit, and delete policies. Admin users also have // access to all policies. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type ClusterPoliciesService interface { // Create a new policy @@ -47,12 +43,6 @@ type ClusterPoliciesService interface { // run, but cannot be edited. Delete(ctx context.Context, request DeletePolicy) error - // DeleteByPolicyId calls Delete, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteByPolicyId(ctx context.Context, policyId string) error - // Update a cluster policy // // Update an existing policy for cluster. This operation may make some @@ -65,21 +55,10 @@ type ClusterPoliciesService interface { // only. Get(ctx context.Context, request GetRequest) (*Policy, error) - // GetByPolicyId calls Get, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetByPolicyId(ctx context.Context, policyId string) (*Policy, error) - // Get a cluster policy // // Returns a list of policies accessible by the requesting user. // // Use ListAll() to get all Policy instances List(ctx context.Context) (*ListPoliciesResponse, error) - - // ListAll calls List() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListAll(ctx context.Context) ([]Policy, error) } diff --git a/service/clusters/api.go b/service/clusters/api.go index f73da7216..f6cff3122 100644 --- a/service/clusters/api.go +++ b/service/clusters/api.go @@ -12,14 +12,57 @@ import ( "github.com/databricks/databricks-sdk-go/databricks/useragent" ) -func NewClusters(client *client.DatabricksClient) ClustersService { +func NewClusters(client *client.DatabricksClient) *ClustersAPI { return &ClustersAPI{ - client: client, + impl: &clustersImpl{ + client: client, + }, } } +// The Clusters API allows you to create, start, edit, list, terminate, and +// delete clusters. +// +// Databricks maps cluster node instance types to compute units known as DBUs. +// See the instance type pricing page for a list of the supported instance types +// and their corresponding DBUs. +// +// A Databricks cluster is a set of computation resources and configurations on +// which you run data engineering, data science, and data analytics workloads, +// such as production ETL pipelines, streaming analytics, ad-hoc analytics, and +// machine learning. +// +// You run these workloads as a set of commands in a notebook or as an automated +// job. Databricks makes a distinction between all-purpose clusters and job +// clusters. You use all-purpose clusters to analyze data collaboratively using +// interactive notebooks. You use job clusters to run fast and robust automated +// jobs. +// +// You can create an all-purpose cluster using the UI, CLI, or REST API. You can +// manually terminate and restart an all-purpose cluster. Multiple users can +// share such clusters to do collaborative interactive analysis. +// +// IMPORTANT: Databricks retains cluster configuration information for up to 200 +// all-purpose clusters terminated in the last 30 days and up to 30 job clusters +// recently terminated by the job scheduler. To keep an all-purpose cluster +// configuration even after it has been terminated for more than 30 days, an +// administrator can pin a cluster to the cluster list. type ClustersAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(ClustersService) + impl ClustersService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *ClustersAPI) WithImpl(impl ClustersService) *ClustersAPI { + a.impl = impl + return a +} + +// Impl returns low-level Clusters API implementation +func (a *ClustersAPI) Impl() ClustersService { + return a.impl } // Change cluster owner @@ -27,9 +70,7 @@ type ClustersAPI struct { // Change the owner of the cluster. You must be an admin to perform this // operation. func (a *ClustersAPI) ChangeOwner(ctx context.Context, request ChangeClusterOwner) error { - path := "/api/2.0/clusters/change-owner" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.ChangeOwner(ctx, request) } // Create new cluster @@ -48,13 +89,10 @@ func (a *ClustersAPI) ChangeOwner(ctx context.Context, request ChangeClusterOwne // creation will succeed. Otherwise the cluster will terminate with an // informative error message. func (a *ClustersAPI) Create(ctx context.Context, request CreateCluster) (*CreateClusterResponse, error) { - var createClusterResponse CreateClusterResponse - path := "/api/2.0/clusters/create" - err := a.client.Post(ctx, path, request, &createClusterResponse) - return &createClusterResponse, err + return a.impl.Create(ctx, request) } -// Create and wait to reach RUNNING state +// Calls [ClustersAPI.Create] and waits to reach RUNNING state // // You can override the default timeout of 20 minutes by calling adding // retries.Timeout[ClusterInfo](60*time.Minute) functional option. @@ -103,12 +141,10 @@ func (a *ClustersAPI) CreateAndWait(ctx context.Context, createCluster CreateClu // “TERMINATED“ state. If the cluster is already in a “TERMINATING“ or // “TERMINATED“ state, nothing will happen. func (a *ClustersAPI) Delete(ctx context.Context, request DeleteCluster) error { - path := "/api/2.0/clusters/delete" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.Delete(ctx, request) } -// Delete and wait to reach TERMINATED state +// Calls [ClustersAPI.Delete] and waits to reach TERMINATED state // // You can override the default timeout of 20 minutes by calling adding // retries.Timeout[ClusterInfo](60*time.Minute) functional option. @@ -157,7 +193,7 @@ func (a *ClustersAPI) DeleteAndWait(ctx context.Context, deleteCluster DeleteClu // “TERMINATED“ state. If the cluster is already in a “TERMINATING“ or // “TERMINATED“ state, nothing will happen. func (a *ClustersAPI) DeleteByClusterId(ctx context.Context, clusterId string) error { - return a.Delete(ctx, DeleteCluster{ + return a.impl.Delete(ctx, DeleteCluster{ ClusterId: clusterId, }) } @@ -184,12 +220,10 @@ func (a *ClustersAPI) DeleteByClusterIdAndWait(ctx context.Context, clusterId st // // Clusters created by the Databricks Jobs service cannot be edited. func (a *ClustersAPI) Edit(ctx context.Context, request EditCluster) error { - path := "/api/2.0/clusters/edit" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.Edit(ctx, request) } -// Edit and wait to reach RUNNING state +// Calls [ClustersAPI.Edit] and waits to reach RUNNING state // // You can override the default timeout of 20 minutes by calling adding // retries.Timeout[ClusterInfo](60*time.Minute) functional option. @@ -237,22 +271,12 @@ func (a *ClustersAPI) EditAndWait(ctx context.Context, editCluster EditCluster, // paginated. If there are more events to read, the response includes all the // nparameters necessary to request the next page of events. // -// Use EventsAll() to get all ClusterEvent instances, which will iterate over every result page. -func (a *ClustersAPI) Events(ctx context.Context, request GetEvents) (*GetEventsResponse, error) { - var getEventsResponse GetEventsResponse - path := "/api/2.0/clusters/events" - err := a.client.Post(ctx, path, request, &getEventsResponse) - return &getEventsResponse, err -} - -// EventsAll returns all ClusterEvent instances by calling Events for every result page -// // This method is generated by Databricks SDK Code Generator. func (a *ClustersAPI) EventsAll(ctx context.Context, request GetEvents) ([]ClusterEvent, error) { var results []ClusterEvent ctx = useragent.InContext(ctx, "sdk-feature", "pagination") for { - response, err := a.Events(ctx, request) + response, err := a.impl.Events(ctx, request) if err != nil { return nil, err } @@ -273,13 +297,10 @@ func (a *ClustersAPI) EventsAll(ctx context.Context, request GetEvents) ([]Clust // be described while they are running, or up to 60 days after they are // terminated. func (a *ClustersAPI) Get(ctx context.Context, request GetRequest) (*ClusterInfo, error) { - var clusterInfo ClusterInfo - path := "/api/2.0/clusters/get" - err := a.client.Get(ctx, path, request, &clusterInfo) - return &clusterInfo, err + return a.impl.Get(ctx, request) } -// Get and wait to reach RUNNING state +// Calls [ClustersAPI.Get] and waits to reach RUNNING state // // You can override the default timeout of 20 minutes by calling adding // retries.Timeout[ClusterInfo](60*time.Minute) functional option. @@ -327,7 +348,7 @@ func (a *ClustersAPI) GetAndWait(ctx context.Context, getRequest GetRequest, opt // be described while they are running, or up to 60 days after they are // terminated. func (a *ClustersAPI) GetByClusterId(ctx context.Context, clusterId string) (*ClusterInfo, error) { - return a.Get(ctx, GetRequest{ + return a.impl.Get(ctx, GetRequest{ ClusterId: clusterId, }) } @@ -351,19 +372,9 @@ func (a *ClustersAPI) GetByClusterIdAndWait(ctx context.Context, clusterId strin // clusters, all 45 terminated interactive clusters, and the 30 most recently // terminated job clusters. // -// Use ListAll() to get all ClusterInfo instances -func (a *ClustersAPI) List(ctx context.Context, request ListRequest) (*ListClustersResponse, error) { - var listClustersResponse ListClustersResponse - path := "/api/2.0/clusters/list" - err := a.client.Get(ctx, path, request, &listClustersResponse) - return &listClustersResponse, err -} - -// ListAll returns all ClusterInfo instances. This method exists for consistency purposes. -// // This method is generated by Databricks SDK Code Generator. func (a *ClustersAPI) ListAll(ctx context.Context, request ListRequest) ([]ClusterInfo, error) { - response, err := a.List(ctx, request) + response, err := a.impl.List(ctx, request) if err != nil { return nil, err } @@ -383,7 +394,7 @@ func (a *ClustersAPI) ListAll(ctx context.Context, request ListRequest) ([]Clust // clusters, all 45 terminated interactive clusters, and the 30 most recently // terminated job clusters. func (a *ClustersAPI) ListByCanUseClient(ctx context.Context, canUseClient string) (*ListClustersResponse, error) { - return a.List(ctx, ListRequest{ + return a.impl.List(ctx, ListRequest{ CanUseClient: canUseClient, }) } @@ -393,10 +404,7 @@ func (a *ClustersAPI) ListByCanUseClient(ctx context.Context, canUseClient strin // Returns a list of supported Spark node types. These node types can be used to // launch a cluster. func (a *ClustersAPI) ListNodeTypes(ctx context.Context) (*ListNodeTypesResponse, error) { - var listNodeTypesResponse ListNodeTypesResponse - path := "/api/2.0/clusters/list-node-types" - err := a.client.Get(ctx, path, nil, &listNodeTypesResponse) - return &listNodeTypesResponse, err + return a.impl.ListNodeTypes(ctx) } // List availability zones @@ -404,10 +412,7 @@ func (a *ClustersAPI) ListNodeTypes(ctx context.Context) (*ListNodeTypesResponse // Returns a list of availability zones where clusters can be created in (For // example, us-west-2a). These zones can be used to launch a cluster. func (a *ClustersAPI) ListZones(ctx context.Context) (*ListAvailableZonesResponse, error) { - var listAvailableZonesResponse ListAvailableZonesResponse - path := "/api/2.0/clusters/list-zones" - err := a.client.Get(ctx, path, nil, &listAvailableZonesResponse) - return &listAvailableZonesResponse, err + return a.impl.ListZones(ctx) } // Permanently delete cluster @@ -419,9 +424,7 @@ func (a *ClustersAPI) ListZones(ctx context.Context) (*ListAvailableZonesRespons // cluster list, and API users can no longer perform any action on permanently // deleted clusters. func (a *ClustersAPI) PermanentDelete(ctx context.Context, request PermanentDeleteCluster) error { - path := "/api/2.0/clusters/permanent-delete" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.PermanentDelete(ctx, request) } // Permanently delete cluster @@ -433,7 +436,7 @@ func (a *ClustersAPI) PermanentDelete(ctx context.Context, request PermanentDele // cluster list, and API users can no longer perform any action on permanently // deleted clusters. func (a *ClustersAPI) PermanentDeleteByClusterId(ctx context.Context, clusterId string) error { - return a.PermanentDelete(ctx, PermanentDeleteCluster{ + return a.impl.PermanentDelete(ctx, PermanentDeleteCluster{ ClusterId: clusterId, }) } @@ -444,9 +447,7 @@ func (a *ClustersAPI) PermanentDeleteByClusterId(ctx context.Context, clusterId // ListClusters API. Pinning a cluster that is already pinned will have no // effect. This API can only be called by workspace admins. func (a *ClustersAPI) Pin(ctx context.Context, request PinCluster) error { - path := "/api/2.0/clusters/pin" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.Pin(ctx, request) } // Pin cluster @@ -455,7 +456,7 @@ func (a *ClustersAPI) Pin(ctx context.Context, request PinCluster) error { // ListClusters API. Pinning a cluster that is already pinned will have no // effect. This API can only be called by workspace admins. func (a *ClustersAPI) PinByClusterId(ctx context.Context, clusterId string) error { - return a.Pin(ctx, PinCluster{ + return a.impl.Pin(ctx, PinCluster{ ClusterId: clusterId, }) } @@ -465,12 +466,10 @@ func (a *ClustersAPI) PinByClusterId(ctx context.Context, clusterId string) erro // Resizes a cluster to have a desired number of workers. This will fail unless // the cluster is in a `RUNNING` state. func (a *ClustersAPI) Resize(ctx context.Context, request ResizeCluster) error { - path := "/api/2.0/clusters/resize" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.Resize(ctx, request) } -// Resize and wait to reach RUNNING state +// Calls [ClustersAPI.Resize] and waits to reach RUNNING state // // You can override the default timeout of 20 minutes by calling adding // retries.Timeout[ClusterInfo](60*time.Minute) functional option. @@ -517,12 +516,10 @@ func (a *ClustersAPI) ResizeAndWait(ctx context.Context, resizeCluster ResizeClu // Restarts a Spark cluster with the supplied ID. If the cluster is not // currently in a `RUNNING` state, nothing will happen. func (a *ClustersAPI) Restart(ctx context.Context, request RestartCluster) error { - path := "/api/2.0/clusters/restart" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.Restart(ctx, request) } -// Restart and wait to reach RUNNING state +// Calls [ClustersAPI.Restart] and waits to reach RUNNING state // // You can override the default timeout of 20 minutes by calling adding // retries.Timeout[ClusterInfo](60*time.Minute) functional option. @@ -569,10 +566,7 @@ func (a *ClustersAPI) RestartAndWait(ctx context.Context, restartCluster Restart // Returns the list of available Spark versions. These versions can be used to // launch a cluster. func (a *ClustersAPI) SparkVersions(ctx context.Context) (*GetSparkVersionsResponse, error) { - var getSparkVersionsResponse GetSparkVersionsResponse - path := "/api/2.0/clusters/spark-versions" - err := a.client.Get(ctx, path, nil, &getSparkVersionsResponse) - return &getSparkVersionsResponse, err + return a.impl.SparkVersions(ctx) } // Start terminated cluster @@ -586,12 +580,10 @@ func (a *ClustersAPI) SparkVersions(ctx context.Context) (*GetSparkVersionsRespo // nodes. * If the cluster is not currently in a “TERMINATED“ state, nothing // will happen. * Clusters launched to run a job cannot be started. func (a *ClustersAPI) Start(ctx context.Context, request StartCluster) error { - path := "/api/2.0/clusters/start" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.Start(ctx, request) } -// Start and wait to reach RUNNING state +// Calls [ClustersAPI.Start] and waits to reach RUNNING state // // You can override the default timeout of 20 minutes by calling adding // retries.Timeout[ClusterInfo](60*time.Minute) functional option. @@ -644,7 +636,7 @@ func (a *ClustersAPI) StartAndWait(ctx context.Context, startCluster StartCluste // nodes. * If the cluster is not currently in a “TERMINATED“ state, nothing // will happen. * Clusters launched to run a job cannot be started. func (a *ClustersAPI) StartByClusterId(ctx context.Context, clusterId string) error { - return a.Start(ctx, StartCluster{ + return a.impl.Start(ctx, StartCluster{ ClusterId: clusterId, }) } @@ -661,9 +653,7 @@ func (a *ClustersAPI) StartByClusterIdAndWait(ctx context.Context, clusterId str // ListClusters API. Unpinning a cluster that is not pinned will have no effect. // This API can only be called by workspace admins. func (a *ClustersAPI) Unpin(ctx context.Context, request UnpinCluster) error { - path := "/api/2.0/clusters/unpin" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.Unpin(ctx, request) } // Unpin cluster @@ -672,7 +662,7 @@ func (a *ClustersAPI) Unpin(ctx context.Context, request UnpinCluster) error { // ListClusters API. Unpinning a cluster that is not pinned will have no effect. // This API can only be called by workspace admins. func (a *ClustersAPI) UnpinByClusterId(ctx context.Context, clusterId string) error { - return a.Unpin(ctx, UnpinCluster{ + return a.impl.Unpin(ctx, UnpinCluster{ ClusterId: clusterId, }) } diff --git a/service/clusters/impl.go b/service/clusters/impl.go new file mode 100755 index 000000000..452e0d1fc --- /dev/null +++ b/service/clusters/impl.go @@ -0,0 +1,117 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package clusters + +import ( + "context" + + "github.com/databricks/databricks-sdk-go/databricks/client" +) + +// unexported type that holds implementations of just Clusters API methods +type clustersImpl struct { + client *client.DatabricksClient +} + +func (a *clustersImpl) ChangeOwner(ctx context.Context, request ChangeClusterOwner) error { + path := "/api/2.0/clusters/change-owner" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *clustersImpl) Create(ctx context.Context, request CreateCluster) (*CreateClusterResponse, error) { + var createClusterResponse CreateClusterResponse + path := "/api/2.0/clusters/create" + err := a.client.Post(ctx, path, request, &createClusterResponse) + return &createClusterResponse, err +} + +func (a *clustersImpl) Delete(ctx context.Context, request DeleteCluster) error { + path := "/api/2.0/clusters/delete" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *clustersImpl) Edit(ctx context.Context, request EditCluster) error { + path := "/api/2.0/clusters/edit" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *clustersImpl) Events(ctx context.Context, request GetEvents) (*GetEventsResponse, error) { + var getEventsResponse GetEventsResponse + path := "/api/2.0/clusters/events" + err := a.client.Post(ctx, path, request, &getEventsResponse) + return &getEventsResponse, err +} + +func (a *clustersImpl) Get(ctx context.Context, request GetRequest) (*ClusterInfo, error) { + var clusterInfo ClusterInfo + path := "/api/2.0/clusters/get" + err := a.client.Get(ctx, path, request, &clusterInfo) + return &clusterInfo, err +} + +func (a *clustersImpl) List(ctx context.Context, request ListRequest) (*ListClustersResponse, error) { + var listClustersResponse ListClustersResponse + path := "/api/2.0/clusters/list" + err := a.client.Get(ctx, path, request, &listClustersResponse) + return &listClustersResponse, err +} + +func (a *clustersImpl) ListNodeTypes(ctx context.Context) (*ListNodeTypesResponse, error) { + var listNodeTypesResponse ListNodeTypesResponse + path := "/api/2.0/clusters/list-node-types" + err := a.client.Get(ctx, path, nil, &listNodeTypesResponse) + return &listNodeTypesResponse, err +} + +func (a *clustersImpl) ListZones(ctx context.Context) (*ListAvailableZonesResponse, error) { + var listAvailableZonesResponse ListAvailableZonesResponse + path := "/api/2.0/clusters/list-zones" + err := a.client.Get(ctx, path, nil, &listAvailableZonesResponse) + return &listAvailableZonesResponse, err +} + +func (a *clustersImpl) PermanentDelete(ctx context.Context, request PermanentDeleteCluster) error { + path := "/api/2.0/clusters/permanent-delete" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *clustersImpl) Pin(ctx context.Context, request PinCluster) error { + path := "/api/2.0/clusters/pin" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *clustersImpl) Resize(ctx context.Context, request ResizeCluster) error { + path := "/api/2.0/clusters/resize" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *clustersImpl) Restart(ctx context.Context, request RestartCluster) error { + path := "/api/2.0/clusters/restart" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *clustersImpl) SparkVersions(ctx context.Context) (*GetSparkVersionsResponse, error) { + var getSparkVersionsResponse GetSparkVersionsResponse + path := "/api/2.0/clusters/spark-versions" + err := a.client.Get(ctx, path, nil, &getSparkVersionsResponse) + return &getSparkVersionsResponse, err +} + +func (a *clustersImpl) Start(ctx context.Context, request StartCluster) error { + path := "/api/2.0/clusters/start" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *clustersImpl) Unpin(ctx context.Context, request UnpinCluster) error { + path := "/api/2.0/clusters/unpin" + err := a.client.Post(ctx, path, request, nil) + return err +} diff --git a/service/clusters/interface.go b/service/clusters/interface.go index acd49eefa..111cda0ca 100755 --- a/service/clusters/interface.go +++ b/service/clusters/interface.go @@ -4,8 +4,6 @@ package clusters import ( "context" - - "github.com/databricks/databricks-sdk-go/databricks/retries" ) // The Clusters API allows you to create, start, edit, list, terminate, and @@ -35,10 +33,6 @@ import ( // recently terminated by the job scheduler. To keep an all-purpose cluster // configuration even after it has been terminated for more than 30 days, an // administrator can pin a cluster to the cluster list. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type ClustersService interface { // Change cluster owner @@ -64,11 +58,6 @@ type ClustersService interface { // an informative error message. Create(ctx context.Context, request CreateCluster) (*CreateClusterResponse, error) - // CreateAndWait calls Create() and waits to reach RUNNING state - // - // This method is generated by Databricks SDK Code Generator. - CreateAndWait(ctx context.Context, request CreateCluster, options ...retries.Option[ClusterInfo]) (*ClusterInfo, error) - // Terminate cluster // // Terminates the Spark cluster with the specified ID. The cluster is @@ -77,21 +66,6 @@ type ClustersService interface { // ``TERMINATING`` or ``TERMINATED`` state, nothing will happen. Delete(ctx context.Context, request DeleteCluster) error - // DeleteAndWait calls Delete() and waits to reach TERMINATED state - // - // This method is generated by Databricks SDK Code Generator. - DeleteAndWait(ctx context.Context, request DeleteCluster, options ...retries.Option[ClusterInfo]) (*ClusterInfo, error) - // DeleteByClusterId calls Delete, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteByClusterId(ctx context.Context, clusterId string) error - - // DeleteByClusterIdAndWait calls DeleteByClusterId and waits until ClusterInfo is in desired state. - // - // This method is generated by Databricks SDK Code Generator. - DeleteByClusterIdAndWait(ctx context.Context, clusterId string, options ...retries.Option[ClusterInfo]) (*ClusterInfo, error) - // Update cluster configuration // // Updates the configuration of a cluster to match the provided attributes @@ -109,11 +83,6 @@ type ClustersService interface { // Clusters created by the Databricks Jobs service cannot be edited. Edit(ctx context.Context, request EditCluster) error - // EditAndWait calls Edit() and waits to reach RUNNING state - // - // This method is generated by Databricks SDK Code Generator. - EditAndWait(ctx context.Context, request EditCluster, options ...retries.Option[ClusterInfo]) (*ClusterInfo, error) - // List cluster activity events // // Retrieves a list of events about the activity of a cluster. This API is @@ -123,11 +92,6 @@ type ClustersService interface { // Use EventsAll() to get all ClusterEvent instances, which will iterate over every result page. Events(ctx context.Context, request GetEvents) (*GetEventsResponse, error) - // EventsAll calls Events() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - EventsAll(ctx context.Context, request GetEvents) ([]ClusterEvent, error) - // Get cluster info // // "Retrieves the information for a cluster given its identifier. Clusters @@ -135,21 +99,6 @@ type ClustersService interface { // terminated. Get(ctx context.Context, request GetRequest) (*ClusterInfo, error) - // GetAndWait calls Get() and waits to reach RUNNING state - // - // This method is generated by Databricks SDK Code Generator. - GetAndWait(ctx context.Context, request GetRequest, options ...retries.Option[ClusterInfo]) (*ClusterInfo, error) - // GetByClusterId calls Get, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetByClusterId(ctx context.Context, clusterId string) (*ClusterInfo, error) - - // GetByClusterIdAndWait calls GetByClusterId and waits until ClusterInfo is in desired state. - // - // This method is generated by Databricks SDK Code Generator. - GetByClusterIdAndWait(ctx context.Context, clusterId string, options ...retries.Option[ClusterInfo]) (*ClusterInfo, error) - // List all clusters // // Returns information about all pinned clusters, currently active clusters, @@ -166,16 +115,6 @@ type ClustersService interface { // Use ListAll() to get all ClusterInfo instances List(ctx context.Context, request ListRequest) (*ListClustersResponse, error) - // ListByCanUseClient calls List, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - ListByCanUseClient(ctx context.Context, canUseClient string) (*ListClustersResponse, error) - // ListAll calls List() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListAll(ctx context.Context, request ListRequest) ([]ClusterInfo, error) - // List node types // // Returns a list of supported Spark node types. These node types can be @@ -198,12 +137,6 @@ type ClustersService interface { // permanently deleted clusters. PermanentDelete(ctx context.Context, request PermanentDeleteCluster) error - // PermanentDeleteByClusterId calls PermanentDelete, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - PermanentDeleteByClusterId(ctx context.Context, clusterId string) error - // Pin cluster // // Pinning a cluster ensures that the cluster will always be returned by the @@ -211,34 +144,18 @@ type ClustersService interface { // effect. This API can only be called by workspace admins. Pin(ctx context.Context, request PinCluster) error - // PinByClusterId calls Pin, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - PinByClusterId(ctx context.Context, clusterId string) error - // Resize cluster // // Resizes a cluster to have a desired number of workers. This will fail // unless the cluster is in a `RUNNING` state. Resize(ctx context.Context, request ResizeCluster) error - // ResizeAndWait calls Resize() and waits to reach RUNNING state - // - // This method is generated by Databricks SDK Code Generator. - ResizeAndWait(ctx context.Context, request ResizeCluster, options ...retries.Option[ClusterInfo]) (*ClusterInfo, error) - // Restart cluster // // Restarts a Spark cluster with the supplied ID. If the cluster is not // currently in a `RUNNING` state, nothing will happen. Restart(ctx context.Context, request RestartCluster) error - // RestartAndWait calls Restart() and waits to reach RUNNING state - // - // This method is generated by Databricks SDK Code Generator. - RestartAndWait(ctx context.Context, request RestartCluster, options ...retries.Option[ClusterInfo]) (*ClusterInfo, error) - // List available Spark versions // // Returns the list of available Spark versions. These versions can be used @@ -258,34 +175,10 @@ type ClustersService interface { // started. Start(ctx context.Context, request StartCluster) error - // StartAndWait calls Start() and waits to reach RUNNING state - // - // This method is generated by Databricks SDK Code Generator. - StartAndWait(ctx context.Context, request StartCluster, options ...retries.Option[ClusterInfo]) (*ClusterInfo, error) - // StartByClusterId calls Start, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - StartByClusterId(ctx context.Context, clusterId string) error - - // StartByClusterIdAndWait calls StartByClusterId and waits until ClusterInfo is in desired state. - // - // This method is generated by Databricks SDK Code Generator. - StartByClusterIdAndWait(ctx context.Context, clusterId string, options ...retries.Option[ClusterInfo]) (*ClusterInfo, error) - // Unpin cluster // // Unpinning a cluster will allow the cluster to eventually be removed from // the ListClusters API. Unpinning a cluster that is not pinned will have no // effect. This API can only be called by workspace admins. Unpin(ctx context.Context, request UnpinCluster) error - - // UnpinByClusterId calls Unpin, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - UnpinByClusterId(ctx context.Context, clusterId string) error - - // GetOrCreateRunningCluster creates an autoterminating cluster if it doesn't exist - GetOrCreateRunningCluster(ctx context.Context, name string, custom ...CreateCluster) (c *ClusterInfo, err error) } diff --git a/service/clusters/utilities.go b/service/clusters/utilities.go index e5feb378a..c97c89cbe 100644 --- a/service/clusters/utilities.go +++ b/service/clusters/utilities.go @@ -25,11 +25,11 @@ func (a *ClustersAPI) GetOrCreateRunningCluster(ctx context.Context, name string err = fmt.Errorf("you can only specify 1 custom cluster conf, not %d", len(custom)) return } - clusters, err := a.List(ctx, ListRequest{}) + clusters, err := a.ListAll(ctx, ListRequest{}) if err != nil { return } - for _, cl := range clusters.Clusters { + for _, cl := range clusters { if cl.ClusterName != name { continue } @@ -73,7 +73,11 @@ func (a *ClustersAPI) GetOrCreateRunningCluster(ctx context.Context, name string NodeTypeId: smallestNodeType, AutoterminationMinutes: 10, } - if a.client.Config.IsAws() { + api, ok := a.impl.(*clustersImpl) + if !ok { + return nil, fmt.Errorf("cannot get raw clusters API") + } + if api.client.Config.IsAws() { r.AwsAttributes = &AwsAttributes{ Availability: "SPOT", } diff --git a/service/commands/api.go b/service/commands/api.go index f8cb194b0..2959a445f 100755 --- a/service/commands/api.go +++ b/service/commands/api.go @@ -12,14 +12,32 @@ import ( "github.com/databricks/databricks-sdk-go/databricks/useragent" ) -func NewCommandExecution(client *client.DatabricksClient) CommandExecutionService { +func NewCommandExecution(client *client.DatabricksClient) *CommandExecutionAPI { return &CommandExecutionAPI{ - client: client, + impl: &commandExecutionImpl{ + client: client, + }, } } +// This API allows execution of Python, Scala, SQL, or R commands on running +// Databricks Clusters. type CommandExecutionAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(CommandExecutionService) + impl CommandExecutionService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *CommandExecutionAPI) WithImpl(impl CommandExecutionService) *CommandExecutionAPI { + a.impl = impl + return a +} + +// Impl returns low-level CommandExecution API implementation +func (a *CommandExecutionAPI) Impl() CommandExecutionService { + return a.impl } // Cancel a command @@ -28,12 +46,10 @@ type CommandExecutionAPI struct { // // The command ID is obtained from a prior successful call to __execute__. func (a *CommandExecutionAPI) Cancel(ctx context.Context, request CancelCommand) error { - path := "/api/1.2/commands/cancel" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.Cancel(ctx, request) } -// Cancel and wait to reach Cancelled state +// Calls [CommandExecutionAPI.Cancel] and waits to reach Cancelled state // // You can override the default timeout of 20 minutes by calling adding // retries.Timeout[CommandStatusResponse](60*time.Minute) functional option. @@ -84,20 +100,14 @@ func (a *CommandExecutionAPI) CancelAndWait(ctx context.Context, cancelCommand C // // The command ID is obtained from a prior successful call to __execute__. func (a *CommandExecutionAPI) CommandStatus(ctx context.Context, request CommandStatusRequest) (*CommandStatusResponse, error) { - var commandStatusResponse CommandStatusResponse - path := "/api/1.2/commands/status" - err := a.client.Get(ctx, path, request, &commandStatusResponse) - return &commandStatusResponse, err + return a.impl.CommandStatus(ctx, request) } // Get status // // Gets the status for an execution context. func (a *CommandExecutionAPI) ContextStatus(ctx context.Context, request ContextStatusRequest) (*ContextStatusResponse, error) { - var contextStatusResponse ContextStatusResponse - path := "/api/1.2/contexts/status" - err := a.client.Get(ctx, path, request, &contextStatusResponse) - return &contextStatusResponse, err + return a.impl.ContextStatus(ctx, request) } // Create an execution context @@ -106,13 +116,10 @@ func (a *CommandExecutionAPI) ContextStatus(ctx context.Context, request Context // // If successful, this method returns the ID of the new execution context. func (a *CommandExecutionAPI) Create(ctx context.Context, request CreateContext) (*Created, error) { - var created Created - path := "/api/1.2/contexts/create" - err := a.client.Post(ctx, path, request, &created) - return &created, err + return a.impl.Create(ctx, request) } -// Create and wait to reach Running state +// Calls [CommandExecutionAPI.Create] and waits to reach Running state // // You can override the default timeout of 20 minutes by calling adding // retries.Timeout[ContextStatusResponse](60*time.Minute) functional option. @@ -159,9 +166,7 @@ func (a *CommandExecutionAPI) CreateAndWait(ctx context.Context, createContext C // // Deletes an execution context. func (a *CommandExecutionAPI) Destroy(ctx context.Context, request DestroyContext) error { - path := "/api/1.2/contexts/destroy" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.Destroy(ctx, request) } // Run a command @@ -172,13 +177,10 @@ func (a *CommandExecutionAPI) Destroy(ctx context.Context, request DestroyContex // If successful, it returns an ID for tracking the status of the command's // execution. func (a *CommandExecutionAPI) Execute(ctx context.Context, request Command) (*Created, error) { - var created Created - path := "/api/1.2/commands/execute" - err := a.client.Post(ctx, path, request, &created) - return &created, err + return a.impl.Execute(ctx, request) } -// Execute and wait to reach Finished or Error state +// Calls [CommandExecutionAPI.Execute] and waits to reach Finished or Error state // // You can override the default timeout of 20 minutes by calling adding // retries.Timeout[CommandStatusResponse](60*time.Minute) functional option. diff --git a/service/commands/commands.go b/service/commands/commands.go index 1ff0e150c..f95eb422c 100644 --- a/service/commands/commands.go +++ b/service/commands/commands.go @@ -31,8 +31,8 @@ func NewCommandExecutor(client *client.DatabricksClient) CommandExecutor { // CommandsHighLevelAPI exposes more friendly wrapper over command execution type CommandsHighLevelAPI struct { - clusters clusters.ClustersService - execution CommandExecutionService + clusters *clusters.ClustersAPI + execution *CommandExecutionAPI } // Execute creates a spark context and executes a command and then closes context diff --git a/service/commands/impl.go b/service/commands/impl.go new file mode 100755 index 000000000..0715956ec --- /dev/null +++ b/service/commands/impl.go @@ -0,0 +1,54 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package commands + +import ( + "context" + + "github.com/databricks/databricks-sdk-go/databricks/client" +) + +// unexported type that holds implementations of just CommandExecution API methods +type commandExecutionImpl struct { + client *client.DatabricksClient +} + +func (a *commandExecutionImpl) Cancel(ctx context.Context, request CancelCommand) error { + path := "/api/1.2/commands/cancel" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *commandExecutionImpl) CommandStatus(ctx context.Context, request CommandStatusRequest) (*CommandStatusResponse, error) { + var commandStatusResponse CommandStatusResponse + path := "/api/1.2/commands/status" + err := a.client.Get(ctx, path, request, &commandStatusResponse) + return &commandStatusResponse, err +} + +func (a *commandExecutionImpl) ContextStatus(ctx context.Context, request ContextStatusRequest) (*ContextStatusResponse, error) { + var contextStatusResponse ContextStatusResponse + path := "/api/1.2/contexts/status" + err := a.client.Get(ctx, path, request, &contextStatusResponse) + return &contextStatusResponse, err +} + +func (a *commandExecutionImpl) Create(ctx context.Context, request CreateContext) (*Created, error) { + var created Created + path := "/api/1.2/contexts/create" + err := a.client.Post(ctx, path, request, &created) + return &created, err +} + +func (a *commandExecutionImpl) Destroy(ctx context.Context, request DestroyContext) error { + path := "/api/1.2/contexts/destroy" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *commandExecutionImpl) Execute(ctx context.Context, request Command) (*Created, error) { + var created Created + path := "/api/1.2/commands/execute" + err := a.client.Post(ctx, path, request, &created) + return &created, err +} diff --git a/service/commands/interface.go b/service/commands/interface.go index efa33077a..9f296aa88 100755 --- a/service/commands/interface.go +++ b/service/commands/interface.go @@ -4,16 +4,10 @@ package commands import ( "context" - - "github.com/databricks/databricks-sdk-go/databricks/retries" ) // This API allows execution of Python, Scala, SQL, or R commands on running // Databricks Clusters. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type CommandExecutionService interface { // Cancel a command @@ -23,11 +17,6 @@ type CommandExecutionService interface { // The command ID is obtained from a prior successful call to __execute__. Cancel(ctx context.Context, request CancelCommand) error - // CancelAndWait calls Cancel() and waits to reach Cancelled state - // - // This method is generated by Databricks SDK Code Generator. - CancelAndWait(ctx context.Context, request CancelCommand, options ...retries.Option[CommandStatusResponse]) (*CommandStatusResponse, error) - // Get command info // // Gets the status of and, if available, the results from a currently @@ -48,11 +37,6 @@ type CommandExecutionService interface { // If successful, this method returns the ID of the new execution context. Create(ctx context.Context, request CreateContext) (*Created, error) - // CreateAndWait calls Create() and waits to reach Running state - // - // This method is generated by Databricks SDK Code Generator. - CreateAndWait(ctx context.Context, request CreateContext, options ...retries.Option[ContextStatusResponse]) (*ContextStatusResponse, error) - // Delete an execution context // // Deletes an execution context. @@ -66,9 +50,4 @@ type CommandExecutionService interface { // If successful, it returns an ID for tracking the status of the command's // execution. Execute(ctx context.Context, request Command) (*Created, error) - - // ExecuteAndWait calls Execute() and waits to reach Finished or Error state - // - // This method is generated by Databricks SDK Code Generator. - ExecuteAndWait(ctx context.Context, request Command, options ...retries.Option[CommandStatusResponse]) (*CommandStatusResponse, error) } diff --git a/service/dbfs/api.go b/service/dbfs/api.go index 9e839525a..12e7049a2 100755 --- a/service/dbfs/api.go +++ b/service/dbfs/api.go @@ -8,14 +8,32 @@ import ( "github.com/databricks/databricks-sdk-go/databricks/client" ) -func NewDbfs(client *client.DatabricksClient) DbfsService { +func NewDbfs(client *client.DatabricksClient) *DbfsAPI { return &DbfsAPI{ - client: client, + impl: &dbfsImpl{ + client: client, + }, } } +// DBFS API makes it simple to interact with various data sources without having +// to include a users credentials every time to read a file. type DbfsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(DbfsService) + impl DbfsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *DbfsAPI) WithImpl(impl DbfsService) *DbfsAPI { + a.impl = impl + return a +} + +// Impl returns low-level Dbfs API implementation +func (a *DbfsAPI) Impl() DbfsService { + return a.impl } // Append data block @@ -29,9 +47,7 @@ type DbfsAPI struct { // // Example of request: ``` { "data": "ZGF0YWJyaWNrcwo=", "handle": 7904256 } ``` func (a *DbfsAPI) AddBlock(ctx context.Context, request AddBlock) error { - path := "/api/2.0/dbfs/add-block" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.AddBlock(ctx, request) } // Close the stream @@ -39,9 +55,7 @@ func (a *DbfsAPI) AddBlock(ctx context.Context, request AddBlock) error { // Closes the stream specified by the input handle. If the handle does not // exist, this call throws an exception with “RESOURCE_DOES_NOT_EXIST“. func (a *DbfsAPI) Close(ctx context.Context, request Close) error { - path := "/api/2.0/dbfs/close" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.Close(ctx, request) } // Close the stream @@ -49,7 +63,7 @@ func (a *DbfsAPI) Close(ctx context.Context, request Close) error { // Closes the stream specified by the input handle. If the handle does not // exist, this call throws an exception with “RESOURCE_DOES_NOT_EXIST“. func (a *DbfsAPI) CloseByHandle(ctx context.Context, handle int64) error { - return a.Close(ctx, Close{ + return a.impl.Close(ctx, Close{ Handle: handle, }) } @@ -67,10 +81,7 @@ func (a *DbfsAPI) CloseByHandle(ctx context.Context, handle int64) error { // calls with the handle you have. 3. Issue a `close` call with the handle you // have. func (a *DbfsAPI) Create(ctx context.Context, request Create) (*CreateResponse, error) { - var createResponse CreateResponse - path := "/api/2.0/dbfs/create" - err := a.client.Post(ctx, path, request, &createResponse) - return &createResponse, err + return a.impl.Create(ctx, request) } // Delete a file/directory @@ -81,9 +92,7 @@ func (a *DbfsAPI) Create(ctx context.Context, request Create) (*CreateResponse, // This all throws an exception with “IO_ERROR“ if the path is a non-empty // directory and recursive is set to `false` or other similar errors.", func (a *DbfsAPI) Delete(ctx context.Context, request Delete) error { - path := "/api/2.0/dbfs/delete" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.Delete(ctx, request) } // Get the information of a file or directory @@ -92,10 +101,7 @@ func (a *DbfsAPI) Delete(ctx context.Context, request Delete) error { // does not exist, this call throws an exception with // “RESOURCE_DOES_NOT_EXIST“. func (a *DbfsAPI) GetStatus(ctx context.Context, request GetStatusRequest) (*FileInfo, error) { - var fileInfo FileInfo - path := "/api/2.0/dbfs/get-status" - err := a.client.Get(ctx, path, request, &fileInfo) - return &fileInfo, err + return a.impl.GetStatus(ctx, request) } // Get the information of a file or directory @@ -104,7 +110,7 @@ func (a *DbfsAPI) GetStatus(ctx context.Context, request GetStatusRequest) (*Fil // does not exist, this call throws an exception with // “RESOURCE_DOES_NOT_EXIST“. func (a *DbfsAPI) GetStatusByPath(ctx context.Context, path string) (*FileInfo, error) { - return a.GetStatus(ctx, GetStatusRequest{ + return a.impl.GetStatus(ctx, GetStatusRequest{ Path: path, }) } @@ -120,19 +126,9 @@ func (a *DbfsAPI) GetStatusByPath(ctx context.Context, path string) (*FileInfo, // ``` { "files": [ { "path": "/a.cpp", "is_dir": false, "file_size\": 261 }, { // "path": "/databricks-results", "is_dir": true, "file_size\": 0 } ] } ``` // -// Use ListAll() to get all FileInfo instances -func (a *DbfsAPI) List(ctx context.Context, request ListRequest) (*ListStatusResponse, error) { - var listStatusResponse ListStatusResponse - path := "/api/2.0/dbfs/list" - err := a.client.Get(ctx, path, request, &listStatusResponse) - return &listStatusResponse, err -} - -// ListAll returns all FileInfo instances. This method exists for consistency purposes. -// // This method is generated by Databricks SDK Code Generator. func (a *DbfsAPI) ListAll(ctx context.Context, request ListRequest) ([]FileInfo, error) { - response, err := a.List(ctx, request) + response, err := a.impl.List(ctx, request) if err != nil { return nil, err } @@ -150,7 +146,7 @@ func (a *DbfsAPI) ListAll(ctx context.Context, request ListRequest) ([]FileInfo, // ``` { "files": [ { "path": "/a.cpp", "is_dir": false, "file_size\": 261 }, { // "path": "/databricks-results", "is_dir": true, "file_size\": 0 } ] } ``` func (a *DbfsAPI) ListByPath(ctx context.Context, path string) (*ListStatusResponse, error) { - return a.List(ctx, ListRequest{ + return a.impl.List(ctx, ListRequest{ Path: path, }) } @@ -163,9 +159,7 @@ func (a *DbfsAPI) ListByPath(ctx context.Context, path string) (*ListStatusRespo // this operation fails, it might have succeeded in creating some of the // necessary parent directories.", func (a *DbfsAPI) Mkdirs(ctx context.Context, request MkDirs) error { - path := "/api/2.0/dbfs/mkdirs" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.Mkdirs(ctx, request) } // Create a directory @@ -176,7 +170,7 @@ func (a *DbfsAPI) Mkdirs(ctx context.Context, request MkDirs) error { // this operation fails, it might have succeeded in creating some of the // necessary parent directories.", func (a *DbfsAPI) MkdirsByPath(ctx context.Context, path string) error { - return a.Mkdirs(ctx, MkDirs{ + return a.impl.Mkdirs(ctx, MkDirs{ Path: path, }) } @@ -190,9 +184,7 @@ func (a *DbfsAPI) MkdirsByPath(ctx context.Context, path string) error { // given source path is a directory, this call always recursively moves all // files.", func (a *DbfsAPI) Move(ctx context.Context, request Move) error { - path := "/api/2.0/dbfs/move" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.Move(ctx, request) } // Upload a file @@ -219,9 +211,7 @@ func (a *DbfsAPI) Move(ctx context.Context, request Move) error { // If you want to upload large files, use the streaming upload. For details, see // :method:create, :method:addBlock, :method:close. func (a *DbfsAPI) Put(ctx context.Context, request Put) error { - path := "/api/2.0/dbfs/put" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.Put(ctx, request) } // Get the contents of a file @@ -235,8 +225,5 @@ func (a *DbfsAPI) Put(ctx context.Context, request Put) error { // If “offset + length“ exceeds the number of bytes in a file, it reads the // contents until the end of file.", func (a *DbfsAPI) Read(ctx context.Context, request ReadRequest) (*ReadResponse, error) { - var readResponse ReadResponse - path := "/api/2.0/dbfs/read" - err := a.client.Get(ctx, path, request, &readResponse) - return &readResponse, err + return a.impl.Read(ctx, request) } diff --git a/service/dbfs/impl.go b/service/dbfs/impl.go new file mode 100755 index 000000000..6227569ee --- /dev/null +++ b/service/dbfs/impl.go @@ -0,0 +1,78 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package dbfs + +import ( + "context" + + "github.com/databricks/databricks-sdk-go/databricks/client" +) + +// unexported type that holds implementations of just Dbfs API methods +type dbfsImpl struct { + client *client.DatabricksClient +} + +func (a *dbfsImpl) AddBlock(ctx context.Context, request AddBlock) error { + path := "/api/2.0/dbfs/add-block" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *dbfsImpl) Close(ctx context.Context, request Close) error { + path := "/api/2.0/dbfs/close" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *dbfsImpl) Create(ctx context.Context, request Create) (*CreateResponse, error) { + var createResponse CreateResponse + path := "/api/2.0/dbfs/create" + err := a.client.Post(ctx, path, request, &createResponse) + return &createResponse, err +} + +func (a *dbfsImpl) Delete(ctx context.Context, request Delete) error { + path := "/api/2.0/dbfs/delete" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *dbfsImpl) GetStatus(ctx context.Context, request GetStatusRequest) (*FileInfo, error) { + var fileInfo FileInfo + path := "/api/2.0/dbfs/get-status" + err := a.client.Get(ctx, path, request, &fileInfo) + return &fileInfo, err +} + +func (a *dbfsImpl) List(ctx context.Context, request ListRequest) (*ListStatusResponse, error) { + var listStatusResponse ListStatusResponse + path := "/api/2.0/dbfs/list" + err := a.client.Get(ctx, path, request, &listStatusResponse) + return &listStatusResponse, err +} + +func (a *dbfsImpl) Mkdirs(ctx context.Context, request MkDirs) error { + path := "/api/2.0/dbfs/mkdirs" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *dbfsImpl) Move(ctx context.Context, request Move) error { + path := "/api/2.0/dbfs/move" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *dbfsImpl) Put(ctx context.Context, request Put) error { + path := "/api/2.0/dbfs/put" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *dbfsImpl) Read(ctx context.Context, request ReadRequest) (*ReadResponse, error) { + var readResponse ReadResponse + path := "/api/2.0/dbfs/read" + err := a.client.Get(ctx, path, request, &readResponse) + return &readResponse, err +} diff --git a/service/dbfs/interface.go b/service/dbfs/interface.go index 7c7bc0c75..f08076f3e 100755 --- a/service/dbfs/interface.go +++ b/service/dbfs/interface.go @@ -4,15 +4,10 @@ package dbfs import ( "context" - "io" ) // DBFS API makes it simple to interact with various data sources without having // to include a users credentials every time to read a file. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type DbfsService interface { // Append data block @@ -34,12 +29,6 @@ type DbfsService interface { // exist, this call throws an exception with ``RESOURCE_DOES_NOT_EXIST``. Close(ctx context.Context, request Close) error - // CloseByHandle calls Close, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - CloseByHandle(ctx context.Context, handle int64) error - // Open a stream // // "Opens a stream to write to a file and returns a handle to this stream. @@ -70,12 +59,6 @@ type DbfsService interface { // ``RESOURCE_DOES_NOT_EXIST``. GetStatus(ctx context.Context, request GetStatusRequest) (*FileInfo, error) - // GetStatusByPath calls GetStatus, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetStatusByPath(ctx context.Context, path string) (*FileInfo, error) - // List directory contents or file details // // Lists the contents of a directory, or details of a file. If the file or @@ -91,16 +74,6 @@ type DbfsService interface { // Use ListAll() to get all FileInfo instances List(ctx context.Context, request ListRequest) (*ListStatusResponse, error) - // ListByPath calls List, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - ListByPath(ctx context.Context, path string) (*ListStatusResponse, error) - // ListAll calls List() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListAll(ctx context.Context, request ListRequest) ([]FileInfo, error) - // Create a directory // // Creates the given directory and necessary parent directories if they do @@ -110,12 +83,6 @@ type DbfsService interface { // some of the necessary parent directories.", Mkdirs(ctx context.Context, request MkDirs) error - // MkdirsByPath calls Mkdirs, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - MkdirsByPath(ctx context.Context, path string) error - // Move a file // // Moves a file from one location to another location within DBFS. If the @@ -163,9 +130,4 @@ type DbfsService interface { // If ``offset + length`` exceeds the number of bytes in a file, it reads // the contents until the end of file.", Read(ctx context.Context, request ReadRequest) (*ReadResponse, error) - - // Overwrite uploads a file from supplied `io.Reader` - Overwrite(ctx context.Context, path string, r io.Reader) error - // Open returns `io.Reader` to download file in chunks - Open(ctx context.Context, path string) (*FileReader, error) } diff --git a/service/dbsql/api.go b/service/dbsql/api.go index 47df83438..d3c452414 100755 --- a/service/dbsql/api.go +++ b/service/dbsql/api.go @@ -4,20 +4,39 @@ package dbsql import ( "context" - "fmt" "github.com/databricks/databricks-sdk-go/databricks/client" "github.com/databricks/databricks-sdk-go/databricks/useragent" ) -func NewAlerts(client *client.DatabricksClient) AlertsService { +func NewAlerts(client *client.DatabricksClient) *AlertsAPI { return &AlertsAPI{ - client: client, + impl: &alertsImpl{ + client: client, + }, } } +// The alerts API can be used to perform CRUD operations on alerts. An alert is +// a Databricks SQL object that periodically runs a query, evaluates a condition +// of its result, and notifies one or more users and/or alert destinations if +// the condition was met. type AlertsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(AlertsService) + impl AlertsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *AlertsAPI) WithImpl(impl AlertsService) *AlertsAPI { + a.impl = impl + return a +} + +// Impl returns low-level Alerts API implementation +func (a *AlertsAPI) Impl() AlertsService { + return a.impl } // Create an alert @@ -26,10 +45,7 @@ type AlertsAPI struct { // a query, evaluates a condition of its result, and notifies users or alert // destinations if the condition was met. func (a *AlertsAPI) CreateAlert(ctx context.Context, request EditAlert) (*Alert, error) { - var alert Alert - path := "/api/2.0/preview/sql/alerts" - err := a.client.Post(ctx, path, request, &alert) - return &alert, err + return a.impl.CreateAlert(ctx, request) } // Create a refresh schedule @@ -38,10 +54,7 @@ func (a *AlertsAPI) CreateAlert(ctx context.Context, request EditAlert) (*Alert, // // **Note:** The structure of refresh schedules is subject to change. func (a *AlertsAPI) CreateSchedule(ctx context.Context, request CreateRefreshSchedule) (*RefreshSchedule, error) { - var refreshSchedule RefreshSchedule - path := fmt.Sprintf("/api/2.0/preview/sql/alerts/%v/refresh-schedules", request.AlertId) - err := a.client.Post(ctx, path, request, &refreshSchedule) - return &refreshSchedule, err + return a.impl.CreateSchedule(ctx, request) } // Delete an alert @@ -50,9 +63,7 @@ func (a *AlertsAPI) CreateSchedule(ctx context.Context, request CreateRefreshSch // restored. **Note:** Unlike queries and dashboards, alerts cannot be moved to // the trash. func (a *AlertsAPI) DeleteAlert(ctx context.Context, request DeleteAlertRequest) error { - path := fmt.Sprintf("/api/2.0/preview/sql/alerts/%v", request.AlertId) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteAlert(ctx, request) } // Delete an alert @@ -61,7 +72,7 @@ func (a *AlertsAPI) DeleteAlert(ctx context.Context, request DeleteAlertRequest) // restored. **Note:** Unlike queries and dashboards, alerts cannot be moved to // the trash. func (a *AlertsAPI) DeleteAlertByAlertId(ctx context.Context, alertId string) error { - return a.DeleteAlert(ctx, DeleteAlertRequest{ + return a.impl.DeleteAlert(ctx, DeleteAlertRequest{ AlertId: alertId, }) } @@ -71,9 +82,7 @@ func (a *AlertsAPI) DeleteAlertByAlertId(ctx context.Context, alertId string) er // Deletes an alert's refresh schedule. The refresh schedule specifies when to // refresh and evaluate the associated query result. func (a *AlertsAPI) DeleteSchedule(ctx context.Context, request DeleteScheduleRequest) error { - path := fmt.Sprintf("/api/2.0/preview/sql/alerts/%v/refresh-schedules/%v", request.AlertId, request.ScheduleId) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteSchedule(ctx, request) } // Delete a refresh schedule @@ -81,7 +90,7 @@ func (a *AlertsAPI) DeleteSchedule(ctx context.Context, request DeleteScheduleRe // Deletes an alert's refresh schedule. The refresh schedule specifies when to // refresh and evaluate the associated query result. func (a *AlertsAPI) DeleteScheduleByAlertIdAndScheduleId(ctx context.Context, alertId string, scheduleId string) error { - return a.DeleteSchedule(ctx, DeleteScheduleRequest{ + return a.impl.DeleteSchedule(ctx, DeleteScheduleRequest{ AlertId: alertId, ScheduleId: scheduleId, }) @@ -91,17 +100,14 @@ func (a *AlertsAPI) DeleteScheduleByAlertIdAndScheduleId(ctx context.Context, al // // Gets an alert. func (a *AlertsAPI) GetAlert(ctx context.Context, request GetAlertRequest) (*Alert, error) { - var alert Alert - path := fmt.Sprintf("/api/2.0/preview/sql/alerts/%v", request.AlertId) - err := a.client.Get(ctx, path, request, &alert) - return &alert, err + return a.impl.GetAlert(ctx, request) } // Get an alert // // Gets an alert. func (a *AlertsAPI) GetAlertByAlertId(ctx context.Context, alertId string) (*Alert, error) { - return a.GetAlert(ctx, GetAlertRequest{ + return a.impl.GetAlert(ctx, GetAlertRequest{ AlertId: alertId, }) } @@ -113,10 +119,7 @@ func (a *AlertsAPI) GetAlertByAlertId(ctx context.Context, alertId string) (*Ale // recipient is specified by either the `user` field or the `destination` field. // The `user` field is ignored if `destination` is non-`null`. func (a *AlertsAPI) GetSubscriptions(ctx context.Context, request GetSubscriptionsRequest) ([]Subscription, error) { - var subscriptionList []Subscription - path := fmt.Sprintf("/api/2.0/preview/sql/alerts/%v/subscriptions", request.AlertId) - err := a.client.Get(ctx, path, request, &subscriptionList) - return subscriptionList, err + return a.impl.GetSubscriptions(ctx, request) } // Get an alert's subscriptions @@ -126,7 +129,7 @@ func (a *AlertsAPI) GetSubscriptions(ctx context.Context, request GetSubscriptio // recipient is specified by either the `user` field or the `destination` field. // The `user` field is ignored if `destination` is non-`null`. func (a *AlertsAPI) GetSubscriptionsByAlertId(ctx context.Context, alertId string) ([]Subscription, error) { - return a.GetSubscriptions(ctx, GetSubscriptionsRequest{ + return a.impl.GetSubscriptions(ctx, GetSubscriptionsRequest{ AlertId: alertId, }) } @@ -135,10 +138,7 @@ func (a *AlertsAPI) GetSubscriptionsByAlertId(ctx context.Context, alertId strin // // Gets a list of alerts. func (a *AlertsAPI) ListAlerts(ctx context.Context) ([]Alert, error) { - var alertList []Alert - path := "/api/2.0/preview/sql/alerts" - err := a.client.Get(ctx, path, nil, &alertList) - return alertList, err + return a.impl.ListAlerts(ctx) } // Get refresh schedules @@ -151,10 +151,7 @@ func (a *AlertsAPI) ListAlerts(ctx context.Context) ([]Alert, error) { // schedule per alert is currently supported. The structure of refresh schedules // is subject to change. func (a *AlertsAPI) ListSchedules(ctx context.Context, request ListSchedulesRequest) ([]RefreshSchedule, error) { - var refreshScheduleList []RefreshSchedule - path := fmt.Sprintf("/api/2.0/preview/sql/alerts/%v/refresh-schedules", request.AlertId) - err := a.client.Get(ctx, path, request, &refreshScheduleList) - return refreshScheduleList, err + return a.impl.ListSchedules(ctx, request) } // Get refresh schedules @@ -167,33 +164,28 @@ func (a *AlertsAPI) ListSchedules(ctx context.Context, request ListSchedulesRequ // schedule per alert is currently supported. The structure of refresh schedules // is subject to change. func (a *AlertsAPI) ListSchedulesByAlertId(ctx context.Context, alertId string) ([]RefreshSchedule, error) { - return a.ListSchedules(ctx, ListSchedulesRequest{ + return a.impl.ListSchedules(ctx, ListSchedulesRequest{ AlertId: alertId, }) } // Subscribe to an alert func (a *AlertsAPI) Subscribe(ctx context.Context, request CreateSubscription) (*Subscription, error) { - var subscription Subscription - path := fmt.Sprintf("/api/2.0/preview/sql/alerts/%v/subscriptions", request.AlertId) - err := a.client.Post(ctx, path, request, &subscription) - return &subscription, err + return a.impl.Subscribe(ctx, request) } // Unsubscribe to an alert // // Unsubscribes a user or a destination to an alert. func (a *AlertsAPI) Unsubscribe(ctx context.Context, request UnsubscribeRequest) error { - path := fmt.Sprintf("/api/2.0/preview/sql/alerts/%v/subscriptions/%v", request.AlertId, request.SubscriptionId) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.Unsubscribe(ctx, request) } // Unsubscribe to an alert // // Unsubscribes a user or a destination to an alert. func (a *AlertsAPI) UnsubscribeByAlertIdAndSubscriptionId(ctx context.Context, alertId string, subscriptionId string) error { - return a.Unsubscribe(ctx, UnsubscribeRequest{ + return a.impl.Unsubscribe(ctx, UnsubscribeRequest{ AlertId: alertId, SubscriptionId: subscriptionId, }) @@ -203,27 +195,43 @@ func (a *AlertsAPI) UnsubscribeByAlertIdAndSubscriptionId(ctx context.Context, a // // Updates an alert. func (a *AlertsAPI) UpdateAlert(ctx context.Context, request EditAlert) error { - path := fmt.Sprintf("/api/2.0/preview/sql/alerts/%v", request.AlertId) - err := a.client.Put(ctx, path, request) - return err + return a.impl.UpdateAlert(ctx, request) } -func NewDashboards(client *client.DatabricksClient) DashboardsService { +func NewDashboards(client *client.DatabricksClient) *DashboardsAPI { return &DashboardsAPI{ - client: client, + impl: &dashboardsImpl{ + client: client, + }, } } +// In general, there is little need to modify dashboards using the API. However, +// it can be useful to use dashboard objects to look-up a collection of related +// query IDs. The API can also be used to duplicate multiple dashboards at once +// since you can get a dashboard definition with a GET request and then POST it +// to create a new one. type DashboardsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(DashboardsService) + impl DashboardsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *DashboardsAPI) WithImpl(impl DashboardsService) *DashboardsAPI { + a.impl = impl + return a +} + +// Impl returns low-level Dashboards API implementation +func (a *DashboardsAPI) Impl() DashboardsService { + return a.impl } // Create a dashboard object func (a *DashboardsAPI) CreateDashboard(ctx context.Context, request CreateDashboardRequest) (*Dashboard, error) { - var dashboard Dashboard - path := "/api/2.0/preview/sql/dashboards" - err := a.client.Post(ctx, path, request, &dashboard) - return &dashboard, err + return a.impl.CreateDashboard(ctx, request) } // Remove a dashboard @@ -231,9 +239,7 @@ func (a *DashboardsAPI) CreateDashboard(ctx context.Context, request CreateDashb // Moves a dashboard to the trash. Trashed dashboards do not appear in list // views or searches, and cannot be shared. func (a *DashboardsAPI) DeleteDashboard(ctx context.Context, request DeleteDashboardRequest) error { - path := fmt.Sprintf("/api/2.0/preview/sql/dashboards/%v", request.DashboardId) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteDashboard(ctx, request) } // Remove a dashboard @@ -241,7 +247,7 @@ func (a *DashboardsAPI) DeleteDashboard(ctx context.Context, request DeleteDashb // Moves a dashboard to the trash. Trashed dashboards do not appear in list // views or searches, and cannot be shared. func (a *DashboardsAPI) DeleteDashboardByDashboardId(ctx context.Context, dashboardId string) error { - return a.DeleteDashboard(ctx, DeleteDashboardRequest{ + return a.impl.DeleteDashboard(ctx, DeleteDashboardRequest{ DashboardId: dashboardId, }) } @@ -251,10 +257,7 @@ func (a *DashboardsAPI) DeleteDashboardByDashboardId(ctx context.Context, dashbo // Returns a JSON representation of a dashboard object, including its // visualization and query objects. func (a *DashboardsAPI) GetDashboard(ctx context.Context, request GetDashboardRequest) (*Dashboard, error) { - var dashboard Dashboard - path := fmt.Sprintf("/api/2.0/preview/sql/dashboards/%v", request.DashboardId) - err := a.client.Get(ctx, path, request, &dashboard) - return &dashboard, err + return a.impl.GetDashboard(ctx, request) } // Retrieve a definition @@ -262,7 +265,7 @@ func (a *DashboardsAPI) GetDashboard(ctx context.Context, request GetDashboardRe // Returns a JSON representation of a dashboard object, including its // visualization and query objects. func (a *DashboardsAPI) GetDashboardByDashboardId(ctx context.Context, dashboardId string) (*Dashboard, error) { - return a.GetDashboard(ctx, GetDashboardRequest{ + return a.impl.GetDashboard(ctx, GetDashboardRequest{ DashboardId: dashboardId, }) } @@ -271,23 +274,13 @@ func (a *DashboardsAPI) GetDashboardByDashboardId(ctx context.Context, dashboard // // Fetch a paginated list of dashboard objects. // -// Use ListDashboardsAll() to get all Dashboard instances, which will iterate over every result page. -func (a *DashboardsAPI) ListDashboards(ctx context.Context, request ListDashboardsRequest) (*ListDashboardsResponse, error) { - var listDashboardsResponse ListDashboardsResponse - path := "/api/2.0/preview/sql/dashboards" - err := a.client.Get(ctx, path, request, &listDashboardsResponse) - return &listDashboardsResponse, err -} - -// ListDashboardsAll returns all Dashboard instances by calling ListDashboards for every result page -// // This method is generated by Databricks SDK Code Generator. func (a *DashboardsAPI) ListDashboardsAll(ctx context.Context, request ListDashboardsRequest) ([]Dashboard, error) { var results []Dashboard ctx = useragent.InContext(ctx, "sdk-feature", "pagination") request.Page = 1 // start iterating from the first page for { - response, err := a.ListDashboards(ctx, request) + response, err := a.impl.ListDashboards(ctx, request) if err != nil { return nil, err } @@ -306,19 +299,43 @@ func (a *DashboardsAPI) ListDashboardsAll(ctx context.Context, request ListDashb // // A restored dashboard appears in list views and searches and can be shared. func (a *DashboardsAPI) RestoreDashboard(ctx context.Context, request RestoreDashboardRequest) error { - path := fmt.Sprintf("/api/2.0/preview/sql/dashboards/trash/%v", request.DashboardId) - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.RestoreDashboard(ctx, request) } -func NewDataSources(client *client.DatabricksClient) DataSourcesService { +func NewDataSources(client *client.DatabricksClient) *DataSourcesAPI { return &DataSourcesAPI{ - client: client, + impl: &dataSourcesImpl{ + client: client, + }, } } +// This API is provided to assist you in making new query objects. When creating +// a query object, you may optionally specify a `data_source_id` for the SQL +// warehouse against which it will run. If you don't already know the +// `data_source_id` for your desired SQL warehouse, this API will help you find +// it. +// +// This API does not support searches. It returns the full list of SQL +// warehouses in your workspace. We advise you to use any text editor, REST +// client, or `grep` to search the response from this API for the name of your +// SQL warehouse as it appears in Databricks SQL. type DataSourcesAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(DataSourcesService) + impl DataSourcesService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *DataSourcesAPI) WithImpl(impl DataSourcesService) *DataSourcesAPI { + a.impl = impl + return a +} + +// Impl returns low-level DataSources API implementation +func (a *DataSourcesAPI) Impl() DataSourcesService { + return a.impl } // Get a list of SQL warehouses @@ -327,20 +344,46 @@ type DataSourcesAPI struct { // fields that appear in this API response are enumerated for clarity. However, // you need only a SQL warehouse's `id` to create new queries against it. func (a *DataSourcesAPI) ListDataSources(ctx context.Context) ([]DataSource, error) { - var dataSourceList []DataSource - path := "/api/2.0/preview/sql/data_sources" - err := a.client.Get(ctx, path, nil, &dataSourceList) - return dataSourceList, err + return a.impl.ListDataSources(ctx) } -func NewDbsqlPermissions(client *client.DatabricksClient) DbsqlPermissionsService { +func NewDbsqlPermissions(client *client.DatabricksClient) *DbsqlPermissionsAPI { return &DbsqlPermissionsAPI{ - client: client, + impl: &dbsqlPermissionsImpl{ + client: client, + }, } } +// The SQL Permissions API is similar to the endpoints of the +// :method:permissions/setobjectpermissions. However, this exposes only one +// endpoint, which gets the Access Control List for a given object. You cannot +// modify any permissions using this API. +// +// There are three levels of permission: +// +// - `CAN_VIEW`: Allows read-only access +// +// - `CAN_RUN`: Allows read access and run access (superset of `CAN_VIEW`) +// +// - `CAN_MANAGE`: Allows all actions: read, run, edit, delete, modify +// permissions (superset of `CAN_RUN`) type DbsqlPermissionsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(DbsqlPermissionsService) + impl DbsqlPermissionsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *DbsqlPermissionsAPI) WithImpl(impl DbsqlPermissionsService) *DbsqlPermissionsAPI { + a.impl = impl + return a +} + +// Impl returns low-level DbsqlPermissions API implementation +func (a *DbsqlPermissionsAPI) Impl() DbsqlPermissionsService { + return a.impl } // Get object ACL @@ -348,10 +391,7 @@ type DbsqlPermissionsAPI struct { // Gets a JSON representation of the access control list (ACL) for a specified // object. func (a *DbsqlPermissionsAPI) GetPermissions(ctx context.Context, request GetPermissionsRequest) (*GetPermissionsResponse, error) { - var getPermissionsResponse GetPermissionsResponse - path := fmt.Sprintf("/api/2.0/preview/sql/permissions/%v/%v", request.ObjectType, request.ObjectId) - err := a.client.Get(ctx, path, request, &getPermissionsResponse) - return &getPermissionsResponse, err + return a.impl.GetPermissions(ctx, request) } // Get object ACL @@ -359,7 +399,7 @@ func (a *DbsqlPermissionsAPI) GetPermissions(ctx context.Context, request GetPer // Gets a JSON representation of the access control list (ACL) for a specified // object. func (a *DbsqlPermissionsAPI) GetPermissionsByObjectTypeAndObjectId(ctx context.Context, objectType ObjectTypePlural, objectId string) (*GetPermissionsResponse, error) { - return a.GetPermissions(ctx, GetPermissionsRequest{ + return a.impl.GetPermissions(ctx, GetPermissionsRequest{ ObjectType: objectType, ObjectId: objectId, }) @@ -370,10 +410,7 @@ func (a *DbsqlPermissionsAPI) GetPermissionsByObjectTypeAndObjectId(ctx context. // Sets the access control list (ACL) for a specified object. This operation // will complete rewrite the ACL. func (a *DbsqlPermissionsAPI) SetPermissions(ctx context.Context, request SetPermissionsRequest) (*SetPermissionsResponse, error) { - var setPermissionsResponse SetPermissionsResponse - path := fmt.Sprintf("/api/2.0/preview/sql/permissions/%v/%v", request.ObjectType, request.ObjectId) - err := a.client.Post(ctx, path, request, &setPermissionsResponse) - return &setPermissionsResponse, err + return a.impl.SetPermissions(ctx, request) } // Transfer object ownership @@ -381,20 +418,36 @@ func (a *DbsqlPermissionsAPI) SetPermissions(ctx context.Context, request SetPer // Transfers ownership of a dashboard, query, or alert to an active user. // Requires an admin API key. func (a *DbsqlPermissionsAPI) TransferOwnership(ctx context.Context, request TransferOwnershipRequest) (*Success, error) { - var success Success - path := fmt.Sprintf("/api/2.0/preview/sql/permissions/%v/%v/transfer", request.ObjectType, request.ObjectId) - err := a.client.Post(ctx, path, request, &success) - return &success, err + return a.impl.TransferOwnership(ctx, request) } -func NewQueries(client *client.DatabricksClient) QueriesService { +func NewQueries(client *client.DatabricksClient) *QueriesAPI { return &QueriesAPI{ - client: client, + impl: &queriesImpl{ + client: client, + }, } } +// These endpoints are used for CRUD operations on query definitions. Query +// definitions include the target SQL warehouse, query text, name, description, +// tags, execution schedule, parameters, and visualizations. type QueriesAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(QueriesService) + impl QueriesService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *QueriesAPI) WithImpl(impl QueriesService) *QueriesAPI { + a.impl = impl + return a +} + +// Impl returns low-level Queries API implementation +func (a *QueriesAPI) Impl() QueriesService { + return a.impl } // Create a new query definition @@ -409,10 +462,7 @@ type QueriesAPI struct { // // **Note**: You cannot add a visualization until you create the query. func (a *QueriesAPI) CreateQuery(ctx context.Context, request QueryPostContent) (*Query, error) { - var query Query - path := "/api/2.0/preview/sql/queries" - err := a.client.Post(ctx, path, request, &query) - return &query, err + return a.impl.CreateQuery(ctx, request) } // Delete a query @@ -421,9 +471,7 @@ func (a *QueriesAPI) CreateQuery(ctx context.Context, request QueryPostContent) // searches and list views, and they cannot be used for alerts. The trash is // deleted after 30 days. func (a *QueriesAPI) DeleteQuery(ctx context.Context, request DeleteQueryRequest) error { - path := fmt.Sprintf("/api/2.0/preview/sql/queries/%v", request.QueryId) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteQuery(ctx, request) } // Delete a query @@ -432,7 +480,7 @@ func (a *QueriesAPI) DeleteQuery(ctx context.Context, request DeleteQueryRequest // searches and list views, and they cannot be used for alerts. The trash is // deleted after 30 days. func (a *QueriesAPI) DeleteQueryByQueryId(ctx context.Context, queryId string) error { - return a.DeleteQuery(ctx, DeleteQueryRequest{ + return a.impl.DeleteQuery(ctx, DeleteQueryRequest{ QueryId: queryId, }) } @@ -442,10 +490,7 @@ func (a *QueriesAPI) DeleteQueryByQueryId(ctx context.Context, queryId string) e // Retrieve a query object definition along with contextual permissions // information about the currently authenticated user. func (a *QueriesAPI) GetQuery(ctx context.Context, request GetQueryRequest) (*Query, error) { - var query Query - path := fmt.Sprintf("/api/2.0/preview/sql/queries/%v", request.QueryId) - err := a.client.Get(ctx, path, request, &query) - return &query, err + return a.impl.GetQuery(ctx, request) } // Get a query definition. @@ -453,7 +498,7 @@ func (a *QueriesAPI) GetQuery(ctx context.Context, request GetQueryRequest) (*Qu // Retrieve a query object definition along with contextual permissions // information about the currently authenticated user. func (a *QueriesAPI) GetQueryByQueryId(ctx context.Context, queryId string) (*Query, error) { - return a.GetQuery(ctx, GetQueryRequest{ + return a.impl.GetQuery(ctx, GetQueryRequest{ QueryId: queryId, }) } @@ -463,23 +508,13 @@ func (a *QueriesAPI) GetQueryByQueryId(ctx context.Context, queryId string) (*Qu // Gets a list of queries. Optionally, this list can be filtered by a search // term. // -// Use ListQueriesAll() to get all Query instances, which will iterate over every result page. -func (a *QueriesAPI) ListQueries(ctx context.Context, request ListQueriesRequest) (*ListQueriesResponse, error) { - var listQueriesResponse ListQueriesResponse - path := "/api/2.0/preview/sql/queries" - err := a.client.Get(ctx, path, request, &listQueriesResponse) - return &listQueriesResponse, err -} - -// ListQueriesAll returns all Query instances by calling ListQueries for every result page -// // This method is generated by Databricks SDK Code Generator. func (a *QueriesAPI) ListQueriesAll(ctx context.Context, request ListQueriesRequest) ([]Query, error) { var results []Query ctx = useragent.InContext(ctx, "sdk-feature", "pagination") request.Page = 1 // start iterating from the first page for { - response, err := a.ListQueries(ctx, request) + response, err := a.impl.ListQueries(ctx, request) if err != nil { return nil, err } @@ -499,9 +534,7 @@ func (a *QueriesAPI) ListQueriesAll(ctx context.Context, request ListQueriesRequ // Restore a query that has been moved to the trash. A restored query appears in // list views and searches. You can use restored queries for alerts. func (a *QueriesAPI) RestoreQuery(ctx context.Context, request RestoreQueryRequest) error { - path := fmt.Sprintf("/api/2.0/preview/sql/queries/trash/%v", request.QueryId) - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.RestoreQuery(ctx, request) } // Change a query definition @@ -510,8 +543,5 @@ func (a *QueriesAPI) RestoreQuery(ctx context.Context, request RestoreQueryReque // // **Note**: You cannot undo this operation. func (a *QueriesAPI) UpdateQuery(ctx context.Context, request QueryPostContent) (*Query, error) { - var query Query - path := fmt.Sprintf("/api/2.0/preview/sql/queries/%v", request.QueryId) - err := a.client.Post(ctx, path, request, &query) - return &query, err + return a.impl.UpdateQuery(ctx, request) } diff --git a/service/dbsql/impl.go b/service/dbsql/impl.go new file mode 100755 index 000000000..a9d52115e --- /dev/null +++ b/service/dbsql/impl.go @@ -0,0 +1,209 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package dbsql + +import ( + "context" + "fmt" + + "github.com/databricks/databricks-sdk-go/databricks/client" +) + +// unexported type that holds implementations of just Alerts API methods +type alertsImpl struct { + client *client.DatabricksClient +} + +func (a *alertsImpl) CreateAlert(ctx context.Context, request EditAlert) (*Alert, error) { + var alert Alert + path := "/api/2.0/preview/sql/alerts" + err := a.client.Post(ctx, path, request, &alert) + return &alert, err +} + +func (a *alertsImpl) CreateSchedule(ctx context.Context, request CreateRefreshSchedule) (*RefreshSchedule, error) { + var refreshSchedule RefreshSchedule + path := fmt.Sprintf("/api/2.0/preview/sql/alerts/%v/refresh-schedules", request.AlertId) + err := a.client.Post(ctx, path, request, &refreshSchedule) + return &refreshSchedule, err +} + +func (a *alertsImpl) DeleteAlert(ctx context.Context, request DeleteAlertRequest) error { + path := fmt.Sprintf("/api/2.0/preview/sql/alerts/%v", request.AlertId) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *alertsImpl) DeleteSchedule(ctx context.Context, request DeleteScheduleRequest) error { + path := fmt.Sprintf("/api/2.0/preview/sql/alerts/%v/refresh-schedules/%v", request.AlertId, request.ScheduleId) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *alertsImpl) GetAlert(ctx context.Context, request GetAlertRequest) (*Alert, error) { + var alert Alert + path := fmt.Sprintf("/api/2.0/preview/sql/alerts/%v", request.AlertId) + err := a.client.Get(ctx, path, request, &alert) + return &alert, err +} + +func (a *alertsImpl) GetSubscriptions(ctx context.Context, request GetSubscriptionsRequest) ([]Subscription, error) { + var subscriptionList []Subscription + path := fmt.Sprintf("/api/2.0/preview/sql/alerts/%v/subscriptions", request.AlertId) + err := a.client.Get(ctx, path, request, &subscriptionList) + return subscriptionList, err +} + +func (a *alertsImpl) ListAlerts(ctx context.Context) ([]Alert, error) { + var alertList []Alert + path := "/api/2.0/preview/sql/alerts" + err := a.client.Get(ctx, path, nil, &alertList) + return alertList, err +} + +func (a *alertsImpl) ListSchedules(ctx context.Context, request ListSchedulesRequest) ([]RefreshSchedule, error) { + var refreshScheduleList []RefreshSchedule + path := fmt.Sprintf("/api/2.0/preview/sql/alerts/%v/refresh-schedules", request.AlertId) + err := a.client.Get(ctx, path, request, &refreshScheduleList) + return refreshScheduleList, err +} + +func (a *alertsImpl) Subscribe(ctx context.Context, request CreateSubscription) (*Subscription, error) { + var subscription Subscription + path := fmt.Sprintf("/api/2.0/preview/sql/alerts/%v/subscriptions", request.AlertId) + err := a.client.Post(ctx, path, request, &subscription) + return &subscription, err +} + +func (a *alertsImpl) Unsubscribe(ctx context.Context, request UnsubscribeRequest) error { + path := fmt.Sprintf("/api/2.0/preview/sql/alerts/%v/subscriptions/%v", request.AlertId, request.SubscriptionId) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *alertsImpl) UpdateAlert(ctx context.Context, request EditAlert) error { + path := fmt.Sprintf("/api/2.0/preview/sql/alerts/%v", request.AlertId) + err := a.client.Put(ctx, path, request) + return err +} + +// unexported type that holds implementations of just Dashboards API methods +type dashboardsImpl struct { + client *client.DatabricksClient +} + +func (a *dashboardsImpl) CreateDashboard(ctx context.Context, request CreateDashboardRequest) (*Dashboard, error) { + var dashboard Dashboard + path := "/api/2.0/preview/sql/dashboards" + err := a.client.Post(ctx, path, request, &dashboard) + return &dashboard, err +} + +func (a *dashboardsImpl) DeleteDashboard(ctx context.Context, request DeleteDashboardRequest) error { + path := fmt.Sprintf("/api/2.0/preview/sql/dashboards/%v", request.DashboardId) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *dashboardsImpl) GetDashboard(ctx context.Context, request GetDashboardRequest) (*Dashboard, error) { + var dashboard Dashboard + path := fmt.Sprintf("/api/2.0/preview/sql/dashboards/%v", request.DashboardId) + err := a.client.Get(ctx, path, request, &dashboard) + return &dashboard, err +} + +func (a *dashboardsImpl) ListDashboards(ctx context.Context, request ListDashboardsRequest) (*ListDashboardsResponse, error) { + var listDashboardsResponse ListDashboardsResponse + path := "/api/2.0/preview/sql/dashboards" + err := a.client.Get(ctx, path, request, &listDashboardsResponse) + return &listDashboardsResponse, err +} + +func (a *dashboardsImpl) RestoreDashboard(ctx context.Context, request RestoreDashboardRequest) error { + path := fmt.Sprintf("/api/2.0/preview/sql/dashboards/trash/%v", request.DashboardId) + err := a.client.Post(ctx, path, request, nil) + return err +} + +// unexported type that holds implementations of just DataSources API methods +type dataSourcesImpl struct { + client *client.DatabricksClient +} + +func (a *dataSourcesImpl) ListDataSources(ctx context.Context) ([]DataSource, error) { + var dataSourceList []DataSource + path := "/api/2.0/preview/sql/data_sources" + err := a.client.Get(ctx, path, nil, &dataSourceList) + return dataSourceList, err +} + +// unexported type that holds implementations of just DbsqlPermissions API methods +type dbsqlPermissionsImpl struct { + client *client.DatabricksClient +} + +func (a *dbsqlPermissionsImpl) GetPermissions(ctx context.Context, request GetPermissionsRequest) (*GetPermissionsResponse, error) { + var getPermissionsResponse GetPermissionsResponse + path := fmt.Sprintf("/api/2.0/preview/sql/permissions/%v/%v", request.ObjectType, request.ObjectId) + err := a.client.Get(ctx, path, request, &getPermissionsResponse) + return &getPermissionsResponse, err +} + +func (a *dbsqlPermissionsImpl) SetPermissions(ctx context.Context, request SetPermissionsRequest) (*SetPermissionsResponse, error) { + var setPermissionsResponse SetPermissionsResponse + path := fmt.Sprintf("/api/2.0/preview/sql/permissions/%v/%v", request.ObjectType, request.ObjectId) + err := a.client.Post(ctx, path, request, &setPermissionsResponse) + return &setPermissionsResponse, err +} + +func (a *dbsqlPermissionsImpl) TransferOwnership(ctx context.Context, request TransferOwnershipRequest) (*Success, error) { + var success Success + path := fmt.Sprintf("/api/2.0/preview/sql/permissions/%v/%v/transfer", request.ObjectType, request.ObjectId) + err := a.client.Post(ctx, path, request, &success) + return &success, err +} + +// unexported type that holds implementations of just Queries API methods +type queriesImpl struct { + client *client.DatabricksClient +} + +func (a *queriesImpl) CreateQuery(ctx context.Context, request QueryPostContent) (*Query, error) { + var query Query + path := "/api/2.0/preview/sql/queries" + err := a.client.Post(ctx, path, request, &query) + return &query, err +} + +func (a *queriesImpl) DeleteQuery(ctx context.Context, request DeleteQueryRequest) error { + path := fmt.Sprintf("/api/2.0/preview/sql/queries/%v", request.QueryId) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *queriesImpl) GetQuery(ctx context.Context, request GetQueryRequest) (*Query, error) { + var query Query + path := fmt.Sprintf("/api/2.0/preview/sql/queries/%v", request.QueryId) + err := a.client.Get(ctx, path, request, &query) + return &query, err +} + +func (a *queriesImpl) ListQueries(ctx context.Context, request ListQueriesRequest) (*ListQueriesResponse, error) { + var listQueriesResponse ListQueriesResponse + path := "/api/2.0/preview/sql/queries" + err := a.client.Get(ctx, path, request, &listQueriesResponse) + return &listQueriesResponse, err +} + +func (a *queriesImpl) RestoreQuery(ctx context.Context, request RestoreQueryRequest) error { + path := fmt.Sprintf("/api/2.0/preview/sql/queries/trash/%v", request.QueryId) + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *queriesImpl) UpdateQuery(ctx context.Context, request QueryPostContent) (*Query, error) { + var query Query + path := fmt.Sprintf("/api/2.0/preview/sql/queries/%v", request.QueryId) + err := a.client.Post(ctx, path, request, &query) + return &query, err +} diff --git a/service/dbsql/interface.go b/service/dbsql/interface.go index 67c75939b..3a180441e 100755 --- a/service/dbsql/interface.go +++ b/service/dbsql/interface.go @@ -10,10 +10,6 @@ import ( // a Databricks SQL object that periodically runs a query, evaluates a condition // of its result, and notifies one or more users and/or alert destinations if // the condition was met. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type AlertsService interface { // Create an alert @@ -37,35 +33,17 @@ type AlertsService interface { // to the trash. DeleteAlert(ctx context.Context, request DeleteAlertRequest) error - // DeleteAlertByAlertId calls DeleteAlert, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteAlertByAlertId(ctx context.Context, alertId string) error - // Delete a refresh schedule // // Deletes an alert's refresh schedule. The refresh schedule specifies when // to refresh and evaluate the associated query result. DeleteSchedule(ctx context.Context, request DeleteScheduleRequest) error - // DeleteScheduleByAlertIdAndScheduleId calls DeleteSchedule, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteScheduleByAlertIdAndScheduleId(ctx context.Context, alertId string, scheduleId string) error - // Get an alert // // Gets an alert. GetAlert(ctx context.Context, request GetAlertRequest) (*Alert, error) - // GetAlertByAlertId calls GetAlert, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetAlertByAlertId(ctx context.Context, alertId string) (*Alert, error) - // Get an alert's subscriptions // // Get the subscriptions for an alert. An alert subscription represents @@ -75,12 +53,6 @@ type AlertsService interface { // non-`null`. GetSubscriptions(ctx context.Context, request GetSubscriptionsRequest) ([]Subscription, error) - // GetSubscriptionsByAlertId calls GetSubscriptions, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetSubscriptionsByAlertId(ctx context.Context, alertId string) ([]Subscription, error) - // Get alerts // // Gets a list of alerts. @@ -97,12 +69,6 @@ type AlertsService interface { // refresh schedules is subject to change. ListSchedules(ctx context.Context, request ListSchedulesRequest) ([]RefreshSchedule, error) - // ListSchedulesByAlertId calls ListSchedules, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - ListSchedulesByAlertId(ctx context.Context, alertId string) ([]RefreshSchedule, error) - // Subscribe to an alert Subscribe(ctx context.Context, request CreateSubscription) (*Subscription, error) @@ -111,12 +77,6 @@ type AlertsService interface { // Unsubscribes a user or a destination to an alert. Unsubscribe(ctx context.Context, request UnsubscribeRequest) error - // UnsubscribeByAlertIdAndSubscriptionId calls Unsubscribe, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - UnsubscribeByAlertIdAndSubscriptionId(ctx context.Context, alertId string, subscriptionId string) error - // Update an alert // // Updates an alert. @@ -128,10 +88,6 @@ type AlertsService interface { // query IDs. The API can also be used to duplicate multiple dashboards at once // since you can get a dashboard definition with a GET request and then POST it // to create a new one. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type DashboardsService interface { // Create a dashboard object @@ -143,24 +99,12 @@ type DashboardsService interface { // views or searches, and cannot be shared. DeleteDashboard(ctx context.Context, request DeleteDashboardRequest) error - // DeleteDashboardByDashboardId calls DeleteDashboard, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteDashboardByDashboardId(ctx context.Context, dashboardId string) error - // Retrieve a definition // // Returns a JSON representation of a dashboard object, including its // visualization and query objects. GetDashboard(ctx context.Context, request GetDashboardRequest) (*Dashboard, error) - // GetDashboardByDashboardId calls GetDashboard, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetDashboardByDashboardId(ctx context.Context, dashboardId string) (*Dashboard, error) - // Get dashboard objects // // Fetch a paginated list of dashboard objects. @@ -168,11 +112,6 @@ type DashboardsService interface { // Use ListDashboardsAll() to get all Dashboard instances, which will iterate over every result page. ListDashboards(ctx context.Context, request ListDashboardsRequest) (*ListDashboardsResponse, error) - // ListDashboardsAll calls ListDashboards() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListDashboardsAll(ctx context.Context, request ListDashboardsRequest) ([]Dashboard, error) - // Restore a dashboard // // A restored dashboard appears in list views and searches and can be @@ -190,10 +129,6 @@ type DashboardsService interface { // warehouses in your workspace. We advise you to use any text editor, REST // client, or `grep` to search the response from this API for the name of your // SQL warehouse as it appears in Databricks SQL. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type DataSourcesService interface { // Get a list of SQL warehouses @@ -218,10 +153,6 @@ type DataSourcesService interface { // // - `CAN_MANAGE`: Allows all actions: read, run, edit, delete, modify // permissions (superset of `CAN_RUN`) -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type DbsqlPermissionsService interface { // Get object ACL @@ -230,12 +161,6 @@ type DbsqlPermissionsService interface { // specified object. GetPermissions(ctx context.Context, request GetPermissionsRequest) (*GetPermissionsResponse, error) - // GetPermissionsByObjectTypeAndObjectId calls GetPermissions, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetPermissionsByObjectTypeAndObjectId(ctx context.Context, objectType ObjectTypePlural, objectId string) (*GetPermissionsResponse, error) - // Set object ACL // // Sets the access control list (ACL) for a specified object. This operation @@ -252,10 +177,6 @@ type DbsqlPermissionsService interface { // These endpoints are used for CRUD operations on query definitions. Query // definitions include the target SQL warehouse, query text, name, description, // tags, execution schedule, parameters, and visualizations. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type QueriesService interface { // Create a new query definition @@ -278,24 +199,12 @@ type QueriesService interface { // deleted after 30 days. DeleteQuery(ctx context.Context, request DeleteQueryRequest) error - // DeleteQueryByQueryId calls DeleteQuery, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteQueryByQueryId(ctx context.Context, queryId string) error - // Get a query definition. // // Retrieve a query object definition along with contextual permissions // information about the currently authenticated user. GetQuery(ctx context.Context, request GetQueryRequest) (*Query, error) - // GetQueryByQueryId calls GetQuery, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetQueryByQueryId(ctx context.Context, queryId string) (*Query, error) - // Get a list of queries // // Gets a list of queries. Optionally, this list can be filtered by a search @@ -304,11 +213,6 @@ type QueriesService interface { // Use ListQueriesAll() to get all Query instances, which will iterate over every result page. ListQueries(ctx context.Context, request ListQueriesRequest) (*ListQueriesResponse, error) - // ListQueriesAll calls ListQueries() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListQueriesAll(ctx context.Context, request ListQueriesRequest) ([]Query, error) - // Restore a query // // Restore a query that has been moved to the trash. A restored query diff --git a/service/deployment/api.go b/service/deployment/api.go index 3af5a1e80..b4b1d7acf 100755 --- a/service/deployment/api.go +++ b/service/deployment/api.go @@ -12,14 +12,35 @@ import ( "github.com/databricks/databricks-sdk-go/databricks/useragent" ) -func NewCredentialConfigurations(client *client.DatabricksClient) CredentialConfigurationsService { +func NewCredentialConfigurations(client *client.DatabricksClient) *CredentialConfigurationsAPI { return &CredentialConfigurationsAPI{ - client: client, + impl: &credentialConfigurationsImpl{ + client: client, + }, } } +// These APIs manage credential configurations for this workspace. Databricks +// needs access to a cross-account service IAM role in your AWS account so that +// Databricks can deploy clusters in the appropriate VPC for the new workspace. +// A credential configuration encapsulates this role information, and its ID is +// used when creating a new workspace. type CredentialConfigurationsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(CredentialConfigurationsService) + impl CredentialConfigurationsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *CredentialConfigurationsAPI) WithImpl(impl CredentialConfigurationsService) *CredentialConfigurationsAPI { + a.impl = impl + return a +} + +// Impl returns low-level CredentialConfigurations API implementation +func (a *CredentialConfigurationsAPI) Impl() CredentialConfigurationsService { + return a.impl } // Create credential configuration @@ -38,10 +59,7 @@ type CredentialConfigurationsAPI struct { // [Create a new workspace using the Account // API](http://docs.databricks.com/administration-guide/account-api/new-workspace.html) func (a *CredentialConfigurationsAPI) CreateCredentialConfig(ctx context.Context, request CreateCredentialRequest) (*Credential, error) { - var credential Credential - path := fmt.Sprintf("/api/2.0/accounts/%v/credentials", a.client.Config.AccountID) - err := a.client.Post(ctx, path, request, &credential) - return &credential, err + return a.impl.CreateCredentialConfig(ctx, request) } // Delete credential configuration @@ -50,9 +68,7 @@ func (a *CredentialConfigurationsAPI) CreateCredentialConfig(ctx context.Context // specified by ID. You cannot delete a credential that is associated with any // workspace. func (a *CredentialConfigurationsAPI) DeleteCredentialConfig(ctx context.Context, request DeleteCredentialConfigRequest) error { - path := fmt.Sprintf("/api/2.0/accounts/%v/credentials/%v", a.client.Config.AccountID, request.CredentialsId) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteCredentialConfig(ctx, request) } // Delete credential configuration @@ -61,7 +77,7 @@ func (a *CredentialConfigurationsAPI) DeleteCredentialConfig(ctx context.Context // specified by ID. You cannot delete a credential that is associated with any // workspace. func (a *CredentialConfigurationsAPI) DeleteCredentialConfigByCredentialsId(ctx context.Context, credentialsId string) error { - return a.DeleteCredentialConfig(ctx, DeleteCredentialConfigRequest{ + return a.impl.DeleteCredentialConfig(ctx, DeleteCredentialConfigRequest{ CredentialsId: credentialsId, }) } @@ -71,10 +87,7 @@ func (a *CredentialConfigurationsAPI) DeleteCredentialConfigByCredentialsId(ctx // Gets a Databricks credential configuration object for an account, both // specified by ID. func (a *CredentialConfigurationsAPI) GetCredentialConfig(ctx context.Context, request GetCredentialConfigRequest) (*Credential, error) { - var credential Credential - path := fmt.Sprintf("/api/2.0/accounts/%v/credentials/%v", a.client.Config.AccountID, request.CredentialsId) - err := a.client.Get(ctx, path, request, &credential) - return &credential, err + return a.impl.GetCredentialConfig(ctx, request) } // Get credential configuration @@ -82,7 +95,7 @@ func (a *CredentialConfigurationsAPI) GetCredentialConfig(ctx context.Context, r // Gets a Databricks credential configuration object for an account, both // specified by ID. func (a *CredentialConfigurationsAPI) GetCredentialConfigByCredentialsId(ctx context.Context, credentialsId string) (*Credential, error) { - return a.GetCredentialConfig(ctx, GetCredentialConfigRequest{ + return a.impl.GetCredentialConfig(ctx, GetCredentialConfigRequest{ CredentialsId: credentialsId, }) } @@ -92,20 +105,49 @@ func (a *CredentialConfigurationsAPI) GetCredentialConfigByCredentialsId(ctx con // Gets all Databricks credential configurations associated with an account // specified by ID. func (a *CredentialConfigurationsAPI) ListCredentials(ctx context.Context) ([]Credential, error) { - var credentialList []Credential - path := fmt.Sprintf("/api/2.0/accounts/%v/credentials", a.client.Config.AccountID) - err := a.client.Get(ctx, path, nil, &credentialList) - return credentialList, err + return a.impl.ListCredentials(ctx) } -func NewKeyConfigurations(client *client.DatabricksClient) KeyConfigurationsService { +func NewKeyConfigurations(client *client.DatabricksClient) *KeyConfigurationsAPI { return &KeyConfigurationsAPI{ - client: client, + impl: &keyConfigurationsImpl{ + client: client, + }, } } +// These APIs manage encryption key configurations for this workspace +// (optional). A key configuration encapsulates the AWS KMS key information and +// some information about how the key configuration can be used. There are two +// possible uses for key configurations: +// +// * Managed services: A key configuration can be used to encrypt a workspace's +// notebook and secret data in the control plane, as well as Databricks SQL +// queries and query history. * Storage: A key configuration can be used to +// encrypt a workspace's DBFS and EBS data in the data plane. +// +// In both of these cases, the key configuration's ID is used when creating a +// new workspace. This Preview feature is available if your account is on the E2 +// version of the platform. Updating a running workspace with workspace storage +// encryption requires that the workspace is on the E2 version of the platform. +// If you have an older workspace, it might not be on the E2 version of the +// platform. If you are not sure, contact your Databricks reprsentative. type KeyConfigurationsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(KeyConfigurationsService) + impl KeyConfigurationsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *KeyConfigurationsAPI) WithImpl(impl KeyConfigurationsService) *KeyConfigurationsAPI { + a.impl = impl + return a +} + +// Impl returns low-level KeyConfigurations API implementation +func (a *KeyConfigurationsAPI) Impl() KeyConfigurationsService { + return a.impl } // Create encryption key configuration @@ -127,10 +169,7 @@ type KeyConfigurationsAPI struct { // platform or on a select custom plan that allows multiple workspaces per // account. func (a *KeyConfigurationsAPI) CreateKeyConfig(ctx context.Context, request CreateCustomerManagedKeyRequest) (*CustomerManagedKey, error) { - var customerManagedKey CustomerManagedKey - path := fmt.Sprintf("/api/2.0/accounts/%v/customer-managed-keys", a.client.Config.AccountID) - err := a.client.Post(ctx, path, request, &customerManagedKey) - return &customerManagedKey, err + return a.impl.CreateKeyConfig(ctx, request) } // Delete encryption key configuration @@ -138,9 +177,7 @@ func (a *KeyConfigurationsAPI) CreateKeyConfig(ctx context.Context, request Crea // Deletes a customer-managed key configuration object for an account. You // cannot delete a configuration that is associated with a running workspace. func (a *KeyConfigurationsAPI) DeleteKeyConfig(ctx context.Context, request DeleteKeyConfigRequest) error { - path := fmt.Sprintf("/api/2.0/accounts/%v/customer-managed-keys/%v", a.client.Config.AccountID, request.CustomerManagedKeyId) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteKeyConfig(ctx, request) } // Delete encryption key configuration @@ -148,7 +185,7 @@ func (a *KeyConfigurationsAPI) DeleteKeyConfig(ctx context.Context, request Dele // Deletes a customer-managed key configuration object for an account. You // cannot delete a configuration that is associated with a running workspace. func (a *KeyConfigurationsAPI) DeleteKeyConfigByCustomerManagedKeyId(ctx context.Context, customerManagedKeyId string) error { - return a.DeleteKeyConfig(ctx, DeleteKeyConfigRequest{ + return a.impl.DeleteKeyConfig(ctx, DeleteKeyConfigRequest{ CustomerManagedKeyId: customerManagedKeyId, }) } @@ -171,10 +208,7 @@ func (a *KeyConfigurationsAPI) DeleteKeyConfigByCustomerManagedKeyId(ctx context // This operation is available only if your account is on the E2 version of the // platform. func (a *KeyConfigurationsAPI) GetKeyConfig(ctx context.Context, request GetKeyConfigRequest) (*CustomerManagedKey, error) { - var customerManagedKey CustomerManagedKey - path := fmt.Sprintf("/api/2.0/accounts/%v/customer-managed-keys/%v", a.client.Config.AccountID, request.CustomerManagedKeyId) - err := a.client.Get(ctx, path, request, &customerManagedKey) - return &customerManagedKey, err + return a.impl.GetKeyConfig(ctx, request) } // Get encryption key configuration @@ -195,7 +229,7 @@ func (a *KeyConfigurationsAPI) GetKeyConfig(ctx context.Context, request GetKeyC // This operation is available only if your account is on the E2 version of the // platform. func (a *KeyConfigurationsAPI) GetKeyConfigByCustomerManagedKeyId(ctx context.Context, customerManagedKeyId string) (*CustomerManagedKey, error) { - return a.GetKeyConfig(ctx, GetKeyConfigRequest{ + return a.impl.GetKeyConfig(ctx, GetKeyConfigRequest{ CustomerManagedKeyId: customerManagedKeyId, }) } @@ -211,10 +245,7 @@ func (a *KeyConfigurationsAPI) GetKeyConfigByCustomerManagedKeyId(ctx context.Co // This operation is available only if your account is on the E2 version of the // platform. func (a *KeyConfigurationsAPI) GetKeyWorkspaceHistory(ctx context.Context) (*ListWorkspaceEncryptionKeyRecordsResponse, error) { - var listWorkspaceEncryptionKeyRecordsResponse ListWorkspaceEncryptionKeyRecordsResponse - path := fmt.Sprintf("/api/2.0/accounts/%v/customer-managed-key-history", a.client.Config.AccountID) - err := a.client.Get(ctx, path, nil, &listWorkspaceEncryptionKeyRecordsResponse) - return &listWorkspaceEncryptionKeyRecordsResponse, err + return a.impl.GetKeyWorkspaceHistory(ctx) } // Get all encryption key configurations @@ -233,20 +264,37 @@ func (a *KeyConfigurationsAPI) GetKeyWorkspaceHistory(ctx context.Context) (*Lis // This operation is available only if your account is on the E2 version of the // platform. func (a *KeyConfigurationsAPI) ListKeyConfigs(ctx context.Context) ([]CustomerManagedKey, error) { - var customerManagedKeyList []CustomerManagedKey - path := fmt.Sprintf("/api/2.0/accounts/%v/customer-managed-keys", a.client.Config.AccountID) - err := a.client.Get(ctx, path, nil, &customerManagedKeyList) - return customerManagedKeyList, err + return a.impl.ListKeyConfigs(ctx) } -func NewNetworkConfigurations(client *client.DatabricksClient) NetworkConfigurationsService { +func NewNetworkConfigurations(client *client.DatabricksClient) *NetworkConfigurationsAPI { return &NetworkConfigurationsAPI{ - client: client, + impl: &networkConfigurationsImpl{ + client: client, + }, } } +// These APIs manage network configurations for customer-managed VPCs +// (optional). A network configuration encapsulates the IDs for AWS VPCs, +// subnets, and security groups. Its ID is used when creating a new workspace if +// you use customer-managed VPCs. type NetworkConfigurationsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(NetworkConfigurationsService) + impl NetworkConfigurationsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *NetworkConfigurationsAPI) WithImpl(impl NetworkConfigurationsService) *NetworkConfigurationsAPI { + a.impl = impl + return a +} + +// Impl returns low-level NetworkConfigurations API implementation +func (a *NetworkConfigurationsAPI) Impl() NetworkConfigurationsService { + return a.impl } // Create network configuration @@ -270,10 +318,7 @@ type NetworkConfigurationsAPI struct { // This operation is available only if your account is on the E2 version of the // platform. func (a *NetworkConfigurationsAPI) CreateNetworkConfig(ctx context.Context, request CreateNetworkRequest) (*Network, error) { - var network Network - path := fmt.Sprintf("/api/2.0/accounts/%v/networks", a.client.Config.AccountID) - err := a.client.Post(ctx, path, request, &network) - return &network, err + return a.impl.CreateNetworkConfig(ctx, request) } // Delete network configuration @@ -285,9 +330,7 @@ func (a *NetworkConfigurationsAPI) CreateNetworkConfig(ctx context.Context, requ // This operation is available only if your account is on the E2 version of the // platform. func (a *NetworkConfigurationsAPI) DeleteNetworkConfig(ctx context.Context, request DeleteNetworkConfigRequest) error { - path := fmt.Sprintf("/api/2.0/accounts/%v/networks/%v", a.client.Config.AccountID, request.NetworkId) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteNetworkConfig(ctx, request) } // Delete network configuration @@ -299,7 +342,7 @@ func (a *NetworkConfigurationsAPI) DeleteNetworkConfig(ctx context.Context, requ // This operation is available only if your account is on the E2 version of the // platform. func (a *NetworkConfigurationsAPI) DeleteNetworkConfigByNetworkId(ctx context.Context, networkId string) error { - return a.DeleteNetworkConfig(ctx, DeleteNetworkConfigRequest{ + return a.impl.DeleteNetworkConfig(ctx, DeleteNetworkConfigRequest{ NetworkId: networkId, }) } @@ -314,10 +357,7 @@ func (a *NetworkConfigurationsAPI) DeleteNetworkConfigByNetworkId(ctx context.Co // This operation is available only if your account is on the E2 version of the // platform. func (a *NetworkConfigurationsAPI) GetNetworkConfig(ctx context.Context, request GetNetworkConfigRequest) (*Network, error) { - var network Network - path := fmt.Sprintf("/api/2.0/accounts/%v/networks/%v", a.client.Config.AccountID, request.NetworkId) - err := a.client.Get(ctx, path, request, &network) - return &network, err + return a.impl.GetNetworkConfig(ctx, request) } // Get a network configuration @@ -330,7 +370,7 @@ func (a *NetworkConfigurationsAPI) GetNetworkConfig(ctx context.Context, request // This operation is available only if your account is on the E2 version of the // platform. func (a *NetworkConfigurationsAPI) GetNetworkConfigByNetworkId(ctx context.Context, networkId string) (*Network, error) { - return a.GetNetworkConfig(ctx, GetNetworkConfigRequest{ + return a.impl.GetNetworkConfig(ctx, GetNetworkConfigRequest{ NetworkId: networkId, }) } @@ -343,20 +383,41 @@ func (a *NetworkConfigurationsAPI) GetNetworkConfigByNetworkId(ctx context.Conte // This operation is available only if your account is on the E2 version of the // platform. func (a *NetworkConfigurationsAPI) ListNetworkConfigs(ctx context.Context) ([]Network, error) { - var networkList []Network - path := fmt.Sprintf("/api/2.0/accounts/%v/networks", a.client.Config.AccountID) - err := a.client.Get(ctx, path, nil, &networkList) - return networkList, err + return a.impl.ListNetworkConfigs(ctx) } -func NewPrivateAccessSettings(client *client.DatabricksClient) PrivateAccessSettingsService { +func NewPrivateAccessSettings(client *client.DatabricksClient) *PrivateAccessSettingsAPI { return &PrivateAccessSettingsAPI{ - client: client, + impl: &privateAccessSettingsImpl{ + client: client, + }, } } +// These APIs manage private access settings for this account. A private access +// settings object specifies how your workspace is accessed using AWS +// PrivateLink. Each workspace that has any PrivateLink connections must include +// the ID for a private access settings object is in its workspace configuration +// object. Your account must be enabled for PrivateLink to use these APIs. +// Before configuring PrivateLink, it is important to read the [Databricks +// article about +// PrivateLink](https://docs.databricks.com/administration-guide/cloud-configurations/aws/privatelink.html). type PrivateAccessSettingsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(PrivateAccessSettingsService) + impl PrivateAccessSettingsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *PrivateAccessSettingsAPI) WithImpl(impl PrivateAccessSettingsService) *PrivateAccessSettingsAPI { + a.impl = impl + return a +} + +// Impl returns low-level PrivateAccessSettings API implementation +func (a *PrivateAccessSettingsAPI) Impl() PrivateAccessSettingsService { + return a.impl } // Create private access settings @@ -379,10 +440,7 @@ type PrivateAccessSettingsAPI struct { // Preview). Contact your Databricks representative to enable your account for // PrivateLink. func (a *PrivateAccessSettingsAPI) CreatePrivateAccessSettings(ctx context.Context, request UpsertPrivateAccessSettingsRequest) (*PrivateAccessSettings, error) { - var privateAccessSettings PrivateAccessSettings - path := fmt.Sprintf("/api/2.0/accounts/%v/private-access-settings", a.client.Config.AccountID) - err := a.client.Post(ctx, path, request, &privateAccessSettings) - return &privateAccessSettings, err + return a.impl.CreatePrivateAccessSettings(ctx, request) } // Delete a private access settings object @@ -398,9 +456,7 @@ func (a *PrivateAccessSettingsAPI) CreatePrivateAccessSettings(ctx context.Conte // Preview). Contact your Databricks representative to enable your account for // PrivateLink. func (a *PrivateAccessSettingsAPI) DeletePrivateAccessSettings(ctx context.Context, request DeletePrivateAccessSettingsRequest) error { - path := fmt.Sprintf("/api/2.0/accounts/%v/private-access-settings/%v", a.client.Config.AccountID, request.PrivateAccessSettingsId) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeletePrivateAccessSettings(ctx, request) } // Delete a private access settings object @@ -416,7 +472,7 @@ func (a *PrivateAccessSettingsAPI) DeletePrivateAccessSettings(ctx context.Conte // Preview). Contact your Databricks representative to enable your account for // PrivateLink. func (a *PrivateAccessSettingsAPI) DeletePrivateAccessSettingsByPrivateAccessSettingsId(ctx context.Context, privateAccessSettingsId string) error { - return a.DeletePrivateAccessSettings(ctx, DeletePrivateAccessSettingsRequest{ + return a.impl.DeletePrivateAccessSettings(ctx, DeletePrivateAccessSettingsRequest{ PrivateAccessSettingsId: privateAccessSettingsId, }) } @@ -434,10 +490,7 @@ func (a *PrivateAccessSettingsAPI) DeletePrivateAccessSettingsByPrivateAccessSet // Preview). Contact your Databricks representative to enable your account for // PrivateLink. func (a *PrivateAccessSettingsAPI) GetPrivateAccessSettings(ctx context.Context, request GetPrivateAccessSettingsRequest) (*PrivateAccessSettings, error) { - var privateAccessSettings PrivateAccessSettings - path := fmt.Sprintf("/api/2.0/accounts/%v/private-access-settings/%v", a.client.Config.AccountID, request.PrivateAccessSettingsId) - err := a.client.Get(ctx, path, request, &privateAccessSettings) - return &privateAccessSettings, err + return a.impl.GetPrivateAccessSettings(ctx, request) } // Get a private access settings object @@ -453,7 +506,7 @@ func (a *PrivateAccessSettingsAPI) GetPrivateAccessSettings(ctx context.Context, // Preview). Contact your Databricks representative to enable your account for // PrivateLink. func (a *PrivateAccessSettingsAPI) GetPrivateAccessSettingsByPrivateAccessSettingsId(ctx context.Context, privateAccessSettingsId string) (*PrivateAccessSettings, error) { - return a.GetPrivateAccessSettings(ctx, GetPrivateAccessSettingsRequest{ + return a.impl.GetPrivateAccessSettings(ctx, GetPrivateAccessSettingsRequest{ PrivateAccessSettingsId: privateAccessSettingsId, }) } @@ -468,10 +521,7 @@ func (a *PrivateAccessSettingsAPI) GetPrivateAccessSettingsByPrivateAccessSettin // Preview). Contact your Databricks representative to enable your account for // PrivateLink. func (a *PrivateAccessSettingsAPI) ListPrivateAccessSettings(ctx context.Context) ([]PrivateAccessSettings, error) { - var privateAccessSettingsList []PrivateAccessSettings - path := fmt.Sprintf("/api/2.0/accounts/%v/private-access-settings", a.client.Config.AccountID) - err := a.client.Get(ctx, path, nil, &privateAccessSettingsList) - return privateAccessSettingsList, err + return a.impl.ListPrivateAccessSettings(ctx) } // Replace private access settings @@ -500,19 +550,39 @@ func (a *PrivateAccessSettingsAPI) ListPrivateAccessSettings(ctx context.Context // Preview). Contact your Databricks representative to enable your account for // PrivateLink. func (a *PrivateAccessSettingsAPI) ReplacePrivateAccessSettings(ctx context.Context, request UpsertPrivateAccessSettingsRequest) error { - path := fmt.Sprintf("/api/2.0/accounts/%v/private-access-settings/%v", a.client.Config.AccountID, request.PrivateAccessSettingsId) - err := a.client.Put(ctx, path, request) - return err + return a.impl.ReplacePrivateAccessSettings(ctx, request) } -func NewStorageConfigurations(client *client.DatabricksClient) StorageConfigurationsService { +func NewStorageConfigurations(client *client.DatabricksClient) *StorageConfigurationsAPI { return &StorageConfigurationsAPI{ - client: client, + impl: &storageConfigurationsImpl{ + client: client, + }, } } +// These APIs manage storage configurations for this workspace. A root storage +// S3 bucket in your account is required to store objects like cluster logs, +// notebook revisions, and job results. You can also use the root storage S3 +// bucket for storage of non-production DBFS data. A storage configuration +// encapsulates this bucket information, and its ID is used when creating a new +// workspace. type StorageConfigurationsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(StorageConfigurationsService) + impl StorageConfigurationsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *StorageConfigurationsAPI) WithImpl(impl StorageConfigurationsService) *StorageConfigurationsAPI { + a.impl = impl + return a +} + +// Impl returns low-level StorageConfigurations API implementation +func (a *StorageConfigurationsAPI) Impl() StorageConfigurationsService { + return a.impl } // Create new storage configuration @@ -527,10 +597,7 @@ type StorageConfigurationsAPI struct { // [Create a new workspace using the Account // API](http://docs.databricks.com/administration-guide/account-api/new-workspace.html) func (a *StorageConfigurationsAPI) CreateStorageConfig(ctx context.Context, request CreateStorageConfigurationRequest) (*StorageConfiguration, error) { - var storageConfiguration StorageConfiguration - path := fmt.Sprintf("/api/2.0/accounts/%v/storage-configurations", a.client.Config.AccountID) - err := a.client.Post(ctx, path, request, &storageConfiguration) - return &storageConfiguration, err + return a.impl.CreateStorageConfig(ctx, request) } // Delete storage configuration @@ -538,9 +605,7 @@ func (a *StorageConfigurationsAPI) CreateStorageConfig(ctx context.Context, requ // Deletes a Databricks storage configuration. You cannot delete a storage // configuration that is associated with any workspace. func (a *StorageConfigurationsAPI) DeleteStorageConfig(ctx context.Context, request DeleteStorageConfigRequest) error { - path := fmt.Sprintf("/api/2.0/accounts/%v/storage-configurations/%v", a.client.Config.AccountID, request.StorageConfigurationId) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteStorageConfig(ctx, request) } // Delete storage configuration @@ -548,7 +613,7 @@ func (a *StorageConfigurationsAPI) DeleteStorageConfig(ctx context.Context, requ // Deletes a Databricks storage configuration. You cannot delete a storage // configuration that is associated with any workspace. func (a *StorageConfigurationsAPI) DeleteStorageConfigByStorageConfigurationId(ctx context.Context, storageConfigurationId string) error { - return a.DeleteStorageConfig(ctx, DeleteStorageConfigRequest{ + return a.impl.DeleteStorageConfig(ctx, DeleteStorageConfigRequest{ StorageConfigurationId: storageConfigurationId, }) } @@ -557,17 +622,14 @@ func (a *StorageConfigurationsAPI) DeleteStorageConfigByStorageConfigurationId(c // // Gets a Databricks storage configuration for an account, both specified by ID. func (a *StorageConfigurationsAPI) GetStorageConfig(ctx context.Context, request GetStorageConfigRequest) (*StorageConfiguration, error) { - var storageConfiguration StorageConfiguration - path := fmt.Sprintf("/api/2.0/accounts/%v/storage-configurations/%v", a.client.Config.AccountID, request.StorageConfigurationId) - err := a.client.Get(ctx, path, request, &storageConfiguration) - return &storageConfiguration, err + return a.impl.GetStorageConfig(ctx, request) } // Get storage configuration // // Gets a Databricks storage configuration for an account, both specified by ID. func (a *StorageConfigurationsAPI) GetStorageConfigByStorageConfigurationId(ctx context.Context, storageConfigurationId string) (*StorageConfiguration, error) { - return a.GetStorageConfig(ctx, GetStorageConfigRequest{ + return a.impl.GetStorageConfig(ctx, GetStorageConfigRequest{ StorageConfigurationId: storageConfigurationId, }) } @@ -577,20 +639,42 @@ func (a *StorageConfigurationsAPI) GetStorageConfigByStorageConfigurationId(ctx // Gets a list of all Databricks storage configurations for your account, // specified by ID. func (a *StorageConfigurationsAPI) ListStorageConfigs(ctx context.Context) ([]StorageConfiguration, error) { - var storageConfigurationList []StorageConfiguration - path := fmt.Sprintf("/api/2.0/accounts/%v/storage-configurations", a.client.Config.AccountID) - err := a.client.Get(ctx, path, nil, &storageConfigurationList) - return storageConfigurationList, err + return a.impl.ListStorageConfigs(ctx) } -func NewVpcEndpoints(client *client.DatabricksClient) VpcEndpointsService { +func NewVpcEndpoints(client *client.DatabricksClient) *VpcEndpointsAPI { return &VpcEndpointsAPI{ - client: client, + impl: &vpcEndpointsImpl{ + client: client, + }, } } +// These APIs manage VPC endpoint configurations for this account. This object +// registers an AWS VPC endpoint in your Databricks account so your workspace +// can use it with AWS PrivateLink. Your VPC endpoint connects to one of two VPC +// endpoint services -- one for workspace (both for front-end connection and for +// back-end connection to REST APIs) and one for the back-end secure cluster +// connectivity relay from the data plane. Your account must be enabled for +// PrivateLink to use these APIs. Before configuring PrivateLink, it is +// important to read the [Databricks article about +// PrivateLink](https://docs.databricks.com/administration-guide/cloud-configurations/aws/privatelink.html). type VpcEndpointsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(VpcEndpointsService) + impl VpcEndpointsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *VpcEndpointsAPI) WithImpl(impl VpcEndpointsService) *VpcEndpointsAPI { + a.impl = impl + return a +} + +// Impl returns low-level VpcEndpoints API implementation +func (a *VpcEndpointsAPI) Impl() VpcEndpointsService { + return a.impl } // Create VPC endpoint configuration @@ -623,10 +707,7 @@ type VpcEndpointsAPI struct { // Preview). Contact your Databricks representative to enable your account for // PrivateLink. func (a *VpcEndpointsAPI) CreateVpcEndpoint(ctx context.Context, request CreateVpcEndpointRequest) (*VpcEndpoint, error) { - var vpcEndpoint VpcEndpoint - path := fmt.Sprintf("/api/2.0/accounts/%v/vpc-endpoints", a.client.Config.AccountID) - err := a.client.Post(ctx, path, request, &vpcEndpoint) - return &vpcEndpoint, err + return a.impl.CreateVpcEndpoint(ctx, request) } // Delete VPC endpoint configuration @@ -648,9 +729,7 @@ func (a *VpcEndpointsAPI) CreateVpcEndpoint(ctx context.Context, request CreateV // Preview). Contact your Databricks representative to enable your account for // PrivateLink. func (a *VpcEndpointsAPI) DeleteVpcEndpoint(ctx context.Context, request DeleteVpcEndpointRequest) error { - path := fmt.Sprintf("/api/2.0/accounts/%v/vpc-endpoints/%v", a.client.Config.AccountID, request.VpcEndpointId) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteVpcEndpoint(ctx, request) } // Delete VPC endpoint configuration @@ -672,7 +751,7 @@ func (a *VpcEndpointsAPI) DeleteVpcEndpoint(ctx context.Context, request DeleteV // Preview). Contact your Databricks representative to enable your account for // PrivateLink. func (a *VpcEndpointsAPI) DeleteVpcEndpointByVpcEndpointId(ctx context.Context, vpcEndpointId string) error { - return a.DeleteVpcEndpoint(ctx, DeleteVpcEndpointRequest{ + return a.impl.DeleteVpcEndpoint(ctx, DeleteVpcEndpointRequest{ VpcEndpointId: vpcEndpointId, }) } @@ -689,10 +768,7 @@ func (a *VpcEndpointsAPI) DeleteVpcEndpointByVpcEndpointId(ctx context.Context, // Preview). Contact your Databricks representative to enable your account for // PrivateLink. func (a *VpcEndpointsAPI) GetVpcEndpoint(ctx context.Context, request GetVpcEndpointRequest) (*VpcEndpoint, error) { - var vpcEndpoint VpcEndpoint - path := fmt.Sprintf("/api/2.0/accounts/%v/vpc-endpoints/%v", a.client.Config.AccountID, request.VpcEndpointId) - err := a.client.Get(ctx, path, request, &vpcEndpoint) - return &vpcEndpoint, err + return a.impl.GetVpcEndpoint(ctx, request) } // Get a VPC endpoint configuration @@ -707,7 +783,7 @@ func (a *VpcEndpointsAPI) GetVpcEndpoint(ctx context.Context, request GetVpcEndp // Preview). Contact your Databricks representative to enable your account for // PrivateLink. func (a *VpcEndpointsAPI) GetVpcEndpointByVpcEndpointId(ctx context.Context, vpcEndpointId string) (*VpcEndpoint, error) { - return a.GetVpcEndpoint(ctx, GetVpcEndpointRequest{ + return a.impl.GetVpcEndpoint(ctx, GetVpcEndpointRequest{ VpcEndpointId: vpcEndpointId, }) } @@ -724,20 +800,42 @@ func (a *VpcEndpointsAPI) GetVpcEndpointByVpcEndpointId(ctx context.Context, vpc // Preview). Contact your Databricks representative to enable your account for // PrivateLink. func (a *VpcEndpointsAPI) ListVpcEndpoints(ctx context.Context) ([]VpcEndpoint, error) { - var vpcEndpointList []VpcEndpoint - path := fmt.Sprintf("/api/2.0/accounts/%v/vpc-endpoints", a.client.Config.AccountID) - err := a.client.Get(ctx, path, nil, &vpcEndpointList) - return vpcEndpointList, err + return a.impl.ListVpcEndpoints(ctx) } -func NewWorkspaces(client *client.DatabricksClient) WorkspacesService { +func NewWorkspaces(client *client.DatabricksClient) *WorkspacesAPI { return &WorkspacesAPI{ - client: client, + impl: &workspacesImpl{ + client: client, + }, } } +// These APIs manage workspaces for this account. A Databricks workspace is an +// environment for accessing all of your Databricks assets. The workspace +// organizes objects (notebooks, libraries, and experiments) into folders, and +// provides access to data and computational resources such as clusters and +// jobs. +// +// These endpoints are available if your account is on the E2 version of the +// platform or on a select custom plan that allows multiple workspaces per +// account. type WorkspacesAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(WorkspacesService) + impl WorkspacesService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *WorkspacesAPI) WithImpl(impl WorkspacesService) *WorkspacesAPI { + a.impl = impl + return a +} + +// Impl returns low-level Workspaces API implementation +func (a *WorkspacesAPI) Impl() WorkspacesService { + return a.impl } // Create a new workspace @@ -776,13 +874,10 @@ type WorkspacesAPI struct { // E2 version of the platform or on a select custom plan that allows multiple // workspaces per account. func (a *WorkspacesAPI) CreateWorkspace(ctx context.Context, request CreateWorkspaceRequest) (*Workspace, error) { - var workspace Workspace - path := fmt.Sprintf("/api/2.0/accounts/%v/workspaces", a.client.Config.AccountID) - err := a.client.Post(ctx, path, request, &workspace) - return &workspace, err + return a.impl.CreateWorkspace(ctx, request) } -// CreateWorkspace and wait to reach RUNNING state +// Calls [WorkspacesAPI.CreateWorkspace] and waits to reach RUNNING state // // You can override the default timeout of 20 minutes by calling adding // retries.Timeout[Workspace](60*time.Minute) functional option. @@ -835,9 +930,7 @@ func (a *WorkspacesAPI) CreateWorkspaceAndWait(ctx context.Context, createWorksp // platform or on a select custom plan that allows multiple workspaces per // account. func (a *WorkspacesAPI) DeleteWorkspace(ctx context.Context, request DeleteWorkspaceRequest) error { - path := fmt.Sprintf("/api/2.0/accounts/%v/workspaces/%v", a.client.Config.AccountID, request.WorkspaceId) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteWorkspace(ctx, request) } // Delete workspace @@ -851,7 +944,7 @@ func (a *WorkspacesAPI) DeleteWorkspace(ctx context.Context, request DeleteWorks // platform or on a select custom plan that allows multiple workspaces per // account. func (a *WorkspacesAPI) DeleteWorkspaceByWorkspaceId(ctx context.Context, workspaceId int64) error { - return a.DeleteWorkspace(ctx, DeleteWorkspaceRequest{ + return a.impl.DeleteWorkspace(ctx, DeleteWorkspaceRequest{ WorkspaceId: workspaceId, }) } @@ -864,10 +957,7 @@ func (a *WorkspacesAPI) DeleteWorkspaceByWorkspaceId(ctx context.Context, worksp // platform or on a select custom plan that allows multiple workspaces per // account. func (a *WorkspacesAPI) GetAllWorkspaces(ctx context.Context) ([]Workspace, error) { - var workspaceList []Workspace - path := fmt.Sprintf("/api/2.0/accounts/%v/workspaces", a.client.Config.AccountID) - err := a.client.Get(ctx, path, nil, &workspaceList) - return workspaceList, err + return a.impl.GetAllWorkspaces(ctx) } // Get workspace @@ -886,10 +976,7 @@ func (a *WorkspacesAPI) GetAllWorkspaces(ctx context.Context) ([]Workspace, erro // platform or on a select custom plan that allows multiple workspaces per // account. func (a *WorkspacesAPI) GetWorkspace(ctx context.Context, request GetWorkspaceRequest) (*Workspace, error) { - var workspace Workspace - path := fmt.Sprintf("/api/2.0/accounts/%v/workspaces/%v", a.client.Config.AccountID, request.WorkspaceId) - err := a.client.Get(ctx, path, request, &workspace) - return &workspace, err + return a.impl.GetWorkspace(ctx, request) } // Get workspace @@ -908,7 +995,7 @@ func (a *WorkspacesAPI) GetWorkspace(ctx context.Context, request GetWorkspaceRe // platform or on a select custom plan that allows multiple workspaces per // account. func (a *WorkspacesAPI) GetWorkspaceByWorkspaceId(ctx context.Context, workspaceId int64) (*Workspace, error) { - return a.GetWorkspace(ctx, GetWorkspaceRequest{ + return a.impl.GetWorkspace(ctx, GetWorkspaceRequest{ WorkspaceId: workspaceId, }) } @@ -930,10 +1017,7 @@ func (a *WorkspacesAPI) GetWorkspaceByWorkspaceId(ctx context.Context, workspace // This operation is available only if your account is on the E2 version of the // platform. func (a *WorkspacesAPI) GetWorkspaceKeyHistory(ctx context.Context, request GetWorkspaceKeyHistoryRequest) (*ListWorkspaceEncryptionKeyRecordsResponse, error) { - var listWorkspaceEncryptionKeyRecordsResponse ListWorkspaceEncryptionKeyRecordsResponse - path := fmt.Sprintf("/api/2.0/accounts/%v/workspaces/%v/customer-managed-key-history", a.client.Config.AccountID, request.WorkspaceId) - err := a.client.Get(ctx, path, request, &listWorkspaceEncryptionKeyRecordsResponse) - return &listWorkspaceEncryptionKeyRecordsResponse, err + return a.impl.GetWorkspaceKeyHistory(ctx, request) } // Get the history of a workspace's associations with keys @@ -953,7 +1037,7 @@ func (a *WorkspacesAPI) GetWorkspaceKeyHistory(ctx context.Context, request GetW // This operation is available only if your account is on the E2 version of the // platform. func (a *WorkspacesAPI) GetWorkspaceKeyHistoryByWorkspaceId(ctx context.Context, workspaceId int64) (*ListWorkspaceEncryptionKeyRecordsResponse, error) { - return a.GetWorkspaceKeyHistory(ctx, GetWorkspaceKeyHistoryRequest{ + return a.impl.GetWorkspaceKeyHistory(ctx, GetWorkspaceKeyHistoryRequest{ WorkspaceId: workspaceId, }) } @@ -1063,7 +1147,5 @@ func (a *WorkspacesAPI) GetWorkspaceKeyHistoryByWorkspaceId(ctx context.Context, // platform or on a select custom plan that allows multiple workspaces per // account. func (a *WorkspacesAPI) UpdateWorkspace(ctx context.Context, request UpdateWorkspaceRequest) error { - path := fmt.Sprintf("/api/2.0/accounts/%v/workspaces/%v", a.client.Config.AccountID, request.WorkspaceId) - err := a.client.Patch(ctx, path, request) - return err + return a.impl.UpdateWorkspace(ctx, request) } diff --git a/service/deployment/impl.go b/service/deployment/impl.go new file mode 100755 index 000000000..2f55726d3 --- /dev/null +++ b/service/deployment/impl.go @@ -0,0 +1,260 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package deployment + +import ( + "context" + "fmt" + + "github.com/databricks/databricks-sdk-go/databricks/client" +) + +// unexported type that holds implementations of just CredentialConfigurations API methods +type credentialConfigurationsImpl struct { + client *client.DatabricksClient +} + +func (a *credentialConfigurationsImpl) CreateCredentialConfig(ctx context.Context, request CreateCredentialRequest) (*Credential, error) { + var credential Credential + path := fmt.Sprintf("/api/2.0/accounts/%v/credentials", a.client.Config.AccountID) + err := a.client.Post(ctx, path, request, &credential) + return &credential, err +} + +func (a *credentialConfigurationsImpl) DeleteCredentialConfig(ctx context.Context, request DeleteCredentialConfigRequest) error { + path := fmt.Sprintf("/api/2.0/accounts/%v/credentials/%v", a.client.Config.AccountID, request.CredentialsId) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *credentialConfigurationsImpl) GetCredentialConfig(ctx context.Context, request GetCredentialConfigRequest) (*Credential, error) { + var credential Credential + path := fmt.Sprintf("/api/2.0/accounts/%v/credentials/%v", a.client.Config.AccountID, request.CredentialsId) + err := a.client.Get(ctx, path, request, &credential) + return &credential, err +} + +func (a *credentialConfigurationsImpl) ListCredentials(ctx context.Context) ([]Credential, error) { + var credentialList []Credential + path := fmt.Sprintf("/api/2.0/accounts/%v/credentials", a.client.Config.AccountID) + err := a.client.Get(ctx, path, nil, &credentialList) + return credentialList, err +} + +// unexported type that holds implementations of just KeyConfigurations API methods +type keyConfigurationsImpl struct { + client *client.DatabricksClient +} + +func (a *keyConfigurationsImpl) CreateKeyConfig(ctx context.Context, request CreateCustomerManagedKeyRequest) (*CustomerManagedKey, error) { + var customerManagedKey CustomerManagedKey + path := fmt.Sprintf("/api/2.0/accounts/%v/customer-managed-keys", a.client.Config.AccountID) + err := a.client.Post(ctx, path, request, &customerManagedKey) + return &customerManagedKey, err +} + +func (a *keyConfigurationsImpl) DeleteKeyConfig(ctx context.Context, request DeleteKeyConfigRequest) error { + path := fmt.Sprintf("/api/2.0/accounts/%v/customer-managed-keys/%v", a.client.Config.AccountID, request.CustomerManagedKeyId) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *keyConfigurationsImpl) GetKeyConfig(ctx context.Context, request GetKeyConfigRequest) (*CustomerManagedKey, error) { + var customerManagedKey CustomerManagedKey + path := fmt.Sprintf("/api/2.0/accounts/%v/customer-managed-keys/%v", a.client.Config.AccountID, request.CustomerManagedKeyId) + err := a.client.Get(ctx, path, request, &customerManagedKey) + return &customerManagedKey, err +} + +func (a *keyConfigurationsImpl) GetKeyWorkspaceHistory(ctx context.Context) (*ListWorkspaceEncryptionKeyRecordsResponse, error) { + var listWorkspaceEncryptionKeyRecordsResponse ListWorkspaceEncryptionKeyRecordsResponse + path := fmt.Sprintf("/api/2.0/accounts/%v/customer-managed-key-history", a.client.Config.AccountID) + err := a.client.Get(ctx, path, nil, &listWorkspaceEncryptionKeyRecordsResponse) + return &listWorkspaceEncryptionKeyRecordsResponse, err +} + +func (a *keyConfigurationsImpl) ListKeyConfigs(ctx context.Context) ([]CustomerManagedKey, error) { + var customerManagedKeyList []CustomerManagedKey + path := fmt.Sprintf("/api/2.0/accounts/%v/customer-managed-keys", a.client.Config.AccountID) + err := a.client.Get(ctx, path, nil, &customerManagedKeyList) + return customerManagedKeyList, err +} + +// unexported type that holds implementations of just NetworkConfigurations API methods +type networkConfigurationsImpl struct { + client *client.DatabricksClient +} + +func (a *networkConfigurationsImpl) CreateNetworkConfig(ctx context.Context, request CreateNetworkRequest) (*Network, error) { + var network Network + path := fmt.Sprintf("/api/2.0/accounts/%v/networks", a.client.Config.AccountID) + err := a.client.Post(ctx, path, request, &network) + return &network, err +} + +func (a *networkConfigurationsImpl) DeleteNetworkConfig(ctx context.Context, request DeleteNetworkConfigRequest) error { + path := fmt.Sprintf("/api/2.0/accounts/%v/networks/%v", a.client.Config.AccountID, request.NetworkId) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *networkConfigurationsImpl) GetNetworkConfig(ctx context.Context, request GetNetworkConfigRequest) (*Network, error) { + var network Network + path := fmt.Sprintf("/api/2.0/accounts/%v/networks/%v", a.client.Config.AccountID, request.NetworkId) + err := a.client.Get(ctx, path, request, &network) + return &network, err +} + +func (a *networkConfigurationsImpl) ListNetworkConfigs(ctx context.Context) ([]Network, error) { + var networkList []Network + path := fmt.Sprintf("/api/2.0/accounts/%v/networks", a.client.Config.AccountID) + err := a.client.Get(ctx, path, nil, &networkList) + return networkList, err +} + +// unexported type that holds implementations of just PrivateAccessSettings API methods +type privateAccessSettingsImpl struct { + client *client.DatabricksClient +} + +func (a *privateAccessSettingsImpl) CreatePrivateAccessSettings(ctx context.Context, request UpsertPrivateAccessSettingsRequest) (*PrivateAccessSettings, error) { + var privateAccessSettings PrivateAccessSettings + path := fmt.Sprintf("/api/2.0/accounts/%v/private-access-settings", a.client.Config.AccountID) + err := a.client.Post(ctx, path, request, &privateAccessSettings) + return &privateAccessSettings, err +} + +func (a *privateAccessSettingsImpl) DeletePrivateAccessSettings(ctx context.Context, request DeletePrivateAccessSettingsRequest) error { + path := fmt.Sprintf("/api/2.0/accounts/%v/private-access-settings/%v", a.client.Config.AccountID, request.PrivateAccessSettingsId) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *privateAccessSettingsImpl) GetPrivateAccessSettings(ctx context.Context, request GetPrivateAccessSettingsRequest) (*PrivateAccessSettings, error) { + var privateAccessSettings PrivateAccessSettings + path := fmt.Sprintf("/api/2.0/accounts/%v/private-access-settings/%v", a.client.Config.AccountID, request.PrivateAccessSettingsId) + err := a.client.Get(ctx, path, request, &privateAccessSettings) + return &privateAccessSettings, err +} + +func (a *privateAccessSettingsImpl) ListPrivateAccessSettings(ctx context.Context) ([]PrivateAccessSettings, error) { + var privateAccessSettingsList []PrivateAccessSettings + path := fmt.Sprintf("/api/2.0/accounts/%v/private-access-settings", a.client.Config.AccountID) + err := a.client.Get(ctx, path, nil, &privateAccessSettingsList) + return privateAccessSettingsList, err +} + +func (a *privateAccessSettingsImpl) ReplacePrivateAccessSettings(ctx context.Context, request UpsertPrivateAccessSettingsRequest) error { + path := fmt.Sprintf("/api/2.0/accounts/%v/private-access-settings/%v", a.client.Config.AccountID, request.PrivateAccessSettingsId) + err := a.client.Put(ctx, path, request) + return err +} + +// unexported type that holds implementations of just StorageConfigurations API methods +type storageConfigurationsImpl struct { + client *client.DatabricksClient +} + +func (a *storageConfigurationsImpl) CreateStorageConfig(ctx context.Context, request CreateStorageConfigurationRequest) (*StorageConfiguration, error) { + var storageConfiguration StorageConfiguration + path := fmt.Sprintf("/api/2.0/accounts/%v/storage-configurations", a.client.Config.AccountID) + err := a.client.Post(ctx, path, request, &storageConfiguration) + return &storageConfiguration, err +} + +func (a *storageConfigurationsImpl) DeleteStorageConfig(ctx context.Context, request DeleteStorageConfigRequest) error { + path := fmt.Sprintf("/api/2.0/accounts/%v/storage-configurations/%v", a.client.Config.AccountID, request.StorageConfigurationId) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *storageConfigurationsImpl) GetStorageConfig(ctx context.Context, request GetStorageConfigRequest) (*StorageConfiguration, error) { + var storageConfiguration StorageConfiguration + path := fmt.Sprintf("/api/2.0/accounts/%v/storage-configurations/%v", a.client.Config.AccountID, request.StorageConfigurationId) + err := a.client.Get(ctx, path, request, &storageConfiguration) + return &storageConfiguration, err +} + +func (a *storageConfigurationsImpl) ListStorageConfigs(ctx context.Context) ([]StorageConfiguration, error) { + var storageConfigurationList []StorageConfiguration + path := fmt.Sprintf("/api/2.0/accounts/%v/storage-configurations", a.client.Config.AccountID) + err := a.client.Get(ctx, path, nil, &storageConfigurationList) + return storageConfigurationList, err +} + +// unexported type that holds implementations of just VpcEndpoints API methods +type vpcEndpointsImpl struct { + client *client.DatabricksClient +} + +func (a *vpcEndpointsImpl) CreateVpcEndpoint(ctx context.Context, request CreateVpcEndpointRequest) (*VpcEndpoint, error) { + var vpcEndpoint VpcEndpoint + path := fmt.Sprintf("/api/2.0/accounts/%v/vpc-endpoints", a.client.Config.AccountID) + err := a.client.Post(ctx, path, request, &vpcEndpoint) + return &vpcEndpoint, err +} + +func (a *vpcEndpointsImpl) DeleteVpcEndpoint(ctx context.Context, request DeleteVpcEndpointRequest) error { + path := fmt.Sprintf("/api/2.0/accounts/%v/vpc-endpoints/%v", a.client.Config.AccountID, request.VpcEndpointId) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *vpcEndpointsImpl) GetVpcEndpoint(ctx context.Context, request GetVpcEndpointRequest) (*VpcEndpoint, error) { + var vpcEndpoint VpcEndpoint + path := fmt.Sprintf("/api/2.0/accounts/%v/vpc-endpoints/%v", a.client.Config.AccountID, request.VpcEndpointId) + err := a.client.Get(ctx, path, request, &vpcEndpoint) + return &vpcEndpoint, err +} + +func (a *vpcEndpointsImpl) ListVpcEndpoints(ctx context.Context) ([]VpcEndpoint, error) { + var vpcEndpointList []VpcEndpoint + path := fmt.Sprintf("/api/2.0/accounts/%v/vpc-endpoints", a.client.Config.AccountID) + err := a.client.Get(ctx, path, nil, &vpcEndpointList) + return vpcEndpointList, err +} + +// unexported type that holds implementations of just Workspaces API methods +type workspacesImpl struct { + client *client.DatabricksClient +} + +func (a *workspacesImpl) CreateWorkspace(ctx context.Context, request CreateWorkspaceRequest) (*Workspace, error) { + var workspace Workspace + path := fmt.Sprintf("/api/2.0/accounts/%v/workspaces", a.client.Config.AccountID) + err := a.client.Post(ctx, path, request, &workspace) + return &workspace, err +} + +func (a *workspacesImpl) DeleteWorkspace(ctx context.Context, request DeleteWorkspaceRequest) error { + path := fmt.Sprintf("/api/2.0/accounts/%v/workspaces/%v", a.client.Config.AccountID, request.WorkspaceId) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *workspacesImpl) GetAllWorkspaces(ctx context.Context) ([]Workspace, error) { + var workspaceList []Workspace + path := fmt.Sprintf("/api/2.0/accounts/%v/workspaces", a.client.Config.AccountID) + err := a.client.Get(ctx, path, nil, &workspaceList) + return workspaceList, err +} + +func (a *workspacesImpl) GetWorkspace(ctx context.Context, request GetWorkspaceRequest) (*Workspace, error) { + var workspace Workspace + path := fmt.Sprintf("/api/2.0/accounts/%v/workspaces/%v", a.client.Config.AccountID, request.WorkspaceId) + err := a.client.Get(ctx, path, request, &workspace) + return &workspace, err +} + +func (a *workspacesImpl) GetWorkspaceKeyHistory(ctx context.Context, request GetWorkspaceKeyHistoryRequest) (*ListWorkspaceEncryptionKeyRecordsResponse, error) { + var listWorkspaceEncryptionKeyRecordsResponse ListWorkspaceEncryptionKeyRecordsResponse + path := fmt.Sprintf("/api/2.0/accounts/%v/workspaces/%v/customer-managed-key-history", a.client.Config.AccountID, request.WorkspaceId) + err := a.client.Get(ctx, path, request, &listWorkspaceEncryptionKeyRecordsResponse) + return &listWorkspaceEncryptionKeyRecordsResponse, err +} + +func (a *workspacesImpl) UpdateWorkspace(ctx context.Context, request UpdateWorkspaceRequest) error { + path := fmt.Sprintf("/api/2.0/accounts/%v/workspaces/%v", a.client.Config.AccountID, request.WorkspaceId) + err := a.client.Patch(ctx, path, request) + return err +} diff --git a/service/deployment/interface.go b/service/deployment/interface.go index 9e1ed38d8..28a09722d 100755 --- a/service/deployment/interface.go +++ b/service/deployment/interface.go @@ -4,8 +4,6 @@ package deployment import ( "context" - - "github.com/databricks/databricks-sdk-go/databricks/retries" ) // These APIs manage credential configurations for this workspace. Databricks @@ -13,10 +11,6 @@ import ( // Databricks can deploy clusters in the appropriate VPC for the new workspace. // A credential configuration encapsulates this role information, and its ID is // used when creating a new workspace. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type CredentialConfigurationsService interface { // Create credential configuration @@ -43,24 +37,12 @@ type CredentialConfigurationsService interface { // any workspace. DeleteCredentialConfig(ctx context.Context, request DeleteCredentialConfigRequest) error - // DeleteCredentialConfigByCredentialsId calls DeleteCredentialConfig, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteCredentialConfigByCredentialsId(ctx context.Context, credentialsId string) error - // Get credential configuration // // Gets a Databricks credential configuration object for an account, both // specified by ID. GetCredentialConfig(ctx context.Context, request GetCredentialConfigRequest) (*Credential, error) - // GetCredentialConfigByCredentialsId calls GetCredentialConfig, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetCredentialConfigByCredentialsId(ctx context.Context, credentialsId string) (*Credential, error) - // Get all credential configurations // // Gets all Databricks credential configurations associated with an account @@ -84,10 +66,6 @@ type CredentialConfigurationsService interface { // encryption requires that the workspace is on the E2 version of the platform. // If you have an older workspace, it might not be on the E2 version of the // platform. If you are not sure, contact your Databricks reprsentative. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type KeyConfigurationsService interface { // Create encryption key configuration @@ -117,12 +95,6 @@ type KeyConfigurationsService interface { // workspace. DeleteKeyConfig(ctx context.Context, request DeleteKeyConfigRequest) error - // DeleteKeyConfigByCustomerManagedKeyId calls DeleteKeyConfig, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteKeyConfigByCustomerManagedKeyId(ctx context.Context, customerManagedKeyId string) error - // Get encryption key configuration // // Gets a customer-managed key configuration object for an account, @@ -142,12 +114,6 @@ type KeyConfigurationsService interface { // the platform. GetKeyConfig(ctx context.Context, request GetKeyConfigRequest) (*CustomerManagedKey, error) - // GetKeyConfigByCustomerManagedKeyId calls GetKeyConfig, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetKeyConfigByCustomerManagedKeyId(ctx context.Context, customerManagedKeyId string) (*CustomerManagedKey, error) - // Get history of a key's associations with workspaces // // Gets a list of records that show how key configurations are associated @@ -183,10 +149,6 @@ type KeyConfigurationsService interface { // (optional). A network configuration encapsulates the IDs for AWS VPCs, // subnets, and security groups. Its ID is used when creating a new workspace if // you use customer-managed VPCs. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type NetworkConfigurationsService interface { // Create network configuration @@ -223,12 +185,6 @@ type NetworkConfigurationsService interface { // the platform. DeleteNetworkConfig(ctx context.Context, request DeleteNetworkConfigRequest) error - // DeleteNetworkConfigByNetworkId calls DeleteNetworkConfig, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteNetworkConfigByNetworkId(ctx context.Context, networkId string) error - // Get a network configuration // // Gets a Databricks network configuration, which represents an AWS VPC and @@ -240,12 +196,6 @@ type NetworkConfigurationsService interface { // the platform. GetNetworkConfig(ctx context.Context, request GetNetworkConfigRequest) (*Network, error) - // GetNetworkConfigByNetworkId calls GetNetworkConfig, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetNetworkConfigByNetworkId(ctx context.Context, networkId string) (*Network, error) - // Get all network configurations // // Gets a list of all Databricks network configurations for an account, @@ -264,10 +214,6 @@ type NetworkConfigurationsService interface { // Before configuring PrivateLink, it is important to read the [Databricks // article about // PrivateLink](https://docs.databricks.com/administration-guide/cloud-configurations/aws/privatelink.html). -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type PrivateAccessSettingsService interface { // Create private access settings @@ -307,12 +253,6 @@ type PrivateAccessSettingsService interface { // account for PrivateLink. DeletePrivateAccessSettings(ctx context.Context, request DeletePrivateAccessSettingsRequest) error - // DeletePrivateAccessSettingsByPrivateAccessSettingsId calls DeletePrivateAccessSettings, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeletePrivateAccessSettingsByPrivateAccessSettingsId(ctx context.Context, privateAccessSettingsId string) error - // Get a private access settings object // // Gets a private access settings object, which specifies how your workspace @@ -327,12 +267,6 @@ type PrivateAccessSettingsService interface { // account for PrivateLink. GetPrivateAccessSettings(ctx context.Context, request GetPrivateAccessSettingsRequest) (*PrivateAccessSettings, error) - // GetPrivateAccessSettingsByPrivateAccessSettingsId calls GetPrivateAccessSettings, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetPrivateAccessSettingsByPrivateAccessSettingsId(ctx context.Context, privateAccessSettingsId string) (*PrivateAccessSettings, error) - // Get all private access settings objects // // Gets a list of all private access settings objects for an account, @@ -379,10 +313,6 @@ type PrivateAccessSettingsService interface { // bucket for storage of non-production DBFS data. A storage configuration // encapsulates this bucket information, and its ID is used when creating a new // workspace. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type StorageConfigurationsService interface { // Create new storage configuration @@ -404,24 +334,12 @@ type StorageConfigurationsService interface { // configuration that is associated with any workspace. DeleteStorageConfig(ctx context.Context, request DeleteStorageConfigRequest) error - // DeleteStorageConfigByStorageConfigurationId calls DeleteStorageConfig, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteStorageConfigByStorageConfigurationId(ctx context.Context, storageConfigurationId string) error - // Get storage configuration // // Gets a Databricks storage configuration for an account, both specified by // ID. GetStorageConfig(ctx context.Context, request GetStorageConfigRequest) (*StorageConfiguration, error) - // GetStorageConfigByStorageConfigurationId calls GetStorageConfig, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetStorageConfigByStorageConfigurationId(ctx context.Context, storageConfigurationId string) (*StorageConfiguration, error) - // Get all storage configurations // // Gets a list of all Databricks storage configurations for your account, @@ -438,10 +356,6 @@ type StorageConfigurationsService interface { // PrivateLink to use these APIs. Before configuring PrivateLink, it is // important to read the [Databricks article about // PrivateLink](https://docs.databricks.com/administration-guide/cloud-configurations/aws/privatelink.html). -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type VpcEndpointsService interface { // Create VPC endpoint configuration @@ -496,12 +410,6 @@ type VpcEndpointsService interface { // account for PrivateLink. DeleteVpcEndpoint(ctx context.Context, request DeleteVpcEndpointRequest) error - // DeleteVpcEndpointByVpcEndpointId calls DeleteVpcEndpoint, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteVpcEndpointByVpcEndpointId(ctx context.Context, vpcEndpointId string) error - // Get a VPC endpoint configuration // // Gets a VPC endpoint configuration, which represents a [VPC @@ -515,12 +423,6 @@ type VpcEndpointsService interface { // account for PrivateLink. GetVpcEndpoint(ctx context.Context, request GetVpcEndpointRequest) (*VpcEndpoint, error) - // GetVpcEndpointByVpcEndpointId calls GetVpcEndpoint, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetVpcEndpointByVpcEndpointId(ctx context.Context, vpcEndpointId string) (*VpcEndpoint, error) - // Get all VPC endpoint configurations // // Gets a list of all VPC endpoints for an account, specified by ID. @@ -544,10 +446,6 @@ type VpcEndpointsService interface { // These endpoints are available if your account is on the E2 version of the // platform or on a select custom plan that allows multiple workspaces per // account. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type WorkspacesService interface { // Create a new workspace @@ -589,11 +487,6 @@ type WorkspacesService interface { // multiple workspaces per account. CreateWorkspace(ctx context.Context, request CreateWorkspaceRequest) (*Workspace, error) - // CreateWorkspaceAndWait calls CreateWorkspace() and waits to reach RUNNING state - // - // This method is generated by Databricks SDK Code Generator. - CreateWorkspaceAndWait(ctx context.Context, request CreateWorkspaceRequest, options ...retries.Option[Workspace]) (*Workspace, error) - // Delete workspace // // Terminates and deletes a Databricks workspace. From an API perspective, @@ -606,12 +499,6 @@ type WorkspacesService interface { // per account. DeleteWorkspace(ctx context.Context, request DeleteWorkspaceRequest) error - // DeleteWorkspaceByWorkspaceId calls DeleteWorkspace, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteWorkspaceByWorkspaceId(ctx context.Context, workspaceId int64) error - // Get all workspaces // // Gets a list of all workspaces associated with an account, specified by @@ -640,12 +527,6 @@ type WorkspacesService interface { // per account. GetWorkspace(ctx context.Context, request GetWorkspaceRequest) (*Workspace, error) - // GetWorkspaceByWorkspaceId calls GetWorkspace, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetWorkspaceByWorkspaceId(ctx context.Context, workspaceId int64) (*Workspace, error) - // Get the history of a workspace's associations with keys // // Gets a list of all associations with key configuration objects for the @@ -664,12 +545,6 @@ type WorkspacesService interface { // the platform. GetWorkspaceKeyHistory(ctx context.Context, request GetWorkspaceKeyHistoryRequest) (*ListWorkspaceEncryptionKeyRecordsResponse, error) - // GetWorkspaceKeyHistoryByWorkspaceId calls GetWorkspaceKeyHistory, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetWorkspaceKeyHistoryByWorkspaceId(ctx context.Context, workspaceId int64) (*ListWorkspaceEncryptionKeyRecordsResponse, error) - // Update workspace configuration // // Updates a workspace configuration for either a running workspace or a diff --git a/service/gitcredentials/api.go b/service/gitcredentials/api.go index 2280db846..faeaad184 100755 --- a/service/gitcredentials/api.go +++ b/service/gitcredentials/api.go @@ -4,19 +4,39 @@ package gitcredentials import ( "context" - "fmt" "github.com/databricks/databricks-sdk-go/databricks/client" ) -func NewGitCredentials(client *client.DatabricksClient) GitCredentialsService { +func NewGitCredentials(client *client.DatabricksClient) *GitCredentialsAPI { return &GitCredentialsAPI{ - client: client, + impl: &gitCredentialsImpl{ + client: client, + }, } } +// Registers personal access token for Databricks to do operations on behalf of +// the user. +// +// See [more +// info](https://docs.databricks.com/repos/get-access-tokens-from-git-provider.html). type GitCredentialsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(GitCredentialsService) + impl GitCredentialsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *GitCredentialsAPI) WithImpl(impl GitCredentialsService) *GitCredentialsAPI { + a.impl = impl + return a +} + +// Impl returns low-level GitCredentials API implementation +func (a *GitCredentialsAPI) Impl() GitCredentialsService { + return a.impl } // Create a credential entry @@ -26,26 +46,21 @@ type GitCredentialsAPI struct { // exists will fail. Use the PATCH endpoint to update existing credentials, or // the DELETE endpoint to delete existing credentials. func (a *GitCredentialsAPI) Create(ctx context.Context, request CreateCredentials) (*CreateCredentialsResponse, error) { - var createCredentialsResponse CreateCredentialsResponse - path := "/api/2.0/git-credentials" - err := a.client.Post(ctx, path, request, &createCredentialsResponse) - return &createCredentialsResponse, err + return a.impl.Create(ctx, request) } // Delete a credential // // Deletes the specified Git credential. func (a *GitCredentialsAPI) Delete(ctx context.Context, request DeleteRequest) error { - path := fmt.Sprintf("/api/2.0/git-credentials/%v", request.CredentialId) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.Delete(ctx, request) } // Delete a credential // // Deletes the specified Git credential. func (a *GitCredentialsAPI) DeleteByCredentialId(ctx context.Context, credentialId int64) error { - return a.Delete(ctx, DeleteRequest{ + return a.impl.Delete(ctx, DeleteRequest{ CredentialId: credentialId, }) } @@ -54,17 +69,14 @@ func (a *GitCredentialsAPI) DeleteByCredentialId(ctx context.Context, credential // // Gets the Git credential with the specified credential ID. func (a *GitCredentialsAPI) Get(ctx context.Context, request GetRequest) (*CredentialInfo, error) { - var credentialInfo CredentialInfo - path := fmt.Sprintf("/api/2.0/git-credentials/%v", request.CredentialId) - err := a.client.Get(ctx, path, request, &credentialInfo) - return &credentialInfo, err + return a.impl.Get(ctx, request) } // Get a credential entry // // Gets the Git credential with the specified credential ID. func (a *GitCredentialsAPI) GetByCredentialId(ctx context.Context, credentialId int64) (*CredentialInfo, error) { - return a.Get(ctx, GetRequest{ + return a.impl.Get(ctx, GetRequest{ CredentialId: credentialId, }) } @@ -74,19 +86,9 @@ func (a *GitCredentialsAPI) GetByCredentialId(ctx context.Context, credentialId // Lists the calling user's Git credentials. One credential per user is // supported. // -// Use ListAll() to get all CredentialInfo instances -func (a *GitCredentialsAPI) List(ctx context.Context) (*GetCredentialsResponse, error) { - var getCredentialsResponse GetCredentialsResponse - path := "/api/2.0/git-credentials" - err := a.client.Get(ctx, path, nil, &getCredentialsResponse) - return &getCredentialsResponse, err -} - -// ListAll returns all CredentialInfo instances. This method exists for consistency purposes. -// // This method is generated by Databricks SDK Code Generator. func (a *GitCredentialsAPI) ListAll(ctx context.Context) ([]CredentialInfo, error) { - response, err := a.List(ctx) + response, err := a.impl.List(ctx) if err != nil { return nil, err } @@ -97,7 +99,5 @@ func (a *GitCredentialsAPI) ListAll(ctx context.Context) ([]CredentialInfo, erro // // Updates the specified Git credential. func (a *GitCredentialsAPI) Update(ctx context.Context, request UpdateCredentials) error { - path := fmt.Sprintf("/api/2.0/git-credentials/%v", request.CredentialId) - err := a.client.Patch(ctx, path, request) - return err + return a.impl.Update(ctx, request) } diff --git a/service/gitcredentials/impl.go b/service/gitcredentials/impl.go new file mode 100755 index 000000000..c4a9db272 --- /dev/null +++ b/service/gitcredentials/impl.go @@ -0,0 +1,48 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package gitcredentials + +import ( + "context" + "fmt" + + "github.com/databricks/databricks-sdk-go/databricks/client" +) + +// unexported type that holds implementations of just GitCredentials API methods +type gitCredentialsImpl struct { + client *client.DatabricksClient +} + +func (a *gitCredentialsImpl) Create(ctx context.Context, request CreateCredentials) (*CreateCredentialsResponse, error) { + var createCredentialsResponse CreateCredentialsResponse + path := "/api/2.0/git-credentials" + err := a.client.Post(ctx, path, request, &createCredentialsResponse) + return &createCredentialsResponse, err +} + +func (a *gitCredentialsImpl) Delete(ctx context.Context, request DeleteRequest) error { + path := fmt.Sprintf("/api/2.0/git-credentials/%v", request.CredentialId) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *gitCredentialsImpl) Get(ctx context.Context, request GetRequest) (*CredentialInfo, error) { + var credentialInfo CredentialInfo + path := fmt.Sprintf("/api/2.0/git-credentials/%v", request.CredentialId) + err := a.client.Get(ctx, path, request, &credentialInfo) + return &credentialInfo, err +} + +func (a *gitCredentialsImpl) List(ctx context.Context) (*GetCredentialsResponse, error) { + var getCredentialsResponse GetCredentialsResponse + path := "/api/2.0/git-credentials" + err := a.client.Get(ctx, path, nil, &getCredentialsResponse) + return &getCredentialsResponse, err +} + +func (a *gitCredentialsImpl) Update(ctx context.Context, request UpdateCredentials) error { + path := fmt.Sprintf("/api/2.0/git-credentials/%v", request.CredentialId) + err := a.client.Patch(ctx, path, request) + return err +} diff --git a/service/gitcredentials/interface.go b/service/gitcredentials/interface.go index 8503dc4f1..dfb3cf9be 100755 --- a/service/gitcredentials/interface.go +++ b/service/gitcredentials/interface.go @@ -11,10 +11,6 @@ import ( // // See [more // info](https://docs.databricks.com/repos/get-access-tokens-from-git-provider.html). -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type GitCredentialsService interface { // Create a credential entry @@ -30,23 +26,11 @@ type GitCredentialsService interface { // Deletes the specified Git credential. Delete(ctx context.Context, request DeleteRequest) error - // DeleteByCredentialId calls Delete, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteByCredentialId(ctx context.Context, credentialId int64) error - // Get a credential entry // // Gets the Git credential with the specified credential ID. Get(ctx context.Context, request GetRequest) (*CredentialInfo, error) - // GetByCredentialId calls Get, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetByCredentialId(ctx context.Context, credentialId int64) (*CredentialInfo, error) - // Get Git credentials // // Lists the calling user's Git credentials. One credential per user is @@ -55,11 +39,6 @@ type GitCredentialsService interface { // Use ListAll() to get all CredentialInfo instances List(ctx context.Context) (*GetCredentialsResponse, error) - // ListAll calls List() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListAll(ctx context.Context) ([]CredentialInfo, error) - // Update a credential // // Updates the specified Git credential. diff --git a/service/globalinitscripts/api.go b/service/globalinitscripts/api.go index 4f763d1c8..84d72ffbb 100755 --- a/service/globalinitscripts/api.go +++ b/service/globalinitscripts/api.go @@ -4,45 +4,65 @@ package globalinitscripts import ( "context" - "fmt" "github.com/databricks/databricks-sdk-go/databricks/client" ) -func NewGlobalInitScripts(client *client.DatabricksClient) GlobalInitScriptsService { +func NewGlobalInitScripts(client *client.DatabricksClient) *GlobalInitScriptsAPI { return &GlobalInitScriptsAPI{ - client: client, + impl: &globalInitScriptsImpl{ + client: client, + }, } } +// The Global Init Scripts API enables Workspace administrators to configure +// global initialization scripts for their workspace. These scripts run on every +// node in every cluster in the workspace. +// +// **Important:** Existing clusters must be restarted to pick up any changes +// made to global init scripts. Global init scripts are run in order. If the +// init script returns with a bad exit code, the Apache Spark container fails to +// launch and init scripts with later position are skipped. If enough containers +// fail, the entire cluster fails with a `GLOBAL_INIT_SCRIPT_FAILURE` error +// code. type GlobalInitScriptsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(GlobalInitScriptsService) + impl GlobalInitScriptsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *GlobalInitScriptsAPI) WithImpl(impl GlobalInitScriptsService) *GlobalInitScriptsAPI { + a.impl = impl + return a +} + +// Impl returns low-level GlobalInitScripts API implementation +func (a *GlobalInitScriptsAPI) Impl() GlobalInitScriptsService { + return a.impl } // Create init script // // Creates a new global init script in this workspace. func (a *GlobalInitScriptsAPI) CreateScript(ctx context.Context, request GlobalInitScriptCreateRequest) (*CreateScriptResponse, error) { - var createScriptResponse CreateScriptResponse - path := "/api/2.0/global-init-scripts" - err := a.client.Post(ctx, path, request, &createScriptResponse) - return &createScriptResponse, err + return a.impl.CreateScript(ctx, request) } // Delete init script // // Deletes a global init script. func (a *GlobalInitScriptsAPI) DeleteScript(ctx context.Context, request DeleteScriptRequest) error { - path := fmt.Sprintf("/api/2.0/global-init-scripts/%v", request.ScriptId) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteScript(ctx, request) } // Delete init script // // Deletes a global init script. func (a *GlobalInitScriptsAPI) DeleteScriptByScriptId(ctx context.Context, scriptId string) error { - return a.DeleteScript(ctx, DeleteScriptRequest{ + return a.impl.DeleteScript(ctx, DeleteScriptRequest{ ScriptId: scriptId, }) } @@ -51,17 +71,14 @@ func (a *GlobalInitScriptsAPI) DeleteScriptByScriptId(ctx context.Context, scrip // // Gets all the details of a script, including its Base64-encoded contents. func (a *GlobalInitScriptsAPI) GetScript(ctx context.Context, request GetScriptRequest) (*GlobalInitScriptDetailsWithContent, error) { - var globalInitScriptDetailsWithContent GlobalInitScriptDetailsWithContent - path := fmt.Sprintf("/api/2.0/global-init-scripts/%v", request.ScriptId) - err := a.client.Get(ctx, path, request, &globalInitScriptDetailsWithContent) - return &globalInitScriptDetailsWithContent, err + return a.impl.GetScript(ctx, request) } // Get an init script // // Gets all the details of a script, including its Base64-encoded contents. func (a *GlobalInitScriptsAPI) GetScriptByScriptId(ctx context.Context, scriptId string) (*GlobalInitScriptDetailsWithContent, error) { - return a.GetScript(ctx, GetScriptRequest{ + return a.impl.GetScript(ctx, GetScriptRequest{ ScriptId: scriptId, }) } @@ -73,10 +90,7 @@ func (a *GlobalInitScriptsAPI) GetScriptByScriptId(ctx context.Context, scriptId // contents of a script, use the [get a global init // script](#operation/get-script) operation. func (a *GlobalInitScriptsAPI) ListScripts(ctx context.Context) ([]GlobalInitScriptDetails, error) { - var globalInitScriptDetailsList []GlobalInitScriptDetails - path := "/api/2.0/global-init-scripts" - err := a.client.Get(ctx, path, nil, &globalInitScriptDetailsList) - return globalInitScriptDetailsList, err + return a.impl.ListScripts(ctx) } // Update init script @@ -84,7 +98,5 @@ func (a *GlobalInitScriptsAPI) ListScripts(ctx context.Context) ([]GlobalInitScr // Updates a global init script, specifying only the fields to change. All // fields are optional. Unspecified fields retain their current value. func (a *GlobalInitScriptsAPI) UpdateScript(ctx context.Context, request GlobalInitScriptUpdateRequest) error { - path := fmt.Sprintf("/api/2.0/global-init-scripts/%v", request.ScriptId) - err := a.client.Patch(ctx, path, request) - return err + return a.impl.UpdateScript(ctx, request) } diff --git a/service/globalinitscripts/impl.go b/service/globalinitscripts/impl.go new file mode 100755 index 000000000..0600a2fe7 --- /dev/null +++ b/service/globalinitscripts/impl.go @@ -0,0 +1,48 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package globalinitscripts + +import ( + "context" + "fmt" + + "github.com/databricks/databricks-sdk-go/databricks/client" +) + +// unexported type that holds implementations of just GlobalInitScripts API methods +type globalInitScriptsImpl struct { + client *client.DatabricksClient +} + +func (a *globalInitScriptsImpl) CreateScript(ctx context.Context, request GlobalInitScriptCreateRequest) (*CreateScriptResponse, error) { + var createScriptResponse CreateScriptResponse + path := "/api/2.0/global-init-scripts" + err := a.client.Post(ctx, path, request, &createScriptResponse) + return &createScriptResponse, err +} + +func (a *globalInitScriptsImpl) DeleteScript(ctx context.Context, request DeleteScriptRequest) error { + path := fmt.Sprintf("/api/2.0/global-init-scripts/%v", request.ScriptId) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *globalInitScriptsImpl) GetScript(ctx context.Context, request GetScriptRequest) (*GlobalInitScriptDetailsWithContent, error) { + var globalInitScriptDetailsWithContent GlobalInitScriptDetailsWithContent + path := fmt.Sprintf("/api/2.0/global-init-scripts/%v", request.ScriptId) + err := a.client.Get(ctx, path, request, &globalInitScriptDetailsWithContent) + return &globalInitScriptDetailsWithContent, err +} + +func (a *globalInitScriptsImpl) ListScripts(ctx context.Context) ([]GlobalInitScriptDetails, error) { + var globalInitScriptDetailsList []GlobalInitScriptDetails + path := "/api/2.0/global-init-scripts" + err := a.client.Get(ctx, path, nil, &globalInitScriptDetailsList) + return globalInitScriptDetailsList, err +} + +func (a *globalInitScriptsImpl) UpdateScript(ctx context.Context, request GlobalInitScriptUpdateRequest) error { + path := fmt.Sprintf("/api/2.0/global-init-scripts/%v", request.ScriptId) + err := a.client.Patch(ctx, path, request) + return err +} diff --git a/service/globalinitscripts/interface.go b/service/globalinitscripts/interface.go index c616d5cd8..8bd20866d 100755 --- a/service/globalinitscripts/interface.go +++ b/service/globalinitscripts/interface.go @@ -16,10 +16,6 @@ import ( // launch and init scripts with later position are skipped. If enough containers // fail, the entire cluster fails with a `GLOBAL_INIT_SCRIPT_FAILURE` error // code. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type GlobalInitScriptsService interface { // Create init script @@ -32,23 +28,11 @@ type GlobalInitScriptsService interface { // Deletes a global init script. DeleteScript(ctx context.Context, request DeleteScriptRequest) error - // DeleteScriptByScriptId calls DeleteScript, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteScriptByScriptId(ctx context.Context, scriptId string) error - // Get an init script // // Gets all the details of a script, including its Base64-encoded contents. GetScript(ctx context.Context, request GetScriptRequest) (*GlobalInitScriptDetailsWithContent, error) - // GetScriptByScriptId calls GetScript, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetScriptByScriptId(ctx context.Context, scriptId string) (*GlobalInitScriptDetailsWithContent, error) - // Get init scripts // // "Get a list of all global init scripts for this workspace. This returns diff --git a/service/instancepools/api.go b/service/instancepools/api.go index 5db91aca6..02f31d550 100755 --- a/service/instancepools/api.go +++ b/service/instancepools/api.go @@ -8,24 +8,55 @@ import ( "github.com/databricks/databricks-sdk-go/databricks/client" ) -func NewInstancePools(client *client.DatabricksClient) InstancePoolsService { +func NewInstancePools(client *client.DatabricksClient) *InstancePoolsAPI { return &InstancePoolsAPI{ - client: client, + impl: &instancePoolsImpl{ + client: client, + }, } } +// Instance Pools API are used to create, edit, delete and list instance pools +// by using ready-to-use cloud instances which reduces a cluster start and +// auto-scaling times. +// +// Databricks pools reduce cluster start and auto-scaling times by maintaining a +// set of idle, ready-to-use instances. When a cluster is attached to a pool, +// cluster nodes are created using the pool’s idle instances. If the pool has +// no idle instances, the pool expands by allocating a new instance from the +// instance provider in order to accommodate the cluster’s request. When a +// cluster releases an instance, it returns to the pool and is free for another +// cluster to use. Only clusters attached to a pool can use that pool’s idle +// instances. +// +// You can specify a different pool for the driver node and worker nodes, or use +// the same pool for both. +// +// Databricks does not charge DBUs while instances are idle in the pool. +// Instance provider billing does apply. See pricing. type InstancePoolsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(InstancePoolsService) + impl InstancePoolsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *InstancePoolsAPI) WithImpl(impl InstancePoolsService) *InstancePoolsAPI { + a.impl = impl + return a +} + +// Impl returns low-level InstancePools API implementation +func (a *InstancePoolsAPI) Impl() InstancePoolsService { + return a.impl } // Create a new instance pool // // Creates a new instance pool using idle and ready-to-use cloud instances. func (a *InstancePoolsAPI) Create(ctx context.Context, request CreateInstancePool) (*CreateInstancePoolResponse, error) { - var createInstancePoolResponse CreateInstancePoolResponse - path := "/api/2.0/instance-pools/create" - err := a.client.Post(ctx, path, request, &createInstancePoolResponse) - return &createInstancePoolResponse, err + return a.impl.Create(ctx, request) } // Delete an instance pool @@ -33,9 +64,7 @@ func (a *InstancePoolsAPI) Create(ctx context.Context, request CreateInstancePoo // Deletes the instance pool permanently. The idle instances in the pool are // terminated asynchronously. func (a *InstancePoolsAPI) Delete(ctx context.Context, request DeleteInstancePool) error { - path := "/api/2.0/instance-pools/delete" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.Delete(ctx, request) } // Delete an instance pool @@ -43,7 +72,7 @@ func (a *InstancePoolsAPI) Delete(ctx context.Context, request DeleteInstancePoo // Deletes the instance pool permanently. The idle instances in the pool are // terminated asynchronously. func (a *InstancePoolsAPI) DeleteByInstancePoolId(ctx context.Context, instancePoolId string) error { - return a.Delete(ctx, DeleteInstancePool{ + return a.impl.Delete(ctx, DeleteInstancePool{ InstancePoolId: instancePoolId, }) } @@ -52,26 +81,21 @@ func (a *InstancePoolsAPI) DeleteByInstancePoolId(ctx context.Context, instanceP // // Modifies the configuration of an existing instance pool. func (a *InstancePoolsAPI) Edit(ctx context.Context, request EditInstancePool) error { - path := "/api/2.0/instance-pools/edit" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.Edit(ctx, request) } // Get instance pool information // // Retrieve the information for an instance pool based on its identifier. func (a *InstancePoolsAPI) Get(ctx context.Context, request GetRequest) (*GetInstancePool, error) { - var getInstancePool GetInstancePool - path := "/api/2.0/instance-pools/get" - err := a.client.Get(ctx, path, request, &getInstancePool) - return &getInstancePool, err + return a.impl.Get(ctx, request) } // Get instance pool information // // Retrieve the information for an instance pool based on its identifier. func (a *InstancePoolsAPI) GetByInstancePoolId(ctx context.Context, instancePoolId string) (*GetInstancePool, error) { - return a.Get(ctx, GetRequest{ + return a.impl.Get(ctx, GetRequest{ InstancePoolId: instancePoolId, }) } @@ -80,19 +104,9 @@ func (a *InstancePoolsAPI) GetByInstancePoolId(ctx context.Context, instancePool // // Gets a list of instance pools with their statistics. // -// Use ListAll() to get all InstancePoolAndStats instances -func (a *InstancePoolsAPI) List(ctx context.Context) (*ListInstancePools, error) { - var listInstancePools ListInstancePools - path := "/api/2.0/instance-pools/list" - err := a.client.Get(ctx, path, nil, &listInstancePools) - return &listInstancePools, err -} - -// ListAll returns all InstancePoolAndStats instances. This method exists for consistency purposes. -// // This method is generated by Databricks SDK Code Generator. func (a *InstancePoolsAPI) ListAll(ctx context.Context) ([]InstancePoolAndStats, error) { - response, err := a.List(ctx) + response, err := a.impl.List(ctx) if err != nil { return nil, err } diff --git a/service/instancepools/impl.go b/service/instancepools/impl.go new file mode 100755 index 000000000..3249516c7 --- /dev/null +++ b/service/instancepools/impl.go @@ -0,0 +1,47 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package instancepools + +import ( + "context" + + "github.com/databricks/databricks-sdk-go/databricks/client" +) + +// unexported type that holds implementations of just InstancePools API methods +type instancePoolsImpl struct { + client *client.DatabricksClient +} + +func (a *instancePoolsImpl) Create(ctx context.Context, request CreateInstancePool) (*CreateInstancePoolResponse, error) { + var createInstancePoolResponse CreateInstancePoolResponse + path := "/api/2.0/instance-pools/create" + err := a.client.Post(ctx, path, request, &createInstancePoolResponse) + return &createInstancePoolResponse, err +} + +func (a *instancePoolsImpl) Delete(ctx context.Context, request DeleteInstancePool) error { + path := "/api/2.0/instance-pools/delete" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *instancePoolsImpl) Edit(ctx context.Context, request EditInstancePool) error { + path := "/api/2.0/instance-pools/edit" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *instancePoolsImpl) Get(ctx context.Context, request GetRequest) (*GetInstancePool, error) { + var getInstancePool GetInstancePool + path := "/api/2.0/instance-pools/get" + err := a.client.Get(ctx, path, request, &getInstancePool) + return &getInstancePool, err +} + +func (a *instancePoolsImpl) List(ctx context.Context) (*ListInstancePools, error) { + var listInstancePools ListInstancePools + path := "/api/2.0/instance-pools/list" + err := a.client.Get(ctx, path, nil, &listInstancePools) + return &listInstancePools, err +} diff --git a/service/instancepools/interface.go b/service/instancepools/interface.go index f8c1f1ff4..fae678453 100755 --- a/service/instancepools/interface.go +++ b/service/instancepools/interface.go @@ -24,10 +24,6 @@ import ( // // Databricks does not charge DBUs while instances are idle in the pool. // Instance provider billing does apply. See pricing. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type InstancePoolsService interface { // Create a new instance pool @@ -41,12 +37,6 @@ type InstancePoolsService interface { // terminated asynchronously. Delete(ctx context.Context, request DeleteInstancePool) error - // DeleteByInstancePoolId calls Delete, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteByInstancePoolId(ctx context.Context, instancePoolId string) error - // Edit an existing instance pool // // Modifies the configuration of an existing instance pool. @@ -57,21 +47,10 @@ type InstancePoolsService interface { // Retrieve the information for an instance pool based on its identifier. Get(ctx context.Context, request GetRequest) (*GetInstancePool, error) - // GetByInstancePoolId calls Get, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetByInstancePoolId(ctx context.Context, instancePoolId string) (*GetInstancePool, error) - // List instance pool info // // Gets a list of instance pools with their statistics. // // Use ListAll() to get all InstancePoolAndStats instances List(ctx context.Context) (*ListInstancePools, error) - - // ListAll calls List() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListAll(ctx context.Context) ([]InstancePoolAndStats, error) } diff --git a/service/ipaccesslists/api.go b/service/ipaccesslists/api.go index 7b3cd6ab8..b849bc628 100755 --- a/service/ipaccesslists/api.go +++ b/service/ipaccesslists/api.go @@ -4,19 +4,56 @@ package ipaccesslists import ( "context" - "fmt" "github.com/databricks/databricks-sdk-go/databricks/client" ) -func NewIpAccessLists(client *client.DatabricksClient) IpAccessListsService { +func NewIpAccessLists(client *client.DatabricksClient) *IpAccessListsAPI { return &IpAccessListsAPI{ - client: client, + impl: &ipAccessListsImpl{ + client: client, + }, } } +// The IP Access List API enables Databricks admins to configure IP access lists +// for a workspace. +// +// IP access lists affect web application access and REST API access to this +// workspace only. If the feature is disabled for a workspace, all access is +// allowed for this workspace. There is support for allow lists (inclusion) and +// block lists (exclusion). +// +// When a connection is attempted: 1. **First, all block lists are checked.** If +// the connection IP address matches any block list, the connection is rejected. +// 2. **If the connection was not rejected by block lists**, the IP address is +// compared with the allow lists. +// +// If there is at least one allow list for the workspace, the connection is +// allowed only if the IP address matches an allow list. If there are no allow +// lists for the workspace, all IP addresses are allowed. +// +// For all allow lists and block lists combined, the workspace supports a +// maximum of 1000 IP/CIDR values, where one CIDR counts as a single value. +// +// After changes to the IP access list feature, it can take a few minutes for +// changes to take effect. type IpAccessListsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(IpAccessListsService) + impl IpAccessListsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *IpAccessListsAPI) WithImpl(impl IpAccessListsService) *IpAccessListsAPI { + a.impl = impl + return a +} + +// Impl returns low-level IpAccessLists API implementation +func (a *IpAccessListsAPI) Impl() IpAccessListsService { + return a.impl } // Create access list @@ -37,26 +74,21 @@ type IpAccessListsAPI struct { // IP access list has no effect until you enable the feature. See // [`/workspace-conf`](#operation/set-status). func (a *IpAccessListsAPI) CreateIpAccessList(ctx context.Context, request CreateIpAccessListRequest) (*IpAccessListInfo, error) { - var ipAccessListInfo IpAccessListInfo - path := "/api/2.0/ip-access-lists" - err := a.client.Post(ctx, path, request, &ipAccessListInfo) - return &ipAccessListInfo, err + return a.impl.CreateIpAccessList(ctx, request) } // Delete access list // // Deletes an IP access list, specified by its list ID. func (a *IpAccessListsAPI) DeleteIpAccessList(ctx context.Context, request DeleteIpAccessListRequest) error { - path := fmt.Sprintf("/api/2.0/ip-access-lists/%v", request.IpAccessListId) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteIpAccessList(ctx, request) } // Delete access list // // Deletes an IP access list, specified by its list ID. func (a *IpAccessListsAPI) DeleteIpAccessListByIpAccessListId(ctx context.Context, ipAccessListId string) error { - return a.DeleteIpAccessList(ctx, DeleteIpAccessListRequest{ + return a.impl.DeleteIpAccessList(ctx, DeleteIpAccessListRequest{ IpAccessListId: ipAccessListId, }) } @@ -65,17 +97,14 @@ func (a *IpAccessListsAPI) DeleteIpAccessListByIpAccessListId(ctx context.Contex // // Gets an IP access list, specified by its list ID. func (a *IpAccessListsAPI) FetchIpAccessList(ctx context.Context, request FetchIpAccessListRequest) (*IpAccessListInfo, error) { - var ipAccessListInfo IpAccessListInfo - path := fmt.Sprintf("/api/2.0/ip-access-lists/%v", request.IpAccessListId) - err := a.client.Get(ctx, path, request, &ipAccessListInfo) - return &ipAccessListInfo, err + return a.impl.FetchIpAccessList(ctx, request) } // Get access list // // Gets an IP access list, specified by its list ID. func (a *IpAccessListsAPI) FetchIpAccessListByIpAccessListId(ctx context.Context, ipAccessListId string) (*IpAccessListInfo, error) { - return a.FetchIpAccessList(ctx, FetchIpAccessListRequest{ + return a.impl.FetchIpAccessList(ctx, FetchIpAccessListRequest{ IpAccessListId: ipAccessListId, }) } @@ -84,19 +113,9 @@ func (a *IpAccessListsAPI) FetchIpAccessListByIpAccessListId(ctx context.Context // // Gets all IP access lists for the specified workspace. // -// Use ListIpAccessListsAll() to get all IpAccessListInfo instances -func (a *IpAccessListsAPI) ListIpAccessLists(ctx context.Context) (*GetIpAccessListResponse, error) { - var getIpAccessListResponse GetIpAccessListResponse - path := "/api/2.0/ip-access-lists" - err := a.client.Get(ctx, path, nil, &getIpAccessListResponse) - return &getIpAccessListResponse, err -} - -// ListIpAccessListsAll returns all IpAccessListInfo instances. This method exists for consistency purposes. -// // This method is generated by Databricks SDK Code Generator. func (a *IpAccessListsAPI) ListIpAccessListsAll(ctx context.Context) ([]IpAccessListInfo, error) { - response, err := a.ListIpAccessLists(ctx) + response, err := a.impl.ListIpAccessLists(ctx) if err != nil { return nil, err } @@ -124,9 +143,7 @@ func (a *IpAccessListsAPI) ListIpAccessListsAll(ctx context.Context) ([]IpAccess // Note that your resulting IP access list has no effect until you enable the // feature. See [`/workspace-conf`](#operation/set-status). func (a *IpAccessListsAPI) ReplaceIpAccessList(ctx context.Context, request ReplaceIpAccessListRequest) error { - path := fmt.Sprintf("/api/2.0/ip-access-lists/%v", request.IpAccessListId) - err := a.client.Put(ctx, path, request) - return err + return a.impl.ReplaceIpAccessList(ctx, request) } // Update access list @@ -147,7 +164,5 @@ func (a *IpAccessListsAPI) ReplaceIpAccessList(ctx context.Context, request Repl // resulting IP access list has no effect until you enable the feature. See // [`/workspace-conf`](#operation/set-status). func (a *IpAccessListsAPI) UpdateIpAccessList(ctx context.Context, request UpdateIpAccessListRequest) error { - path := fmt.Sprintf("/api/2.0/ip-access-lists/%v", request.IpAccessListId) - err := a.client.Patch(ctx, path, request) - return err + return a.impl.UpdateIpAccessList(ctx, request) } diff --git a/service/ipaccesslists/impl.go b/service/ipaccesslists/impl.go new file mode 100755 index 000000000..b4ab781a3 --- /dev/null +++ b/service/ipaccesslists/impl.go @@ -0,0 +1,54 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package ipaccesslists + +import ( + "context" + "fmt" + + "github.com/databricks/databricks-sdk-go/databricks/client" +) + +// unexported type that holds implementations of just IpAccessLists API methods +type ipAccessListsImpl struct { + client *client.DatabricksClient +} + +func (a *ipAccessListsImpl) CreateIpAccessList(ctx context.Context, request CreateIpAccessListRequest) (*IpAccessListInfo, error) { + var ipAccessListInfo IpAccessListInfo + path := "/api/2.0/ip-access-lists" + err := a.client.Post(ctx, path, request, &ipAccessListInfo) + return &ipAccessListInfo, err +} + +func (a *ipAccessListsImpl) DeleteIpAccessList(ctx context.Context, request DeleteIpAccessListRequest) error { + path := fmt.Sprintf("/api/2.0/ip-access-lists/%v", request.IpAccessListId) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *ipAccessListsImpl) FetchIpAccessList(ctx context.Context, request FetchIpAccessListRequest) (*IpAccessListInfo, error) { + var ipAccessListInfo IpAccessListInfo + path := fmt.Sprintf("/api/2.0/ip-access-lists/%v", request.IpAccessListId) + err := a.client.Get(ctx, path, request, &ipAccessListInfo) + return &ipAccessListInfo, err +} + +func (a *ipAccessListsImpl) ListIpAccessLists(ctx context.Context) (*GetIpAccessListResponse, error) { + var getIpAccessListResponse GetIpAccessListResponse + path := "/api/2.0/ip-access-lists" + err := a.client.Get(ctx, path, nil, &getIpAccessListResponse) + return &getIpAccessListResponse, err +} + +func (a *ipAccessListsImpl) ReplaceIpAccessList(ctx context.Context, request ReplaceIpAccessListRequest) error { + path := fmt.Sprintf("/api/2.0/ip-access-lists/%v", request.IpAccessListId) + err := a.client.Put(ctx, path, request) + return err +} + +func (a *ipAccessListsImpl) UpdateIpAccessList(ctx context.Context, request UpdateIpAccessListRequest) error { + path := fmt.Sprintf("/api/2.0/ip-access-lists/%v", request.IpAccessListId) + err := a.client.Patch(ctx, path, request) + return err +} diff --git a/service/ipaccesslists/interface.go b/service/ipaccesslists/interface.go index 4edce3764..dfec2dd20 100755 --- a/service/ipaccesslists/interface.go +++ b/service/ipaccesslists/interface.go @@ -28,10 +28,6 @@ import ( // // After changes to the IP access list feature, it can take a few minutes for // changes to take effect. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type IpAccessListsService interface { // Create access list @@ -59,23 +55,11 @@ type IpAccessListsService interface { // Deletes an IP access list, specified by its list ID. DeleteIpAccessList(ctx context.Context, request DeleteIpAccessListRequest) error - // DeleteIpAccessListByIpAccessListId calls DeleteIpAccessList, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteIpAccessListByIpAccessListId(ctx context.Context, ipAccessListId string) error - // Get access list // // Gets an IP access list, specified by its list ID. FetchIpAccessList(ctx context.Context, request FetchIpAccessListRequest) (*IpAccessListInfo, error) - // FetchIpAccessListByIpAccessListId calls FetchIpAccessList, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - FetchIpAccessListByIpAccessListId(ctx context.Context, ipAccessListId string) (*IpAccessListInfo, error) - // Get access lists // // Gets all IP access lists for the specified workspace. @@ -83,11 +67,6 @@ type IpAccessListsService interface { // Use ListIpAccessListsAll() to get all IpAccessListInfo instances ListIpAccessLists(ctx context.Context) (*GetIpAccessListResponse, error) - // ListIpAccessListsAll calls ListIpAccessLists() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListIpAccessListsAll(ctx context.Context) ([]IpAccessListInfo, error) - // Replace access list // // Replaces an IP access list, specified by its ID. diff --git a/service/jobs/api.go b/service/jobs/api.go index e957c7e2d..197b07d1a 100755 --- a/service/jobs/api.go +++ b/service/jobs/api.go @@ -12,14 +12,40 @@ import ( "github.com/databricks/databricks-sdk-go/databricks/useragent" ) -func NewJobs(client *client.DatabricksClient) JobsService { +func NewJobs(client *client.DatabricksClient) *JobsAPI { return &JobsAPI{ - client: client, + impl: &jobsImpl{ + client: client, + }, } } +// The Jobs API allows you to create, edit, and delete jobs. +// +// You can use a Databricks job to run a data processing or data analysis task +// in a Databricks cluster with scalable resources. Your job can consist of a +// single task or can be a large, multi-task workflow with complex dependencies. +// Databricks manages the task orchestration, cluster management, monitoring, +// and error reporting for all of your jobs. You can run your jobs immediately +// or periodically through an easy-to-use scheduling system. You can implement +// job tasks using notebooks, JARS, Delta Live Tables pipelines, or Python, +// Scala, Spark submit, and Java applications. type JobsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(JobsService) + impl JobsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *JobsAPI) WithImpl(impl JobsService) *JobsAPI { + a.impl = impl + return a +} + +// Impl returns low-level Jobs API implementation +func (a *JobsAPI) Impl() JobsService { + return a.impl } // Cancel all runs of a job @@ -27,9 +53,7 @@ type JobsAPI struct { // Cancels all active runs of a job. The runs are canceled asynchronously, so it // doesn't prevent new runs from being started. func (a *JobsAPI) CancelAllRuns(ctx context.Context, request CancelAllRuns) error { - path := "/api/2.1/jobs/runs/cancel-all" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.CancelAllRuns(ctx, request) } // Cancel all runs of a job @@ -37,7 +61,7 @@ func (a *JobsAPI) CancelAllRuns(ctx context.Context, request CancelAllRuns) erro // Cancels all active runs of a job. The runs are canceled asynchronously, so it // doesn't prevent new runs from being started. func (a *JobsAPI) CancelAllRunsByJobId(ctx context.Context, jobId int64) error { - return a.CancelAllRuns(ctx, CancelAllRuns{ + return a.impl.CancelAllRuns(ctx, CancelAllRuns{ JobId: jobId, }) } @@ -47,12 +71,10 @@ func (a *JobsAPI) CancelAllRunsByJobId(ctx context.Context, jobId int64) error { // Cancels a job run. The run is canceled asynchronously, so it may still be // running when this request completes. func (a *JobsAPI) CancelRun(ctx context.Context, request CancelRun) error { - path := "/api/2.1/jobs/runs/cancel" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.CancelRun(ctx, request) } -// CancelRun and wait to reach TERMINATED or SKIPPED state +// Calls [JobsAPI.CancelRun] and waits to reach TERMINATED or SKIPPED state // // You can override the default timeout of 20 minutes by calling adding // retries.Timeout[Run](60*time.Minute) functional option. @@ -99,7 +121,7 @@ func (a *JobsAPI) CancelRunAndWait(ctx context.Context, cancelRun CancelRun, opt // Cancels a job run. The run is canceled asynchronously, so it may still be // running when this request completes. func (a *JobsAPI) CancelRunByRunId(ctx context.Context, runId int64) error { - return a.CancelRun(ctx, CancelRun{ + return a.impl.CancelRun(ctx, CancelRun{ RunId: runId, }) } @@ -114,26 +136,21 @@ func (a *JobsAPI) CancelRunByRunIdAndWait(ctx context.Context, runId int64, opti // // Create a new job. func (a *JobsAPI) Create(ctx context.Context, request CreateJob) (*CreateResponse, error) { - var createResponse CreateResponse - path := "/api/2.1/jobs/create" - err := a.client.Post(ctx, path, request, &createResponse) - return &createResponse, err + return a.impl.Create(ctx, request) } // Delete a job // // Deletes a job. func (a *JobsAPI) Delete(ctx context.Context, request DeleteJob) error { - path := "/api/2.1/jobs/delete" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.Delete(ctx, request) } // Delete a job // // Deletes a job. func (a *JobsAPI) DeleteByJobId(ctx context.Context, jobId int64) error { - return a.Delete(ctx, DeleteJob{ + return a.impl.Delete(ctx, DeleteJob{ JobId: jobId, }) } @@ -142,16 +159,14 @@ func (a *JobsAPI) DeleteByJobId(ctx context.Context, jobId int64) error { // // Deletes a non-active run. Returns an error if the run is active. func (a *JobsAPI) DeleteRun(ctx context.Context, request DeleteRun) error { - path := "/api/2.1/jobs/runs/delete" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.DeleteRun(ctx, request) } // Delete a job run // // Deletes a non-active run. Returns an error if the run is active. func (a *JobsAPI) DeleteRunByRunId(ctx context.Context, runId int64) error { - return a.DeleteRun(ctx, DeleteRun{ + return a.impl.DeleteRun(ctx, DeleteRun{ RunId: runId, }) } @@ -160,27 +175,21 @@ func (a *JobsAPI) DeleteRunByRunId(ctx context.Context, runId int64) error { // // Export and retrieve the job run task. func (a *JobsAPI) ExportRun(ctx context.Context, request ExportRunRequest) (*ExportRunOutput, error) { - var exportRunOutput ExportRunOutput - path := "/api/2.1/jobs/runs/export" - err := a.client.Get(ctx, path, request, &exportRunOutput) - return &exportRunOutput, err + return a.impl.ExportRun(ctx, request) } // Get a single job // // Retrieves the details for a single job. func (a *JobsAPI) Get(ctx context.Context, request GetRequest) (*Job, error) { - var job Job - path := "/api/2.1/jobs/get" - err := a.client.Get(ctx, path, request, &job) - return &job, err + return a.impl.Get(ctx, request) } // Get a single job // // Retrieves the details for a single job. func (a *JobsAPI) GetByJobId(ctx context.Context, jobId int64) (*Job, error) { - return a.Get(ctx, GetRequest{ + return a.impl.Get(ctx, GetRequest{ JobId: jobId, }) } @@ -189,13 +198,10 @@ func (a *JobsAPI) GetByJobId(ctx context.Context, jobId int64) (*Job, error) { // // Retrieve the metadata of a run. func (a *JobsAPI) GetRun(ctx context.Context, request GetRunRequest) (*Run, error) { - var run Run - path := "/api/2.1/jobs/runs/get" - err := a.client.Get(ctx, path, request, &run) - return &run, err + return a.impl.GetRun(ctx, request) } -// GetRun and wait to reach TERMINATED or SKIPPED state +// Calls [JobsAPI.GetRun] and waits to reach TERMINATED or SKIPPED state // // You can override the default timeout of 20 minutes by calling adding // retries.Timeout[Run](60*time.Minute) functional option. @@ -250,10 +256,7 @@ func (a *JobsAPI) GetRunAndWait(ctx context.Context, getRunRequest GetRunRequest // automatically removed after 60 days. If you to want to reference them beyond // 60 days, you must save old run results before they expire. func (a *JobsAPI) GetRunOutput(ctx context.Context, request GetRunOutputRequest) (*RunOutput, error) { - var runOutput RunOutput - path := "/api/2.1/jobs/runs/get-output" - err := a.client.Get(ctx, path, request, &runOutput) - return &runOutput, err + return a.impl.GetRunOutput(ctx, request) } // Get the output for a single run @@ -269,7 +272,7 @@ func (a *JobsAPI) GetRunOutput(ctx context.Context, request GetRunOutputRequest) // automatically removed after 60 days. If you to want to reference them beyond // 60 days, you must save old run results before they expire. func (a *JobsAPI) GetRunOutputByRunId(ctx context.Context, runId int64) (*RunOutput, error) { - return a.GetRunOutput(ctx, GetRunOutputRequest{ + return a.impl.GetRunOutput(ctx, GetRunOutputRequest{ RunId: runId, }) } @@ -278,22 +281,12 @@ func (a *JobsAPI) GetRunOutputByRunId(ctx context.Context, runId int64) (*RunOut // // Retrieves a list of jobs. // -// Use ListAll() to get all Job instances, which will iterate over every result page. -func (a *JobsAPI) List(ctx context.Context, request ListRequest) (*ListResponse, error) { - var listResponse ListResponse - path := "/api/2.1/jobs/list" - err := a.client.Get(ctx, path, request, &listResponse) - return &listResponse, err -} - -// ListAll returns all Job instances by calling List for every result page -// // This method is generated by Databricks SDK Code Generator. func (a *JobsAPI) ListAll(ctx context.Context, request ListRequest) ([]Job, error) { var results []Job ctx = useragent.InContext(ctx, "sdk-feature", "pagination") for { - response, err := a.List(ctx, request) + response, err := a.impl.List(ctx, request) if err != nil { return nil, err } @@ -312,22 +305,12 @@ func (a *JobsAPI) ListAll(ctx context.Context, request ListRequest) ([]Job, erro // // List runs in descending order by start time. // -// Use ListRunsAll() to get all Run instances, which will iterate over every result page. -func (a *JobsAPI) ListRuns(ctx context.Context, request ListRunsRequest) (*ListRunsResponse, error) { - var listRunsResponse ListRunsResponse - path := "/api/2.1/jobs/runs/list" - err := a.client.Get(ctx, path, request, &listRunsResponse) - return &listRunsResponse, err -} - -// ListRunsAll returns all Run instances by calling ListRuns for every result page -// // This method is generated by Databricks SDK Code Generator. func (a *JobsAPI) ListRunsAll(ctx context.Context, request ListRunsRequest) ([]Run, error) { var results []Run ctx = useragent.InContext(ctx, "sdk-feature", "pagination") for { - response, err := a.ListRuns(ctx, request) + response, err := a.impl.ListRuns(ctx, request) if err != nil { return nil, err } @@ -348,13 +331,10 @@ func (a *JobsAPI) ListRunsAll(ctx context.Context, request ListRunsRequest) ([]R // They use the current job and task settings, and can be viewed in the history // for the original job run. func (a *JobsAPI) RepairRun(ctx context.Context, request RepairRun) (*RepairRunResponse, error) { - var repairRunResponse RepairRunResponse - path := "/api/2.1/jobs/runs/repair" - err := a.client.Post(ctx, path, request, &repairRunResponse) - return &repairRunResponse, err + return a.impl.RepairRun(ctx, request) } -// RepairRun and wait to reach TERMINATED or SKIPPED state +// Calls [JobsAPI.RepairRun] and waits to reach TERMINATED or SKIPPED state // // You can override the default timeout of 20 minutes by calling adding // retries.Timeout[Run](60*time.Minute) functional option. @@ -401,22 +381,17 @@ func (a *JobsAPI) RepairRunAndWait(ctx context.Context, repairRun RepairRun, opt // Overwrites all the settings for a specific job. Use the Update endpoint to // update job settings partially. func (a *JobsAPI) Reset(ctx context.Context, request ResetJob) error { - path := "/api/2.1/jobs/reset" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.Reset(ctx, request) } // Trigger a new job run // // Run a job and return the `run_id` of the triggered run. func (a *JobsAPI) RunNow(ctx context.Context, request RunNow) (*RunNowResponse, error) { - var runNowResponse RunNowResponse - path := "/api/2.1/jobs/run-now" - err := a.client.Post(ctx, path, request, &runNowResponse) - return &runNowResponse, err + return a.impl.RunNow(ctx, request) } -// RunNow and wait to reach TERMINATED or SKIPPED state +// Calls [JobsAPI.RunNow] and waits to reach TERMINATED or SKIPPED state // // You can override the default timeout of 20 minutes by calling adding // retries.Timeout[Run](60*time.Minute) functional option. @@ -465,13 +440,10 @@ func (a *JobsAPI) RunNowAndWait(ctx context.Context, runNow RunNow, options ...r // the UI. Use the `jobs/runs/get` API to check the run state after the job is // submitted. func (a *JobsAPI) Submit(ctx context.Context, request SubmitRun) (*SubmitRunResponse, error) { - var submitRunResponse SubmitRunResponse - path := "/api/2.1/jobs/runs/submit" - err := a.client.Post(ctx, path, request, &submitRunResponse) - return &submitRunResponse, err + return a.impl.Submit(ctx, request) } -// Submit and wait to reach TERMINATED or SKIPPED state +// Calls [JobsAPI.Submit] and waits to reach TERMINATED or SKIPPED state // // You can override the default timeout of 20 minutes by calling adding // retries.Timeout[Run](60*time.Minute) functional option. @@ -518,7 +490,5 @@ func (a *JobsAPI) SubmitAndWait(ctx context.Context, submitRun SubmitRun, option // Add, update, or remove specific settings of an existing job. Use the ResetJob // to overwrite all job settings. func (a *JobsAPI) Update(ctx context.Context, request UpdateJob) error { - path := "/api/2.1/jobs/update" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.Update(ctx, request) } diff --git a/service/jobs/impl.go b/service/jobs/impl.go new file mode 100755 index 000000000..e8c8ebc63 --- /dev/null +++ b/service/jobs/impl.go @@ -0,0 +1,120 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package jobs + +import ( + "context" + + "github.com/databricks/databricks-sdk-go/databricks/client" +) + +// unexported type that holds implementations of just Jobs API methods +type jobsImpl struct { + client *client.DatabricksClient +} + +func (a *jobsImpl) CancelAllRuns(ctx context.Context, request CancelAllRuns) error { + path := "/api/2.1/jobs/runs/cancel-all" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *jobsImpl) CancelRun(ctx context.Context, request CancelRun) error { + path := "/api/2.1/jobs/runs/cancel" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *jobsImpl) Create(ctx context.Context, request CreateJob) (*CreateResponse, error) { + var createResponse CreateResponse + path := "/api/2.1/jobs/create" + err := a.client.Post(ctx, path, request, &createResponse) + return &createResponse, err +} + +func (a *jobsImpl) Delete(ctx context.Context, request DeleteJob) error { + path := "/api/2.1/jobs/delete" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *jobsImpl) DeleteRun(ctx context.Context, request DeleteRun) error { + path := "/api/2.1/jobs/runs/delete" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *jobsImpl) ExportRun(ctx context.Context, request ExportRunRequest) (*ExportRunOutput, error) { + var exportRunOutput ExportRunOutput + path := "/api/2.1/jobs/runs/export" + err := a.client.Get(ctx, path, request, &exportRunOutput) + return &exportRunOutput, err +} + +func (a *jobsImpl) Get(ctx context.Context, request GetRequest) (*Job, error) { + var job Job + path := "/api/2.1/jobs/get" + err := a.client.Get(ctx, path, request, &job) + return &job, err +} + +func (a *jobsImpl) GetRun(ctx context.Context, request GetRunRequest) (*Run, error) { + var run Run + path := "/api/2.1/jobs/runs/get" + err := a.client.Get(ctx, path, request, &run) + return &run, err +} + +func (a *jobsImpl) GetRunOutput(ctx context.Context, request GetRunOutputRequest) (*RunOutput, error) { + var runOutput RunOutput + path := "/api/2.1/jobs/runs/get-output" + err := a.client.Get(ctx, path, request, &runOutput) + return &runOutput, err +} + +func (a *jobsImpl) List(ctx context.Context, request ListRequest) (*ListResponse, error) { + var listResponse ListResponse + path := "/api/2.1/jobs/list" + err := a.client.Get(ctx, path, request, &listResponse) + return &listResponse, err +} + +func (a *jobsImpl) ListRuns(ctx context.Context, request ListRunsRequest) (*ListRunsResponse, error) { + var listRunsResponse ListRunsResponse + path := "/api/2.1/jobs/runs/list" + err := a.client.Get(ctx, path, request, &listRunsResponse) + return &listRunsResponse, err +} + +func (a *jobsImpl) RepairRun(ctx context.Context, request RepairRun) (*RepairRunResponse, error) { + var repairRunResponse RepairRunResponse + path := "/api/2.1/jobs/runs/repair" + err := a.client.Post(ctx, path, request, &repairRunResponse) + return &repairRunResponse, err +} + +func (a *jobsImpl) Reset(ctx context.Context, request ResetJob) error { + path := "/api/2.1/jobs/reset" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *jobsImpl) RunNow(ctx context.Context, request RunNow) (*RunNowResponse, error) { + var runNowResponse RunNowResponse + path := "/api/2.1/jobs/run-now" + err := a.client.Post(ctx, path, request, &runNowResponse) + return &runNowResponse, err +} + +func (a *jobsImpl) Submit(ctx context.Context, request SubmitRun) (*SubmitRunResponse, error) { + var submitRunResponse SubmitRunResponse + path := "/api/2.1/jobs/runs/submit" + err := a.client.Post(ctx, path, request, &submitRunResponse) + return &submitRunResponse, err +} + +func (a *jobsImpl) Update(ctx context.Context, request UpdateJob) error { + path := "/api/2.1/jobs/update" + err := a.client.Post(ctx, path, request, nil) + return err +} diff --git a/service/jobs/interface.go b/service/jobs/interface.go index 49fb47138..9a3a010a0 100755 --- a/service/jobs/interface.go +++ b/service/jobs/interface.go @@ -4,8 +4,6 @@ package jobs import ( "context" - - "github.com/databricks/databricks-sdk-go/databricks/retries" ) // The Jobs API allows you to create, edit, and delete jobs. @@ -18,10 +16,6 @@ import ( // or periodically through an easy-to-use scheduling system. You can implement // job tasks using notebooks, JARS, Delta Live Tables pipelines, or Python, // Scala, Spark submit, and Java applications. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type JobsService interface { // Cancel all runs of a job @@ -30,33 +24,12 @@ type JobsService interface { // so it doesn't prevent new runs from being started. CancelAllRuns(ctx context.Context, request CancelAllRuns) error - // CancelAllRunsByJobId calls CancelAllRuns, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - CancelAllRunsByJobId(ctx context.Context, jobId int64) error - // Cancel a job run // // Cancels a job run. The run is canceled asynchronously, so it may still be // running when this request completes. CancelRun(ctx context.Context, request CancelRun) error - // CancelRunAndWait calls CancelRun() and waits to reach TERMINATED or SKIPPED state - // - // This method is generated by Databricks SDK Code Generator. - CancelRunAndWait(ctx context.Context, request CancelRun, options ...retries.Option[Run]) (*Run, error) - // CancelRunByRunId calls CancelRun, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - CancelRunByRunId(ctx context.Context, runId int64) error - - // CancelRunByRunIdAndWait calls CancelRunByRunId and waits until Run is in desired state. - // - // This method is generated by Databricks SDK Code Generator. - CancelRunByRunIdAndWait(ctx context.Context, runId int64, options ...retries.Option[Run]) (*Run, error) - // Create a new job // // Create a new job. @@ -67,23 +40,11 @@ type JobsService interface { // Deletes a job. Delete(ctx context.Context, request DeleteJob) error - // DeleteByJobId calls Delete, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteByJobId(ctx context.Context, jobId int64) error - // Delete a job run // // Deletes a non-active run. Returns an error if the run is active. DeleteRun(ctx context.Context, request DeleteRun) error - // DeleteRunByRunId calls DeleteRun, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteRunByRunId(ctx context.Context, runId int64) error - // Export and retrieve a job run // // Export and retrieve the job run task. @@ -94,22 +55,11 @@ type JobsService interface { // Retrieves the details for a single job. Get(ctx context.Context, request GetRequest) (*Job, error) - // GetByJobId calls Get, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetByJobId(ctx context.Context, jobId int64) (*Job, error) - // Get a single job run // // Retrieve the metadata of a run. GetRun(ctx context.Context, request GetRunRequest) (*Run, error) - // GetRunAndWait calls GetRun() and waits to reach TERMINATED or SKIPPED state - // - // This method is generated by Databricks SDK Code Generator. - GetRunAndWait(ctx context.Context, request GetRunRequest, options ...retries.Option[Run]) (*Run, error) - // Get the output for a single run // // Retrieve the output and metadata of a single task run. When a notebook @@ -124,12 +74,6 @@ type JobsService interface { // them beyond 60 days, you must save old run results before they expire. GetRunOutput(ctx context.Context, request GetRunOutputRequest) (*RunOutput, error) - // GetRunOutputByRunId calls GetRunOutput, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetRunOutputByRunId(ctx context.Context, runId int64) (*RunOutput, error) - // List all jobs // // Retrieves a list of jobs. @@ -137,11 +81,6 @@ type JobsService interface { // Use ListAll() to get all Job instances, which will iterate over every result page. List(ctx context.Context, request ListRequest) (*ListResponse, error) - // ListAll calls List() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListAll(ctx context.Context, request ListRequest) ([]Job, error) - // List runs for a job // // List runs in descending order by start time. @@ -149,11 +88,6 @@ type JobsService interface { // Use ListRunsAll() to get all Run instances, which will iterate over every result page. ListRuns(ctx context.Context, request ListRunsRequest) (*ListRunsResponse, error) - // ListRunsAll calls ListRuns() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListRunsAll(ctx context.Context, request ListRunsRequest) ([]Run, error) - // Repair a job run // // Re-run one or more tasks. Tasks are re-run as part of the original job @@ -161,11 +95,6 @@ type JobsService interface { // history for the original job run. RepairRun(ctx context.Context, request RepairRun) (*RepairRunResponse, error) - // RepairRunAndWait calls RepairRun() and waits to reach TERMINATED or SKIPPED state - // - // This method is generated by Databricks SDK Code Generator. - RepairRunAndWait(ctx context.Context, request RepairRun, options ...retries.Option[Run]) (*Run, error) - // Overwrites all settings for a job // // Overwrites all the settings for a specific job. Use the Update endpoint @@ -177,11 +106,6 @@ type JobsService interface { // Run a job and return the `run_id` of the triggered run. RunNow(ctx context.Context, request RunNow) (*RunNowResponse, error) - // RunNowAndWait calls RunNow() and waits to reach TERMINATED or SKIPPED state - // - // This method is generated by Databricks SDK Code Generator. - RunNowAndWait(ctx context.Context, request RunNow, options ...retries.Option[Run]) (*Run, error) - // Create and trigger a one-time run // // Submit a one-time run. This endpoint allows you to submit a workload @@ -190,11 +114,6 @@ type JobsService interface { // state after the job is submitted. Submit(ctx context.Context, request SubmitRun) (*SubmitRunResponse, error) - // SubmitAndWait calls Submit() and waits to reach TERMINATED or SKIPPED state - // - // This method is generated by Databricks SDK Code Generator. - SubmitAndWait(ctx context.Context, request SubmitRun, options ...retries.Option[Run]) (*Run, error) - // Partially updates a job // // Add, update, or remove specific settings of an existing job. Use the diff --git a/service/libraries/api.go b/service/libraries/api.go index 17753012c..4acec0ed8 100755 --- a/service/libraries/api.go +++ b/service/libraries/api.go @@ -8,14 +8,50 @@ import ( "github.com/databricks/databricks-sdk-go/databricks/client" ) -func NewLibraries(client *client.DatabricksClient) LibrariesService { +func NewLibraries(client *client.DatabricksClient) *LibrariesAPI { return &LibrariesAPI{ - client: client, + impl: &librariesImpl{ + client: client, + }, } } +// The Libraries API allows you to install and uninstall libraries and get the +// status of libraries on a cluster. +// +// To make third-party or custom code available to notebooks and jobs running on +// your clusters, you can install a library. Libraries can be written in Python, +// Java, Scala, and R. You can upload Java, Scala, and Python libraries and +// point to external packages in PyPI, Maven, and CRAN repositories. +// +// Cluster libraries can be used by all notebooks running on a cluster. You can +// install a cluster library directly from a public repository such as PyPI or +// Maven, using a previously installed workspace library, or using an init +// script. +// +// When you install a library on a cluster, a notebook already attached to that +// cluster will not immediately see the new library. You must first detach and +// then reattach the notebook to the cluster. +// +// When you uninstall a library from a cluster, the library is removed only when +// you restart the cluster. Until you restart the cluster, the status of the +// uninstalled library appears as Uninstall pending restart. type LibrariesAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(LibrariesService) + impl LibrariesService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *LibrariesAPI) WithImpl(impl LibrariesService) *LibrariesAPI { + a.impl = impl + return a +} + +// Impl returns low-level Libraries API implementation +func (a *LibrariesAPI) Impl() LibrariesService { + return a.impl } // Get all statuses @@ -25,10 +61,7 @@ type LibrariesAPI struct { // as well as libraries set to be installed on all clusters via the libraries // UI. func (a *LibrariesAPI) AllClusterStatuses(ctx context.Context) (*ListAllClusterLibraryStatusesResponse, error) { - var listAllClusterLibraryStatusesResponse ListAllClusterLibraryStatusesResponse - path := "/api/2.0/libraries/all-cluster-statuses" - err := a.client.Get(ctx, path, nil, &listAllClusterLibraryStatusesResponse) - return &listAllClusterLibraryStatusesResponse, err + return a.impl.AllClusterStatuses(ctx) } // Get status @@ -49,10 +82,7 @@ func (a *LibrariesAPI) AllClusterStatuses(ctx context.Context) (*ListAllClusterL // clusters, but now marked for removal. Within this group there is no order // guarantee. func (a *LibrariesAPI) ClusterStatus(ctx context.Context, request ClusterStatusRequest) (*ClusterLibraryStatuses, error) { - var clusterLibraryStatuses ClusterLibraryStatuses - path := "/api/2.0/libraries/cluster-status" - err := a.client.Get(ctx, path, request, &clusterLibraryStatuses) - return &clusterLibraryStatuses, err + return a.impl.ClusterStatus(ctx, request) } // Get status @@ -73,7 +103,7 @@ func (a *LibrariesAPI) ClusterStatus(ctx context.Context, request ClusterStatusR // clusters, but now marked for removal. Within this group there is no order // guarantee. func (a *LibrariesAPI) ClusterStatusByClusterId(ctx context.Context, clusterId string) (*ClusterLibraryStatuses, error) { - return a.ClusterStatus(ctx, ClusterStatusRequest{ + return a.impl.ClusterStatus(ctx, ClusterStatusRequest{ ClusterId: clusterId, }) } @@ -87,9 +117,7 @@ func (a *LibrariesAPI) ClusterStatusByClusterId(ctx context.Context, clusterId s // union of the libraries specified via this method and the libraries set to be // installed on all clusters via the libraries UI. func (a *LibrariesAPI) Install(ctx context.Context, request InstallLibraries) error { - path := "/api/2.0/libraries/install" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.Install(ctx, request) } // Uninstall libraries @@ -98,7 +126,5 @@ func (a *LibrariesAPI) Install(ctx context.Context, request InstallLibraries) er // uninstalled until the cluster is restarted. Uninstalling libraries that are // not installed on the cluster will have no impact but is not an error. func (a *LibrariesAPI) Uninstall(ctx context.Context, request UninstallLibraries) error { - path := "/api/2.0/libraries/uninstall" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.Uninstall(ctx, request) } diff --git a/service/libraries/impl.go b/service/libraries/impl.go new file mode 100755 index 000000000..04a1ef5e2 --- /dev/null +++ b/service/libraries/impl.go @@ -0,0 +1,40 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package libraries + +import ( + "context" + + "github.com/databricks/databricks-sdk-go/databricks/client" +) + +// unexported type that holds implementations of just Libraries API methods +type librariesImpl struct { + client *client.DatabricksClient +} + +func (a *librariesImpl) AllClusterStatuses(ctx context.Context) (*ListAllClusterLibraryStatusesResponse, error) { + var listAllClusterLibraryStatusesResponse ListAllClusterLibraryStatusesResponse + path := "/api/2.0/libraries/all-cluster-statuses" + err := a.client.Get(ctx, path, nil, &listAllClusterLibraryStatusesResponse) + return &listAllClusterLibraryStatusesResponse, err +} + +func (a *librariesImpl) ClusterStatus(ctx context.Context, request ClusterStatusRequest) (*ClusterLibraryStatuses, error) { + var clusterLibraryStatuses ClusterLibraryStatuses + path := "/api/2.0/libraries/cluster-status" + err := a.client.Get(ctx, path, request, &clusterLibraryStatuses) + return &clusterLibraryStatuses, err +} + +func (a *librariesImpl) Install(ctx context.Context, request InstallLibraries) error { + path := "/api/2.0/libraries/install" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *librariesImpl) Uninstall(ctx context.Context, request UninstallLibraries) error { + path := "/api/2.0/libraries/uninstall" + err := a.client.Post(ctx, path, request, nil) + return err +} diff --git a/service/libraries/interface.go b/service/libraries/interface.go index 9ecb3ea51..cedf3627e 100755 --- a/service/libraries/interface.go +++ b/service/libraries/interface.go @@ -4,8 +4,6 @@ package libraries import ( "context" - - "github.com/databricks/databricks-sdk-go/databricks/retries" ) // The Libraries API allows you to install and uninstall libraries and get the @@ -28,10 +26,6 @@ import ( // When you uninstall a library from a cluster, the library is removed only when // you restart the cluster. Until you restart the cluster, the status of the // uninstalled library appears as Uninstall pending restart. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type LibrariesService interface { // Get all statuses @@ -61,12 +55,6 @@ type LibrariesService interface { // guarantee. ClusterStatus(ctx context.Context, request ClusterStatusRequest) (*ClusterLibraryStatuses, error) - // ClusterStatusByClusterId calls ClusterStatus, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - ClusterStatusByClusterId(ctx context.Context, clusterId string) (*ClusterLibraryStatuses, error) - // Add a library // // Add libraries to be installed on a cluster. The installation is @@ -84,10 +72,4 @@ type LibrariesService interface { // uninstalled until the cluster is restarted. Uninstalling libraries that // are not installed on the cluster will have no impact but is not an error. Uninstall(ctx context.Context, request UninstallLibraries) error - - // UpdateAndWait installs or uninstalls specified libraries - // and waits until they are in a usable state - UpdateAndWait(ctx context.Context, update Update, options ...retries.Option[ClusterLibraryStatuses]) error - // Wait returns only once the libraries are in the usable state - Wait(ctx context.Context, wait Wait, options ...retries.Option[ClusterLibraryStatuses]) (*ClusterLibraryStatuses, error) } diff --git a/service/mlflow/api.go b/service/mlflow/api.go index 6aa21a5d0..b6978e0d9 100755 --- a/service/mlflow/api.go +++ b/service/mlflow/api.go @@ -9,14 +9,30 @@ import ( "github.com/databricks/databricks-sdk-go/databricks/useragent" ) -func NewExperiments(client *client.DatabricksClient) ExperimentsService { +func NewExperiments(client *client.DatabricksClient) *ExperimentsAPI { return &ExperimentsAPI{ - client: client, + impl: &experimentsImpl{ + client: client, + }, } } type ExperimentsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(ExperimentsService) + impl ExperimentsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *ExperimentsAPI) WithImpl(impl ExperimentsService) *ExperimentsAPI { + a.impl = impl + return a +} + +// Impl returns low-level Experiments API implementation +func (a *ExperimentsAPI) Impl() ExperimentsService { + return a.impl } // Create experiment @@ -29,10 +45,7 @@ type ExperimentsAPI struct { // Throws “RESOURCE_ALREADY_EXISTS“ if a experiment with the given name // exists. func (a *ExperimentsAPI) Create(ctx context.Context, request CreateExperiment) (*CreateExperimentResponse, error) { - var createExperimentResponse CreateExperimentResponse - path := "/api/2.0/mlflow/experiments/create" - err := a.client.Post(ctx, path, request, &createExperimentResponse) - return &createExperimentResponse, err + return a.impl.Create(ctx, request) } // Delete an experiment @@ -41,9 +54,7 @@ func (a *ExperimentsAPI) Create(ctx context.Context, request CreateExperiment) ( // for deletion. If the experiment uses FileStore, artifacts associated with // experiment are also deleted. func (a *ExperimentsAPI) Delete(ctx context.Context, request DeleteExperiment) error { - path := "/api/2.0/mlflow/experiments/delete" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.Delete(ctx, request) } // Delete an experiment @@ -52,7 +63,7 @@ func (a *ExperimentsAPI) Delete(ctx context.Context, request DeleteExperiment) e // for deletion. If the experiment uses FileStore, artifacts associated with // experiment are also deleted. func (a *ExperimentsAPI) DeleteByExperimentId(ctx context.Context, experimentId string) error { - return a.Delete(ctx, DeleteExperiment{ + return a.impl.Delete(ctx, DeleteExperiment{ ExperimentId: experimentId, }) } @@ -61,17 +72,14 @@ func (a *ExperimentsAPI) DeleteByExperimentId(ctx context.Context, experimentId // // Gets metadata for an experiment. This method works on deleted experiments. func (a *ExperimentsAPI) Get(ctx context.Context, request GetExperimentRequest) (*Experiment, error) { - var experiment Experiment - path := "/api/2.0/mlflow/experiments/get" - err := a.client.Get(ctx, path, request, &experiment) - return &experiment, err + return a.impl.Get(ctx, request) } // Get an experiment // // Gets metadata for an experiment. This method works on deleted experiments. func (a *ExperimentsAPI) GetByExperimentId(ctx context.Context, experimentId string) (*Experiment, error) { - return a.Get(ctx, GetExperimentRequest{ + return a.impl.Get(ctx, GetExperimentRequest{ ExperimentId: experimentId, }) } @@ -88,10 +96,7 @@ func (a *ExperimentsAPI) GetByExperimentId(ctx context.Context, experimentId str // Throws “RESOURCE_DOES_NOT_EXIST“ if no experiment with the specified name // exists.S func (a *ExperimentsAPI) GetByName(ctx context.Context, request GetByNameRequest) (*GetExperimentByNameResponse, error) { - var getExperimentByNameResponse GetExperimentByNameResponse - path := "/api/2.0/mlflow/experiments/get-by-name" - err := a.client.Get(ctx, path, request, &getExperimentByNameResponse) - return &getExperimentByNameResponse, err + return a.impl.GetByName(ctx, request) } // Get metadata @@ -106,7 +111,7 @@ func (a *ExperimentsAPI) GetByName(ctx context.Context, request GetByNameRequest // Throws “RESOURCE_DOES_NOT_EXIST“ if no experiment with the specified name // exists.S func (a *ExperimentsAPI) GetByNameByExperimentName(ctx context.Context, experimentName string) (*GetExperimentByNameResponse, error) { - return a.GetByName(ctx, GetByNameRequest{ + return a.impl.GetByName(ctx, GetByNameRequest{ ExperimentName: experimentName, }) } @@ -115,22 +120,12 @@ func (a *ExperimentsAPI) GetByNameByExperimentName(ctx context.Context, experime // // Gets a list of all experiments. // -// Use ListAll() to get all Experiment instances, which will iterate over every result page. -func (a *ExperimentsAPI) List(ctx context.Context, request ListExperimentsRequest) (*ListExperimentsResponse, error) { - var listExperimentsResponse ListExperimentsResponse - path := "/api/2.0/mlflow/experiments/list" - err := a.client.Get(ctx, path, request, &listExperimentsResponse) - return &listExperimentsResponse, err -} - -// ListAll returns all Experiment instances by calling List for every result page -// // This method is generated by Databricks SDK Code Generator. func (a *ExperimentsAPI) ListAll(ctx context.Context, request ListExperimentsRequest) ([]Experiment, error) { var results []Experiment ctx = useragent.InContext(ctx, "sdk-feature", "pagination") for { - response, err := a.List(ctx, request) + response, err := a.impl.List(ctx, request) if err != nil { return nil, err } @@ -156,9 +151,7 @@ func (a *ExperimentsAPI) ListAll(ctx context.Context, request ListExperimentsReq // “RESOURCE_DOES_NOT_EXIST“ if experiment was never created or was // permanently deleted.", func (a *ExperimentsAPI) Restore(ctx context.Context, request RestoreExperiment) error { - path := "/api/2.0/mlflow/experiments/restore" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.Restore(ctx, request) } // Restores an experiment @@ -169,7 +162,7 @@ func (a *ExperimentsAPI) Restore(ctx context.Context, request RestoreExperiment) // “RESOURCE_DOES_NOT_EXIST“ if experiment was never created or was // permanently deleted.", func (a *ExperimentsAPI) RestoreByExperimentId(ctx context.Context, experimentId string) error { - return a.Restore(ctx, RestoreExperiment{ + return a.impl.Restore(ctx, RestoreExperiment{ ExperimentId: experimentId, }) } @@ -178,22 +171,12 @@ func (a *ExperimentsAPI) RestoreByExperimentId(ctx context.Context, experimentId // // Searches for experiments that satisfy specified search criteria. // -// Use SearchAll() to get all Experiment instances, which will iterate over every result page. -func (a *ExperimentsAPI) Search(ctx context.Context, request SearchExperiments) (*SearchExperimentsResponse, error) { - var searchExperimentsResponse SearchExperimentsResponse - path := "/api/2.0/mlflow/experiments/search" - err := a.client.Post(ctx, path, request, &searchExperimentsResponse) - return &searchExperimentsResponse, err -} - -// SearchAll returns all Experiment instances by calling Search for every result page -// // This method is generated by Databricks SDK Code Generator. func (a *ExperimentsAPI) SearchAll(ctx context.Context, request SearchExperiments) ([]Experiment, error) { var results []Experiment ctx = useragent.InContext(ctx, "sdk-feature", "pagination") for { - response, err := a.Search(ctx, request) + response, err := a.impl.Search(ctx, request) if err != nil { return nil, err } @@ -216,28 +199,40 @@ func (a *ExperimentsAPI) SearchAll(ctx context.Context, request SearchExperiment // Sets a tag on an experiment. Experiment tags are metadata that can be // updated. func (a *ExperimentsAPI) SetExperimentTag(ctx context.Context, request SetExperimentTag) error { - path := "/api/2.0/mlflow/experiments/set-experiment-tag" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.SetExperimentTag(ctx, request) } // Update an experiment // // Updates experiment metadata. func (a *ExperimentsAPI) Update(ctx context.Context, request UpdateExperiment) error { - path := "/api/2.0/mlflow/experiments/update" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.Update(ctx, request) } -func NewMLflowArtifacts(client *client.DatabricksClient) MLflowArtifactsService { +func NewMLflowArtifacts(client *client.DatabricksClient) *MLflowArtifactsAPI { return &MLflowArtifactsAPI{ - client: client, + impl: &mLflowArtifactsImpl{ + client: client, + }, } } type MLflowArtifactsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(MLflowArtifactsService) + impl MLflowArtifactsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *MLflowArtifactsAPI) WithImpl(impl MLflowArtifactsService) *MLflowArtifactsAPI { + a.impl = impl + return a +} + +// Impl returns low-level MLflowArtifacts API implementation +func (a *MLflowArtifactsAPI) Impl() MLflowArtifactsService { + return a.impl } // Get all artifacts @@ -246,22 +241,12 @@ type MLflowArtifactsAPI struct { // is specified, the response contains only artifacts with the specified // prefix.", // -// Use ListAll() to get all FileInfo instances, which will iterate over every result page. -func (a *MLflowArtifactsAPI) List(ctx context.Context, request ListArtifactsRequest) (*ListArtifactsResponse, error) { - var listArtifactsResponse ListArtifactsResponse - path := "/api/2.0/mlflow/artifacts/list" - err := a.client.Get(ctx, path, request, &listArtifactsResponse) - return &listArtifactsResponse, err -} - -// ListAll returns all FileInfo instances by calling List for every result page -// // This method is generated by Databricks SDK Code Generator. func (a *MLflowArtifactsAPI) ListAll(ctx context.Context, request ListArtifactsRequest) ([]FileInfo, error) { var results []FileInfo ctx = useragent.InContext(ctx, "sdk-feature", "pagination") for { - response, err := a.List(ctx, request) + response, err := a.impl.List(ctx, request) if err != nil { return nil, err } @@ -279,14 +264,32 @@ func (a *MLflowArtifactsAPI) ListAll(ctx context.Context, request ListArtifactsR return results, nil } -func NewMLflowDatabricks(client *client.DatabricksClient) MLflowDatabricksService { +func NewMLflowDatabricks(client *client.DatabricksClient) *MLflowDatabricksAPI { return &MLflowDatabricksAPI{ - client: client, + impl: &mLflowDatabricksImpl{ + client: client, + }, } } +// These endpoints are modified versions of the MLflow API that accept +// additional input parameters or return additional information. type MLflowDatabricksAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(MLflowDatabricksService) + impl MLflowDatabricksService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *MLflowDatabricksAPI) WithImpl(impl MLflowDatabricksService) *MLflowDatabricksAPI { + a.impl = impl + return a +} + +// Impl returns low-level MLflowDatabricks API implementation +func (a *MLflowDatabricksAPI) Impl() MLflowDatabricksService { + return a.impl } // Get model @@ -297,10 +300,7 @@ type MLflowDatabricksAPI struct { // that also returns the model's Databricks Workspace ID and the permission // level of the requesting user on the model. func (a *MLflowDatabricksAPI) Get(ctx context.Context, request GetRequest) (*GetResponse, error) { - var getResponse GetResponse - path := "/api/2.0/mlflow/databricks/registered-models/get" - err := a.client.Get(ctx, path, request, &getResponse) - return &getResponse, err + return a.impl.Get(ctx, request) } // Get model @@ -311,7 +311,7 @@ func (a *MLflowDatabricksAPI) Get(ctx context.Context, request GetRequest) (*Get // that also returns the model's Databricks Workspace ID and the permission // level of the requesting user on the model. func (a *MLflowDatabricksAPI) GetByName(ctx context.Context, name string) (*GetResponse, error) { - return a.Get(ctx, GetRequest{ + return a.impl.Get(ctx, GetRequest{ Name: name, }) } @@ -323,40 +323,66 @@ func (a *MLflowDatabricksAPI) GetByName(ctx context.Context, name string) (*GetR // endpoint](https://www.mlflow.org/docs/latest/rest-api.html#transition-modelversion-stage) // that also accepts a comment associated with the transition to be recorded.", func (a *MLflowDatabricksAPI) TransitionStage(ctx context.Context, request TransitionModelVersionStageDatabricks) (*TransitionStageResponse, error) { - var transitionStageResponse TransitionStageResponse - path := "/api/2.0/mlflow/databricks/model-versions/transition-stage" - err := a.client.Post(ctx, path, request, &transitionStageResponse) - return &transitionStageResponse, err + return a.impl.TransitionStage(ctx, request) } -func NewMLflowMetrics(client *client.DatabricksClient) MLflowMetricsService { +func NewMLflowMetrics(client *client.DatabricksClient) *MLflowMetricsAPI { return &MLflowMetricsAPI{ - client: client, + impl: &mLflowMetricsImpl{ + client: client, + }, } } type MLflowMetricsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(MLflowMetricsService) + impl MLflowMetricsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *MLflowMetricsAPI) WithImpl(impl MLflowMetricsService) *MLflowMetricsAPI { + a.impl = impl + return a +} + +// Impl returns low-level MLflowMetrics API implementation +func (a *MLflowMetricsAPI) Impl() MLflowMetricsService { + return a.impl } // Get all history // // Gets a list of all values for the specified metric for a given run. func (a *MLflowMetricsAPI) GetHistory(ctx context.Context, request GetHistoryRequest) (*GetMetricHistoryResponse, error) { - var getMetricHistoryResponse GetMetricHistoryResponse - path := "/api/2.0/mlflow/metrics/get-history" - err := a.client.Get(ctx, path, request, &getMetricHistoryResponse) - return &getMetricHistoryResponse, err + return a.impl.GetHistory(ctx, request) } -func NewMLflowRuns(client *client.DatabricksClient) MLflowRunsService { +func NewMLflowRuns(client *client.DatabricksClient) *MLflowRunsAPI { return &MLflowRunsAPI{ - client: client, + impl: &mLflowRunsImpl{ + client: client, + }, } } type MLflowRunsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(MLflowRunsService) + impl MLflowRunsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *MLflowRunsAPI) WithImpl(impl MLflowRunsService) *MLflowRunsAPI { + a.impl = impl + return a +} + +// Impl returns low-level MLflowRuns API implementation +func (a *MLflowRunsAPI) Impl() MLflowRunsService { + return a.impl } // Create a run @@ -366,26 +392,21 @@ type MLflowRunsAPI struct { // `mlflowParam`, `mlflowMetric` and `mlflowRunTag` associated with a single // execution. func (a *MLflowRunsAPI) Create(ctx context.Context, request CreateRun) (*CreateRunResponse, error) { - var createRunResponse CreateRunResponse - path := "/api/2.0/mlflow/runs/create" - err := a.client.Post(ctx, path, request, &createRunResponse) - return &createRunResponse, err + return a.impl.Create(ctx, request) } // Delete a run // // Marks a run for deletion. func (a *MLflowRunsAPI) Delete(ctx context.Context, request DeleteRun) error { - path := "/api/2.0/mlflow/runs/delete" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.Delete(ctx, request) } // Delete a run // // Marks a run for deletion. func (a *MLflowRunsAPI) DeleteByRunId(ctx context.Context, runId string) error { - return a.Delete(ctx, DeleteRun{ + return a.impl.Delete(ctx, DeleteRun{ RunId: runId, }) } @@ -395,9 +416,7 @@ func (a *MLflowRunsAPI) DeleteByRunId(ctx context.Context, runId string) error { // Deletes a tag on a run. Tags are run metadata that can be updated during a // run and after a run completes. func (a *MLflowRunsAPI) DeleteTag(ctx context.Context, request DeleteTag) error { - path := "/api/2.0/mlflow/runs/delete-tag" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.DeleteTag(ctx, request) } // Get a run @@ -409,10 +428,7 @@ func (a *MLflowRunsAPI) DeleteTag(ctx context.Context, request DeleteTag) error // If there are multiple values with the latest timestamp, return the maximum of // these values. func (a *MLflowRunsAPI) Get(ctx context.Context, request GetRunRequest) (*GetRunResponse, error) { - var getRunResponse GetRunResponse - path := "/api/2.0/mlflow/runs/get" - err := a.client.Get(ctx, path, request, &getRunResponse) - return &getRunResponse, err + return a.impl.Get(ctx, request) } // Log a batch @@ -464,9 +480,7 @@ func (a *MLflowRunsAPI) Get(ctx context.Context, request GetRunRequest) (*GetRun // * Metric keyes, param keys, and tag keys can be up to 250 characters in // length * Parameter and tag values can be up to 250 characters in length func (a *MLflowRunsAPI) LogBatch(ctx context.Context, request LogBatch) error { - path := "/api/2.0/mlflow/runs/log-batch" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.LogBatch(ctx, request) } // Log a metric @@ -475,9 +489,7 @@ func (a *MLflowRunsAPI) LogBatch(ctx context.Context, request LogBatch) error { // value) with an associated timestamp. Examples include the various metrics // that represent ML model accuracy. A metric can be logged multiple times. func (a *MLflowRunsAPI) LogMetric(ctx context.Context, request LogMetric) error { - path := "/api/2.0/mlflow/runs/log-metric" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.LogMetric(ctx, request) } // Log a model @@ -485,9 +497,7 @@ func (a *MLflowRunsAPI) LogMetric(ctx context.Context, request LogMetric) error // **NOTE:** Experimental: This API may change or be removed in a future release // without warning. func (a *MLflowRunsAPI) LogModel(ctx context.Context, request LogModel) error { - path := "/api/2.0/mlflow/runs/log-model" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.LogModel(ctx, request) } // Log a param @@ -497,25 +507,21 @@ func (a *MLflowRunsAPI) LogModel(ctx context.Context, request LogModel) error { // constant dates and values used in an ETL pipeline. A param can be logged only // once for a run. func (a *MLflowRunsAPI) LogParameter(ctx context.Context, request LogParam) error { - path := "/api/2.0/mlflow/runs/log-parameter" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.LogParameter(ctx, request) } // Restore a run // // Restores a deleted run. func (a *MLflowRunsAPI) Restore(ctx context.Context, request RestoreRun) error { - path := "/api/2.0/mlflow/runs/restore" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.Restore(ctx, request) } // Restore a run // // Restores a deleted run. func (a *MLflowRunsAPI) RestoreByRunId(ctx context.Context, runId string) error { - return a.Restore(ctx, RestoreRun{ + return a.impl.Restore(ctx, RestoreRun{ RunId: runId, }) } @@ -526,22 +532,12 @@ func (a *MLflowRunsAPI) RestoreByRunId(ctx context.Context, runId string) error // // Search expressions can use `mlflowMetric` and `mlflowParam` keys.", // -// Use SearchAll() to get all Run instances, which will iterate over every result page. -func (a *MLflowRunsAPI) Search(ctx context.Context, request SearchRuns) (*SearchRunsResponse, error) { - var searchRunsResponse SearchRunsResponse - path := "/api/2.0/mlflow/runs/search" - err := a.client.Post(ctx, path, request, &searchRunsResponse) - return &searchRunsResponse, err -} - -// SearchAll returns all Run instances by calling Search for every result page -// // This method is generated by Databricks SDK Code Generator. func (a *MLflowRunsAPI) SearchAll(ctx context.Context, request SearchRuns) ([]Run, error) { var results []Run ctx = useragent.InContext(ctx, "sdk-feature", "pagination") for { - response, err := a.Search(ctx, request) + response, err := a.impl.Search(ctx, request) if err != nil { return nil, err } @@ -564,29 +560,40 @@ func (a *MLflowRunsAPI) SearchAll(ctx context.Context, request SearchRuns) ([]Ru // Sets a tag on a run. Tags are run metadata that can be updated during a run // and after a run completes. func (a *MLflowRunsAPI) SetTag(ctx context.Context, request SetTag) error { - path := "/api/2.0/mlflow/runs/set-tag" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.SetTag(ctx, request) } // Update a run // // Updates run metadata. func (a *MLflowRunsAPI) Update(ctx context.Context, request UpdateRun) (*UpdateRunResponse, error) { - var updateRunResponse UpdateRunResponse - path := "/api/2.0/mlflow/runs/update" - err := a.client.Post(ctx, path, request, &updateRunResponse) - return &updateRunResponse, err + return a.impl.Update(ctx, request) } -func NewModelVersionComments(client *client.DatabricksClient) ModelVersionCommentsService { +func NewModelVersionComments(client *client.DatabricksClient) *ModelVersionCommentsAPI { return &ModelVersionCommentsAPI{ - client: client, + impl: &modelVersionCommentsImpl{ + client: client, + }, } } type ModelVersionCommentsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(ModelVersionCommentsService) + impl ModelVersionCommentsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *ModelVersionCommentsAPI) WithImpl(impl ModelVersionCommentsService) *ModelVersionCommentsAPI { + a.impl = impl + return a +} + +// Impl returns low-level ModelVersionComments API implementation +func (a *ModelVersionCommentsAPI) Impl() ModelVersionCommentsService { + return a.impl } // Post a comment @@ -595,26 +602,21 @@ type ModelVersionCommentsAPI struct { // user or programmatically to display relevant information about the model. For // example, test results or deployment errors. func (a *ModelVersionCommentsAPI) Create(ctx context.Context, request CreateComment) (*CreateResponse, error) { - var createResponse CreateResponse - path := "/api/2.0/mlflow/comments/create" - err := a.client.Post(ctx, path, request, &createResponse) - return &createResponse, err + return a.impl.Create(ctx, request) } // Delete a comment // // Deletes a comment on a model version. func (a *ModelVersionCommentsAPI) Delete(ctx context.Context, request DeleteRequest) error { - path := "/api/2.0/mlflow/comments/delete" - err := a.client.Delete(ctx, path, request) - return err + return a.impl.Delete(ctx, request) } // Delete a comment // // Deletes a comment on a model version. func (a *ModelVersionCommentsAPI) DeleteById(ctx context.Context, id string) error { - return a.Delete(ctx, DeleteRequest{ + return a.impl.Delete(ctx, DeleteRequest{ Id: id, }) } @@ -623,90 +625,80 @@ func (a *ModelVersionCommentsAPI) DeleteById(ctx context.Context, id string) err // // Post an edit to a comment on a model version. func (a *ModelVersionCommentsAPI) Update(ctx context.Context, request UpdateComment) (*UpdateResponse, error) { - var updateResponse UpdateResponse - path := "/api/2.0/mlflow/comments/update" - err := a.client.Post(ctx, path, request, &updateResponse) - return &updateResponse, err + return a.impl.Update(ctx, request) } -func NewModelVersions(client *client.DatabricksClient) ModelVersionsService { +func NewModelVersions(client *client.DatabricksClient) *ModelVersionsAPI { return &ModelVersionsAPI{ - client: client, + impl: &modelVersionsImpl{ + client: client, + }, } } type ModelVersionsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(ModelVersionsService) + impl ModelVersionsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *ModelVersionsAPI) WithImpl(impl ModelVersionsService) *ModelVersionsAPI { + a.impl = impl + return a +} + +// Impl returns low-level ModelVersions API implementation +func (a *ModelVersionsAPI) Impl() ModelVersionsService { + return a.impl } // Create a model version // // Creates a model version. func (a *ModelVersionsAPI) Create(ctx context.Context, request CreateModelVersionRequest) (*CreateModelVersionResponse, error) { - var createModelVersionResponse CreateModelVersionResponse - path := "/api/2.0/mlflow/model-versions/create" - err := a.client.Post(ctx, path, request, &createModelVersionResponse) - return &createModelVersionResponse, err + return a.impl.Create(ctx, request) } // Delete a model version. // // Deletes a model version. func (a *ModelVersionsAPI) Delete(ctx context.Context, request DeleteModelVersionRequest) error { - path := "/api/2.0/mlflow/model-versions/delete" - err := a.client.Delete(ctx, path, request) - return err + return a.impl.Delete(ctx, request) } // Delete a model version tag // // Deletes a model version tag. func (a *ModelVersionsAPI) DeleteTag(ctx context.Context, request DeleteModelVersionTagRequest) error { - path := "/api/2.0/mlflow/model-versions/delete-tag" - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteTag(ctx, request) } // Get a model version // // Get a model version. func (a *ModelVersionsAPI) Get(ctx context.Context, request GetModelVersionRequest) (*GetModelVersionResponse, error) { - var getModelVersionResponse GetModelVersionResponse - path := "/api/2.0/mlflow/model-versions/get" - err := a.client.Get(ctx, path, request, &getModelVersionResponse) - return &getModelVersionResponse, err + return a.impl.Get(ctx, request) } // Get a model version URI // // Gets a URI to download the model version. func (a *ModelVersionsAPI) GetDownloadUri(ctx context.Context, request GetModelVersionDownloadUriRequest) (*GetModelVersionDownloadUriResponse, error) { - var getModelVersionDownloadUriResponse GetModelVersionDownloadUriResponse - path := "/api/2.0/mlflow/model-versions/get-download-uri" - err := a.client.Get(ctx, path, request, &getModelVersionDownloadUriResponse) - return &getModelVersionDownloadUriResponse, err + return a.impl.GetDownloadUri(ctx, request) } // Searches model versions // // Searches for specific model versions based on the supplied __filter__. // -// Use SearchAll() to get all ModelVersion instances, which will iterate over every result page. -func (a *ModelVersionsAPI) Search(ctx context.Context, request SearchModelVersionsRequest) (*SearchModelVersionsResponse, error) { - var searchModelVersionsResponse SearchModelVersionsResponse - path := "/api/2.0/mlflow/model-versions/search" - err := a.client.Get(ctx, path, request, &searchModelVersionsResponse) - return &searchModelVersionsResponse, err -} - -// SearchAll returns all ModelVersion instances by calling Search for every result page -// // This method is generated by Databricks SDK Code Generator. func (a *ModelVersionsAPI) SearchAll(ctx context.Context, request SearchModelVersionsRequest) ([]ModelVersion, error) { var results []ModelVersion ctx = useragent.InContext(ctx, "sdk-feature", "pagination") for { - response, err := a.Search(ctx, request) + response, err := a.impl.Search(ctx, request) if err != nil { return nil, err } @@ -728,38 +720,47 @@ func (a *ModelVersionsAPI) SearchAll(ctx context.Context, request SearchModelVer // // Sets a model version tag. func (a *ModelVersionsAPI) SetTag(ctx context.Context, request SetModelVersionTagRequest) error { - path := "/api/2.0/mlflow/model-versions/set-tag" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.SetTag(ctx, request) } // Transition a stage // // Transition to the next model stage. func (a *ModelVersionsAPI) TransitionStage(ctx context.Context, request TransitionModelVersionStage) (*TransitionModelVersionStageResponse, error) { - var transitionModelVersionStageResponse TransitionModelVersionStageResponse - path := "/api/2.0/mlflow/model-versions/transition-stage" - err := a.client.Post(ctx, path, request, &transitionModelVersionStageResponse) - return &transitionModelVersionStageResponse, err + return a.impl.TransitionStage(ctx, request) } // Update model version // // Updates the model version. func (a *ModelVersionsAPI) Update(ctx context.Context, request UpdateModelVersionRequest) error { - path := "/api/2.0/mlflow/model-versions/update" - err := a.client.Patch(ctx, path, request) - return err + return a.impl.Update(ctx, request) } -func NewRegisteredModels(client *client.DatabricksClient) RegisteredModelsService { +func NewRegisteredModels(client *client.DatabricksClient) *RegisteredModelsAPI { return &RegisteredModelsAPI{ - client: client, + impl: ®isteredModelsImpl{ + client: client, + }, } } type RegisteredModelsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(RegisteredModelsService) + impl RegisteredModelsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *RegisteredModelsAPI) WithImpl(impl RegisteredModelsService) *RegisteredModelsAPI { + a.impl = impl + return a +} + +// Impl returns low-level RegisteredModels API implementation +func (a *RegisteredModelsAPI) Impl() RegisteredModelsService { + return a.impl } // Create a model @@ -769,26 +770,21 @@ type RegisteredModelsAPI struct { // Throws “RESOURCE_ALREADY_EXISTS“ if a registered model with the given name // exists. func (a *RegisteredModelsAPI) Create(ctx context.Context, request CreateRegisteredModelRequest) (*CreateRegisteredModelResponse, error) { - var createRegisteredModelResponse CreateRegisteredModelResponse - path := "/api/2.0/mlflow/registered-models/create" - err := a.client.Post(ctx, path, request, &createRegisteredModelResponse) - return &createRegisteredModelResponse, err + return a.impl.Create(ctx, request) } // Delete a model // // Deletes a registered model. func (a *RegisteredModelsAPI) Delete(ctx context.Context, request DeleteRegisteredModelRequest) error { - path := "/api/2.0/mlflow/registered-models/delete" - err := a.client.Delete(ctx, path, request) - return err + return a.impl.Delete(ctx, request) } // Delete a model // // Deletes a registered model. func (a *RegisteredModelsAPI) DeleteByName(ctx context.Context, name string) error { - return a.Delete(ctx, DeleteRegisteredModelRequest{ + return a.impl.Delete(ctx, DeleteRegisteredModelRequest{ Name: name, }) } @@ -797,26 +793,21 @@ func (a *RegisteredModelsAPI) DeleteByName(ctx context.Context, name string) err // // Deletes the tag for a registered model. func (a *RegisteredModelsAPI) DeleteTag(ctx context.Context, request DeleteRegisteredModelTagRequest) error { - path := "/api/2.0/mlflow/registered-models/delete-tag" - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteTag(ctx, request) } // Get a model // // Gets the registered model that matches the specified ID. func (a *RegisteredModelsAPI) Get(ctx context.Context, request GetRegisteredModelRequest) (*GetRegisteredModelResponse, error) { - var getRegisteredModelResponse GetRegisteredModelResponse - path := "/api/2.0/mlflow/registered-models/get" - err := a.client.Get(ctx, path, request, &getRegisteredModelResponse) - return &getRegisteredModelResponse, err + return a.impl.Get(ctx, request) } // Get a model // // Gets the registered model that matches the specified ID. func (a *RegisteredModelsAPI) GetByName(ctx context.Context, name string) (*GetRegisteredModelResponse, error) { - return a.Get(ctx, GetRegisteredModelRequest{ + return a.impl.Get(ctx, GetRegisteredModelRequest{ Name: name, }) } @@ -825,19 +816,9 @@ func (a *RegisteredModelsAPI) GetByName(ctx context.Context, name string) (*GetR // // Gets the latest version of a registered model. // -// Use GetLatestVersionsAll() to get all ModelVersion instances -func (a *RegisteredModelsAPI) GetLatestVersions(ctx context.Context, request GetLatestVersionsRequest) (*GetLatestVersionsResponse, error) { - var getLatestVersionsResponse GetLatestVersionsResponse - path := "/api/2.0/mlflow/registered-models/get-latest-versions" - err := a.client.Post(ctx, path, request, &getLatestVersionsResponse) - return &getLatestVersionsResponse, err -} - -// GetLatestVersionsAll returns all ModelVersion instances. This method exists for consistency purposes. -// // This method is generated by Databricks SDK Code Generator. func (a *RegisteredModelsAPI) GetLatestVersionsAll(ctx context.Context, request GetLatestVersionsRequest) ([]ModelVersion, error) { - response, err := a.GetLatestVersions(ctx, request) + response, err := a.impl.GetLatestVersions(ctx, request) if err != nil { return nil, err } @@ -849,22 +830,12 @@ func (a *RegisteredModelsAPI) GetLatestVersionsAll(ctx context.Context, request // Lists all available registered models, up to the limit specified in // __max_results__. // -// Use ListAll() to get all RegisteredModel instances, which will iterate over every result page. -func (a *RegisteredModelsAPI) List(ctx context.Context, request ListRegisteredModelsRequest) (*ListRegisteredModelsResponse, error) { - var listRegisteredModelsResponse ListRegisteredModelsResponse - path := "/api/2.0/mlflow/registered-models/list" - err := a.client.Get(ctx, path, request, &listRegisteredModelsResponse) - return &listRegisteredModelsResponse, err -} - -// ListAll returns all RegisteredModel instances by calling List for every result page -// // This method is generated by Databricks SDK Code Generator. func (a *RegisteredModelsAPI) ListAll(ctx context.Context, request ListRegisteredModelsRequest) ([]RegisteredModel, error) { var results []RegisteredModel ctx = useragent.InContext(ctx, "sdk-feature", "pagination") for { - response, err := a.List(ctx, request) + response, err := a.impl.List(ctx, request) if err != nil { return nil, err } @@ -886,32 +857,19 @@ func (a *RegisteredModelsAPI) ListAll(ctx context.Context, request ListRegistere // // Renames a registered model. func (a *RegisteredModelsAPI) Rename(ctx context.Context, request RenameRegisteredModelRequest) (*RenameRegisteredModelResponse, error) { - var renameRegisteredModelResponse RenameRegisteredModelResponse - path := "/api/2.0/mlflow/registered-models/rename" - err := a.client.Post(ctx, path, request, &renameRegisteredModelResponse) - return &renameRegisteredModelResponse, err + return a.impl.Rename(ctx, request) } // Search models // // Search for registered models based on the specified __filter__. // -// Use SearchAll() to get all RegisteredModel instances, which will iterate over every result page. -func (a *RegisteredModelsAPI) Search(ctx context.Context, request SearchRegisteredModelsRequest) (*SearchRegisteredModelsResponse, error) { - var searchRegisteredModelsResponse SearchRegisteredModelsResponse - path := "/api/2.0/mlflow/registered-models/search" - err := a.client.Get(ctx, path, request, &searchRegisteredModelsResponse) - return &searchRegisteredModelsResponse, err -} - -// SearchAll returns all RegisteredModel instances by calling Search for every result page -// // This method is generated by Databricks SDK Code Generator. func (a *RegisteredModelsAPI) SearchAll(ctx context.Context, request SearchRegisteredModelsRequest) ([]RegisteredModel, error) { var results []RegisteredModel ctx = useragent.InContext(ctx, "sdk-feature", "pagination") for { - response, err := a.Search(ctx, request) + response, err := a.impl.Search(ctx, request) if err != nil { return nil, err } @@ -933,28 +891,40 @@ func (a *RegisteredModelsAPI) SearchAll(ctx context.Context, request SearchRegis // // Sets a tag on a registered model. func (a *RegisteredModelsAPI) SetTag(ctx context.Context, request SetRegisteredModelTagRequest) error { - path := "/api/2.0/mlflow/registered-models/set-tag" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.SetTag(ctx, request) } // Update model // // Updates a registered model. func (a *RegisteredModelsAPI) Update(ctx context.Context, request UpdateRegisteredModelRequest) error { - path := "/api/2.0/mlflow/registered-models/update" - err := a.client.Patch(ctx, path, request) - return err + return a.impl.Update(ctx, request) } -func NewRegistryWebhooks(client *client.DatabricksClient) RegistryWebhooksService { +func NewRegistryWebhooks(client *client.DatabricksClient) *RegistryWebhooksAPI { return &RegistryWebhooksAPI{ - client: client, + impl: ®istryWebhooksImpl{ + client: client, + }, } } type RegistryWebhooksAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(RegistryWebhooksService) + impl RegistryWebhooksService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *RegistryWebhooksAPI) WithImpl(impl RegistryWebhooksService) *RegistryWebhooksAPI { + a.impl = impl + return a +} + +// Impl returns low-level RegistryWebhooks API implementation +func (a *RegistryWebhooksAPI) Impl() RegistryWebhooksService { + return a.impl } // Create a webhook @@ -963,10 +933,7 @@ type RegistryWebhooksAPI struct { // // Creates a registry webhook. func (a *RegistryWebhooksAPI) Create(ctx context.Context, request CreateRegistryWebhook) (*CreateResponse, error) { - var createResponse CreateResponse - path := "/api/2.0/mlflow/registry-webhooks/create" - err := a.client.Post(ctx, path, request, &createResponse) - return &createResponse, err + return a.impl.Create(ctx, request) } // Delete a webhook @@ -975,9 +942,7 @@ func (a *RegistryWebhooksAPI) Create(ctx context.Context, request CreateRegistry // // Deletes a registry webhook. func (a *RegistryWebhooksAPI) Delete(ctx context.Context, request DeleteRequest) error { - path := "/api/2.0/mlflow/registry-webhooks/delete" - err := a.client.Delete(ctx, path, request) - return err + return a.impl.Delete(ctx, request) } // Delete a webhook @@ -986,7 +951,7 @@ func (a *RegistryWebhooksAPI) Delete(ctx context.Context, request DeleteRequest) // // Deletes a registry webhook. func (a *RegistryWebhooksAPI) DeleteById(ctx context.Context, id string) error { - return a.Delete(ctx, DeleteRequest{ + return a.impl.Delete(ctx, DeleteRequest{ Id: id, }) } @@ -997,22 +962,12 @@ func (a *RegistryWebhooksAPI) DeleteById(ctx context.Context, id string) error { // // Lists all registry webhooks. // -// Use ListAll() to get all RegistryWebhook instances, which will iterate over every result page. -func (a *RegistryWebhooksAPI) List(ctx context.Context, request ListRequest) (*ListRegistryWebhooks, error) { - var listRegistryWebhooks ListRegistryWebhooks - path := "/api/2.0/mlflow/registry-webhooks/list" - err := a.client.Get(ctx, path, request, &listRegistryWebhooks) - return &listRegistryWebhooks, err -} - -// ListAll returns all RegistryWebhook instances by calling List for every result page -// // This method is generated by Databricks SDK Code Generator. func (a *RegistryWebhooksAPI) ListAll(ctx context.Context, request ListRequest) ([]RegistryWebhook, error) { var results []RegistryWebhook ctx = useragent.InContext(ctx, "sdk-feature", "pagination") for { - response, err := a.List(ctx, request) + response, err := a.impl.List(ctx, request) if err != nil { return nil, err } @@ -1036,10 +991,7 @@ func (a *RegistryWebhooksAPI) ListAll(ctx context.Context, request ListRequest) // // Tests a registry webhook. func (a *RegistryWebhooksAPI) Test(ctx context.Context, request TestRegistryWebhookRequest) (*TestRegistryWebhookResponse, error) { - var testRegistryWebhookResponse TestRegistryWebhookResponse - path := "/api/2.0/mlflow/registry-webhooks/test" - err := a.client.Post(ctx, path, request, &testRegistryWebhookResponse) - return &testRegistryWebhookResponse, err + return a.impl.Test(ctx, request) } // Update a webhook @@ -1048,67 +1000,63 @@ func (a *RegistryWebhooksAPI) Test(ctx context.Context, request TestRegistryWebh // // Updates a registry webhook. func (a *RegistryWebhooksAPI) Update(ctx context.Context, request UpdateRegistryWebhook) error { - path := "/api/2.0/mlflow/registry-webhooks/update" - err := a.client.Patch(ctx, path, request) - return err + return a.impl.Update(ctx, request) } -func NewTransitionRequests(client *client.DatabricksClient) TransitionRequestsService { +func NewTransitionRequests(client *client.DatabricksClient) *TransitionRequestsAPI { return &TransitionRequestsAPI{ - client: client, + impl: &transitionRequestsImpl{ + client: client, + }, } } type TransitionRequestsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(TransitionRequestsService) + impl TransitionRequestsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *TransitionRequestsAPI) WithImpl(impl TransitionRequestsService) *TransitionRequestsAPI { + a.impl = impl + return a +} + +// Impl returns low-level TransitionRequests API implementation +func (a *TransitionRequestsAPI) Impl() TransitionRequestsService { + return a.impl } // Approve transition requests // // Approves a model version stage transition request. func (a *TransitionRequestsAPI) Approve(ctx context.Context, request ApproveTransitionRequest) (*ApproveResponse, error) { - var approveResponse ApproveResponse - path := "/api/2.0/mlflow/transition-requests/approve" - err := a.client.Post(ctx, path, request, &approveResponse) - return &approveResponse, err + return a.impl.Approve(ctx, request) } // Make a transition request // // Creates a model version stage transition request. func (a *TransitionRequestsAPI) Create(ctx context.Context, request CreateTransitionRequest) (*CreateResponse, error) { - var createResponse CreateResponse - path := "/api/2.0/mlflow/transition-requests/create" - err := a.client.Post(ctx, path, request, &createResponse) - return &createResponse, err + return a.impl.Create(ctx, request) } // Delete a ransition request // // Cancels a model version stage transition request. func (a *TransitionRequestsAPI) Delete(ctx context.Context, request DeleteRequest) error { - path := "/api/2.0/mlflow/transition-requests/delete" - err := a.client.Delete(ctx, path, request) - return err + return a.impl.Delete(ctx, request) } // List transition requests // // Gets a list of all open stage transition requests for the model version. // -// Use ListAll() to get all Activity instances -func (a *TransitionRequestsAPI) List(ctx context.Context, request ListRequest) (*ListResponse, error) { - var listResponse ListResponse - path := "/api/2.0/mlflow/transition-requests/list" - err := a.client.Get(ctx, path, request, &listResponse) - return &listResponse, err -} - -// ListAll returns all Activity instances. This method exists for consistency purposes. -// // This method is generated by Databricks SDK Code Generator. func (a *TransitionRequestsAPI) ListAll(ctx context.Context, request ListRequest) ([]Activity, error) { - response, err := a.List(ctx, request) + response, err := a.impl.List(ctx, request) if err != nil { return nil, err } @@ -1119,8 +1067,5 @@ func (a *TransitionRequestsAPI) ListAll(ctx context.Context, request ListRequest // // Rejects a model version stage transition request. func (a *TransitionRequestsAPI) Reject(ctx context.Context, request RejectTransitionRequest) (*RejectResponse, error) { - var rejectResponse RejectResponse - path := "/api/2.0/mlflow/transition-requests/reject" - err := a.client.Post(ctx, path, request, &rejectResponse) - return &rejectResponse, err + return a.impl.Reject(ctx, request) } diff --git a/service/mlflow/impl.go b/service/mlflow/impl.go new file mode 100755 index 000000000..277783616 --- /dev/null +++ b/service/mlflow/impl.go @@ -0,0 +1,434 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package mlflow + +import ( + "context" + + "github.com/databricks/databricks-sdk-go/databricks/client" +) + +// unexported type that holds implementations of just Experiments API methods +type experimentsImpl struct { + client *client.DatabricksClient +} + +func (a *experimentsImpl) Create(ctx context.Context, request CreateExperiment) (*CreateExperimentResponse, error) { + var createExperimentResponse CreateExperimentResponse + path := "/api/2.0/mlflow/experiments/create" + err := a.client.Post(ctx, path, request, &createExperimentResponse) + return &createExperimentResponse, err +} + +func (a *experimentsImpl) Delete(ctx context.Context, request DeleteExperiment) error { + path := "/api/2.0/mlflow/experiments/delete" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *experimentsImpl) Get(ctx context.Context, request GetExperimentRequest) (*Experiment, error) { + var experiment Experiment + path := "/api/2.0/mlflow/experiments/get" + err := a.client.Get(ctx, path, request, &experiment) + return &experiment, err +} + +func (a *experimentsImpl) GetByName(ctx context.Context, request GetByNameRequest) (*GetExperimentByNameResponse, error) { + var getExperimentByNameResponse GetExperimentByNameResponse + path := "/api/2.0/mlflow/experiments/get-by-name" + err := a.client.Get(ctx, path, request, &getExperimentByNameResponse) + return &getExperimentByNameResponse, err +} + +func (a *experimentsImpl) List(ctx context.Context, request ListExperimentsRequest) (*ListExperimentsResponse, error) { + var listExperimentsResponse ListExperimentsResponse + path := "/api/2.0/mlflow/experiments/list" + err := a.client.Get(ctx, path, request, &listExperimentsResponse) + return &listExperimentsResponse, err +} + +func (a *experimentsImpl) Restore(ctx context.Context, request RestoreExperiment) error { + path := "/api/2.0/mlflow/experiments/restore" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *experimentsImpl) Search(ctx context.Context, request SearchExperiments) (*SearchExperimentsResponse, error) { + var searchExperimentsResponse SearchExperimentsResponse + path := "/api/2.0/mlflow/experiments/search" + err := a.client.Post(ctx, path, request, &searchExperimentsResponse) + return &searchExperimentsResponse, err +} + +func (a *experimentsImpl) SetExperimentTag(ctx context.Context, request SetExperimentTag) error { + path := "/api/2.0/mlflow/experiments/set-experiment-tag" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *experimentsImpl) Update(ctx context.Context, request UpdateExperiment) error { + path := "/api/2.0/mlflow/experiments/update" + err := a.client.Post(ctx, path, request, nil) + return err +} + +// unexported type that holds implementations of just MLflowArtifacts API methods +type mLflowArtifactsImpl struct { + client *client.DatabricksClient +} + +func (a *mLflowArtifactsImpl) List(ctx context.Context, request ListArtifactsRequest) (*ListArtifactsResponse, error) { + var listArtifactsResponse ListArtifactsResponse + path := "/api/2.0/mlflow/artifacts/list" + err := a.client.Get(ctx, path, request, &listArtifactsResponse) + return &listArtifactsResponse, err +} + +// unexported type that holds implementations of just MLflowDatabricks API methods +type mLflowDatabricksImpl struct { + client *client.DatabricksClient +} + +func (a *mLflowDatabricksImpl) Get(ctx context.Context, request GetRequest) (*GetResponse, error) { + var getResponse GetResponse + path := "/api/2.0/mlflow/databricks/registered-models/get" + err := a.client.Get(ctx, path, request, &getResponse) + return &getResponse, err +} + +func (a *mLflowDatabricksImpl) TransitionStage(ctx context.Context, request TransitionModelVersionStageDatabricks) (*TransitionStageResponse, error) { + var transitionStageResponse TransitionStageResponse + path := "/api/2.0/mlflow/databricks/model-versions/transition-stage" + err := a.client.Post(ctx, path, request, &transitionStageResponse) + return &transitionStageResponse, err +} + +// unexported type that holds implementations of just MLflowMetrics API methods +type mLflowMetricsImpl struct { + client *client.DatabricksClient +} + +func (a *mLflowMetricsImpl) GetHistory(ctx context.Context, request GetHistoryRequest) (*GetMetricHistoryResponse, error) { + var getMetricHistoryResponse GetMetricHistoryResponse + path := "/api/2.0/mlflow/metrics/get-history" + err := a.client.Get(ctx, path, request, &getMetricHistoryResponse) + return &getMetricHistoryResponse, err +} + +// unexported type that holds implementations of just MLflowRuns API methods +type mLflowRunsImpl struct { + client *client.DatabricksClient +} + +func (a *mLflowRunsImpl) Create(ctx context.Context, request CreateRun) (*CreateRunResponse, error) { + var createRunResponse CreateRunResponse + path := "/api/2.0/mlflow/runs/create" + err := a.client.Post(ctx, path, request, &createRunResponse) + return &createRunResponse, err +} + +func (a *mLflowRunsImpl) Delete(ctx context.Context, request DeleteRun) error { + path := "/api/2.0/mlflow/runs/delete" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *mLflowRunsImpl) DeleteTag(ctx context.Context, request DeleteTag) error { + path := "/api/2.0/mlflow/runs/delete-tag" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *mLflowRunsImpl) Get(ctx context.Context, request GetRunRequest) (*GetRunResponse, error) { + var getRunResponse GetRunResponse + path := "/api/2.0/mlflow/runs/get" + err := a.client.Get(ctx, path, request, &getRunResponse) + return &getRunResponse, err +} + +func (a *mLflowRunsImpl) LogBatch(ctx context.Context, request LogBatch) error { + path := "/api/2.0/mlflow/runs/log-batch" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *mLflowRunsImpl) LogMetric(ctx context.Context, request LogMetric) error { + path := "/api/2.0/mlflow/runs/log-metric" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *mLflowRunsImpl) LogModel(ctx context.Context, request LogModel) error { + path := "/api/2.0/mlflow/runs/log-model" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *mLflowRunsImpl) LogParameter(ctx context.Context, request LogParam) error { + path := "/api/2.0/mlflow/runs/log-parameter" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *mLflowRunsImpl) Restore(ctx context.Context, request RestoreRun) error { + path := "/api/2.0/mlflow/runs/restore" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *mLflowRunsImpl) Search(ctx context.Context, request SearchRuns) (*SearchRunsResponse, error) { + var searchRunsResponse SearchRunsResponse + path := "/api/2.0/mlflow/runs/search" + err := a.client.Post(ctx, path, request, &searchRunsResponse) + return &searchRunsResponse, err +} + +func (a *mLflowRunsImpl) SetTag(ctx context.Context, request SetTag) error { + path := "/api/2.0/mlflow/runs/set-tag" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *mLflowRunsImpl) Update(ctx context.Context, request UpdateRun) (*UpdateRunResponse, error) { + var updateRunResponse UpdateRunResponse + path := "/api/2.0/mlflow/runs/update" + err := a.client.Post(ctx, path, request, &updateRunResponse) + return &updateRunResponse, err +} + +// unexported type that holds implementations of just ModelVersionComments API methods +type modelVersionCommentsImpl struct { + client *client.DatabricksClient +} + +func (a *modelVersionCommentsImpl) Create(ctx context.Context, request CreateComment) (*CreateResponse, error) { + var createResponse CreateResponse + path := "/api/2.0/mlflow/comments/create" + err := a.client.Post(ctx, path, request, &createResponse) + return &createResponse, err +} + +func (a *modelVersionCommentsImpl) Delete(ctx context.Context, request DeleteRequest) error { + path := "/api/2.0/mlflow/comments/delete" + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *modelVersionCommentsImpl) Update(ctx context.Context, request UpdateComment) (*UpdateResponse, error) { + var updateResponse UpdateResponse + path := "/api/2.0/mlflow/comments/update" + err := a.client.Post(ctx, path, request, &updateResponse) + return &updateResponse, err +} + +// unexported type that holds implementations of just ModelVersions API methods +type modelVersionsImpl struct { + client *client.DatabricksClient +} + +func (a *modelVersionsImpl) Create(ctx context.Context, request CreateModelVersionRequest) (*CreateModelVersionResponse, error) { + var createModelVersionResponse CreateModelVersionResponse + path := "/api/2.0/mlflow/model-versions/create" + err := a.client.Post(ctx, path, request, &createModelVersionResponse) + return &createModelVersionResponse, err +} + +func (a *modelVersionsImpl) Delete(ctx context.Context, request DeleteModelVersionRequest) error { + path := "/api/2.0/mlflow/model-versions/delete" + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *modelVersionsImpl) DeleteTag(ctx context.Context, request DeleteModelVersionTagRequest) error { + path := "/api/2.0/mlflow/model-versions/delete-tag" + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *modelVersionsImpl) Get(ctx context.Context, request GetModelVersionRequest) (*GetModelVersionResponse, error) { + var getModelVersionResponse GetModelVersionResponse + path := "/api/2.0/mlflow/model-versions/get" + err := a.client.Get(ctx, path, request, &getModelVersionResponse) + return &getModelVersionResponse, err +} + +func (a *modelVersionsImpl) GetDownloadUri(ctx context.Context, request GetModelVersionDownloadUriRequest) (*GetModelVersionDownloadUriResponse, error) { + var getModelVersionDownloadUriResponse GetModelVersionDownloadUriResponse + path := "/api/2.0/mlflow/model-versions/get-download-uri" + err := a.client.Get(ctx, path, request, &getModelVersionDownloadUriResponse) + return &getModelVersionDownloadUriResponse, err +} + +func (a *modelVersionsImpl) Search(ctx context.Context, request SearchModelVersionsRequest) (*SearchModelVersionsResponse, error) { + var searchModelVersionsResponse SearchModelVersionsResponse + path := "/api/2.0/mlflow/model-versions/search" + err := a.client.Get(ctx, path, request, &searchModelVersionsResponse) + return &searchModelVersionsResponse, err +} + +func (a *modelVersionsImpl) SetTag(ctx context.Context, request SetModelVersionTagRequest) error { + path := "/api/2.0/mlflow/model-versions/set-tag" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *modelVersionsImpl) TransitionStage(ctx context.Context, request TransitionModelVersionStage) (*TransitionModelVersionStageResponse, error) { + var transitionModelVersionStageResponse TransitionModelVersionStageResponse + path := "/api/2.0/mlflow/model-versions/transition-stage" + err := a.client.Post(ctx, path, request, &transitionModelVersionStageResponse) + return &transitionModelVersionStageResponse, err +} + +func (a *modelVersionsImpl) Update(ctx context.Context, request UpdateModelVersionRequest) error { + path := "/api/2.0/mlflow/model-versions/update" + err := a.client.Patch(ctx, path, request) + return err +} + +// unexported type that holds implementations of just RegisteredModels API methods +type registeredModelsImpl struct { + client *client.DatabricksClient +} + +func (a *registeredModelsImpl) Create(ctx context.Context, request CreateRegisteredModelRequest) (*CreateRegisteredModelResponse, error) { + var createRegisteredModelResponse CreateRegisteredModelResponse + path := "/api/2.0/mlflow/registered-models/create" + err := a.client.Post(ctx, path, request, &createRegisteredModelResponse) + return &createRegisteredModelResponse, err +} + +func (a *registeredModelsImpl) Delete(ctx context.Context, request DeleteRegisteredModelRequest) error { + path := "/api/2.0/mlflow/registered-models/delete" + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *registeredModelsImpl) DeleteTag(ctx context.Context, request DeleteRegisteredModelTagRequest) error { + path := "/api/2.0/mlflow/registered-models/delete-tag" + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *registeredModelsImpl) Get(ctx context.Context, request GetRegisteredModelRequest) (*GetRegisteredModelResponse, error) { + var getRegisteredModelResponse GetRegisteredModelResponse + path := "/api/2.0/mlflow/registered-models/get" + err := a.client.Get(ctx, path, request, &getRegisteredModelResponse) + return &getRegisteredModelResponse, err +} + +func (a *registeredModelsImpl) GetLatestVersions(ctx context.Context, request GetLatestVersionsRequest) (*GetLatestVersionsResponse, error) { + var getLatestVersionsResponse GetLatestVersionsResponse + path := "/api/2.0/mlflow/registered-models/get-latest-versions" + err := a.client.Post(ctx, path, request, &getLatestVersionsResponse) + return &getLatestVersionsResponse, err +} + +func (a *registeredModelsImpl) List(ctx context.Context, request ListRegisteredModelsRequest) (*ListRegisteredModelsResponse, error) { + var listRegisteredModelsResponse ListRegisteredModelsResponse + path := "/api/2.0/mlflow/registered-models/list" + err := a.client.Get(ctx, path, request, &listRegisteredModelsResponse) + return &listRegisteredModelsResponse, err +} + +func (a *registeredModelsImpl) Rename(ctx context.Context, request RenameRegisteredModelRequest) (*RenameRegisteredModelResponse, error) { + var renameRegisteredModelResponse RenameRegisteredModelResponse + path := "/api/2.0/mlflow/registered-models/rename" + err := a.client.Post(ctx, path, request, &renameRegisteredModelResponse) + return &renameRegisteredModelResponse, err +} + +func (a *registeredModelsImpl) Search(ctx context.Context, request SearchRegisteredModelsRequest) (*SearchRegisteredModelsResponse, error) { + var searchRegisteredModelsResponse SearchRegisteredModelsResponse + path := "/api/2.0/mlflow/registered-models/search" + err := a.client.Get(ctx, path, request, &searchRegisteredModelsResponse) + return &searchRegisteredModelsResponse, err +} + +func (a *registeredModelsImpl) SetTag(ctx context.Context, request SetRegisteredModelTagRequest) error { + path := "/api/2.0/mlflow/registered-models/set-tag" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *registeredModelsImpl) Update(ctx context.Context, request UpdateRegisteredModelRequest) error { + path := "/api/2.0/mlflow/registered-models/update" + err := a.client.Patch(ctx, path, request) + return err +} + +// unexported type that holds implementations of just RegistryWebhooks API methods +type registryWebhooksImpl struct { + client *client.DatabricksClient +} + +func (a *registryWebhooksImpl) Create(ctx context.Context, request CreateRegistryWebhook) (*CreateResponse, error) { + var createResponse CreateResponse + path := "/api/2.0/mlflow/registry-webhooks/create" + err := a.client.Post(ctx, path, request, &createResponse) + return &createResponse, err +} + +func (a *registryWebhooksImpl) Delete(ctx context.Context, request DeleteRequest) error { + path := "/api/2.0/mlflow/registry-webhooks/delete" + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *registryWebhooksImpl) List(ctx context.Context, request ListRequest) (*ListRegistryWebhooks, error) { + var listRegistryWebhooks ListRegistryWebhooks + path := "/api/2.0/mlflow/registry-webhooks/list" + err := a.client.Get(ctx, path, request, &listRegistryWebhooks) + return &listRegistryWebhooks, err +} + +func (a *registryWebhooksImpl) Test(ctx context.Context, request TestRegistryWebhookRequest) (*TestRegistryWebhookResponse, error) { + var testRegistryWebhookResponse TestRegistryWebhookResponse + path := "/api/2.0/mlflow/registry-webhooks/test" + err := a.client.Post(ctx, path, request, &testRegistryWebhookResponse) + return &testRegistryWebhookResponse, err +} + +func (a *registryWebhooksImpl) Update(ctx context.Context, request UpdateRegistryWebhook) error { + path := "/api/2.0/mlflow/registry-webhooks/update" + err := a.client.Patch(ctx, path, request) + return err +} + +// unexported type that holds implementations of just TransitionRequests API methods +type transitionRequestsImpl struct { + client *client.DatabricksClient +} + +func (a *transitionRequestsImpl) Approve(ctx context.Context, request ApproveTransitionRequest) (*ApproveResponse, error) { + var approveResponse ApproveResponse + path := "/api/2.0/mlflow/transition-requests/approve" + err := a.client.Post(ctx, path, request, &approveResponse) + return &approveResponse, err +} + +func (a *transitionRequestsImpl) Create(ctx context.Context, request CreateTransitionRequest) (*CreateResponse, error) { + var createResponse CreateResponse + path := "/api/2.0/mlflow/transition-requests/create" + err := a.client.Post(ctx, path, request, &createResponse) + return &createResponse, err +} + +func (a *transitionRequestsImpl) Delete(ctx context.Context, request DeleteRequest) error { + path := "/api/2.0/mlflow/transition-requests/delete" + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *transitionRequestsImpl) List(ctx context.Context, request ListRequest) (*ListResponse, error) { + var listResponse ListResponse + path := "/api/2.0/mlflow/transition-requests/list" + err := a.client.Get(ctx, path, request, &listResponse) + return &listResponse, err +} + +func (a *transitionRequestsImpl) Reject(ctx context.Context, request RejectTransitionRequest) (*RejectResponse, error) { + var rejectResponse RejectResponse + path := "/api/2.0/mlflow/transition-requests/reject" + err := a.client.Post(ctx, path, request, &rejectResponse) + return &rejectResponse, err +} diff --git a/service/mlflow/interface.go b/service/mlflow/interface.go index 96c1a7ea0..560cb8a66 100755 --- a/service/mlflow/interface.go +++ b/service/mlflow/interface.go @@ -6,9 +6,6 @@ import ( "context" ) -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type ExperimentsService interface { // Create experiment @@ -29,24 +26,12 @@ type ExperimentsService interface { // with experiment are also deleted. Delete(ctx context.Context, request DeleteExperiment) error - // DeleteByExperimentId calls Delete, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteByExperimentId(ctx context.Context, experimentId string) error - // Get an experiment // // Gets metadata for an experiment. This method works on deleted // experiments. Get(ctx context.Context, request GetExperimentRequest) (*Experiment, error) - // GetByExperimentId calls Get, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetByExperimentId(ctx context.Context, experimentId string) (*Experiment, error) - // Get metadata // // "Gets metadata for an experiment. @@ -60,12 +45,6 @@ type ExperimentsService interface { // name exists.S GetByName(ctx context.Context, request GetByNameRequest) (*GetExperimentByNameResponse, error) - // GetByNameByExperimentName calls GetByName, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetByNameByExperimentName(ctx context.Context, experimentName string) (*GetExperimentByNameResponse, error) - // List experiments // // Gets a list of all experiments. @@ -73,11 +52,6 @@ type ExperimentsService interface { // Use ListAll() to get all Experiment instances, which will iterate over every result page. List(ctx context.Context, request ListExperimentsRequest) (*ListExperimentsResponse, error) - // ListAll calls List() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListAll(ctx context.Context, request ListExperimentsRequest) ([]Experiment, error) - // Restores an experiment // // "Restore an experiment marked for deletion. This also @@ -87,12 +61,6 @@ type ExperimentsService interface { // experiment was never created or was permanently deleted.", Restore(ctx context.Context, request RestoreExperiment) error - // RestoreByExperimentId calls Restore, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - RestoreByExperimentId(ctx context.Context, experimentId string) error - // Search experiments // // Searches for experiments that satisfy specified search criteria. @@ -100,11 +68,6 @@ type ExperimentsService interface { // Use SearchAll() to get all Experiment instances, which will iterate over every result page. Search(ctx context.Context, request SearchExperiments) (*SearchExperimentsResponse, error) - // SearchAll calls Search() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - SearchAll(ctx context.Context, request SearchExperiments) ([]Experiment, error) - // Set a tag // // Sets a tag on an experiment. Experiment tags are metadata that can be @@ -117,9 +80,6 @@ type ExperimentsService interface { Update(ctx context.Context, request UpdateExperiment) error } -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type MLflowArtifactsService interface { // Get all artifacts @@ -130,19 +90,10 @@ type MLflowArtifactsService interface { // // Use ListAll() to get all FileInfo instances, which will iterate over every result page. List(ctx context.Context, request ListArtifactsRequest) (*ListArtifactsResponse, error) - - // ListAll calls List() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListAll(ctx context.Context, request ListArtifactsRequest) ([]FileInfo, error) } // These endpoints are modified versions of the MLflow API that accept // additional input parameters or return additional information. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type MLflowDatabricksService interface { // Get model @@ -154,12 +105,6 @@ type MLflowDatabricksService interface { // level of the requesting user on the model. Get(ctx context.Context, request GetRequest) (*GetResponse, error) - // GetByName calls Get, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetByName(ctx context.Context, name string) (*GetResponse, error) - // Transition a stage // // Transition a model version's stage. This is a Databricks Workspace @@ -170,9 +115,6 @@ type MLflowDatabricksService interface { TransitionStage(ctx context.Context, request TransitionModelVersionStageDatabricks) (*TransitionStageResponse, error) } -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type MLflowMetricsService interface { // Get all history @@ -181,9 +123,6 @@ type MLflowMetricsService interface { GetHistory(ctx context.Context, request GetHistoryRequest) (*GetMetricHistoryResponse, error) } -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type MLflowRunsService interface { // Create a run @@ -199,12 +138,6 @@ type MLflowRunsService interface { // Marks a run for deletion. Delete(ctx context.Context, request DeleteRun) error - // DeleteByRunId calls Delete, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteByRunId(ctx context.Context, runId string) error - // Delete a tag // // Deletes a tag on a run. Tags are run metadata that can be updated during @@ -302,12 +235,6 @@ type MLflowRunsService interface { // Restores a deleted run. Restore(ctx context.Context, request RestoreRun) error - // RestoreByRunId calls Restore, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - RestoreByRunId(ctx context.Context, runId string) error - // Search for runs // // Searches for runs that satisfy expressions. @@ -317,11 +244,6 @@ type MLflowRunsService interface { // Use SearchAll() to get all Run instances, which will iterate over every result page. Search(ctx context.Context, request SearchRuns) (*SearchRunsResponse, error) - // SearchAll calls Search() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - SearchAll(ctx context.Context, request SearchRuns) ([]Run, error) - // Set a tag // // Sets a tag on a run. Tags are run metadata that can be updated during a @@ -334,9 +256,6 @@ type MLflowRunsService interface { Update(ctx context.Context, request UpdateRun) (*UpdateRunResponse, error) } -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type ModelVersionCommentsService interface { // Post a comment @@ -351,21 +270,12 @@ type ModelVersionCommentsService interface { // Deletes a comment on a model version. Delete(ctx context.Context, request DeleteRequest) error - // DeleteById calls Delete, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteById(ctx context.Context, id string) error - // Update a comment // // Post an edit to a comment on a model version. Update(ctx context.Context, request UpdateComment) (*UpdateResponse, error) } -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type ModelVersionsService interface { // Create a model version @@ -400,11 +310,6 @@ type ModelVersionsService interface { // Use SearchAll() to get all ModelVersion instances, which will iterate over every result page. Search(ctx context.Context, request SearchModelVersionsRequest) (*SearchModelVersionsResponse, error) - // SearchAll calls Search() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - SearchAll(ctx context.Context, request SearchModelVersionsRequest) ([]ModelVersion, error) - // Set a version tag // // Sets a model version tag. @@ -421,9 +326,6 @@ type ModelVersionsService interface { Update(ctx context.Context, request UpdateModelVersionRequest) error } -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type RegisteredModelsService interface { // Create a model @@ -440,12 +342,6 @@ type RegisteredModelsService interface { // Deletes a registered model. Delete(ctx context.Context, request DeleteRegisteredModelRequest) error - // DeleteByName calls Delete, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteByName(ctx context.Context, name string) error - // Delete a model tag // // Deletes the tag for a registered model. @@ -456,12 +352,6 @@ type RegisteredModelsService interface { // Gets the registered model that matches the specified ID. Get(ctx context.Context, request GetRegisteredModelRequest) (*GetRegisteredModelResponse, error) - // GetByName calls Get, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetByName(ctx context.Context, name string) (*GetRegisteredModelResponse, error) - // Get the latest version // // Gets the latest version of a registered model. @@ -469,11 +359,6 @@ type RegisteredModelsService interface { // Use GetLatestVersionsAll() to get all ModelVersion instances GetLatestVersions(ctx context.Context, request GetLatestVersionsRequest) (*GetLatestVersionsResponse, error) - // GetLatestVersionsAll calls GetLatestVersions() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - GetLatestVersionsAll(ctx context.Context, request GetLatestVersionsRequest) ([]ModelVersion, error) - // List models // // Lists all available registered models, up to the limit specified in @@ -482,11 +367,6 @@ type RegisteredModelsService interface { // Use ListAll() to get all RegisteredModel instances, which will iterate over every result page. List(ctx context.Context, request ListRegisteredModelsRequest) (*ListRegisteredModelsResponse, error) - // ListAll calls List() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListAll(ctx context.Context, request ListRegisteredModelsRequest) ([]RegisteredModel, error) - // Rename a model // // Renames a registered model. @@ -499,11 +379,6 @@ type RegisteredModelsService interface { // Use SearchAll() to get all RegisteredModel instances, which will iterate over every result page. Search(ctx context.Context, request SearchRegisteredModelsRequest) (*SearchRegisteredModelsResponse, error) - // SearchAll calls Search() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - SearchAll(ctx context.Context, request SearchRegisteredModelsRequest) ([]RegisteredModel, error) - // Set a tag // // Sets a tag on a registered model. @@ -515,9 +390,6 @@ type RegisteredModelsService interface { Update(ctx context.Context, request UpdateRegisteredModelRequest) error } -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type RegistryWebhooksService interface { // Create a webhook @@ -534,12 +406,6 @@ type RegistryWebhooksService interface { // Deletes a registry webhook. Delete(ctx context.Context, request DeleteRequest) error - // DeleteById calls Delete, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteById(ctx context.Context, id string) error - // List registry webhooks // // **NOTE:** This endpoint is in Public Preview. @@ -549,11 +415,6 @@ type RegistryWebhooksService interface { // Use ListAll() to get all RegistryWebhook instances, which will iterate over every result page. List(ctx context.Context, request ListRequest) (*ListRegistryWebhooks, error) - // ListAll calls List() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListAll(ctx context.Context, request ListRequest) ([]RegistryWebhook, error) - // Test a webhook // // **NOTE:** This endpoint is in Public Preview. @@ -569,9 +430,6 @@ type RegistryWebhooksService interface { Update(ctx context.Context, request UpdateRegistryWebhook) error } -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type TransitionRequestsService interface { // Approve transition requests @@ -596,11 +454,6 @@ type TransitionRequestsService interface { // Use ListAll() to get all Activity instances List(ctx context.Context, request ListRequest) (*ListResponse, error) - // ListAll calls List() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListAll(ctx context.Context, request ListRequest) ([]Activity, error) - // Reject a transition request // // Rejects a model version stage transition request. diff --git a/service/permissions/api.go b/service/permissions/api.go index 19738e481..41ba96c0b 100755 --- a/service/permissions/api.go +++ b/service/permissions/api.go @@ -4,19 +4,36 @@ package permissions import ( "context" - "fmt" "github.com/databricks/databricks-sdk-go/databricks/client" ) -func NewPermissions(client *client.DatabricksClient) PermissionsService { +func NewPermissions(client *client.DatabricksClient) *PermissionsAPI { return &PermissionsAPI{ - client: client, + impl: &permissionsImpl{ + client: client, + }, } } +// Permissions API are used to create read, write, edit, update and manage +// access for various users on different objects and endpoints. type PermissionsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(PermissionsService) + impl PermissionsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *PermissionsAPI) WithImpl(impl PermissionsService) *PermissionsAPI { + a.impl = impl + return a +} + +// Impl returns low-level Permissions API implementation +func (a *PermissionsAPI) Impl() PermissionsService { + return a.impl } // Get object permissions @@ -24,10 +41,7 @@ type PermissionsAPI struct { // Gets the permission of an object. Objects can inherit permissions from their // parent objects or root objects. func (a *PermissionsAPI) GetObjectPermissions(ctx context.Context, request GetObjectPermissionsRequest) (*ObjectPermissions, error) { - var objectPermissions ObjectPermissions - path := fmt.Sprintf("/api/2.0/permissions/%v/%v", request.ObjectType, request.ObjectId) - err := a.client.Get(ctx, path, request, &objectPermissions) - return &objectPermissions, err + return a.impl.GetObjectPermissions(ctx, request) } // Get object permissions @@ -35,7 +49,7 @@ func (a *PermissionsAPI) GetObjectPermissions(ctx context.Context, request GetOb // Gets the permission of an object. Objects can inherit permissions from their // parent objects or root objects. func (a *PermissionsAPI) GetObjectPermissionsByObjectTypeAndObjectId(ctx context.Context, objectType string, objectId string) (*ObjectPermissions, error) { - return a.GetObjectPermissions(ctx, GetObjectPermissionsRequest{ + return a.impl.GetObjectPermissions(ctx, GetObjectPermissionsRequest{ ObjectType: objectType, ObjectId: objectId, }) @@ -45,17 +59,14 @@ func (a *PermissionsAPI) GetObjectPermissionsByObjectTypeAndObjectId(ctx context // // Gets the permission levels that a user can have on an object. func (a *PermissionsAPI) GetPermissionLevels(ctx context.Context, request GetPermissionLevelsRequest) (*GetPermissionLevelsResponse, error) { - var getPermissionLevelsResponse GetPermissionLevelsResponse - path := fmt.Sprintf("/api/2.0/permissions/%v/%v/permissionLevels", request.RequestObjectType, request.RequestObjectId) - err := a.client.Get(ctx, path, request, &getPermissionLevelsResponse) - return &getPermissionLevelsResponse, err + return a.impl.GetPermissionLevels(ctx, request) } // Get permission levels // // Gets the permission levels that a user can have on an object. func (a *PermissionsAPI) GetPermissionLevelsByRequestObjectTypeAndRequestObjectId(ctx context.Context, requestObjectType string, requestObjectId string) (*GetPermissionLevelsResponse, error) { - return a.GetPermissionLevels(ctx, GetPermissionLevelsRequest{ + return a.impl.GetPermissionLevels(ctx, GetPermissionLevelsRequest{ RequestObjectType: requestObjectType, RequestObjectId: requestObjectId, }) @@ -66,38 +77,48 @@ func (a *PermissionsAPI) GetPermissionLevelsByRequestObjectTypeAndRequestObjectI // Sets permissions on object. Objects can inherit permissions from their parent // objects and root objects. func (a *PermissionsAPI) SetObjectPermissions(ctx context.Context, request SetObjectPermissions) error { - path := fmt.Sprintf("/api/2.0/permissions/%v/%v", request.ObjectType, request.ObjectId) - err := a.client.Put(ctx, path, request) - return err + return a.impl.SetObjectPermissions(ctx, request) } // Update permission // // Updates the permissions on an object. func (a *PermissionsAPI) UpdateObjectPermissions(ctx context.Context, request UpdateObjectPermissions) error { - path := fmt.Sprintf("/api/2.0/permissions/%v/%v", request.ObjectType, request.ObjectId) - err := a.client.Patch(ctx, path, request) - return err + return a.impl.UpdateObjectPermissions(ctx, request) } -func NewWorkspaceAssignment(client *client.DatabricksClient) WorkspaceAssignmentService { +func NewWorkspaceAssignment(client *client.DatabricksClient) *WorkspaceAssignmentAPI { return &WorkspaceAssignmentAPI{ - client: client, + impl: &workspaceAssignmentImpl{ + client: client, + }, } } +// Databricks Workspace Assignment REST API type WorkspaceAssignmentAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(WorkspaceAssignmentService) + impl WorkspaceAssignmentService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *WorkspaceAssignmentAPI) WithImpl(impl WorkspaceAssignmentService) *WorkspaceAssignmentAPI { + a.impl = impl + return a +} + +// Impl returns low-level WorkspaceAssignment API implementation +func (a *WorkspaceAssignmentAPI) Impl() WorkspaceAssignmentService { + return a.impl } // Create permission assignments // // Create new permission assignments for the specified account and workspace. func (a *WorkspaceAssignmentAPI) Create(ctx context.Context, request CreateWorkspaceAssignments) (*WorkspaceAssignmentsCreated, error) { - var workspaceAssignmentsCreated WorkspaceAssignmentsCreated - path := fmt.Sprintf("/api/2.0/preview/accounts/%v/workspaces/%v/permissionassignments", a.client.Config.AccountID, request.WorkspaceId) - err := a.client.Post(ctx, path, request, &workspaceAssignmentsCreated) - return &workspaceAssignmentsCreated, err + return a.impl.Create(ctx, request) } // Delete permissions assignment @@ -105,9 +126,7 @@ func (a *WorkspaceAssignmentAPI) Create(ctx context.Context, request CreateWorks // Deletes the workspace permissions assignment for a given account and // workspace using the specified service principal. func (a *WorkspaceAssignmentAPI) Delete(ctx context.Context, request DeleteRequest) error { - path := fmt.Sprintf("/api/2.0/preview/accounts/%v/workspaces/%v/permissionassignments/principals/%v", a.client.Config.AccountID, request.WorkspaceId, request.PrincipalId) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.Delete(ctx, request) } // Delete permissions assignment @@ -115,7 +134,7 @@ func (a *WorkspaceAssignmentAPI) Delete(ctx context.Context, request DeleteReque // Deletes the workspace permissions assignment for a given account and // workspace using the specified service principal. func (a *WorkspaceAssignmentAPI) DeleteByWorkspaceIdAndPrincipalId(ctx context.Context, workspaceId int64, principalId int64) error { - return a.Delete(ctx, DeleteRequest{ + return a.impl.Delete(ctx, DeleteRequest{ WorkspaceId: workspaceId, PrincipalId: principalId, }) @@ -126,10 +145,7 @@ func (a *WorkspaceAssignmentAPI) DeleteByWorkspaceIdAndPrincipalId(ctx context.C // Get an array of workspace permissions for the specified account and // workspace. func (a *WorkspaceAssignmentAPI) Get(ctx context.Context, request GetRequest) (*WorkspacePermissions, error) { - var workspacePermissions WorkspacePermissions - path := fmt.Sprintf("/api/2.0/preview/accounts/%v/workspaces/%v/permissionassignments/permissions", a.client.Config.AccountID, request.WorkspaceId) - err := a.client.Get(ctx, path, request, &workspacePermissions) - return &workspacePermissions, err + return a.impl.Get(ctx, request) } // List workspace permissions @@ -137,7 +153,7 @@ func (a *WorkspaceAssignmentAPI) Get(ctx context.Context, request GetRequest) (* // Get an array of workspace permissions for the specified account and // workspace. func (a *WorkspaceAssignmentAPI) GetByWorkspaceId(ctx context.Context, workspaceId int64) (*WorkspacePermissions, error) { - return a.Get(ctx, GetRequest{ + return a.impl.Get(ctx, GetRequest{ WorkspaceId: workspaceId, }) } @@ -147,19 +163,9 @@ func (a *WorkspaceAssignmentAPI) GetByWorkspaceId(ctx context.Context, workspace // Get the permission assignments for the specified Databricks Account and // Databricks Workspace. // -// Use ListAll() to get all PermissionAssignment instances -func (a *WorkspaceAssignmentAPI) List(ctx context.Context, request ListRequest) (*PermissionAssignments, error) { - var permissionAssignments PermissionAssignments - path := fmt.Sprintf("/api/2.0/preview/accounts/%v/workspaces/%v/permissionassignments", a.client.Config.AccountID, request.WorkspaceId) - err := a.client.Get(ctx, path, request, &permissionAssignments) - return &permissionAssignments, err -} - -// ListAll returns all PermissionAssignment instances. This method exists for consistency purposes. -// // This method is generated by Databricks SDK Code Generator. func (a *WorkspaceAssignmentAPI) ListAll(ctx context.Context, request ListRequest) ([]PermissionAssignment, error) { - response, err := a.List(ctx, request) + response, err := a.impl.List(ctx, request) if err != nil { return nil, err } @@ -171,7 +177,7 @@ func (a *WorkspaceAssignmentAPI) ListAll(ctx context.Context, request ListReques // Get the permission assignments for the specified Databricks Account and // Databricks Workspace. func (a *WorkspaceAssignmentAPI) ListByWorkspaceId(ctx context.Context, workspaceId int64) (*PermissionAssignments, error) { - return a.List(ctx, ListRequest{ + return a.impl.List(ctx, ListRequest{ WorkspaceId: workspaceId, }) } @@ -181,7 +187,5 @@ func (a *WorkspaceAssignmentAPI) ListByWorkspaceId(ctx context.Context, workspac // Updates the workspace permissions assignment for a given account and // workspace using the specified service principal. func (a *WorkspaceAssignmentAPI) Update(ctx context.Context, request UpdateWorkspaceAssignments) error { - path := fmt.Sprintf("/api/2.0/preview/accounts/%v/workspaces/%v/permissionassignments/principals/%v", a.client.Config.AccountID, request.WorkspaceId, request.PrincipalId) - err := a.client.Put(ctx, path, request) - return err + return a.impl.Update(ctx, request) } diff --git a/service/permissions/impl.go b/service/permissions/impl.go new file mode 100755 index 000000000..2894a1369 --- /dev/null +++ b/service/permissions/impl.go @@ -0,0 +1,79 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package permissions + +import ( + "context" + "fmt" + + "github.com/databricks/databricks-sdk-go/databricks/client" +) + +// unexported type that holds implementations of just Permissions API methods +type permissionsImpl struct { + client *client.DatabricksClient +} + +func (a *permissionsImpl) GetObjectPermissions(ctx context.Context, request GetObjectPermissionsRequest) (*ObjectPermissions, error) { + var objectPermissions ObjectPermissions + path := fmt.Sprintf("/api/2.0/permissions/%v/%v", request.ObjectType, request.ObjectId) + err := a.client.Get(ctx, path, request, &objectPermissions) + return &objectPermissions, err +} + +func (a *permissionsImpl) GetPermissionLevels(ctx context.Context, request GetPermissionLevelsRequest) (*GetPermissionLevelsResponse, error) { + var getPermissionLevelsResponse GetPermissionLevelsResponse + path := fmt.Sprintf("/api/2.0/permissions/%v/%v/permissionLevels", request.RequestObjectType, request.RequestObjectId) + err := a.client.Get(ctx, path, request, &getPermissionLevelsResponse) + return &getPermissionLevelsResponse, err +} + +func (a *permissionsImpl) SetObjectPermissions(ctx context.Context, request SetObjectPermissions) error { + path := fmt.Sprintf("/api/2.0/permissions/%v/%v", request.ObjectType, request.ObjectId) + err := a.client.Put(ctx, path, request) + return err +} + +func (a *permissionsImpl) UpdateObjectPermissions(ctx context.Context, request UpdateObjectPermissions) error { + path := fmt.Sprintf("/api/2.0/permissions/%v/%v", request.ObjectType, request.ObjectId) + err := a.client.Patch(ctx, path, request) + return err +} + +// unexported type that holds implementations of just WorkspaceAssignment API methods +type workspaceAssignmentImpl struct { + client *client.DatabricksClient +} + +func (a *workspaceAssignmentImpl) Create(ctx context.Context, request CreateWorkspaceAssignments) (*WorkspaceAssignmentsCreated, error) { + var workspaceAssignmentsCreated WorkspaceAssignmentsCreated + path := fmt.Sprintf("/api/2.0/preview/accounts/%v/workspaces/%v/permissionassignments", a.client.Config.AccountID, request.WorkspaceId) + err := a.client.Post(ctx, path, request, &workspaceAssignmentsCreated) + return &workspaceAssignmentsCreated, err +} + +func (a *workspaceAssignmentImpl) Delete(ctx context.Context, request DeleteRequest) error { + path := fmt.Sprintf("/api/2.0/preview/accounts/%v/workspaces/%v/permissionassignments/principals/%v", a.client.Config.AccountID, request.WorkspaceId, request.PrincipalId) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *workspaceAssignmentImpl) Get(ctx context.Context, request GetRequest) (*WorkspacePermissions, error) { + var workspacePermissions WorkspacePermissions + path := fmt.Sprintf("/api/2.0/preview/accounts/%v/workspaces/%v/permissionassignments/permissions", a.client.Config.AccountID, request.WorkspaceId) + err := a.client.Get(ctx, path, request, &workspacePermissions) + return &workspacePermissions, err +} + +func (a *workspaceAssignmentImpl) List(ctx context.Context, request ListRequest) (*PermissionAssignments, error) { + var permissionAssignments PermissionAssignments + path := fmt.Sprintf("/api/2.0/preview/accounts/%v/workspaces/%v/permissionassignments", a.client.Config.AccountID, request.WorkspaceId) + err := a.client.Get(ctx, path, request, &permissionAssignments) + return &permissionAssignments, err +} + +func (a *workspaceAssignmentImpl) Update(ctx context.Context, request UpdateWorkspaceAssignments) error { + path := fmt.Sprintf("/api/2.0/preview/accounts/%v/workspaces/%v/permissionassignments/principals/%v", a.client.Config.AccountID, request.WorkspaceId, request.PrincipalId) + err := a.client.Put(ctx, path, request) + return err +} diff --git a/service/permissions/interface.go b/service/permissions/interface.go index eb5a043cf..a6c8a0982 100755 --- a/service/permissions/interface.go +++ b/service/permissions/interface.go @@ -8,10 +8,6 @@ import ( // Permissions API are used to create read, write, edit, update and manage // access for various users on different objects and endpoints. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type PermissionsService interface { // Get object permissions @@ -20,23 +16,11 @@ type PermissionsService interface { // their parent objects or root objects. GetObjectPermissions(ctx context.Context, request GetObjectPermissionsRequest) (*ObjectPermissions, error) - // GetObjectPermissionsByObjectTypeAndObjectId calls GetObjectPermissions, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetObjectPermissionsByObjectTypeAndObjectId(ctx context.Context, objectType string, objectId string) (*ObjectPermissions, error) - // Get permission levels // // Gets the permission levels that a user can have on an object. GetPermissionLevels(ctx context.Context, request GetPermissionLevelsRequest) (*GetPermissionLevelsResponse, error) - // GetPermissionLevelsByRequestObjectTypeAndRequestObjectId calls GetPermissionLevels, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetPermissionLevelsByRequestObjectTypeAndRequestObjectId(ctx context.Context, requestObjectType string, requestObjectId string) (*GetPermissionLevelsResponse, error) - // Set permissions // // Sets permissions on object. Objects can inherit permissions from their @@ -50,10 +34,6 @@ type PermissionsService interface { } // Databricks Workspace Assignment REST API -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type WorkspaceAssignmentService interface { // Create permission assignments @@ -68,24 +48,12 @@ type WorkspaceAssignmentService interface { // workspace using the specified service principal. Delete(ctx context.Context, request DeleteRequest) error - // DeleteByWorkspaceIdAndPrincipalId calls Delete, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteByWorkspaceIdAndPrincipalId(ctx context.Context, workspaceId int64, principalId int64) error - // List workspace permissions // // Get an array of workspace permissions for the specified account and // workspace. Get(ctx context.Context, request GetRequest) (*WorkspacePermissions, error) - // GetByWorkspaceId calls Get, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetByWorkspaceId(ctx context.Context, workspaceId int64) (*WorkspacePermissions, error) - // Get permission assignments // // Get the permission assignments for the specified Databricks Account and @@ -94,16 +62,6 @@ type WorkspaceAssignmentService interface { // Use ListAll() to get all PermissionAssignment instances List(ctx context.Context, request ListRequest) (*PermissionAssignments, error) - // ListByWorkspaceId calls List, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - ListByWorkspaceId(ctx context.Context, workspaceId int64) (*PermissionAssignments, error) - // ListAll calls List() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListAll(ctx context.Context, request ListRequest) ([]PermissionAssignment, error) - // Update permissions assignment // // Updates the workspace permissions assignment for a given account and diff --git a/service/pipelines/api.go b/service/pipelines/api.go index 51a3ba83c..1219dfae1 100755 --- a/service/pipelines/api.go +++ b/service/pipelines/api.go @@ -12,14 +12,44 @@ import ( "github.com/databricks/databricks-sdk-go/databricks/useragent" ) -func NewPipelines(client *client.DatabricksClient) PipelinesService { +func NewPipelines(client *client.DatabricksClient) *PipelinesAPI { return &PipelinesAPI{ - client: client, + impl: &pipelinesImpl{ + client: client, + }, } } +// The Delta Live Tables API allows you to create, edit, delete, start, and view +// details about pipelines. +// +// Delta Live Tables is a framework for building reliable, maintainable, and +// testable data processing pipelines. You define the transformations to perform +// on your data, and Delta Live Tables manages task orchestration, cluster +// management, monitoring, data quality, and error handling. +// +// Instead of defining your data pipelines using a series of separate Apache +// Spark tasks, Delta Live Tables manages how your data is transformed based on +// a target schema you define for each processing step. You can also enforce +// data quality with Delta Live Tables expectations. Expectations allow you to +// define expected data quality and specify how to handle records that fail +// those expectations. type PipelinesAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(PipelinesService) + impl PipelinesService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *PipelinesAPI) WithImpl(impl PipelinesService) *PipelinesAPI { + a.impl = impl + return a +} + +// Impl returns low-level Pipelines API implementation +func (a *PipelinesAPI) Impl() PipelinesService { + return a.impl } // Create a pipeline @@ -27,13 +57,10 @@ type PipelinesAPI struct { // Creates a new data processing pipeline based on the requested configuration. // If successful, this method returns the ID of the new pipeline. func (a *PipelinesAPI) CreatePipeline(ctx context.Context, request CreatePipeline) (*CreatePipelineResponse, error) { - var createPipelineResponse CreatePipelineResponse - path := "/api/2.0/pipelines" - err := a.client.Post(ctx, path, request, &createPipelineResponse) - return &createPipelineResponse, err + return a.impl.CreatePipeline(ctx, request) } -// CreatePipeline and wait to reach RUNNING state +// Calls [PipelinesAPI.CreatePipeline] and waits to reach RUNNING state // // You can override the default timeout of 20 minutes by calling adding // retries.Timeout[GetPipelineResponse](60*time.Minute) functional option. @@ -79,29 +106,24 @@ func (a *PipelinesAPI) CreatePipelineAndWait(ctx context.Context, createPipeline // // Deletes a pipeline. func (a *PipelinesAPI) DeletePipeline(ctx context.Context, request DeletePipelineRequest) error { - path := fmt.Sprintf("/api/2.0/pipelines/%v", request.PipelineId) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeletePipeline(ctx, request) } // Delete a pipeline // // Deletes a pipeline. func (a *PipelinesAPI) DeletePipelineByPipelineId(ctx context.Context, pipelineId string) error { - return a.DeletePipeline(ctx, DeletePipelineRequest{ + return a.impl.DeletePipeline(ctx, DeletePipelineRequest{ PipelineId: pipelineId, }) } // Get a pipeline func (a *PipelinesAPI) GetPipeline(ctx context.Context, request GetPipelineRequest) (*GetPipelineResponse, error) { - var getPipelineResponse GetPipelineResponse - path := fmt.Sprintf("/api/2.0/pipelines/%v", request.PipelineId) - err := a.client.Get(ctx, path, request, &getPipelineResponse) - return &getPipelineResponse, err + return a.impl.GetPipeline(ctx, request) } -// GetPipeline and wait to reach RUNNING state +// Calls [PipelinesAPI.GetPipeline] and waits to reach RUNNING state // // You can override the default timeout of 20 minutes by calling adding // retries.Timeout[GetPipelineResponse](60*time.Minute) functional option. @@ -145,7 +167,7 @@ func (a *PipelinesAPI) GetPipelineAndWait(ctx context.Context, getPipelineReques // Get a pipeline func (a *PipelinesAPI) GetPipelineByPipelineId(ctx context.Context, pipelineId string) (*GetPipelineResponse, error) { - return a.GetPipeline(ctx, GetPipelineRequest{ + return a.impl.GetPipeline(ctx, GetPipelineRequest{ PipelineId: pipelineId, }) } @@ -160,17 +182,14 @@ func (a *PipelinesAPI) GetPipelineByPipelineIdAndWait(ctx context.Context, pipel // // Gets an update from an active pipeline. func (a *PipelinesAPI) GetUpdate(ctx context.Context, request GetUpdateRequest) (*GetUpdateResponse, error) { - var getUpdateResponse GetUpdateResponse - path := fmt.Sprintf("/api/2.0/pipelines/%v/updates/%v", request.PipelineId, request.UpdateId) - err := a.client.Get(ctx, path, request, &getUpdateResponse) - return &getUpdateResponse, err + return a.impl.GetUpdate(ctx, request) } // Get a pipeline update // // Gets an update from an active pipeline. func (a *PipelinesAPI) GetUpdateByPipelineIdAndUpdateId(ctx context.Context, pipelineId string, updateId string) (*GetUpdateResponse, error) { - return a.GetUpdate(ctx, GetUpdateRequest{ + return a.impl.GetUpdate(ctx, GetUpdateRequest{ PipelineId: pipelineId, UpdateId: updateId, }) @@ -180,17 +199,14 @@ func (a *PipelinesAPI) GetUpdateByPipelineIdAndUpdateId(ctx context.Context, pip // // List updates for an active pipeline. func (a *PipelinesAPI) ListUpdates(ctx context.Context, request ListUpdatesRequest) (*ListUpdatesResponse, error) { - var listUpdatesResponse ListUpdatesResponse - path := fmt.Sprintf("/api/2.0/pipelines/%v/updates", request.PipelineId) - err := a.client.Get(ctx, path, request, &listUpdatesResponse) - return &listUpdatesResponse, err + return a.impl.ListUpdates(ctx, request) } // List pipeline updates // // List updates for an active pipeline. func (a *PipelinesAPI) ListUpdatesByPipelineId(ctx context.Context, pipelineId string) (*ListUpdatesResponse, error) { - return a.ListUpdates(ctx, ListUpdatesRequest{ + return a.impl.ListUpdates(ctx, ListUpdatesRequest{ PipelineId: pipelineId, }) } @@ -199,12 +215,10 @@ func (a *PipelinesAPI) ListUpdatesByPipelineId(ctx context.Context, pipelineId s // // Resets a pipeline. func (a *PipelinesAPI) ResetPipeline(ctx context.Context, request ResetPipelineRequest) error { - path := fmt.Sprintf("/api/2.0/pipelines/%v/reset", request.PipelineId) - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.ResetPipeline(ctx, request) } -// ResetPipeline and wait to reach RUNNING state +// Calls [PipelinesAPI.ResetPipeline] and waits to reach RUNNING state // // You can override the default timeout of 20 minutes by calling adding // retries.Timeout[GetPipelineResponse](60*time.Minute) functional option. @@ -250,22 +264,17 @@ func (a *PipelinesAPI) ResetPipelineAndWait(ctx context.Context, resetPipelineRe // // Starts or queues a pipeline update. func (a *PipelinesAPI) StartUpdate(ctx context.Context, request StartUpdate) (*StartUpdateResponse, error) { - var startUpdateResponse StartUpdateResponse - path := fmt.Sprintf("/api/2.0/pipelines/%v/updates", request.PipelineId) - err := a.client.Post(ctx, path, request, &startUpdateResponse) - return &startUpdateResponse, err + return a.impl.StartUpdate(ctx, request) } // Stop a pipeline // // Stops a pipeline. func (a *PipelinesAPI) StopPipeline(ctx context.Context, request StopPipelineRequest) error { - path := fmt.Sprintf("/api/2.0/pipelines/%v/stop", request.PipelineId) - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.StopPipeline(ctx, request) } -// StopPipeline and wait to reach IDLE state +// Calls [PipelinesAPI.StopPipeline] and waits to reach IDLE state // // You can override the default timeout of 20 minutes by calling adding // retries.Timeout[GetPipelineResponse](60*time.Minute) functional option. @@ -311,7 +320,5 @@ func (a *PipelinesAPI) StopPipelineAndWait(ctx context.Context, stopPipelineRequ // // Updates a pipeline with the supplied configuration. func (a *PipelinesAPI) UpdatePipeline(ctx context.Context, request EditPipeline) error { - path := fmt.Sprintf("/api/2.0/pipelines/%v", request.PipelineId) - err := a.client.Put(ctx, path, request) - return err + return a.impl.UpdatePipeline(ctx, request) } diff --git a/service/pipelines/impl.go b/service/pipelines/impl.go new file mode 100755 index 000000000..46fc2f3e2 --- /dev/null +++ b/service/pipelines/impl.go @@ -0,0 +1,74 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package pipelines + +import ( + "context" + "fmt" + + "github.com/databricks/databricks-sdk-go/databricks/client" +) + +// unexported type that holds implementations of just Pipelines API methods +type pipelinesImpl struct { + client *client.DatabricksClient +} + +func (a *pipelinesImpl) CreatePipeline(ctx context.Context, request CreatePipeline) (*CreatePipelineResponse, error) { + var createPipelineResponse CreatePipelineResponse + path := "/api/2.0/pipelines" + err := a.client.Post(ctx, path, request, &createPipelineResponse) + return &createPipelineResponse, err +} + +func (a *pipelinesImpl) DeletePipeline(ctx context.Context, request DeletePipelineRequest) error { + path := fmt.Sprintf("/api/2.0/pipelines/%v", request.PipelineId) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *pipelinesImpl) GetPipeline(ctx context.Context, request GetPipelineRequest) (*GetPipelineResponse, error) { + var getPipelineResponse GetPipelineResponse + path := fmt.Sprintf("/api/2.0/pipelines/%v", request.PipelineId) + err := a.client.Get(ctx, path, request, &getPipelineResponse) + return &getPipelineResponse, err +} + +func (a *pipelinesImpl) GetUpdate(ctx context.Context, request GetUpdateRequest) (*GetUpdateResponse, error) { + var getUpdateResponse GetUpdateResponse + path := fmt.Sprintf("/api/2.0/pipelines/%v/updates/%v", request.PipelineId, request.UpdateId) + err := a.client.Get(ctx, path, request, &getUpdateResponse) + return &getUpdateResponse, err +} + +func (a *pipelinesImpl) ListUpdates(ctx context.Context, request ListUpdatesRequest) (*ListUpdatesResponse, error) { + var listUpdatesResponse ListUpdatesResponse + path := fmt.Sprintf("/api/2.0/pipelines/%v/updates", request.PipelineId) + err := a.client.Get(ctx, path, request, &listUpdatesResponse) + return &listUpdatesResponse, err +} + +func (a *pipelinesImpl) ResetPipeline(ctx context.Context, request ResetPipelineRequest) error { + path := fmt.Sprintf("/api/2.0/pipelines/%v/reset", request.PipelineId) + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *pipelinesImpl) StartUpdate(ctx context.Context, request StartUpdate) (*StartUpdateResponse, error) { + var startUpdateResponse StartUpdateResponse + path := fmt.Sprintf("/api/2.0/pipelines/%v/updates", request.PipelineId) + err := a.client.Post(ctx, path, request, &startUpdateResponse) + return &startUpdateResponse, err +} + +func (a *pipelinesImpl) StopPipeline(ctx context.Context, request StopPipelineRequest) error { + path := fmt.Sprintf("/api/2.0/pipelines/%v/stop", request.PipelineId) + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *pipelinesImpl) UpdatePipeline(ctx context.Context, request EditPipeline) error { + path := fmt.Sprintf("/api/2.0/pipelines/%v", request.PipelineId) + err := a.client.Put(ctx, path, request) + return err +} diff --git a/service/pipelines/interface.go b/service/pipelines/interface.go index 7bf12ac29..01df887f6 100755 --- a/service/pipelines/interface.go +++ b/service/pipelines/interface.go @@ -4,8 +4,6 @@ package pipelines import ( "context" - - "github.com/databricks/databricks-sdk-go/databricks/retries" ) // The Delta Live Tables API allows you to create, edit, delete, start, and view @@ -22,10 +20,6 @@ import ( // data quality with Delta Live Tables expectations. Expectations allow you to // define expected data quality and specify how to handle records that fail // those expectations. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type PipelinesService interface { // Create a pipeline @@ -35,72 +29,29 @@ type PipelinesService interface { // pipeline. CreatePipeline(ctx context.Context, request CreatePipeline) (*CreatePipelineResponse, error) - // CreatePipelineAndWait calls CreatePipeline() and waits to reach RUNNING state - // - // This method is generated by Databricks SDK Code Generator. - CreatePipelineAndWait(ctx context.Context, request CreatePipeline, options ...retries.Option[GetPipelineResponse]) (*GetPipelineResponse, error) - // Delete a pipeline // // Deletes a pipeline. DeletePipeline(ctx context.Context, request DeletePipelineRequest) error - // DeletePipelineByPipelineId calls DeletePipeline, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeletePipelineByPipelineId(ctx context.Context, pipelineId string) error - // Get a pipeline GetPipeline(ctx context.Context, request GetPipelineRequest) (*GetPipelineResponse, error) - // GetPipelineAndWait calls GetPipeline() and waits to reach RUNNING state - // - // This method is generated by Databricks SDK Code Generator. - GetPipelineAndWait(ctx context.Context, request GetPipelineRequest, options ...retries.Option[GetPipelineResponse]) (*GetPipelineResponse, error) - // GetPipelineByPipelineId calls GetPipeline, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetPipelineByPipelineId(ctx context.Context, pipelineId string) (*GetPipelineResponse, error) - - // GetPipelineByPipelineIdAndWait calls GetPipelineByPipelineId and waits until GetPipelineResponse is in desired state. - // - // This method is generated by Databricks SDK Code Generator. - GetPipelineByPipelineIdAndWait(ctx context.Context, pipelineId string, options ...retries.Option[GetPipelineResponse]) (*GetPipelineResponse, error) - // Get a pipeline update // // Gets an update from an active pipeline. GetUpdate(ctx context.Context, request GetUpdateRequest) (*GetUpdateResponse, error) - // GetUpdateByPipelineIdAndUpdateId calls GetUpdate, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetUpdateByPipelineIdAndUpdateId(ctx context.Context, pipelineId string, updateId string) (*GetUpdateResponse, error) - // List pipeline updates // // List updates for an active pipeline. ListUpdates(ctx context.Context, request ListUpdatesRequest) (*ListUpdatesResponse, error) - // ListUpdatesByPipelineId calls ListUpdates, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - ListUpdatesByPipelineId(ctx context.Context, pipelineId string) (*ListUpdatesResponse, error) - // Reset a pipeline // // Resets a pipeline. ResetPipeline(ctx context.Context, request ResetPipelineRequest) error - // ResetPipelineAndWait calls ResetPipeline() and waits to reach RUNNING state - // - // This method is generated by Databricks SDK Code Generator. - ResetPipelineAndWait(ctx context.Context, request ResetPipelineRequest, options ...retries.Option[GetPipelineResponse]) (*GetPipelineResponse, error) - // Queue a pipeline update // // Starts or queues a pipeline update. @@ -111,11 +62,6 @@ type PipelinesService interface { // Stops a pipeline. StopPipeline(ctx context.Context, request StopPipelineRequest) error - // StopPipelineAndWait calls StopPipeline() and waits to reach IDLE state - // - // This method is generated by Databricks SDK Code Generator. - StopPipelineAndWait(ctx context.Context, request StopPipelineRequest, options ...retries.Option[GetPipelineResponse]) (*GetPipelineResponse, error) - // Edit a pipeline // // Updates a pipeline with the supplied configuration. diff --git a/service/repos/api.go b/service/repos/api.go index e58649dd5..f8a91662a 100755 --- a/service/repos/api.go +++ b/service/repos/api.go @@ -4,20 +4,45 @@ package repos import ( "context" - "fmt" "github.com/databricks/databricks-sdk-go/databricks/client" "github.com/databricks/databricks-sdk-go/databricks/useragent" ) -func NewRepos(client *client.DatabricksClient) ReposService { +func NewRepos(client *client.DatabricksClient) *ReposAPI { return &ReposAPI{ - client: client, + impl: &reposImpl{ + client: client, + }, } } +// The Repos API allows users to manage their git repos. Users can use the API +// to access all repos that they have manage permissions on. +// +// Databricks Repos is a visual Git client in Databricks. It supports common Git +// operations such a cloning a repository, committing and pushing, pulling, +// branch management, and visual comparison of diffs when committing. +// +// Within Repos you can develop code in notebooks or other files and follow data +// science and engineering code development best practices using Git for version +// control, collaboration, and CI/CD. type ReposAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(ReposService) + impl ReposService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *ReposAPI) WithImpl(impl ReposService) *ReposAPI { + a.impl = impl + return a +} + +// Impl returns low-level Repos API implementation +func (a *ReposAPI) Impl() ReposService { + return a.impl } // Create a repo @@ -26,26 +51,21 @@ type ReposAPI struct { // specified. Note that repos created programmatically must be linked to a // remote Git repo, unlike repos created in the browser. func (a *ReposAPI) Create(ctx context.Context, request CreateRepo) (*RepoInfo, error) { - var repoInfo RepoInfo - path := "/api/2.0/repos" - err := a.client.Post(ctx, path, request, &repoInfo) - return &repoInfo, err + return a.impl.Create(ctx, request) } // Delete a repo // // Deletes the specified repo. func (a *ReposAPI) Delete(ctx context.Context, request DeleteRequest) error { - path := fmt.Sprintf("/api/2.0/repos/%v", request.RepoId) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.Delete(ctx, request) } // Delete a repo // // Deletes the specified repo. func (a *ReposAPI) DeleteByRepoId(ctx context.Context, repoId int64) error { - return a.Delete(ctx, DeleteRequest{ + return a.impl.Delete(ctx, DeleteRequest{ RepoId: repoId, }) } @@ -54,17 +74,14 @@ func (a *ReposAPI) DeleteByRepoId(ctx context.Context, repoId int64) error { // // Returns the repo with the given repo ID. func (a *ReposAPI) Get(ctx context.Context, request GetRequest) (*RepoInfo, error) { - var repoInfo RepoInfo - path := fmt.Sprintf("/api/2.0/repos/%v", request.RepoId) - err := a.client.Get(ctx, path, request, &repoInfo) - return &repoInfo, err + return a.impl.Get(ctx, request) } // Get a repo // // Returns the repo with the given repo ID. func (a *ReposAPI) GetByRepoId(ctx context.Context, repoId int64) (*RepoInfo, error) { - return a.Get(ctx, GetRequest{ + return a.impl.Get(ctx, GetRequest{ RepoId: repoId, }) } @@ -74,22 +91,12 @@ func (a *ReposAPI) GetByRepoId(ctx context.Context, repoId int64) (*RepoInfo, er // Returns repos that the calling user has Manage permissions on. Results are // paginated with each page containing twenty repos. // -// Use ListAll() to get all RepoInfo instances, which will iterate over every result page. -func (a *ReposAPI) List(ctx context.Context, request ListRequest) (*ListReposResponse, error) { - var listReposResponse ListReposResponse - path := "/api/2.0/repos" - err := a.client.Get(ctx, path, request, &listReposResponse) - return &listReposResponse, err -} - -// ListAll returns all RepoInfo instances by calling List for every result page -// // This method is generated by Databricks SDK Code Generator. func (a *ReposAPI) ListAll(ctx context.Context, request ListRequest) ([]RepoInfo, error) { var results []RepoInfo ctx = useragent.InContext(ctx, "sdk-feature", "pagination") for { - response, err := a.List(ctx, request) + response, err := a.impl.List(ctx, request) if err != nil { return nil, err } @@ -112,7 +119,5 @@ func (a *ReposAPI) ListAll(ctx context.Context, request ListRequest) ([]RepoInfo // Updates the repo to a different branch or tag, or updates the repo to the // latest commit on the same branch. func (a *ReposAPI) Update(ctx context.Context, request UpdateRepo) error { - path := fmt.Sprintf("/api/2.0/repos/%v", request.RepoId) - err := a.client.Patch(ctx, path, request) - return err + return a.impl.Update(ctx, request) } diff --git a/service/repos/impl.go b/service/repos/impl.go new file mode 100755 index 000000000..725bb199a --- /dev/null +++ b/service/repos/impl.go @@ -0,0 +1,48 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package repos + +import ( + "context" + "fmt" + + "github.com/databricks/databricks-sdk-go/databricks/client" +) + +// unexported type that holds implementations of just Repos API methods +type reposImpl struct { + client *client.DatabricksClient +} + +func (a *reposImpl) Create(ctx context.Context, request CreateRepo) (*RepoInfo, error) { + var repoInfo RepoInfo + path := "/api/2.0/repos" + err := a.client.Post(ctx, path, request, &repoInfo) + return &repoInfo, err +} + +func (a *reposImpl) Delete(ctx context.Context, request DeleteRequest) error { + path := fmt.Sprintf("/api/2.0/repos/%v", request.RepoId) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *reposImpl) Get(ctx context.Context, request GetRequest) (*RepoInfo, error) { + var repoInfo RepoInfo + path := fmt.Sprintf("/api/2.0/repos/%v", request.RepoId) + err := a.client.Get(ctx, path, request, &repoInfo) + return &repoInfo, err +} + +func (a *reposImpl) List(ctx context.Context, request ListRequest) (*ListReposResponse, error) { + var listReposResponse ListReposResponse + path := "/api/2.0/repos" + err := a.client.Get(ctx, path, request, &listReposResponse) + return &listReposResponse, err +} + +func (a *reposImpl) Update(ctx context.Context, request UpdateRepo) error { + path := fmt.Sprintf("/api/2.0/repos/%v", request.RepoId) + err := a.client.Patch(ctx, path, request) + return err +} diff --git a/service/repos/interface.go b/service/repos/interface.go index 84e8ab179..3630da6c3 100755 --- a/service/repos/interface.go +++ b/service/repos/interface.go @@ -16,10 +16,6 @@ import ( // Within Repos you can develop code in notebooks or other files and follow data // science and engineering code development best practices using Git for version // control, collaboration, and CI/CD. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type ReposService interface { // Create a repo @@ -34,23 +30,11 @@ type ReposService interface { // Deletes the specified repo. Delete(ctx context.Context, request DeleteRequest) error - // DeleteByRepoId calls Delete, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteByRepoId(ctx context.Context, repoId int64) error - // Get a repo // // Returns the repo with the given repo ID. Get(ctx context.Context, request GetRequest) (*RepoInfo, error) - // GetByRepoId calls Get, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetByRepoId(ctx context.Context, repoId int64) (*RepoInfo, error) - // Get repos // // Returns repos that the calling user has Manage permissions on. Results @@ -59,11 +43,6 @@ type ReposService interface { // Use ListAll() to get all RepoInfo instances, which will iterate over every result page. List(ctx context.Context, request ListRequest) (*ListReposResponse, error) - // ListAll calls List() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListAll(ctx context.Context, request ListRequest) ([]RepoInfo, error) - // Update a repo // // Updates the repo to a different branch or tag, or updates the repo to the diff --git a/service/scim/api.go b/service/scim/api.go index 7100cce67..54992c1f2 100755 --- a/service/scim/api.go +++ b/service/scim/api.go @@ -4,19 +4,41 @@ package scim import ( "context" - "fmt" "github.com/databricks/databricks-sdk-go/databricks/client" ) -func NewAccountGroups(client *client.DatabricksClient) AccountGroupsService { +func NewAccountGroups(client *client.DatabricksClient) *AccountGroupsAPI { return &AccountGroupsAPI{ - client: client, + impl: &accountGroupsImpl{ + client: client, + }, } } +// Groups simplify identity management, making it easier to assign access to +// Databricks Account, data, and other securable objects. +// +// It is best practice to assign access to workspaces and access-control +// policies in Unity Catalog to groups, instead of to users individually. All +// Databricks Account identities can be assigned as members of groups, and +// members inherit permissions that are assigned to their group. type AccountGroupsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(AccountGroupsService) + impl AccountGroupsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *AccountGroupsAPI) WithImpl(impl AccountGroupsService) *AccountGroupsAPI { + a.impl = impl + return a +} + +// Impl returns low-level AccountGroups API implementation +func (a *AccountGroupsAPI) Impl() AccountGroupsService { + return a.impl } // Create a new group @@ -24,26 +46,21 @@ type AccountGroupsAPI struct { // Creates a group in the Databricks Account with a unique name, using the // supplied group details. func (a *AccountGroupsAPI) CreateGroup(ctx context.Context, request Group) (*Group, error) { - var group Group - path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Groups", a.client.Config.AccountID) - err := a.client.Post(ctx, path, request, &group) - return &group, err + return a.impl.CreateGroup(ctx, request) } // Delete a group // // Deletes a group from the Databricks Account. func (a *AccountGroupsAPI) DeleteGroup(ctx context.Context, request DeleteGroupRequest) error { - path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Groups/%v", a.client.Config.AccountID, request.Id) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteGroup(ctx, request) } // Delete a group // // Deletes a group from the Databricks Account. func (a *AccountGroupsAPI) DeleteGroupById(ctx context.Context, id string) error { - return a.DeleteGroup(ctx, DeleteGroupRequest{ + return a.impl.DeleteGroup(ctx, DeleteGroupRequest{ Id: id, }) } @@ -52,17 +69,14 @@ func (a *AccountGroupsAPI) DeleteGroupById(ctx context.Context, id string) error // // Gets the information for a specific group in the Databricks Account. func (a *AccountGroupsAPI) GetGroup(ctx context.Context, request GetGroupRequest) (*Group, error) { - var group Group - path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Groups/%v", a.client.Config.AccountID, request.Id) - err := a.client.Get(ctx, path, request, &group) - return &group, err + return a.impl.GetGroup(ctx, request) } // Get group details // // Gets the information for a specific group in the Databricks Account. func (a *AccountGroupsAPI) GetGroupById(ctx context.Context, id string) (*Group, error) { - return a.GetGroup(ctx, GetGroupRequest{ + return a.impl.GetGroup(ctx, GetGroupRequest{ Id: id, }) } @@ -71,19 +85,9 @@ func (a *AccountGroupsAPI) GetGroupById(ctx context.Context, id string) (*Group, // // Gets all details of the groups associated with the Databricks Account. // -// Use ListGroupsAll() to get all Group instances -func (a *AccountGroupsAPI) ListGroups(ctx context.Context, request ListGroupsRequest) (*ListGroupsResponse, error) { - var listGroupsResponse ListGroupsResponse - path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Groups", a.client.Config.AccountID) - err := a.client.Get(ctx, path, request, &listGroupsResponse) - return &listGroupsResponse, err -} - -// ListGroupsAll returns all Group instances. This method exists for consistency purposes. -// // This method is generated by Databricks SDK Code Generator. func (a *AccountGroupsAPI) ListGroupsAll(ctx context.Context, request ListGroupsRequest) ([]Group, error) { - response, err := a.ListGroups(ctx, request) + response, err := a.impl.ListGroups(ctx, request) if err != nil { return nil, err } @@ -94,54 +98,67 @@ func (a *AccountGroupsAPI) ListGroupsAll(ctx context.Context, request ListGroups // // Partially updates the details of a group. func (a *AccountGroupsAPI) PatchGroup(ctx context.Context, request PartialUpdate) error { - path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Groups/%v", a.client.Config.AccountID, request.Id) - err := a.client.Patch(ctx, path, request) - return err + return a.impl.PatchGroup(ctx, request) } // Replace a group // // Updates the details of a group by replacing the entire group entity. func (a *AccountGroupsAPI) UpdateGroup(ctx context.Context, request Group) error { - path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Groups/%v", a.client.Config.AccountID, request.Id) - err := a.client.Put(ctx, path, request) - return err + return a.impl.UpdateGroup(ctx, request) } -func NewAccountServicePrincipals(client *client.DatabricksClient) AccountServicePrincipalsService { +func NewAccountServicePrincipals(client *client.DatabricksClient) *AccountServicePrincipalsAPI { return &AccountServicePrincipalsAPI{ - client: client, + impl: &accountServicePrincipalsImpl{ + client: client, + }, } } +// Identities for use with jobs, automated tools, and systems such as scripts, +// apps, and CI/CD platforms. Databricks recommends creating service principals +// to run production jobs or modify production data. If all processes that act +// on production data run with service principals, interactive users do not need +// any write, delete, or modify privileges in production. This eliminates the +// risk of a user overwriting production data by accident. type AccountServicePrincipalsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(AccountServicePrincipalsService) + impl AccountServicePrincipalsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *AccountServicePrincipalsAPI) WithImpl(impl AccountServicePrincipalsService) *AccountServicePrincipalsAPI { + a.impl = impl + return a +} + +// Impl returns low-level AccountServicePrincipals API implementation +func (a *AccountServicePrincipalsAPI) Impl() AccountServicePrincipalsService { + return a.impl } // Create a service principal // // Creates a new service principal in the Databricks Account. func (a *AccountServicePrincipalsAPI) CreateServicePrincipal(ctx context.Context, request ServicePrincipal) (*ServicePrincipal, error) { - var servicePrincipal ServicePrincipal - path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/ServicePrincipals", a.client.Config.AccountID) - err := a.client.Post(ctx, path, request, &servicePrincipal) - return &servicePrincipal, err + return a.impl.CreateServicePrincipal(ctx, request) } // Delete a service principal // // Delete a single service principal in the Databricks Account. func (a *AccountServicePrincipalsAPI) DeleteServicePrincipal(ctx context.Context, request DeleteServicePrincipalRequest) error { - path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/ServicePrincipals/%v", a.client.Config.AccountID, request.Id) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteServicePrincipal(ctx, request) } // Delete a service principal // // Delete a single service principal in the Databricks Account. func (a *AccountServicePrincipalsAPI) DeleteServicePrincipalById(ctx context.Context, id string) error { - return a.DeleteServicePrincipal(ctx, DeleteServicePrincipalRequest{ + return a.impl.DeleteServicePrincipal(ctx, DeleteServicePrincipalRequest{ Id: id, }) } @@ -151,10 +168,7 @@ func (a *AccountServicePrincipalsAPI) DeleteServicePrincipalById(ctx context.Con // Gets the details for a single service principal define in the Databricks // Account. func (a *AccountServicePrincipalsAPI) GetServicePrincipal(ctx context.Context, request GetServicePrincipalRequest) (*ServicePrincipal, error) { - var servicePrincipal ServicePrincipal - path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/ServicePrincipals/%v", a.client.Config.AccountID, request.Id) - err := a.client.Get(ctx, path, request, &servicePrincipal) - return &servicePrincipal, err + return a.impl.GetServicePrincipal(ctx, request) } // Get service principal details @@ -162,7 +176,7 @@ func (a *AccountServicePrincipalsAPI) GetServicePrincipal(ctx context.Context, r // Gets the details for a single service principal define in the Databricks // Account. func (a *AccountServicePrincipalsAPI) GetServicePrincipalById(ctx context.Context, id string) (*ServicePrincipal, error) { - return a.GetServicePrincipal(ctx, GetServicePrincipalRequest{ + return a.impl.GetServicePrincipal(ctx, GetServicePrincipalRequest{ Id: id, }) } @@ -171,19 +185,9 @@ func (a *AccountServicePrincipalsAPI) GetServicePrincipalById(ctx context.Contex // // Gets the set of service principals associated with a Databricks Account. // -// Use ListServicePrincipalsAll() to get all ServicePrincipal instances -func (a *AccountServicePrincipalsAPI) ListServicePrincipals(ctx context.Context, request ListServicePrincipalsRequest) (*ListServicePrincipalResponse, error) { - var listServicePrincipalResponse ListServicePrincipalResponse - path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/ServicePrincipals", a.client.Config.AccountID) - err := a.client.Get(ctx, path, request, &listServicePrincipalResponse) - return &listServicePrincipalResponse, err -} - -// ListServicePrincipalsAll returns all ServicePrincipal instances. This method exists for consistency purposes. -// // This method is generated by Databricks SDK Code Generator. func (a *AccountServicePrincipalsAPI) ListServicePrincipalsAll(ctx context.Context, request ListServicePrincipalsRequest) ([]ServicePrincipal, error) { - response, err := a.ListServicePrincipals(ctx, request) + response, err := a.impl.ListServicePrincipals(ctx, request) if err != nil { return nil, err } @@ -195,9 +199,7 @@ func (a *AccountServicePrincipalsAPI) ListServicePrincipalsAll(ctx context.Conte // Partially updates the details of a single service principal in the Databricks // Account. func (a *AccountServicePrincipalsAPI) PatchServicePrincipal(ctx context.Context, request PartialUpdate) error { - path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/ServicePrincipals/%v", a.client.Config.AccountID, request.Id) - err := a.client.Patch(ctx, path, request) - return err + return a.impl.PatchServicePrincipal(ctx, request) } // Replace service principal @@ -206,19 +208,44 @@ func (a *AccountServicePrincipalsAPI) PatchServicePrincipal(ctx context.Context, // // This action replaces the existing service principal with the same name. func (a *AccountServicePrincipalsAPI) UpdateServicePrincipal(ctx context.Context, request ServicePrincipal) error { - path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/ServicePrincipals/%v", a.client.Config.AccountID, request.Id) - err := a.client.Put(ctx, path, request) - return err + return a.impl.UpdateServicePrincipal(ctx, request) } -func NewAccountUsers(client *client.DatabricksClient) AccountUsersService { +func NewAccountUsers(client *client.DatabricksClient) *AccountUsersAPI { return &AccountUsersAPI{ - client: client, + impl: &accountUsersImpl{ + client: client, + }, } } +// User identities recognized by Databricks and represented by email addresses. +// +// Databricks recommends using SCIM provisioning to sync users and groups +// automatically from your identity provider to your Databricks Account. SCIM +// streamlines onboarding a new employee or team by using your identity provider +// to create users and groups in Databricks Account and give them the proper +// level of access. When a user leaves your organization or no longer needs +// access to Databricks Account, admins can terminate the user in your identity +// provider and that user’s account will also be removed from Databricks +// Account. This ensures a consistent offboarding process and prevents +// unauthorized users from accessing sensitive data. type AccountUsersAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(AccountUsersService) + impl AccountUsersService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *AccountUsersAPI) WithImpl(impl AccountUsersService) *AccountUsersAPI { + a.impl = impl + return a +} + +// Impl returns low-level AccountUsers API implementation +func (a *AccountUsersAPI) Impl() AccountUsersService { + return a.impl } // Create a new user @@ -226,10 +253,7 @@ type AccountUsersAPI struct { // Creates a new user in the Databricks Account. This new user will also be // added to the Databricks account. func (a *AccountUsersAPI) CreateUser(ctx context.Context, request User) (*User, error) { - var user User - path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Users", a.client.Config.AccountID) - err := a.client.Post(ctx, path, request, &user) - return &user, err + return a.impl.CreateUser(ctx, request) } // Delete a user @@ -237,9 +261,7 @@ func (a *AccountUsersAPI) CreateUser(ctx context.Context, request User) (*User, // Deletes a user. Deleting a user from a Databricks Account also removes // objects associated with the user. func (a *AccountUsersAPI) DeleteUser(ctx context.Context, request DeleteUserRequest) error { - path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Users/%v", a.client.Config.AccountID, request.Id) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteUser(ctx, request) } // Delete a user @@ -247,7 +269,7 @@ func (a *AccountUsersAPI) DeleteUser(ctx context.Context, request DeleteUserRequ // Deletes a user. Deleting a user from a Databricks Account also removes // objects associated with the user. func (a *AccountUsersAPI) DeleteUserById(ctx context.Context, id string) error { - return a.DeleteUser(ctx, DeleteUserRequest{ + return a.impl.DeleteUser(ctx, DeleteUserRequest{ Id: id, }) } @@ -256,17 +278,14 @@ func (a *AccountUsersAPI) DeleteUserById(ctx context.Context, id string) error { // // Gets information for a specific user in Databricks Account. func (a *AccountUsersAPI) GetUser(ctx context.Context, request GetUserRequest) (*User, error) { - var user User - path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Users/%v", a.client.Config.AccountID, request.Id) - err := a.client.Get(ctx, path, request, &user) - return &user, err + return a.impl.GetUser(ctx, request) } // Get user details // // Gets information for a specific user in Databricks Account. func (a *AccountUsersAPI) GetUserById(ctx context.Context, id string) (*User, error) { - return a.GetUser(ctx, GetUserRequest{ + return a.impl.GetUser(ctx, GetUserRequest{ Id: id, }) } @@ -275,19 +294,9 @@ func (a *AccountUsersAPI) GetUserById(ctx context.Context, id string) (*User, er // // Gets details for all the users associated with a Databricks Account. // -// Use ListUsersAll() to get all User instances -func (a *AccountUsersAPI) ListUsers(ctx context.Context, request ListUsersRequest) (*ListUsersResponse, error) { - var listUsersResponse ListUsersResponse - path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Users", a.client.Config.AccountID) - err := a.client.Get(ctx, path, request, &listUsersResponse) - return &listUsersResponse, err -} - -// ListUsersAll returns all User instances. This method exists for consistency purposes. -// // This method is generated by Databricks SDK Code Generator. func (a *AccountUsersAPI) ListUsersAll(ctx context.Context, request ListUsersRequest) ([]User, error) { - response, err := a.ListUsers(ctx, request) + response, err := a.impl.ListUsers(ctx, request) if err != nil { return nil, err } @@ -299,48 +308,82 @@ func (a *AccountUsersAPI) ListUsersAll(ctx context.Context, request ListUsersReq // Partially updates a user resource by applying the supplied operations on // specific user attributes. func (a *AccountUsersAPI) PatchUser(ctx context.Context, request PartialUpdate) error { - path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Users/%v", a.client.Config.AccountID, request.Id) - err := a.client.Patch(ctx, path, request) - return err + return a.impl.PatchUser(ctx, request) } // Replace a user // // Replaces a user's information with the data supplied in request. func (a *AccountUsersAPI) UpdateUser(ctx context.Context, request User) error { - path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Users/%v", a.client.Config.AccountID, request.Id) - err := a.client.Put(ctx, path, request) - return err + return a.impl.UpdateUser(ctx, request) } -func NewCurrentUser(client *client.DatabricksClient) CurrentUserService { +func NewCurrentUser(client *client.DatabricksClient) *CurrentUserAPI { return &CurrentUserAPI{ - client: client, + impl: ¤tUserImpl{ + client: client, + }, } } +// This API allows retrieving information about currently authenticated user or +// service principal. type CurrentUserAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(CurrentUserService) + impl CurrentUserService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *CurrentUserAPI) WithImpl(impl CurrentUserService) *CurrentUserAPI { + a.impl = impl + return a +} + +// Impl returns low-level CurrentUser API implementation +func (a *CurrentUserAPI) Impl() CurrentUserService { + return a.impl } // Get current user info // // Get details about the current method caller's identity. func (a *CurrentUserAPI) Me(ctx context.Context) (*User, error) { - var user User - path := "/api/2.0/preview/scim/v2/Me" - err := a.client.Get(ctx, path, nil, &user) - return &user, err + return a.impl.Me(ctx) } -func NewGroups(client *client.DatabricksClient) GroupsService { +func NewGroups(client *client.DatabricksClient) *GroupsAPI { return &GroupsAPI{ - client: client, + impl: &groupsImpl{ + client: client, + }, } } +// Groups simplify identity management, making it easier to assign access to +// Databricks Workspace, data, and other securable objects. +// +// It is best practice to assign access to workspaces and access-control +// policies in Unity Catalog to groups, instead of to users individually. All +// Databricks Workspace identities can be assigned as members of groups, and +// members inherit permissions that are assigned to their group. type GroupsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(GroupsService) + impl GroupsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *GroupsAPI) WithImpl(impl GroupsService) *GroupsAPI { + a.impl = impl + return a +} + +// Impl returns low-level Groups API implementation +func (a *GroupsAPI) Impl() GroupsService { + return a.impl } // Create a new group @@ -348,26 +391,21 @@ type GroupsAPI struct { // Creates a group in the Databricks Workspace with a unique name, using the // supplied group details. func (a *GroupsAPI) CreateGroup(ctx context.Context, request Group) (*Group, error) { - var group Group - path := "/api/2.0/preview/scim/v2/Groups" - err := a.client.Post(ctx, path, request, &group) - return &group, err + return a.impl.CreateGroup(ctx, request) } // Delete a group // // Deletes a group from the Databricks Workspace. func (a *GroupsAPI) DeleteGroup(ctx context.Context, request DeleteGroupRequest) error { - path := fmt.Sprintf("/api/2.0/preview/scim/v2/Groups/%v", request.Id) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteGroup(ctx, request) } // Delete a group // // Deletes a group from the Databricks Workspace. func (a *GroupsAPI) DeleteGroupById(ctx context.Context, id string) error { - return a.DeleteGroup(ctx, DeleteGroupRequest{ + return a.impl.DeleteGroup(ctx, DeleteGroupRequest{ Id: id, }) } @@ -376,17 +414,14 @@ func (a *GroupsAPI) DeleteGroupById(ctx context.Context, id string) error { // // Gets the information for a specific group in the Databricks Workspace. func (a *GroupsAPI) GetGroup(ctx context.Context, request GetGroupRequest) (*Group, error) { - var group Group - path := fmt.Sprintf("/api/2.0/preview/scim/v2/Groups/%v", request.Id) - err := a.client.Get(ctx, path, request, &group) - return &group, err + return a.impl.GetGroup(ctx, request) } // Get group details // // Gets the information for a specific group in the Databricks Workspace. func (a *GroupsAPI) GetGroupById(ctx context.Context, id string) (*Group, error) { - return a.GetGroup(ctx, GetGroupRequest{ + return a.impl.GetGroup(ctx, GetGroupRequest{ Id: id, }) } @@ -395,19 +430,9 @@ func (a *GroupsAPI) GetGroupById(ctx context.Context, id string) (*Group, error) // // Gets all details of the groups associated with the Databricks Workspace. // -// Use ListGroupsAll() to get all Group instances -func (a *GroupsAPI) ListGroups(ctx context.Context, request ListGroupsRequest) (*ListGroupsResponse, error) { - var listGroupsResponse ListGroupsResponse - path := "/api/2.0/preview/scim/v2/Groups" - err := a.client.Get(ctx, path, request, &listGroupsResponse) - return &listGroupsResponse, err -} - -// ListGroupsAll returns all Group instances. This method exists for consistency purposes. -// // This method is generated by Databricks SDK Code Generator. func (a *GroupsAPI) ListGroupsAll(ctx context.Context, request ListGroupsRequest) ([]Group, error) { - response, err := a.ListGroups(ctx, request) + response, err := a.impl.ListGroups(ctx, request) if err != nil { return nil, err } @@ -418,54 +443,67 @@ func (a *GroupsAPI) ListGroupsAll(ctx context.Context, request ListGroupsRequest // // Partially updates the details of a group. func (a *GroupsAPI) PatchGroup(ctx context.Context, request PartialUpdate) error { - path := fmt.Sprintf("/api/2.0/preview/scim/v2/Groups/%v", request.Id) - err := a.client.Patch(ctx, path, request) - return err + return a.impl.PatchGroup(ctx, request) } // Replace a group // // Updates the details of a group by replacing the entire group entity. func (a *GroupsAPI) UpdateGroup(ctx context.Context, request Group) error { - path := fmt.Sprintf("/api/2.0/preview/scim/v2/Groups/%v", request.Id) - err := a.client.Put(ctx, path, request) - return err + return a.impl.UpdateGroup(ctx, request) } -func NewServicePrincipals(client *client.DatabricksClient) ServicePrincipalsService { +func NewServicePrincipals(client *client.DatabricksClient) *ServicePrincipalsAPI { return &ServicePrincipalsAPI{ - client: client, + impl: &servicePrincipalsImpl{ + client: client, + }, } } +// Identities for use with jobs, automated tools, and systems such as scripts, +// apps, and CI/CD platforms. Databricks recommends creating service principals +// to run production jobs or modify production data. If all processes that act +// on production data run with service principals, interactive users do not need +// any write, delete, or modify privileges in production. This eliminates the +// risk of a user overwriting production data by accident. type ServicePrincipalsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(ServicePrincipalsService) + impl ServicePrincipalsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *ServicePrincipalsAPI) WithImpl(impl ServicePrincipalsService) *ServicePrincipalsAPI { + a.impl = impl + return a +} + +// Impl returns low-level ServicePrincipals API implementation +func (a *ServicePrincipalsAPI) Impl() ServicePrincipalsService { + return a.impl } // Create a service principal // // Creates a new service principal in the Databricks Workspace. func (a *ServicePrincipalsAPI) CreateServicePrincipal(ctx context.Context, request ServicePrincipal) (*ServicePrincipal, error) { - var servicePrincipal ServicePrincipal - path := "/api/2.0/preview/scim/v2/ServicePrincipals" - err := a.client.Post(ctx, path, request, &servicePrincipal) - return &servicePrincipal, err + return a.impl.CreateServicePrincipal(ctx, request) } // Delete a service principal // // Delete a single service principal in the Databricks Workspace. func (a *ServicePrincipalsAPI) DeleteServicePrincipal(ctx context.Context, request DeleteServicePrincipalRequest) error { - path := fmt.Sprintf("/api/2.0/preview/scim/v2/ServicePrincipals/%v", request.Id) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteServicePrincipal(ctx, request) } // Delete a service principal // // Delete a single service principal in the Databricks Workspace. func (a *ServicePrincipalsAPI) DeleteServicePrincipalById(ctx context.Context, id string) error { - return a.DeleteServicePrincipal(ctx, DeleteServicePrincipalRequest{ + return a.impl.DeleteServicePrincipal(ctx, DeleteServicePrincipalRequest{ Id: id, }) } @@ -475,10 +513,7 @@ func (a *ServicePrincipalsAPI) DeleteServicePrincipalById(ctx context.Context, i // Gets the details for a single service principal define in the Databricks // Workspace. func (a *ServicePrincipalsAPI) GetServicePrincipal(ctx context.Context, request GetServicePrincipalRequest) (*ServicePrincipal, error) { - var servicePrincipal ServicePrincipal - path := fmt.Sprintf("/api/2.0/preview/scim/v2/ServicePrincipals/%v", request.Id) - err := a.client.Get(ctx, path, request, &servicePrincipal) - return &servicePrincipal, err + return a.impl.GetServicePrincipal(ctx, request) } // Get service principal details @@ -486,7 +521,7 @@ func (a *ServicePrincipalsAPI) GetServicePrincipal(ctx context.Context, request // Gets the details for a single service principal define in the Databricks // Workspace. func (a *ServicePrincipalsAPI) GetServicePrincipalById(ctx context.Context, id string) (*ServicePrincipal, error) { - return a.GetServicePrincipal(ctx, GetServicePrincipalRequest{ + return a.impl.GetServicePrincipal(ctx, GetServicePrincipalRequest{ Id: id, }) } @@ -495,19 +530,9 @@ func (a *ServicePrincipalsAPI) GetServicePrincipalById(ctx context.Context, id s // // Gets the set of service principals associated with a Databricks Workspace. // -// Use ListServicePrincipalsAll() to get all ServicePrincipal instances -func (a *ServicePrincipalsAPI) ListServicePrincipals(ctx context.Context, request ListServicePrincipalsRequest) (*ListServicePrincipalResponse, error) { - var listServicePrincipalResponse ListServicePrincipalResponse - path := "/api/2.0/preview/scim/v2/ServicePrincipals" - err := a.client.Get(ctx, path, request, &listServicePrincipalResponse) - return &listServicePrincipalResponse, err -} - -// ListServicePrincipalsAll returns all ServicePrincipal instances. This method exists for consistency purposes. -// // This method is generated by Databricks SDK Code Generator. func (a *ServicePrincipalsAPI) ListServicePrincipalsAll(ctx context.Context, request ListServicePrincipalsRequest) ([]ServicePrincipal, error) { - response, err := a.ListServicePrincipals(ctx, request) + response, err := a.impl.ListServicePrincipals(ctx, request) if err != nil { return nil, err } @@ -519,9 +544,7 @@ func (a *ServicePrincipalsAPI) ListServicePrincipalsAll(ctx context.Context, req // Partially updates the details of a single service principal in the Databricks // Workspace. func (a *ServicePrincipalsAPI) PatchServicePrincipal(ctx context.Context, request PartialUpdate) error { - path := fmt.Sprintf("/api/2.0/preview/scim/v2/ServicePrincipals/%v", request.Id) - err := a.client.Patch(ctx, path, request) - return err + return a.impl.PatchServicePrincipal(ctx, request) } // Replace service principal @@ -530,19 +553,44 @@ func (a *ServicePrincipalsAPI) PatchServicePrincipal(ctx context.Context, reques // // This action replaces the existing service principal with the same name. func (a *ServicePrincipalsAPI) UpdateServicePrincipal(ctx context.Context, request ServicePrincipal) error { - path := fmt.Sprintf("/api/2.0/preview/scim/v2/ServicePrincipals/%v", request.Id) - err := a.client.Put(ctx, path, request) - return err + return a.impl.UpdateServicePrincipal(ctx, request) } -func NewUsers(client *client.DatabricksClient) UsersService { +func NewUsers(client *client.DatabricksClient) *UsersAPI { return &UsersAPI{ - client: client, + impl: &usersImpl{ + client: client, + }, } } +// User identities recognized by Databricks and represented by email addresses. +// +// Databricks recommends using SCIM provisioning to sync users and groups +// automatically from your identity provider to your Databricks Workspace. SCIM +// streamlines onboarding a new employee or team by using your identity provider +// to create users and groups in Databricks Workspace and give them the proper +// level of access. When a user leaves your organization or no longer needs +// access to Databricks Workspace, admins can terminate the user in your +// identity provider and that user’s account will also be removed from +// Databricks Workspace. This ensures a consistent offboarding process and +// prevents unauthorized users from accessing sensitive data. type UsersAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(UsersService) + impl UsersService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *UsersAPI) WithImpl(impl UsersService) *UsersAPI { + a.impl = impl + return a +} + +// Impl returns low-level Users API implementation +func (a *UsersAPI) Impl() UsersService { + return a.impl } // Create a new user @@ -550,10 +598,7 @@ type UsersAPI struct { // Creates a new user in the Databricks Workspace. This new user will also be // added to the Databricks account. func (a *UsersAPI) CreateUser(ctx context.Context, request User) (*User, error) { - var user User - path := "/api/2.0/preview/scim/v2/Users" - err := a.client.Post(ctx, path, request, &user) - return &user, err + return a.impl.CreateUser(ctx, request) } // Delete a user @@ -561,9 +606,7 @@ func (a *UsersAPI) CreateUser(ctx context.Context, request User) (*User, error) // Deletes a user. Deleting a user from a Databricks Workspace also removes // objects associated with the user. func (a *UsersAPI) DeleteUser(ctx context.Context, request DeleteUserRequest) error { - path := fmt.Sprintf("/api/2.0/preview/scim/v2/Users/%v", request.Id) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteUser(ctx, request) } // Delete a user @@ -571,7 +614,7 @@ func (a *UsersAPI) DeleteUser(ctx context.Context, request DeleteUserRequest) er // Deletes a user. Deleting a user from a Databricks Workspace also removes // objects associated with the user. func (a *UsersAPI) DeleteUserById(ctx context.Context, id string) error { - return a.DeleteUser(ctx, DeleteUserRequest{ + return a.impl.DeleteUser(ctx, DeleteUserRequest{ Id: id, }) } @@ -580,17 +623,14 @@ func (a *UsersAPI) DeleteUserById(ctx context.Context, id string) error { // // Gets information for a specific user in Databricks Workspace. func (a *UsersAPI) GetUser(ctx context.Context, request GetUserRequest) (*User, error) { - var user User - path := fmt.Sprintf("/api/2.0/preview/scim/v2/Users/%v", request.Id) - err := a.client.Get(ctx, path, request, &user) - return &user, err + return a.impl.GetUser(ctx, request) } // Get user details // // Gets information for a specific user in Databricks Workspace. func (a *UsersAPI) GetUserById(ctx context.Context, id string) (*User, error) { - return a.GetUser(ctx, GetUserRequest{ + return a.impl.GetUser(ctx, GetUserRequest{ Id: id, }) } @@ -599,19 +639,9 @@ func (a *UsersAPI) GetUserById(ctx context.Context, id string) (*User, error) { // // Gets details for all the users associated with a Databricks Workspace. // -// Use ListUsersAll() to get all User instances -func (a *UsersAPI) ListUsers(ctx context.Context, request ListUsersRequest) (*ListUsersResponse, error) { - var listUsersResponse ListUsersResponse - path := "/api/2.0/preview/scim/v2/Users" - err := a.client.Get(ctx, path, request, &listUsersResponse) - return &listUsersResponse, err -} - -// ListUsersAll returns all User instances. This method exists for consistency purposes. -// // This method is generated by Databricks SDK Code Generator. func (a *UsersAPI) ListUsersAll(ctx context.Context, request ListUsersRequest) ([]User, error) { - response, err := a.ListUsers(ctx, request) + response, err := a.impl.ListUsers(ctx, request) if err != nil { return nil, err } @@ -623,16 +653,12 @@ func (a *UsersAPI) ListUsersAll(ctx context.Context, request ListUsersRequest) ( // Partially updates a user resource by applying the supplied operations on // specific user attributes. func (a *UsersAPI) PatchUser(ctx context.Context, request PartialUpdate) error { - path := fmt.Sprintf("/api/2.0/preview/scim/v2/Users/%v", request.Id) - err := a.client.Patch(ctx, path, request) - return err + return a.impl.PatchUser(ctx, request) } // Replace a user // // Replaces a user's information with the data supplied in request. func (a *UsersAPI) UpdateUser(ctx context.Context, request User) error { - path := fmt.Sprintf("/api/2.0/preview/scim/v2/Users/%v", request.Id) - err := a.client.Put(ctx, path, request) - return err + return a.impl.UpdateUser(ctx, request) } diff --git a/service/scim/impl.go b/service/scim/impl.go new file mode 100755 index 000000000..fdbadd527 --- /dev/null +++ b/service/scim/impl.go @@ -0,0 +1,286 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package scim + +import ( + "context" + "fmt" + + "github.com/databricks/databricks-sdk-go/databricks/client" +) + +// unexported type that holds implementations of just AccountGroups API methods +type accountGroupsImpl struct { + client *client.DatabricksClient +} + +func (a *accountGroupsImpl) CreateGroup(ctx context.Context, request Group) (*Group, error) { + var group Group + path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Groups", a.client.Config.AccountID) + err := a.client.Post(ctx, path, request, &group) + return &group, err +} + +func (a *accountGroupsImpl) DeleteGroup(ctx context.Context, request DeleteGroupRequest) error { + path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Groups/%v", a.client.Config.AccountID, request.Id) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *accountGroupsImpl) GetGroup(ctx context.Context, request GetGroupRequest) (*Group, error) { + var group Group + path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Groups/%v", a.client.Config.AccountID, request.Id) + err := a.client.Get(ctx, path, request, &group) + return &group, err +} + +func (a *accountGroupsImpl) ListGroups(ctx context.Context, request ListGroupsRequest) (*ListGroupsResponse, error) { + var listGroupsResponse ListGroupsResponse + path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Groups", a.client.Config.AccountID) + err := a.client.Get(ctx, path, request, &listGroupsResponse) + return &listGroupsResponse, err +} + +func (a *accountGroupsImpl) PatchGroup(ctx context.Context, request PartialUpdate) error { + path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Groups/%v", a.client.Config.AccountID, request.Id) + err := a.client.Patch(ctx, path, request) + return err +} + +func (a *accountGroupsImpl) UpdateGroup(ctx context.Context, request Group) error { + path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Groups/%v", a.client.Config.AccountID, request.Id) + err := a.client.Put(ctx, path, request) + return err +} + +// unexported type that holds implementations of just AccountServicePrincipals API methods +type accountServicePrincipalsImpl struct { + client *client.DatabricksClient +} + +func (a *accountServicePrincipalsImpl) CreateServicePrincipal(ctx context.Context, request ServicePrincipal) (*ServicePrincipal, error) { + var servicePrincipal ServicePrincipal + path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/ServicePrincipals", a.client.Config.AccountID) + err := a.client.Post(ctx, path, request, &servicePrincipal) + return &servicePrincipal, err +} + +func (a *accountServicePrincipalsImpl) DeleteServicePrincipal(ctx context.Context, request DeleteServicePrincipalRequest) error { + path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/ServicePrincipals/%v", a.client.Config.AccountID, request.Id) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *accountServicePrincipalsImpl) GetServicePrincipal(ctx context.Context, request GetServicePrincipalRequest) (*ServicePrincipal, error) { + var servicePrincipal ServicePrincipal + path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/ServicePrincipals/%v", a.client.Config.AccountID, request.Id) + err := a.client.Get(ctx, path, request, &servicePrincipal) + return &servicePrincipal, err +} + +func (a *accountServicePrincipalsImpl) ListServicePrincipals(ctx context.Context, request ListServicePrincipalsRequest) (*ListServicePrincipalResponse, error) { + var listServicePrincipalResponse ListServicePrincipalResponse + path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/ServicePrincipals", a.client.Config.AccountID) + err := a.client.Get(ctx, path, request, &listServicePrincipalResponse) + return &listServicePrincipalResponse, err +} + +func (a *accountServicePrincipalsImpl) PatchServicePrincipal(ctx context.Context, request PartialUpdate) error { + path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/ServicePrincipals/%v", a.client.Config.AccountID, request.Id) + err := a.client.Patch(ctx, path, request) + return err +} + +func (a *accountServicePrincipalsImpl) UpdateServicePrincipal(ctx context.Context, request ServicePrincipal) error { + path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/ServicePrincipals/%v", a.client.Config.AccountID, request.Id) + err := a.client.Put(ctx, path, request) + return err +} + +// unexported type that holds implementations of just AccountUsers API methods +type accountUsersImpl struct { + client *client.DatabricksClient +} + +func (a *accountUsersImpl) CreateUser(ctx context.Context, request User) (*User, error) { + var user User + path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Users", a.client.Config.AccountID) + err := a.client.Post(ctx, path, request, &user) + return &user, err +} + +func (a *accountUsersImpl) DeleteUser(ctx context.Context, request DeleteUserRequest) error { + path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Users/%v", a.client.Config.AccountID, request.Id) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *accountUsersImpl) GetUser(ctx context.Context, request GetUserRequest) (*User, error) { + var user User + path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Users/%v", a.client.Config.AccountID, request.Id) + err := a.client.Get(ctx, path, request, &user) + return &user, err +} + +func (a *accountUsersImpl) ListUsers(ctx context.Context, request ListUsersRequest) (*ListUsersResponse, error) { + var listUsersResponse ListUsersResponse + path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Users", a.client.Config.AccountID) + err := a.client.Get(ctx, path, request, &listUsersResponse) + return &listUsersResponse, err +} + +func (a *accountUsersImpl) PatchUser(ctx context.Context, request PartialUpdate) error { + path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Users/%v", a.client.Config.AccountID, request.Id) + err := a.client.Patch(ctx, path, request) + return err +} + +func (a *accountUsersImpl) UpdateUser(ctx context.Context, request User) error { + path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Users/%v", a.client.Config.AccountID, request.Id) + err := a.client.Put(ctx, path, request) + return err +} + +// unexported type that holds implementations of just CurrentUser API methods +type currentUserImpl struct { + client *client.DatabricksClient +} + +func (a *currentUserImpl) Me(ctx context.Context) (*User, error) { + var user User + path := "/api/2.0/preview/scim/v2/Me" + err := a.client.Get(ctx, path, nil, &user) + return &user, err +} + +// unexported type that holds implementations of just Groups API methods +type groupsImpl struct { + client *client.DatabricksClient +} + +func (a *groupsImpl) CreateGroup(ctx context.Context, request Group) (*Group, error) { + var group Group + path := "/api/2.0/preview/scim/v2/Groups" + err := a.client.Post(ctx, path, request, &group) + return &group, err +} + +func (a *groupsImpl) DeleteGroup(ctx context.Context, request DeleteGroupRequest) error { + path := fmt.Sprintf("/api/2.0/preview/scim/v2/Groups/%v", request.Id) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *groupsImpl) GetGroup(ctx context.Context, request GetGroupRequest) (*Group, error) { + var group Group + path := fmt.Sprintf("/api/2.0/preview/scim/v2/Groups/%v", request.Id) + err := a.client.Get(ctx, path, request, &group) + return &group, err +} + +func (a *groupsImpl) ListGroups(ctx context.Context, request ListGroupsRequest) (*ListGroupsResponse, error) { + var listGroupsResponse ListGroupsResponse + path := "/api/2.0/preview/scim/v2/Groups" + err := a.client.Get(ctx, path, request, &listGroupsResponse) + return &listGroupsResponse, err +} + +func (a *groupsImpl) PatchGroup(ctx context.Context, request PartialUpdate) error { + path := fmt.Sprintf("/api/2.0/preview/scim/v2/Groups/%v", request.Id) + err := a.client.Patch(ctx, path, request) + return err +} + +func (a *groupsImpl) UpdateGroup(ctx context.Context, request Group) error { + path := fmt.Sprintf("/api/2.0/preview/scim/v2/Groups/%v", request.Id) + err := a.client.Put(ctx, path, request) + return err +} + +// unexported type that holds implementations of just ServicePrincipals API methods +type servicePrincipalsImpl struct { + client *client.DatabricksClient +} + +func (a *servicePrincipalsImpl) CreateServicePrincipal(ctx context.Context, request ServicePrincipal) (*ServicePrincipal, error) { + var servicePrincipal ServicePrincipal + path := "/api/2.0/preview/scim/v2/ServicePrincipals" + err := a.client.Post(ctx, path, request, &servicePrincipal) + return &servicePrincipal, err +} + +func (a *servicePrincipalsImpl) DeleteServicePrincipal(ctx context.Context, request DeleteServicePrincipalRequest) error { + path := fmt.Sprintf("/api/2.0/preview/scim/v2/ServicePrincipals/%v", request.Id) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *servicePrincipalsImpl) GetServicePrincipal(ctx context.Context, request GetServicePrincipalRequest) (*ServicePrincipal, error) { + var servicePrincipal ServicePrincipal + path := fmt.Sprintf("/api/2.0/preview/scim/v2/ServicePrincipals/%v", request.Id) + err := a.client.Get(ctx, path, request, &servicePrincipal) + return &servicePrincipal, err +} + +func (a *servicePrincipalsImpl) ListServicePrincipals(ctx context.Context, request ListServicePrincipalsRequest) (*ListServicePrincipalResponse, error) { + var listServicePrincipalResponse ListServicePrincipalResponse + path := "/api/2.0/preview/scim/v2/ServicePrincipals" + err := a.client.Get(ctx, path, request, &listServicePrincipalResponse) + return &listServicePrincipalResponse, err +} + +func (a *servicePrincipalsImpl) PatchServicePrincipal(ctx context.Context, request PartialUpdate) error { + path := fmt.Sprintf("/api/2.0/preview/scim/v2/ServicePrincipals/%v", request.Id) + err := a.client.Patch(ctx, path, request) + return err +} + +func (a *servicePrincipalsImpl) UpdateServicePrincipal(ctx context.Context, request ServicePrincipal) error { + path := fmt.Sprintf("/api/2.0/preview/scim/v2/ServicePrincipals/%v", request.Id) + err := a.client.Put(ctx, path, request) + return err +} + +// unexported type that holds implementations of just Users API methods +type usersImpl struct { + client *client.DatabricksClient +} + +func (a *usersImpl) CreateUser(ctx context.Context, request User) (*User, error) { + var user User + path := "/api/2.0/preview/scim/v2/Users" + err := a.client.Post(ctx, path, request, &user) + return &user, err +} + +func (a *usersImpl) DeleteUser(ctx context.Context, request DeleteUserRequest) error { + path := fmt.Sprintf("/api/2.0/preview/scim/v2/Users/%v", request.Id) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *usersImpl) GetUser(ctx context.Context, request GetUserRequest) (*User, error) { + var user User + path := fmt.Sprintf("/api/2.0/preview/scim/v2/Users/%v", request.Id) + err := a.client.Get(ctx, path, request, &user) + return &user, err +} + +func (a *usersImpl) ListUsers(ctx context.Context, request ListUsersRequest) (*ListUsersResponse, error) { + var listUsersResponse ListUsersResponse + path := "/api/2.0/preview/scim/v2/Users" + err := a.client.Get(ctx, path, request, &listUsersResponse) + return &listUsersResponse, err +} + +func (a *usersImpl) PatchUser(ctx context.Context, request PartialUpdate) error { + path := fmt.Sprintf("/api/2.0/preview/scim/v2/Users/%v", request.Id) + err := a.client.Patch(ctx, path, request) + return err +} + +func (a *usersImpl) UpdateUser(ctx context.Context, request User) error { + path := fmt.Sprintf("/api/2.0/preview/scim/v2/Users/%v", request.Id) + err := a.client.Put(ctx, path, request) + return err +} diff --git a/service/scim/interface.go b/service/scim/interface.go index 355b1031e..3515f143c 100755 --- a/service/scim/interface.go +++ b/service/scim/interface.go @@ -13,10 +13,6 @@ import ( // policies in Unity Catalog to groups, instead of to users individually. All // Databricks Account identities can be assigned as members of groups, and // members inherit permissions that are assigned to their group. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type AccountGroupsService interface { // Create a new group @@ -30,23 +26,11 @@ type AccountGroupsService interface { // Deletes a group from the Databricks Account. DeleteGroup(ctx context.Context, request DeleteGroupRequest) error - // DeleteGroupById calls DeleteGroup, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteGroupById(ctx context.Context, id string) error - // Get group details // // Gets the information for a specific group in the Databricks Account. GetGroup(ctx context.Context, request GetGroupRequest) (*Group, error) - // GetGroupById calls GetGroup, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetGroupById(ctx context.Context, id string) (*Group, error) - // List group details // // Gets all details of the groups associated with the Databricks Account. @@ -54,11 +38,6 @@ type AccountGroupsService interface { // Use ListGroupsAll() to get all Group instances ListGroups(ctx context.Context, request ListGroupsRequest) (*ListGroupsResponse, error) - // ListGroupsAll calls ListGroups() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListGroupsAll(ctx context.Context, request ListGroupsRequest) ([]Group, error) - // Update group details // // Partially updates the details of a group. @@ -76,10 +55,6 @@ type AccountGroupsService interface { // on production data run with service principals, interactive users do not need // any write, delete, or modify privileges in production. This eliminates the // risk of a user overwriting production data by accident. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type AccountServicePrincipalsService interface { // Create a service principal @@ -92,24 +67,12 @@ type AccountServicePrincipalsService interface { // Delete a single service principal in the Databricks Account. DeleteServicePrincipal(ctx context.Context, request DeleteServicePrincipalRequest) error - // DeleteServicePrincipalById calls DeleteServicePrincipal, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteServicePrincipalById(ctx context.Context, id string) error - // Get service principal details // // Gets the details for a single service principal define in the Databricks // Account. GetServicePrincipal(ctx context.Context, request GetServicePrincipalRequest) (*ServicePrincipal, error) - // GetServicePrincipalById calls GetServicePrincipal, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetServicePrincipalById(ctx context.Context, id string) (*ServicePrincipal, error) - // List service principals // // Gets the set of service principals associated with a Databricks Account. @@ -117,11 +80,6 @@ type AccountServicePrincipalsService interface { // Use ListServicePrincipalsAll() to get all ServicePrincipal instances ListServicePrincipals(ctx context.Context, request ListServicePrincipalsRequest) (*ListServicePrincipalResponse, error) - // ListServicePrincipalsAll calls ListServicePrincipals() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListServicePrincipalsAll(ctx context.Context, request ListServicePrincipalsRequest) ([]ServicePrincipal, error) - // Update service principal details // // Partially updates the details of a single service principal in the @@ -147,10 +105,6 @@ type AccountServicePrincipalsService interface { // provider and that user’s account will also be removed from Databricks // Account. This ensures a consistent offboarding process and prevents // unauthorized users from accessing sensitive data. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type AccountUsersService interface { // Create a new user @@ -165,23 +119,11 @@ type AccountUsersService interface { // objects associated with the user. DeleteUser(ctx context.Context, request DeleteUserRequest) error - // DeleteUserById calls DeleteUser, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteUserById(ctx context.Context, id string) error - // Get user details // // Gets information for a specific user in Databricks Account. GetUser(ctx context.Context, request GetUserRequest) (*User, error) - // GetUserById calls GetUser, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetUserById(ctx context.Context, id string) (*User, error) - // List users // // Gets details for all the users associated with a Databricks Account. @@ -189,11 +131,6 @@ type AccountUsersService interface { // Use ListUsersAll() to get all User instances ListUsers(ctx context.Context, request ListUsersRequest) (*ListUsersResponse, error) - // ListUsersAll calls ListUsers() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListUsersAll(ctx context.Context, request ListUsersRequest) ([]User, error) - // Update user details // // Partially updates a user resource by applying the supplied operations on @@ -208,10 +145,6 @@ type AccountUsersService interface { // This API allows retrieving information about currently authenticated user or // service principal. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type CurrentUserService interface { // Get current user info @@ -227,10 +160,6 @@ type CurrentUserService interface { // policies in Unity Catalog to groups, instead of to users individually. All // Databricks Workspace identities can be assigned as members of groups, and // members inherit permissions that are assigned to their group. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type GroupsService interface { // Create a new group @@ -244,23 +173,11 @@ type GroupsService interface { // Deletes a group from the Databricks Workspace. DeleteGroup(ctx context.Context, request DeleteGroupRequest) error - // DeleteGroupById calls DeleteGroup, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteGroupById(ctx context.Context, id string) error - // Get group details // // Gets the information for a specific group in the Databricks Workspace. GetGroup(ctx context.Context, request GetGroupRequest) (*Group, error) - // GetGroupById calls GetGroup, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetGroupById(ctx context.Context, id string) (*Group, error) - // List group details // // Gets all details of the groups associated with the Databricks Workspace. @@ -268,11 +185,6 @@ type GroupsService interface { // Use ListGroupsAll() to get all Group instances ListGroups(ctx context.Context, request ListGroupsRequest) (*ListGroupsResponse, error) - // ListGroupsAll calls ListGroups() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListGroupsAll(ctx context.Context, request ListGroupsRequest) ([]Group, error) - // Update group details // // Partially updates the details of a group. @@ -290,10 +202,6 @@ type GroupsService interface { // on production data run with service principals, interactive users do not need // any write, delete, or modify privileges in production. This eliminates the // risk of a user overwriting production data by accident. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type ServicePrincipalsService interface { // Create a service principal @@ -306,24 +214,12 @@ type ServicePrincipalsService interface { // Delete a single service principal in the Databricks Workspace. DeleteServicePrincipal(ctx context.Context, request DeleteServicePrincipalRequest) error - // DeleteServicePrincipalById calls DeleteServicePrincipal, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteServicePrincipalById(ctx context.Context, id string) error - // Get service principal details // // Gets the details for a single service principal define in the Databricks // Workspace. GetServicePrincipal(ctx context.Context, request GetServicePrincipalRequest) (*ServicePrincipal, error) - // GetServicePrincipalById calls GetServicePrincipal, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetServicePrincipalById(ctx context.Context, id string) (*ServicePrincipal, error) - // List service principals // // Gets the set of service principals associated with a Databricks @@ -332,11 +228,6 @@ type ServicePrincipalsService interface { // Use ListServicePrincipalsAll() to get all ServicePrincipal instances ListServicePrincipals(ctx context.Context, request ListServicePrincipalsRequest) (*ListServicePrincipalResponse, error) - // ListServicePrincipalsAll calls ListServicePrincipals() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListServicePrincipalsAll(ctx context.Context, request ListServicePrincipalsRequest) ([]ServicePrincipal, error) - // Update service principal details // // Partially updates the details of a single service principal in the @@ -362,10 +253,6 @@ type ServicePrincipalsService interface { // identity provider and that user’s account will also be removed from // Databricks Workspace. This ensures a consistent offboarding process and // prevents unauthorized users from accessing sensitive data. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type UsersService interface { // Create a new user @@ -380,23 +267,11 @@ type UsersService interface { // objects associated with the user. DeleteUser(ctx context.Context, request DeleteUserRequest) error - // DeleteUserById calls DeleteUser, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteUserById(ctx context.Context, id string) error - // Get user details // // Gets information for a specific user in Databricks Workspace. GetUser(ctx context.Context, request GetUserRequest) (*User, error) - // GetUserById calls GetUser, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetUserById(ctx context.Context, id string) (*User, error) - // List users // // Gets details for all the users associated with a Databricks Workspace. @@ -404,11 +279,6 @@ type UsersService interface { // Use ListUsersAll() to get all User instances ListUsers(ctx context.Context, request ListUsersRequest) (*ListUsersResponse, error) - // ListUsersAll calls ListUsers() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListUsersAll(ctx context.Context, request ListUsersRequest) ([]User, error) - // Update user details // // Partially updates a user resource by applying the supplied operations on diff --git a/service/secrets/api.go b/service/secrets/api.go index d561359b0..db41f9566 100755 --- a/service/secrets/api.go +++ b/service/secrets/api.go @@ -8,14 +8,42 @@ import ( "github.com/databricks/databricks-sdk-go/databricks/client" ) -func NewSecrets(client *client.DatabricksClient) SecretsService { +func NewSecrets(client *client.DatabricksClient) *SecretsAPI { return &SecretsAPI{ - client: client, + impl: &secretsImpl{ + client: client, + }, } } +// The Secrets API allows you to manage secrets, secret scopes, and access +// permissions. +// +// Sometimes accessing data requires that you authenticate to external data +// sources through JDBC. Instead of directly entering your credentials into a +// notebook, use Databricks secrets to store your credentials and reference them +// in notebooks and jobs. +// +// Administrators, secret creators, and users granted permission can read +// Databricks secrets. While Databricks makes an effort to redact secret values +// that might be displayed in notebooks, it is not possible to prevent such +// users from reading secrets. type SecretsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(SecretsService) + impl SecretsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *SecretsAPI) WithImpl(impl SecretsService) *SecretsAPI { + a.impl = impl + return a +} + +// Impl returns low-level Secrets API implementation +func (a *SecretsAPI) Impl() SecretsService { + return a.impl } // Create a new secret scope @@ -24,9 +52,7 @@ type SecretsAPI struct { // and periods, and may not exceed 128 characters. The maximum number of scopes // in a workspace is 100. func (a *SecretsAPI) CreateScope(ctx context.Context, request CreateScope) error { - path := "/api/2.0/secrets/scopes/create" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.CreateScope(ctx, request) } // Delete an ACL @@ -38,9 +64,7 @@ func (a *SecretsAPI) CreateScope(ctx context.Context, request CreateScope) error // exists. Throws “PERMISSION_DENIED“ if the user does not have permission to // make this API call. func (a *SecretsAPI) DeleteAcl(ctx context.Context, request DeleteAcl) error { - path := "/api/2.0/secrets/acls/delete" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.DeleteAcl(ctx, request) } // Delete a secret scope @@ -51,9 +75,7 @@ func (a *SecretsAPI) DeleteAcl(ctx context.Context, request DeleteAcl) error { // “PERMISSION_DENIED“ if the user does not have permission to make this API // call. func (a *SecretsAPI) DeleteScope(ctx context.Context, request DeleteScope) error { - path := "/api/2.0/secrets/scopes/delete" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.DeleteScope(ctx, request) } // Delete a secret scope @@ -64,7 +86,7 @@ func (a *SecretsAPI) DeleteScope(ctx context.Context, request DeleteScope) error // “PERMISSION_DENIED“ if the user does not have permission to make this API // call. func (a *SecretsAPI) DeleteScopeByScope(ctx context.Context, scope string) error { - return a.DeleteScope(ctx, DeleteScope{ + return a.impl.DeleteScope(ctx, DeleteScope{ Scope: scope, }) } @@ -78,9 +100,7 @@ func (a *SecretsAPI) DeleteScopeByScope(ctx context.Context, scope string) error // Throws “PERMISSION_DENIED“ if the user does not have permission to make // this API call. func (a *SecretsAPI) DeleteSecret(ctx context.Context, request DeleteSecret) error { - path := "/api/2.0/secrets/delete" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.DeleteSecret(ctx, request) } // Get secret ACL details @@ -92,10 +112,7 @@ func (a *SecretsAPI) DeleteSecret(ctx context.Context, request DeleteSecret) err // “PERMISSION_DENIED“ if the user does not have permission to make this API // call. func (a *SecretsAPI) GetAcl(ctx context.Context, request GetAclRequest) (*AclItem, error) { - var aclItem AclItem - path := "/api/2.0/secrets/acls/get" - err := a.client.Get(ctx, path, request, &aclItem) - return &aclItem, err + return a.impl.GetAcl(ctx, request) } // Lists ACLs @@ -107,19 +124,9 @@ func (a *SecretsAPI) GetAcl(ctx context.Context, request GetAclRequest) (*AclIte // “PERMISSION_DENIED“ if the user does not have permission to make this API // call. // -// Use ListAclsAll() to get all AclItem instances -func (a *SecretsAPI) ListAcls(ctx context.Context, request ListAclsRequest) (*ListAclsResponse, error) { - var listAclsResponse ListAclsResponse - path := "/api/2.0/secrets/acls/list" - err := a.client.Get(ctx, path, request, &listAclsResponse) - return &listAclsResponse, err -} - -// ListAclsAll returns all AclItem instances. This method exists for consistency purposes. -// // This method is generated by Databricks SDK Code Generator. func (a *SecretsAPI) ListAclsAll(ctx context.Context, request ListAclsRequest) ([]AclItem, error) { - response, err := a.ListAcls(ctx, request) + response, err := a.impl.ListAcls(ctx, request) if err != nil { return nil, err } @@ -135,7 +142,7 @@ func (a *SecretsAPI) ListAclsAll(ctx context.Context, request ListAclsRequest) ( // “PERMISSION_DENIED“ if the user does not have permission to make this API // call. func (a *SecretsAPI) ListAclsByScope(ctx context.Context, scope string) (*ListAclsResponse, error) { - return a.ListAcls(ctx, ListAclsRequest{ + return a.impl.ListAcls(ctx, ListAclsRequest{ Scope: scope, }) } @@ -147,19 +154,9 @@ func (a *SecretsAPI) ListAclsByScope(ctx context.Context, scope string) (*ListAc // Throws “PERMISSION_DENIED“ if the user does not have permission to make // this API call. // -// Use ListScopesAll() to get all SecretScope instances -func (a *SecretsAPI) ListScopes(ctx context.Context) (*ListScopesResponse, error) { - var listScopesResponse ListScopesResponse - path := "/api/2.0/secrets/scopes/list" - err := a.client.Get(ctx, path, nil, &listScopesResponse) - return &listScopesResponse, err -} - -// ListScopesAll returns all SecretScope instances. This method exists for consistency purposes. -// // This method is generated by Databricks SDK Code Generator. func (a *SecretsAPI) ListScopesAll(ctx context.Context) ([]SecretScope, error) { - response, err := a.ListScopes(ctx) + response, err := a.impl.ListScopes(ctx) if err != nil { return nil, err } @@ -177,19 +174,9 @@ func (a *SecretsAPI) ListScopesAll(ctx context.Context) ([]SecretScope, error) { // “PERMISSION_DENIED“ if the user does not have permission to make this API // call. // -// Use ListSecretsAll() to get all SecretMetadata instances -func (a *SecretsAPI) ListSecrets(ctx context.Context, request ListSecretsRequest) (*ListSecretsResponse, error) { - var listSecretsResponse ListSecretsResponse - path := "/api/2.0/secrets/list" - err := a.client.Get(ctx, path, request, &listSecretsResponse) - return &listSecretsResponse, err -} - -// ListSecretsAll returns all SecretMetadata instances. This method exists for consistency purposes. -// // This method is generated by Databricks SDK Code Generator. func (a *SecretsAPI) ListSecretsAll(ctx context.Context, request ListSecretsRequest) ([]SecretMetadata, error) { - response, err := a.ListSecrets(ctx, request) + response, err := a.impl.ListSecrets(ctx, request) if err != nil { return nil, err } @@ -207,7 +194,7 @@ func (a *SecretsAPI) ListSecretsAll(ctx context.Context, request ListSecretsRequ // “PERMISSION_DENIED“ if the user does not have permission to make this API // call. func (a *SecretsAPI) ListSecretsByScope(ctx context.Context, scope string) (*ListSecretsResponse, error) { - return a.ListSecrets(ctx, ListSecretsRequest{ + return a.impl.ListSecrets(ctx, ListSecretsRequest{ Scope: scope, }) } @@ -242,9 +229,7 @@ func (a *SecretsAPI) ListSecretsByScope(ctx context.Context, scope string) (*Lis // “PERMISSION_DENIED“ if the user does not have permission to make this API // call. func (a *SecretsAPI) PutAcl(ctx context.Context, request PutAcl) error { - path := "/api/2.0/secrets/acls/put" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.PutAcl(ctx, request) } // Add a secret @@ -269,7 +254,5 @@ func (a *SecretsAPI) PutAcl(ctx context.Context, request PutAcl) error { // is invalid. Throws “PERMISSION_DENIED“ if the user does not have permission // to make this API call. func (a *SecretsAPI) PutSecret(ctx context.Context, request PutSecret) error { - path := "/api/2.0/secrets/put" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.PutSecret(ctx, request) } diff --git a/service/secrets/impl.go b/service/secrets/impl.go new file mode 100755 index 000000000..291c51cdb --- /dev/null +++ b/service/secrets/impl.go @@ -0,0 +1,78 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package secrets + +import ( + "context" + + "github.com/databricks/databricks-sdk-go/databricks/client" +) + +// unexported type that holds implementations of just Secrets API methods +type secretsImpl struct { + client *client.DatabricksClient +} + +func (a *secretsImpl) CreateScope(ctx context.Context, request CreateScope) error { + path := "/api/2.0/secrets/scopes/create" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *secretsImpl) DeleteAcl(ctx context.Context, request DeleteAcl) error { + path := "/api/2.0/secrets/acls/delete" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *secretsImpl) DeleteScope(ctx context.Context, request DeleteScope) error { + path := "/api/2.0/secrets/scopes/delete" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *secretsImpl) DeleteSecret(ctx context.Context, request DeleteSecret) error { + path := "/api/2.0/secrets/delete" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *secretsImpl) GetAcl(ctx context.Context, request GetAclRequest) (*AclItem, error) { + var aclItem AclItem + path := "/api/2.0/secrets/acls/get" + err := a.client.Get(ctx, path, request, &aclItem) + return &aclItem, err +} + +func (a *secretsImpl) ListAcls(ctx context.Context, request ListAclsRequest) (*ListAclsResponse, error) { + var listAclsResponse ListAclsResponse + path := "/api/2.0/secrets/acls/list" + err := a.client.Get(ctx, path, request, &listAclsResponse) + return &listAclsResponse, err +} + +func (a *secretsImpl) ListScopes(ctx context.Context) (*ListScopesResponse, error) { + var listScopesResponse ListScopesResponse + path := "/api/2.0/secrets/scopes/list" + err := a.client.Get(ctx, path, nil, &listScopesResponse) + return &listScopesResponse, err +} + +func (a *secretsImpl) ListSecrets(ctx context.Context, request ListSecretsRequest) (*ListSecretsResponse, error) { + var listSecretsResponse ListSecretsResponse + path := "/api/2.0/secrets/list" + err := a.client.Get(ctx, path, request, &listSecretsResponse) + return &listSecretsResponse, err +} + +func (a *secretsImpl) PutAcl(ctx context.Context, request PutAcl) error { + path := "/api/2.0/secrets/acls/put" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *secretsImpl) PutSecret(ctx context.Context, request PutSecret) error { + path := "/api/2.0/secrets/put" + err := a.client.Post(ctx, path, request, nil) + return err +} diff --git a/service/secrets/interface.go b/service/secrets/interface.go index 59ce8f4b8..44713f0fe 100755 --- a/service/secrets/interface.go +++ b/service/secrets/interface.go @@ -18,10 +18,6 @@ import ( // Databricks secrets. While Databricks makes an effort to redact secret values // that might be displayed in notebooks, it is not possible to prevent such // users from reading secrets. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type SecretsService interface { // Create a new secret scope @@ -50,12 +46,6 @@ type SecretsService interface { // API call. DeleteScope(ctx context.Context, request DeleteScope) error - // DeleteScopeByScope calls DeleteScope, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteScopeByScope(ctx context.Context, scope string) error - // Delete a secret // // Deletes the secret stored in this secret scope. You must have ``WRITE`` @@ -88,16 +78,6 @@ type SecretsService interface { // Use ListAclsAll() to get all AclItem instances ListAcls(ctx context.Context, request ListAclsRequest) (*ListAclsResponse, error) - // ListAclsByScope calls ListAcls, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - ListAclsByScope(ctx context.Context, scope string) (*ListAclsResponse, error) - // ListAclsAll calls ListAcls() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListAclsAll(ctx context.Context, request ListAclsRequest) ([]AclItem, error) - // List all scopes // // Lists all secret scopes available in the workspace. @@ -108,11 +88,6 @@ type SecretsService interface { // Use ListScopesAll() to get all SecretScope instances ListScopes(ctx context.Context) (*ListScopesResponse, error) - // ListScopesAll calls ListScopes() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListScopesAll(ctx context.Context) ([]SecretScope, error) - // List secret keys // // Lists the secret keys that are stored at this scope. This is a @@ -127,16 +102,6 @@ type SecretsService interface { // Use ListSecretsAll() to get all SecretMetadata instances ListSecrets(ctx context.Context, request ListSecretsRequest) (*ListSecretsResponse, error) - // ListSecretsByScope calls ListSecrets, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - ListSecretsByScope(ctx context.Context, scope string) (*ListSecretsResponse, error) - // ListSecretsAll calls ListSecrets() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListSecretsAll(ctx context.Context, request ListSecretsRequest) ([]SecretMetadata, error) - // Create/update an ACL // // Creates or overwrites the Access Control List (ACL) associated with the diff --git a/service/tokenmanagement/api.go b/service/tokenmanagement/api.go index 01ae9a0e9..21acbdca3 100755 --- a/service/tokenmanagement/api.go +++ b/service/tokenmanagement/api.go @@ -4,45 +4,58 @@ package tokenmanagement import ( "context" - "fmt" "github.com/databricks/databricks-sdk-go/databricks/client" ) -func NewTokenManagement(client *client.DatabricksClient) TokenManagementService { +func NewTokenManagement(client *client.DatabricksClient) *TokenManagementAPI { return &TokenManagementAPI{ - client: client, + impl: &tokenManagementImpl{ + client: client, + }, } } +// Enables administrators to get all tokens and delete tokens for other users. +// Admins can either get every token, get a specific token by ID, or get all +// tokens for a particular user. type TokenManagementAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(TokenManagementService) + impl TokenManagementService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *TokenManagementAPI) WithImpl(impl TokenManagementService) *TokenManagementAPI { + a.impl = impl + return a +} + +// Impl returns low-level TokenManagement API implementation +func (a *TokenManagementAPI) Impl() TokenManagementService { + return a.impl } // Create on-behalf token // // Creates a token on behalf of a service principal. func (a *TokenManagementAPI) CreateOboToken(ctx context.Context, request CreateOboTokenRequest) (*CreateOboTokenResponse, error) { - var createOboTokenResponse CreateOboTokenResponse - path := "/api/2.0/token-management/on-behalf-of/tokens" - err := a.client.Post(ctx, path, request, &createOboTokenResponse) - return &createOboTokenResponse, err + return a.impl.CreateOboToken(ctx, request) } // Delete a token // // Deletes a token, specified by its ID. func (a *TokenManagementAPI) DeleteToken(ctx context.Context, request DeleteTokenRequest) error { - path := fmt.Sprintf("/api/2.0/token-management/tokens/%v", request.TokenId) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteToken(ctx, request) } // Delete a token // // Deletes a token, specified by its ID. func (a *TokenManagementAPI) DeleteTokenByTokenId(ctx context.Context, tokenId string) error { - return a.DeleteToken(ctx, DeleteTokenRequest{ + return a.impl.DeleteToken(ctx, DeleteTokenRequest{ TokenId: tokenId, }) } @@ -51,17 +64,14 @@ func (a *TokenManagementAPI) DeleteTokenByTokenId(ctx context.Context, tokenId s // // Gets information about a token, specified by its ID. func (a *TokenManagementAPI) GetTokenInfo(ctx context.Context, request GetTokenInfoRequest) (*TokenInfo, error) { - var tokenInfo TokenInfo - path := fmt.Sprintf("/api/2.0/token-management/tokens/%v", request.TokenId) - err := a.client.Get(ctx, path, request, &tokenInfo) - return &tokenInfo, err + return a.impl.GetTokenInfo(ctx, request) } // Get token info // // Gets information about a token, specified by its ID. func (a *TokenManagementAPI) GetTokenInfoByTokenId(ctx context.Context, tokenId string) (*TokenInfo, error) { - return a.GetTokenInfo(ctx, GetTokenInfoRequest{ + return a.impl.GetTokenInfo(ctx, GetTokenInfoRequest{ TokenId: tokenId, }) } @@ -70,19 +80,9 @@ func (a *TokenManagementAPI) GetTokenInfoByTokenId(ctx context.Context, tokenId // // Lists all tokens associated with the specified workspace or user. // -// Use ListTokensAll() to get all TokenInfo instances -func (a *TokenManagementAPI) ListTokens(ctx context.Context, request ListTokensRequest) (*ListTokensResponse, error) { - var listTokensResponse ListTokensResponse - path := "/api/2.0/token-management/tokens" - err := a.client.Get(ctx, path, request, &listTokensResponse) - return &listTokensResponse, err -} - -// ListTokensAll returns all TokenInfo instances. This method exists for consistency purposes. -// // This method is generated by Databricks SDK Code Generator. func (a *TokenManagementAPI) ListTokensAll(ctx context.Context, request ListTokensRequest) ([]TokenInfo, error) { - response, err := a.ListTokens(ctx, request) + response, err := a.impl.ListTokens(ctx, request) if err != nil { return nil, err } diff --git a/service/tokenmanagement/impl.go b/service/tokenmanagement/impl.go new file mode 100755 index 000000000..03dcf57f5 --- /dev/null +++ b/service/tokenmanagement/impl.go @@ -0,0 +1,42 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package tokenmanagement + +import ( + "context" + "fmt" + + "github.com/databricks/databricks-sdk-go/databricks/client" +) + +// unexported type that holds implementations of just TokenManagement API methods +type tokenManagementImpl struct { + client *client.DatabricksClient +} + +func (a *tokenManagementImpl) CreateOboToken(ctx context.Context, request CreateOboTokenRequest) (*CreateOboTokenResponse, error) { + var createOboTokenResponse CreateOboTokenResponse + path := "/api/2.0/token-management/on-behalf-of/tokens" + err := a.client.Post(ctx, path, request, &createOboTokenResponse) + return &createOboTokenResponse, err +} + +func (a *tokenManagementImpl) DeleteToken(ctx context.Context, request DeleteTokenRequest) error { + path := fmt.Sprintf("/api/2.0/token-management/tokens/%v", request.TokenId) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *tokenManagementImpl) GetTokenInfo(ctx context.Context, request GetTokenInfoRequest) (*TokenInfo, error) { + var tokenInfo TokenInfo + path := fmt.Sprintf("/api/2.0/token-management/tokens/%v", request.TokenId) + err := a.client.Get(ctx, path, request, &tokenInfo) + return &tokenInfo, err +} + +func (a *tokenManagementImpl) ListTokens(ctx context.Context, request ListTokensRequest) (*ListTokensResponse, error) { + var listTokensResponse ListTokensResponse + path := "/api/2.0/token-management/tokens" + err := a.client.Get(ctx, path, request, &listTokensResponse) + return &listTokensResponse, err +} diff --git a/service/tokenmanagement/interface.go b/service/tokenmanagement/interface.go index c5e6363e0..e50a38836 100755 --- a/service/tokenmanagement/interface.go +++ b/service/tokenmanagement/interface.go @@ -9,10 +9,6 @@ import ( // Enables administrators to get all tokens and delete tokens for other users. // Admins can either get every token, get a specific token by ID, or get all // tokens for a particular user. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type TokenManagementService interface { // Create on-behalf token @@ -25,32 +21,15 @@ type TokenManagementService interface { // Deletes a token, specified by its ID. DeleteToken(ctx context.Context, request DeleteTokenRequest) error - // DeleteTokenByTokenId calls DeleteToken, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteTokenByTokenId(ctx context.Context, tokenId string) error - // Get token info // // Gets information about a token, specified by its ID. GetTokenInfo(ctx context.Context, request GetTokenInfoRequest) (*TokenInfo, error) - // GetTokenInfoByTokenId calls GetTokenInfo, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetTokenInfoByTokenId(ctx context.Context, tokenId string) (*TokenInfo, error) - // List all tokens // // Lists all tokens associated with the specified workspace or user. // // Use ListTokensAll() to get all TokenInfo instances ListTokens(ctx context.Context, request ListTokensRequest) (*ListTokensResponse, error) - - // ListTokensAll calls ListTokens() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListTokensAll(ctx context.Context, request ListTokensRequest) ([]TokenInfo, error) } diff --git a/service/tokens/api.go b/service/tokens/api.go index 6eb8db11e..b4f30315c 100755 --- a/service/tokens/api.go +++ b/service/tokens/api.go @@ -8,14 +8,32 @@ import ( "github.com/databricks/databricks-sdk-go/databricks/client" ) -func NewTokens(client *client.DatabricksClient) TokensService { +func NewTokens(client *client.DatabricksClient) *TokensAPI { return &TokensAPI{ - client: client, + impl: &tokensImpl{ + client: client, + }, } } +// The Token API allows you to create, list, and revoke tokens that can be used +// to authenticate and access Databricks REST APIs. type TokensAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(TokensService) + impl TokensService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *TokensAPI) WithImpl(impl TokensService) *TokensAPI { + a.impl = impl + return a +} + +// Impl returns low-level Tokens API implementation +func (a *TokensAPI) Impl() TokensService { + return a.impl } // Create a user token @@ -26,10 +44,7 @@ type TokensAPI struct { // the same client ID as the authenticated token. If the user's token quota is // exceeded, this call returns an error **QUOTA_EXCEEDED**. func (a *TokensAPI) Create(ctx context.Context, request CreateTokenRequest) (*CreateTokenResponse, error) { - var createTokenResponse CreateTokenResponse - path := "/api/2.0/token/create" - err := a.client.Post(ctx, path, request, &createTokenResponse) - return &createTokenResponse, err + return a.impl.Create(ctx, request) } // Revoke token @@ -39,9 +54,7 @@ func (a *TokensAPI) Create(ctx context.Context, request CreateTokenRequest) (*Cr // If a token with the specified ID is not valid, this call returns an error // **RESOURCE_DOES_NOT_EXIST**. func (a *TokensAPI) Delete(ctx context.Context, request RevokeTokenRequest) error { - path := "/api/2.0/token/delete" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.Delete(ctx, request) } // Revoke token @@ -51,7 +64,7 @@ func (a *TokensAPI) Delete(ctx context.Context, request RevokeTokenRequest) erro // If a token with the specified ID is not valid, this call returns an error // **RESOURCE_DOES_NOT_EXIST**. func (a *TokensAPI) DeleteByTokenId(ctx context.Context, tokenId string) error { - return a.Delete(ctx, RevokeTokenRequest{ + return a.impl.Delete(ctx, RevokeTokenRequest{ TokenId: tokenId, }) } @@ -60,8 +73,5 @@ func (a *TokensAPI) DeleteByTokenId(ctx context.Context, tokenId string) error { // // Lists all the valid tokens for a user-workspace pair. func (a *TokensAPI) List(ctx context.Context) (*ListTokensResponse, error) { - var listTokensResponse ListTokensResponse - path := "/api/2.0/token/list" - err := a.client.Get(ctx, path, nil, &listTokensResponse) - return &listTokensResponse, err + return a.impl.List(ctx) } diff --git a/service/tokens/impl.go b/service/tokens/impl.go new file mode 100755 index 000000000..85ba8fe9b --- /dev/null +++ b/service/tokens/impl.go @@ -0,0 +1,34 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package tokens + +import ( + "context" + + "github.com/databricks/databricks-sdk-go/databricks/client" +) + +// unexported type that holds implementations of just Tokens API methods +type tokensImpl struct { + client *client.DatabricksClient +} + +func (a *tokensImpl) Create(ctx context.Context, request CreateTokenRequest) (*CreateTokenResponse, error) { + var createTokenResponse CreateTokenResponse + path := "/api/2.0/token/create" + err := a.client.Post(ctx, path, request, &createTokenResponse) + return &createTokenResponse, err +} + +func (a *tokensImpl) Delete(ctx context.Context, request RevokeTokenRequest) error { + path := "/api/2.0/token/delete" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *tokensImpl) List(ctx context.Context) (*ListTokensResponse, error) { + var listTokensResponse ListTokensResponse + path := "/api/2.0/token/list" + err := a.client.Get(ctx, path, nil, &listTokensResponse) + return &listTokensResponse, err +} diff --git a/service/tokens/interface.go b/service/tokens/interface.go index 938f32d50..f8c3b507b 100755 --- a/service/tokens/interface.go +++ b/service/tokens/interface.go @@ -8,10 +8,6 @@ import ( // The Token API allows you to create, list, and revoke tokens that can be used // to authenticate and access Databricks REST APIs. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type TokensService interface { // Create a user token @@ -31,12 +27,6 @@ type TokensService interface { // **RESOURCE_DOES_NOT_EXIST**. Delete(ctx context.Context, request RevokeTokenRequest) error - // DeleteByTokenId calls Delete, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteByTokenId(ctx context.Context, tokenId string) error - // List tokens // // Lists all the valid tokens for a user-workspace pair. diff --git a/service/unitycatalog/api.go b/service/unitycatalog/api.go index 8b5766853..19b8f2110 100755 --- a/service/unitycatalog/api.go +++ b/service/unitycatalog/api.go @@ -4,19 +4,42 @@ package unitycatalog import ( "context" - "fmt" "github.com/databricks/databricks-sdk-go/databricks/client" ) -func NewCatalogs(client *client.DatabricksClient) CatalogsService { +func NewCatalogs(client *client.DatabricksClient) *CatalogsAPI { return &CatalogsAPI{ - client: client, + impl: &catalogsImpl{ + client: client, + }, } } +// A catalog is the first layer of Unity Catalog’s three-level namespace. +// It’s used to organize your data assets. Users can see all catalogs on which +// they have been assigned the USAGE data permission. +// +// In Unity Catalog, admins and data stewards manage users and their access to +// data centrally across all of the workspaces in a Databricks account. Users in +// different workspaces can share access to the same data, depending on +// privileges granted centrally in Unity Catalog. type CatalogsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(CatalogsService) + impl CatalogsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *CatalogsAPI) WithImpl(impl CatalogsService) *CatalogsAPI { + a.impl = impl + return a +} + +// Impl returns low-level Catalogs API implementation +func (a *CatalogsAPI) Impl() CatalogsService { + return a.impl } // Create a catalog @@ -24,10 +47,7 @@ type CatalogsAPI struct { // Creates a new catalog instance in the parent Metastore if the caller is a // Metastore admin or has the CREATE CATALOG privilege. func (a *CatalogsAPI) Create(ctx context.Context, request CreateCatalog) (*CreateCatalogResponse, error) { - var createCatalogResponse CreateCatalogResponse - path := "/api/2.1/unity-catalog/catalogs" - err := a.client.Post(ctx, path, request, &createCatalogResponse) - return &createCatalogResponse, err + return a.impl.Create(ctx, request) } // Delete a catalog @@ -35,9 +55,7 @@ func (a *CatalogsAPI) Create(ctx context.Context, request CreateCatalog) (*Creat // Deletes the catalog that matches the supplied name. The caller must be a // Metastore admin or the owner of the catalog. func (a *CatalogsAPI) DeleteCatalog(ctx context.Context, request DeleteCatalogRequest) error { - path := fmt.Sprintf("/api/2.1/unity-catalog/catalogs/%v", request.Name) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteCatalog(ctx, request) } // Delete a catalog @@ -45,7 +63,7 @@ func (a *CatalogsAPI) DeleteCatalog(ctx context.Context, request DeleteCatalogRe // Deletes the catalog that matches the supplied name. The caller must be a // Metastore admin or the owner of the catalog. func (a *CatalogsAPI) DeleteCatalogByName(ctx context.Context, name string) error { - return a.DeleteCatalog(ctx, DeleteCatalogRequest{ + return a.impl.DeleteCatalog(ctx, DeleteCatalogRequest{ Name: name, }) } @@ -55,10 +73,7 @@ func (a *CatalogsAPI) DeleteCatalogByName(ctx context.Context, name string) erro // Gets an array of all catalogs in the current Metastore for which the user is // an admin or Catalog owner, or has the USAGE privilege set for their account. func (a *CatalogsAPI) GetCatalog(ctx context.Context, request GetCatalogRequest) (*GetCatalogResponse, error) { - var getCatalogResponse GetCatalogResponse - path := fmt.Sprintf("/api/2.1/unity-catalog/catalogs/%v", request.Name) - err := a.client.Get(ctx, path, request, &getCatalogResponse) - return &getCatalogResponse, err + return a.impl.GetCatalog(ctx, request) } // Get a catalog @@ -66,7 +81,7 @@ func (a *CatalogsAPI) GetCatalog(ctx context.Context, request GetCatalogRequest) // Gets an array of all catalogs in the current Metastore for which the user is // an admin or Catalog owner, or has the USAGE privilege set for their account. func (a *CatalogsAPI) GetCatalogByName(ctx context.Context, name string) (*GetCatalogResponse, error) { - return a.GetCatalog(ctx, GetCatalogRequest{ + return a.impl.GetCatalog(ctx, GetCatalogRequest{ Name: name, }) } @@ -77,19 +92,9 @@ func (a *CatalogsAPI) GetCatalogByName(ctx context.Context, name string) (*GetCa // Metastore. The caller must be a Metastore admin, is the owner of the External // Location, or has privileges to access the External Location. // -// Use ListCatalogsAll() to get all CatalogInfo instances -func (a *CatalogsAPI) ListCatalogs(ctx context.Context) (*ListCatalogsResponse, error) { - var listCatalogsResponse ListCatalogsResponse - path := "/api/2.1/unity-catalog/catalogs" - err := a.client.Get(ctx, path, nil, &listCatalogsResponse) - return &listCatalogsResponse, err -} - -// ListCatalogsAll returns all CatalogInfo instances. This method exists for consistency purposes. -// // This method is generated by Databricks SDK Code Generator. func (a *CatalogsAPI) ListCatalogsAll(ctx context.Context) ([]CatalogInfo, error) { - response, err := a.ListCatalogs(ctx) + response, err := a.impl.ListCatalogs(ctx) if err != nil { return nil, err } @@ -102,19 +107,46 @@ func (a *CatalogsAPI) ListCatalogsAll(ctx context.Context) ([]CatalogInfo, error // the owner of the catalog, or a Metastore admin (when changing the owner field // of the catalog). func (a *CatalogsAPI) Update(ctx context.Context, request UpdateCatalog) error { - path := fmt.Sprintf("/api/2.1/unity-catalog/catalogs/%v", request.Name) - err := a.client.Patch(ctx, path, request) - return err + return a.impl.Update(ctx, request) } -func NewExternalLocations(client *client.DatabricksClient) ExternalLocationsService { +func NewExternalLocations(client *client.DatabricksClient) *ExternalLocationsAPI { return &ExternalLocationsAPI{ - client: client, + impl: &externalLocationsImpl{ + client: client, + }, } } +// An external location is an object that combines a cloud storage path with a +// storage credential that authorizes access to the cloud storage path. Each +// storage location is subject to Unity Catalog access-control policies that +// control which users and groups can access the credential. If a user does not +// have access to a storage location in Unity Catalog, the request fails and +// Unity Catalog does not attempt to authenticate to your cloud tenant on the +// user’s behalf. +// +// Databricks recommends using external locations rather than using storage +// credentials directly. +// +// To create external locations, you must be a metastore admin or a user with +// the CREATE EXTERNAL LOCATION privilege. type ExternalLocationsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(ExternalLocationsService) + impl ExternalLocationsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *ExternalLocationsAPI) WithImpl(impl ExternalLocationsService) *ExternalLocationsAPI { + a.impl = impl + return a +} + +// Impl returns low-level ExternalLocations API implementation +func (a *ExternalLocationsAPI) Impl() ExternalLocationsService { + return a.impl } // Create an external location @@ -123,10 +155,7 @@ type ExternalLocationsAPI struct { // Metastore admin or have the CREATE EXTERNAL LOCATION privilege on the // Metastore. func (a *ExternalLocationsAPI) Create(ctx context.Context, request CreateExternalLocation) (*CreateExternalLocationResponse, error) { - var createExternalLocationResponse CreateExternalLocationResponse - path := "/api/2.1/unity-catalog/external-locations" - err := a.client.Post(ctx, path, request, &createExternalLocationResponse) - return &createExternalLocationResponse, err + return a.impl.Create(ctx, request) } // Delete an external location @@ -134,9 +163,7 @@ func (a *ExternalLocationsAPI) Create(ctx context.Context, request CreateExterna // Deletes the specified external location from the Metastore. The caller must // be the owner of the external location. func (a *ExternalLocationsAPI) DeleteExternalLocation(ctx context.Context, request DeleteExternalLocationRequest) error { - path := fmt.Sprintf("/api/2.1/unity-catalog/external-locations/%v", request.Name) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteExternalLocation(ctx, request) } // Delete an external location @@ -144,7 +171,7 @@ func (a *ExternalLocationsAPI) DeleteExternalLocation(ctx context.Context, reque // Deletes the specified external location from the Metastore. The caller must // be the owner of the external location. func (a *ExternalLocationsAPI) DeleteExternalLocationByName(ctx context.Context, name string) error { - return a.DeleteExternalLocation(ctx, DeleteExternalLocationRequest{ + return a.impl.DeleteExternalLocation(ctx, DeleteExternalLocationRequest{ Name: name, }) } @@ -155,10 +182,7 @@ func (a *ExternalLocationsAPI) DeleteExternalLocationByName(ctx context.Context, // Metastore admin, the owner of the external location, or has an appropriate // privilege level on the Metastore. func (a *ExternalLocationsAPI) GetExternalLocation(ctx context.Context, request GetExternalLocationRequest) (*GetExternalLocationResponse, error) { - var getExternalLocationResponse GetExternalLocationResponse - path := fmt.Sprintf("/api/2.1/unity-catalog/external-locations/%v", request.Name) - err := a.client.Get(ctx, path, request, &getExternalLocationResponse) - return &getExternalLocationResponse, err + return a.impl.GetExternalLocation(ctx, request) } // Get an external location @@ -167,7 +191,7 @@ func (a *ExternalLocationsAPI) GetExternalLocation(ctx context.Context, request // Metastore admin, the owner of the external location, or has an appropriate // privilege level on the Metastore. func (a *ExternalLocationsAPI) GetExternalLocationByName(ctx context.Context, name string) (*GetExternalLocationResponse, error) { - return a.GetExternalLocation(ctx, GetExternalLocationRequest{ + return a.impl.GetExternalLocation(ctx, GetExternalLocationRequest{ Name: name, }) } @@ -178,19 +202,9 @@ func (a *ExternalLocationsAPI) GetExternalLocationByName(ctx context.Context, na // Metastore. The caller must be a Metastore admin, is the owner of the external // location, or has privileges to access the external location. // -// Use ListExternalLocationsAll() to get all ExternalLocationInfo instances -func (a *ExternalLocationsAPI) ListExternalLocations(ctx context.Context) (*ListExternalLocationsResponse, error) { - var listExternalLocationsResponse ListExternalLocationsResponse - path := "/api/2.1/unity-catalog/external-locations" - err := a.client.Get(ctx, path, nil, &listExternalLocationsResponse) - return &listExternalLocationsResponse, err -} - -// ListExternalLocationsAll returns all ExternalLocationInfo instances. This method exists for consistency purposes. -// // This method is generated by Databricks SDK Code Generator. func (a *ExternalLocationsAPI) ListExternalLocationsAll(ctx context.Context) ([]ExternalLocationInfo, error) { - response, err := a.ListExternalLocations(ctx) + response, err := a.impl.ListExternalLocations(ctx) if err != nil { return nil, err } @@ -203,36 +217,62 @@ func (a *ExternalLocationsAPI) ListExternalLocationsAll(ctx context.Context) ([] // of the externa location, or be a Metastore admin. In the second case, the // admin can only update the name of the external location. func (a *ExternalLocationsAPI) Update(ctx context.Context, request UpdateExternalLocation) error { - path := fmt.Sprintf("/api/2.1/unity-catalog/external-locations/%v", request.Name) - err := a.client.Patch(ctx, path, request) - return err + return a.impl.Update(ctx, request) } -func NewGrants(client *client.DatabricksClient) GrantsService { +func NewGrants(client *client.DatabricksClient) *GrantsAPI { return &GrantsAPI{ - client: client, + impl: &grantsImpl{ + client: client, + }, } } +// In Unity Catalog, data is secure by default. Initially, users have no access +// to data in a metastore. Access can be granted by either a metastore admin, +// the owner of an object, or the owner of the catalog or schema that contains +// the object. Securable objects in Unity Catalog are hierarchical and +// privileges are inherited downward. +// +// Initially, users have no access to data in a metastore. Access can be granted +// by either a metastore admin, the owner of an object, or the owner of the +// catalog or schema that contains the object. +// +// Securable objects in Unity Catalog are hierarchical and privileges are +// inherited downward. This means that granting a privilege on the catalog +// automatically grants the privilege to all current and future objects within +// the catalog. Similarly, privileges granted on a schema are inherited by all +// current and future objects within that schema. type GrantsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(GrantsService) + impl GrantsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *GrantsAPI) WithImpl(impl GrantsService) *GrantsAPI { + a.impl = impl + return a +} + +// Impl returns low-level Grants API implementation +func (a *GrantsAPI) Impl() GrantsService { + return a.impl } // Get permissions // // Gets the permissions for a Securable type. func (a *GrantsAPI) GetPermissions(ctx context.Context, request GetPermissionsRequest) (*GetPermissionsResponse, error) { - var getPermissionsResponse GetPermissionsResponse - path := fmt.Sprintf("/api/2.1/unity-catalog/permissions/%v/%v", request.SecurableType, request.FullName) - err := a.client.Get(ctx, path, request, &getPermissionsResponse) - return &getPermissionsResponse, err + return a.impl.GetPermissions(ctx, request) } // Get permissions // // Gets the permissions for a Securable type. func (a *GrantsAPI) GetPermissionsBySecurableTypeAndFullName(ctx context.Context, securableType string, fullName string) (*GetPermissionsResponse, error) { - return a.GetPermissions(ctx, GetPermissionsRequest{ + return a.impl.GetPermissions(ctx, GetPermissionsRequest{ SecurableType: securableType, FullName: fullName, }) @@ -242,29 +282,54 @@ func (a *GrantsAPI) GetPermissionsBySecurableTypeAndFullName(ctx context.Context // // Updates the permissions for a Securable type. func (a *GrantsAPI) UpdatePermissions(ctx context.Context, request UpdatePermissions) error { - path := fmt.Sprintf("/api/2.1/unity-catalog/permissions/%v/%v", request.SecurableType, request.FullName) - err := a.client.Patch(ctx, path, request) - return err + return a.impl.UpdatePermissions(ctx, request) } -func NewMetastores(client *client.DatabricksClient) MetastoresService { +func NewMetastores(client *client.DatabricksClient) *MetastoresAPI { return &MetastoresAPI{ - client: client, + impl: &metastoresImpl{ + client: client, + }, } } +// A metastore is the top-level container of objects in Unity Catalog. It stores +// data assets (tables and views) and the permissions that govern access to +// them. Databricks account admins can create metastores and assign them to +// Databricks workspaces to control which workloads use each metastore. For a +// workspace to use Unity Catalog, it must have a Unity Catalog metastore +// attached. +// +// Each metastore is configured with a root storage location in a cloud storage +// account. This storage location is used for metadata and managed tables data. +// +// NOTE: This metastore is distinct from the metastore included in Databricks +// workspaces created before Unity Catalog was released. If your workspace +// includes a legacy Hive metastore, the data in that metastore is available in +// Unity Catalog in a catalog named hive_metastore. type MetastoresAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(MetastoresService) + impl MetastoresService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *MetastoresAPI) WithImpl(impl MetastoresService) *MetastoresAPI { + a.impl = impl + return a +} + +// Impl returns low-level Metastores API implementation +func (a *MetastoresAPI) Impl() MetastoresService { + return a.impl } // Create a Metastore // // Creates a new Metastore based on a provided name and storage root path. func (a *MetastoresAPI) Create(ctx context.Context, request CreateMetastore) (*CreateMetastoreResponse, error) { - var createMetastoreResponse CreateMetastoreResponse - path := "/api/2.1/unity-catalog/metastores" - err := a.client.Post(ctx, path, request, &createMetastoreResponse) - return &createMetastoreResponse, err + return a.impl.Create(ctx, request) } // Create an assignment @@ -273,25 +338,21 @@ func (a *MetastoresAPI) Create(ctx context.Context, request CreateMetastore) (*C // __workspace_id__ exists, it will be overwritten by the new __metastore_id__ // and __default_catalog_name__. The caller must be an account admin. func (a *MetastoresAPI) CreateMetastoreAssignment(ctx context.Context, request CreateMetastoreAssignment) error { - path := fmt.Sprintf("/api/2.1/unity-catalog/workspaces/%v/metastore", request.WorkspaceId) - err := a.client.Put(ctx, path, request) - return err + return a.impl.CreateMetastoreAssignment(ctx, request) } // Delete a Metastore // // Deletes a Metastore. The caller must be a Metastore admin. func (a *MetastoresAPI) DeleteMetastore(ctx context.Context, request DeleteMetastoreRequest) error { - path := fmt.Sprintf("/api/2.1/unity-catalog/metastores/%v", request.Id) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteMetastore(ctx, request) } // Delete a Metastore // // Deletes a Metastore. The caller must be a Metastore admin. func (a *MetastoresAPI) DeleteMetastoreById(ctx context.Context, id string) error { - return a.DeleteMetastore(ctx, DeleteMetastoreRequest{ + return a.impl.DeleteMetastore(ctx, DeleteMetastoreRequest{ Id: id, }) } @@ -300,16 +361,14 @@ func (a *MetastoresAPI) DeleteMetastoreById(ctx context.Context, id string) erro // // Deletes a Metastore assignment. The caller must be an account administrator. func (a *MetastoresAPI) DeleteMetastoreAssignment(ctx context.Context, request DeleteMetastoreAssignmentRequest) error { - path := fmt.Sprintf("/api/2.1/unity-catalog/workspaces/%v/metastore", request.WorkspaceId) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteMetastoreAssignment(ctx, request) } // Delete an assignment // // Deletes a Metastore assignment. The caller must be an account administrator. func (a *MetastoresAPI) DeleteMetastoreAssignmentByWorkspaceId(ctx context.Context, workspaceId int) error { - return a.DeleteMetastoreAssignment(ctx, DeleteMetastoreAssignmentRequest{ + return a.impl.DeleteMetastoreAssignment(ctx, DeleteMetastoreAssignmentRequest{ WorkspaceId: workspaceId, }) } @@ -319,10 +378,7 @@ func (a *MetastoresAPI) DeleteMetastoreAssignmentByWorkspaceId(ctx context.Conte // Gets a Metastore that matches the supplied ID. The caller must be a Metastore // admin to retrieve this info. func (a *MetastoresAPI) GetMetastore(ctx context.Context, request GetMetastoreRequest) (*GetMetastoreResponse, error) { - var getMetastoreResponse GetMetastoreResponse - path := fmt.Sprintf("/api/2.1/unity-catalog/metastores/%v", request.Id) - err := a.client.Get(ctx, path, request, &getMetastoreResponse) - return &getMetastoreResponse, err + return a.impl.GetMetastore(ctx, request) } // Get a Metastore @@ -330,7 +386,7 @@ func (a *MetastoresAPI) GetMetastore(ctx context.Context, request GetMetastoreRe // Gets a Metastore that matches the supplied ID. The caller must be a Metastore // admin to retrieve this info. func (a *MetastoresAPI) GetMetastoreById(ctx context.Context, id string) (*GetMetastoreResponse, error) { - return a.GetMetastore(ctx, GetMetastoreRequest{ + return a.impl.GetMetastore(ctx, GetMetastoreRequest{ Id: id, }) } @@ -340,10 +396,7 @@ func (a *MetastoresAPI) GetMetastoreById(ctx context.Context, id string) (*GetMe // Gets information about a Metastore. This summary includes the storage // credential, the cloud vendor, the cloud region, and the global Metastore ID. func (a *MetastoresAPI) GetMetastoreSummary(ctx context.Context) (*GetMetastoreSummaryResponse, error) { - var getMetastoreSummaryResponse GetMetastoreSummaryResponse - path := "/api/2.1/unity-catalog/metastore_summary" - err := a.client.Get(ctx, path, nil, &getMetastoreSummaryResponse) - return &getMetastoreSummaryResponse, err + return a.impl.GetMetastoreSummary(ctx) } // List Metastores @@ -351,19 +404,9 @@ func (a *MetastoresAPI) GetMetastoreSummary(ctx context.Context) (*GetMetastoreS // Gets an array of the available Metastores (as MetastoreInfo objects). The // caller must be an admin to retrieve this info. // -// Use ListMetastoresAll() to get all MetastoreInfo instances -func (a *MetastoresAPI) ListMetastores(ctx context.Context) (*ListMetastoresResponse, error) { - var listMetastoresResponse ListMetastoresResponse - path := "/api/2.1/unity-catalog/metastores" - err := a.client.Get(ctx, path, nil, &listMetastoresResponse) - return &listMetastoresResponse, err -} - -// ListMetastoresAll returns all MetastoreInfo instances. This method exists for consistency purposes. -// // This method is generated by Databricks SDK Code Generator. func (a *MetastoresAPI) ListMetastoresAll(ctx context.Context) ([]MetastoreInfo, error) { - response, err := a.ListMetastores(ctx) + response, err := a.impl.ListMetastores(ctx) if err != nil { return nil, err } @@ -375,9 +418,7 @@ func (a *MetastoresAPI) ListMetastoresAll(ctx context.Context) ([]MetastoreInfo, // Updates information for a specific Metastore. The caller must be a Metastore // admin. func (a *MetastoresAPI) Update(ctx context.Context, request UpdateMetastore) error { - path := fmt.Sprintf("/api/2.1/unity-catalog/metastores/%v", request.Id) - err := a.client.Patch(ctx, path, request) - return err + return a.impl.Update(ctx, request) } // Update an assignment @@ -388,19 +429,34 @@ func (a *MetastoresAPI) Update(ctx context.Context, request UpdateMetastore) err // admin to update __metastore_id__; otherwise, the caller can be a Workspace // admin. func (a *MetastoresAPI) UpdateMetastoreAssignment(ctx context.Context, request UpdateMetastoreAssignment) error { - path := fmt.Sprintf("/api/2.1/unity-catalog/workspaces/%v/metastore", request.WorkspaceId) - err := a.client.Patch(ctx, path, request) - return err + return a.impl.UpdateMetastoreAssignment(ctx, request) } -func NewProviders(client *client.DatabricksClient) ProvidersService { +func NewProviders(client *client.DatabricksClient) *ProvidersAPI { return &ProvidersAPI{ - client: client, + impl: &providersImpl{ + client: client, + }, } } +// Databricks Delta Sharing: Providers REST API type ProvidersAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(ProvidersService) + impl ProvidersService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *ProvidersAPI) WithImpl(impl ProvidersService) *ProvidersAPI { + a.impl = impl + return a +} + +// Impl returns low-level Providers API implementation +func (a *ProvidersAPI) Impl() ProvidersService { + return a.impl } // Create an auth provider @@ -408,10 +464,7 @@ type ProvidersAPI struct { // Creates a new authentication provider minimally based on a name and // authentication type. The caller must be an admin on the Metastore. func (a *ProvidersAPI) Create(ctx context.Context, request CreateProvider) (*CreateProviderResponse, error) { - var createProviderResponse CreateProviderResponse - path := "/api/2.1/unity-catalog/providers" - err := a.client.Post(ctx, path, request, &createProviderResponse) - return &createProviderResponse, err + return a.impl.Create(ctx, request) } // Delete a provider @@ -419,9 +472,7 @@ func (a *ProvidersAPI) Create(ctx context.Context, request CreateProvider) (*Cre // Deletes an authentication provider, if the caller is a Metastore admin or is // the owner of the provider. func (a *ProvidersAPI) DeleteProvider(ctx context.Context, request DeleteProviderRequest) error { - path := fmt.Sprintf("/api/2.1/unity-catalog/providers/%v", request.Name) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteProvider(ctx, request) } // Delete a provider @@ -429,7 +480,7 @@ func (a *ProvidersAPI) DeleteProvider(ctx context.Context, request DeleteProvide // Deletes an authentication provider, if the caller is a Metastore admin or is // the owner of the provider. func (a *ProvidersAPI) DeleteProviderByName(ctx context.Context, name string) error { - return a.DeleteProvider(ctx, DeleteProviderRequest{ + return a.impl.DeleteProvider(ctx, DeleteProviderRequest{ Name: name, }) } @@ -440,10 +491,7 @@ func (a *ProvidersAPI) DeleteProviderByName(ctx context.Context, name string) er // the provider, and must either be a Metastore admin or the owner of the // provider. func (a *ProvidersAPI) GetProvider(ctx context.Context, request GetProviderRequest) (*GetProviderResponse, error) { - var getProviderResponse GetProviderResponse - path := fmt.Sprintf("/api/2.1/unity-catalog/providers/%v", request.Name) - err := a.client.Get(ctx, path, request, &getProviderResponse) - return &getProviderResponse, err + return a.impl.GetProvider(ctx, request) } // Get a provider @@ -452,7 +500,7 @@ func (a *ProvidersAPI) GetProvider(ctx context.Context, request GetProviderReque // the provider, and must either be a Metastore admin or the owner of the // provider. func (a *ProvidersAPI) GetProviderByName(ctx context.Context, name string) (*GetProviderResponse, error) { - return a.GetProvider(ctx, GetProviderRequest{ + return a.impl.GetProvider(ctx, GetProviderRequest{ Name: name, }) } @@ -463,19 +511,9 @@ func (a *ProvidersAPI) GetProviderByName(ctx context.Context, name string) (*Get // be a Metastore admin or the owner of the providers. Providers not owned by // the caller are not included in the response. // -// Use ListProvidersAll() to get all ProviderInfo instances -func (a *ProvidersAPI) ListProviders(ctx context.Context, request ListProvidersRequest) (*ListProvidersResponse, error) { - var listProvidersResponse ListProvidersResponse - path := "/api/2.1/unity-catalog/providers" - err := a.client.Get(ctx, path, request, &listProvidersResponse) - return &listProvidersResponse, err -} - -// ListProvidersAll returns all ProviderInfo instances. This method exists for consistency purposes. -// // This method is generated by Databricks SDK Code Generator. func (a *ProvidersAPI) ListProvidersAll(ctx context.Context, request ListProvidersRequest) ([]ProviderInfo, error) { - response, err := a.ListProviders(ctx, request) + response, err := a.impl.ListProviders(ctx, request) if err != nil { return nil, err } @@ -488,10 +526,7 @@ func (a *ProvidersAPI) ListProvidersAll(ctx context.Context, request ListProvide // // * the caller is a Metastore admin, or * the caller is the owner. func (a *ProvidersAPI) ListShares(ctx context.Context, request ListSharesRequest) (*ListProviderSharesResponse, error) { - var listProviderSharesResponse ListProviderSharesResponse - path := fmt.Sprintf("/api/2.1/unity-catalog/providers/%v/shares", request.Name) - err := a.client.Get(ctx, path, request, &listProviderSharesResponse) - return &listProviderSharesResponse, err + return a.impl.ListShares(ctx, request) } // List shares @@ -500,7 +535,7 @@ func (a *ProvidersAPI) ListShares(ctx context.Context, request ListSharesRequest // // * the caller is a Metastore admin, or * the caller is the owner. func (a *ProvidersAPI) ListSharesByName(ctx context.Context, name string) (*ListProviderSharesResponse, error) { - return a.ListShares(ctx, ListSharesRequest{ + return a.impl.ListShares(ctx, ListSharesRequest{ Name: name, }) } @@ -512,35 +547,48 @@ func (a *ProvidersAPI) ListSharesByName(ctx context.Context, name string) (*List // provider name, the caller must be both a Metastore admin and the owner of the // provider. func (a *ProvidersAPI) Update(ctx context.Context, request UpdateProvider) error { - path := fmt.Sprintf("/api/2.1/unity-catalog/providers/%v", request.Name) - err := a.client.Patch(ctx, path, request) - return err + return a.impl.Update(ctx, request) } -func NewRecipientActivation(client *client.DatabricksClient) RecipientActivationService { +func NewRecipientActivation(client *client.DatabricksClient) *RecipientActivationAPI { return &RecipientActivationAPI{ - client: client, + impl: &recipientActivationImpl{ + client: client, + }, } } +// Databricks Delta Sharing: Recipient Activation REST API type RecipientActivationAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(RecipientActivationService) + impl RecipientActivationService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *RecipientActivationAPI) WithImpl(impl RecipientActivationService) *RecipientActivationAPI { + a.impl = impl + return a +} + +// Impl returns low-level RecipientActivation API implementation +func (a *RecipientActivationAPI) Impl() RecipientActivationService { + return a.impl } // Get a share activation URL // // Gets information about an Activation URL. func (a *RecipientActivationAPI) GetActivationUrlInfo(ctx context.Context, request GetActivationUrlInfoRequest) error { - path := fmt.Sprintf("/api/2.1/unity-catalog/public/data_sharing_activation_info/%v", request.ActivationUrl) - err := a.client.Get(ctx, path, request, nil) - return err + return a.impl.GetActivationUrlInfo(ctx, request) } // Get a share activation URL // // Gets information about an Activation URL. func (a *RecipientActivationAPI) GetActivationUrlInfoByActivationUrl(ctx context.Context, activationUrl string) error { - return a.GetActivationUrlInfo(ctx, GetActivationUrlInfoRequest{ + return a.impl.GetActivationUrlInfo(ctx, GetActivationUrlInfoRequest{ ActivationUrl: activationUrl, }) } @@ -550,10 +598,7 @@ func (a *RecipientActivationAPI) GetActivationUrlInfoByActivationUrl(ctx context // RPC to retrieve access token with an activation token. This is a public API // without any authentication. func (a *RecipientActivationAPI) RetrieveToken(ctx context.Context, request RetrieveTokenRequest) (*RetrieveTokenResponse, error) { - var retrieveTokenResponse RetrieveTokenResponse - path := fmt.Sprintf("/api/2.1/unity-catalog/public/data_sharing_activation/%v", request.ActivationUrl) - err := a.client.Get(ctx, path, request, &retrieveTokenResponse) - return &retrieveTokenResponse, err + return a.impl.RetrieveToken(ctx, request) } // Get an access token @@ -561,19 +606,36 @@ func (a *RecipientActivationAPI) RetrieveToken(ctx context.Context, request Retr // RPC to retrieve access token with an activation token. This is a public API // without any authentication. func (a *RecipientActivationAPI) RetrieveTokenByActivationUrl(ctx context.Context, activationUrl string) (*RetrieveTokenResponse, error) { - return a.RetrieveToken(ctx, RetrieveTokenRequest{ + return a.impl.RetrieveToken(ctx, RetrieveTokenRequest{ ActivationUrl: activationUrl, }) } -func NewRecipients(client *client.DatabricksClient) RecipientsService { +func NewRecipients(client *client.DatabricksClient) *RecipientsAPI { return &RecipientsAPI{ - client: client, + impl: &recipientsImpl{ + client: client, + }, } } +// Databricks Delta Sharing: Recipients REST API type RecipientsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(RecipientsService) + impl RecipientsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *RecipientsAPI) WithImpl(impl RecipientsService) *RecipientsAPI { + a.impl = impl + return a +} + +// Impl returns low-level Recipients API implementation +func (a *RecipientsAPI) Impl() RecipientsService { + return a.impl } // Create a share recipient @@ -582,10 +644,7 @@ type RecipientsAPI struct { // Metastore. The caller must be a Metastore admin or has the CREATE RECIPIENT // privilege on the Metastore. func (a *RecipientsAPI) Create(ctx context.Context, request CreateRecipient) (*CreateRecipientResponse, error) { - var createRecipientResponse CreateRecipientResponse - path := "/api/2.1/unity-catalog/recipients" - err := a.client.Post(ctx, path, request, &createRecipientResponse) - return &createRecipientResponse, err + return a.impl.Create(ctx, request) } // Delete a share recipient @@ -593,9 +652,7 @@ func (a *RecipientsAPI) Create(ctx context.Context, request CreateRecipient) (*C // Deletes the specified recipient from the Metastore. The caller must be the // owner of the recipient. func (a *RecipientsAPI) DeleteRecipient(ctx context.Context, request DeleteRecipientRequest) error { - path := fmt.Sprintf("/api/2.1/unity-catalog/recipients/%v", request.Name) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteRecipient(ctx, request) } // Delete a share recipient @@ -603,7 +660,7 @@ func (a *RecipientsAPI) DeleteRecipient(ctx context.Context, request DeleteRecip // Deletes the specified recipient from the Metastore. The caller must be the // owner of the recipient. func (a *RecipientsAPI) DeleteRecipientByName(ctx context.Context, name string) error { - return a.DeleteRecipient(ctx, DeleteRecipientRequest{ + return a.impl.DeleteRecipient(ctx, DeleteRecipientRequest{ Name: name, }) } @@ -614,10 +671,7 @@ func (a *RecipientsAPI) DeleteRecipientByName(ctx context.Context, name string) // // * the caller is the owner of the share recipient, or: * is a Metastore admin func (a *RecipientsAPI) GetRecipient(ctx context.Context, request GetRecipientRequest) (*GetRecipientResponse, error) { - var getRecipientResponse GetRecipientResponse - path := fmt.Sprintf("/api/2.1/unity-catalog/recipients/%v", request.Name) - err := a.client.Get(ctx, path, request, &getRecipientResponse) - return &getRecipientResponse, err + return a.impl.GetRecipient(ctx, request) } // Get a share recipient @@ -626,7 +680,7 @@ func (a *RecipientsAPI) GetRecipient(ctx context.Context, request GetRecipientRe // // * the caller is the owner of the share recipient, or: * is a Metastore admin func (a *RecipientsAPI) GetRecipientByName(ctx context.Context, name string) (*GetRecipientResponse, error) { - return a.GetRecipient(ctx, GetRecipientRequest{ + return a.impl.GetRecipient(ctx, GetRecipientRequest{ Name: name, }) } @@ -636,10 +690,7 @@ func (a *RecipientsAPI) GetRecipientByName(ctx context.Context, name string) (*G // Gets the share permissions for the specified Recipient. The caller must be a // Metastore admin or the owner of the Recipient. func (a *RecipientsAPI) GetRecipientSharePermissions(ctx context.Context, request GetRecipientSharePermissionsRequest) (*GetRecipientSharePermissionsResponse, error) { - var getRecipientSharePermissionsResponse GetRecipientSharePermissionsResponse - path := fmt.Sprintf("/api/2.1/unity-catalog/recipients/%v/share-permissions", request.Name) - err := a.client.Get(ctx, path, request, &getRecipientSharePermissionsResponse) - return &getRecipientSharePermissionsResponse, err + return a.impl.GetRecipientSharePermissions(ctx, request) } // Get share permissions @@ -647,7 +698,7 @@ func (a *RecipientsAPI) GetRecipientSharePermissions(ctx context.Context, reques // Gets the share permissions for the specified Recipient. The caller must be a // Metastore admin or the owner of the Recipient. func (a *RecipientsAPI) GetRecipientSharePermissionsByName(ctx context.Context, name string) (*GetRecipientSharePermissionsResponse, error) { - return a.GetRecipientSharePermissions(ctx, GetRecipientSharePermissionsRequest{ + return a.impl.GetRecipientSharePermissions(ctx, GetRecipientSharePermissionsRequest{ Name: name, }) } @@ -658,19 +709,9 @@ func (a *RecipientsAPI) GetRecipientSharePermissionsByName(ctx context.Context, // // * the caller is a Metastore admin, or * the caller is the owner. // -// Use ListRecipientsAll() to get all RecipientInfo instances -func (a *RecipientsAPI) ListRecipients(ctx context.Context, request ListRecipientsRequest) (*ListRecipientsResponse, error) { - var listRecipientsResponse ListRecipientsResponse - path := "/api/2.1/unity-catalog/recipients" - err := a.client.Get(ctx, path, request, &listRecipientsResponse) - return &listRecipientsResponse, err -} - -// ListRecipientsAll returns all RecipientInfo instances. This method exists for consistency purposes. -// // This method is generated by Databricks SDK Code Generator. func (a *RecipientsAPI) ListRecipientsAll(ctx context.Context, request ListRecipientsRequest) ([]RecipientInfo, error) { - response, err := a.ListRecipients(ctx, request) + response, err := a.impl.ListRecipients(ctx, request) if err != nil { return nil, err } @@ -682,10 +723,7 @@ func (a *RecipientsAPI) ListRecipientsAll(ctx context.Context, request ListRecip // Refreshes the specified recipient's delta sharing authentication token with // the provided token info. The caller must be the owner of the recipient. func (a *RecipientsAPI) RotateRecipientToken(ctx context.Context, request RotateRecipientToken) (*RotateRecipientTokenResponse, error) { - var rotateRecipientTokenResponse RotateRecipientTokenResponse - path := fmt.Sprintf("/api/2.1/unity-catalog/recipients/%v/rotate-token", request.Name) - err := a.client.Post(ctx, path, request, &rotateRecipientTokenResponse) - return &rotateRecipientTokenResponse, err + return a.impl.RotateRecipientToken(ctx, request) } // Update a share recipient @@ -695,19 +733,38 @@ func (a *RecipientsAPI) RotateRecipientToken(ctx context.Context, request Rotate // updated, the user must be both a Metastore admin and the owner of the // recipient. func (a *RecipientsAPI) Update(ctx context.Context, request UpdateRecipient) error { - path := fmt.Sprintf("/api/2.1/unity-catalog/recipients/%v", request.Name) - err := a.client.Patch(ctx, path, request) - return err + return a.impl.Update(ctx, request) } -func NewSchemas(client *client.DatabricksClient) SchemasService { +func NewSchemas(client *client.DatabricksClient) *SchemasAPI { return &SchemasAPI{ - client: client, + impl: &schemasImpl{ + client: client, + }, } } +// A schema (also called a database) is the second layer of Unity Catalog’s +// three-level namespace. A schema organizes tables and views. To access (or +// list) a table or view in a schema, users must have the USAGE data permission +// on the schema and its parent catalog, and they must have the SELECT +// permission on the table or view. type SchemasAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(SchemasService) + impl SchemasService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *SchemasAPI) WithImpl(impl SchemasService) *SchemasAPI { + a.impl = impl + return a +} + +// Impl returns low-level Schemas API implementation +func (a *SchemasAPI) Impl() SchemasService { + return a.impl } // Create a schema @@ -715,10 +772,7 @@ type SchemasAPI struct { // Creates a new schema for catalog in the Metatastore. The caller must be a // Metastore admin, or have the CREATE privilege in the parentcatalog. func (a *SchemasAPI) Create(ctx context.Context, request CreateSchema) (*CreateSchemaResponse, error) { - var createSchemaResponse CreateSchemaResponse - path := "/api/2.1/unity-catalog/schemas" - err := a.client.Post(ctx, path, request, &createSchemaResponse) - return &createSchemaResponse, err + return a.impl.Create(ctx, request) } // Delete a schema @@ -726,9 +780,7 @@ func (a *SchemasAPI) Create(ctx context.Context, request CreateSchema) (*CreateS // Deletes the specified schema from the parent catalog. The caller must be the // owner of the schema or an owner of the parent catalog. func (a *SchemasAPI) DeleteSchema(ctx context.Context, request DeleteSchemaRequest) error { - path := fmt.Sprintf("/api/2.1/unity-catalog/schemas/%v", request.FullName) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteSchema(ctx, request) } // Delete a schema @@ -736,7 +788,7 @@ func (a *SchemasAPI) DeleteSchema(ctx context.Context, request DeleteSchemaReque // Deletes the specified schema from the parent catalog. The caller must be the // owner of the schema or an owner of the parent catalog. func (a *SchemasAPI) DeleteSchemaByFullName(ctx context.Context, fullName string) error { - return a.DeleteSchema(ctx, DeleteSchemaRequest{ + return a.impl.DeleteSchema(ctx, DeleteSchemaRequest{ FullName: fullName, }) } @@ -747,10 +799,7 @@ func (a *SchemasAPI) DeleteSchemaByFullName(ctx context.Context, fullName string // a Metastore admin, the owner of the schema, or a user that has the USAGE // privilege on the schema. func (a *SchemasAPI) GetSchema(ctx context.Context, request GetSchemaRequest) (*GetSchemaResponse, error) { - var getSchemaResponse GetSchemaResponse - path := fmt.Sprintf("/api/2.1/unity-catalog/schemas/%v", request.FullName) - err := a.client.Get(ctx, path, request, &getSchemaResponse) - return &getSchemaResponse, err + return a.impl.GetSchema(ctx, request) } // Get a schema @@ -759,7 +808,7 @@ func (a *SchemasAPI) GetSchema(ctx context.Context, request GetSchemaRequest) (* // a Metastore admin, the owner of the schema, or a user that has the USAGE // privilege on the schema. func (a *SchemasAPI) GetSchemaByFullName(ctx context.Context, fullName string) (*GetSchemaResponse, error) { - return a.GetSchema(ctx, GetSchemaRequest{ + return a.impl.GetSchema(ctx, GetSchemaRequest{ FullName: fullName, }) } @@ -771,19 +820,9 @@ func (a *SchemasAPI) GetSchemaByFullName(ctx context.Context, fullName string) ( // catalog will be retrieved. Otherwise, only schemas owned by the caller (or // for which the caller has the USAGE privilege) will be retrieved. // -// Use ListSchemasAll() to get all SchemaInfo instances -func (a *SchemasAPI) ListSchemas(ctx context.Context, request ListSchemasRequest) (*ListSchemasResponse, error) { - var listSchemasResponse ListSchemasResponse - path := "/api/2.1/unity-catalog/schemas" - err := a.client.Get(ctx, path, request, &listSchemasResponse) - return &listSchemasResponse, err -} - -// ListSchemasAll returns all SchemaInfo instances. This method exists for consistency purposes. -// // This method is generated by Databricks SDK Code Generator. func (a *SchemasAPI) ListSchemasAll(ctx context.Context, request ListSchemasRequest) ([]SchemaInfo, error) { - response, err := a.ListSchemas(ctx, request) + response, err := a.impl.ListSchemas(ctx, request) if err != nil { return nil, err } @@ -797,19 +836,34 @@ func (a *SchemasAPI) ListSchemasAll(ctx context.Context, request ListSchemasRequ // in the update. If the __name__ field must be updated, the caller must be a // Metastore admin or have the CREATE privilege on the parent catalog. func (a *SchemasAPI) Update(ctx context.Context, request UpdateSchema) error { - path := fmt.Sprintf("/api/2.1/unity-catalog/schemas/%v", request.FullName) - err := a.client.Patch(ctx, path, request) - return err + return a.impl.Update(ctx, request) } -func NewShares(client *client.DatabricksClient) SharesService { +func NewShares(client *client.DatabricksClient) *SharesAPI { return &SharesAPI{ - client: client, + impl: &sharesImpl{ + client: client, + }, } } +// Databricks Delta Sharing: Shares REST API type SharesAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(SharesService) + impl SharesService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *SharesAPI) WithImpl(impl SharesService) *SharesAPI { + a.impl = impl + return a +} + +// Impl returns low-level Shares API implementation +func (a *SharesAPI) Impl() SharesService { + return a.impl } // Create a share @@ -818,10 +872,7 @@ type SharesAPI struct { // or after creation with **update**. The caller must be a Metastore admin or // have the CREATE SHARE privilege on the Metastore. func (a *SharesAPI) Create(ctx context.Context, request CreateShare) (*CreateShareResponse, error) { - var createShareResponse CreateShareResponse - path := "/api/2.1/unity-catalog/shares" - err := a.client.Post(ctx, path, request, &createShareResponse) - return &createShareResponse, err + return a.impl.Create(ctx, request) } // Delete a share @@ -829,9 +880,7 @@ func (a *SharesAPI) Create(ctx context.Context, request CreateShare) (*CreateSha // Deletes a data object share from the Metastore. The caller must be an owner // of the share. func (a *SharesAPI) DeleteShare(ctx context.Context, request DeleteShareRequest) error { - path := fmt.Sprintf("/api/2.1/unity-catalog/shares/%v", request.Name) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteShare(ctx, request) } // Delete a share @@ -839,7 +888,7 @@ func (a *SharesAPI) DeleteShare(ctx context.Context, request DeleteShareRequest) // Deletes a data object share from the Metastore. The caller must be an owner // of the share. func (a *SharesAPI) DeleteShareByName(ctx context.Context, name string) error { - return a.DeleteShare(ctx, DeleteShareRequest{ + return a.impl.DeleteShare(ctx, DeleteShareRequest{ Name: name, }) } @@ -849,10 +898,7 @@ func (a *SharesAPI) DeleteShareByName(ctx context.Context, name string) error { // Gets a data object share from the Metastore. The caller must be a Metastore // admin or the owner of the share. func (a *SharesAPI) GetShare(ctx context.Context, request GetShareRequest) (*GetShareResponse, error) { - var getShareResponse GetShareResponse - path := fmt.Sprintf("/api/2.1/unity-catalog/shares/%v", request.Name) - err := a.client.Get(ctx, path, request, &getShareResponse) - return &getShareResponse, err + return a.impl.GetShare(ctx, request) } // Get a share @@ -860,7 +906,7 @@ func (a *SharesAPI) GetShare(ctx context.Context, request GetShareRequest) (*Get // Gets a data object share from the Metastore. The caller must be a Metastore // admin or the owner of the share. func (a *SharesAPI) GetShareByName(ctx context.Context, name string) (*GetShareResponse, error) { - return a.GetShare(ctx, GetShareRequest{ + return a.impl.GetShare(ctx, GetShareRequest{ Name: name, }) } @@ -870,10 +916,7 @@ func (a *SharesAPI) GetShareByName(ctx context.Context, name string) (*GetShareR // Gets the permissions for a data share from the Metastore. The caller must be // a Metastore admin or the owner of the share. func (a *SharesAPI) GetSharePermissions(ctx context.Context, request GetSharePermissionsRequest) (*GetSharePermissionsResponse, error) { - var getSharePermissionsResponse GetSharePermissionsResponse - path := fmt.Sprintf("/api/2.1/unity-catalog/shares/%v/permissions", request.Name) - err := a.client.Get(ctx, path, request, &getSharePermissionsResponse) - return &getSharePermissionsResponse, err + return a.impl.GetSharePermissions(ctx, request) } // Get permissions @@ -881,7 +924,7 @@ func (a *SharesAPI) GetSharePermissions(ctx context.Context, request GetSharePer // Gets the permissions for a data share from the Metastore. The caller must be // a Metastore admin or the owner of the share. func (a *SharesAPI) GetSharePermissionsByName(ctx context.Context, name string) (*GetSharePermissionsResponse, error) { - return a.GetSharePermissions(ctx, GetSharePermissionsRequest{ + return a.impl.GetSharePermissions(ctx, GetSharePermissionsRequest{ Name: name, }) } @@ -891,19 +934,9 @@ func (a *SharesAPI) GetSharePermissionsByName(ctx context.Context, name string) // Gets an array of data object shares from the Metastore. The caller must be a // Metastore admin or the owner of the share. // -// Use ListSharesAll() to get all ShareInfo instances -func (a *SharesAPI) ListShares(ctx context.Context) (*ListSharesResponse, error) { - var listSharesResponse ListSharesResponse - path := "/api/2.1/unity-catalog/shares" - err := a.client.Get(ctx, path, nil, &listSharesResponse) - return &listSharesResponse, err -} - -// ListSharesAll returns all ShareInfo instances. This method exists for consistency purposes. -// // This method is generated by Databricks SDK Code Generator. func (a *SharesAPI) ListSharesAll(ctx context.Context) ([]ShareInfo, error) { - response, err := a.ListShares(ctx) + response, err := a.impl.ListShares(ctx) if err != nil { return nil, err } @@ -928,9 +961,7 @@ func (a *SharesAPI) ListSharesAll(ctx context.Context) ([]ShareInfo, error) { // // Table removals through **update** do not require additional privileges. func (a *SharesAPI) Update(ctx context.Context, request UpdateShare) error { - path := fmt.Sprintf("/api/2.1/unity-catalog/shares/%v", request.Name) - err := a.client.Patch(ctx, path, request) - return err + return a.impl.Update(ctx, request) } // Update permissions @@ -941,19 +972,47 @@ func (a *SharesAPI) Update(ctx context.Context, request UpdateShare) error { // For new recipient grants, the user must also be the owner of the recipients. // recipient revocations do not require additional privileges. func (a *SharesAPI) UpdateSharePermissions(ctx context.Context, request UpdateSharePermissions) error { - path := fmt.Sprintf("/api/2.1/unity-catalog/shares/%v/permissions", request.Name) - err := a.client.Patch(ctx, path, request) - return err + return a.impl.UpdateSharePermissions(ctx, request) } -func NewStorageCredentials(client *client.DatabricksClient) StorageCredentialsService { +func NewStorageCredentials(client *client.DatabricksClient) *StorageCredentialsAPI { return &StorageCredentialsAPI{ - client: client, + impl: &storageCredentialsImpl{ + client: client, + }, } } +// A storage credential represents an authentication and authorization mechanism +// for accessing data stored on your cloud tenant, using an IAM role. Each +// storage credential is subject to Unity Catalog access-control policies that +// control which users and groups can access the credential. If a user does not +// have access to a storage credential in Unity Catalog, the request fails and +// Unity Catalog does not attempt to authenticate to your cloud tenant on the +// user’s behalf. +// +// Databricks recommends using external locations rather than using storage +// credentials directly. +// +// To create storage credentials, you must be a Databricks account admin. The +// account admin who creates the storage credential can delegate ownership to +// another user or group to manage permissions on it. type StorageCredentialsAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(StorageCredentialsService) + impl StorageCredentialsService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *StorageCredentialsAPI) WithImpl(impl StorageCredentialsService) *StorageCredentialsAPI { + a.impl = impl + return a +} + +// Impl returns low-level StorageCredentials API implementation +func (a *StorageCredentialsAPI) Impl() StorageCredentialsService { + return a.impl } // Create credentials @@ -967,10 +1026,7 @@ type StorageCredentialsAPI struct { // The caller must be a Metastore admin and have the CREATE STORAGE CREDENTIAL // privilege on the Metastore. func (a *StorageCredentialsAPI) Create(ctx context.Context, request CreateStorageCredential) (*CreateStorageCredentialResponse, error) { - var createStorageCredentialResponse CreateStorageCredentialResponse - path := "/api/2.1/unity-catalog/storage-credentials" - err := a.client.Post(ctx, path, request, &createStorageCredentialResponse) - return &createStorageCredentialResponse, err + return a.impl.Create(ctx, request) } // Delete a credential @@ -978,9 +1034,7 @@ func (a *StorageCredentialsAPI) Create(ctx context.Context, request CreateStorag // Deletes a storage credential from the Metastore. The caller must be an owner // of the storage credential. func (a *StorageCredentialsAPI) DeleteStorageCredential(ctx context.Context, request DeleteStorageCredentialRequest) error { - path := fmt.Sprintf("/api/2.1/unity-catalog/storage-credentials/%v", request.Name) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteStorageCredential(ctx, request) } // Delete a credential @@ -988,7 +1042,7 @@ func (a *StorageCredentialsAPI) DeleteStorageCredential(ctx context.Context, req // Deletes a storage credential from the Metastore. The caller must be an owner // of the storage credential. func (a *StorageCredentialsAPI) DeleteStorageCredentialByName(ctx context.Context, name string) error { - return a.DeleteStorageCredential(ctx, DeleteStorageCredentialRequest{ + return a.impl.DeleteStorageCredential(ctx, DeleteStorageCredentialRequest{ Name: name, }) } @@ -999,10 +1053,7 @@ func (a *StorageCredentialsAPI) DeleteStorageCredentialByName(ctx context.Contex // admin, the owner of the storage credential, or have a level of privilege on // the storage credential. func (a *StorageCredentialsAPI) GetStorageCredentials(ctx context.Context, request GetStorageCredentialsRequest) (*GetStorageCredentialResponse, error) { - var getStorageCredentialResponse GetStorageCredentialResponse - path := fmt.Sprintf("/api/2.1/unity-catalog/storage-credentials/%v", request.Name) - err := a.client.Get(ctx, path, request, &getStorageCredentialResponse) - return &getStorageCredentialResponse, err + return a.impl.GetStorageCredentials(ctx, request) } // Get a credential @@ -1011,7 +1062,7 @@ func (a *StorageCredentialsAPI) GetStorageCredentials(ctx context.Context, reque // admin, the owner of the storage credential, or have a level of privilege on // the storage credential. func (a *StorageCredentialsAPI) GetStorageCredentialsByName(ctx context.Context, name string) (*GetStorageCredentialResponse, error) { - return a.GetStorageCredentials(ctx, GetStorageCredentialsRequest{ + return a.impl.GetStorageCredentials(ctx, GetStorageCredentialsRequest{ Name: name, }) } @@ -1023,19 +1074,9 @@ func (a *StorageCredentialsAPI) GetStorageCredentialsByName(ctx context.Context, // privilege level to access. If the caller is a Metastore admin, all storage // credentials will be retrieved. // -// Use ListStorageCredentialsAll() to get all StorageCredentialInfo instances -func (a *StorageCredentialsAPI) ListStorageCredentials(ctx context.Context) (*ListStorageCredentialsResponse, error) { - var listStorageCredentialsResponse ListStorageCredentialsResponse - path := "/api/2.1/unity-catalog/storage-credentials" - err := a.client.Get(ctx, path, nil, &listStorageCredentialsResponse) - return &listStorageCredentialsResponse, err -} - -// ListStorageCredentialsAll returns all StorageCredentialInfo instances. This method exists for consistency purposes. -// // This method is generated by Databricks SDK Code Generator. func (a *StorageCredentialsAPI) ListStorageCredentialsAll(ctx context.Context) ([]StorageCredentialInfo, error) { - response, err := a.ListStorageCredentials(ctx) + response, err := a.impl.ListStorageCredentials(ctx) if err != nil { return nil, err } @@ -1048,19 +1089,41 @@ func (a *StorageCredentialsAPI) ListStorageCredentialsAll(ctx context.Context) ( // of the storage credential. If the caller is a Metastore admin, only the // __owner__ credential can be changed. func (a *StorageCredentialsAPI) Update(ctx context.Context, request UpdateStorageCredential) error { - path := fmt.Sprintf("/api/2.1/unity-catalog/storage-credentials/%v", request.Name) - err := a.client.Patch(ctx, path, request) - return err + return a.impl.Update(ctx, request) } -func NewTables(client *client.DatabricksClient) TablesService { +func NewTables(client *client.DatabricksClient) *TablesAPI { return &TablesAPI{ - client: client, + impl: &tablesImpl{ + client: client, + }, } } +// A table resides in the third layer of Unity Catalog’s three-level +// namespace. It contains rows of data. To create a table, users must have +// CREATE and USAGE permissions on the schema, and they must have the USAGE +// permission on its parent catalog. To query a table, users must have the +// SELECT permission on the table, and they must have the USAGE permission on +// its parent schema and catalog. +// +// A table can be managed or external. type TablesAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(TablesService) + impl TablesService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *TablesAPI) WithImpl(impl TablesService) *TablesAPI { + a.impl = impl + return a +} + +// Impl returns low-level Tables API implementation +func (a *TablesAPI) Impl() TablesService { + return a.impl } // Create a table @@ -1076,10 +1139,7 @@ type TablesAPI struct { // a Metastore admin or meet the permissions requirements of the storage // credential or the external location. func (a *TablesAPI) Create(ctx context.Context, request CreateTable) (*CreateTableResponse, error) { - var createTableResponse CreateTableResponse - path := "/api/2.1/unity-catalog/tables" - err := a.client.Post(ctx, path, request, &createTableResponse) - return &createTableResponse, err + return a.impl.Create(ctx, request) } // Create a staging table @@ -1088,10 +1148,7 @@ func (a *TablesAPI) Create(ctx context.Context, request CreateTable) (*CreateTab // privilege on the parent Catalog and the USAGE and CREATE privileges on the // parent schema. func (a *TablesAPI) CreateStagingTable(ctx context.Context, request CreateStagingTable) (*CreateStagingTableResponse, error) { - var createStagingTableResponse CreateStagingTableResponse - path := "/api/2.1/unity-catalog/staging-tables" - err := a.client.Post(ctx, path, request, &createStagingTableResponse) - return &createStagingTableResponse, err + return a.impl.CreateStagingTable(ctx, request) } // Delete a table @@ -1101,9 +1158,7 @@ func (a *TablesAPI) CreateStagingTable(ctx context.Context, request CreateStagin // catalog and be the owner of the parent schema, or be the owner of the table // and have the USAGE privilege on both the parent catalog and schema. func (a *TablesAPI) DeleteTable(ctx context.Context, request DeleteTableRequest) error { - path := fmt.Sprintf("/api/2.1/unity-catalog/tables/%v", request.FullName) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteTable(ctx, request) } // Delete a table @@ -1113,7 +1168,7 @@ func (a *TablesAPI) DeleteTable(ctx context.Context, request DeleteTableRequest) // catalog and be the owner of the parent schema, or be the owner of the table // and have the USAGE privilege on both the parent catalog and schema. func (a *TablesAPI) DeleteTableByFullName(ctx context.Context, fullName string) error { - return a.DeleteTable(ctx, DeleteTableRequest{ + return a.impl.DeleteTable(ctx, DeleteTableRequest{ FullName: fullName, }) } @@ -1125,10 +1180,7 @@ func (a *TablesAPI) DeleteTableByFullName(ctx context.Context, fullName string) // privilege on both the parent catalog and schema, or be the owner of the table // and have the SELECT privilege on it as well. func (a *TablesAPI) GetTable(ctx context.Context, request GetTableRequest) (*GetTableResponse, error) { - var getTableResponse GetTableResponse - path := fmt.Sprintf("/api/2.1/unity-catalog/tables/%v", request.FullName) - err := a.client.Get(ctx, path, request, &getTableResponse) - return &getTableResponse, err + return a.impl.GetTable(ctx, request) } // Get a table @@ -1138,7 +1190,7 @@ func (a *TablesAPI) GetTable(ctx context.Context, request GetTableRequest) (*Get // privilege on both the parent catalog and schema, or be the owner of the table // and have the SELECT privilege on it as well. func (a *TablesAPI) GetTableByFullName(ctx context.Context, fullName string) (*GetTableResponse, error) { - return a.GetTable(ctx, GetTableRequest{ + return a.impl.GetTable(ctx, GetTableRequest{ FullName: fullName, }) } @@ -1155,10 +1207,7 @@ func (a *TablesAPI) GetTableByFullName(ctx context.Context, fullName string) (*G // ownership or USAGE privilege on the Schema, provided that the user also has // ownership or the USAGE privilege on the parent Catalog func (a *TablesAPI) ListTableSummaries(ctx context.Context, request ListTableSummariesRequest) (*ListTableSummariesResponse, error) { - var listTableSummariesResponse ListTableSummariesResponse - path := "/api/2.1/unity-catalog/table-summaries" - err := a.client.Get(ctx, path, request, &listTableSummariesResponse) - return &listTableSummariesResponse, err + return a.impl.ListTableSummaries(ctx, request) } // List tables @@ -1169,19 +1218,9 @@ func (a *TablesAPI) ListTableSummaries(ctx context.Context, request ListTableSum // also be the owner or have the USAGE privilege on the parent catalog and // schema. // -// Use ListTablesAll() to get all TableInfo instances -func (a *TablesAPI) ListTables(ctx context.Context, request ListTablesRequest) (*ListTablesResponse, error) { - var listTablesResponse ListTablesResponse - path := "/api/2.1/unity-catalog/tables" - err := a.client.Get(ctx, path, request, &listTablesResponse) - return &listTablesResponse, err -} - -// ListTablesAll returns all TableInfo instances. This method exists for consistency purposes. -// // This method is generated by Databricks SDK Code Generator. func (a *TablesAPI) ListTablesAll(ctx context.Context, request ListTablesRequest) ([]TableInfo, error) { - response, err := a.ListTables(ctx, request) + response, err := a.impl.ListTables(ctx, request) if err != nil { return nil, err } @@ -1194,27 +1233,39 @@ func (a *TablesAPI) ListTablesAll(ctx context.Context, request ListTablesRequest // owner of have the USAGE privilege on the parent catalog and schema, or, if // changing the owner, be a Metastore admin as well. func (a *TablesAPI) Update(ctx context.Context, request UpdateTable) error { - path := fmt.Sprintf("/api/2.1/unity-catalog/tables/%v", request.FullName) - err := a.client.Patch(ctx, path, request) - return err + return a.impl.Update(ctx, request) } -func NewUnityFiles(client *client.DatabricksClient) UnityFilesService { +func NewUnityFiles(client *client.DatabricksClient) *UnityFilesAPI { return &UnityFilesAPI{ - client: client, + impl: &unityFilesImpl{ + client: client, + }, } } +// Databricks Unity Catalog: Files REST API type UnityFilesAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(UnityFilesService) + impl UnityFilesService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *UnityFilesAPI) WithImpl(impl UnityFilesService) *UnityFilesAPI { + a.impl = impl + return a +} + +// Impl returns low-level UnityFiles API implementation +func (a *UnityFilesAPI) Impl() UnityFilesService { + return a.impl } // List files // // List the files sound at the supplied URL. func (a *UnityFilesAPI) ListFiles(ctx context.Context, request ListFilesRequest) (*ListFilesResponse, error) { - var listFilesResponse ListFilesResponse - path := "/api/2.1/unity-catalog/files" - err := a.client.Get(ctx, path, request, &listFilesResponse) - return &listFilesResponse, err + return a.impl.ListFiles(ctx, request) } diff --git a/service/unitycatalog/impl.go b/service/unitycatalog/impl.go new file mode 100755 index 000000000..921245844 --- /dev/null +++ b/service/unitycatalog/impl.go @@ -0,0 +1,473 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package unitycatalog + +import ( + "context" + "fmt" + + "github.com/databricks/databricks-sdk-go/databricks/client" +) + +// unexported type that holds implementations of just Catalogs API methods +type catalogsImpl struct { + client *client.DatabricksClient +} + +func (a *catalogsImpl) Create(ctx context.Context, request CreateCatalog) (*CreateCatalogResponse, error) { + var createCatalogResponse CreateCatalogResponse + path := "/api/2.1/unity-catalog/catalogs" + err := a.client.Post(ctx, path, request, &createCatalogResponse) + return &createCatalogResponse, err +} + +func (a *catalogsImpl) DeleteCatalog(ctx context.Context, request DeleteCatalogRequest) error { + path := fmt.Sprintf("/api/2.1/unity-catalog/catalogs/%v", request.Name) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *catalogsImpl) GetCatalog(ctx context.Context, request GetCatalogRequest) (*GetCatalogResponse, error) { + var getCatalogResponse GetCatalogResponse + path := fmt.Sprintf("/api/2.1/unity-catalog/catalogs/%v", request.Name) + err := a.client.Get(ctx, path, request, &getCatalogResponse) + return &getCatalogResponse, err +} + +func (a *catalogsImpl) ListCatalogs(ctx context.Context) (*ListCatalogsResponse, error) { + var listCatalogsResponse ListCatalogsResponse + path := "/api/2.1/unity-catalog/catalogs" + err := a.client.Get(ctx, path, nil, &listCatalogsResponse) + return &listCatalogsResponse, err +} + +func (a *catalogsImpl) Update(ctx context.Context, request UpdateCatalog) error { + path := fmt.Sprintf("/api/2.1/unity-catalog/catalogs/%v", request.Name) + err := a.client.Patch(ctx, path, request) + return err +} + +// unexported type that holds implementations of just ExternalLocations API methods +type externalLocationsImpl struct { + client *client.DatabricksClient +} + +func (a *externalLocationsImpl) Create(ctx context.Context, request CreateExternalLocation) (*CreateExternalLocationResponse, error) { + var createExternalLocationResponse CreateExternalLocationResponse + path := "/api/2.1/unity-catalog/external-locations" + err := a.client.Post(ctx, path, request, &createExternalLocationResponse) + return &createExternalLocationResponse, err +} + +func (a *externalLocationsImpl) DeleteExternalLocation(ctx context.Context, request DeleteExternalLocationRequest) error { + path := fmt.Sprintf("/api/2.1/unity-catalog/external-locations/%v", request.Name) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *externalLocationsImpl) GetExternalLocation(ctx context.Context, request GetExternalLocationRequest) (*GetExternalLocationResponse, error) { + var getExternalLocationResponse GetExternalLocationResponse + path := fmt.Sprintf("/api/2.1/unity-catalog/external-locations/%v", request.Name) + err := a.client.Get(ctx, path, request, &getExternalLocationResponse) + return &getExternalLocationResponse, err +} + +func (a *externalLocationsImpl) ListExternalLocations(ctx context.Context) (*ListExternalLocationsResponse, error) { + var listExternalLocationsResponse ListExternalLocationsResponse + path := "/api/2.1/unity-catalog/external-locations" + err := a.client.Get(ctx, path, nil, &listExternalLocationsResponse) + return &listExternalLocationsResponse, err +} + +func (a *externalLocationsImpl) Update(ctx context.Context, request UpdateExternalLocation) error { + path := fmt.Sprintf("/api/2.1/unity-catalog/external-locations/%v", request.Name) + err := a.client.Patch(ctx, path, request) + return err +} + +// unexported type that holds implementations of just Grants API methods +type grantsImpl struct { + client *client.DatabricksClient +} + +func (a *grantsImpl) GetPermissions(ctx context.Context, request GetPermissionsRequest) (*GetPermissionsResponse, error) { + var getPermissionsResponse GetPermissionsResponse + path := fmt.Sprintf("/api/2.1/unity-catalog/permissions/%v/%v", request.SecurableType, request.FullName) + err := a.client.Get(ctx, path, request, &getPermissionsResponse) + return &getPermissionsResponse, err +} + +func (a *grantsImpl) UpdatePermissions(ctx context.Context, request UpdatePermissions) error { + path := fmt.Sprintf("/api/2.1/unity-catalog/permissions/%v/%v", request.SecurableType, request.FullName) + err := a.client.Patch(ctx, path, request) + return err +} + +// unexported type that holds implementations of just Metastores API methods +type metastoresImpl struct { + client *client.DatabricksClient +} + +func (a *metastoresImpl) Create(ctx context.Context, request CreateMetastore) (*CreateMetastoreResponse, error) { + var createMetastoreResponse CreateMetastoreResponse + path := "/api/2.1/unity-catalog/metastores" + err := a.client.Post(ctx, path, request, &createMetastoreResponse) + return &createMetastoreResponse, err +} + +func (a *metastoresImpl) CreateMetastoreAssignment(ctx context.Context, request CreateMetastoreAssignment) error { + path := fmt.Sprintf("/api/2.1/unity-catalog/workspaces/%v/metastore", request.WorkspaceId) + err := a.client.Put(ctx, path, request) + return err +} + +func (a *metastoresImpl) DeleteMetastore(ctx context.Context, request DeleteMetastoreRequest) error { + path := fmt.Sprintf("/api/2.1/unity-catalog/metastores/%v", request.Id) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *metastoresImpl) DeleteMetastoreAssignment(ctx context.Context, request DeleteMetastoreAssignmentRequest) error { + path := fmt.Sprintf("/api/2.1/unity-catalog/workspaces/%v/metastore", request.WorkspaceId) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *metastoresImpl) GetMetastore(ctx context.Context, request GetMetastoreRequest) (*GetMetastoreResponse, error) { + var getMetastoreResponse GetMetastoreResponse + path := fmt.Sprintf("/api/2.1/unity-catalog/metastores/%v", request.Id) + err := a.client.Get(ctx, path, request, &getMetastoreResponse) + return &getMetastoreResponse, err +} + +func (a *metastoresImpl) GetMetastoreSummary(ctx context.Context) (*GetMetastoreSummaryResponse, error) { + var getMetastoreSummaryResponse GetMetastoreSummaryResponse + path := "/api/2.1/unity-catalog/metastore_summary" + err := a.client.Get(ctx, path, nil, &getMetastoreSummaryResponse) + return &getMetastoreSummaryResponse, err +} + +func (a *metastoresImpl) ListMetastores(ctx context.Context) (*ListMetastoresResponse, error) { + var listMetastoresResponse ListMetastoresResponse + path := "/api/2.1/unity-catalog/metastores" + err := a.client.Get(ctx, path, nil, &listMetastoresResponse) + return &listMetastoresResponse, err +} + +func (a *metastoresImpl) Update(ctx context.Context, request UpdateMetastore) error { + path := fmt.Sprintf("/api/2.1/unity-catalog/metastores/%v", request.Id) + err := a.client.Patch(ctx, path, request) + return err +} + +func (a *metastoresImpl) UpdateMetastoreAssignment(ctx context.Context, request UpdateMetastoreAssignment) error { + path := fmt.Sprintf("/api/2.1/unity-catalog/workspaces/%v/metastore", request.WorkspaceId) + err := a.client.Patch(ctx, path, request) + return err +} + +// unexported type that holds implementations of just Providers API methods +type providersImpl struct { + client *client.DatabricksClient +} + +func (a *providersImpl) Create(ctx context.Context, request CreateProvider) (*CreateProviderResponse, error) { + var createProviderResponse CreateProviderResponse + path := "/api/2.1/unity-catalog/providers" + err := a.client.Post(ctx, path, request, &createProviderResponse) + return &createProviderResponse, err +} + +func (a *providersImpl) DeleteProvider(ctx context.Context, request DeleteProviderRequest) error { + path := fmt.Sprintf("/api/2.1/unity-catalog/providers/%v", request.Name) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *providersImpl) GetProvider(ctx context.Context, request GetProviderRequest) (*GetProviderResponse, error) { + var getProviderResponse GetProviderResponse + path := fmt.Sprintf("/api/2.1/unity-catalog/providers/%v", request.Name) + err := a.client.Get(ctx, path, request, &getProviderResponse) + return &getProviderResponse, err +} + +func (a *providersImpl) ListProviders(ctx context.Context, request ListProvidersRequest) (*ListProvidersResponse, error) { + var listProvidersResponse ListProvidersResponse + path := "/api/2.1/unity-catalog/providers" + err := a.client.Get(ctx, path, request, &listProvidersResponse) + return &listProvidersResponse, err +} + +func (a *providersImpl) ListShares(ctx context.Context, request ListSharesRequest) (*ListProviderSharesResponse, error) { + var listProviderSharesResponse ListProviderSharesResponse + path := fmt.Sprintf("/api/2.1/unity-catalog/providers/%v/shares", request.Name) + err := a.client.Get(ctx, path, request, &listProviderSharesResponse) + return &listProviderSharesResponse, err +} + +func (a *providersImpl) Update(ctx context.Context, request UpdateProvider) error { + path := fmt.Sprintf("/api/2.1/unity-catalog/providers/%v", request.Name) + err := a.client.Patch(ctx, path, request) + return err +} + +// unexported type that holds implementations of just RecipientActivation API methods +type recipientActivationImpl struct { + client *client.DatabricksClient +} + +func (a *recipientActivationImpl) GetActivationUrlInfo(ctx context.Context, request GetActivationUrlInfoRequest) error { + path := fmt.Sprintf("/api/2.1/unity-catalog/public/data_sharing_activation_info/%v", request.ActivationUrl) + err := a.client.Get(ctx, path, request, nil) + return err +} + +func (a *recipientActivationImpl) RetrieveToken(ctx context.Context, request RetrieveTokenRequest) (*RetrieveTokenResponse, error) { + var retrieveTokenResponse RetrieveTokenResponse + path := fmt.Sprintf("/api/2.1/unity-catalog/public/data_sharing_activation/%v", request.ActivationUrl) + err := a.client.Get(ctx, path, request, &retrieveTokenResponse) + return &retrieveTokenResponse, err +} + +// unexported type that holds implementations of just Recipients API methods +type recipientsImpl struct { + client *client.DatabricksClient +} + +func (a *recipientsImpl) Create(ctx context.Context, request CreateRecipient) (*CreateRecipientResponse, error) { + var createRecipientResponse CreateRecipientResponse + path := "/api/2.1/unity-catalog/recipients" + err := a.client.Post(ctx, path, request, &createRecipientResponse) + return &createRecipientResponse, err +} + +func (a *recipientsImpl) DeleteRecipient(ctx context.Context, request DeleteRecipientRequest) error { + path := fmt.Sprintf("/api/2.1/unity-catalog/recipients/%v", request.Name) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *recipientsImpl) GetRecipient(ctx context.Context, request GetRecipientRequest) (*GetRecipientResponse, error) { + var getRecipientResponse GetRecipientResponse + path := fmt.Sprintf("/api/2.1/unity-catalog/recipients/%v", request.Name) + err := a.client.Get(ctx, path, request, &getRecipientResponse) + return &getRecipientResponse, err +} + +func (a *recipientsImpl) GetRecipientSharePermissions(ctx context.Context, request GetRecipientSharePermissionsRequest) (*GetRecipientSharePermissionsResponse, error) { + var getRecipientSharePermissionsResponse GetRecipientSharePermissionsResponse + path := fmt.Sprintf("/api/2.1/unity-catalog/recipients/%v/share-permissions", request.Name) + err := a.client.Get(ctx, path, request, &getRecipientSharePermissionsResponse) + return &getRecipientSharePermissionsResponse, err +} + +func (a *recipientsImpl) ListRecipients(ctx context.Context, request ListRecipientsRequest) (*ListRecipientsResponse, error) { + var listRecipientsResponse ListRecipientsResponse + path := "/api/2.1/unity-catalog/recipients" + err := a.client.Get(ctx, path, request, &listRecipientsResponse) + return &listRecipientsResponse, err +} + +func (a *recipientsImpl) RotateRecipientToken(ctx context.Context, request RotateRecipientToken) (*RotateRecipientTokenResponse, error) { + var rotateRecipientTokenResponse RotateRecipientTokenResponse + path := fmt.Sprintf("/api/2.1/unity-catalog/recipients/%v/rotate-token", request.Name) + err := a.client.Post(ctx, path, request, &rotateRecipientTokenResponse) + return &rotateRecipientTokenResponse, err +} + +func (a *recipientsImpl) Update(ctx context.Context, request UpdateRecipient) error { + path := fmt.Sprintf("/api/2.1/unity-catalog/recipients/%v", request.Name) + err := a.client.Patch(ctx, path, request) + return err +} + +// unexported type that holds implementations of just Schemas API methods +type schemasImpl struct { + client *client.DatabricksClient +} + +func (a *schemasImpl) Create(ctx context.Context, request CreateSchema) (*CreateSchemaResponse, error) { + var createSchemaResponse CreateSchemaResponse + path := "/api/2.1/unity-catalog/schemas" + err := a.client.Post(ctx, path, request, &createSchemaResponse) + return &createSchemaResponse, err +} + +func (a *schemasImpl) DeleteSchema(ctx context.Context, request DeleteSchemaRequest) error { + path := fmt.Sprintf("/api/2.1/unity-catalog/schemas/%v", request.FullName) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *schemasImpl) GetSchema(ctx context.Context, request GetSchemaRequest) (*GetSchemaResponse, error) { + var getSchemaResponse GetSchemaResponse + path := fmt.Sprintf("/api/2.1/unity-catalog/schemas/%v", request.FullName) + err := a.client.Get(ctx, path, request, &getSchemaResponse) + return &getSchemaResponse, err +} + +func (a *schemasImpl) ListSchemas(ctx context.Context, request ListSchemasRequest) (*ListSchemasResponse, error) { + var listSchemasResponse ListSchemasResponse + path := "/api/2.1/unity-catalog/schemas" + err := a.client.Get(ctx, path, request, &listSchemasResponse) + return &listSchemasResponse, err +} + +func (a *schemasImpl) Update(ctx context.Context, request UpdateSchema) error { + path := fmt.Sprintf("/api/2.1/unity-catalog/schemas/%v", request.FullName) + err := a.client.Patch(ctx, path, request) + return err +} + +// unexported type that holds implementations of just Shares API methods +type sharesImpl struct { + client *client.DatabricksClient +} + +func (a *sharesImpl) Create(ctx context.Context, request CreateShare) (*CreateShareResponse, error) { + var createShareResponse CreateShareResponse + path := "/api/2.1/unity-catalog/shares" + err := a.client.Post(ctx, path, request, &createShareResponse) + return &createShareResponse, err +} + +func (a *sharesImpl) DeleteShare(ctx context.Context, request DeleteShareRequest) error { + path := fmt.Sprintf("/api/2.1/unity-catalog/shares/%v", request.Name) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *sharesImpl) GetShare(ctx context.Context, request GetShareRequest) (*GetShareResponse, error) { + var getShareResponse GetShareResponse + path := fmt.Sprintf("/api/2.1/unity-catalog/shares/%v", request.Name) + err := a.client.Get(ctx, path, request, &getShareResponse) + return &getShareResponse, err +} + +func (a *sharesImpl) GetSharePermissions(ctx context.Context, request GetSharePermissionsRequest) (*GetSharePermissionsResponse, error) { + var getSharePermissionsResponse GetSharePermissionsResponse + path := fmt.Sprintf("/api/2.1/unity-catalog/shares/%v/permissions", request.Name) + err := a.client.Get(ctx, path, request, &getSharePermissionsResponse) + return &getSharePermissionsResponse, err +} + +func (a *sharesImpl) ListShares(ctx context.Context) (*ListSharesResponse, error) { + var listSharesResponse ListSharesResponse + path := "/api/2.1/unity-catalog/shares" + err := a.client.Get(ctx, path, nil, &listSharesResponse) + return &listSharesResponse, err +} + +func (a *sharesImpl) Update(ctx context.Context, request UpdateShare) error { + path := fmt.Sprintf("/api/2.1/unity-catalog/shares/%v", request.Name) + err := a.client.Patch(ctx, path, request) + return err +} + +func (a *sharesImpl) UpdateSharePermissions(ctx context.Context, request UpdateSharePermissions) error { + path := fmt.Sprintf("/api/2.1/unity-catalog/shares/%v/permissions", request.Name) + err := a.client.Patch(ctx, path, request) + return err +} + +// unexported type that holds implementations of just StorageCredentials API methods +type storageCredentialsImpl struct { + client *client.DatabricksClient +} + +func (a *storageCredentialsImpl) Create(ctx context.Context, request CreateStorageCredential) (*CreateStorageCredentialResponse, error) { + var createStorageCredentialResponse CreateStorageCredentialResponse + path := "/api/2.1/unity-catalog/storage-credentials" + err := a.client.Post(ctx, path, request, &createStorageCredentialResponse) + return &createStorageCredentialResponse, err +} + +func (a *storageCredentialsImpl) DeleteStorageCredential(ctx context.Context, request DeleteStorageCredentialRequest) error { + path := fmt.Sprintf("/api/2.1/unity-catalog/storage-credentials/%v", request.Name) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *storageCredentialsImpl) GetStorageCredentials(ctx context.Context, request GetStorageCredentialsRequest) (*GetStorageCredentialResponse, error) { + var getStorageCredentialResponse GetStorageCredentialResponse + path := fmt.Sprintf("/api/2.1/unity-catalog/storage-credentials/%v", request.Name) + err := a.client.Get(ctx, path, request, &getStorageCredentialResponse) + return &getStorageCredentialResponse, err +} + +func (a *storageCredentialsImpl) ListStorageCredentials(ctx context.Context) (*ListStorageCredentialsResponse, error) { + var listStorageCredentialsResponse ListStorageCredentialsResponse + path := "/api/2.1/unity-catalog/storage-credentials" + err := a.client.Get(ctx, path, nil, &listStorageCredentialsResponse) + return &listStorageCredentialsResponse, err +} + +func (a *storageCredentialsImpl) Update(ctx context.Context, request UpdateStorageCredential) error { + path := fmt.Sprintf("/api/2.1/unity-catalog/storage-credentials/%v", request.Name) + err := a.client.Patch(ctx, path, request) + return err +} + +// unexported type that holds implementations of just Tables API methods +type tablesImpl struct { + client *client.DatabricksClient +} + +func (a *tablesImpl) Create(ctx context.Context, request CreateTable) (*CreateTableResponse, error) { + var createTableResponse CreateTableResponse + path := "/api/2.1/unity-catalog/tables" + err := a.client.Post(ctx, path, request, &createTableResponse) + return &createTableResponse, err +} + +func (a *tablesImpl) CreateStagingTable(ctx context.Context, request CreateStagingTable) (*CreateStagingTableResponse, error) { + var createStagingTableResponse CreateStagingTableResponse + path := "/api/2.1/unity-catalog/staging-tables" + err := a.client.Post(ctx, path, request, &createStagingTableResponse) + return &createStagingTableResponse, err +} + +func (a *tablesImpl) DeleteTable(ctx context.Context, request DeleteTableRequest) error { + path := fmt.Sprintf("/api/2.1/unity-catalog/tables/%v", request.FullName) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *tablesImpl) GetTable(ctx context.Context, request GetTableRequest) (*GetTableResponse, error) { + var getTableResponse GetTableResponse + path := fmt.Sprintf("/api/2.1/unity-catalog/tables/%v", request.FullName) + err := a.client.Get(ctx, path, request, &getTableResponse) + return &getTableResponse, err +} + +func (a *tablesImpl) ListTableSummaries(ctx context.Context, request ListTableSummariesRequest) (*ListTableSummariesResponse, error) { + var listTableSummariesResponse ListTableSummariesResponse + path := "/api/2.1/unity-catalog/table-summaries" + err := a.client.Get(ctx, path, request, &listTableSummariesResponse) + return &listTableSummariesResponse, err +} + +func (a *tablesImpl) ListTables(ctx context.Context, request ListTablesRequest) (*ListTablesResponse, error) { + var listTablesResponse ListTablesResponse + path := "/api/2.1/unity-catalog/tables" + err := a.client.Get(ctx, path, request, &listTablesResponse) + return &listTablesResponse, err +} + +func (a *tablesImpl) Update(ctx context.Context, request UpdateTable) error { + path := fmt.Sprintf("/api/2.1/unity-catalog/tables/%v", request.FullName) + err := a.client.Patch(ctx, path, request) + return err +} + +// unexported type that holds implementations of just UnityFiles API methods +type unityFilesImpl struct { + client *client.DatabricksClient +} + +func (a *unityFilesImpl) ListFiles(ctx context.Context, request ListFilesRequest) (*ListFilesResponse, error) { + var listFilesResponse ListFilesResponse + path := "/api/2.1/unity-catalog/files" + err := a.client.Get(ctx, path, request, &listFilesResponse) + return &listFilesResponse, err +} diff --git a/service/unitycatalog/interface.go b/service/unitycatalog/interface.go index 8710ac7df..a09bca04f 100755 --- a/service/unitycatalog/interface.go +++ b/service/unitycatalog/interface.go @@ -14,10 +14,6 @@ import ( // data centrally across all of the workspaces in a Databricks account. Users in // different workspaces can share access to the same data, depending on // privileges granted centrally in Unity Catalog. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type CatalogsService interface { // Create a catalog @@ -32,12 +28,6 @@ type CatalogsService interface { // Metastore admin or the owner of the catalog. DeleteCatalog(ctx context.Context, request DeleteCatalogRequest) error - // DeleteCatalogByName calls DeleteCatalog, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteCatalogByName(ctx context.Context, name string) error - // Get a catalog // // Gets an array of all catalogs in the current Metastore for which the user @@ -45,12 +35,6 @@ type CatalogsService interface { // account. GetCatalog(ctx context.Context, request GetCatalogRequest) (*GetCatalogResponse, error) - // GetCatalogByName calls GetCatalog, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetCatalogByName(ctx context.Context, name string) (*GetCatalogResponse, error) - // List catalogs // // Gets an array of External Locations (ExternalLocationInfo objects) from @@ -60,11 +44,6 @@ type CatalogsService interface { // Use ListCatalogsAll() to get all CatalogInfo instances ListCatalogs(ctx context.Context) (*ListCatalogsResponse, error) - // ListCatalogsAll calls ListCatalogs() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListCatalogsAll(ctx context.Context) ([]CatalogInfo, error) - // Update a catalog // // Updates the catalog that matches the supplied name. The caller must be @@ -86,10 +65,6 @@ type CatalogsService interface { // // To create external locations, you must be a metastore admin or a user with // the CREATE EXTERNAL LOCATION privilege. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type ExternalLocationsService interface { // Create an external location @@ -105,12 +80,6 @@ type ExternalLocationsService interface { // must be the owner of the external location. DeleteExternalLocation(ctx context.Context, request DeleteExternalLocationRequest) error - // DeleteExternalLocationByName calls DeleteExternalLocation, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteExternalLocationByName(ctx context.Context, name string) error - // Get an external location // // Gets an external location from the Metastore. The caller must be either a @@ -118,12 +87,6 @@ type ExternalLocationsService interface { // appropriate privilege level on the Metastore. GetExternalLocation(ctx context.Context, request GetExternalLocationRequest) (*GetExternalLocationResponse, error) - // GetExternalLocationByName calls GetExternalLocation, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetExternalLocationByName(ctx context.Context, name string) (*GetExternalLocationResponse, error) - // List external locations // // Gets an array of External Locations (ExternalLocationInfo objects) from @@ -133,11 +96,6 @@ type ExternalLocationsService interface { // Use ListExternalLocationsAll() to get all ExternalLocationInfo instances ListExternalLocations(ctx context.Context) (*ListExternalLocationsResponse, error) - // ListExternalLocationsAll calls ListExternalLocations() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListExternalLocationsAll(ctx context.Context) ([]ExternalLocationInfo, error) - // Update an external location // // Updates an external location in the Metastore. The caller must be the @@ -161,10 +119,6 @@ type ExternalLocationsService interface { // automatically grants the privilege to all current and future objects within // the catalog. Similarly, privileges granted on a schema are inherited by all // current and future objects within that schema. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type GrantsService interface { // Get permissions @@ -172,12 +126,6 @@ type GrantsService interface { // Gets the permissions for a Securable type. GetPermissions(ctx context.Context, request GetPermissionsRequest) (*GetPermissionsResponse, error) - // GetPermissionsBySecurableTypeAndFullName calls GetPermissions, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetPermissionsBySecurableTypeAndFullName(ctx context.Context, securableType string, fullName string) (*GetPermissionsResponse, error) - // Update permissions // // Updates the permissions for a Securable type. @@ -198,10 +146,6 @@ type GrantsService interface { // workspaces created before Unity Catalog was released. If your workspace // includes a legacy Hive metastore, the data in that metastore is available in // Unity Catalog in a catalog named hive_metastore. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type MetastoresService interface { // Create a Metastore @@ -222,36 +166,18 @@ type MetastoresService interface { // Deletes a Metastore. The caller must be a Metastore admin. DeleteMetastore(ctx context.Context, request DeleteMetastoreRequest) error - // DeleteMetastoreById calls DeleteMetastore, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteMetastoreById(ctx context.Context, id string) error - // Delete an assignment // // Deletes a Metastore assignment. The caller must be an account // administrator. DeleteMetastoreAssignment(ctx context.Context, request DeleteMetastoreAssignmentRequest) error - // DeleteMetastoreAssignmentByWorkspaceId calls DeleteMetastoreAssignment, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteMetastoreAssignmentByWorkspaceId(ctx context.Context, workspaceId int) error - // Get a Metastore // // Gets a Metastore that matches the supplied ID. The caller must be a // Metastore admin to retrieve this info. GetMetastore(ctx context.Context, request GetMetastoreRequest) (*GetMetastoreResponse, error) - // GetMetastoreById calls GetMetastore, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetMetastoreById(ctx context.Context, id string) (*GetMetastoreResponse, error) - // Get a summary // // Gets information about a Metastore. This summary includes the storage @@ -267,11 +193,6 @@ type MetastoresService interface { // Use ListMetastoresAll() to get all MetastoreInfo instances ListMetastores(ctx context.Context) (*ListMetastoresResponse, error) - // ListMetastoresAll calls ListMetastores() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListMetastoresAll(ctx context.Context) ([]MetastoreInfo, error) - // Update a Metastore // // Updates information for a specific Metastore. The caller must be a @@ -289,10 +210,6 @@ type MetastoresService interface { } // Databricks Delta Sharing: Providers REST API -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type ProvidersService interface { // Create an auth provider @@ -307,12 +224,6 @@ type ProvidersService interface { // is the owner of the provider. DeleteProvider(ctx context.Context, request DeleteProviderRequest) error - // DeleteProviderByName calls DeleteProvider, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteProviderByName(ctx context.Context, name string) error - // Get a provider // // Gets a specific authentication provider. The caller must supply the name @@ -320,12 +231,6 @@ type ProvidersService interface { // provider. GetProvider(ctx context.Context, request GetProviderRequest) (*GetProviderResponse, error) - // GetProviderByName calls GetProvider, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetProviderByName(ctx context.Context, name string) (*GetProviderResponse, error) - // List providers // // Gets an array of available authentication providers. The caller must @@ -335,11 +240,6 @@ type ProvidersService interface { // Use ListProvidersAll() to get all ProviderInfo instances ListProviders(ctx context.Context, request ListProvidersRequest) (*ListProvidersResponse, error) - // ListProvidersAll calls ListProviders() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListProvidersAll(ctx context.Context, request ListProvidersRequest) ([]ProviderInfo, error) - // List shares // // Gets an array of all shares within the Metastore where: @@ -347,12 +247,6 @@ type ProvidersService interface { // * the caller is a Metastore admin, or * the caller is the owner. ListShares(ctx context.Context, request ListSharesRequest) (*ListProviderSharesResponse, error) - // ListSharesByName calls ListShares, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - ListSharesByName(ctx context.Context, name string) (*ListProviderSharesResponse, error) - // Update a provider // // Updates the information for an authentication provider, if the caller is @@ -363,10 +257,6 @@ type ProvidersService interface { } // Databricks Delta Sharing: Recipient Activation REST API -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type RecipientActivationService interface { // Get a share activation URL @@ -374,30 +264,14 @@ type RecipientActivationService interface { // Gets information about an Activation URL. GetActivationUrlInfo(ctx context.Context, request GetActivationUrlInfoRequest) error - // GetActivationUrlInfoByActivationUrl calls GetActivationUrlInfo, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetActivationUrlInfoByActivationUrl(ctx context.Context, activationUrl string) error - // Get an access token // // RPC to retrieve access token with an activation token. This is a public // API without any authentication. RetrieveToken(ctx context.Context, request RetrieveTokenRequest) (*RetrieveTokenResponse, error) - - // RetrieveTokenByActivationUrl calls RetrieveToken, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - RetrieveTokenByActivationUrl(ctx context.Context, activationUrl string) (*RetrieveTokenResponse, error) } // Databricks Delta Sharing: Recipients REST API -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type RecipientsService interface { // Create a share recipient @@ -413,12 +287,6 @@ type RecipientsService interface { // the owner of the recipient. DeleteRecipient(ctx context.Context, request DeleteRecipientRequest) error - // DeleteRecipientByName calls DeleteRecipient, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteRecipientByName(ctx context.Context, name string) error - // Get a share recipient // // Gets a share recipient from the Metastore if: @@ -427,24 +295,12 @@ type RecipientsService interface { // admin GetRecipient(ctx context.Context, request GetRecipientRequest) (*GetRecipientResponse, error) - // GetRecipientByName calls GetRecipient, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetRecipientByName(ctx context.Context, name string) (*GetRecipientResponse, error) - // Get share permissions // // Gets the share permissions for the specified Recipient. The caller must // be a Metastore admin or the owner of the Recipient. GetRecipientSharePermissions(ctx context.Context, request GetRecipientSharePermissionsRequest) (*GetRecipientSharePermissionsResponse, error) - // GetRecipientSharePermissionsByName calls GetRecipientSharePermissions, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetRecipientSharePermissionsByName(ctx context.Context, name string) (*GetRecipientSharePermissionsResponse, error) - // List share recipients // // Gets an array of all share recipients within the current Metastore where: @@ -454,11 +310,6 @@ type RecipientsService interface { // Use ListRecipientsAll() to get all RecipientInfo instances ListRecipients(ctx context.Context, request ListRecipientsRequest) (*ListRecipientsResponse, error) - // ListRecipientsAll calls ListRecipients() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListRecipientsAll(ctx context.Context, request ListRecipientsRequest) ([]RecipientInfo, error) - // Rotate a token // // Refreshes the specified recipient's delta sharing authentication token @@ -480,10 +331,6 @@ type RecipientsService interface { // list) a table or view in a schema, users must have the USAGE data permission // on the schema and its parent catalog, and they must have the SELECT // permission on the table or view. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type SchemasService interface { // Create a schema @@ -498,12 +345,6 @@ type SchemasService interface { // the owner of the schema or an owner of the parent catalog. DeleteSchema(ctx context.Context, request DeleteSchemaRequest) error - // DeleteSchemaByFullName calls DeleteSchema, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteSchemaByFullName(ctx context.Context, fullName string) error - // Get a schema // // Gets the specified schema for a catalog in the Metastore. The caller must @@ -511,12 +352,6 @@ type SchemasService interface { // USAGE privilege on the schema. GetSchema(ctx context.Context, request GetSchemaRequest) (*GetSchemaResponse, error) - // GetSchemaByFullName calls GetSchema, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetSchemaByFullName(ctx context.Context, fullName string) (*GetSchemaResponse, error) - // List schemas // // Gets an array of schemas for catalog in the Metastore. If the caller is @@ -528,11 +363,6 @@ type SchemasService interface { // Use ListSchemasAll() to get all SchemaInfo instances ListSchemas(ctx context.Context, request ListSchemasRequest) (*ListSchemasResponse, error) - // ListSchemasAll calls ListSchemas() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListSchemasAll(ctx context.Context, request ListSchemasRequest) ([]SchemaInfo, error) - // Update a schema // // Updates a schema for a catalog. The caller must be the owner of the @@ -544,10 +374,6 @@ type SchemasService interface { } // Databricks Delta Sharing: Shares REST API -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type SharesService interface { // Create a share @@ -563,36 +389,18 @@ type SharesService interface { // owner of the share. DeleteShare(ctx context.Context, request DeleteShareRequest) error - // DeleteShareByName calls DeleteShare, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteShareByName(ctx context.Context, name string) error - // Get a share // // Gets a data object share from the Metastore. The caller must be a // Metastore admin or the owner of the share. GetShare(ctx context.Context, request GetShareRequest) (*GetShareResponse, error) - // GetShareByName calls GetShare, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetShareByName(ctx context.Context, name string) (*GetShareResponse, error) - // Get permissions // // Gets the permissions for a data share from the Metastore. The caller must // be a Metastore admin or the owner of the share. GetSharePermissions(ctx context.Context, request GetSharePermissionsRequest) (*GetSharePermissionsResponse, error) - // GetSharePermissionsByName calls GetSharePermissions, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetSharePermissionsByName(ctx context.Context, name string) (*GetSharePermissionsResponse, error) - // List shares // // Gets an array of data object shares from the Metastore. The caller must @@ -601,11 +409,6 @@ type SharesService interface { // Use ListSharesAll() to get all ShareInfo instances ListShares(ctx context.Context) (*ListSharesResponse, error) - // ListSharesAll calls ListShares() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListSharesAll(ctx context.Context) ([]ShareInfo, error) - // Update a share // // Updates the share with the changes and data objects in the request. The @@ -649,10 +452,6 @@ type SharesService interface { // To create storage credentials, you must be a Databricks account admin. The // account admin who creates the storage credential can delegate ownership to // another user or group to manage permissions on it. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type StorageCredentialsService interface { // Create credentials @@ -673,12 +472,6 @@ type StorageCredentialsService interface { // owner of the storage credential. DeleteStorageCredential(ctx context.Context, request DeleteStorageCredentialRequest) error - // DeleteStorageCredentialByName calls DeleteStorageCredential, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteStorageCredentialByName(ctx context.Context, name string) error - // Get a credential // // Gets a storage credential from the Metastore. The caller must be a @@ -686,12 +479,6 @@ type StorageCredentialsService interface { // privilege on the storage credential. GetStorageCredentials(ctx context.Context, request GetStorageCredentialsRequest) (*GetStorageCredentialResponse, error) - // GetStorageCredentialsByName calls GetStorageCredentials, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetStorageCredentialsByName(ctx context.Context, name string) (*GetStorageCredentialResponse, error) - // List credentials // // Gets an array of storage credentials (as StorageCredentialInfo objects). @@ -702,11 +489,6 @@ type StorageCredentialsService interface { // Use ListStorageCredentialsAll() to get all StorageCredentialInfo instances ListStorageCredentials(ctx context.Context) (*ListStorageCredentialsResponse, error) - // ListStorageCredentialsAll calls ListStorageCredentials() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListStorageCredentialsAll(ctx context.Context) ([]StorageCredentialInfo, error) - // Update a credential // // Updates a storage credential on the Metastore. The caller must be the @@ -723,10 +505,6 @@ type StorageCredentialsService interface { // its parent schema and catalog. // // A table can be managed or external. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type TablesService interface { // Create a table @@ -759,12 +537,6 @@ type TablesService interface { // schema. DeleteTable(ctx context.Context, request DeleteTableRequest) error - // DeleteTableByFullName calls DeleteTable, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteTableByFullName(ctx context.Context, fullName string) error - // Get a table // // Gets a table from the Metastore for a specific catalog and schema. The @@ -773,12 +545,6 @@ type TablesService interface { // the table and have the SELECT privilege on it as well. GetTable(ctx context.Context, request GetTableRequest) (*GetTableResponse, error) - // GetTableByFullName calls GetTable, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetTableByFullName(ctx context.Context, fullName string) (*GetTableResponse, error) - // List table summaries // // Gets an array of summaries for tables for a schema and catalog within the @@ -803,11 +569,6 @@ type TablesService interface { // Use ListTablesAll() to get all TableInfo instances ListTables(ctx context.Context, request ListTablesRequest) (*ListTablesResponse, error) - // ListTablesAll calls ListTables() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListTablesAll(ctx context.Context, request ListTablesRequest) ([]TableInfo, error) - // Update a table // // Updates a table in the specified catalog and schema. The caller must be @@ -817,10 +578,6 @@ type TablesService interface { } // Databricks Unity Catalog: Files REST API -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type UnityFilesService interface { // List files diff --git a/service/warehouses/api.go b/service/warehouses/api.go index e352ea35a..aec10c194 100755 --- a/service/warehouses/api.go +++ b/service/warehouses/api.go @@ -12,14 +12,31 @@ import ( "github.com/databricks/databricks-sdk-go/databricks/useragent" ) -func NewQueryHistory(client *client.DatabricksClient) QueryHistoryService { +func NewQueryHistory(client *client.DatabricksClient) *QueryHistoryAPI { return &QueryHistoryAPI{ - client: client, + impl: &queryHistoryImpl{ + client: client, + }, } } +// Access the history of queries through SQL warehouses. type QueryHistoryAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(QueryHistoryService) + impl QueryHistoryService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *QueryHistoryAPI) WithImpl(impl QueryHistoryService) *QueryHistoryAPI { + a.impl = impl + return a +} + +// Impl returns low-level QueryHistory API implementation +func (a *QueryHistoryAPI) Impl() QueryHistoryService { + return a.impl } // List @@ -28,22 +45,12 @@ type QueryHistoryAPI struct { // // You can filter by user ID, warehouse ID, status, and time range. // -// Use ListQueriesAll() to get all QueryInfo instances, which will iterate over every result page. -func (a *QueryHistoryAPI) ListQueries(ctx context.Context, request ListQueriesRequest) (*ListQueriesResponse, error) { - var listQueriesResponse ListQueriesResponse - path := "/api/2.0/sql/history/queries" - err := a.client.Get(ctx, path, request, &listQueriesResponse) - return &listQueriesResponse, err -} - -// ListQueriesAll returns all QueryInfo instances by calling ListQueries for every result page -// // This method is generated by Databricks SDK Code Generator. func (a *QueryHistoryAPI) ListQueriesAll(ctx context.Context, request ListQueriesRequest) ([]QueryInfo, error) { var results []QueryInfo ctx = useragent.InContext(ctx, "sdk-feature", "pagination") for { - response, err := a.ListQueries(ctx, request) + response, err := a.impl.ListQueries(ctx, request) if err != nil { return nil, err } @@ -61,27 +68,43 @@ func (a *QueryHistoryAPI) ListQueriesAll(ctx context.Context, request ListQuerie return results, nil } -func NewWarehouses(client *client.DatabricksClient) WarehousesService { +func NewWarehouses(client *client.DatabricksClient) *WarehousesAPI { return &WarehousesAPI{ - client: client, + impl: &warehousesImpl{ + client: client, + }, } } +// A SQL warehouse is a compute resource that lets you run SQL commands on data +// objects within Databricks SQL. Compute resources are infrastructure resources +// that provide processing capabilities in the cloud. type WarehousesAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(WarehousesService) + impl WarehousesService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *WarehousesAPI) WithImpl(impl WarehousesService) *WarehousesAPI { + a.impl = impl + return a +} + +// Impl returns low-level Warehouses API implementation +func (a *WarehousesAPI) Impl() WarehousesService { + return a.impl } // Create a warehouse // // Creates a new SQL warehouse. func (a *WarehousesAPI) CreateWarehouse(ctx context.Context, request CreateWarehouseRequest) (*CreateWarehouseResponse, error) { - var createWarehouseResponse CreateWarehouseResponse - path := "/api/2.0/sql/warehouses" - err := a.client.Post(ctx, path, request, &createWarehouseResponse) - return &createWarehouseResponse, err + return a.impl.CreateWarehouse(ctx, request) } -// CreateWarehouse and wait to reach RUNNING state +// Calls [WarehousesAPI.CreateWarehouse] and waits to reach RUNNING state // // You can override the default timeout of 20 minutes by calling adding // retries.Timeout[GetWarehouseResponse](60*time.Minute) functional option. @@ -127,12 +150,10 @@ func (a *WarehousesAPI) CreateWarehouseAndWait(ctx context.Context, createWareho // // Deletes a SQL warehouse. func (a *WarehousesAPI) DeleteWarehouse(ctx context.Context, request DeleteWarehouseRequest) error { - path := fmt.Sprintf("/api/2.0/sql/warehouses/%v", request.Id) - err := a.client.Delete(ctx, path, request) - return err + return a.impl.DeleteWarehouse(ctx, request) } -// DeleteWarehouse and wait to reach DELETED state +// Calls [WarehousesAPI.DeleteWarehouse] and waits to reach DELETED state // // You can override the default timeout of 20 minutes by calling adding // retries.Timeout[GetWarehouseResponse](60*time.Minute) functional option. @@ -174,7 +195,7 @@ func (a *WarehousesAPI) DeleteWarehouseAndWait(ctx context.Context, deleteWareho // // Deletes a SQL warehouse. func (a *WarehousesAPI) DeleteWarehouseById(ctx context.Context, id string) error { - return a.DeleteWarehouse(ctx, DeleteWarehouseRequest{ + return a.impl.DeleteWarehouse(ctx, DeleteWarehouseRequest{ Id: id, }) } @@ -189,12 +210,10 @@ func (a *WarehousesAPI) DeleteWarehouseByIdAndWait(ctx context.Context, id strin // // Updates the configuration for a SQL warehouse. func (a *WarehousesAPI) EditWarehouse(ctx context.Context, request EditWarehouseRequest) error { - path := fmt.Sprintf("/api/2.0/sql/warehouses/%v/edit", request.Id) - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.EditWarehouse(ctx, request) } -// EditWarehouse and wait to reach RUNNING state +// Calls [WarehousesAPI.EditWarehouse] and waits to reach RUNNING state // // You can override the default timeout of 20 minutes by calling adding // retries.Timeout[GetWarehouseResponse](60*time.Minute) functional option. @@ -240,13 +259,10 @@ func (a *WarehousesAPI) EditWarehouseAndWait(ctx context.Context, editWarehouseR // // Gets the information for a single SQL warehouse. func (a *WarehousesAPI) GetWarehouse(ctx context.Context, request GetWarehouseRequest) (*GetWarehouseResponse, error) { - var getWarehouseResponse GetWarehouseResponse - path := fmt.Sprintf("/api/2.0/sql/warehouses/%v", request.Id) - err := a.client.Get(ctx, path, request, &getWarehouseResponse) - return &getWarehouseResponse, err + return a.impl.GetWarehouse(ctx, request) } -// GetWarehouse and wait to reach RUNNING state +// Calls [WarehousesAPI.GetWarehouse] and waits to reach RUNNING state // // You can override the default timeout of 20 minutes by calling adding // retries.Timeout[GetWarehouseResponse](60*time.Minute) functional option. @@ -292,7 +308,7 @@ func (a *WarehousesAPI) GetWarehouseAndWait(ctx context.Context, getWarehouseReq // // Gets the information for a single SQL warehouse. func (a *WarehousesAPI) GetWarehouseById(ctx context.Context, id string) (*GetWarehouseResponse, error) { - return a.GetWarehouse(ctx, GetWarehouseRequest{ + return a.impl.GetWarehouse(ctx, GetWarehouseRequest{ Id: id, }) } @@ -308,29 +324,16 @@ func (a *WarehousesAPI) GetWarehouseByIdAndWait(ctx context.Context, id string, // Gets the workspace level configuration that is shared by all SQL warehouses // in a workspace. func (a *WarehousesAPI) GetWorkspaceWarehouseConfig(ctx context.Context) (*GetWorkspaceWarehouseConfigResponse, error) { - var getWorkspaceWarehouseConfigResponse GetWorkspaceWarehouseConfigResponse - path := "/api/2.0/sql/config/warehouses" - err := a.client.Get(ctx, path, nil, &getWorkspaceWarehouseConfigResponse) - return &getWorkspaceWarehouseConfigResponse, err + return a.impl.GetWorkspaceWarehouseConfig(ctx) } // List warehouses // // Lists all SQL warehouses that a user has manager permissions on. // -// Use ListWarehousesAll() to get all EndpointInfo instances -func (a *WarehousesAPI) ListWarehouses(ctx context.Context, request ListWarehousesRequest) (*ListWarehousesResponse, error) { - var listWarehousesResponse ListWarehousesResponse - path := "/api/2.0/sql/warehouses" - err := a.client.Get(ctx, path, request, &listWarehousesResponse) - return &listWarehousesResponse, err -} - -// ListWarehousesAll returns all EndpointInfo instances. This method exists for consistency purposes. -// // This method is generated by Databricks SDK Code Generator. func (a *WarehousesAPI) ListWarehousesAll(ctx context.Context, request ListWarehousesRequest) ([]EndpointInfo, error) { - response, err := a.ListWarehouses(ctx, request) + response, err := a.impl.ListWarehouses(ctx, request) if err != nil { return nil, err } @@ -342,21 +345,17 @@ func (a *WarehousesAPI) ListWarehousesAll(ctx context.Context, request ListWareh // Sets the workspace level configuration that is shared by all SQL warehouses // in a workspace. func (a *WarehousesAPI) SetWorkspaceWarehouseConfig(ctx context.Context, request SetWorkspaceWarehouseConfigRequest) error { - path := "/api/2.0/sql/config/warehouses" - err := a.client.Put(ctx, path, request) - return err + return a.impl.SetWorkspaceWarehouseConfig(ctx, request) } // Start a warehouse // // Starts a SQL warehouse. func (a *WarehousesAPI) StartWarehouse(ctx context.Context, request StartWarehouseRequest) error { - path := fmt.Sprintf("/api/2.0/sql/warehouses/%v/start", request.Id) - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.StartWarehouse(ctx, request) } -// StartWarehouse and wait to reach RUNNING state +// Calls [WarehousesAPI.StartWarehouse] and waits to reach RUNNING state // // You can override the default timeout of 20 minutes by calling adding // retries.Timeout[GetWarehouseResponse](60*time.Minute) functional option. @@ -402,12 +401,10 @@ func (a *WarehousesAPI) StartWarehouseAndWait(ctx context.Context, startWarehous // // Stops a SQL warehouse. func (a *WarehousesAPI) StopWarehouse(ctx context.Context, request StopWarehouseRequest) error { - path := fmt.Sprintf("/api/2.0/sql/warehouses/%v/stop", request.Id) - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.StopWarehouse(ctx, request) } -// StopWarehouse and wait to reach STOPPED state +// Calls [WarehousesAPI.StopWarehouse] and waits to reach STOPPED state // // You can override the default timeout of 20 minutes by calling adding // retries.Timeout[GetWarehouseResponse](60*time.Minute) functional option. diff --git a/service/warehouses/impl.go b/service/warehouses/impl.go new file mode 100755 index 000000000..c0ff023f3 --- /dev/null +++ b/service/warehouses/impl.go @@ -0,0 +1,85 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package warehouses + +import ( + "context" + "fmt" + + "github.com/databricks/databricks-sdk-go/databricks/client" +) + +// unexported type that holds implementations of just QueryHistory API methods +type queryHistoryImpl struct { + client *client.DatabricksClient +} + +func (a *queryHistoryImpl) ListQueries(ctx context.Context, request ListQueriesRequest) (*ListQueriesResponse, error) { + var listQueriesResponse ListQueriesResponse + path := "/api/2.0/sql/history/queries" + err := a.client.Get(ctx, path, request, &listQueriesResponse) + return &listQueriesResponse, err +} + +// unexported type that holds implementations of just Warehouses API methods +type warehousesImpl struct { + client *client.DatabricksClient +} + +func (a *warehousesImpl) CreateWarehouse(ctx context.Context, request CreateWarehouseRequest) (*CreateWarehouseResponse, error) { + var createWarehouseResponse CreateWarehouseResponse + path := "/api/2.0/sql/warehouses" + err := a.client.Post(ctx, path, request, &createWarehouseResponse) + return &createWarehouseResponse, err +} + +func (a *warehousesImpl) DeleteWarehouse(ctx context.Context, request DeleteWarehouseRequest) error { + path := fmt.Sprintf("/api/2.0/sql/warehouses/%v", request.Id) + err := a.client.Delete(ctx, path, request) + return err +} + +func (a *warehousesImpl) EditWarehouse(ctx context.Context, request EditWarehouseRequest) error { + path := fmt.Sprintf("/api/2.0/sql/warehouses/%v/edit", request.Id) + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *warehousesImpl) GetWarehouse(ctx context.Context, request GetWarehouseRequest) (*GetWarehouseResponse, error) { + var getWarehouseResponse GetWarehouseResponse + path := fmt.Sprintf("/api/2.0/sql/warehouses/%v", request.Id) + err := a.client.Get(ctx, path, request, &getWarehouseResponse) + return &getWarehouseResponse, err +} + +func (a *warehousesImpl) GetWorkspaceWarehouseConfig(ctx context.Context) (*GetWorkspaceWarehouseConfigResponse, error) { + var getWorkspaceWarehouseConfigResponse GetWorkspaceWarehouseConfigResponse + path := "/api/2.0/sql/config/warehouses" + err := a.client.Get(ctx, path, nil, &getWorkspaceWarehouseConfigResponse) + return &getWorkspaceWarehouseConfigResponse, err +} + +func (a *warehousesImpl) ListWarehouses(ctx context.Context, request ListWarehousesRequest) (*ListWarehousesResponse, error) { + var listWarehousesResponse ListWarehousesResponse + path := "/api/2.0/sql/warehouses" + err := a.client.Get(ctx, path, request, &listWarehousesResponse) + return &listWarehousesResponse, err +} + +func (a *warehousesImpl) SetWorkspaceWarehouseConfig(ctx context.Context, request SetWorkspaceWarehouseConfigRequest) error { + path := "/api/2.0/sql/config/warehouses" + err := a.client.Put(ctx, path, request) + return err +} + +func (a *warehousesImpl) StartWarehouse(ctx context.Context, request StartWarehouseRequest) error { + path := fmt.Sprintf("/api/2.0/sql/warehouses/%v/start", request.Id) + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *warehousesImpl) StopWarehouse(ctx context.Context, request StopWarehouseRequest) error { + path := fmt.Sprintf("/api/2.0/sql/warehouses/%v/stop", request.Id) + err := a.client.Post(ctx, path, request, nil) + return err +} diff --git a/service/warehouses/interface.go b/service/warehouses/interface.go index 393a1e239..cd345cb1e 100755 --- a/service/warehouses/interface.go +++ b/service/warehouses/interface.go @@ -4,15 +4,9 @@ package warehouses import ( "context" - - "github.com/databricks/databricks-sdk-go/databricks/retries" ) // Access the history of queries through SQL warehouses. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type QueryHistoryService interface { // List @@ -23,20 +17,11 @@ type QueryHistoryService interface { // // Use ListQueriesAll() to get all QueryInfo instances, which will iterate over every result page. ListQueries(ctx context.Context, request ListQueriesRequest) (*ListQueriesResponse, error) - - // ListQueriesAll calls ListQueries() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListQueriesAll(ctx context.Context, request ListQueriesRequest) ([]QueryInfo, error) } // A SQL warehouse is a compute resource that lets you run SQL commands on data // objects within Databricks SQL. Compute resources are infrastructure resources // that provide processing capabilities in the cloud. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type WarehousesService interface { // Create a warehouse @@ -44,61 +29,21 @@ type WarehousesService interface { // Creates a new SQL warehouse. CreateWarehouse(ctx context.Context, request CreateWarehouseRequest) (*CreateWarehouseResponse, error) - // CreateWarehouseAndWait calls CreateWarehouse() and waits to reach RUNNING state - // - // This method is generated by Databricks SDK Code Generator. - CreateWarehouseAndWait(ctx context.Context, request CreateWarehouseRequest, options ...retries.Option[GetWarehouseResponse]) (*GetWarehouseResponse, error) - // Delete a warehouse // // Deletes a SQL warehouse. DeleteWarehouse(ctx context.Context, request DeleteWarehouseRequest) error - // DeleteWarehouseAndWait calls DeleteWarehouse() and waits to reach DELETED state - // - // This method is generated by Databricks SDK Code Generator. - DeleteWarehouseAndWait(ctx context.Context, request DeleteWarehouseRequest, options ...retries.Option[GetWarehouseResponse]) (*GetWarehouseResponse, error) - // DeleteWarehouseById calls DeleteWarehouse, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - DeleteWarehouseById(ctx context.Context, id string) error - - // DeleteWarehouseByIdAndWait calls DeleteWarehouseById and waits until GetWarehouseResponse is in desired state. - // - // This method is generated by Databricks SDK Code Generator. - DeleteWarehouseByIdAndWait(ctx context.Context, id string, options ...retries.Option[GetWarehouseResponse]) (*GetWarehouseResponse, error) - // Update a warehouse // // Updates the configuration for a SQL warehouse. EditWarehouse(ctx context.Context, request EditWarehouseRequest) error - // EditWarehouseAndWait calls EditWarehouse() and waits to reach RUNNING state - // - // This method is generated by Databricks SDK Code Generator. - EditWarehouseAndWait(ctx context.Context, request EditWarehouseRequest, options ...retries.Option[GetWarehouseResponse]) (*GetWarehouseResponse, error) - // Get warehouse info // // Gets the information for a single SQL warehouse. GetWarehouse(ctx context.Context, request GetWarehouseRequest) (*GetWarehouseResponse, error) - // GetWarehouseAndWait calls GetWarehouse() and waits to reach RUNNING state - // - // This method is generated by Databricks SDK Code Generator. - GetWarehouseAndWait(ctx context.Context, request GetWarehouseRequest, options ...retries.Option[GetWarehouseResponse]) (*GetWarehouseResponse, error) - // GetWarehouseById calls GetWarehouse, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetWarehouseById(ctx context.Context, id string) (*GetWarehouseResponse, error) - - // GetWarehouseByIdAndWait calls GetWarehouseById and waits until GetWarehouseResponse is in desired state. - // - // This method is generated by Databricks SDK Code Generator. - GetWarehouseByIdAndWait(ctx context.Context, id string, options ...retries.Option[GetWarehouseResponse]) (*GetWarehouseResponse, error) - // Get a configuration // // Gets the workspace level configuration that is shared by all SQL @@ -112,11 +57,6 @@ type WarehousesService interface { // Use ListWarehousesAll() to get all EndpointInfo instances ListWarehouses(ctx context.Context, request ListWarehousesRequest) (*ListWarehousesResponse, error) - // ListWarehousesAll calls ListWarehouses() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListWarehousesAll(ctx context.Context, request ListWarehousesRequest) ([]EndpointInfo, error) - // Set a configuration // // Sets the workspace level configuration that is shared by all SQL @@ -128,18 +68,8 @@ type WarehousesService interface { // Starts a SQL warehouse. StartWarehouse(ctx context.Context, request StartWarehouseRequest) error - // StartWarehouseAndWait calls StartWarehouse() and waits to reach RUNNING state - // - // This method is generated by Databricks SDK Code Generator. - StartWarehouseAndWait(ctx context.Context, request StartWarehouseRequest, options ...retries.Option[GetWarehouseResponse]) (*GetWarehouseResponse, error) - // Stop a warehouse // // Stops a SQL warehouse. StopWarehouse(ctx context.Context, request StopWarehouseRequest) error - - // StopWarehouseAndWait calls StopWarehouse() and waits to reach STOPPED state - // - // This method is generated by Databricks SDK Code Generator. - StopWarehouseAndWait(ctx context.Context, request StopWarehouseRequest, options ...retries.Option[GetWarehouseResponse]) (*GetWarehouseResponse, error) } diff --git a/service/workspace/api.go b/service/workspace/api.go index b9512d9ef..085c7ac38 100755 --- a/service/workspace/api.go +++ b/service/workspace/api.go @@ -8,14 +8,35 @@ import ( "github.com/databricks/databricks-sdk-go/databricks/client" ) -func NewWorkspace(client *client.DatabricksClient) WorkspaceService { +func NewWorkspace(client *client.DatabricksClient) *WorkspaceAPI { return &WorkspaceAPI{ - client: client, + impl: &workspaceImpl{ + client: client, + }, } } +// The Workspace API allows you to list, import, export, and delete notebooks +// and folders. +// +// A notebook is a web-based interface to a document that contains runnable +// code, visualizations, and explanatory text. type WorkspaceAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(WorkspaceService) + impl WorkspaceService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *WorkspaceAPI) WithImpl(impl WorkspaceService) *WorkspaceAPI { + a.impl = impl + return a +} + +// Impl returns low-level Workspace API implementation +func (a *WorkspaceAPI) Impl() WorkspaceService { + return a.impl } // Delete a workspace object @@ -29,9 +50,7 @@ type WorkspaceAPI struct { // Object deletion cannot be undone and deleting a directory recursively is not // atomic. func (a *WorkspaceAPI) Delete(ctx context.Context, request Delete) error { - path := "/api/2.0/workspace/delete" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.Delete(ctx, request) } // Export a notebook @@ -49,10 +68,7 @@ func (a *WorkspaceAPI) Delete(ctx context.Context, request Delete) error { // “direct_download“. Example: `curl -n -o example.scala // 'https://XX.cloud.databricks.com/api/2.0/workspace/export?path=/Users/user@example.com/ScalaExampleNotebook&direct_download=true'` func (a *WorkspaceAPI) Export(ctx context.Context, request ExportRequest) (*ExportResponse, error) { - var exportResponse ExportResponse - path := "/api/2.0/workspace/export" - err := a.client.Get(ctx, path, request, &exportResponse) - return &exportResponse, err + return a.impl.Export(ctx, request) } // Get status @@ -60,10 +76,7 @@ func (a *WorkspaceAPI) Export(ctx context.Context, request ExportRequest) (*Expo // Gets the status of an object or a directory. If “path“ does not exist, this // call returns an error “RESOURCE_DOES_NOT_EXIST“. func (a *WorkspaceAPI) GetStatus(ctx context.Context, request GetStatusRequest) (*ObjectInfo, error) { - var objectInfo ObjectInfo - path := "/api/2.0/workspace/get-status" - err := a.client.Get(ctx, path, request, &objectInfo) - return &objectInfo, err + return a.impl.GetStatus(ctx, request) } // Get status @@ -71,7 +84,7 @@ func (a *WorkspaceAPI) GetStatus(ctx context.Context, request GetStatusRequest) // Gets the status of an object or a directory. If “path“ does not exist, this // call returns an error “RESOURCE_DOES_NOT_EXIST“. func (a *WorkspaceAPI) GetStatusByPath(ctx context.Context, path string) (*ObjectInfo, error) { - return a.GetStatus(ctx, GetStatusRequest{ + return a.impl.GetStatus(ctx, GetStatusRequest{ Path: path, }) } @@ -83,9 +96,7 @@ func (a *WorkspaceAPI) GetStatusByPath(ctx context.Context, path string) (*Objec // error “RESOURCE_ALREADY_EXISTS“. One can only use “DBC“ format to import // a directory. func (a *WorkspaceAPI) Import(ctx context.Context, request Import) error { - path := "/api/2.0/workspace/import" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.Import(ctx, request) } // List contents @@ -94,19 +105,9 @@ func (a *WorkspaceAPI) Import(ctx context.Context, request Import) error { // the input path does not exist, this call returns an error // “RESOURCE_DOES_NOT_EXIST“. // -// Use ListAll() to get all ObjectInfo instances -func (a *WorkspaceAPI) List(ctx context.Context, request ListRequest) (*ListResponse, error) { - var listResponse ListResponse - path := "/api/2.0/workspace/list" - err := a.client.Get(ctx, path, request, &listResponse) - return &listResponse, err -} - -// ListAll returns all ObjectInfo instances. This method exists for consistency purposes. -// // This method is generated by Databricks SDK Code Generator. func (a *WorkspaceAPI) ListAll(ctx context.Context, request ListRequest) ([]ObjectInfo, error) { - response, err := a.List(ctx, request) + response, err := a.impl.List(ctx, request) if err != nil { return nil, err } @@ -122,9 +123,7 @@ func (a *WorkspaceAPI) ListAll(ctx context.Context, request ListRequest) ([]Obje // Note that if this operation fails it may have succeeded in creating some of // the necessary\nparrent directories. func (a *WorkspaceAPI) Mkdirs(ctx context.Context, request Mkdirs) error { - path := "/api/2.0/workspace/mkdirs" - err := a.client.Post(ctx, path, request, nil) - return err + return a.impl.Mkdirs(ctx, request) } // Create a directory @@ -136,7 +135,7 @@ func (a *WorkspaceAPI) Mkdirs(ctx context.Context, request Mkdirs) error { // Note that if this operation fails it may have succeeded in creating some of // the necessary\nparrent directories. func (a *WorkspaceAPI) MkdirsByPath(ctx context.Context, path string) error { - return a.Mkdirs(ctx, Mkdirs{ + return a.impl.Mkdirs(ctx, Mkdirs{ Path: path, }) } diff --git a/service/workspace/impl.go b/service/workspace/impl.go new file mode 100755 index 000000000..06fbc6728 --- /dev/null +++ b/service/workspace/impl.go @@ -0,0 +1,53 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package workspace + +import ( + "context" + + "github.com/databricks/databricks-sdk-go/databricks/client" +) + +// unexported type that holds implementations of just Workspace API methods +type workspaceImpl struct { + client *client.DatabricksClient +} + +func (a *workspaceImpl) Delete(ctx context.Context, request Delete) error { + path := "/api/2.0/workspace/delete" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *workspaceImpl) Export(ctx context.Context, request ExportRequest) (*ExportResponse, error) { + var exportResponse ExportResponse + path := "/api/2.0/workspace/export" + err := a.client.Get(ctx, path, request, &exportResponse) + return &exportResponse, err +} + +func (a *workspaceImpl) GetStatus(ctx context.Context, request GetStatusRequest) (*ObjectInfo, error) { + var objectInfo ObjectInfo + path := "/api/2.0/workspace/get-status" + err := a.client.Get(ctx, path, request, &objectInfo) + return &objectInfo, err +} + +func (a *workspaceImpl) Import(ctx context.Context, request Import) error { + path := "/api/2.0/workspace/import" + err := a.client.Post(ctx, path, request, nil) + return err +} + +func (a *workspaceImpl) List(ctx context.Context, request ListRequest) (*ListResponse, error) { + var listResponse ListResponse + path := "/api/2.0/workspace/list" + err := a.client.Get(ctx, path, request, &listResponse) + return &listResponse, err +} + +func (a *workspaceImpl) Mkdirs(ctx context.Context, request Mkdirs) error { + path := "/api/2.0/workspace/mkdirs" + err := a.client.Post(ctx, path, request, nil) + return err +} diff --git a/service/workspace/interface.go b/service/workspace/interface.go index 1c3b49b26..bdec0059f 100755 --- a/service/workspace/interface.go +++ b/service/workspace/interface.go @@ -11,10 +11,6 @@ import ( // // A notebook is a web-based interface to a document that contains runnable // code, visualizations, and explanatory text. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type WorkspaceService interface { // Delete a workspace object @@ -52,12 +48,6 @@ type WorkspaceService interface { // this call returns an error ``RESOURCE_DOES_NOT_EXIST``. GetStatus(ctx context.Context, request GetStatusRequest) (*ObjectInfo, error) - // GetStatusByPath calls GetStatus, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - GetStatusByPath(ctx context.Context, path string) (*ObjectInfo, error) - // Import a notebook // // Imports a notebook or the contents of an entire directory. If ``path`` @@ -75,11 +65,6 @@ type WorkspaceService interface { // Use ListAll() to get all ObjectInfo instances List(ctx context.Context, request ListRequest) (*ListResponse, error) - // ListAll calls List() to retrieve all available results from the platform. - // - // This method is generated by Databricks SDK Code Generator. - ListAll(ctx context.Context, request ListRequest) ([]ObjectInfo, error) - // Create a directory // // Creates the specified directory (and necessary parent directories if they @@ -89,10 +74,4 @@ type WorkspaceService interface { // Note that if this operation fails it may have succeeded in creating some // of the necessary\nparrent directories. Mkdirs(ctx context.Context, request Mkdirs) error - - // MkdirsByPath calls Mkdirs, but directly with primitive function arguments, - // instead of constructing request instance. - // - // This method is generated by Databricks SDK Code Generator. - MkdirsByPath(ctx context.Context, path string) error } diff --git a/service/workspaceconf/api.go b/service/workspaceconf/api.go index 0676b2875..b7c03a22e 100755 --- a/service/workspaceconf/api.go +++ b/service/workspaceconf/api.go @@ -8,24 +8,38 @@ import ( "github.com/databricks/databricks-sdk-go/databricks/client" ) -func NewWorkspaceConf(client *client.DatabricksClient) WorkspaceConfService { +func NewWorkspaceConf(client *client.DatabricksClient) *WorkspaceConfAPI { return &WorkspaceConfAPI{ - client: client, + impl: &workspaceConfImpl{ + client: client, + }, } } +// This API allows updating known workspace settings for advanced users. type WorkspaceConfAPI struct { - client *client.DatabricksClient + // impl contains low-level REST API interface, that could be overridden + // through WithImpl(WorkspaceConfService) + impl WorkspaceConfService +} + +// WithImpl could be used to override low-level API implementations for unit +// testing purposes with [github.com/golang/mock] or other mocking frameworks. +func (a *WorkspaceConfAPI) WithImpl(impl WorkspaceConfService) *WorkspaceConfAPI { + a.impl = impl + return a +} + +// Impl returns low-level WorkspaceConf API implementation +func (a *WorkspaceConfAPI) Impl() WorkspaceConfService { + return a.impl } // Check configuration status // // Gets the configuration status for a workspace. func (a *WorkspaceConfAPI) GetStatus(ctx context.Context, request GetStatusRequest) (*WorkspaceConf, error) { - var workspaceConf WorkspaceConf - path := "/api/2.0/workspace-conf" - err := a.client.Get(ctx, path, request, &workspaceConf) - return &workspaceConf, err + return a.impl.GetStatus(ctx, request) } // Enable/disable features @@ -33,7 +47,5 @@ func (a *WorkspaceConfAPI) GetStatus(ctx context.Context, request GetStatusReque // Sets the configuration status for a workspace, including enabling or // disabling it. func (a *WorkspaceConfAPI) SetStatus(ctx context.Context, request WorkspaceConf) error { - path := "/api/2.0/workspace-conf" - err := a.client.Patch(ctx, path, request) - return err + return a.impl.SetStatus(ctx, request) } diff --git a/service/workspaceconf/impl.go b/service/workspaceconf/impl.go new file mode 100755 index 000000000..4a98585f2 --- /dev/null +++ b/service/workspaceconf/impl.go @@ -0,0 +1,27 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package workspaceconf + +import ( + "context" + + "github.com/databricks/databricks-sdk-go/databricks/client" +) + +// unexported type that holds implementations of just WorkspaceConf API methods +type workspaceConfImpl struct { + client *client.DatabricksClient +} + +func (a *workspaceConfImpl) GetStatus(ctx context.Context, request GetStatusRequest) (*WorkspaceConf, error) { + var workspaceConf WorkspaceConf + path := "/api/2.0/workspace-conf" + err := a.client.Get(ctx, path, request, &workspaceConf) + return &workspaceConf, err +} + +func (a *workspaceConfImpl) SetStatus(ctx context.Context, request WorkspaceConf) error { + path := "/api/2.0/workspace-conf" + err := a.client.Patch(ctx, path, request) + return err +} diff --git a/service/workspaceconf/interface.go b/service/workspaceconf/interface.go index ce6a98bcb..e6198bacd 100755 --- a/service/workspaceconf/interface.go +++ b/service/workspaceconf/interface.go @@ -7,10 +7,6 @@ import ( ) // This API allows updating known workspace settings for advanced users. -// -// This is the high-level interface, that contains generated methods. -// -// Evolving: this interface is under development. Method signatures may change. type WorkspaceConfService interface { // Check configuration status diff --git a/workspaces/client.go b/workspaces/client.go index 8a148dd76..013c2daae 100644 --- a/workspaces/client.go +++ b/workspaces/client.go @@ -1,8 +1,11 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + package workspaces import ( "github.com/databricks/databricks-sdk-go/databricks" "github.com/databricks/databricks-sdk-go/databricks/client" + "github.com/databricks/databricks-sdk-go/service/clusterpolicies" "github.com/databricks/databricks-sdk-go/service/clusters" "github.com/databricks/databricks-sdk-go/service/commands" @@ -11,7 +14,6 @@ import ( "github.com/databricks/databricks-sdk-go/service/gitcredentials" "github.com/databricks/databricks-sdk-go/service/globalinitscripts" "github.com/databricks/databricks-sdk-go/service/instancepools" - "github.com/databricks/databricks-sdk-go/service/instanceprofiles" "github.com/databricks/databricks-sdk-go/service/ipaccesslists" "github.com/databricks/databricks-sdk-go/service/jobs" "github.com/databricks/databricks-sdk-go/service/libraries" @@ -32,58 +34,450 @@ import ( type WorkspacesClient struct { Config *databricks.Config - Alerts dbsql.AlertsService - Catalogs unitycatalog.CatalogsService - ClusterPolicies clusterpolicies.ClusterPoliciesService - Clusters clusters.ClustersService - CommandExecutor commands.CommandExecutor - CurrentUser scim.CurrentUserService - Dashboards dbsql.DashboardsService - DataSources dbsql.DataSourcesService - Dbfs dbfs.DbfsService - DbsqlPermissions dbsql.DbsqlPermissionsService - Experiments mlflow.ExperimentsService - ExternalLocations unitycatalog.ExternalLocationsService - GitCredentials gitcredentials.GitCredentialsService - GlobalInitScripts globalinitscripts.GlobalInitScriptsService - Grants unitycatalog.GrantsService - Groups scim.GroupsService - Jobs jobs.JobsService - InstancePools instancepools.InstancePoolsService - InstanceProfiles instanceprofiles.InstanceprofilesService - IpAccessLists ipaccesslists.IpAccessListsService - Libraries libraries.LibrariesService - Metastores unitycatalog.MetastoresService - MLflowArtifacts mlflow.MLflowArtifactsService - MLflowDatabricks mlflow.MLflowDatabricksService - MLflowMetrics mlflow.MLflowMetricsService - MLflowRuns mlflow.MLflowRunsService - ModelVersions mlflow.ModelVersionsService - ModelVersionComments mlflow.ModelVersionCommentsService - Pipelines pipelines.PipelinesService - Permissions permissions.PermissionsService - Providers unitycatalog.ProvidersService - RecipientActivation unitycatalog.RecipientActivationService - Recipients unitycatalog.RecipientsService - RegisteredModels mlflow.RegisteredModelsService - RegistryWebhooks mlflow.RegistryWebhooksService - Repos repos.ReposService - Schemas unitycatalog.SchemasService - Secrets secrets.SecretsService - Shares unitycatalog.SharesService - ServicePrincipals scim.ServicePrincipalsService - StorageCredentials unitycatalog.StorageCredentialsService - Tables unitycatalog.TablesService - Tokens tokens.TokensService - TokenManagement tokenmanagement.TokenManagementService - TransitionRequests mlflow.TransitionRequestsService - Queries dbsql.QueriesService - QueryHistory warehouses.QueryHistoryService - UnityFiles unitycatalog.UnityFilesService - Users scim.UsersService - Warehouses warehouses.WarehousesService - Workspace workspace.WorkspaceService - WorkspaceConf workspaceconf.WorkspaceConfService + // The alerts API can be used to perform CRUD operations on alerts. An alert + // is a Databricks SQL object that periodically runs a query, evaluates a + // condition of its result, and notifies one or more users and/or alert + // destinations if the condition was met. + Alerts *dbsql.AlertsAPI + + // A catalog is the first layer of Unity Catalog’s three-level namespace. + // It’s used to organize your data assets. Users can see all catalogs on + // which they have been assigned the USAGE data permission. + // + // In Unity Catalog, admins and data stewards manage users and their access + // to data centrally across all of the workspaces in a Databricks account. + // Users in different workspaces can share access to the same data, + // depending on privileges granted centrally in Unity Catalog. + Catalogs *unitycatalog.CatalogsAPI + + // Cluster policy limits the ability to configure clusters based on a set of + // rules. The policy rules limit the attributes or attribute values + // available for cluster creation. Cluster policies have ACLs that limit + // their use to specific users and groups. + // + // Cluster policies let you limit users to create clusters with prescribed + // settings, simplify the user interface and enable more users to create + // their own clusters (by fixing and hiding some values), control cost by + // limiting per cluster maximum cost (by setting limits on attributes whose + // values contribute to hourly price). + // + // Cluster policy permissions limit which policies a user can select in the + // Policy drop-down when the user creates a cluster: - A user who has + // cluster create permission can select the Unrestricted policy and create + // fully-configurable clusters. - A user who has both cluster create + // permission and access to cluster policies can select the Unrestricted + // policy and policies they have access to. - A user that has access to only + // cluster policies, can select the policies they have access to. + // + // If no policies have been created in the workspace, the Policy drop-down + // does not display. + // + // Only admin users can create, edit, and delete policies. Admin users also + // have access to all policies. + ClusterPolicies *clusterpolicies.ClusterPoliciesAPI + + // The Clusters API allows you to create, start, edit, list, terminate, and + // delete clusters. + // + // Databricks maps cluster node instance types to compute units known as + // DBUs. See the instance type pricing page for a list of the supported + // instance types and their corresponding DBUs. + // + // A Databricks cluster is a set of computation resources and configurations + // on which you run data engineering, data science, and data analytics + // workloads, such as production ETL pipelines, streaming analytics, ad-hoc + // analytics, and machine learning. + // + // You run these workloads as a set of commands in a notebook or as an + // automated job. Databricks makes a distinction between all-purpose + // clusters and job clusters. You use all-purpose clusters to analyze data + // collaboratively using interactive notebooks. You use job clusters to run + // fast and robust automated jobs. + // + // You can create an all-purpose cluster using the UI, CLI, or REST API. You + // can manually terminate and restart an all-purpose cluster. Multiple users + // can share such clusters to do collaborative interactive analysis. + // + // IMPORTANT: Databricks retains cluster configuration information for up to + // 200 all-purpose clusters terminated in the last 30 days and up to 30 job + // clusters recently terminated by the job scheduler. To keep an all-purpose + // cluster configuration even after it has been terminated for more than 30 + // days, an administrator can pin a cluster to the cluster list. + Clusters *clusters.ClustersAPI + + // This API allows executing commands on running clusters. + CommandExecutor commands.CommandExecutor + + // This API allows retrieving information about currently authenticated user + // or service principal. + CurrentUser *scim.CurrentUserAPI + + // In general, there is little need to modify dashboards using the API. + // However, it can be useful to use dashboard objects to look-up a + // collection of related query IDs. The API can also be used to duplicate + // multiple dashboards at once since you can get a dashboard definition with + // a GET request and then POST it to create a new one. + Dashboards *dbsql.DashboardsAPI + + // This API is provided to assist you in making new query objects. When + // creating a query object, you may optionally specify a `data_source_id` + // for the SQL warehouse against which it will run. If you don't already + // know the `data_source_id` for your desired SQL warehouse, this API will + // help you find it. + // + // This API does not support searches. It returns the full list of SQL + // warehouses in your workspace. We advise you to use any text editor, REST + // client, or `grep` to search the response from this API for the name of + // your SQL warehouse as it appears in Databricks SQL. + DataSources *dbsql.DataSourcesAPI + + // DBFS API makes it simple to interact with various data sources without + // having to include a users credentials every time to read a file. + Dbfs *dbfs.DbfsAPI + + // The SQL Permissions API is similar to the endpoints of the + // :method:permissions/setobjectpermissions. However, this exposes only one + // endpoint, which gets the Access Control List for a given object. You + // cannot modify any permissions using this API. + // + // There are three levels of permission: + // + // - `CAN_VIEW`: Allows read-only access + // + // - `CAN_RUN`: Allows read access and run access (superset of `CAN_VIEW`) + // + // - `CAN_MANAGE`: Allows all actions: read, run, edit, delete, modify + // permissions (superset of `CAN_RUN`) + DbsqlPermissions *dbsql.DbsqlPermissionsAPI + + Experiments *mlflow.ExperimentsAPI + + // An external location is an object that combines a cloud storage path with + // a storage credential that authorizes access to the cloud storage path. + // Each storage location is subject to Unity Catalog access-control policies + // that control which users and groups can access the credential. If a user + // does not have access to a storage location in Unity Catalog, the request + // fails and Unity Catalog does not attempt to authenticate to your cloud + // tenant on the user’s behalf. + // + // Databricks recommends using external locations rather than using storage + // credentials directly. + // + // To create external locations, you must be a metastore admin or a user + // with the CREATE EXTERNAL LOCATION privilege. + ExternalLocations *unitycatalog.ExternalLocationsAPI + + // Registers personal access token for Databricks to do operations on behalf + // of the user. + // + // See [more + // info](https://docs.databricks.com/repos/get-access-tokens-from-git-provider.html). + GitCredentials *gitcredentials.GitCredentialsAPI + + // The Global Init Scripts API enables Workspace administrators to configure + // global initialization scripts for their workspace. These scripts run on + // every node in every cluster in the workspace. + // + // **Important:** Existing clusters must be restarted to pick up any changes + // made to global init scripts. Global init scripts are run in order. If the + // init script returns with a bad exit code, the Apache Spark container + // fails to launch and init scripts with later position are skipped. If + // enough containers fail, the entire cluster fails with a + // `GLOBAL_INIT_SCRIPT_FAILURE` error code. + GlobalInitScripts *globalinitscripts.GlobalInitScriptsAPI + + // In Unity Catalog, data is secure by default. Initially, users have no + // access to data in a metastore. Access can be granted by either a + // metastore admin, the owner of an object, or the owner of the catalog or + // schema that contains the object. Securable objects in Unity Catalog are + // hierarchical and privileges are inherited downward. + // + // Initially, users have no access to data in a metastore. Access can be + // granted by either a metastore admin, the owner of an object, or the owner + // of the catalog or schema that contains the object. + // + // Securable objects in Unity Catalog are hierarchical and privileges are + // inherited downward. This means that granting a privilege on the catalog + // automatically grants the privilege to all current and future objects + // within the catalog. Similarly, privileges granted on a schema are + // inherited by all current and future objects within that schema. + Grants *unitycatalog.GrantsAPI + + // Groups simplify identity management, making it easier to assign access to + // Databricks Workspace, data, and other securable objects. + // + // It is best practice to assign access to workspaces and access-control + // policies in Unity Catalog to groups, instead of to users individually. + // All Databricks Workspace identities can be assigned as members of groups, + // and members inherit permissions that are assigned to their group. + Groups *scim.GroupsAPI + + // Instance Pools API are used to create, edit, delete and list instance + // pools by using ready-to-use cloud instances which reduces a cluster start + // and auto-scaling times. + // + // Databricks pools reduce cluster start and auto-scaling times by + // maintaining a set of idle, ready-to-use instances. When a cluster is + // attached to a pool, cluster nodes are created using the pool’s idle + // instances. If the pool has no idle instances, the pool expands by + // allocating a new instance from the instance provider in order to + // accommodate the cluster’s request. When a cluster releases an instance, + // it returns to the pool and is free for another cluster to use. Only + // clusters attached to a pool can use that pool’s idle instances. + // + // You can specify a different pool for the driver node and worker nodes, or + // use the same pool for both. + // + // Databricks does not charge DBUs while instances are idle in the pool. + // Instance provider billing does apply. See pricing. + InstancePools *instancepools.InstancePoolsAPI + + // The IP Access List API enables Databricks admins to configure IP access + // lists for a workspace. + // + // IP access lists affect web application access and REST API access to this + // workspace only. If the feature is disabled for a workspace, all access is + // allowed for this workspace. There is support for allow lists (inclusion) + // and block lists (exclusion). + // + // When a connection is attempted: 1. **First, all block lists are + // checked.** If the connection IP address matches any block list, the + // connection is rejected. 2. **If the connection was not rejected by block + // lists**, the IP address is compared with the allow lists. + // + // If there is at least one allow list for the workspace, the connection is + // allowed only if the IP address matches an allow list. If there are no + // allow lists for the workspace, all IP addresses are allowed. + // + // For all allow lists and block lists combined, the workspace supports a + // maximum of 1000 IP/CIDR values, where one CIDR counts as a single value. + // + // After changes to the IP access list feature, it can take a few minutes + // for changes to take effect. + IpAccessLists *ipaccesslists.IpAccessListsAPI + + // The Jobs API allows you to create, edit, and delete jobs. + // + // You can use a Databricks job to run a data processing or data analysis + // task in a Databricks cluster with scalable resources. Your job can + // consist of a single task or can be a large, multi-task workflow with + // complex dependencies. Databricks manages the task orchestration, cluster + // management, monitoring, and error reporting for all of your jobs. You can + // run your jobs immediately or periodically through an easy-to-use + // scheduling system. You can implement job tasks using notebooks, JARS, + // Delta Live Tables pipelines, or Python, Scala, Spark submit, and Java + // applications. + Jobs *jobs.JobsAPI + + // The Libraries API allows you to install and uninstall libraries and get + // the status of libraries on a cluster. + // + // To make third-party or custom code available to notebooks and jobs + // running on your clusters, you can install a library. Libraries can be + // written in Python, Java, Scala, and R. You can upload Java, Scala, and + // Python libraries and point to external packages in PyPI, Maven, and CRAN + // repositories. + // + // Cluster libraries can be used by all notebooks running on a cluster. You + // can install a cluster library directly from a public repository such as + // PyPI or Maven, using a previously installed workspace library, or using + // an init script. + // + // When you install a library on a cluster, a notebook already attached to + // that cluster will not immediately see the new library. You must first + // detach and then reattach the notebook to the cluster. + // + // When you uninstall a library from a cluster, the library is removed only + // when you restart the cluster. Until you restart the cluster, the status + // of the uninstalled library appears as Uninstall pending restart. + Libraries *libraries.LibrariesAPI + + MLflowArtifacts *mlflow.MLflowArtifactsAPI + + // These endpoints are modified versions of the MLflow API that accept + // additional input parameters or return additional information. + MLflowDatabricks *mlflow.MLflowDatabricksAPI + + MLflowMetrics *mlflow.MLflowMetricsAPI + + MLflowRuns *mlflow.MLflowRunsAPI + + // A metastore is the top-level container of objects in Unity Catalog. It + // stores data assets (tables and views) and the permissions that govern + // access to them. Databricks account admins can create metastores and + // assign them to Databricks workspaces to control which workloads use each + // metastore. For a workspace to use Unity Catalog, it must have a Unity + // Catalog metastore attached. + // + // Each metastore is configured with a root storage location in a cloud + // storage account. This storage location is used for metadata and managed + // tables data. + // + // NOTE: This metastore is distinct from the metastore included in + // Databricks workspaces created before Unity Catalog was released. If your + // workspace includes a legacy Hive metastore, the data in that metastore is + // available in Unity Catalog in a catalog named hive_metastore. + Metastores *unitycatalog.MetastoresAPI + + ModelVersionComments *mlflow.ModelVersionCommentsAPI + + ModelVersions *mlflow.ModelVersionsAPI + + // Permissions API are used to create read, write, edit, update and manage + // access for various users on different objects and endpoints. + Permissions *permissions.PermissionsAPI + + // The Delta Live Tables API allows you to create, edit, delete, start, and + // view details about pipelines. + // + // Delta Live Tables is a framework for building reliable, maintainable, and + // testable data processing pipelines. You define the transformations to + // perform on your data, and Delta Live Tables manages task orchestration, + // cluster management, monitoring, data quality, and error handling. + // + // Instead of defining your data pipelines using a series of separate Apache + // Spark tasks, Delta Live Tables manages how your data is transformed based + // on a target schema you define for each processing step. You can also + // enforce data quality with Delta Live Tables expectations. Expectations + // allow you to define expected data quality and specify how to handle + // records that fail those expectations. + Pipelines *pipelines.PipelinesAPI + + // Databricks Delta Sharing: Providers REST API + Providers *unitycatalog.ProvidersAPI + + // These endpoints are used for CRUD operations on query definitions. Query + // definitions include the target SQL warehouse, query text, name, + // description, tags, execution schedule, parameters, and visualizations. + Queries *dbsql.QueriesAPI + + // Access the history of queries through SQL warehouses. + QueryHistory *warehouses.QueryHistoryAPI + + // Databricks Delta Sharing: Recipient Activation REST API + RecipientActivation *unitycatalog.RecipientActivationAPI + + // Databricks Delta Sharing: Recipients REST API + Recipients *unitycatalog.RecipientsAPI + + RegisteredModels *mlflow.RegisteredModelsAPI + + RegistryWebhooks *mlflow.RegistryWebhooksAPI + + // The Repos API allows users to manage their git repos. Users can use the + // API to access all repos that they have manage permissions on. + // + // Databricks Repos is a visual Git client in Databricks. It supports common + // Git operations such a cloning a repository, committing and pushing, + // pulling, branch management, and visual comparison of diffs when + // committing. + // + // Within Repos you can develop code in notebooks or other files and follow + // data science and engineering code development best practices using Git + // for version control, collaboration, and CI/CD. + Repos *repos.ReposAPI + + // A schema (also called a database) is the second layer of Unity + // Catalog’s three-level namespace. A schema organizes tables and views. + // To access (or list) a table or view in a schema, users must have the + // USAGE data permission on the schema and its parent catalog, and they must + // have the SELECT permission on the table or view. + Schemas *unitycatalog.SchemasAPI + + // The Secrets API allows you to manage secrets, secret scopes, and access + // permissions. + // + // Sometimes accessing data requires that you authenticate to external data + // sources through JDBC. Instead of directly entering your credentials into + // a notebook, use Databricks secrets to store your credentials and + // reference them in notebooks and jobs. + // + // Administrators, secret creators, and users granted permission can read + // Databricks secrets. While Databricks makes an effort to redact secret + // values that might be displayed in notebooks, it is not possible to + // prevent such users from reading secrets. + Secrets *secrets.SecretsAPI + + // Identities for use with jobs, automated tools, and systems such as + // scripts, apps, and CI/CD platforms. Databricks recommends creating + // service principals to run production jobs or modify production data. If + // all processes that act on production data run with service principals, + // interactive users do not need any write, delete, or modify privileges in + // production. This eliminates the risk of a user overwriting production + // data by accident. + ServicePrincipals *scim.ServicePrincipalsAPI + + // Databricks Delta Sharing: Shares REST API + Shares *unitycatalog.SharesAPI + + // A storage credential represents an authentication and authorization + // mechanism for accessing data stored on your cloud tenant, using an IAM + // role. Each storage credential is subject to Unity Catalog access-control + // policies that control which users and groups can access the credential. + // If a user does not have access to a storage credential in Unity Catalog, + // the request fails and Unity Catalog does not attempt to authenticate to + // your cloud tenant on the user’s behalf. + // + // Databricks recommends using external locations rather than using storage + // credentials directly. + // + // To create storage credentials, you must be a Databricks account admin. + // The account admin who creates the storage credential can delegate + // ownership to another user or group to manage permissions on it. + StorageCredentials *unitycatalog.StorageCredentialsAPI + + // A table resides in the third layer of Unity Catalog’s three-level + // namespace. It contains rows of data. To create a table, users must have + // CREATE and USAGE permissions on the schema, and they must have the USAGE + // permission on its parent catalog. To query a table, users must have the + // SELECT permission on the table, and they must have the USAGE permission + // on its parent schema and catalog. + // + // A table can be managed or external. + Tables *unitycatalog.TablesAPI + + // Enables administrators to get all tokens and delete tokens for other + // users. Admins can either get every token, get a specific token by ID, or + // get all tokens for a particular user. + TokenManagement *tokenmanagement.TokenManagementAPI + + // The Token API allows you to create, list, and revoke tokens that can be + // used to authenticate and access Databricks REST APIs. + Tokens *tokens.TokensAPI + + TransitionRequests *mlflow.TransitionRequestsAPI + + // Databricks Unity Catalog: Files REST API + UnityFiles *unitycatalog.UnityFilesAPI + + // User identities recognized by Databricks and represented by email + // addresses. + // + // Databricks recommends using SCIM provisioning to sync users and groups + // automatically from your identity provider to your Databricks Workspace. + // SCIM streamlines onboarding a new employee or team by using your identity + // provider to create users and groups in Databricks Workspace and give them + // the proper level of access. When a user leaves your organization or no + // longer needs access to Databricks Workspace, admins can terminate the + // user in your identity provider and that user’s account will also be + // removed from Databricks Workspace. This ensures a consistent offboarding + // process and prevents unauthorized users from accessing sensitive data. + Users *scim.UsersAPI + + // A SQL warehouse is a compute resource that lets you run SQL commands on + // data objects within Databricks SQL. Compute resources are infrastructure + // resources that provide processing capabilities in the cloud. + Warehouses *warehouses.WarehousesAPI + + // The Workspace API allows you to list, import, export, and delete + // notebooks and folders. + // + // A notebook is a web-based interface to a document that contains runnable + // code, visualizations, and explanatory text. + Workspace *workspace.WorkspaceAPI + + // This API allows updating known workspace settings for advanced users. + WorkspaceConf *workspaceconf.WorkspaceConfAPI } func New(c ...*databricks.Config) *WorkspacesClient { @@ -117,21 +511,22 @@ func New(c ...*databricks.Config) *WorkspacesClient { GlobalInitScripts: globalinitscripts.NewGlobalInitScripts(apiClient), Grants: unitycatalog.NewGrants(apiClient), Groups: scim.NewGroups(apiClient), - Jobs: jobs.NewJobs(apiClient), InstancePools: instancepools.NewInstancePools(apiClient), - InstanceProfiles: instanceprofiles.New(apiClient), IpAccessLists: ipaccesslists.NewIpAccessLists(apiClient), + Jobs: jobs.NewJobs(apiClient), Libraries: libraries.NewLibraries(apiClient), - Metastores: unitycatalog.NewMetastores(apiClient), MLflowArtifacts: mlflow.NewMLflowArtifacts(apiClient), MLflowDatabricks: mlflow.NewMLflowDatabricks(apiClient), MLflowMetrics: mlflow.NewMLflowMetrics(apiClient), MLflowRuns: mlflow.NewMLflowRuns(apiClient), - ModelVersions: mlflow.NewModelVersions(apiClient), + Metastores: unitycatalog.NewMetastores(apiClient), ModelVersionComments: mlflow.NewModelVersionComments(apiClient), - Pipelines: pipelines.NewPipelines(apiClient), + ModelVersions: mlflow.NewModelVersions(apiClient), Permissions: permissions.NewPermissions(apiClient), + Pipelines: pipelines.NewPipelines(apiClient), Providers: unitycatalog.NewProviders(apiClient), + Queries: dbsql.NewQueries(apiClient), + QueryHistory: warehouses.NewQueryHistory(apiClient), RecipientActivation: unitycatalog.NewRecipientActivation(apiClient), Recipients: unitycatalog.NewRecipients(apiClient), RegisteredModels: mlflow.NewRegisteredModels(apiClient), @@ -139,15 +534,13 @@ func New(c ...*databricks.Config) *WorkspacesClient { Repos: repos.NewRepos(apiClient), Schemas: unitycatalog.NewSchemas(apiClient), Secrets: secrets.NewSecrets(apiClient), - Shares: unitycatalog.NewShares(apiClient), ServicePrincipals: scim.NewServicePrincipals(apiClient), + Shares: unitycatalog.NewShares(apiClient), StorageCredentials: unitycatalog.NewStorageCredentials(apiClient), Tables: unitycatalog.NewTables(apiClient), - Tokens: tokens.NewTokens(apiClient), TokenManagement: tokenmanagement.NewTokenManagement(apiClient), + Tokens: tokens.NewTokens(apiClient), TransitionRequests: mlflow.NewTransitionRequests(apiClient), - Queries: dbsql.NewQueries(apiClient), - QueryHistory: warehouses.NewQueryHistory(apiClient), UnityFiles: unitycatalog.NewUnityFiles(apiClient), Users: scim.NewUsers(apiClient), Warehouses: warehouses.NewWarehouses(apiClient),