diff --git a/.codegen/_openapi_sha b/.codegen/_openapi_sha index 3e23eb96e..ea5620b88 100644 --- a/.codegen/_openapi_sha +++ b/.codegen/_openapi_sha @@ -1 +1 @@ -bc129a369da83018a34e1178448f00874e6bbfab \ No newline at end of file +c66f4a39b2c4d2f2a3d873a0a566c5e722649efb \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index a9036ffa8..25ab9614d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,98 @@ # Version changelog +## [Release] Release v0.56.1 + +### Bug Fixes + + * Do not send query parameters when set to zero value ([#1136](https://github.com/databricks/databricks-sdk-go/pull/1136)). + + + +## [Release] Release v0.56.0 + +### Bug Fixes + + * Support Query parameters for all HTTP operations ([#1124](https://github.com/databricks/databricks-sdk-go/pull/1124)). + + +### Internal Changes + + * Add download target to MakeFile ([#1125](https://github.com/databricks/databricks-sdk-go/pull/1125)). + * Delete examples/mocking module ([#1126](https://github.com/databricks/databricks-sdk-go/pull/1126)). + * Scope the traversing directory in the Recursive list workspace test ([#1120](https://github.com/databricks/databricks-sdk-go/pull/1120)). + + +### API Changes: + + * Added [w.AccessControl](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/iam#AccessControlAPI) workspace-level service. + * Added `HttpRequest` method for [w.ServingEndpoints](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#ServingEndpointsAPI) workspace-level service. + * Added `ReviewState`, `Reviews` and `RunnerCollaborators` fields for [cleanrooms.CleanRoomAssetNotebook](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/cleanrooms#CleanRoomAssetNotebook). + * Added `CleanRoomsNotebookOutput` field for [jobs.RunOutput](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#RunOutput). + * Added `RunAsRepl` field for [jobs.SparkJarTask](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#SparkJarTask). + * Added `Scopes` field for [oauth2.UpdateCustomAppIntegration](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/oauth2#UpdateCustomAppIntegration). + * Added `Contents` field for [serving.GetOpenApiResponse](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#GetOpenApiResponse). + * Added `Activated`, `ActivationUrl`, `AuthenticationType`, `Cloud`, `Comment`, `CreatedAt`, `CreatedBy`, `DataRecipientGlobalMetastoreId`, `IpAccessList`, `MetastoreId`, `Name`, `Owner`, `PropertiesKvpairs`, `Region`, `SharingCode`, `Tokens`, `UpdatedAt` and `UpdatedBy` fields for [sharing.RecipientInfo](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/sharing#RecipientInfo). + * Added `ExpirationTime` field for [sharing.RecipientInfo](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/sharing#RecipientInfo). + * Added `Pending` enum value for [cleanrooms.CleanRoomAssetStatusEnum](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/cleanrooms#CleanRoomAssetStatusEnum). + * Added `AddNodesFailed`, `AutomaticClusterUpdate`, `AutoscalingBackoff` and `AutoscalingFailed` enum values for [compute.EventType](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/compute#EventType). + * Added `PendingWarehouse` enum value for [dashboards.MessageStatus](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/dashboards#MessageStatus). + * Added `Cpu`, `GpuLarge`, `GpuMedium`, `GpuSmall` and `MultigpuMedium` enum values for [serving.ServingModelWorkloadType](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#ServingModelWorkloadType). + * Changed `Update` method for [w.Recipients](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/sharing#RecipientsAPI) workspace-level service to return [sharing.RecipientInfo](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/sharing#RecipientInfo). + * Changed `Update` method for [w.Recipients](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/sharing#RecipientsAPI) workspace-level service return type to become non-empty. + * Changed `Update` method for [w.Recipients](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/sharing#RecipientsAPI) workspace-level service to type `Update` method for [w.Recipients](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/sharing#RecipientsAPI) workspace-level service. + * Changed `Create` method for [w.ServingEndpoints](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#ServingEndpointsAPI) workspace-level service with new required argument order. + * Changed `GetOpenApi` method for [w.ServingEndpoints](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#ServingEndpointsAPI) workspace-level service return type to become non-empty. + * Changed `Patch` method for [w.ServingEndpoints](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#ServingEndpointsAPI) workspace-level service to type `Patch` method for [w.ServingEndpoints](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#ServingEndpointsAPI) workspace-level service. + * Changed `Patch` method for [w.ServingEndpoints](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#ServingEndpointsAPI) workspace-level service to return [serving.EndpointTags](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#EndpointTags). + * Changed [serving.EndpointTagList](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#EndpointTagList) to. + * Changed `CollaboratorAlias` field for [cleanrooms.CleanRoomCollaborator](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/cleanrooms#CleanRoomCollaborator) to be required. + * Changed `CollaboratorAlias` field for [cleanrooms.CleanRoomCollaborator](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/cleanrooms#CleanRoomCollaborator) to be required. + * Changed `Behavior` field for [serving.AiGatewayGuardrailPiiBehavior](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#AiGatewayGuardrailPiiBehavior) to no longer be required. + * Changed `Behavior` field for [serving.AiGatewayGuardrailPiiBehavior](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#AiGatewayGuardrailPiiBehavior) to no longer be required. + * Changed `Config` field for [serving.CreateServingEndpoint](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#CreateServingEndpoint) to no longer be required. + * Changed `ProjectId` and `Region` fields for [serving.GoogleCloudVertexAiConfig](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#GoogleCloudVertexAiConfig) to be required. + * Changed `ProjectId` and `Region` fields for [serving.GoogleCloudVertexAiConfig](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#GoogleCloudVertexAiConfig) to be required. + * Changed `WorkloadType` field for [serving.ServedEntityInput](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#ServedEntityInput) to type [serving.ServingModelWorkloadType](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#ServingModelWorkloadType). + * Changed `WorkloadType` field for [serving.ServedEntityOutput](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#ServedEntityOutput) to type [serving.ServingModelWorkloadType](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#ServingModelWorkloadType). + * Changed `WorkloadType` field for [serving.ServedModelOutput](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#ServedModelOutput) to type [serving.ServingModelWorkloadType](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#ServingModelWorkloadType). + * Changed waiter for [ServingEndpointsAPI.Create](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#ServingEndpointsAPI.Create). + * Changed waiter for [ServingEndpointsAPI.UpdateConfig](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#ServingEndpointsAPI.UpdateConfig). + + +OpenAPI SHA: 0be1b914249781b5e903b7676fd02255755bc851, Date: 2025-01-22 + +## [Release] Release v0.55.0 + +### Internal Changes + + * Bump staticcheck to 0.5.1 and add go 1.23 test coverage ([#1106](https://github.com/databricks/databricks-sdk-go/pull/1106)). + * Bump x/net, x/crypto dependencies ([#1107](https://github.com/databricks/databricks-sdk-go/pull/1107)). + * Create custom codeql.yml ([#1114](https://github.com/databricks/databricks-sdk-go/pull/1114)). + * Decouple serving and oauth2 package ([#1110](https://github.com/databricks/databricks-sdk-go/pull/1110)). + * Migrate workflows that need write access to use hosted runners ([#1112](https://github.com/databricks/databricks-sdk-go/pull/1112)). + * Move package credentials in config ([#1115](https://github.com/databricks/databricks-sdk-go/pull/1115)). + * Update Queries test ([#1104](https://github.com/databricks/databricks-sdk-go/pull/1104)). + + +### API Changes: + + * Added `NoCompute` field for [apps.CreateAppRequest](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/apps#CreateAppRequest). + * Added `HasMore` field for [jobs.BaseJob](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#BaseJob). + * Added `HasMore` field for [jobs.BaseRun](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#BaseRun). + * Added `PageToken` field for [jobs.GetJobRequest](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#GetJobRequest). + * Added `HasMore` and `NextPageToken` fields for [jobs.Job](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#Job). + * Added `HasMore` field for [jobs.Run](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#Run). + * Added `RunAs` field for [pipelines.CreatePipeline](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/pipelines#CreatePipeline). + * Added `RunAs` field for [pipelines.EditPipeline](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/pipelines#EditPipeline). + * Added `AuthorizationDetails` and `EndpointUrl` fields for [serving.DataPlaneInfo](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#DataPlaneInfo). + * [Breaking] Changed `Update` method for [a.AccountFederationPolicy](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/oauth2#AccountFederationPolicyAPI) account-level service with new required argument order. + * [Breaking] Changed `Update` method for [a.ServicePrincipalFederationPolicy](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/oauth2#ServicePrincipalFederationPolicyAPI) account-level service with new required argument order. + * Changed `UpdateMask` field for [oauth2.UpdateAccountFederationPolicyRequest](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/oauth2#UpdateAccountFederationPolicyRequest) to no longer be required. + * Changed `UpdateMask` field for [oauth2.UpdateServicePrincipalFederationPolicyRequest](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/oauth2#UpdateServicePrincipalFederationPolicyRequest) to no longer be required. + * [Breaking] Changed `DaysOfWeek` field for [pipelines.RestartWindow](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/pipelines#RestartWindow) to type [pipelines.DayOfWeekList](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/pipelines#DayOfWeekList). + +OpenAPI SHA: 779817ed8d63031f5ea761fbd25ee84f38feec0d, Date: 2025-01-08 + ## [Release] Release v0.55.0 ### Internal Changes diff --git a/apps/go.mod b/apps/go.mod index a0e270542..5fdf03d42 100644 --- a/apps/go.mod +++ b/apps/go.mod @@ -6,6 +6,7 @@ replace github.com/databricks/databricks-sdk-go/databricks => ../databricks require ( github.com/databricks/databricks-sdk-go/databricks v0.0.0-00010101000000-000000000000 + golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 golang.org/x/oauth2 v0.25.0 ) @@ -27,7 +28,6 @@ require ( go.opentelemetry.io/otel/metric v1.24.0 // indirect go.opentelemetry.io/otel/trace v1.24.0 // indirect golang.org/x/crypto v0.31.0 // indirect - golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.33.0 // indirect golang.org/x/sys v0.28.0 // indirect diff --git a/apps/v2/api.go b/apps/v2/api.go index 59b2de9fa..66d58e8b9 100755 --- a/apps/v2/api.go +++ b/apps/v2/api.go @@ -8,7 +8,6 @@ import ( "github.com/databricks/databricks-sdk-go/databricks/client" "github.com/databricks/databricks-sdk-go/databricks/listing" - "github.com/databricks/databricks-sdk-go/databricks/useragent" ) type AppsInterface interface { @@ -202,89 +201,11 @@ func (a *AppsAPI) GetPermissionsByAppName(ctx context.Context, appName string) ( }) } -// List apps. -// -// Lists all apps in the workspace. -// -// This method is generated by Databricks SDK Code Generator. -func (a *AppsAPI) List(ctx context.Context, request ListAppsRequest) listing.Iterator[App] { - - getNextPage := func(ctx context.Context, req ListAppsRequest) (*ListAppsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.appsImpl.List(ctx, req) - } - getItems := func(resp *ListAppsResponse) []App { - return resp.Apps - } - getNextReq := func(resp *ListAppsResponse) *ListAppsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List apps. -// -// Lists all apps in the workspace. -// -// This method is generated by Databricks SDK Code Generator. -func (a *AppsAPI) ListAll(ctx context.Context, request ListAppsRequest) ([]App, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[App](ctx, iterator) -} - -// List app deployments. -// -// Lists all app deployments for the app with the supplied name. -// -// This method is generated by Databricks SDK Code Generator. -func (a *AppsAPI) ListDeployments(ctx context.Context, request ListAppDeploymentsRequest) listing.Iterator[AppDeployment] { - - getNextPage := func(ctx context.Context, req ListAppDeploymentsRequest) (*ListAppDeploymentsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.appsImpl.ListDeployments(ctx, req) - } - getItems := func(resp *ListAppDeploymentsResponse) []AppDeployment { - return resp.AppDeployments - } - getNextReq := func(resp *ListAppDeploymentsResponse) *ListAppDeploymentsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List app deployments. -// -// Lists all app deployments for the app with the supplied name. -// -// This method is generated by Databricks SDK Code Generator. -func (a *AppsAPI) ListDeploymentsAll(ctx context.Context, request ListAppDeploymentsRequest) ([]AppDeployment, error) { - iterator := a.ListDeployments(ctx, request) - return listing.ToSlice[AppDeployment](ctx, iterator) -} - // List app deployments. // // Lists all app deployments for the app with the supplied name. func (a *AppsAPI) ListDeploymentsByAppName(ctx context.Context, appName string) (*ListAppDeploymentsResponse, error) { - return a.appsImpl.ListDeployments(ctx, ListAppDeploymentsRequest{ + return a.appsImpl.internalListDeployments(ctx, ListAppDeploymentsRequest{ AppName: appName, }) } diff --git a/apps/v2/impl.go b/apps/v2/impl.go index 2b34fb1d1..61239614c 100755 --- a/apps/v2/impl.go +++ b/apps/v2/impl.go @@ -8,6 +8,9 @@ import ( "net/http" "github.com/databricks/databricks-sdk-go/databricks/client" + "github.com/databricks/databricks-sdk-go/databricks/listing" + "github.com/databricks/databricks-sdk-go/databricks/useragent" + "golang.org/x/exp/slices" ) // unexported type that holds implementations of just Apps API methods @@ -18,132 +21,217 @@ type appsImpl struct { func (a *appsImpl) Create(ctx context.Context, request CreateAppRequest) (*App, error) { var app App path := "/api/2.0/apps" + queryParams := make(map[string]any) + if request.NoCompute != false || slices.Contains(request.ForceSendFields, "NoCompute") { + queryParams["no_compute"] = request.NoCompute + } headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request.App, &app) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request.App, &app) return &app, err } func (a *appsImpl) Delete(ctx context.Context, request DeleteAppRequest) (*App, error) { var app App path := fmt.Sprintf("/api/2.0/apps/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &app) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &app) return &app, err } func (a *appsImpl) Deploy(ctx context.Context, request CreateAppDeploymentRequest) (*AppDeployment, error) { var appDeployment AppDeployment path := fmt.Sprintf("/api/2.0/apps/%v/deployments", request.AppName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request.AppDeployment, &appDeployment) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request.AppDeployment, &appDeployment) return &appDeployment, err } func (a *appsImpl) Get(ctx context.Context, request GetAppRequest) (*App, error) { var app App path := fmt.Sprintf("/api/2.0/apps/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &app) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &app) return &app, err } func (a *appsImpl) GetDeployment(ctx context.Context, request GetAppDeploymentRequest) (*AppDeployment, error) { var appDeployment AppDeployment path := fmt.Sprintf("/api/2.0/apps/%v/deployments/%v", request.AppName, request.DeploymentId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &appDeployment) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &appDeployment) return &appDeployment, err } func (a *appsImpl) GetPermissionLevels(ctx context.Context, request GetAppPermissionLevelsRequest) (*GetAppPermissionLevelsResponse, error) { var getAppPermissionLevelsResponse GetAppPermissionLevelsResponse path := fmt.Sprintf("/api/2.0/permissions/apps/%v/permissionLevels", request.AppName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getAppPermissionLevelsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getAppPermissionLevelsResponse) return &getAppPermissionLevelsResponse, err } func (a *appsImpl) GetPermissions(ctx context.Context, request GetAppPermissionsRequest) (*AppPermissions, error) { var appPermissions AppPermissions path := fmt.Sprintf("/api/2.0/permissions/apps/%v", request.AppName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &appPermissions) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &appPermissions) return &appPermissions, err } -func (a *appsImpl) List(ctx context.Context, request ListAppsRequest) (*ListAppsResponse, error) { +// List apps. +// +// Lists all apps in the workspace. +func (a *appsImpl) List(ctx context.Context, request ListAppsRequest) listing.Iterator[App] { + + getNextPage := func(ctx context.Context, req ListAppsRequest) (*ListAppsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListAppsResponse) []App { + return resp.Apps + } + getNextReq := func(resp *ListAppsResponse) *ListAppsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List apps. +// +// Lists all apps in the workspace. +func (a *appsImpl) ListAll(ctx context.Context, request ListAppsRequest) ([]App, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[App](ctx, iterator) +} +func (a *appsImpl) internalList(ctx context.Context, request ListAppsRequest) (*ListAppsResponse, error) { var listAppsResponse ListAppsResponse path := "/api/2.0/apps" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listAppsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listAppsResponse) return &listAppsResponse, err } -func (a *appsImpl) ListDeployments(ctx context.Context, request ListAppDeploymentsRequest) (*ListAppDeploymentsResponse, error) { +// List app deployments. +// +// Lists all app deployments for the app with the supplied name. +func (a *appsImpl) ListDeployments(ctx context.Context, request ListAppDeploymentsRequest) listing.Iterator[AppDeployment] { + + getNextPage := func(ctx context.Context, req ListAppDeploymentsRequest) (*ListAppDeploymentsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalListDeployments(ctx, req) + } + getItems := func(resp *ListAppDeploymentsResponse) []AppDeployment { + return resp.AppDeployments + } + getNextReq := func(resp *ListAppDeploymentsResponse) *ListAppDeploymentsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List app deployments. +// +// Lists all app deployments for the app with the supplied name. +func (a *appsImpl) ListDeploymentsAll(ctx context.Context, request ListAppDeploymentsRequest) ([]AppDeployment, error) { + iterator := a.ListDeployments(ctx, request) + return listing.ToSlice[AppDeployment](ctx, iterator) +} +func (a *appsImpl) internalListDeployments(ctx context.Context, request ListAppDeploymentsRequest) (*ListAppDeploymentsResponse, error) { var listAppDeploymentsResponse ListAppDeploymentsResponse path := fmt.Sprintf("/api/2.0/apps/%v/deployments", request.AppName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listAppDeploymentsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listAppDeploymentsResponse) return &listAppDeploymentsResponse, err } func (a *appsImpl) SetPermissions(ctx context.Context, request AppPermissionsRequest) (*AppPermissions, error) { var appPermissions AppPermissions path := fmt.Sprintf("/api/2.0/permissions/apps/%v", request.AppName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &appPermissions) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &appPermissions) return &appPermissions, err } func (a *appsImpl) Start(ctx context.Context, request StartAppRequest) (*App, error) { var app App path := fmt.Sprintf("/api/2.0/apps/%v/start", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &app) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &app) return &app, err } func (a *appsImpl) Stop(ctx context.Context, request StopAppRequest) (*App, error) { var app App path := fmt.Sprintf("/api/2.0/apps/%v/stop", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &app) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &app) return &app, err } func (a *appsImpl) Update(ctx context.Context, request UpdateAppRequest) (*App, error) { var app App path := fmt.Sprintf("/api/2.0/apps/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request.App, &app) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request.App, &app) return &app, err } func (a *appsImpl) UpdatePermissions(ctx context.Context, request AppPermissionsRequest) (*AppPermissions, error) { var appPermissions AppPermissions path := fmt.Sprintf("/api/2.0/permissions/apps/%v", request.AppName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &appPermissions) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &appPermissions) return &appPermissions, err } diff --git a/apps/v2/model.go b/apps/v2/model.go index 65af0d184..5e5ac380a 100755 --- a/apps/v2/model.go +++ b/apps/v2/model.go @@ -26,6 +26,8 @@ type App struct { DefaultSourceCodePath string `json:"default_source_code_path,omitempty"` // The description of the app. Description string `json:"description,omitempty"` + // The unique identifier of the app. + Id string `json:"id,omitempty"` // The name of the app. The name must contain only lowercase alphanumeric // characters and hyphens. It must be unique within the workspace. Name string `json:"name"` diff --git a/billing/go.mod b/billing/go.mod index 6aee30f45..eab95c6e1 100644 --- a/billing/go.mod +++ b/billing/go.mod @@ -6,6 +6,7 @@ replace github.com/databricks/databricks-sdk-go/databricks => ../databricks require ( github.com/databricks/databricks-sdk-go/databricks v0.0.0-00010101000000-000000000000 + golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 golang.org/x/oauth2 v0.25.0 ) @@ -27,7 +28,6 @@ require ( go.opentelemetry.io/otel/metric v1.24.0 // indirect go.opentelemetry.io/otel/trace v1.24.0 // indirect golang.org/x/crypto v0.31.0 // indirect - golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.33.0 // indirect golang.org/x/sys v0.28.0 // indirect diff --git a/billing/v2/api.go b/billing/v2/api.go index 20c594c6e..3fc105ee0 100755 --- a/billing/v2/api.go +++ b/billing/v2/api.go @@ -123,47 +123,6 @@ func (a *BudgetPolicyAPI) GetByPolicyId(ctx context.Context, policyId string) (* }) } -// List policies. -// -// Lists all policies. Policies are returned in the alphabetically ascending -// order of their names. -// -// This method is generated by Databricks SDK Code Generator. -func (a *BudgetPolicyAPI) List(ctx context.Context, request ListBudgetPoliciesRequest) listing.Iterator[BudgetPolicy] { - - getNextPage := func(ctx context.Context, req ListBudgetPoliciesRequest) (*ListBudgetPoliciesResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.budgetPolicyImpl.List(ctx, req) - } - getItems := func(resp *ListBudgetPoliciesResponse) []BudgetPolicy { - return resp.Policies - } - getNextReq := func(resp *ListBudgetPoliciesResponse) *ListBudgetPoliciesRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List policies. -// -// Lists all policies. Policies are returned in the alphabetically ascending -// order of their names. -// -// This method is generated by Databricks SDK Code Generator. -func (a *BudgetPolicyAPI) ListAll(ctx context.Context, request ListBudgetPoliciesRequest) ([]BudgetPolicy, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[BudgetPolicy](ctx, iterator) -} - type BudgetsInterface interface { // Create new budget. @@ -253,45 +212,6 @@ func (a *BudgetsAPI) GetByBudgetId(ctx context.Context, budgetId string) (*GetBu }) } -// Get all budgets. -// -// Gets all budgets associated with this account. -// -// This method is generated by Databricks SDK Code Generator. -func (a *BudgetsAPI) List(ctx context.Context, request ListBudgetConfigurationsRequest) listing.Iterator[BudgetConfiguration] { - - getNextPage := func(ctx context.Context, req ListBudgetConfigurationsRequest) (*ListBudgetConfigurationsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.budgetsImpl.List(ctx, req) - } - getItems := func(resp *ListBudgetConfigurationsResponse) []BudgetConfiguration { - return resp.Budgets - } - getNextReq := func(resp *ListBudgetConfigurationsResponse) *ListBudgetConfigurationsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// Get all budgets. -// -// Gets all budgets associated with this account. -// -// This method is generated by Databricks SDK Code Generator. -func (a *BudgetsAPI) ListAll(ctx context.Context, request ListBudgetConfigurationsRequest) ([]BudgetConfiguration, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[BudgetConfiguration](ctx, iterator) -} - type LogDeliveryInterface interface { // Create a new log delivery configuration. @@ -462,41 +382,6 @@ func (a *LogDeliveryAPI) GetByLogDeliveryConfigurationId(ctx context.Context, lo }) } -// Get all log delivery configurations. -// -// Gets all Databricks log delivery configurations associated with an account -// specified by ID. -// -// This method is generated by Databricks SDK Code Generator. -func (a *LogDeliveryAPI) List(ctx context.Context, request ListLogDeliveryRequest) listing.Iterator[LogDeliveryConfiguration] { - - getNextPage := func(ctx context.Context, req ListLogDeliveryRequest) (*WrappedLogDeliveryConfigurations, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.logDeliveryImpl.List(ctx, req) - } - getItems := func(resp *WrappedLogDeliveryConfigurations) []LogDeliveryConfiguration { - return resp.LogDeliveryConfigurations - } - - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - nil) - return iterator -} - -// Get all log delivery configurations. -// -// Gets all Databricks log delivery configurations associated with an account -// specified by ID. -// -// This method is generated by Databricks SDK Code Generator. -func (a *LogDeliveryAPI) ListAll(ctx context.Context, request ListLogDeliveryRequest) ([]LogDeliveryConfiguration, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[LogDeliveryConfiguration](ctx, iterator) -} - // LogDeliveryConfigurationConfigNameToConfigIdMap calls [LogDeliveryAPI.ListAll] and creates a map of results with [LogDeliveryConfiguration].ConfigName as key and [LogDeliveryConfiguration].ConfigId as value. // // Returns an error if there's more than one [LogDeliveryConfiguration] with the same .ConfigName. diff --git a/billing/v2/impl.go b/billing/v2/impl.go index f7daad249..d1aa6cb88 100755 --- a/billing/v2/impl.go +++ b/billing/v2/impl.go @@ -8,6 +8,8 @@ import ( "net/http" "github.com/databricks/databricks-sdk-go/databricks/client" + "github.com/databricks/databricks-sdk-go/databricks/listing" + "github.com/databricks/databricks-sdk-go/databricks/useragent" ) // unexported type that holds implementations of just BillableUsage API methods @@ -18,9 +20,10 @@ type billableUsageImpl struct { func (a *billableUsageImpl) Download(ctx context.Context, request DownloadRequest) (*DownloadResponse, error) { var downloadResponse DownloadResponse path := fmt.Sprintf("/api/2.0/accounts/%v/usage/download", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "text/plain" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &downloadResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &downloadResponse) return &downloadResponse, err } @@ -32,47 +35,91 @@ type budgetPolicyImpl struct { func (a *budgetPolicyImpl) Create(ctx context.Context, request CreateBudgetPolicyRequest) (*BudgetPolicy, error) { var budgetPolicy BudgetPolicy path := fmt.Sprintf("/api/2.1/accounts/%v/budget-policies", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &budgetPolicy) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &budgetPolicy) return &budgetPolicy, err } func (a *budgetPolicyImpl) Delete(ctx context.Context, request DeleteBudgetPolicyRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.1/accounts/%v/budget-policies/%v", a.client.ConfiguredAccountID(), request.PolicyId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *budgetPolicyImpl) Get(ctx context.Context, request GetBudgetPolicyRequest) (*BudgetPolicy, error) { var budgetPolicy BudgetPolicy path := fmt.Sprintf("/api/2.1/accounts/%v/budget-policies/%v", a.client.ConfiguredAccountID(), request.PolicyId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &budgetPolicy) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &budgetPolicy) return &budgetPolicy, err } -func (a *budgetPolicyImpl) List(ctx context.Context, request ListBudgetPoliciesRequest) (*ListBudgetPoliciesResponse, error) { +// List policies. +// +// Lists all policies. Policies are returned in the alphabetically ascending +// order of their names. +func (a *budgetPolicyImpl) List(ctx context.Context, request ListBudgetPoliciesRequest) listing.Iterator[BudgetPolicy] { + + getNextPage := func(ctx context.Context, req ListBudgetPoliciesRequest) (*ListBudgetPoliciesResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListBudgetPoliciesResponse) []BudgetPolicy { + return resp.Policies + } + getNextReq := func(resp *ListBudgetPoliciesResponse) *ListBudgetPoliciesRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List policies. +// +// Lists all policies. Policies are returned in the alphabetically ascending +// order of their names. +func (a *budgetPolicyImpl) ListAll(ctx context.Context, request ListBudgetPoliciesRequest) ([]BudgetPolicy, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[BudgetPolicy](ctx, iterator) +} +func (a *budgetPolicyImpl) internalList(ctx context.Context, request ListBudgetPoliciesRequest) (*ListBudgetPoliciesResponse, error) { var listBudgetPoliciesResponse ListBudgetPoliciesResponse path := fmt.Sprintf("/api/2.1/accounts/%v/budget-policies", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listBudgetPoliciesResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listBudgetPoliciesResponse) return &listBudgetPoliciesResponse, err } func (a *budgetPolicyImpl) Update(ctx context.Context, request UpdateBudgetPolicyRequest) (*BudgetPolicy, error) { var budgetPolicy BudgetPolicy path := fmt.Sprintf("/api/2.1/accounts/%v/budget-policies/%v", a.client.ConfiguredAccountID(), request.PolicyId) + queryParams := make(map[string]any) + if request.LimitConfig != nil { + queryParams["limit_config"] = request.LimitConfig + } headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request.Policy, &budgetPolicy) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request.Policy, &budgetPolicy) return &budgetPolicy, err } @@ -84,47 +131,86 @@ type budgetsImpl struct { func (a *budgetsImpl) Create(ctx context.Context, request CreateBudgetConfigurationRequest) (*CreateBudgetConfigurationResponse, error) { var createBudgetConfigurationResponse CreateBudgetConfigurationResponse path := fmt.Sprintf("/api/2.1/accounts/%v/budgets", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createBudgetConfigurationResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createBudgetConfigurationResponse) return &createBudgetConfigurationResponse, err } func (a *budgetsImpl) Delete(ctx context.Context, request DeleteBudgetConfigurationRequest) error { var deleteBudgetConfigurationResponse DeleteBudgetConfigurationResponse path := fmt.Sprintf("/api/2.1/accounts/%v/budgets/%v", a.client.ConfiguredAccountID(), request.BudgetId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteBudgetConfigurationResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteBudgetConfigurationResponse) return err } func (a *budgetsImpl) Get(ctx context.Context, request GetBudgetConfigurationRequest) (*GetBudgetConfigurationResponse, error) { var getBudgetConfigurationResponse GetBudgetConfigurationResponse path := fmt.Sprintf("/api/2.1/accounts/%v/budgets/%v", a.client.ConfiguredAccountID(), request.BudgetId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getBudgetConfigurationResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getBudgetConfigurationResponse) return &getBudgetConfigurationResponse, err } -func (a *budgetsImpl) List(ctx context.Context, request ListBudgetConfigurationsRequest) (*ListBudgetConfigurationsResponse, error) { +// Get all budgets. +// +// Gets all budgets associated with this account. +func (a *budgetsImpl) List(ctx context.Context, request ListBudgetConfigurationsRequest) listing.Iterator[BudgetConfiguration] { + + getNextPage := func(ctx context.Context, req ListBudgetConfigurationsRequest) (*ListBudgetConfigurationsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListBudgetConfigurationsResponse) []BudgetConfiguration { + return resp.Budgets + } + getNextReq := func(resp *ListBudgetConfigurationsResponse) *ListBudgetConfigurationsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// Get all budgets. +// +// Gets all budgets associated with this account. +func (a *budgetsImpl) ListAll(ctx context.Context, request ListBudgetConfigurationsRequest) ([]BudgetConfiguration, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[BudgetConfiguration](ctx, iterator) +} +func (a *budgetsImpl) internalList(ctx context.Context, request ListBudgetConfigurationsRequest) (*ListBudgetConfigurationsResponse, error) { var listBudgetConfigurationsResponse ListBudgetConfigurationsResponse path := fmt.Sprintf("/api/2.1/accounts/%v/budgets", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listBudgetConfigurationsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listBudgetConfigurationsResponse) return &listBudgetConfigurationsResponse, err } func (a *budgetsImpl) Update(ctx context.Context, request UpdateBudgetConfigurationRequest) (*UpdateBudgetConfigurationResponse, error) { var updateBudgetConfigurationResponse UpdateBudgetConfigurationResponse path := fmt.Sprintf("/api/2.1/accounts/%v/budgets/%v", a.client.ConfiguredAccountID(), request.BudgetId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &updateBudgetConfigurationResponse) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &updateBudgetConfigurationResponse) return &updateBudgetConfigurationResponse, err } @@ -136,38 +222,72 @@ type logDeliveryImpl struct { func (a *logDeliveryImpl) Create(ctx context.Context, request WrappedCreateLogDeliveryConfiguration) (*WrappedLogDeliveryConfiguration, error) { var wrappedLogDeliveryConfiguration WrappedLogDeliveryConfiguration path := fmt.Sprintf("/api/2.0/accounts/%v/log-delivery", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &wrappedLogDeliveryConfiguration) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &wrappedLogDeliveryConfiguration) return &wrappedLogDeliveryConfiguration, err } func (a *logDeliveryImpl) Get(ctx context.Context, request GetLogDeliveryRequest) (*WrappedLogDeliveryConfiguration, error) { var wrappedLogDeliveryConfiguration WrappedLogDeliveryConfiguration path := fmt.Sprintf("/api/2.0/accounts/%v/log-delivery/%v", a.client.ConfiguredAccountID(), request.LogDeliveryConfigurationId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &wrappedLogDeliveryConfiguration) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &wrappedLogDeliveryConfiguration) return &wrappedLogDeliveryConfiguration, err } -func (a *logDeliveryImpl) List(ctx context.Context, request ListLogDeliveryRequest) (*WrappedLogDeliveryConfigurations, error) { +// Get all log delivery configurations. +// +// Gets all Databricks log delivery configurations associated with an account +// specified by ID. +func (a *logDeliveryImpl) List(ctx context.Context, request ListLogDeliveryRequest) listing.Iterator[LogDeliveryConfiguration] { + + getNextPage := func(ctx context.Context, req ListLogDeliveryRequest) (*WrappedLogDeliveryConfigurations, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *WrappedLogDeliveryConfigurations) []LogDeliveryConfiguration { + return resp.LogDeliveryConfigurations + } + + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + nil) + return iterator +} + +// Get all log delivery configurations. +// +// Gets all Databricks log delivery configurations associated with an account +// specified by ID. +func (a *logDeliveryImpl) ListAll(ctx context.Context, request ListLogDeliveryRequest) ([]LogDeliveryConfiguration, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[LogDeliveryConfiguration](ctx, iterator) +} +func (a *logDeliveryImpl) internalList(ctx context.Context, request ListLogDeliveryRequest) (*WrappedLogDeliveryConfigurations, error) { var wrappedLogDeliveryConfigurations WrappedLogDeliveryConfigurations path := fmt.Sprintf("/api/2.0/accounts/%v/log-delivery", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &wrappedLogDeliveryConfigurations) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &wrappedLogDeliveryConfigurations) return &wrappedLogDeliveryConfigurations, err } func (a *logDeliveryImpl) PatchStatus(ctx context.Context, request UpdateLogDeliveryConfigurationStatusRequest) error { var patchStatusResponse PatchStatusResponse path := fmt.Sprintf("/api/2.0/accounts/%v/log-delivery/%v", a.client.ConfiguredAccountID(), request.LogDeliveryConfigurationId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &patchStatusResponse) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &patchStatusResponse) return err } @@ -179,18 +299,20 @@ type usageDashboardsImpl struct { func (a *usageDashboardsImpl) Create(ctx context.Context, request CreateBillingUsageDashboardRequest) (*CreateBillingUsageDashboardResponse, error) { var createBillingUsageDashboardResponse CreateBillingUsageDashboardResponse path := fmt.Sprintf("/api/2.0/accounts/%v/dashboard", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createBillingUsageDashboardResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createBillingUsageDashboardResponse) return &createBillingUsageDashboardResponse, err } func (a *usageDashboardsImpl) Get(ctx context.Context, request GetBillingUsageDashboardRequest) (*GetBillingUsageDashboardResponse, error) { var getBillingUsageDashboardResponse GetBillingUsageDashboardResponse path := fmt.Sprintf("/api/2.0/accounts/%v/dashboard", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getBillingUsageDashboardResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getBillingUsageDashboardResponse) return &getBillingUsageDashboardResponse, err } diff --git a/billing/v2/model.go b/billing/v2/model.go index fe6fd608a..11aaed236 100755 --- a/billing/v2/model.go +++ b/billing/v2/model.go @@ -701,6 +701,11 @@ type GetLogDeliveryRequest struct { LogDeliveryConfigurationId string `json:"-" url:"-"` } +// The limit configuration of the policy. Limit configuration provide a budget +// policy level cost control by enforcing the limit. +type LimitConfig struct { +} + // Get all budgets type ListBudgetConfigurationsRequest struct { // A page token received from a previous get all budget configurations call. @@ -1130,6 +1135,9 @@ type UpdateBudgetConfigurationResponse struct { // Update a budget policy type UpdateBudgetPolicyRequest struct { + // DEPRECATED. This is redundant field as LimitConfig is part of the + // BudgetPolicy + LimitConfig *LimitConfig `json:"-" url:"limit_config,omitempty"` // Contains the BudgetPolicy details. Policy *BudgetPolicy `json:"policy,omitempty"` // The Id of the policy. This field is generated by Databricks and globally diff --git a/catalog/go.mod b/catalog/go.mod index 115109eb5..3de9255f6 100644 --- a/catalog/go.mod +++ b/catalog/go.mod @@ -6,6 +6,7 @@ replace github.com/databricks/databricks-sdk-go/databricks => ../databricks require ( github.com/databricks/databricks-sdk-go/databricks v0.0.0-00010101000000-000000000000 + golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 golang.org/x/oauth2 v0.25.0 ) @@ -27,7 +28,6 @@ require ( go.opentelemetry.io/otel/metric v1.24.0 // indirect go.opentelemetry.io/otel/trace v1.24.0 // indirect golang.org/x/crypto v0.31.0 // indirect - golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.33.0 // indirect golang.org/x/sys v0.28.0 // indirect diff --git a/catalog/v2/api.go b/catalog/v2/api.go index d4bc2b367..947dbedc0 100755 --- a/catalog/v2/api.go +++ b/catalog/v2/api.go @@ -112,47 +112,12 @@ func (a *AccountMetastoreAssignmentsAPI) GetByWorkspaceId(ctx context.Context, w }) } -// Get all workspaces assigned to a metastore. -// -// Gets a list of all Databricks workspace IDs that have been assigned to given -// metastore. -// -// This method is generated by Databricks SDK Code Generator. -func (a *AccountMetastoreAssignmentsAPI) List(ctx context.Context, request ListAccountMetastoreAssignmentsRequest) listing.Iterator[int64] { - - getNextPage := func(ctx context.Context, req ListAccountMetastoreAssignmentsRequest) (*ListAccountMetastoreAssignmentsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.accountMetastoreAssignmentsImpl.List(ctx, req) - } - getItems := func(resp *ListAccountMetastoreAssignmentsResponse) []int64 { - return resp.WorkspaceIds - } - - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - nil) - return iterator -} - -// Get all workspaces assigned to a metastore. -// -// Gets a list of all Databricks workspace IDs that have been assigned to given -// metastore. -// -// This method is generated by Databricks SDK Code Generator. -func (a *AccountMetastoreAssignmentsAPI) ListAll(ctx context.Context, request ListAccountMetastoreAssignmentsRequest) ([]int64, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[int64](ctx, iterator) -} - // Get all workspaces assigned to a metastore. // // Gets a list of all Databricks workspace IDs that have been assigned to given // metastore. func (a *AccountMetastoreAssignmentsAPI) ListByMetastoreId(ctx context.Context, metastoreId string) (*ListAccountMetastoreAssignmentsResponse, error) { - return a.accountMetastoreAssignmentsImpl.List(ctx, ListAccountMetastoreAssignmentsRequest{ + return a.accountMetastoreAssignmentsImpl.internalList(ctx, ListAccountMetastoreAssignmentsRequest{ MetastoreId: metastoreId, }) } @@ -236,40 +201,6 @@ func (a *AccountMetastoresAPI) GetByMetastoreId(ctx context.Context, metastoreId }) } -// Get all metastores associated with an account. -// -// Gets all Unity Catalog metastores associated with an account specified by ID. -// -// This method is generated by Databricks SDK Code Generator. -func (a *AccountMetastoresAPI) List(ctx context.Context) listing.Iterator[MetastoreInfo] { - request := struct{}{} - - getNextPage := func(ctx context.Context, req struct{}) (*ListMetastoresResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.accountMetastoresImpl.List(ctx) - } - getItems := func(resp *ListMetastoresResponse) []MetastoreInfo { - return resp.Metastores - } - - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - nil) - return iterator -} - -// Get all metastores associated with an account. -// -// Gets all Unity Catalog metastores associated with an account specified by ID. -// -// This method is generated by Databricks SDK Code Generator. -func (a *AccountMetastoresAPI) ListAll(ctx context.Context) ([]MetastoreInfo, error) { - iterator := a.List(ctx) - return listing.ToSlice[MetastoreInfo](ctx, iterator) -} - type AccountStorageCredentialsInterface interface { // Create a storage credential. @@ -376,47 +307,12 @@ func (a *AccountStorageCredentialsAPI) GetByMetastoreIdAndStorageCredentialName( }) } -// Get all storage credentials assigned to a metastore. -// -// Gets a list of all storage credentials that have been assigned to given -// metastore. -// -// This method is generated by Databricks SDK Code Generator. -func (a *AccountStorageCredentialsAPI) List(ctx context.Context, request ListAccountStorageCredentialsRequest) listing.Iterator[StorageCredentialInfo] { - - getNextPage := func(ctx context.Context, req ListAccountStorageCredentialsRequest) (*ListAccountStorageCredentialsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.accountStorageCredentialsImpl.List(ctx, req) - } - getItems := func(resp *ListAccountStorageCredentialsResponse) []StorageCredentialInfo { - return resp.StorageCredentials - } - - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - nil) - return iterator -} - -// Get all storage credentials assigned to a metastore. -// -// Gets a list of all storage credentials that have been assigned to given -// metastore. -// -// This method is generated by Databricks SDK Code Generator. -func (a *AccountStorageCredentialsAPI) ListAll(ctx context.Context, request ListAccountStorageCredentialsRequest) ([]StorageCredentialInfo, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[StorageCredentialInfo](ctx, iterator) -} - // Get all storage credentials assigned to a metastore. // // Gets a list of all storage credentials that have been assigned to given // metastore. func (a *AccountStorageCredentialsAPI) ListByMetastoreId(ctx context.Context, metastoreId string) (*ListAccountStorageCredentialsResponse, error) { - return a.accountStorageCredentialsImpl.List(ctx, ListAccountStorageCredentialsRequest{ + return a.accountStorageCredentialsImpl.internalList(ctx, ListAccountStorageCredentialsRequest{ MetastoreId: metastoreId, }) } @@ -573,53 +469,6 @@ func (a *CatalogsAPI) GetByName(ctx context.Context, name string) (*CatalogInfo, }) } -// List catalogs. -// -// Gets an array of catalogs in the metastore. If the caller is the metastore -// admin, all catalogs will be retrieved. Otherwise, only catalogs owned by the -// caller (or for which the caller has the **USE_CATALOG** privilege) will be -// retrieved. There is no guarantee of a specific ordering of the elements in -// the array. -// -// This method is generated by Databricks SDK Code Generator. -func (a *CatalogsAPI) List(ctx context.Context, request ListCatalogsRequest) listing.Iterator[CatalogInfo] { - - getNextPage := func(ctx context.Context, req ListCatalogsRequest) (*ListCatalogsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.catalogsImpl.List(ctx, req) - } - getItems := func(resp *ListCatalogsResponse) []CatalogInfo { - return resp.Catalogs - } - getNextReq := func(resp *ListCatalogsResponse) *ListCatalogsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List catalogs. -// -// Gets an array of catalogs in the metastore. If the caller is the metastore -// admin, all catalogs will be retrieved. Otherwise, only catalogs owned by the -// caller (or for which the caller has the **USE_CATALOG** privilege) will be -// retrieved. There is no guarantee of a specific ordering of the elements in -// the array. -// -// This method is generated by Databricks SDK Code Generator. -func (a *CatalogsAPI) ListAll(ctx context.Context, request ListCatalogsRequest) ([]CatalogInfo, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[CatalogInfo](ctx, iterator) -} - type ConnectionsInterface interface { // Create a connection. @@ -721,45 +570,6 @@ func (a *ConnectionsAPI) GetByName(ctx context.Context, name string) (*Connectio }) } -// List connections. -// -// List all connections. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ConnectionsAPI) List(ctx context.Context, request ListConnectionsRequest) listing.Iterator[ConnectionInfo] { - - getNextPage := func(ctx context.Context, req ListConnectionsRequest) (*ListConnectionsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.connectionsImpl.List(ctx, req) - } - getItems := func(resp *ListConnectionsResponse) []ConnectionInfo { - return resp.Connections - } - getNextReq := func(resp *ListConnectionsResponse) *ListConnectionsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List connections. -// -// List all connections. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ConnectionsAPI) ListAll(ctx context.Context, request ListConnectionsRequest) ([]ConnectionInfo, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[ConnectionInfo](ctx, iterator) -} - // ConnectionInfoNameToFullNameMap calls [ConnectionsAPI.ListAll] and creates a map of results with [ConnectionInfo].Name as key and [ConnectionInfo].FullName as value. // // Returns an error if there's more than one [ConnectionInfo] with the same .Name. @@ -924,55 +734,6 @@ func (a *CredentialsAPI) GetCredentialByNameArg(ctx context.Context, nameArg str }) } -// List credentials. -// -// Gets an array of credentials (as __CredentialInfo__ objects). -// -// The array is limited to only the credentials that the caller has permission -// to access. If the caller is a metastore admin, retrieval of credentials is -// unrestricted. There is no guarantee of a specific ordering of the elements in -// the array. -// -// This method is generated by Databricks SDK Code Generator. -func (a *CredentialsAPI) ListCredentials(ctx context.Context, request ListCredentialsRequest) listing.Iterator[CredentialInfo] { - - getNextPage := func(ctx context.Context, req ListCredentialsRequest) (*ListCredentialsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.credentialsImpl.ListCredentials(ctx, req) - } - getItems := func(resp *ListCredentialsResponse) []CredentialInfo { - return resp.Credentials - } - getNextReq := func(resp *ListCredentialsResponse) *ListCredentialsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List credentials. -// -// Gets an array of credentials (as __CredentialInfo__ objects). -// -// The array is limited to only the credentials that the caller has permission -// to access. If the caller is a metastore admin, retrieval of credentials is -// unrestricted. There is no guarantee of a specific ordering of the elements in -// the array. -// -// This method is generated by Databricks SDK Code Generator. -func (a *CredentialsAPI) ListCredentialsAll(ctx context.Context, request ListCredentialsRequest) ([]CredentialInfo, error) { - iterator := a.ListCredentials(ctx, request) - return listing.ToSlice[CredentialInfo](ctx, iterator) -} - type ExternalLocationsInterface interface { // Create an external location. @@ -1084,53 +845,6 @@ func (a *ExternalLocationsAPI) GetByName(ctx context.Context, name string) (*Ext }) } -// List external locations. -// -// Gets an array of external locations (__ExternalLocationInfo__ objects) from -// the metastore. The caller must be a metastore admin, the owner of the -// external location, or a user that has some privilege on the external -// location. There is no guarantee of a specific ordering of the elements in the -// array. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ExternalLocationsAPI) List(ctx context.Context, request ListExternalLocationsRequest) listing.Iterator[ExternalLocationInfo] { - - getNextPage := func(ctx context.Context, req ListExternalLocationsRequest) (*ListExternalLocationsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.externalLocationsImpl.List(ctx, req) - } - getItems := func(resp *ListExternalLocationsResponse) []ExternalLocationInfo { - return resp.ExternalLocations - } - getNextReq := func(resp *ListExternalLocationsResponse) *ListExternalLocationsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List external locations. -// -// Gets an array of external locations (__ExternalLocationInfo__ objects) from -// the metastore. The caller must be a metastore admin, the owner of the -// external location, or a user that has some privilege on the external -// location. There is no guarantee of a specific ordering of the elements in the -// array. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ExternalLocationsAPI) ListAll(ctx context.Context, request ListExternalLocationsRequest) ([]ExternalLocationInfo, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[ExternalLocationInfo](ctx, iterator) -} - type FunctionsInterface interface { // Create a function. @@ -1284,57 +998,6 @@ func (a *FunctionsAPI) GetByName(ctx context.Context, name string) (*FunctionInf }) } -// List functions. -// -// List functions within the specified parent catalog and schema. If the user is -// a metastore admin, all functions are returned in the output list. Otherwise, -// the user must have the **USE_CATALOG** privilege on the catalog and the -// **USE_SCHEMA** privilege on the schema, and the output list contains only -// functions for which either the user has the **EXECUTE** privilege or the user -// is the owner. There is no guarantee of a specific ordering of the elements in -// the array. -// -// This method is generated by Databricks SDK Code Generator. -func (a *FunctionsAPI) List(ctx context.Context, request ListFunctionsRequest) listing.Iterator[FunctionInfo] { - - getNextPage := func(ctx context.Context, req ListFunctionsRequest) (*ListFunctionsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.functionsImpl.List(ctx, req) - } - getItems := func(resp *ListFunctionsResponse) []FunctionInfo { - return resp.Functions - } - getNextReq := func(resp *ListFunctionsResponse) *ListFunctionsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List functions. -// -// List functions within the specified parent catalog and schema. If the user is -// a metastore admin, all functions are returned in the output list. Otherwise, -// the user must have the **USE_CATALOG** privilege on the catalog and the -// **USE_SCHEMA** privilege on the schema, and the output list contains only -// functions for which either the user has the **EXECUTE** privilege or the user -// is the owner. There is no guarantee of a specific ordering of the elements in -// the array. -// -// This method is generated by Databricks SDK Code Generator. -func (a *FunctionsAPI) ListAll(ctx context.Context, request ListFunctionsRequest) ([]FunctionInfo, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[FunctionInfo](ctx, iterator) -} - // FunctionInfoNameToFullNameMap calls [FunctionsAPI.ListAll] and creates a map of results with [FunctionInfo].Name as key and [FunctionInfo].FullName as value. // // Returns an error if there's more than one [FunctionInfo] with the same .Name. @@ -1590,44 +1253,6 @@ func (a *MetastoresAPI) GetById(ctx context.Context, id string) (*MetastoreInfo, }) } -// List metastores. -// -// Gets an array of the available metastores (as __MetastoreInfo__ objects). The -// caller must be an admin to retrieve this info. There is no guarantee of a -// specific ordering of the elements in the array. -// -// This method is generated by Databricks SDK Code Generator. -func (a *MetastoresAPI) List(ctx context.Context) listing.Iterator[MetastoreInfo] { - request := struct{}{} - - getNextPage := func(ctx context.Context, req struct{}) (*ListMetastoresResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.metastoresImpl.List(ctx) - } - getItems := func(resp *ListMetastoresResponse) []MetastoreInfo { - return resp.Metastores - } - - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - nil) - return iterator -} - -// List metastores. -// -// Gets an array of the available metastores (as __MetastoreInfo__ objects). The -// caller must be an admin to retrieve this info. There is no guarantee of a -// specific ordering of the elements in the array. -// -// This method is generated by Databricks SDK Code Generator. -func (a *MetastoresAPI) ListAll(ctx context.Context) ([]MetastoreInfo, error) { - iterator := a.List(ctx) - return listing.ToSlice[MetastoreInfo](ctx, iterator) -} - // MetastoreInfoNameToMetastoreIdMap calls [MetastoresAPI.ListAll] and creates a map of results with [MetastoreInfo].Name as key and [MetastoreInfo].MetastoreId as value. // // Returns an error if there's more than one [MetastoreInfo] with the same .Name. @@ -1887,69 +1512,6 @@ func (a *ModelVersionsAPI) GetByAliasByFullNameAndAlias(ctx context.Context, ful }) } -// List Model Versions. -// -// List model versions. You can list model versions under a particular schema, -// or list all model versions in the current metastore. -// -// The returned models are filtered based on the privileges of the calling user. -// For example, the metastore admin is able to list all the model versions. A -// regular user needs to be the owner or have the **EXECUTE** privilege on the -// parent registered model to recieve the model versions in the response. For -// the latter case, the caller must also be the owner or have the -// **USE_CATALOG** privilege on the parent catalog and the **USE_SCHEMA** -// privilege on the parent schema. -// -// There is no guarantee of a specific ordering of the elements in the response. -// The elements in the response will not contain any aliases or tags. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ModelVersionsAPI) List(ctx context.Context, request ListModelVersionsRequest) listing.Iterator[ModelVersionInfo] { - - getNextPage := func(ctx context.Context, req ListModelVersionsRequest) (*ListModelVersionsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.modelVersionsImpl.List(ctx, req) - } - getItems := func(resp *ListModelVersionsResponse) []ModelVersionInfo { - return resp.ModelVersions - } - getNextReq := func(resp *ListModelVersionsResponse) *ListModelVersionsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List Model Versions. -// -// List model versions. You can list model versions under a particular schema, -// or list all model versions in the current metastore. -// -// The returned models are filtered based on the privileges of the calling user. -// For example, the metastore admin is able to list all the model versions. A -// regular user needs to be the owner or have the **EXECUTE** privilege on the -// parent registered model to recieve the model versions in the response. For -// the latter case, the caller must also be the owner or have the -// **USE_CATALOG** privilege on the parent catalog and the **USE_SCHEMA** -// privilege on the parent schema. -// -// There is no guarantee of a specific ordering of the elements in the response. -// The elements in the response will not contain any aliases or tags. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ModelVersionsAPI) ListAll(ctx context.Context, request ListModelVersionsRequest) ([]ModelVersionInfo, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[ModelVersionInfo](ctx, iterator) -} - // List Model Versions. // // List model versions. You can list model versions under a particular schema, @@ -1966,7 +1528,7 @@ func (a *ModelVersionsAPI) ListAll(ctx context.Context, request ListModelVersion // There is no guarantee of a specific ordering of the elements in the response. // The elements in the response will not contain any aliases or tags. func (a *ModelVersionsAPI) ListByFullName(ctx context.Context, fullName string) (*ListModelVersionsResponse, error) { - return a.modelVersionsImpl.List(ctx, ListModelVersionsRequest{ + return a.modelVersionsImpl.internalList(ctx, ListModelVersionsRequest{ FullName: fullName, }) } @@ -2583,67 +2145,6 @@ func (a *RegisteredModelsAPI) GetByFullName(ctx context.Context, fullName string }) } -// List Registered Models. -// -// List registered models. You can list registered models under a particular -// schema, or list all registered models in the current metastore. -// -// The returned models are filtered based on the privileges of the calling user. -// For example, the metastore admin is able to list all the registered models. A -// regular user needs to be the owner or have the **EXECUTE** privilege on the -// registered model to recieve the registered models in the response. For the -// latter case, the caller must also be the owner or have the **USE_CATALOG** -// privilege on the parent catalog and the **USE_SCHEMA** privilege on the -// parent schema. -// -// There is no guarantee of a specific ordering of the elements in the response. -// -// This method is generated by Databricks SDK Code Generator. -func (a *RegisteredModelsAPI) List(ctx context.Context, request ListRegisteredModelsRequest) listing.Iterator[RegisteredModelInfo] { - - getNextPage := func(ctx context.Context, req ListRegisteredModelsRequest) (*ListRegisteredModelsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.registeredModelsImpl.List(ctx, req) - } - getItems := func(resp *ListRegisteredModelsResponse) []RegisteredModelInfo { - return resp.RegisteredModels - } - getNextReq := func(resp *ListRegisteredModelsResponse) *ListRegisteredModelsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List Registered Models. -// -// List registered models. You can list registered models under a particular -// schema, or list all registered models in the current metastore. -// -// The returned models are filtered based on the privileges of the calling user. -// For example, the metastore admin is able to list all the registered models. A -// regular user needs to be the owner or have the **EXECUTE** privilege on the -// registered model to recieve the registered models in the response. For the -// latter case, the caller must also be the owner or have the **USE_CATALOG** -// privilege on the parent catalog and the **USE_SCHEMA** privilege on the -// parent schema. -// -// There is no guarantee of a specific ordering of the elements in the response. -// -// This method is generated by Databricks SDK Code Generator. -func (a *RegisteredModelsAPI) ListAll(ctx context.Context, request ListRegisteredModelsRequest) ([]RegisteredModelInfo, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[RegisteredModelInfo](ctx, iterator) -} - // RegisteredModelInfoNameToFullNameMap calls [RegisteredModelsAPI.ListAll] and creates a map of results with [RegisteredModelInfo].Name as key and [RegisteredModelInfo].FullName as value. // // Returns an error if there's more than one [RegisteredModelInfo] with the same .Name. @@ -2768,49 +2269,6 @@ func (a *ResourceQuotasAPI) GetQuotaByParentSecurableTypeAndParentFullNameAndQuo }) } -// List all resource quotas under a metastore. -// -// ListQuotas returns all quota values under the metastore. There are no SLAs on -// the freshness of the counts returned. This API does not trigger a refresh of -// quota counts. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ResourceQuotasAPI) ListQuotas(ctx context.Context, request ListQuotasRequest) listing.Iterator[QuotaInfo] { - - getNextPage := func(ctx context.Context, req ListQuotasRequest) (*ListQuotasResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.resourceQuotasImpl.ListQuotas(ctx, req) - } - getItems := func(resp *ListQuotasResponse) []QuotaInfo { - return resp.Quotas - } - getNextReq := func(resp *ListQuotasResponse) *ListQuotasRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List all resource quotas under a metastore. -// -// ListQuotas returns all quota values under the metastore. There are no SLAs on -// the freshness of the counts returned. This API does not trigger a refresh of -// quota counts. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ResourceQuotasAPI) ListQuotasAll(ctx context.Context, request ListQuotasRequest) ([]QuotaInfo, error) { - iterator := a.ListQuotas(ctx, request) - return listing.ToSlice[QuotaInfo](ctx, iterator) -} - type SchemasInterface interface { // Create a schema. @@ -2934,53 +2392,6 @@ func (a *SchemasAPI) GetByFullName(ctx context.Context, fullName string) (*Schem }) } -// List schemas. -// -// Gets an array of schemas for a catalog in the metastore. If the caller is the -// metastore admin or the owner of the parent catalog, all schemas for the -// catalog will be retrieved. Otherwise, only schemas owned by the caller (or -// for which the caller has the **USE_SCHEMA** privilege) will be retrieved. -// There is no guarantee of a specific ordering of the elements in the array. -// -// This method is generated by Databricks SDK Code Generator. -func (a *SchemasAPI) List(ctx context.Context, request ListSchemasRequest) listing.Iterator[SchemaInfo] { - - getNextPage := func(ctx context.Context, req ListSchemasRequest) (*ListSchemasResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.schemasImpl.List(ctx, req) - } - getItems := func(resp *ListSchemasResponse) []SchemaInfo { - return resp.Schemas - } - getNextReq := func(resp *ListSchemasResponse) *ListSchemasRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List schemas. -// -// Gets an array of schemas for a catalog in the metastore. If the caller is the -// metastore admin or the owner of the parent catalog, all schemas for the -// catalog will be retrieved. Otherwise, only schemas owned by the caller (or -// for which the caller has the **USE_SCHEMA** privilege) will be retrieved. -// There is no guarantee of a specific ordering of the elements in the array. -// -// This method is generated by Databricks SDK Code Generator. -func (a *SchemasAPI) ListAll(ctx context.Context, request ListSchemasRequest) ([]SchemaInfo, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[SchemaInfo](ctx, iterator) -} - // SchemaInfoNameToFullNameMap calls [SchemasAPI.ListAll] and creates a map of results with [SchemaInfo].Name as key and [SchemaInfo].FullName as value. // // Returns an error if there's more than one [SchemaInfo] with the same .Name. @@ -3166,53 +2577,6 @@ func (a *StorageCredentialsAPI) GetByName(ctx context.Context, name string) (*St }) } -// List credentials. -// -// Gets an array of storage credentials (as __StorageCredentialInfo__ objects). -// The array is limited to only those storage credentials the caller has -// permission to access. If the caller is a metastore admin, retrieval of -// credentials is unrestricted. There is no guarantee of a specific ordering of -// the elements in the array. -// -// This method is generated by Databricks SDK Code Generator. -func (a *StorageCredentialsAPI) List(ctx context.Context, request ListStorageCredentialsRequest) listing.Iterator[StorageCredentialInfo] { - - getNextPage := func(ctx context.Context, req ListStorageCredentialsRequest) (*ListStorageCredentialsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.storageCredentialsImpl.List(ctx, req) - } - getItems := func(resp *ListStorageCredentialsResponse) []StorageCredentialInfo { - return resp.StorageCredentials - } - getNextReq := func(resp *ListStorageCredentialsResponse) *ListStorageCredentialsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List credentials. -// -// Gets an array of storage credentials (as __StorageCredentialInfo__ objects). -// The array is limited to only those storage credentials the caller has -// permission to access. If the caller is a metastore admin, retrieval of -// credentials is unrestricted. There is no guarantee of a specific ordering of -// the elements in the array. -// -// This method is generated by Databricks SDK Code Generator. -func (a *StorageCredentialsAPI) ListAll(ctx context.Context, request ListStorageCredentialsRequest) ([]StorageCredentialInfo, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[StorageCredentialInfo](ctx, iterator) -} - // StorageCredentialInfoNameToIdMap calls [StorageCredentialsAPI.ListAll] and creates a map of results with [StorageCredentialInfo].Name as key and [StorageCredentialInfo].Id as value. // // Returns an error if there's more than one [StorageCredentialInfo] with the same .Name. @@ -3307,53 +2671,12 @@ func (a *SystemSchemasAPI) DisableByMetastoreIdAndSchemaName(ctx context.Context }) } -// List system schemas. -// -// Gets an array of system schemas for a metastore. The caller must be an -// account admin or a metastore admin. -// -// This method is generated by Databricks SDK Code Generator. -func (a *SystemSchemasAPI) List(ctx context.Context, request ListSystemSchemasRequest) listing.Iterator[SystemSchemaInfo] { - - getNextPage := func(ctx context.Context, req ListSystemSchemasRequest) (*ListSystemSchemasResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.systemSchemasImpl.List(ctx, req) - } - getItems := func(resp *ListSystemSchemasResponse) []SystemSchemaInfo { - return resp.Schemas - } - getNextReq := func(resp *ListSystemSchemasResponse) *ListSystemSchemasRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List system schemas. -// -// Gets an array of system schemas for a metastore. The caller must be an -// account admin or a metastore admin. -// -// This method is generated by Databricks SDK Code Generator. -func (a *SystemSchemasAPI) ListAll(ctx context.Context, request ListSystemSchemasRequest) ([]SystemSchemaInfo, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[SystemSchemaInfo](ctx, iterator) -} - // List system schemas. // // Gets an array of system schemas for a metastore. The caller must be an // account admin or a metastore admin. func (a *SystemSchemasAPI) ListByMetastoreId(ctx context.Context, metastoreId string) (*ListSystemSchemasResponse, error) { - return a.systemSchemasImpl.List(ctx, ListSystemSchemasRequest{ + return a.systemSchemasImpl.internalList(ctx, ListSystemSchemasRequest{ MetastoreId: metastoreId, }) } @@ -3661,55 +2984,6 @@ func (a *TablesAPI) GetByFullName(ctx context.Context, fullName string) (*TableI }) } -// List tables. -// -// Gets an array of all tables for the current metastore under the parent -// catalog and schema. The caller must be a metastore admin or an owner of (or -// have the **SELECT** privilege on) the table. For the latter case, the caller -// must also be the owner or have the **USE_CATALOG** privilege on the parent -// catalog and the **USE_SCHEMA** privilege on the parent schema. There is no -// guarantee of a specific ordering of the elements in the array. -// -// This method is generated by Databricks SDK Code Generator. -func (a *TablesAPI) List(ctx context.Context, request ListTablesRequest) listing.Iterator[TableInfo] { - - getNextPage := func(ctx context.Context, req ListTablesRequest) (*ListTablesResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.tablesImpl.List(ctx, req) - } - getItems := func(resp *ListTablesResponse) []TableInfo { - return resp.Tables - } - getNextReq := func(resp *ListTablesResponse) *ListTablesRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List tables. -// -// Gets an array of all tables for the current metastore under the parent -// catalog and schema. The caller must be a metastore admin or an owner of (or -// have the **SELECT** privilege on) the table. For the latter case, the caller -// must also be the owner or have the **USE_CATALOG** privilege on the parent -// catalog and the **USE_SCHEMA** privilege on the parent schema. There is no -// guarantee of a specific ordering of the elements in the array. -// -// This method is generated by Databricks SDK Code Generator. -func (a *TablesAPI) ListAll(ctx context.Context, request ListTablesRequest) ([]TableInfo, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[TableInfo](ctx, iterator) -} - // TableInfoNameToTableIdMap calls [TablesAPI.ListAll] and creates a map of results with [TableInfo].Name as key and [TableInfo].TableId as value. // // Returns an error if there's more than one [TableInfo] with the same .Name. @@ -3763,65 +3037,6 @@ func (a *TablesAPI) GetByName(ctx context.Context, name string) (*TableInfo, err return &alternatives[0], nil } -// List table summaries. -// -// Gets an array of summaries for tables for a schema and catalog within the -// metastore. The table summaries returned are either: -// -// * summaries for tables (within the current metastore and parent catalog and -// schema), when the user is a metastore admin, or: * summaries for tables and -// schemas (within the current metastore and parent catalog) for which the user -// has ownership or the **SELECT** privilege on the table and ownership or -// **USE_SCHEMA** privilege on the schema, provided that the user also has -// ownership or the **USE_CATALOG** privilege on the parent catalog. -// -// There is no guarantee of a specific ordering of the elements in the array. -// -// This method is generated by Databricks SDK Code Generator. -func (a *TablesAPI) ListSummaries(ctx context.Context, request ListSummariesRequest) listing.Iterator[TableSummary] { - - getNextPage := func(ctx context.Context, req ListSummariesRequest) (*ListTableSummariesResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.tablesImpl.ListSummaries(ctx, req) - } - getItems := func(resp *ListTableSummariesResponse) []TableSummary { - return resp.Tables - } - getNextReq := func(resp *ListTableSummariesResponse) *ListSummariesRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List table summaries. -// -// Gets an array of summaries for tables for a schema and catalog within the -// metastore. The table summaries returned are either: -// -// * summaries for tables (within the current metastore and parent catalog and -// schema), when the user is a metastore admin, or: * summaries for tables and -// schemas (within the current metastore and parent catalog) for which the user -// has ownership or the **SELECT** privilege on the table and ownership or -// **USE_SCHEMA** privilege on the schema, provided that the user also has -// ownership or the **USE_CATALOG** privilege on the parent catalog. -// -// There is no guarantee of a specific ordering of the elements in the array. -// -// This method is generated by Databricks SDK Code Generator. -func (a *TablesAPI) ListSummariesAll(ctx context.Context, request ListSummariesRequest) ([]TableSummary, error) { - iterator := a.ListSummaries(ctx, request) - return listing.ToSlice[TableSummary](ctx, iterator) -} - type TemporaryTableCredentialsInterface interface { // Generate a temporary table credential. @@ -4025,65 +3240,6 @@ func (a *VolumesAPI) DeleteByName(ctx context.Context, name string) error { }) } -// List Volumes. -// -// Gets an array of volumes for the current metastore under the parent catalog -// and schema. -// -// The returned volumes are filtered based on the privileges of the calling -// user. For example, the metastore admin is able to list all the volumes. A -// regular user needs to be the owner or have the **READ VOLUME** privilege on -// the volume to recieve the volumes in the response. For the latter case, the -// caller must also be the owner or have the **USE_CATALOG** privilege on the -// parent catalog and the **USE_SCHEMA** privilege on the parent schema. -// -// There is no guarantee of a specific ordering of the elements in the array. -// -// This method is generated by Databricks SDK Code Generator. -func (a *VolumesAPI) List(ctx context.Context, request ListVolumesRequest) listing.Iterator[VolumeInfo] { - - getNextPage := func(ctx context.Context, req ListVolumesRequest) (*ListVolumesResponseContent, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.volumesImpl.List(ctx, req) - } - getItems := func(resp *ListVolumesResponseContent) []VolumeInfo { - return resp.Volumes - } - getNextReq := func(resp *ListVolumesResponseContent) *ListVolumesRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List Volumes. -// -// Gets an array of volumes for the current metastore under the parent catalog -// and schema. -// -// The returned volumes are filtered based on the privileges of the calling -// user. For example, the metastore admin is able to list all the volumes. A -// regular user needs to be the owner or have the **READ VOLUME** privilege on -// the volume to recieve the volumes in the response. For the latter case, the -// caller must also be the owner or have the **USE_CATALOG** privilege on the -// parent catalog and the **USE_SCHEMA** privilege on the parent schema. -// -// There is no guarantee of a specific ordering of the elements in the array. -// -// This method is generated by Databricks SDK Code Generator. -func (a *VolumesAPI) ListAll(ctx context.Context, request ListVolumesRequest) ([]VolumeInfo, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[VolumeInfo](ctx, iterator) -} - // VolumeInfoNameToVolumeIdMap calls [VolumesAPI.ListAll] and creates a map of results with [VolumeInfo].Name as key and [VolumeInfo].VolumeId as value. // // Returns an error if there's more than one [VolumeInfo] with the same .Name. @@ -4241,53 +3397,12 @@ func (a *WorkspaceBindingsAPI) GetByName(ctx context.Context, name string) (*Cur }) } -// Get securable workspace bindings. -// -// Gets workspace bindings of the securable. The caller must be a metastore -// admin or an owner of the securable. -// -// This method is generated by Databricks SDK Code Generator. -func (a *WorkspaceBindingsAPI) GetBindings(ctx context.Context, request GetBindingsRequest) listing.Iterator[WorkspaceBinding] { - - getNextPage := func(ctx context.Context, req GetBindingsRequest) (*WorkspaceBindingsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.workspaceBindingsImpl.GetBindings(ctx, req) - } - getItems := func(resp *WorkspaceBindingsResponse) []WorkspaceBinding { - return resp.Bindings - } - getNextReq := func(resp *WorkspaceBindingsResponse) *GetBindingsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// Get securable workspace bindings. -// -// Gets workspace bindings of the securable. The caller must be a metastore -// admin or an owner of the securable. -// -// This method is generated by Databricks SDK Code Generator. -func (a *WorkspaceBindingsAPI) GetBindingsAll(ctx context.Context, request GetBindingsRequest) ([]WorkspaceBinding, error) { - iterator := a.GetBindings(ctx, request) - return listing.ToSlice[WorkspaceBinding](ctx, iterator) -} - // Get securable workspace bindings. // // Gets workspace bindings of the securable. The caller must be a metastore // admin or an owner of the securable. func (a *WorkspaceBindingsAPI) GetBindingsBySecurableTypeAndSecurableName(ctx context.Context, securableType GetBindingsSecurableType, securableName string) (*WorkspaceBindingsResponse, error) { - return a.workspaceBindingsImpl.GetBindings(ctx, GetBindingsRequest{ + return a.workspaceBindingsImpl.internalGetBindings(ctx, GetBindingsRequest{ SecurableType: securableType, SecurableName: securableName, }) diff --git a/catalog/v2/impl.go b/catalog/v2/impl.go index 884a63e7b..4c10e6ada 100755 --- a/catalog/v2/impl.go +++ b/catalog/v2/impl.go @@ -8,6 +8,8 @@ import ( "net/http" "github.com/databricks/databricks-sdk-go/databricks/client" + "github.com/databricks/databricks-sdk-go/databricks/listing" + "github.com/databricks/databricks-sdk-go/databricks/useragent" ) // unexported type that holds implementations of just AccountMetastoreAssignments API methods @@ -18,47 +20,82 @@ type accountMetastoreAssignmentsImpl struct { func (a *accountMetastoreAssignmentsImpl) Create(ctx context.Context, request AccountsCreateMetastoreAssignment) error { var createResponse CreateResponse path := fmt.Sprintf("/api/2.0/accounts/%v/workspaces/%v/metastores/%v", a.client.ConfiguredAccountID(), request.WorkspaceId, request.MetastoreId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createResponse) return err } func (a *accountMetastoreAssignmentsImpl) Delete(ctx context.Context, request DeleteAccountMetastoreAssignmentRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.0/accounts/%v/workspaces/%v/metastores/%v", a.client.ConfiguredAccountID(), request.WorkspaceId, request.MetastoreId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *accountMetastoreAssignmentsImpl) Get(ctx context.Context, request GetAccountMetastoreAssignmentRequest) (*AccountsMetastoreAssignment, error) { var accountsMetastoreAssignment AccountsMetastoreAssignment path := fmt.Sprintf("/api/2.0/accounts/%v/workspaces/%v/metastore", a.client.ConfiguredAccountID(), request.WorkspaceId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &accountsMetastoreAssignment) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &accountsMetastoreAssignment) return &accountsMetastoreAssignment, err } -func (a *accountMetastoreAssignmentsImpl) List(ctx context.Context, request ListAccountMetastoreAssignmentsRequest) (*ListAccountMetastoreAssignmentsResponse, error) { +// Get all workspaces assigned to a metastore. +// +// Gets a list of all Databricks workspace IDs that have been assigned to given +// metastore. +func (a *accountMetastoreAssignmentsImpl) List(ctx context.Context, request ListAccountMetastoreAssignmentsRequest) listing.Iterator[int64] { + + getNextPage := func(ctx context.Context, req ListAccountMetastoreAssignmentsRequest) (*ListAccountMetastoreAssignmentsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListAccountMetastoreAssignmentsResponse) []int64 { + return resp.WorkspaceIds + } + + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + nil) + return iterator +} + +// Get all workspaces assigned to a metastore. +// +// Gets a list of all Databricks workspace IDs that have been assigned to given +// metastore. +func (a *accountMetastoreAssignmentsImpl) ListAll(ctx context.Context, request ListAccountMetastoreAssignmentsRequest) ([]int64, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[int64](ctx, iterator) +} +func (a *accountMetastoreAssignmentsImpl) internalList(ctx context.Context, request ListAccountMetastoreAssignmentsRequest) (*ListAccountMetastoreAssignmentsResponse, error) { var listAccountMetastoreAssignmentsResponse ListAccountMetastoreAssignmentsResponse path := fmt.Sprintf("/api/2.0/accounts/%v/metastores/%v/workspaces", a.client.ConfiguredAccountID(), request.MetastoreId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listAccountMetastoreAssignmentsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listAccountMetastoreAssignmentsResponse) return &listAccountMetastoreAssignmentsResponse, err } func (a *accountMetastoreAssignmentsImpl) Update(ctx context.Context, request AccountsUpdateMetastoreAssignment) error { var updateResponse UpdateResponse path := fmt.Sprintf("/api/2.0/accounts/%v/workspaces/%v/metastores/%v", a.client.ConfiguredAccountID(), request.WorkspaceId, request.MetastoreId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &updateResponse) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &updateResponse) return err } @@ -70,47 +107,81 @@ type accountMetastoresImpl struct { func (a *accountMetastoresImpl) Create(ctx context.Context, request AccountsCreateMetastore) (*AccountsMetastoreInfo, error) { var accountsMetastoreInfo AccountsMetastoreInfo path := fmt.Sprintf("/api/2.0/accounts/%v/metastores", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &accountsMetastoreInfo) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &accountsMetastoreInfo) return &accountsMetastoreInfo, err } func (a *accountMetastoresImpl) Delete(ctx context.Context, request DeleteAccountMetastoreRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.0/accounts/%v/metastores/%v", a.client.ConfiguredAccountID(), request.MetastoreId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *accountMetastoresImpl) Get(ctx context.Context, request GetAccountMetastoreRequest) (*AccountsMetastoreInfo, error) { var accountsMetastoreInfo AccountsMetastoreInfo path := fmt.Sprintf("/api/2.0/accounts/%v/metastores/%v", a.client.ConfiguredAccountID(), request.MetastoreId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &accountsMetastoreInfo) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &accountsMetastoreInfo) return &accountsMetastoreInfo, err } -func (a *accountMetastoresImpl) List(ctx context.Context) (*ListMetastoresResponse, error) { +// Get all metastores associated with an account. +// +// Gets all Unity Catalog metastores associated with an account specified by ID. +func (a *accountMetastoresImpl) List(ctx context.Context) listing.Iterator[MetastoreInfo] { + request := struct{}{} + + getNextPage := func(ctx context.Context, req struct{}) (*ListMetastoresResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx) + } + getItems := func(resp *ListMetastoresResponse) []MetastoreInfo { + return resp.Metastores + } + + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + nil) + return iterator +} + +// Get all metastores associated with an account. +// +// Gets all Unity Catalog metastores associated with an account specified by ID. +func (a *accountMetastoresImpl) ListAll(ctx context.Context) ([]MetastoreInfo, error) { + iterator := a.List(ctx) + return listing.ToSlice[MetastoreInfo](ctx, iterator) +} +func (a *accountMetastoresImpl) internalList(ctx context.Context) (*ListMetastoresResponse, error) { var listMetastoresResponse ListMetastoresResponse path := fmt.Sprintf("/api/2.0/accounts/%v/metastores", a.client.ConfiguredAccountID()) + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &listMetastoresResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &listMetastoresResponse) return &listMetastoresResponse, err } func (a *accountMetastoresImpl) Update(ctx context.Context, request AccountsUpdateMetastore) (*AccountsMetastoreInfo, error) { var accountsMetastoreInfo AccountsMetastoreInfo path := fmt.Sprintf("/api/2.0/accounts/%v/metastores/%v", a.client.ConfiguredAccountID(), request.MetastoreId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &accountsMetastoreInfo) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &accountsMetastoreInfo) return &accountsMetastoreInfo, err } @@ -122,47 +193,82 @@ type accountStorageCredentialsImpl struct { func (a *accountStorageCredentialsImpl) Create(ctx context.Context, request AccountsCreateStorageCredential) (*AccountsStorageCredentialInfo, error) { var accountsStorageCredentialInfo AccountsStorageCredentialInfo path := fmt.Sprintf("/api/2.0/accounts/%v/metastores/%v/storage-credentials", a.client.ConfiguredAccountID(), request.MetastoreId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &accountsStorageCredentialInfo) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &accountsStorageCredentialInfo) return &accountsStorageCredentialInfo, err } func (a *accountStorageCredentialsImpl) Delete(ctx context.Context, request DeleteAccountStorageCredentialRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.0/accounts/%v/metastores/%v/storage-credentials/%v", a.client.ConfiguredAccountID(), request.MetastoreId, request.StorageCredentialName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *accountStorageCredentialsImpl) Get(ctx context.Context, request GetAccountStorageCredentialRequest) (*AccountsStorageCredentialInfo, error) { var accountsStorageCredentialInfo AccountsStorageCredentialInfo path := fmt.Sprintf("/api/2.0/accounts/%v/metastores/%v/storage-credentials/%v", a.client.ConfiguredAccountID(), request.MetastoreId, request.StorageCredentialName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &accountsStorageCredentialInfo) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &accountsStorageCredentialInfo) return &accountsStorageCredentialInfo, err } -func (a *accountStorageCredentialsImpl) List(ctx context.Context, request ListAccountStorageCredentialsRequest) (*ListAccountStorageCredentialsResponse, error) { +// Get all storage credentials assigned to a metastore. +// +// Gets a list of all storage credentials that have been assigned to given +// metastore. +func (a *accountStorageCredentialsImpl) List(ctx context.Context, request ListAccountStorageCredentialsRequest) listing.Iterator[StorageCredentialInfo] { + + getNextPage := func(ctx context.Context, req ListAccountStorageCredentialsRequest) (*ListAccountStorageCredentialsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListAccountStorageCredentialsResponse) []StorageCredentialInfo { + return resp.StorageCredentials + } + + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + nil) + return iterator +} + +// Get all storage credentials assigned to a metastore. +// +// Gets a list of all storage credentials that have been assigned to given +// metastore. +func (a *accountStorageCredentialsImpl) ListAll(ctx context.Context, request ListAccountStorageCredentialsRequest) ([]StorageCredentialInfo, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[StorageCredentialInfo](ctx, iterator) +} +func (a *accountStorageCredentialsImpl) internalList(ctx context.Context, request ListAccountStorageCredentialsRequest) (*ListAccountStorageCredentialsResponse, error) { var listAccountStorageCredentialsResponse ListAccountStorageCredentialsResponse path := fmt.Sprintf("/api/2.0/accounts/%v/metastores/%v/storage-credentials", a.client.ConfiguredAccountID(), request.MetastoreId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listAccountStorageCredentialsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listAccountStorageCredentialsResponse) return &listAccountStorageCredentialsResponse, err } func (a *accountStorageCredentialsImpl) Update(ctx context.Context, request AccountsUpdateStorageCredential) (*AccountsStorageCredentialInfo, error) { var accountsStorageCredentialInfo AccountsStorageCredentialInfo path := fmt.Sprintf("/api/2.0/accounts/%v/metastores/%v/storage-credentials/%v", a.client.ConfiguredAccountID(), request.MetastoreId, request.StorageCredentialName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &accountsStorageCredentialInfo) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &accountsStorageCredentialInfo) return &accountsStorageCredentialInfo, err } @@ -174,19 +280,21 @@ type artifactAllowlistsImpl struct { func (a *artifactAllowlistsImpl) Get(ctx context.Context, request GetArtifactAllowlistRequest) (*ArtifactAllowlistInfo, error) { var artifactAllowlistInfo ArtifactAllowlistInfo path := fmt.Sprintf("/api/2.1/unity-catalog/artifact-allowlists/%v", request.ArtifactType) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &artifactAllowlistInfo) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &artifactAllowlistInfo) return &artifactAllowlistInfo, err } func (a *artifactAllowlistsImpl) Update(ctx context.Context, request SetArtifactAllowlist) (*ArtifactAllowlistInfo, error) { var artifactAllowlistInfo ArtifactAllowlistInfo path := fmt.Sprintf("/api/2.1/unity-catalog/artifact-allowlists/%v", request.ArtifactType) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &artifactAllowlistInfo) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &artifactAllowlistInfo) return &artifactAllowlistInfo, err } @@ -198,47 +306,94 @@ type catalogsImpl struct { func (a *catalogsImpl) Create(ctx context.Context, request CreateCatalog) (*CatalogInfo, error) { var catalogInfo CatalogInfo path := "/api/2.1/unity-catalog/catalogs" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &catalogInfo) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &catalogInfo) return &catalogInfo, err } func (a *catalogsImpl) Delete(ctx context.Context, request DeleteCatalogRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.1/unity-catalog/catalogs/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *catalogsImpl) Get(ctx context.Context, request GetCatalogRequest) (*CatalogInfo, error) { var catalogInfo CatalogInfo path := fmt.Sprintf("/api/2.1/unity-catalog/catalogs/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &catalogInfo) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &catalogInfo) return &catalogInfo, err } -func (a *catalogsImpl) List(ctx context.Context, request ListCatalogsRequest) (*ListCatalogsResponse, error) { +// List catalogs. +// +// Gets an array of catalogs in the metastore. If the caller is the metastore +// admin, all catalogs will be retrieved. Otherwise, only catalogs owned by the +// caller (or for which the caller has the **USE_CATALOG** privilege) will be +// retrieved. There is no guarantee of a specific ordering of the elements in +// the array. +func (a *catalogsImpl) List(ctx context.Context, request ListCatalogsRequest) listing.Iterator[CatalogInfo] { + + getNextPage := func(ctx context.Context, req ListCatalogsRequest) (*ListCatalogsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListCatalogsResponse) []CatalogInfo { + return resp.Catalogs + } + getNextReq := func(resp *ListCatalogsResponse) *ListCatalogsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List catalogs. +// +// Gets an array of catalogs in the metastore. If the caller is the metastore +// admin, all catalogs will be retrieved. Otherwise, only catalogs owned by the +// caller (or for which the caller has the **USE_CATALOG** privilege) will be +// retrieved. There is no guarantee of a specific ordering of the elements in +// the array. +func (a *catalogsImpl) ListAll(ctx context.Context, request ListCatalogsRequest) ([]CatalogInfo, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[CatalogInfo](ctx, iterator) +} +func (a *catalogsImpl) internalList(ctx context.Context, request ListCatalogsRequest) (*ListCatalogsResponse, error) { var listCatalogsResponse ListCatalogsResponse path := "/api/2.1/unity-catalog/catalogs" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listCatalogsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listCatalogsResponse) return &listCatalogsResponse, err } func (a *catalogsImpl) Update(ctx context.Context, request UpdateCatalog) (*CatalogInfo, error) { var catalogInfo CatalogInfo path := fmt.Sprintf("/api/2.1/unity-catalog/catalogs/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &catalogInfo) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &catalogInfo) return &catalogInfo, err } @@ -250,47 +405,86 @@ type connectionsImpl struct { func (a *connectionsImpl) Create(ctx context.Context, request CreateConnection) (*ConnectionInfo, error) { var connectionInfo ConnectionInfo path := "/api/2.1/unity-catalog/connections" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &connectionInfo) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &connectionInfo) return &connectionInfo, err } func (a *connectionsImpl) Delete(ctx context.Context, request DeleteConnectionRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.1/unity-catalog/connections/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *connectionsImpl) Get(ctx context.Context, request GetConnectionRequest) (*ConnectionInfo, error) { var connectionInfo ConnectionInfo path := fmt.Sprintf("/api/2.1/unity-catalog/connections/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &connectionInfo) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &connectionInfo) return &connectionInfo, err } -func (a *connectionsImpl) List(ctx context.Context, request ListConnectionsRequest) (*ListConnectionsResponse, error) { +// List connections. +// +// List all connections. +func (a *connectionsImpl) List(ctx context.Context, request ListConnectionsRequest) listing.Iterator[ConnectionInfo] { + + getNextPage := func(ctx context.Context, req ListConnectionsRequest) (*ListConnectionsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListConnectionsResponse) []ConnectionInfo { + return resp.Connections + } + getNextReq := func(resp *ListConnectionsResponse) *ListConnectionsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List connections. +// +// List all connections. +func (a *connectionsImpl) ListAll(ctx context.Context, request ListConnectionsRequest) ([]ConnectionInfo, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[ConnectionInfo](ctx, iterator) +} +func (a *connectionsImpl) internalList(ctx context.Context, request ListConnectionsRequest) (*ListConnectionsResponse, error) { var listConnectionsResponse ListConnectionsResponse path := "/api/2.1/unity-catalog/connections" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listConnectionsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listConnectionsResponse) return &listConnectionsResponse, err } func (a *connectionsImpl) Update(ctx context.Context, request UpdateConnection) (*ConnectionInfo, error) { var connectionInfo ConnectionInfo path := fmt.Sprintf("/api/2.1/unity-catalog/connections/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &connectionInfo) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &connectionInfo) return &connectionInfo, err } @@ -302,67 +496,118 @@ type credentialsImpl struct { func (a *credentialsImpl) CreateCredential(ctx context.Context, request CreateCredentialRequest) (*CredentialInfo, error) { var credentialInfo CredentialInfo path := "/api/2.1/unity-catalog/credentials" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &credentialInfo) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &credentialInfo) return &credentialInfo, err } func (a *credentialsImpl) DeleteCredential(ctx context.Context, request DeleteCredentialRequest) error { var deleteCredentialResponse DeleteCredentialResponse path := fmt.Sprintf("/api/2.1/unity-catalog/credentials/%v", request.NameArg) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteCredentialResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteCredentialResponse) return err } func (a *credentialsImpl) GenerateTemporaryServiceCredential(ctx context.Context, request GenerateTemporaryServiceCredentialRequest) (*TemporaryCredentials, error) { var temporaryCredentials TemporaryCredentials path := "/api/2.1/unity-catalog/temporary-service-credentials" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &temporaryCredentials) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &temporaryCredentials) return &temporaryCredentials, err } func (a *credentialsImpl) GetCredential(ctx context.Context, request GetCredentialRequest) (*CredentialInfo, error) { var credentialInfo CredentialInfo path := fmt.Sprintf("/api/2.1/unity-catalog/credentials/%v", request.NameArg) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &credentialInfo) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &credentialInfo) return &credentialInfo, err } -func (a *credentialsImpl) ListCredentials(ctx context.Context, request ListCredentialsRequest) (*ListCredentialsResponse, error) { +// List credentials. +// +// Gets an array of credentials (as __CredentialInfo__ objects). +// +// The array is limited to only the credentials that the caller has permission +// to access. If the caller is a metastore admin, retrieval of credentials is +// unrestricted. There is no guarantee of a specific ordering of the elements in +// the array. +func (a *credentialsImpl) ListCredentials(ctx context.Context, request ListCredentialsRequest) listing.Iterator[CredentialInfo] { + + getNextPage := func(ctx context.Context, req ListCredentialsRequest) (*ListCredentialsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalListCredentials(ctx, req) + } + getItems := func(resp *ListCredentialsResponse) []CredentialInfo { + return resp.Credentials + } + getNextReq := func(resp *ListCredentialsResponse) *ListCredentialsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List credentials. +// +// Gets an array of credentials (as __CredentialInfo__ objects). +// +// The array is limited to only the credentials that the caller has permission +// to access. If the caller is a metastore admin, retrieval of credentials is +// unrestricted. There is no guarantee of a specific ordering of the elements in +// the array. +func (a *credentialsImpl) ListCredentialsAll(ctx context.Context, request ListCredentialsRequest) ([]CredentialInfo, error) { + iterator := a.ListCredentials(ctx, request) + return listing.ToSlice[CredentialInfo](ctx, iterator) +} +func (a *credentialsImpl) internalListCredentials(ctx context.Context, request ListCredentialsRequest) (*ListCredentialsResponse, error) { var listCredentialsResponse ListCredentialsResponse path := "/api/2.1/unity-catalog/credentials" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listCredentialsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listCredentialsResponse) return &listCredentialsResponse, err } func (a *credentialsImpl) UpdateCredential(ctx context.Context, request UpdateCredentialRequest) (*CredentialInfo, error) { var credentialInfo CredentialInfo path := fmt.Sprintf("/api/2.1/unity-catalog/credentials/%v", request.NameArg) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &credentialInfo) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &credentialInfo) return &credentialInfo, err } func (a *credentialsImpl) ValidateCredential(ctx context.Context, request ValidateCredentialRequest) (*ValidateCredentialResponse, error) { var validateCredentialResponse ValidateCredentialResponse path := "/api/2.1/unity-catalog/validate-credentials" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &validateCredentialResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &validateCredentialResponse) return &validateCredentialResponse, err } @@ -374,47 +619,94 @@ type externalLocationsImpl struct { func (a *externalLocationsImpl) Create(ctx context.Context, request CreateExternalLocation) (*ExternalLocationInfo, error) { var externalLocationInfo ExternalLocationInfo path := "/api/2.1/unity-catalog/external-locations" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &externalLocationInfo) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &externalLocationInfo) return &externalLocationInfo, err } func (a *externalLocationsImpl) Delete(ctx context.Context, request DeleteExternalLocationRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.1/unity-catalog/external-locations/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *externalLocationsImpl) Get(ctx context.Context, request GetExternalLocationRequest) (*ExternalLocationInfo, error) { var externalLocationInfo ExternalLocationInfo path := fmt.Sprintf("/api/2.1/unity-catalog/external-locations/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &externalLocationInfo) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &externalLocationInfo) return &externalLocationInfo, err } -func (a *externalLocationsImpl) List(ctx context.Context, request ListExternalLocationsRequest) (*ListExternalLocationsResponse, error) { +// List external locations. +// +// Gets an array of external locations (__ExternalLocationInfo__ objects) from +// the metastore. The caller must be a metastore admin, the owner of the +// external location, or a user that has some privilege on the external +// location. There is no guarantee of a specific ordering of the elements in the +// array. +func (a *externalLocationsImpl) List(ctx context.Context, request ListExternalLocationsRequest) listing.Iterator[ExternalLocationInfo] { + + getNextPage := func(ctx context.Context, req ListExternalLocationsRequest) (*ListExternalLocationsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListExternalLocationsResponse) []ExternalLocationInfo { + return resp.ExternalLocations + } + getNextReq := func(resp *ListExternalLocationsResponse) *ListExternalLocationsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List external locations. +// +// Gets an array of external locations (__ExternalLocationInfo__ objects) from +// the metastore. The caller must be a metastore admin, the owner of the +// external location, or a user that has some privilege on the external +// location. There is no guarantee of a specific ordering of the elements in the +// array. +func (a *externalLocationsImpl) ListAll(ctx context.Context, request ListExternalLocationsRequest) ([]ExternalLocationInfo, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[ExternalLocationInfo](ctx, iterator) +} +func (a *externalLocationsImpl) internalList(ctx context.Context, request ListExternalLocationsRequest) (*ListExternalLocationsResponse, error) { var listExternalLocationsResponse ListExternalLocationsResponse path := "/api/2.1/unity-catalog/external-locations" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listExternalLocationsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listExternalLocationsResponse) return &listExternalLocationsResponse, err } func (a *externalLocationsImpl) Update(ctx context.Context, request UpdateExternalLocation) (*ExternalLocationInfo, error) { var externalLocationInfo ExternalLocationInfo path := fmt.Sprintf("/api/2.1/unity-catalog/external-locations/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &externalLocationInfo) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &externalLocationInfo) return &externalLocationInfo, err } @@ -426,47 +718,98 @@ type functionsImpl struct { func (a *functionsImpl) Create(ctx context.Context, request CreateFunctionRequest) (*FunctionInfo, error) { var functionInfo FunctionInfo path := "/api/2.1/unity-catalog/functions" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &functionInfo) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &functionInfo) return &functionInfo, err } func (a *functionsImpl) Delete(ctx context.Context, request DeleteFunctionRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.1/unity-catalog/functions/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *functionsImpl) Get(ctx context.Context, request GetFunctionRequest) (*FunctionInfo, error) { var functionInfo FunctionInfo path := fmt.Sprintf("/api/2.1/unity-catalog/functions/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &functionInfo) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &functionInfo) return &functionInfo, err } -func (a *functionsImpl) List(ctx context.Context, request ListFunctionsRequest) (*ListFunctionsResponse, error) { +// List functions. +// +// List functions within the specified parent catalog and schema. If the user is +// a metastore admin, all functions are returned in the output list. Otherwise, +// the user must have the **USE_CATALOG** privilege on the catalog and the +// **USE_SCHEMA** privilege on the schema, and the output list contains only +// functions for which either the user has the **EXECUTE** privilege or the user +// is the owner. There is no guarantee of a specific ordering of the elements in +// the array. +func (a *functionsImpl) List(ctx context.Context, request ListFunctionsRequest) listing.Iterator[FunctionInfo] { + + getNextPage := func(ctx context.Context, req ListFunctionsRequest) (*ListFunctionsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListFunctionsResponse) []FunctionInfo { + return resp.Functions + } + getNextReq := func(resp *ListFunctionsResponse) *ListFunctionsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List functions. +// +// List functions within the specified parent catalog and schema. If the user is +// a metastore admin, all functions are returned in the output list. Otherwise, +// the user must have the **USE_CATALOG** privilege on the catalog and the +// **USE_SCHEMA** privilege on the schema, and the output list contains only +// functions for which either the user has the **EXECUTE** privilege or the user +// is the owner. There is no guarantee of a specific ordering of the elements in +// the array. +func (a *functionsImpl) ListAll(ctx context.Context, request ListFunctionsRequest) ([]FunctionInfo, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[FunctionInfo](ctx, iterator) +} +func (a *functionsImpl) internalList(ctx context.Context, request ListFunctionsRequest) (*ListFunctionsResponse, error) { var listFunctionsResponse ListFunctionsResponse path := "/api/2.1/unity-catalog/functions" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listFunctionsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listFunctionsResponse) return &listFunctionsResponse, err } func (a *functionsImpl) Update(ctx context.Context, request UpdateFunction) (*FunctionInfo, error) { var functionInfo FunctionInfo path := fmt.Sprintf("/api/2.1/unity-catalog/functions/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &functionInfo) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &functionInfo) return &functionInfo, err } @@ -478,28 +821,31 @@ type grantsImpl struct { func (a *grantsImpl) Get(ctx context.Context, request GetGrantRequest) (*PermissionsList, error) { var permissionsList PermissionsList path := fmt.Sprintf("/api/2.1/unity-catalog/permissions/%v/%v", request.SecurableType, request.FullName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &permissionsList) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &permissionsList) return &permissionsList, err } func (a *grantsImpl) GetEffective(ctx context.Context, request GetEffectiveRequest) (*EffectivePermissionsList, error) { var effectivePermissionsList EffectivePermissionsList path := fmt.Sprintf("/api/2.1/unity-catalog/effective-permissions/%v/%v", request.SecurableType, request.FullName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &effectivePermissionsList) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &effectivePermissionsList) return &effectivePermissionsList, err } func (a *grantsImpl) Update(ctx context.Context, request UpdatePermissions) (*PermissionsList, error) { var permissionsList PermissionsList path := fmt.Sprintf("/api/2.1/unity-catalog/permissions/%v/%v", request.SecurableType, request.FullName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &permissionsList) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &permissionsList) return &permissionsList, err } @@ -511,94 +857,137 @@ type metastoresImpl struct { func (a *metastoresImpl) Assign(ctx context.Context, request CreateMetastoreAssignment) error { var assignResponse AssignResponse path := fmt.Sprintf("/api/2.1/unity-catalog/workspaces/%v/metastore", request.WorkspaceId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &assignResponse) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &assignResponse) return err } func (a *metastoresImpl) Create(ctx context.Context, request CreateMetastore) (*MetastoreInfo, error) { var metastoreInfo MetastoreInfo path := "/api/2.1/unity-catalog/metastores" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &metastoreInfo) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &metastoreInfo) return &metastoreInfo, err } func (a *metastoresImpl) Current(ctx context.Context) (*MetastoreAssignment, error) { var metastoreAssignment MetastoreAssignment path := "/api/2.1/unity-catalog/current-metastore-assignment" + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &metastoreAssignment) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &metastoreAssignment) return &metastoreAssignment, err } func (a *metastoresImpl) Delete(ctx context.Context, request DeleteMetastoreRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.1/unity-catalog/metastores/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *metastoresImpl) Get(ctx context.Context, request GetMetastoreRequest) (*MetastoreInfo, error) { var metastoreInfo MetastoreInfo path := fmt.Sprintf("/api/2.1/unity-catalog/metastores/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &metastoreInfo) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &metastoreInfo) return &metastoreInfo, err } -func (a *metastoresImpl) List(ctx context.Context) (*ListMetastoresResponse, error) { +// List metastores. +// +// Gets an array of the available metastores (as __MetastoreInfo__ objects). The +// caller must be an admin to retrieve this info. There is no guarantee of a +// specific ordering of the elements in the array. +func (a *metastoresImpl) List(ctx context.Context) listing.Iterator[MetastoreInfo] { + request := struct{}{} + + getNextPage := func(ctx context.Context, req struct{}) (*ListMetastoresResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx) + } + getItems := func(resp *ListMetastoresResponse) []MetastoreInfo { + return resp.Metastores + } + + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + nil) + return iterator +} + +// List metastores. +// +// Gets an array of the available metastores (as __MetastoreInfo__ objects). The +// caller must be an admin to retrieve this info. There is no guarantee of a +// specific ordering of the elements in the array. +func (a *metastoresImpl) ListAll(ctx context.Context) ([]MetastoreInfo, error) { + iterator := a.List(ctx) + return listing.ToSlice[MetastoreInfo](ctx, iterator) +} +func (a *metastoresImpl) internalList(ctx context.Context) (*ListMetastoresResponse, error) { var listMetastoresResponse ListMetastoresResponse path := "/api/2.1/unity-catalog/metastores" + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &listMetastoresResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &listMetastoresResponse) return &listMetastoresResponse, err } func (a *metastoresImpl) Summary(ctx context.Context) (*GetMetastoreSummaryResponse, error) { var getMetastoreSummaryResponse GetMetastoreSummaryResponse path := "/api/2.1/unity-catalog/metastore_summary" + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &getMetastoreSummaryResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &getMetastoreSummaryResponse) return &getMetastoreSummaryResponse, err } func (a *metastoresImpl) Unassign(ctx context.Context, request UnassignRequest) error { var unassignResponse UnassignResponse path := fmt.Sprintf("/api/2.1/unity-catalog/workspaces/%v/metastore", request.WorkspaceId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &unassignResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &unassignResponse) return err } func (a *metastoresImpl) Update(ctx context.Context, request UpdateMetastore) (*MetastoreInfo, error) { var metastoreInfo MetastoreInfo path := fmt.Sprintf("/api/2.1/unity-catalog/metastores/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &metastoreInfo) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &metastoreInfo) return &metastoreInfo, err } func (a *metastoresImpl) UpdateAssignment(ctx context.Context, request UpdateMetastoreAssignment) error { var updateAssignmentResponse UpdateAssignmentResponse path := fmt.Sprintf("/api/2.1/unity-catalog/workspaces/%v/metastore", request.WorkspaceId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &updateAssignmentResponse) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &updateAssignmentResponse) return err } @@ -610,45 +999,108 @@ type modelVersionsImpl struct { func (a *modelVersionsImpl) Delete(ctx context.Context, request DeleteModelVersionRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.1/unity-catalog/models/%v/versions/%v", request.FullName, request.Version) + queryParams := make(map[string]any) headers := make(map[string]string) - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *modelVersionsImpl) Get(ctx context.Context, request GetModelVersionRequest) (*ModelVersionInfo, error) { var modelVersionInfo ModelVersionInfo path := fmt.Sprintf("/api/2.1/unity-catalog/models/%v/versions/%v", request.FullName, request.Version) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &modelVersionInfo) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &modelVersionInfo) return &modelVersionInfo, err } func (a *modelVersionsImpl) GetByAlias(ctx context.Context, request GetByAliasRequest) (*ModelVersionInfo, error) { var modelVersionInfo ModelVersionInfo path := fmt.Sprintf("/api/2.1/unity-catalog/models/%v/aliases/%v", request.FullName, request.Alias) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &modelVersionInfo) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &modelVersionInfo) return &modelVersionInfo, err } -func (a *modelVersionsImpl) List(ctx context.Context, request ListModelVersionsRequest) (*ListModelVersionsResponse, error) { +// List Model Versions. +// +// List model versions. You can list model versions under a particular schema, +// or list all model versions in the current metastore. +// +// The returned models are filtered based on the privileges of the calling user. +// For example, the metastore admin is able to list all the model versions. A +// regular user needs to be the owner or have the **EXECUTE** privilege on the +// parent registered model to recieve the model versions in the response. For +// the latter case, the caller must also be the owner or have the +// **USE_CATALOG** privilege on the parent catalog and the **USE_SCHEMA** +// privilege on the parent schema. +// +// There is no guarantee of a specific ordering of the elements in the response. +// The elements in the response will not contain any aliases or tags. +func (a *modelVersionsImpl) List(ctx context.Context, request ListModelVersionsRequest) listing.Iterator[ModelVersionInfo] { + + getNextPage := func(ctx context.Context, req ListModelVersionsRequest) (*ListModelVersionsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListModelVersionsResponse) []ModelVersionInfo { + return resp.ModelVersions + } + getNextReq := func(resp *ListModelVersionsResponse) *ListModelVersionsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List Model Versions. +// +// List model versions. You can list model versions under a particular schema, +// or list all model versions in the current metastore. +// +// The returned models are filtered based on the privileges of the calling user. +// For example, the metastore admin is able to list all the model versions. A +// regular user needs to be the owner or have the **EXECUTE** privilege on the +// parent registered model to recieve the model versions in the response. For +// the latter case, the caller must also be the owner or have the +// **USE_CATALOG** privilege on the parent catalog and the **USE_SCHEMA** +// privilege on the parent schema. +// +// There is no guarantee of a specific ordering of the elements in the response. +// The elements in the response will not contain any aliases or tags. +func (a *modelVersionsImpl) ListAll(ctx context.Context, request ListModelVersionsRequest) ([]ModelVersionInfo, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[ModelVersionInfo](ctx, iterator) +} +func (a *modelVersionsImpl) internalList(ctx context.Context, request ListModelVersionsRequest) (*ListModelVersionsResponse, error) { var listModelVersionsResponse ListModelVersionsResponse path := fmt.Sprintf("/api/2.1/unity-catalog/models/%v/versions", request.FullName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listModelVersionsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listModelVersionsResponse) return &listModelVersionsResponse, err } func (a *modelVersionsImpl) Update(ctx context.Context, request UpdateModelVersionRequest) (*ModelVersionInfo, error) { var modelVersionInfo ModelVersionInfo path := fmt.Sprintf("/api/2.1/unity-catalog/models/%v/versions/%v", request.FullName, request.Version) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &modelVersionInfo) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &modelVersionInfo) return &modelVersionInfo, err } @@ -660,28 +1112,31 @@ type onlineTablesImpl struct { func (a *onlineTablesImpl) Create(ctx context.Context, request CreateOnlineTableRequest) (*OnlineTable, error) { var onlineTable OnlineTable path := "/api/2.0/online-tables" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request.Table, &onlineTable) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request.Table, &onlineTable) return &onlineTable, err } func (a *onlineTablesImpl) Delete(ctx context.Context, request DeleteOnlineTableRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.0/online-tables/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *onlineTablesImpl) Get(ctx context.Context, request GetOnlineTableRequest) (*OnlineTable, error) { var onlineTable OnlineTable path := fmt.Sprintf("/api/2.0/online-tables/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &onlineTable) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &onlineTable) return &onlineTable, err } @@ -693,82 +1148,91 @@ type qualityMonitorsImpl struct { func (a *qualityMonitorsImpl) CancelRefresh(ctx context.Context, request CancelRefreshRequest) error { var cancelRefreshResponse CancelRefreshResponse path := fmt.Sprintf("/api/2.1/unity-catalog/tables/%v/monitor/refreshes/%v/cancel", request.TableName, request.RefreshId) + queryParams := make(map[string]any) headers := make(map[string]string) - err := a.client.Do(ctx, http.MethodPost, path, headers, nil, &cancelRefreshResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, nil, &cancelRefreshResponse) return err } func (a *qualityMonitorsImpl) Create(ctx context.Context, request CreateMonitor) (*MonitorInfo, error) { var monitorInfo MonitorInfo path := fmt.Sprintf("/api/2.1/unity-catalog/tables/%v/monitor", request.TableName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &monitorInfo) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &monitorInfo) return &monitorInfo, err } func (a *qualityMonitorsImpl) Delete(ctx context.Context, request DeleteQualityMonitorRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.1/unity-catalog/tables/%v/monitor", request.TableName) + queryParams := make(map[string]any) headers := make(map[string]string) - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *qualityMonitorsImpl) Get(ctx context.Context, request GetQualityMonitorRequest) (*MonitorInfo, error) { var monitorInfo MonitorInfo path := fmt.Sprintf("/api/2.1/unity-catalog/tables/%v/monitor", request.TableName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &monitorInfo) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &monitorInfo) return &monitorInfo, err } func (a *qualityMonitorsImpl) GetRefresh(ctx context.Context, request GetRefreshRequest) (*MonitorRefreshInfo, error) { var monitorRefreshInfo MonitorRefreshInfo path := fmt.Sprintf("/api/2.1/unity-catalog/tables/%v/monitor/refreshes/%v", request.TableName, request.RefreshId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &monitorRefreshInfo) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &monitorRefreshInfo) return &monitorRefreshInfo, err } func (a *qualityMonitorsImpl) ListRefreshes(ctx context.Context, request ListRefreshesRequest) (*MonitorRefreshListResponse, error) { var monitorRefreshListResponse MonitorRefreshListResponse path := fmt.Sprintf("/api/2.1/unity-catalog/tables/%v/monitor/refreshes", request.TableName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &monitorRefreshListResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &monitorRefreshListResponse) return &monitorRefreshListResponse, err } func (a *qualityMonitorsImpl) RegenerateDashboard(ctx context.Context, request RegenerateDashboardRequest) (*RegenerateDashboardResponse, error) { var regenerateDashboardResponse RegenerateDashboardResponse path := fmt.Sprintf("/api/2.1/quality-monitoring/tables/%v/monitor/dashboard", request.TableName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, ®enerateDashboardResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, ®enerateDashboardResponse) return ®enerateDashboardResponse, err } func (a *qualityMonitorsImpl) RunRefresh(ctx context.Context, request RunRefreshRequest) (*MonitorRefreshInfo, error) { var monitorRefreshInfo MonitorRefreshInfo path := fmt.Sprintf("/api/2.1/unity-catalog/tables/%v/monitor/refreshes", request.TableName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, nil, &monitorRefreshInfo) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, nil, &monitorRefreshInfo) return &monitorRefreshInfo, err } func (a *qualityMonitorsImpl) Update(ctx context.Context, request UpdateMonitor) (*MonitorInfo, error) { var monitorInfo MonitorInfo path := fmt.Sprintf("/api/2.1/unity-catalog/tables/%v/monitor", request.TableName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &monitorInfo) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &monitorInfo) return &monitorInfo, err } @@ -780,64 +1244,127 @@ type registeredModelsImpl struct { func (a *registeredModelsImpl) Create(ctx context.Context, request CreateRegisteredModelRequest) (*RegisteredModelInfo, error) { var registeredModelInfo RegisteredModelInfo path := "/api/2.1/unity-catalog/models" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, ®isteredModelInfo) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, ®isteredModelInfo) return ®isteredModelInfo, err } func (a *registeredModelsImpl) Delete(ctx context.Context, request DeleteRegisteredModelRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.1/unity-catalog/models/%v", request.FullName) + queryParams := make(map[string]any) headers := make(map[string]string) - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *registeredModelsImpl) DeleteAlias(ctx context.Context, request DeleteAliasRequest) error { var deleteAliasResponse DeleteAliasResponse path := fmt.Sprintf("/api/2.1/unity-catalog/models/%v/aliases/%v", request.FullName, request.Alias) + queryParams := make(map[string]any) headers := make(map[string]string) - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteAliasResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteAliasResponse) return err } func (a *registeredModelsImpl) Get(ctx context.Context, request GetRegisteredModelRequest) (*RegisteredModelInfo, error) { var registeredModelInfo RegisteredModelInfo path := fmt.Sprintf("/api/2.1/unity-catalog/models/%v", request.FullName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, ®isteredModelInfo) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, ®isteredModelInfo) return ®isteredModelInfo, err } -func (a *registeredModelsImpl) List(ctx context.Context, request ListRegisteredModelsRequest) (*ListRegisteredModelsResponse, error) { +// List Registered Models. +// +// List registered models. You can list registered models under a particular +// schema, or list all registered models in the current metastore. +// +// The returned models are filtered based on the privileges of the calling user. +// For example, the metastore admin is able to list all the registered models. A +// regular user needs to be the owner or have the **EXECUTE** privilege on the +// registered model to recieve the registered models in the response. For the +// latter case, the caller must also be the owner or have the **USE_CATALOG** +// privilege on the parent catalog and the **USE_SCHEMA** privilege on the +// parent schema. +// +// There is no guarantee of a specific ordering of the elements in the response. +func (a *registeredModelsImpl) List(ctx context.Context, request ListRegisteredModelsRequest) listing.Iterator[RegisteredModelInfo] { + + getNextPage := func(ctx context.Context, req ListRegisteredModelsRequest) (*ListRegisteredModelsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListRegisteredModelsResponse) []RegisteredModelInfo { + return resp.RegisteredModels + } + getNextReq := func(resp *ListRegisteredModelsResponse) *ListRegisteredModelsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List Registered Models. +// +// List registered models. You can list registered models under a particular +// schema, or list all registered models in the current metastore. +// +// The returned models are filtered based on the privileges of the calling user. +// For example, the metastore admin is able to list all the registered models. A +// regular user needs to be the owner or have the **EXECUTE** privilege on the +// registered model to recieve the registered models in the response. For the +// latter case, the caller must also be the owner or have the **USE_CATALOG** +// privilege on the parent catalog and the **USE_SCHEMA** privilege on the +// parent schema. +// +// There is no guarantee of a specific ordering of the elements in the response. +func (a *registeredModelsImpl) ListAll(ctx context.Context, request ListRegisteredModelsRequest) ([]RegisteredModelInfo, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[RegisteredModelInfo](ctx, iterator) +} +func (a *registeredModelsImpl) internalList(ctx context.Context, request ListRegisteredModelsRequest) (*ListRegisteredModelsResponse, error) { var listRegisteredModelsResponse ListRegisteredModelsResponse path := "/api/2.1/unity-catalog/models" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listRegisteredModelsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listRegisteredModelsResponse) return &listRegisteredModelsResponse, err } func (a *registeredModelsImpl) SetAlias(ctx context.Context, request SetRegisteredModelAliasRequest) (*RegisteredModelAlias, error) { var registeredModelAlias RegisteredModelAlias path := fmt.Sprintf("/api/2.1/unity-catalog/models/%v/aliases/%v", request.FullName, request.Alias) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, ®isteredModelAlias) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, ®isteredModelAlias) return ®isteredModelAlias, err } func (a *registeredModelsImpl) Update(ctx context.Context, request UpdateRegisteredModelRequest) (*RegisteredModelInfo, error) { var registeredModelInfo RegisteredModelInfo path := fmt.Sprintf("/api/2.1/unity-catalog/models/%v", request.FullName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, ®isteredModelInfo) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, ®isteredModelInfo) return ®isteredModelInfo, err } @@ -849,18 +1376,58 @@ type resourceQuotasImpl struct { func (a *resourceQuotasImpl) GetQuota(ctx context.Context, request GetQuotaRequest) (*GetQuotaResponse, error) { var getQuotaResponse GetQuotaResponse path := fmt.Sprintf("/api/2.1/unity-catalog/resource-quotas/%v/%v/%v", request.ParentSecurableType, request.ParentFullName, request.QuotaName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getQuotaResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getQuotaResponse) return &getQuotaResponse, err } -func (a *resourceQuotasImpl) ListQuotas(ctx context.Context, request ListQuotasRequest) (*ListQuotasResponse, error) { +// List all resource quotas under a metastore. +// +// ListQuotas returns all quota values under the metastore. There are no SLAs on +// the freshness of the counts returned. This API does not trigger a refresh of +// quota counts. +func (a *resourceQuotasImpl) ListQuotas(ctx context.Context, request ListQuotasRequest) listing.Iterator[QuotaInfo] { + + getNextPage := func(ctx context.Context, req ListQuotasRequest) (*ListQuotasResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalListQuotas(ctx, req) + } + getItems := func(resp *ListQuotasResponse) []QuotaInfo { + return resp.Quotas + } + getNextReq := func(resp *ListQuotasResponse) *ListQuotasRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List all resource quotas under a metastore. +// +// ListQuotas returns all quota values under the metastore. There are no SLAs on +// the freshness of the counts returned. This API does not trigger a refresh of +// quota counts. +func (a *resourceQuotasImpl) ListQuotasAll(ctx context.Context, request ListQuotasRequest) ([]QuotaInfo, error) { + iterator := a.ListQuotas(ctx, request) + return listing.ToSlice[QuotaInfo](ctx, iterator) +} +func (a *resourceQuotasImpl) internalListQuotas(ctx context.Context, request ListQuotasRequest) (*ListQuotasResponse, error) { var listQuotasResponse ListQuotasResponse path := "/api/2.1/unity-catalog/resource-quotas/all-resource-quotas" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listQuotasResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listQuotasResponse) return &listQuotasResponse, err } @@ -872,47 +1439,94 @@ type schemasImpl struct { func (a *schemasImpl) Create(ctx context.Context, request CreateSchema) (*SchemaInfo, error) { var schemaInfo SchemaInfo path := "/api/2.1/unity-catalog/schemas" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &schemaInfo) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &schemaInfo) return &schemaInfo, err } func (a *schemasImpl) Delete(ctx context.Context, request DeleteSchemaRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.1/unity-catalog/schemas/%v", request.FullName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *schemasImpl) Get(ctx context.Context, request GetSchemaRequest) (*SchemaInfo, error) { var schemaInfo SchemaInfo path := fmt.Sprintf("/api/2.1/unity-catalog/schemas/%v", request.FullName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &schemaInfo) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &schemaInfo) return &schemaInfo, err } -func (a *schemasImpl) List(ctx context.Context, request ListSchemasRequest) (*ListSchemasResponse, error) { +// List schemas. +// +// Gets an array of schemas for a catalog in the metastore. If the caller is the +// metastore admin or the owner of the parent catalog, all schemas for the +// catalog will be retrieved. Otherwise, only schemas owned by the caller (or +// for which the caller has the **USE_SCHEMA** privilege) will be retrieved. +// There is no guarantee of a specific ordering of the elements in the array. +func (a *schemasImpl) List(ctx context.Context, request ListSchemasRequest) listing.Iterator[SchemaInfo] { + + getNextPage := func(ctx context.Context, req ListSchemasRequest) (*ListSchemasResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListSchemasResponse) []SchemaInfo { + return resp.Schemas + } + getNextReq := func(resp *ListSchemasResponse) *ListSchemasRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List schemas. +// +// Gets an array of schemas for a catalog in the metastore. If the caller is the +// metastore admin or the owner of the parent catalog, all schemas for the +// catalog will be retrieved. Otherwise, only schemas owned by the caller (or +// for which the caller has the **USE_SCHEMA** privilege) will be retrieved. +// There is no guarantee of a specific ordering of the elements in the array. +func (a *schemasImpl) ListAll(ctx context.Context, request ListSchemasRequest) ([]SchemaInfo, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[SchemaInfo](ctx, iterator) +} +func (a *schemasImpl) internalList(ctx context.Context, request ListSchemasRequest) (*ListSchemasResponse, error) { var listSchemasResponse ListSchemasResponse path := "/api/2.1/unity-catalog/schemas" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listSchemasResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listSchemasResponse) return &listSchemasResponse, err } func (a *schemasImpl) Update(ctx context.Context, request UpdateSchema) (*SchemaInfo, error) { var schemaInfo SchemaInfo path := fmt.Sprintf("/api/2.1/unity-catalog/schemas/%v", request.FullName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &schemaInfo) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &schemaInfo) return &schemaInfo, err } @@ -924,57 +1538,105 @@ type storageCredentialsImpl struct { func (a *storageCredentialsImpl) Create(ctx context.Context, request CreateStorageCredential) (*StorageCredentialInfo, error) { var storageCredentialInfo StorageCredentialInfo path := "/api/2.1/unity-catalog/storage-credentials" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &storageCredentialInfo) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &storageCredentialInfo) return &storageCredentialInfo, err } func (a *storageCredentialsImpl) Delete(ctx context.Context, request DeleteStorageCredentialRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.1/unity-catalog/storage-credentials/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *storageCredentialsImpl) Get(ctx context.Context, request GetStorageCredentialRequest) (*StorageCredentialInfo, error) { var storageCredentialInfo StorageCredentialInfo path := fmt.Sprintf("/api/2.1/unity-catalog/storage-credentials/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &storageCredentialInfo) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &storageCredentialInfo) return &storageCredentialInfo, err } -func (a *storageCredentialsImpl) List(ctx context.Context, request ListStorageCredentialsRequest) (*ListStorageCredentialsResponse, error) { +// List credentials. +// +// Gets an array of storage credentials (as __StorageCredentialInfo__ objects). +// The array is limited to only those storage credentials the caller has +// permission to access. If the caller is a metastore admin, retrieval of +// credentials is unrestricted. There is no guarantee of a specific ordering of +// the elements in the array. +func (a *storageCredentialsImpl) List(ctx context.Context, request ListStorageCredentialsRequest) listing.Iterator[StorageCredentialInfo] { + + getNextPage := func(ctx context.Context, req ListStorageCredentialsRequest) (*ListStorageCredentialsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListStorageCredentialsResponse) []StorageCredentialInfo { + return resp.StorageCredentials + } + getNextReq := func(resp *ListStorageCredentialsResponse) *ListStorageCredentialsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List credentials. +// +// Gets an array of storage credentials (as __StorageCredentialInfo__ objects). +// The array is limited to only those storage credentials the caller has +// permission to access. If the caller is a metastore admin, retrieval of +// credentials is unrestricted. There is no guarantee of a specific ordering of +// the elements in the array. +func (a *storageCredentialsImpl) ListAll(ctx context.Context, request ListStorageCredentialsRequest) ([]StorageCredentialInfo, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[StorageCredentialInfo](ctx, iterator) +} +func (a *storageCredentialsImpl) internalList(ctx context.Context, request ListStorageCredentialsRequest) (*ListStorageCredentialsResponse, error) { var listStorageCredentialsResponse ListStorageCredentialsResponse path := "/api/2.1/unity-catalog/storage-credentials" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listStorageCredentialsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listStorageCredentialsResponse) return &listStorageCredentialsResponse, err } func (a *storageCredentialsImpl) Update(ctx context.Context, request UpdateStorageCredential) (*StorageCredentialInfo, error) { var storageCredentialInfo StorageCredentialInfo path := fmt.Sprintf("/api/2.1/unity-catalog/storage-credentials/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &storageCredentialInfo) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &storageCredentialInfo) return &storageCredentialInfo, err } func (a *storageCredentialsImpl) Validate(ctx context.Context, request ValidateStorageCredential) (*ValidateStorageCredentialResponse, error) { var validateStorageCredentialResponse ValidateStorageCredentialResponse path := "/api/2.1/unity-catalog/validate-storage-credentials" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &validateStorageCredentialResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &validateStorageCredentialResponse) return &validateStorageCredentialResponse, err } @@ -986,27 +1648,66 @@ type systemSchemasImpl struct { func (a *systemSchemasImpl) Disable(ctx context.Context, request DisableRequest) error { var disableResponse DisableResponse path := fmt.Sprintf("/api/2.1/unity-catalog/metastores/%v/systemschemas/%v", request.MetastoreId, request.SchemaName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &disableResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &disableResponse) return err } func (a *systemSchemasImpl) Enable(ctx context.Context, request EnableRequest) error { var enableResponse EnableResponse path := fmt.Sprintf("/api/2.1/unity-catalog/metastores/%v/systemschemas/%v", request.MetastoreId, request.SchemaName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, nil, &enableResponse) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, nil, &enableResponse) return err } -func (a *systemSchemasImpl) List(ctx context.Context, request ListSystemSchemasRequest) (*ListSystemSchemasResponse, error) { +// List system schemas. +// +// Gets an array of system schemas for a metastore. The caller must be an +// account admin or a metastore admin. +func (a *systemSchemasImpl) List(ctx context.Context, request ListSystemSchemasRequest) listing.Iterator[SystemSchemaInfo] { + + getNextPage := func(ctx context.Context, req ListSystemSchemasRequest) (*ListSystemSchemasResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListSystemSchemasResponse) []SystemSchemaInfo { + return resp.Schemas + } + getNextReq := func(resp *ListSystemSchemasResponse) *ListSystemSchemasRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List system schemas. +// +// Gets an array of system schemas for a metastore. The caller must be an +// account admin or a metastore admin. +func (a *systemSchemasImpl) ListAll(ctx context.Context, request ListSystemSchemasRequest) ([]SystemSchemaInfo, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[SystemSchemaInfo](ctx, iterator) +} +func (a *systemSchemasImpl) internalList(ctx context.Context, request ListSystemSchemasRequest) (*ListSystemSchemasResponse, error) { var listSystemSchemasResponse ListSystemSchemasResponse path := fmt.Sprintf("/api/2.1/unity-catalog/metastores/%v/systemschemas", request.MetastoreId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listSystemSchemasResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listSystemSchemasResponse) return &listSystemSchemasResponse, err } @@ -1018,19 +1719,21 @@ type tableConstraintsImpl struct { func (a *tableConstraintsImpl) Create(ctx context.Context, request CreateTableConstraint) (*TableConstraint, error) { var tableConstraint TableConstraint path := "/api/2.1/unity-catalog/constraints" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &tableConstraint) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &tableConstraint) return &tableConstraint, err } func (a *tableConstraintsImpl) Delete(ctx context.Context, request DeleteTableConstraintRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.1/unity-catalog/constraints/%v", request.FullName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } @@ -1042,55 +1745,159 @@ type tablesImpl struct { func (a *tablesImpl) Delete(ctx context.Context, request DeleteTableRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.1/unity-catalog/tables/%v", request.FullName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *tablesImpl) Exists(ctx context.Context, request ExistsRequest) (*TableExistsResponse, error) { var tableExistsResponse TableExistsResponse path := fmt.Sprintf("/api/2.1/unity-catalog/tables/%v/exists", request.FullName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &tableExistsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &tableExistsResponse) return &tableExistsResponse, err } func (a *tablesImpl) Get(ctx context.Context, request GetTableRequest) (*TableInfo, error) { var tableInfo TableInfo path := fmt.Sprintf("/api/2.1/unity-catalog/tables/%v", request.FullName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &tableInfo) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &tableInfo) return &tableInfo, err } -func (a *tablesImpl) List(ctx context.Context, request ListTablesRequest) (*ListTablesResponse, error) { +// List tables. +// +// Gets an array of all tables for the current metastore under the parent +// catalog and schema. The caller must be a metastore admin or an owner of (or +// have the **SELECT** privilege on) the table. For the latter case, the caller +// must also be the owner or have the **USE_CATALOG** privilege on the parent +// catalog and the **USE_SCHEMA** privilege on the parent schema. There is no +// guarantee of a specific ordering of the elements in the array. +func (a *tablesImpl) List(ctx context.Context, request ListTablesRequest) listing.Iterator[TableInfo] { + + getNextPage := func(ctx context.Context, req ListTablesRequest) (*ListTablesResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListTablesResponse) []TableInfo { + return resp.Tables + } + getNextReq := func(resp *ListTablesResponse) *ListTablesRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List tables. +// +// Gets an array of all tables for the current metastore under the parent +// catalog and schema. The caller must be a metastore admin or an owner of (or +// have the **SELECT** privilege on) the table. For the latter case, the caller +// must also be the owner or have the **USE_CATALOG** privilege on the parent +// catalog and the **USE_SCHEMA** privilege on the parent schema. There is no +// guarantee of a specific ordering of the elements in the array. +func (a *tablesImpl) ListAll(ctx context.Context, request ListTablesRequest) ([]TableInfo, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[TableInfo](ctx, iterator) +} +func (a *tablesImpl) internalList(ctx context.Context, request ListTablesRequest) (*ListTablesResponse, error) { var listTablesResponse ListTablesResponse path := "/api/2.1/unity-catalog/tables" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listTablesResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listTablesResponse) return &listTablesResponse, err } -func (a *tablesImpl) ListSummaries(ctx context.Context, request ListSummariesRequest) (*ListTableSummariesResponse, error) { +// List table summaries. +// +// Gets an array of summaries for tables for a schema and catalog within the +// metastore. The table summaries returned are either: +// +// * summaries for tables (within the current metastore and parent catalog and +// schema), when the user is a metastore admin, or: * summaries for tables and +// schemas (within the current metastore and parent catalog) for which the user +// has ownership or the **SELECT** privilege on the table and ownership or +// **USE_SCHEMA** privilege on the schema, provided that the user also has +// ownership or the **USE_CATALOG** privilege on the parent catalog. +// +// There is no guarantee of a specific ordering of the elements in the array. +func (a *tablesImpl) ListSummaries(ctx context.Context, request ListSummariesRequest) listing.Iterator[TableSummary] { + + getNextPage := func(ctx context.Context, req ListSummariesRequest) (*ListTableSummariesResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalListSummaries(ctx, req) + } + getItems := func(resp *ListTableSummariesResponse) []TableSummary { + return resp.Tables + } + getNextReq := func(resp *ListTableSummariesResponse) *ListSummariesRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List table summaries. +// +// Gets an array of summaries for tables for a schema and catalog within the +// metastore. The table summaries returned are either: +// +// * summaries for tables (within the current metastore and parent catalog and +// schema), when the user is a metastore admin, or: * summaries for tables and +// schemas (within the current metastore and parent catalog) for which the user +// has ownership or the **SELECT** privilege on the table and ownership or +// **USE_SCHEMA** privilege on the schema, provided that the user also has +// ownership or the **USE_CATALOG** privilege on the parent catalog. +// +// There is no guarantee of a specific ordering of the elements in the array. +func (a *tablesImpl) ListSummariesAll(ctx context.Context, request ListSummariesRequest) ([]TableSummary, error) { + iterator := a.ListSummaries(ctx, request) + return listing.ToSlice[TableSummary](ctx, iterator) +} +func (a *tablesImpl) internalListSummaries(ctx context.Context, request ListSummariesRequest) (*ListTableSummariesResponse, error) { var listTableSummariesResponse ListTableSummariesResponse path := "/api/2.1/unity-catalog/table-summaries" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listTableSummariesResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listTableSummariesResponse) return &listTableSummariesResponse, err } func (a *tablesImpl) Update(ctx context.Context, request UpdateTableRequest) error { var updateResponse UpdateResponse path := fmt.Sprintf("/api/2.1/unity-catalog/tables/%v", request.FullName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &updateResponse) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &updateResponse) return err } @@ -1102,10 +1909,11 @@ type temporaryTableCredentialsImpl struct { func (a *temporaryTableCredentialsImpl) GenerateTemporaryTableCredentials(ctx context.Context, request GenerateTemporaryTableCredentialRequest) (*GenerateTemporaryTableCredentialResponse, error) { var generateTemporaryTableCredentialResponse GenerateTemporaryTableCredentialResponse path := "/api/2.0/unity-catalog/temporary-table-credentials" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &generateTemporaryTableCredentialResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &generateTemporaryTableCredentialResponse) return &generateTemporaryTableCredentialResponse, err } @@ -1117,46 +1925,105 @@ type volumesImpl struct { func (a *volumesImpl) Create(ctx context.Context, request CreateVolumeRequestContent) (*VolumeInfo, error) { var volumeInfo VolumeInfo path := "/api/2.1/unity-catalog/volumes" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &volumeInfo) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &volumeInfo) return &volumeInfo, err } func (a *volumesImpl) Delete(ctx context.Context, request DeleteVolumeRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.1/unity-catalog/volumes/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } -func (a *volumesImpl) List(ctx context.Context, request ListVolumesRequest) (*ListVolumesResponseContent, error) { +// List Volumes. +// +// Gets an array of volumes for the current metastore under the parent catalog +// and schema. +// +// The returned volumes are filtered based on the privileges of the calling +// user. For example, the metastore admin is able to list all the volumes. A +// regular user needs to be the owner or have the **READ VOLUME** privilege on +// the volume to recieve the volumes in the response. For the latter case, the +// caller must also be the owner or have the **USE_CATALOG** privilege on the +// parent catalog and the **USE_SCHEMA** privilege on the parent schema. +// +// There is no guarantee of a specific ordering of the elements in the array. +func (a *volumesImpl) List(ctx context.Context, request ListVolumesRequest) listing.Iterator[VolumeInfo] { + + getNextPage := func(ctx context.Context, req ListVolumesRequest) (*ListVolumesResponseContent, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListVolumesResponseContent) []VolumeInfo { + return resp.Volumes + } + getNextReq := func(resp *ListVolumesResponseContent) *ListVolumesRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List Volumes. +// +// Gets an array of volumes for the current metastore under the parent catalog +// and schema. +// +// The returned volumes are filtered based on the privileges of the calling +// user. For example, the metastore admin is able to list all the volumes. A +// regular user needs to be the owner or have the **READ VOLUME** privilege on +// the volume to recieve the volumes in the response. For the latter case, the +// caller must also be the owner or have the **USE_CATALOG** privilege on the +// parent catalog and the **USE_SCHEMA** privilege on the parent schema. +// +// There is no guarantee of a specific ordering of the elements in the array. +func (a *volumesImpl) ListAll(ctx context.Context, request ListVolumesRequest) ([]VolumeInfo, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[VolumeInfo](ctx, iterator) +} +func (a *volumesImpl) internalList(ctx context.Context, request ListVolumesRequest) (*ListVolumesResponseContent, error) { var listVolumesResponseContent ListVolumesResponseContent path := "/api/2.1/unity-catalog/volumes" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listVolumesResponseContent) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listVolumesResponseContent) return &listVolumesResponseContent, err } func (a *volumesImpl) Read(ctx context.Context, request ReadVolumeRequest) (*VolumeInfo, error) { var volumeInfo VolumeInfo path := fmt.Sprintf("/api/2.1/unity-catalog/volumes/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &volumeInfo) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &volumeInfo) return &volumeInfo, err } func (a *volumesImpl) Update(ctx context.Context, request UpdateVolumeRequestContent) (*VolumeInfo, error) { var volumeInfo VolumeInfo path := fmt.Sprintf("/api/2.1/unity-catalog/volumes/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &volumeInfo) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &volumeInfo) return &volumeInfo, err } @@ -1168,37 +2035,77 @@ type workspaceBindingsImpl struct { func (a *workspaceBindingsImpl) Get(ctx context.Context, request GetWorkspaceBindingRequest) (*CurrentWorkspaceBindings, error) { var currentWorkspaceBindings CurrentWorkspaceBindings path := fmt.Sprintf("/api/2.1/unity-catalog/workspace-bindings/catalogs/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, ¤tWorkspaceBindings) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, ¤tWorkspaceBindings) return ¤tWorkspaceBindings, err } -func (a *workspaceBindingsImpl) GetBindings(ctx context.Context, request GetBindingsRequest) (*WorkspaceBindingsResponse, error) { +// Get securable workspace bindings. +// +// Gets workspace bindings of the securable. The caller must be a metastore +// admin or an owner of the securable. +func (a *workspaceBindingsImpl) GetBindings(ctx context.Context, request GetBindingsRequest) listing.Iterator[WorkspaceBinding] { + + getNextPage := func(ctx context.Context, req GetBindingsRequest) (*WorkspaceBindingsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalGetBindings(ctx, req) + } + getItems := func(resp *WorkspaceBindingsResponse) []WorkspaceBinding { + return resp.Bindings + } + getNextReq := func(resp *WorkspaceBindingsResponse) *GetBindingsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// Get securable workspace bindings. +// +// Gets workspace bindings of the securable. The caller must be a metastore +// admin or an owner of the securable. +func (a *workspaceBindingsImpl) GetBindingsAll(ctx context.Context, request GetBindingsRequest) ([]WorkspaceBinding, error) { + iterator := a.GetBindings(ctx, request) + return listing.ToSlice[WorkspaceBinding](ctx, iterator) +} +func (a *workspaceBindingsImpl) internalGetBindings(ctx context.Context, request GetBindingsRequest) (*WorkspaceBindingsResponse, error) { var workspaceBindingsResponse WorkspaceBindingsResponse path := fmt.Sprintf("/api/2.1/unity-catalog/bindings/%v/%v", request.SecurableType, request.SecurableName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &workspaceBindingsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &workspaceBindingsResponse) return &workspaceBindingsResponse, err } func (a *workspaceBindingsImpl) Update(ctx context.Context, request UpdateWorkspaceBindings) (*CurrentWorkspaceBindings, error) { var currentWorkspaceBindings CurrentWorkspaceBindings path := fmt.Sprintf("/api/2.1/unity-catalog/workspace-bindings/catalogs/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, ¤tWorkspaceBindings) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, ¤tWorkspaceBindings) return ¤tWorkspaceBindings, err } func (a *workspaceBindingsImpl) UpdateBindings(ctx context.Context, request UpdateWorkspaceBindingsParameters) (*WorkspaceBindingsResponse, error) { var workspaceBindingsResponse WorkspaceBindingsResponse path := fmt.Sprintf("/api/2.1/unity-catalog/bindings/%v/%v", request.SecurableType, request.SecurableName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &workspaceBindingsResponse) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &workspaceBindingsResponse) return &workspaceBindingsResponse, err } diff --git a/catalog/v2/model.go b/catalog/v2/model.go index ec45173fc..942162c2d 100755 --- a/catalog/v2/model.go +++ b/catalog/v2/model.go @@ -5267,6 +5267,9 @@ type TemporaryCredentials struct { // Server time when the credential will expire, in epoch milliseconds. The // API client is advised to cache the credential given this expiration time. ExpirationTime int64 `json:"expiration_time,omitempty"` + // GCP temporary credentials for API authentication. Read more at + // https://developers.google.com/identity/protocols/oauth2/service-account + GcpOauthToken *GcpOauthToken `json:"gcp_oauth_token,omitempty"` ForceSendFields []string `json:"-"` } diff --git a/cleanrooms/go.mod b/cleanrooms/go.mod index 559315519..995393b3c 100644 --- a/cleanrooms/go.mod +++ b/cleanrooms/go.mod @@ -6,6 +6,7 @@ replace github.com/databricks/databricks-sdk-go/databricks => ../databricks require ( github.com/databricks/databricks-sdk-go/databricks v0.0.0-00010101000000-000000000000 + golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 golang.org/x/oauth2 v0.25.0 ) @@ -27,7 +28,6 @@ require ( go.opentelemetry.io/otel/metric v1.24.0 // indirect go.opentelemetry.io/otel/trace v1.24.0 // indirect golang.org/x/crypto v0.31.0 // indirect - golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.33.0 // indirect golang.org/x/sys v0.28.0 // indirect diff --git a/cleanrooms/v2/api.go b/cleanrooms/v2/api.go index 7aab23202..27c2c9a83 100755 --- a/cleanrooms/v2/api.go +++ b/cleanrooms/v2/api.go @@ -8,7 +8,6 @@ import ( "github.com/databricks/databricks-sdk-go/databricks/client" "github.com/databricks/databricks-sdk-go/databricks/listing" - "github.com/databricks/databricks-sdk-go/databricks/useragent" ) type CleanRoomAssetsInterface interface { @@ -98,44 +97,9 @@ func (a *CleanRoomAssetsAPI) GetByCleanRoomNameAndAssetTypeAndAssetFullName(ctx }) } -// List assets. -// -// This method is generated by Databricks SDK Code Generator. -func (a *CleanRoomAssetsAPI) List(ctx context.Context, request ListCleanRoomAssetsRequest) listing.Iterator[CleanRoomAsset] { - - getNextPage := func(ctx context.Context, req ListCleanRoomAssetsRequest) (*ListCleanRoomAssetsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.cleanRoomAssetsImpl.List(ctx, req) - } - getItems := func(resp *ListCleanRoomAssetsResponse) []CleanRoomAsset { - return resp.Assets - } - getNextReq := func(resp *ListCleanRoomAssetsResponse) *ListCleanRoomAssetsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List assets. -// -// This method is generated by Databricks SDK Code Generator. -func (a *CleanRoomAssetsAPI) ListAll(ctx context.Context, request ListCleanRoomAssetsRequest) ([]CleanRoomAsset, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[CleanRoomAsset](ctx, iterator) -} - // List assets. func (a *CleanRoomAssetsAPI) ListByCleanRoomName(ctx context.Context, cleanRoomName string) (*ListCleanRoomAssetsResponse, error) { - return a.cleanRoomAssetsImpl.List(ctx, ListCleanRoomAssetsRequest{ + return a.cleanRoomAssetsImpl.internalList(ctx, ListCleanRoomAssetsRequest{ CleanRoomName: cleanRoomName, }) } @@ -175,50 +139,11 @@ type CleanRoomTaskRunsAPI struct { cleanRoomTaskRunsImpl } -// List notebook task runs. -// -// List all the historical notebook task runs in a clean room. -// -// This method is generated by Databricks SDK Code Generator. -func (a *CleanRoomTaskRunsAPI) List(ctx context.Context, request ListCleanRoomNotebookTaskRunsRequest) listing.Iterator[CleanRoomNotebookTaskRun] { - - getNextPage := func(ctx context.Context, req ListCleanRoomNotebookTaskRunsRequest) (*ListCleanRoomNotebookTaskRunsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.cleanRoomTaskRunsImpl.List(ctx, req) - } - getItems := func(resp *ListCleanRoomNotebookTaskRunsResponse) []CleanRoomNotebookTaskRun { - return resp.Runs - } - getNextReq := func(resp *ListCleanRoomNotebookTaskRunsResponse) *ListCleanRoomNotebookTaskRunsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List notebook task runs. -// -// List all the historical notebook task runs in a clean room. -// -// This method is generated by Databricks SDK Code Generator. -func (a *CleanRoomTaskRunsAPI) ListAll(ctx context.Context, request ListCleanRoomNotebookTaskRunsRequest) ([]CleanRoomNotebookTaskRun, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[CleanRoomNotebookTaskRun](ctx, iterator) -} - // List notebook task runs. // // List all the historical notebook task runs in a clean room. func (a *CleanRoomTaskRunsAPI) ListByCleanRoomName(ctx context.Context, cleanRoomName string) (*ListCleanRoomNotebookTaskRunsResponse, error) { - return a.cleanRoomTaskRunsImpl.List(ctx, ListCleanRoomNotebookTaskRunsRequest{ + return a.cleanRoomTaskRunsImpl.internalList(ctx, ListCleanRoomNotebookTaskRunsRequest{ CleanRoomName: cleanRoomName, }) } @@ -230,7 +155,8 @@ type CleanRoomsInterface interface { // Create a new clean room with the specified collaborators. This method is // asynchronous; the returned name field inside the clean_room field can be used // to poll the clean room status, using the :method:cleanrooms/get method. When - // this method returns, the cluster will be in a PROVISIONING state. The cluster + // this method returns, the clean room will be in a PROVISIONING state, with + // only name, owner, comment, created_at and status populated. The clean room // will be usable once it enters an ACTIVE state. // // The caller must be a metastore admin or have the **CREATE_CLEAN_ROOM** @@ -329,44 +255,3 @@ func (a *CleanRoomsAPI) GetByName(ctx context.Context, name string) (*CleanRoom, Name: name, }) } - -// List clean rooms. -// -// Get a list of all clean rooms of the metastore. Only clean rooms the caller -// has access to are returned. -// -// This method is generated by Databricks SDK Code Generator. -func (a *CleanRoomsAPI) List(ctx context.Context, request ListCleanRoomsRequest) listing.Iterator[CleanRoom] { - - getNextPage := func(ctx context.Context, req ListCleanRoomsRequest) (*ListCleanRoomsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.cleanRoomsImpl.List(ctx, req) - } - getItems := func(resp *ListCleanRoomsResponse) []CleanRoom { - return resp.CleanRooms - } - getNextReq := func(resp *ListCleanRoomsResponse) *ListCleanRoomsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List clean rooms. -// -// Get a list of all clean rooms of the metastore. Only clean rooms the caller -// has access to are returned. -// -// This method is generated by Databricks SDK Code Generator. -func (a *CleanRoomsAPI) ListAll(ctx context.Context, request ListCleanRoomsRequest) ([]CleanRoom, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[CleanRoom](ctx, iterator) -} diff --git a/cleanrooms/v2/impl.go b/cleanrooms/v2/impl.go index 6ebc5600e..b6cea4ccf 100755 --- a/cleanrooms/v2/impl.go +++ b/cleanrooms/v2/impl.go @@ -8,6 +8,8 @@ import ( "net/http" "github.com/databricks/databricks-sdk-go/databricks/client" + "github.com/databricks/databricks-sdk-go/databricks/listing" + "github.com/databricks/databricks-sdk-go/databricks/useragent" ) // unexported type that holds implementations of just CleanRoomAssets API methods @@ -18,47 +20,82 @@ type cleanRoomAssetsImpl struct { func (a *cleanRoomAssetsImpl) Create(ctx context.Context, request CreateCleanRoomAssetRequest) (*CleanRoomAsset, error) { var cleanRoomAsset CleanRoomAsset path := fmt.Sprintf("/api/2.0/clean-rooms/%v/assets", request.CleanRoomName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request.Asset, &cleanRoomAsset) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request.Asset, &cleanRoomAsset) return &cleanRoomAsset, err } func (a *cleanRoomAssetsImpl) Delete(ctx context.Context, request DeleteCleanRoomAssetRequest) error { var deleteCleanRoomAssetResponse DeleteCleanRoomAssetResponse path := fmt.Sprintf("/api/2.0/clean-rooms/%v/assets/%v/%v", request.CleanRoomName, request.AssetType, request.AssetFullName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteCleanRoomAssetResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteCleanRoomAssetResponse) return err } func (a *cleanRoomAssetsImpl) Get(ctx context.Context, request GetCleanRoomAssetRequest) (*CleanRoomAsset, error) { var cleanRoomAsset CleanRoomAsset path := fmt.Sprintf("/api/2.0/clean-rooms/%v/assets/%v/%v", request.CleanRoomName, request.AssetType, request.AssetFullName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &cleanRoomAsset) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &cleanRoomAsset) return &cleanRoomAsset, err } -func (a *cleanRoomAssetsImpl) List(ctx context.Context, request ListCleanRoomAssetsRequest) (*ListCleanRoomAssetsResponse, error) { +// List assets. +func (a *cleanRoomAssetsImpl) List(ctx context.Context, request ListCleanRoomAssetsRequest) listing.Iterator[CleanRoomAsset] { + + getNextPage := func(ctx context.Context, req ListCleanRoomAssetsRequest) (*ListCleanRoomAssetsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListCleanRoomAssetsResponse) []CleanRoomAsset { + return resp.Assets + } + getNextReq := func(resp *ListCleanRoomAssetsResponse) *ListCleanRoomAssetsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List assets. +func (a *cleanRoomAssetsImpl) ListAll(ctx context.Context, request ListCleanRoomAssetsRequest) ([]CleanRoomAsset, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[CleanRoomAsset](ctx, iterator) +} +func (a *cleanRoomAssetsImpl) internalList(ctx context.Context, request ListCleanRoomAssetsRequest) (*ListCleanRoomAssetsResponse, error) { var listCleanRoomAssetsResponse ListCleanRoomAssetsResponse path := fmt.Sprintf("/api/2.0/clean-rooms/%v/assets", request.CleanRoomName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listCleanRoomAssetsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listCleanRoomAssetsResponse) return &listCleanRoomAssetsResponse, err } func (a *cleanRoomAssetsImpl) Update(ctx context.Context, request UpdateCleanRoomAssetRequest) (*CleanRoomAsset, error) { var cleanRoomAsset CleanRoomAsset path := fmt.Sprintf("/api/2.0/clean-rooms/%v/assets/%v/%v", request.CleanRoomName, request.AssetType, request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request.Asset, &cleanRoomAsset) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request.Asset, &cleanRoomAsset) return &cleanRoomAsset, err } @@ -67,12 +104,47 @@ type cleanRoomTaskRunsImpl struct { client *client.DatabricksClient } -func (a *cleanRoomTaskRunsImpl) List(ctx context.Context, request ListCleanRoomNotebookTaskRunsRequest) (*ListCleanRoomNotebookTaskRunsResponse, error) { +// List notebook task runs. +// +// List all the historical notebook task runs in a clean room. +func (a *cleanRoomTaskRunsImpl) List(ctx context.Context, request ListCleanRoomNotebookTaskRunsRequest) listing.Iterator[CleanRoomNotebookTaskRun] { + + getNextPage := func(ctx context.Context, req ListCleanRoomNotebookTaskRunsRequest) (*ListCleanRoomNotebookTaskRunsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListCleanRoomNotebookTaskRunsResponse) []CleanRoomNotebookTaskRun { + return resp.Runs + } + getNextReq := func(resp *ListCleanRoomNotebookTaskRunsResponse) *ListCleanRoomNotebookTaskRunsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List notebook task runs. +// +// List all the historical notebook task runs in a clean room. +func (a *cleanRoomTaskRunsImpl) ListAll(ctx context.Context, request ListCleanRoomNotebookTaskRunsRequest) ([]CleanRoomNotebookTaskRun, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[CleanRoomNotebookTaskRun](ctx, iterator) +} +func (a *cleanRoomTaskRunsImpl) internalList(ctx context.Context, request ListCleanRoomNotebookTaskRunsRequest) (*ListCleanRoomNotebookTaskRunsResponse, error) { var listCleanRoomNotebookTaskRunsResponse ListCleanRoomNotebookTaskRunsResponse path := fmt.Sprintf("/api/2.0/clean-rooms/%v/runs", request.CleanRoomName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listCleanRoomNotebookTaskRunsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listCleanRoomNotebookTaskRunsResponse) return &listCleanRoomNotebookTaskRunsResponse, err } @@ -84,56 +156,98 @@ type cleanRoomsImpl struct { func (a *cleanRoomsImpl) Create(ctx context.Context, request CreateCleanRoomRequest) (*CleanRoom, error) { var cleanRoom CleanRoom path := "/api/2.0/clean-rooms" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request.CleanRoom, &cleanRoom) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request.CleanRoom, &cleanRoom) return &cleanRoom, err } func (a *cleanRoomsImpl) CreateOutputCatalog(ctx context.Context, request CreateCleanRoomOutputCatalogRequest) (*CreateCleanRoomOutputCatalogResponse, error) { var createCleanRoomOutputCatalogResponse CreateCleanRoomOutputCatalogResponse path := fmt.Sprintf("/api/2.0/clean-rooms/%v/output-catalogs", request.CleanRoomName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request.OutputCatalog, &createCleanRoomOutputCatalogResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request.OutputCatalog, &createCleanRoomOutputCatalogResponse) return &createCleanRoomOutputCatalogResponse, err } func (a *cleanRoomsImpl) Delete(ctx context.Context, request DeleteCleanRoomRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.0/clean-rooms/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *cleanRoomsImpl) Get(ctx context.Context, request GetCleanRoomRequest) (*CleanRoom, error) { var cleanRoom CleanRoom path := fmt.Sprintf("/api/2.0/clean-rooms/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &cleanRoom) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &cleanRoom) return &cleanRoom, err } -func (a *cleanRoomsImpl) List(ctx context.Context, request ListCleanRoomsRequest) (*ListCleanRoomsResponse, error) { +// List clean rooms. +// +// Get a list of all clean rooms of the metastore. Only clean rooms the caller +// has access to are returned. +func (a *cleanRoomsImpl) List(ctx context.Context, request ListCleanRoomsRequest) listing.Iterator[CleanRoom] { + + getNextPage := func(ctx context.Context, req ListCleanRoomsRequest) (*ListCleanRoomsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListCleanRoomsResponse) []CleanRoom { + return resp.CleanRooms + } + getNextReq := func(resp *ListCleanRoomsResponse) *ListCleanRoomsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List clean rooms. +// +// Get a list of all clean rooms of the metastore. Only clean rooms the caller +// has access to are returned. +func (a *cleanRoomsImpl) ListAll(ctx context.Context, request ListCleanRoomsRequest) ([]CleanRoom, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[CleanRoom](ctx, iterator) +} +func (a *cleanRoomsImpl) internalList(ctx context.Context, request ListCleanRoomsRequest) (*ListCleanRoomsResponse, error) { var listCleanRoomsResponse ListCleanRoomsResponse path := "/api/2.0/clean-rooms" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listCleanRoomsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listCleanRoomsResponse) return &listCleanRoomsResponse, err } func (a *cleanRoomsImpl) Update(ctx context.Context, request UpdateCleanRoomRequest) (*CleanRoom, error) { var cleanRoom CleanRoom path := fmt.Sprintf("/api/2.0/clean-rooms/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &cleanRoom) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &cleanRoom) return &cleanRoom, err } diff --git a/cleanrooms/v2/model.go b/cleanrooms/v2/model.go index ee1208eb6..116138f7d 100755 --- a/cleanrooms/v2/model.go +++ b/cleanrooms/v2/model.go @@ -192,12 +192,6 @@ type CleanRoomAssetNotebook struct { // Base 64 representation of the notebook contents. This is the same format // as returned by :method:workspace/export with the format of **HTML**. NotebookContent string `json:"notebook_content,omitempty"` - // top-level status derived from all reviews - ReviewState CleanRoomNotebookReviewNotebookReviewState `json:"review_state,omitempty"` - // All existing approvals or rejections - Reviews []CleanRoomNotebookReview `json:"reviews,omitempty"` - // collaborators that can run the notebook - RunnerCollaborators []CleanRoomCollaborator `json:"runner_collaborators,omitempty"` ForceSendFields []string `json:"-"` } @@ -342,56 +336,6 @@ func (s CleanRoomCollaborator) MarshalJSON() ([]byte, error) { return marshal.Marshal(s) } -type CleanRoomNotebookReview struct { - // review comment - Comment string `json:"comment,omitempty"` - // timestamp of when the review was submitted - CreatedAtMillis int64 `json:"created_at_millis,omitempty"` - // review outcome - ReviewState CleanRoomNotebookReviewNotebookReviewState `json:"review_state,omitempty"` - // collaborator alias of the reviewer - ReviewerCollaboratorAlias string `json:"reviewer_collaborator_alias,omitempty"` - - ForceSendFields []string `json:"-"` -} - -func (s *CleanRoomNotebookReview) UnmarshalJSON(b []byte) error { - return marshal.Unmarshal(b, s) -} - -func (s CleanRoomNotebookReview) MarshalJSON() ([]byte, error) { - return marshal.Marshal(s) -} - -type CleanRoomNotebookReviewNotebookReviewState string - -const CleanRoomNotebookReviewNotebookReviewStateApproved CleanRoomNotebookReviewNotebookReviewState = `APPROVED` - -const CleanRoomNotebookReviewNotebookReviewStatePending CleanRoomNotebookReviewNotebookReviewState = `PENDING` - -const CleanRoomNotebookReviewNotebookReviewStateRejected CleanRoomNotebookReviewNotebookReviewState = `REJECTED` - -// String representation for [fmt.Print] -func (f *CleanRoomNotebookReviewNotebookReviewState) String() string { - return string(*f) -} - -// Set raw string value and validate it against allowed values -func (f *CleanRoomNotebookReviewNotebookReviewState) Set(v string) error { - switch v { - case `APPROVED`, `PENDING`, `REJECTED`: - *f = CleanRoomNotebookReviewNotebookReviewState(v) - return nil - default: - return fmt.Errorf(`value "%s" is not one of "APPROVED", "PENDING", "REJECTED"`, v) - } -} - -// Type always returns CleanRoomNotebookReviewNotebookReviewState to satisfy [pflag.Value] interface -func (f *CleanRoomNotebookReviewNotebookReviewState) Type() string { - return "CleanRoomNotebookReviewNotebookReviewState" -} - // Stores information about a single task run. type CleanRoomNotebookTaskRun struct { // Job run info of the task in the runner's local workspace. This field is @@ -828,8 +772,12 @@ const ComplianceStandardFedrampModerate ComplianceStandard = `FEDRAMP_MODERATE` const ComplianceStandardHipaa ComplianceStandard = `HIPAA` +const ComplianceStandardHitrust ComplianceStandard = `HITRUST` + const ComplianceStandardIrapProtected ComplianceStandard = `IRAP_PROTECTED` +const ComplianceStandardIsmap ComplianceStandard = `ISMAP` + const ComplianceStandardItarEar ComplianceStandard = `ITAR_EAR` const ComplianceStandardNone ComplianceStandard = `NONE` @@ -844,11 +792,11 @@ func (f *ComplianceStandard) String() string { // Set raw string value and validate it against allowed values func (f *ComplianceStandard) Set(v string) error { switch v { - case `CANADA_PROTECTED_B`, `CYBER_ESSENTIAL_PLUS`, `FEDRAMP_HIGH`, `FEDRAMP_IL5`, `FEDRAMP_MODERATE`, `HIPAA`, `IRAP_PROTECTED`, `ITAR_EAR`, `NONE`, `PCI_DSS`: + case `CANADA_PROTECTED_B`, `CYBER_ESSENTIAL_PLUS`, `FEDRAMP_HIGH`, `FEDRAMP_IL5`, `FEDRAMP_MODERATE`, `HIPAA`, `HITRUST`, `IRAP_PROTECTED`, `ISMAP`, `ITAR_EAR`, `NONE`, `PCI_DSS`: *f = ComplianceStandard(v) return nil default: - return fmt.Errorf(`value "%s" is not one of "CANADA_PROTECTED_B", "CYBER_ESSENTIAL_PLUS", "FEDRAMP_HIGH", "FEDRAMP_IL5", "FEDRAMP_MODERATE", "HIPAA", "IRAP_PROTECTED", "ITAR_EAR", "NONE", "PCI_DSS"`, v) + return fmt.Errorf(`value "%s" is not one of "CANADA_PROTECTED_B", "CYBER_ESSENTIAL_PLUS", "FEDRAMP_HIGH", "FEDRAMP_IL5", "FEDRAMP_MODERATE", "HIPAA", "HITRUST", "IRAP_PROTECTED", "ISMAP", "ITAR_EAR", "NONE", "PCI_DSS"`, v) } } diff --git a/compute/go.mod b/compute/go.mod index abc8463af..22fb85ae1 100644 --- a/compute/go.mod +++ b/compute/go.mod @@ -7,7 +7,9 @@ replace github.com/databricks/databricks-sdk-go/databricks => ../databricks require ( github.com/databricks/databricks-sdk-go/databricks v0.0.0-00010101000000-000000000000 github.com/stretchr/testify v1.10.0 - golang.org/x/mod v0.18.0 + golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 + golang.org/x/mod v0.17.0 + golang.org/x/oauth2 v0.25.0 ) require ( @@ -30,9 +32,7 @@ require ( go.opentelemetry.io/otel/metric v1.24.0 // indirect go.opentelemetry.io/otel/trace v1.24.0 // indirect golang.org/x/crypto v0.31.0 // indirect - golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/net v0.33.0 // indirect - golang.org/x/oauth2 v0.20.0 // indirect golang.org/x/sys v0.28.0 // indirect golang.org/x/text v0.21.0 // indirect golang.org/x/time v0.5.0 // indirect diff --git a/compute/go.sum b/compute/go.sum index f7afe9503..28f3a1b21 100644 --- a/compute/go.sum +++ b/compute/go.sum @@ -88,8 +88,8 @@ golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0= -golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -99,8 +99,8 @@ golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I= golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.20.0 h1:4mQdhULixXKP1rwYBW0vAijoXnkTG0BLCDRzfe1idMo= -golang.org/x/oauth2 v0.20.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/oauth2 v0.25.0 h1:CY4y7XT9v0cRI9oupztF8AgiIu99L/ksR/Xp/6jrZ70= +golang.org/x/oauth2 v0.25.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= diff --git a/compute/v2/api.go b/compute/v2/api.go index 7b12de74f..019501cf3 100755 --- a/compute/v2/api.go +++ b/compute/v2/api.go @@ -191,39 +191,6 @@ func (a *ClusterPoliciesAPI) GetPermissionsByClusterPolicyId(ctx context.Context }) } -// List cluster policies. -// -// Returns a list of policies accessible by the requesting user. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ClusterPoliciesAPI) List(ctx context.Context, request ListClusterPoliciesRequest) listing.Iterator[Policy] { - - getNextPage := func(ctx context.Context, req ListClusterPoliciesRequest) (*ListPoliciesResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.clusterPoliciesImpl.List(ctx, req) - } - getItems := func(resp *ListPoliciesResponse) []Policy { - return resp.Policies - } - - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - nil) - return iterator -} - -// List cluster policies. -// -// Returns a list of policies accessible by the requesting user. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ClusterPoliciesAPI) ListAll(ctx context.Context, request ListClusterPoliciesRequest) ([]Policy, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[Policy](ctx, iterator) -} - // PolicyNameToPolicyIdMap calls [ClusterPoliciesAPI.ListAll] and creates a map of results with [Policy].Name as key and [Policy].PolicyId as value. // // Returns an error if there's more than one [Policy] with the same .Name. @@ -605,51 +572,6 @@ func (a *ClustersAPI) DeleteByClusterId(ctx context.Context, clusterId string) e }) } -// List cluster activity events. -// -// Retrieves a list of events about the activity of a cluster. This API is -// paginated. If there are more events to read, the response includes all the -// nparameters necessary to request the next page of events. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ClustersAPI) Events(ctx context.Context, request GetEvents) listing.Iterator[ClusterEvent] { - - getNextPage := func(ctx context.Context, req GetEvents) (*GetEventsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.clustersImpl.Events(ctx, req) - } - getItems := func(resp *GetEventsResponse) []ClusterEvent { - return resp.Events - } - getNextReq := func(resp *GetEventsResponse) *GetEvents { - if resp.NextPage == nil { - return nil - } - request = *resp.NextPage - - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List cluster activity events. -// -// Retrieves a list of events about the activity of a cluster. This API is -// paginated. If there are more events to read, the response includes all the -// nparameters necessary to request the next page of events. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ClustersAPI) EventsAll(ctx context.Context, request GetEvents) ([]ClusterEvent, error) { - iterator := a.Events(ctx, request) - return listing.ToSliceN[ClusterEvent, int64](ctx, iterator, request.Limit) - -} - // Get cluster info. // // Retrieves the information for a cluster given its identifier. Clusters can be @@ -679,50 +601,6 @@ func (a *ClustersAPI) GetPermissionsByClusterId(ctx context.Context, clusterId s }) } -// List clusters. -// -// Return information about all pinned and active clusters, and all clusters -// terminated within the last 30 days. Clusters terminated prior to this period -// are not included. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ClustersAPI) List(ctx context.Context, request ListClustersRequest) listing.Iterator[ClusterDetails] { - - getNextPage := func(ctx context.Context, req ListClustersRequest) (*ListClustersResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.clustersImpl.List(ctx, req) - } - getItems := func(resp *ListClustersResponse) []ClusterDetails { - return resp.Clusters - } - getNextReq := func(resp *ListClustersResponse) *ListClustersRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List clusters. -// -// Return information about all pinned and active clusters, and all clusters -// terminated within the last 30 days. Clusters terminated prior to this period -// are not included. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ClustersAPI) ListAll(ctx context.Context, request ListClustersRequest) ([]ClusterDetails, error) { - iterator := a.List(ctx, request) - return listing.ToSliceN[ClusterDetails, int](ctx, iterator, request.PageSize) - -} - // ClusterDetailsClusterNameToClusterIdMap calls [ClustersAPI.ListAll] and creates a map of results with [ClusterDetails].ClusterName as key and [ClusterDetails].ClusterId as value. // // Returns an error if there's more than one [ClusterDetails] with the same .ClusterName. @@ -1000,46 +878,6 @@ func (a *GlobalInitScriptsAPI) GetByScriptId(ctx context.Context, scriptId strin }) } -// Get init scripts. -// -// Get a list of all global init scripts for this workspace. This returns all -// properties for each script but **not** the script contents. To retrieve the -// contents of a script, use the [get a global init -// script](:method:globalinitscripts/get) operation. -// -// This method is generated by Databricks SDK Code Generator. -func (a *GlobalInitScriptsAPI) List(ctx context.Context) listing.Iterator[GlobalInitScriptDetails] { - request := struct{}{} - - getNextPage := func(ctx context.Context, req struct{}) (*ListGlobalInitScriptsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.globalInitScriptsImpl.List(ctx) - } - getItems := func(resp *ListGlobalInitScriptsResponse) []GlobalInitScriptDetails { - return resp.Scripts - } - - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - nil) - return iterator -} - -// Get init scripts. -// -// Get a list of all global init scripts for this workspace. This returns all -// properties for each script but **not** the script contents. To retrieve the -// contents of a script, use the [get a global init -// script](:method:globalinitscripts/get) operation. -// -// This method is generated by Databricks SDK Code Generator. -func (a *GlobalInitScriptsAPI) ListAll(ctx context.Context) ([]GlobalInitScriptDetails, error) { - iterator := a.List(ctx) - return listing.ToSlice[GlobalInitScriptDetails](ctx, iterator) -} - // GlobalInitScriptDetailsNameToScriptIdMap calls [GlobalInitScriptsAPI.ListAll] and creates a map of results with [GlobalInitScriptDetails].Name as key and [GlobalInitScriptDetails].ScriptId as value. // // Returns an error if there's more than one [GlobalInitScriptDetails] with the same .Name. @@ -1263,40 +1101,6 @@ func (a *InstancePoolsAPI) GetPermissionsByInstancePoolId(ctx context.Context, i }) } -// List instance pool info. -// -// Gets a list of instance pools with their statistics. -// -// This method is generated by Databricks SDK Code Generator. -func (a *InstancePoolsAPI) List(ctx context.Context) listing.Iterator[InstancePoolAndStats] { - request := struct{}{} - - getNextPage := func(ctx context.Context, req struct{}) (*ListInstancePools, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.instancePoolsImpl.List(ctx) - } - getItems := func(resp *ListInstancePools) []InstancePoolAndStats { - return resp.InstancePools - } - - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - nil) - return iterator -} - -// List instance pool info. -// -// Gets a list of instance pools with their statistics. -// -// This method is generated by Databricks SDK Code Generator. -func (a *InstancePoolsAPI) ListAll(ctx context.Context) ([]InstancePoolAndStats, error) { - iterator := a.List(ctx) - return listing.ToSlice[InstancePoolAndStats](ctx, iterator) -} - // InstancePoolAndStatsInstancePoolNameToInstancePoolIdMap calls [InstancePoolsAPI.ListAll] and creates a map of results with [InstancePoolAndStats].InstancePoolName as key and [InstancePoolAndStats].InstancePoolId as value. // // Returns an error if there's more than one [InstancePoolAndStats] with the same .InstancePoolName. @@ -1430,44 +1234,6 @@ type InstanceProfilesAPI struct { instanceProfilesImpl } -// List available instance profiles. -// -// List the instance profiles that the calling user can use to launch a cluster. -// -// This API is available to all users. -// -// This method is generated by Databricks SDK Code Generator. -func (a *InstanceProfilesAPI) List(ctx context.Context) listing.Iterator[InstanceProfile] { - request := struct{}{} - - getNextPage := func(ctx context.Context, req struct{}) (*ListInstanceProfilesResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.instanceProfilesImpl.List(ctx) - } - getItems := func(resp *ListInstanceProfilesResponse) []InstanceProfile { - return resp.InstanceProfiles - } - - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - nil) - return iterator -} - -// List available instance profiles. -// -// List the instance profiles that the calling user can use to launch a cluster. -// -// This API is available to all users. -// -// This method is generated by Databricks SDK Code Generator. -func (a *InstanceProfilesAPI) ListAll(ctx context.Context) ([]InstanceProfile, error) { - iterator := a.List(ctx) - return listing.ToSlice[InstanceProfile](ctx, iterator) -} - // Remove the instance profile. // // Remove the instance profile with the provided ARN. Existing clusters with @@ -1578,87 +1344,6 @@ type LibrariesAPI struct { librariesImpl } -// Get all statuses. -// -// Get the status of all libraries on all clusters. A status is returned for all -// libraries installed on this cluster via the API or the libraries UI. -// -// This method is generated by Databricks SDK Code Generator. -func (a *LibrariesAPI) AllClusterStatuses(ctx context.Context) listing.Iterator[ClusterLibraryStatuses] { - request := struct{}{} - - getNextPage := func(ctx context.Context, req struct{}) (*ListAllClusterLibraryStatusesResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.librariesImpl.AllClusterStatuses(ctx) - } - getItems := func(resp *ListAllClusterLibraryStatusesResponse) []ClusterLibraryStatuses { - return resp.Statuses - } - - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - nil) - return iterator -} - -// Get all statuses. -// -// Get the status of all libraries on all clusters. A status is returned for all -// libraries installed on this cluster via the API or the libraries UI. -// -// This method is generated by Databricks SDK Code Generator. -func (a *LibrariesAPI) AllClusterStatusesAll(ctx context.Context) ([]ClusterLibraryStatuses, error) { - iterator := a.AllClusterStatuses(ctx) - return listing.ToSlice[ClusterLibraryStatuses](ctx, iterator) -} - -// Get status. -// -// Get the status of libraries on a cluster. A status is returned for all -// libraries installed on this cluster via the API or the libraries UI. The -// order of returned libraries is as follows: 1. Libraries set to be installed -// on this cluster, in the order that the libraries were added to the cluster, -// are returned first. 2. Libraries that were previously requested to be -// installed on this cluster or, but are now marked for removal, in no -// particular order, are returned last. -// -// This method is generated by Databricks SDK Code Generator. -func (a *LibrariesAPI) ClusterStatus(ctx context.Context, request ClusterStatus) listing.Iterator[LibraryFullStatus] { - - getNextPage := func(ctx context.Context, req ClusterStatus) (*ClusterLibraryStatuses, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.librariesImpl.ClusterStatus(ctx, req) - } - getItems := func(resp *ClusterLibraryStatuses) []LibraryFullStatus { - return resp.LibraryStatuses - } - - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - nil) - return iterator -} - -// Get status. -// -// Get the status of libraries on a cluster. A status is returned for all -// libraries installed on this cluster via the API or the libraries UI. The -// order of returned libraries is as follows: 1. Libraries set to be installed -// on this cluster, in the order that the libraries were added to the cluster, -// are returned first. 2. Libraries that were previously requested to be -// installed on this cluster or, but are now marked for removal, in no -// particular order, are returned last. -// -// This method is generated by Databricks SDK Code Generator. -func (a *LibrariesAPI) ClusterStatusAll(ctx context.Context, request ClusterStatus) ([]LibraryFullStatus, error) { - iterator := a.ClusterStatus(ctx, request) - return listing.ToSlice[LibraryFullStatus](ctx, iterator) -} - // Get status. // // Get the status of libraries on a cluster. A status is returned for all @@ -1669,7 +1354,7 @@ func (a *LibrariesAPI) ClusterStatusAll(ctx context.Context, request ClusterStat // installed on this cluster or, but are now marked for removal, in no // particular order, are returned last. func (a *LibrariesAPI) ClusterStatusByClusterId(ctx context.Context, clusterId string) (*ClusterLibraryStatuses, error) { - return a.librariesImpl.ClusterStatus(ctx, ClusterStatus{ + return a.librariesImpl.internalClusterStatus(ctx, ClusterStatus{ ClusterId: clusterId, }) } @@ -1756,49 +1441,6 @@ func (a *PolicyComplianceForClustersAPI) GetComplianceByClusterId(ctx context.Co }) } -// List cluster policy compliance. -// -// Returns the policy compliance status of all clusters that use a given policy. -// Clusters could be out of compliance if their policy was updated after the -// cluster was last edited. -// -// This method is generated by Databricks SDK Code Generator. -func (a *PolicyComplianceForClustersAPI) ListCompliance(ctx context.Context, request ListClusterCompliancesRequest) listing.Iterator[ClusterCompliance] { - - getNextPage := func(ctx context.Context, req ListClusterCompliancesRequest) (*ListClusterCompliancesResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.policyComplianceForClustersImpl.ListCompliance(ctx, req) - } - getItems := func(resp *ListClusterCompliancesResponse) []ClusterCompliance { - return resp.Clusters - } - getNextReq := func(resp *ListClusterCompliancesResponse) *ListClusterCompliancesRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List cluster policy compliance. -// -// Returns the policy compliance status of all clusters that use a given policy. -// Clusters could be out of compliance if their policy was updated after the -// cluster was last edited. -// -// This method is generated by Databricks SDK Code Generator. -func (a *PolicyComplianceForClustersAPI) ListComplianceAll(ctx context.Context, request ListClusterCompliancesRequest) ([]ClusterCompliance, error) { - iterator := a.ListCompliance(ctx, request) - return listing.ToSlice[ClusterCompliance](ctx, iterator) -} - type PolicyFamiliesInterface interface { // Get policy family information. @@ -1860,44 +1502,3 @@ func (a *PolicyFamiliesAPI) GetByPolicyFamilyId(ctx context.Context, policyFamil PolicyFamilyId: policyFamilyId, }) } - -// List policy families. -// -// Returns the list of policy definition types available to use at their latest -// version. This API is paginated. -// -// This method is generated by Databricks SDK Code Generator. -func (a *PolicyFamiliesAPI) List(ctx context.Context, request ListPolicyFamiliesRequest) listing.Iterator[PolicyFamily] { - - getNextPage := func(ctx context.Context, req ListPolicyFamiliesRequest) (*ListPolicyFamiliesResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.policyFamiliesImpl.List(ctx, req) - } - getItems := func(resp *ListPolicyFamiliesResponse) []PolicyFamily { - return resp.PolicyFamilies - } - getNextReq := func(resp *ListPolicyFamiliesResponse) *ListPolicyFamiliesRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List policy families. -// -// Returns the list of policy definition types available to use at their latest -// version. This API is paginated. -// -// This method is generated by Databricks SDK Code Generator. -func (a *PolicyFamiliesAPI) ListAll(ctx context.Context, request ListPolicyFamiliesRequest) ([]PolicyFamily, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[PolicyFamily](ctx, iterator) -} diff --git a/compute/v2/impl.go b/compute/v2/impl.go index 2082900fe..f80542fa9 100755 --- a/compute/v2/impl.go +++ b/compute/v2/impl.go @@ -8,6 +8,8 @@ import ( "net/http" "github.com/databricks/databricks-sdk-go/databricks/client" + "github.com/databricks/databricks-sdk-go/databricks/listing" + "github.com/databricks/databricks-sdk-go/databricks/useragent" ) // unexported type that holds implementations of just ClusterPolicies API methods @@ -18,86 +20,123 @@ type clusterPoliciesImpl struct { func (a *clusterPoliciesImpl) Create(ctx context.Context, request CreatePolicy) (*CreatePolicyResponse, error) { var createPolicyResponse CreatePolicyResponse path := "/api/2.0/policies/clusters/create" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createPolicyResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createPolicyResponse) return &createPolicyResponse, err } func (a *clusterPoliciesImpl) Delete(ctx context.Context, request DeletePolicy) error { var deletePolicyResponse DeletePolicyResponse path := "/api/2.0/policies/clusters/delete" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &deletePolicyResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &deletePolicyResponse) return err } func (a *clusterPoliciesImpl) Edit(ctx context.Context, request EditPolicy) error { var editPolicyResponse EditPolicyResponse path := "/api/2.0/policies/clusters/edit" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &editPolicyResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &editPolicyResponse) return err } func (a *clusterPoliciesImpl) Get(ctx context.Context, request GetClusterPolicyRequest) (*Policy, error) { var policy Policy path := "/api/2.0/policies/clusters/get" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &policy) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &policy) return &policy, err } func (a *clusterPoliciesImpl) GetPermissionLevels(ctx context.Context, request GetClusterPolicyPermissionLevelsRequest) (*GetClusterPolicyPermissionLevelsResponse, error) { var getClusterPolicyPermissionLevelsResponse GetClusterPolicyPermissionLevelsResponse path := fmt.Sprintf("/api/2.0/permissions/cluster-policies/%v/permissionLevels", request.ClusterPolicyId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getClusterPolicyPermissionLevelsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getClusterPolicyPermissionLevelsResponse) return &getClusterPolicyPermissionLevelsResponse, err } func (a *clusterPoliciesImpl) GetPermissions(ctx context.Context, request GetClusterPolicyPermissionsRequest) (*ClusterPolicyPermissions, error) { var clusterPolicyPermissions ClusterPolicyPermissions path := fmt.Sprintf("/api/2.0/permissions/cluster-policies/%v", request.ClusterPolicyId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &clusterPolicyPermissions) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &clusterPolicyPermissions) return &clusterPolicyPermissions, err } -func (a *clusterPoliciesImpl) List(ctx context.Context, request ListClusterPoliciesRequest) (*ListPoliciesResponse, error) { +// List cluster policies. +// +// Returns a list of policies accessible by the requesting user. +func (a *clusterPoliciesImpl) List(ctx context.Context, request ListClusterPoliciesRequest) listing.Iterator[Policy] { + + getNextPage := func(ctx context.Context, req ListClusterPoliciesRequest) (*ListPoliciesResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListPoliciesResponse) []Policy { + return resp.Policies + } + + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + nil) + return iterator +} + +// List cluster policies. +// +// Returns a list of policies accessible by the requesting user. +func (a *clusterPoliciesImpl) ListAll(ctx context.Context, request ListClusterPoliciesRequest) ([]Policy, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[Policy](ctx, iterator) +} +func (a *clusterPoliciesImpl) internalList(ctx context.Context, request ListClusterPoliciesRequest) (*ListPoliciesResponse, error) { var listPoliciesResponse ListPoliciesResponse path := "/api/2.0/policies/clusters/list" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listPoliciesResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listPoliciesResponse) return &listPoliciesResponse, err } func (a *clusterPoliciesImpl) SetPermissions(ctx context.Context, request ClusterPolicyPermissionsRequest) (*ClusterPolicyPermissions, error) { var clusterPolicyPermissions ClusterPolicyPermissions path := fmt.Sprintf("/api/2.0/permissions/cluster-policies/%v", request.ClusterPolicyId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &clusterPolicyPermissions) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &clusterPolicyPermissions) return &clusterPolicyPermissions, err } func (a *clusterPoliciesImpl) UpdatePermissions(ctx context.Context, request ClusterPolicyPermissionsRequest) (*ClusterPolicyPermissions, error) { var clusterPolicyPermissions ClusterPolicyPermissions path := fmt.Sprintf("/api/2.0/permissions/cluster-policies/%v", request.ClusterPolicyId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &clusterPolicyPermissions) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &clusterPolicyPermissions) return &clusterPolicyPermissions, err } @@ -109,203 +148,303 @@ type clustersImpl struct { func (a *clustersImpl) ChangeOwner(ctx context.Context, request ChangeClusterOwner) error { var changeClusterOwnerResponse ChangeClusterOwnerResponse path := "/api/2.1/clusters/change-owner" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &changeClusterOwnerResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &changeClusterOwnerResponse) return err } func (a *clustersImpl) Create(ctx context.Context, request CreateCluster) (*CreateClusterResponse, error) { var createClusterResponse CreateClusterResponse path := "/api/2.1/clusters/create" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createClusterResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createClusterResponse) return &createClusterResponse, err } func (a *clustersImpl) Delete(ctx context.Context, request DeleteCluster) error { var deleteClusterResponse DeleteClusterResponse path := "/api/2.1/clusters/delete" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &deleteClusterResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &deleteClusterResponse) return err } func (a *clustersImpl) Edit(ctx context.Context, request EditCluster) error { var editClusterResponse EditClusterResponse path := "/api/2.1/clusters/edit" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &editClusterResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &editClusterResponse) return err } -func (a *clustersImpl) Events(ctx context.Context, request GetEvents) (*GetEventsResponse, error) { +// List cluster activity events. +// +// Retrieves a list of events about the activity of a cluster. This API is +// paginated. If there are more events to read, the response includes all the +// nparameters necessary to request the next page of events. +func (a *clustersImpl) Events(ctx context.Context, request GetEvents) listing.Iterator[ClusterEvent] { + + getNextPage := func(ctx context.Context, req GetEvents) (*GetEventsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalEvents(ctx, req) + } + getItems := func(resp *GetEventsResponse) []ClusterEvent { + return resp.Events + } + getNextReq := func(resp *GetEventsResponse) *GetEvents { + if resp.NextPage == nil { + return nil + } + request = *resp.NextPage + + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List cluster activity events. +// +// Retrieves a list of events about the activity of a cluster. This API is +// paginated. If there are more events to read, the response includes all the +// nparameters necessary to request the next page of events. +func (a *clustersImpl) EventsAll(ctx context.Context, request GetEvents) ([]ClusterEvent, error) { + iterator := a.Events(ctx, request) + return listing.ToSliceN[ClusterEvent, int64](ctx, iterator, request.Limit) + +} +func (a *clustersImpl) internalEvents(ctx context.Context, request GetEvents) (*GetEventsResponse, error) { var getEventsResponse GetEventsResponse path := "/api/2.1/clusters/events" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &getEventsResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &getEventsResponse) return &getEventsResponse, err } func (a *clustersImpl) Get(ctx context.Context, request GetClusterRequest) (*ClusterDetails, error) { var clusterDetails ClusterDetails path := "/api/2.1/clusters/get" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &clusterDetails) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &clusterDetails) return &clusterDetails, err } func (a *clustersImpl) GetPermissionLevels(ctx context.Context, request GetClusterPermissionLevelsRequest) (*GetClusterPermissionLevelsResponse, error) { var getClusterPermissionLevelsResponse GetClusterPermissionLevelsResponse path := fmt.Sprintf("/api/2.0/permissions/clusters/%v/permissionLevels", request.ClusterId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getClusterPermissionLevelsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getClusterPermissionLevelsResponse) return &getClusterPermissionLevelsResponse, err } func (a *clustersImpl) GetPermissions(ctx context.Context, request GetClusterPermissionsRequest) (*ClusterPermissions, error) { var clusterPermissions ClusterPermissions path := fmt.Sprintf("/api/2.0/permissions/clusters/%v", request.ClusterId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &clusterPermissions) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &clusterPermissions) return &clusterPermissions, err } -func (a *clustersImpl) List(ctx context.Context, request ListClustersRequest) (*ListClustersResponse, error) { +// List clusters. +// +// Return information about all pinned and active clusters, and all clusters +// terminated within the last 30 days. Clusters terminated prior to this period +// are not included. +func (a *clustersImpl) List(ctx context.Context, request ListClustersRequest) listing.Iterator[ClusterDetails] { + + getNextPage := func(ctx context.Context, req ListClustersRequest) (*ListClustersResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListClustersResponse) []ClusterDetails { + return resp.Clusters + } + getNextReq := func(resp *ListClustersResponse) *ListClustersRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List clusters. +// +// Return information about all pinned and active clusters, and all clusters +// terminated within the last 30 days. Clusters terminated prior to this period +// are not included. +func (a *clustersImpl) ListAll(ctx context.Context, request ListClustersRequest) ([]ClusterDetails, error) { + iterator := a.List(ctx, request) + return listing.ToSliceN[ClusterDetails, int](ctx, iterator, request.PageSize) + +} +func (a *clustersImpl) internalList(ctx context.Context, request ListClustersRequest) (*ListClustersResponse, error) { var listClustersResponse ListClustersResponse path := "/api/2.1/clusters/list" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listClustersResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listClustersResponse) return &listClustersResponse, err } func (a *clustersImpl) ListNodeTypes(ctx context.Context) (*ListNodeTypesResponse, error) { var listNodeTypesResponse ListNodeTypesResponse path := "/api/2.1/clusters/list-node-types" + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &listNodeTypesResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &listNodeTypesResponse) return &listNodeTypesResponse, err } func (a *clustersImpl) ListZones(ctx context.Context) (*ListAvailableZonesResponse, error) { var listAvailableZonesResponse ListAvailableZonesResponse path := "/api/2.1/clusters/list-zones" + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &listAvailableZonesResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &listAvailableZonesResponse) return &listAvailableZonesResponse, err } func (a *clustersImpl) PermanentDelete(ctx context.Context, request PermanentDeleteCluster) error { var permanentDeleteClusterResponse PermanentDeleteClusterResponse path := "/api/2.1/clusters/permanent-delete" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &permanentDeleteClusterResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &permanentDeleteClusterResponse) return err } func (a *clustersImpl) Pin(ctx context.Context, request PinCluster) error { var pinClusterResponse PinClusterResponse path := "/api/2.1/clusters/pin" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &pinClusterResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &pinClusterResponse) return err } func (a *clustersImpl) Resize(ctx context.Context, request ResizeCluster) error { var resizeClusterResponse ResizeClusterResponse path := "/api/2.1/clusters/resize" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &resizeClusterResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &resizeClusterResponse) return err } func (a *clustersImpl) Restart(ctx context.Context, request RestartCluster) error { var restartClusterResponse RestartClusterResponse path := "/api/2.1/clusters/restart" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &restartClusterResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &restartClusterResponse) return err } func (a *clustersImpl) SetPermissions(ctx context.Context, request ClusterPermissionsRequest) (*ClusterPermissions, error) { var clusterPermissions ClusterPermissions path := fmt.Sprintf("/api/2.0/permissions/clusters/%v", request.ClusterId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &clusterPermissions) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &clusterPermissions) return &clusterPermissions, err } func (a *clustersImpl) SparkVersions(ctx context.Context) (*GetSparkVersionsResponse, error) { var getSparkVersionsResponse GetSparkVersionsResponse path := "/api/2.1/clusters/spark-versions" + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &getSparkVersionsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &getSparkVersionsResponse) return &getSparkVersionsResponse, err } func (a *clustersImpl) Start(ctx context.Context, request StartCluster) error { var startClusterResponse StartClusterResponse path := "/api/2.1/clusters/start" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &startClusterResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &startClusterResponse) return err } func (a *clustersImpl) Unpin(ctx context.Context, request UnpinCluster) error { var unpinClusterResponse UnpinClusterResponse path := "/api/2.1/clusters/unpin" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &unpinClusterResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &unpinClusterResponse) return err } func (a *clustersImpl) Update(ctx context.Context, request UpdateCluster) error { var updateClusterResponse UpdateClusterResponse path := "/api/2.1/clusters/update" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &updateClusterResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &updateClusterResponse) return err } func (a *clustersImpl) UpdatePermissions(ctx context.Context, request ClusterPermissionsRequest) (*ClusterPermissions, error) { var clusterPermissions ClusterPermissions path := fmt.Sprintf("/api/2.0/permissions/clusters/%v", request.ClusterId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &clusterPermissions) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &clusterPermissions) return &clusterPermissions, err } @@ -317,58 +456,64 @@ type commandExecutionImpl struct { func (a *commandExecutionImpl) Cancel(ctx context.Context, request CancelCommand) error { var cancelResponse CancelResponse path := "/api/1.2/commands/cancel" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &cancelResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &cancelResponse) return err } func (a *commandExecutionImpl) CommandStatus(ctx context.Context, request CommandStatusRequest) (*CommandStatusResponse, error) { var commandStatusResponse CommandStatusResponse path := "/api/1.2/commands/status" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &commandStatusResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, 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" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &contextStatusResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, 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" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &created) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &created) return &created, err } func (a *commandExecutionImpl) Destroy(ctx context.Context, request DestroyContext) error { var destroyResponse DestroyResponse path := "/api/1.2/contexts/destroy" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &destroyResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &destroyResponse) return err } func (a *commandExecutionImpl) Execute(ctx context.Context, request Command) (*Created, error) { var created Created path := "/api/1.2/commands/execute" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &created) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &created) return &created, err } @@ -380,45 +525,85 @@ type globalInitScriptsImpl struct { func (a *globalInitScriptsImpl) Create(ctx context.Context, request GlobalInitScriptCreateRequest) (*CreateResponse, error) { var createResponse CreateResponse path := "/api/2.0/global-init-scripts" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createResponse) return &createResponse, err } func (a *globalInitScriptsImpl) Delete(ctx context.Context, request DeleteGlobalInitScriptRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.0/global-init-scripts/%v", request.ScriptId) + queryParams := make(map[string]any) headers := make(map[string]string) - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *globalInitScriptsImpl) Get(ctx context.Context, request GetGlobalInitScriptRequest) (*GlobalInitScriptDetailsWithContent, error) { var globalInitScriptDetailsWithContent GlobalInitScriptDetailsWithContent path := fmt.Sprintf("/api/2.0/global-init-scripts/%v", request.ScriptId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &globalInitScriptDetailsWithContent) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &globalInitScriptDetailsWithContent) return &globalInitScriptDetailsWithContent, err } -func (a *globalInitScriptsImpl) List(ctx context.Context) (*ListGlobalInitScriptsResponse, error) { +// Get init scripts. +// +// Get a list of all global init scripts for this workspace. This returns all +// properties for each script but **not** the script contents. To retrieve the +// contents of a script, use the [get a global init +// script](:method:globalinitscripts/get) operation. +func (a *globalInitScriptsImpl) List(ctx context.Context) listing.Iterator[GlobalInitScriptDetails] { + request := struct{}{} + + getNextPage := func(ctx context.Context, req struct{}) (*ListGlobalInitScriptsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx) + } + getItems := func(resp *ListGlobalInitScriptsResponse) []GlobalInitScriptDetails { + return resp.Scripts + } + + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + nil) + return iterator +} + +// Get init scripts. +// +// Get a list of all global init scripts for this workspace. This returns all +// properties for each script but **not** the script contents. To retrieve the +// contents of a script, use the [get a global init +// script](:method:globalinitscripts/get) operation. +func (a *globalInitScriptsImpl) ListAll(ctx context.Context) ([]GlobalInitScriptDetails, error) { + iterator := a.List(ctx) + return listing.ToSlice[GlobalInitScriptDetails](ctx, iterator) +} +func (a *globalInitScriptsImpl) internalList(ctx context.Context) (*ListGlobalInitScriptsResponse, error) { var listGlobalInitScriptsResponse ListGlobalInitScriptsResponse path := "/api/2.0/global-init-scripts" + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &listGlobalInitScriptsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &listGlobalInitScriptsResponse) return &listGlobalInitScriptsResponse, err } func (a *globalInitScriptsImpl) Update(ctx context.Context, request GlobalInitScriptUpdateRequest) error { var updateResponse UpdateResponse path := fmt.Sprintf("/api/2.0/global-init-scripts/%v", request.ScriptId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &updateResponse) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &updateResponse) return err } @@ -430,86 +615,124 @@ type instancePoolsImpl struct { func (a *instancePoolsImpl) Create(ctx context.Context, request CreateInstancePool) (*CreateInstancePoolResponse, error) { var createInstancePoolResponse CreateInstancePoolResponse path := "/api/2.0/instance-pools/create" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createInstancePoolResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createInstancePoolResponse) return &createInstancePoolResponse, err } func (a *instancePoolsImpl) Delete(ctx context.Context, request DeleteInstancePool) error { var deleteInstancePoolResponse DeleteInstancePoolResponse path := "/api/2.0/instance-pools/delete" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &deleteInstancePoolResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &deleteInstancePoolResponse) return err } func (a *instancePoolsImpl) Edit(ctx context.Context, request EditInstancePool) error { var editInstancePoolResponse EditInstancePoolResponse path := "/api/2.0/instance-pools/edit" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &editInstancePoolResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &editInstancePoolResponse) return err } func (a *instancePoolsImpl) Get(ctx context.Context, request GetInstancePoolRequest) (*GetInstancePool, error) { var getInstancePool GetInstancePool path := "/api/2.0/instance-pools/get" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getInstancePool) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getInstancePool) return &getInstancePool, err } func (a *instancePoolsImpl) GetPermissionLevels(ctx context.Context, request GetInstancePoolPermissionLevelsRequest) (*GetInstancePoolPermissionLevelsResponse, error) { var getInstancePoolPermissionLevelsResponse GetInstancePoolPermissionLevelsResponse path := fmt.Sprintf("/api/2.0/permissions/instance-pools/%v/permissionLevels", request.InstancePoolId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getInstancePoolPermissionLevelsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getInstancePoolPermissionLevelsResponse) return &getInstancePoolPermissionLevelsResponse, err } func (a *instancePoolsImpl) GetPermissions(ctx context.Context, request GetInstancePoolPermissionsRequest) (*InstancePoolPermissions, error) { var instancePoolPermissions InstancePoolPermissions path := fmt.Sprintf("/api/2.0/permissions/instance-pools/%v", request.InstancePoolId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &instancePoolPermissions) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &instancePoolPermissions) return &instancePoolPermissions, err } -func (a *instancePoolsImpl) List(ctx context.Context) (*ListInstancePools, error) { +// List instance pool info. +// +// Gets a list of instance pools with their statistics. +func (a *instancePoolsImpl) List(ctx context.Context) listing.Iterator[InstancePoolAndStats] { + request := struct{}{} + + getNextPage := func(ctx context.Context, req struct{}) (*ListInstancePools, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx) + } + getItems := func(resp *ListInstancePools) []InstancePoolAndStats { + return resp.InstancePools + } + + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + nil) + return iterator +} + +// List instance pool info. +// +// Gets a list of instance pools with their statistics. +func (a *instancePoolsImpl) ListAll(ctx context.Context) ([]InstancePoolAndStats, error) { + iterator := a.List(ctx) + return listing.ToSlice[InstancePoolAndStats](ctx, iterator) +} +func (a *instancePoolsImpl) internalList(ctx context.Context) (*ListInstancePools, error) { var listInstancePools ListInstancePools path := "/api/2.0/instance-pools/list" + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &listInstancePools) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &listInstancePools) return &listInstancePools, err } func (a *instancePoolsImpl) SetPermissions(ctx context.Context, request InstancePoolPermissionsRequest) (*InstancePoolPermissions, error) { var instancePoolPermissions InstancePoolPermissions path := fmt.Sprintf("/api/2.0/permissions/instance-pools/%v", request.InstancePoolId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &instancePoolPermissions) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &instancePoolPermissions) return &instancePoolPermissions, err } func (a *instancePoolsImpl) UpdatePermissions(ctx context.Context, request InstancePoolPermissionsRequest) (*InstancePoolPermissions, error) { var instancePoolPermissions InstancePoolPermissions path := fmt.Sprintf("/api/2.0/permissions/instance-pools/%v", request.InstancePoolId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &instancePoolPermissions) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &instancePoolPermissions) return &instancePoolPermissions, err } @@ -521,39 +744,76 @@ type instanceProfilesImpl struct { func (a *instanceProfilesImpl) Add(ctx context.Context, request AddInstanceProfile) error { var addResponse AddResponse path := "/api/2.0/instance-profiles/add" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &addResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &addResponse) return err } func (a *instanceProfilesImpl) Edit(ctx context.Context, request InstanceProfile) error { var editResponse EditResponse path := "/api/2.0/instance-profiles/edit" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &editResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &editResponse) return err } -func (a *instanceProfilesImpl) List(ctx context.Context) (*ListInstanceProfilesResponse, error) { +// List available instance profiles. +// +// List the instance profiles that the calling user can use to launch a cluster. +// +// This API is available to all users. +func (a *instanceProfilesImpl) List(ctx context.Context) listing.Iterator[InstanceProfile] { + request := struct{}{} + + getNextPage := func(ctx context.Context, req struct{}) (*ListInstanceProfilesResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx) + } + getItems := func(resp *ListInstanceProfilesResponse) []InstanceProfile { + return resp.InstanceProfiles + } + + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + nil) + return iterator +} + +// List available instance profiles. +// +// List the instance profiles that the calling user can use to launch a cluster. +// +// This API is available to all users. +func (a *instanceProfilesImpl) ListAll(ctx context.Context) ([]InstanceProfile, error) { + iterator := a.List(ctx) + return listing.ToSlice[InstanceProfile](ctx, iterator) +} +func (a *instanceProfilesImpl) internalList(ctx context.Context) (*ListInstanceProfilesResponse, error) { var listInstanceProfilesResponse ListInstanceProfilesResponse path := "/api/2.0/instance-profiles/list" + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &listInstanceProfilesResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &listInstanceProfilesResponse) return &listInstanceProfilesResponse, err } func (a *instanceProfilesImpl) Remove(ctx context.Context, request RemoveInstanceProfile) error { var removeResponse RemoveResponse path := "/api/2.0/instance-profiles/remove" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &removeResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &removeResponse) return err } @@ -562,41 +822,116 @@ type librariesImpl struct { client *client.DatabricksClient } -func (a *librariesImpl) AllClusterStatuses(ctx context.Context) (*ListAllClusterLibraryStatusesResponse, error) { +// Get all statuses. +// +// Get the status of all libraries on all clusters. A status is returned for all +// libraries installed on this cluster via the API or the libraries UI. +func (a *librariesImpl) AllClusterStatuses(ctx context.Context) listing.Iterator[ClusterLibraryStatuses] { + request := struct{}{} + + getNextPage := func(ctx context.Context, req struct{}) (*ListAllClusterLibraryStatusesResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalAllClusterStatuses(ctx) + } + getItems := func(resp *ListAllClusterLibraryStatusesResponse) []ClusterLibraryStatuses { + return resp.Statuses + } + + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + nil) + return iterator +} + +// Get all statuses. +// +// Get the status of all libraries on all clusters. A status is returned for all +// libraries installed on this cluster via the API or the libraries UI. +func (a *librariesImpl) AllClusterStatusesAll(ctx context.Context) ([]ClusterLibraryStatuses, error) { + iterator := a.AllClusterStatuses(ctx) + return listing.ToSlice[ClusterLibraryStatuses](ctx, iterator) +} +func (a *librariesImpl) internalAllClusterStatuses(ctx context.Context) (*ListAllClusterLibraryStatusesResponse, error) { var listAllClusterLibraryStatusesResponse ListAllClusterLibraryStatusesResponse path := "/api/2.0/libraries/all-cluster-statuses" + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &listAllClusterLibraryStatusesResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &listAllClusterLibraryStatusesResponse) return &listAllClusterLibraryStatusesResponse, err } -func (a *librariesImpl) ClusterStatus(ctx context.Context, request ClusterStatus) (*ClusterLibraryStatuses, error) { +// Get status. +// +// Get the status of libraries on a cluster. A status is returned for all +// libraries installed on this cluster via the API or the libraries UI. The +// order of returned libraries is as follows: 1. Libraries set to be installed +// on this cluster, in the order that the libraries were added to the cluster, +// are returned first. 2. Libraries that were previously requested to be +// installed on this cluster or, but are now marked for removal, in no +// particular order, are returned last. +func (a *librariesImpl) ClusterStatus(ctx context.Context, request ClusterStatus) listing.Iterator[LibraryFullStatus] { + + getNextPage := func(ctx context.Context, req ClusterStatus) (*ClusterLibraryStatuses, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalClusterStatus(ctx, req) + } + getItems := func(resp *ClusterLibraryStatuses) []LibraryFullStatus { + return resp.LibraryStatuses + } + + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + nil) + return iterator +} + +// Get status. +// +// Get the status of libraries on a cluster. A status is returned for all +// libraries installed on this cluster via the API or the libraries UI. The +// order of returned libraries is as follows: 1. Libraries set to be installed +// on this cluster, in the order that the libraries were added to the cluster, +// are returned first. 2. Libraries that were previously requested to be +// installed on this cluster or, but are now marked for removal, in no +// particular order, are returned last. +func (a *librariesImpl) ClusterStatusAll(ctx context.Context, request ClusterStatus) ([]LibraryFullStatus, error) { + iterator := a.ClusterStatus(ctx, request) + return listing.ToSlice[LibraryFullStatus](ctx, iterator) +} +func (a *librariesImpl) internalClusterStatus(ctx context.Context, request ClusterStatus) (*ClusterLibraryStatuses, error) { var clusterLibraryStatuses ClusterLibraryStatuses path := "/api/2.0/libraries/cluster-status" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &clusterLibraryStatuses) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &clusterLibraryStatuses) return &clusterLibraryStatuses, err } func (a *librariesImpl) Install(ctx context.Context, request InstallLibraries) error { var installLibrariesResponse InstallLibrariesResponse path := "/api/2.0/libraries/install" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &installLibrariesResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &installLibrariesResponse) return err } func (a *librariesImpl) Uninstall(ctx context.Context, request UninstallLibraries) error { var uninstallLibrariesResponse UninstallLibrariesResponse path := "/api/2.0/libraries/uninstall" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &uninstallLibrariesResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &uninstallLibrariesResponse) return err } @@ -608,28 +943,69 @@ type policyComplianceForClustersImpl struct { func (a *policyComplianceForClustersImpl) EnforceCompliance(ctx context.Context, request EnforceClusterComplianceRequest) (*EnforceClusterComplianceResponse, error) { var enforceClusterComplianceResponse EnforceClusterComplianceResponse path := "/api/2.0/policies/clusters/enforce-compliance" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &enforceClusterComplianceResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &enforceClusterComplianceResponse) return &enforceClusterComplianceResponse, err } func (a *policyComplianceForClustersImpl) GetCompliance(ctx context.Context, request GetClusterComplianceRequest) (*GetClusterComplianceResponse, error) { var getClusterComplianceResponse GetClusterComplianceResponse path := "/api/2.0/policies/clusters/get-compliance" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getClusterComplianceResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getClusterComplianceResponse) return &getClusterComplianceResponse, err } -func (a *policyComplianceForClustersImpl) ListCompliance(ctx context.Context, request ListClusterCompliancesRequest) (*ListClusterCompliancesResponse, error) { +// List cluster policy compliance. +// +// Returns the policy compliance status of all clusters that use a given policy. +// Clusters could be out of compliance if their policy was updated after the +// cluster was last edited. +func (a *policyComplianceForClustersImpl) ListCompliance(ctx context.Context, request ListClusterCompliancesRequest) listing.Iterator[ClusterCompliance] { + + getNextPage := func(ctx context.Context, req ListClusterCompliancesRequest) (*ListClusterCompliancesResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalListCompliance(ctx, req) + } + getItems := func(resp *ListClusterCompliancesResponse) []ClusterCompliance { + return resp.Clusters + } + getNextReq := func(resp *ListClusterCompliancesResponse) *ListClusterCompliancesRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List cluster policy compliance. +// +// Returns the policy compliance status of all clusters that use a given policy. +// Clusters could be out of compliance if their policy was updated after the +// cluster was last edited. +func (a *policyComplianceForClustersImpl) ListComplianceAll(ctx context.Context, request ListClusterCompliancesRequest) ([]ClusterCompliance, error) { + iterator := a.ListCompliance(ctx, request) + return listing.ToSlice[ClusterCompliance](ctx, iterator) +} +func (a *policyComplianceForClustersImpl) internalListCompliance(ctx context.Context, request ListClusterCompliancesRequest) (*ListClusterCompliancesResponse, error) { var listClusterCompliancesResponse ListClusterCompliancesResponse path := "/api/2.0/policies/clusters/list-compliance" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listClusterCompliancesResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listClusterCompliancesResponse) return &listClusterCompliancesResponse, err } @@ -641,17 +1017,55 @@ type policyFamiliesImpl struct { func (a *policyFamiliesImpl) Get(ctx context.Context, request GetPolicyFamilyRequest) (*PolicyFamily, error) { var policyFamily PolicyFamily path := fmt.Sprintf("/api/2.0/policy-families/%v", request.PolicyFamilyId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &policyFamily) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &policyFamily) return &policyFamily, err } -func (a *policyFamiliesImpl) List(ctx context.Context, request ListPolicyFamiliesRequest) (*ListPolicyFamiliesResponse, error) { +// List policy families. +// +// Returns the list of policy definition types available to use at their latest +// version. This API is paginated. +func (a *policyFamiliesImpl) List(ctx context.Context, request ListPolicyFamiliesRequest) listing.Iterator[PolicyFamily] { + + getNextPage := func(ctx context.Context, req ListPolicyFamiliesRequest) (*ListPolicyFamiliesResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListPolicyFamiliesResponse) []PolicyFamily { + return resp.PolicyFamilies + } + getNextReq := func(resp *ListPolicyFamiliesResponse) *ListPolicyFamiliesRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List policy families. +// +// Returns the list of policy definition types available to use at their latest +// version. This API is paginated. +func (a *policyFamiliesImpl) ListAll(ctx context.Context, request ListPolicyFamiliesRequest) ([]PolicyFamily, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[PolicyFamily](ctx, iterator) +} +func (a *policyFamiliesImpl) internalList(ctx context.Context, request ListPolicyFamiliesRequest) (*ListPolicyFamiliesResponse, error) { var listPolicyFamiliesResponse ListPolicyFamiliesResponse path := "/api/2.0/policy-families" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listPolicyFamiliesResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listPolicyFamiliesResponse) return &listPolicyFamiliesResponse, err } diff --git a/compute/v2/model.go b/compute/v2/model.go index debc3610b..a2cbbb831 100755 --- a/compute/v2/model.go +++ b/compute/v2/model.go @@ -417,11 +417,12 @@ type ClusterAttributes struct { // specified at cluster creation, a set of default values will be used. AzureAttributes *AzureAttributes `json:"azure_attributes,omitempty"` // The configuration for delivering spark logs to a long-term storage - // destination. Two kinds of destinations (dbfs and s3) are supported. Only - // one destination can be specified for one cluster. If the conf is given, - // the logs will be delivered to the destination every `5 mins`. The - // destination of driver logs is `$destination/$clusterId/driver`, while the - // destination of executor logs is `$destination/$clusterId/executor`. + // destination. Three kinds of destinations (DBFS, S3 and Unity Catalog + // volumes) are supported. Only one destination can be specified for one + // cluster. If the conf is given, the logs will be delivered to the + // destination every `5 mins`. The destination of driver logs is + // `$destination/$clusterId/driver`, while the destination of executor logs + // is `$destination/$clusterId/executor`. ClusterLogConf *ClusterLogConf `json:"cluster_log_conf,omitempty"` // Cluster name requested by the user. This doesn't have to be unique. If // not specified at creation, the cluster name will be an empty string. @@ -620,11 +621,12 @@ type ClusterDetails struct { // restarts and resizes, while each new cluster has a globally unique id. ClusterId string `json:"cluster_id,omitempty"` // The configuration for delivering spark logs to a long-term storage - // destination. Two kinds of destinations (dbfs and s3) are supported. Only - // one destination can be specified for one cluster. If the conf is given, - // the logs will be delivered to the destination every `5 mins`. The - // destination of driver logs is `$destination/$clusterId/driver`, while the - // destination of executor logs is `$destination/$clusterId/executor`. + // destination. Three kinds of destinations (DBFS, S3 and Unity Catalog + // volumes) are supported. Only one destination can be specified for one + // cluster. If the conf is given, the logs will be delivered to the + // destination every `5 mins`. The destination of driver logs is + // `$destination/$clusterId/driver`, while the destination of executor logs + // is `$destination/$clusterId/executor`. ClusterLogConf *ClusterLogConf `json:"cluster_log_conf,omitempty"` // Cluster log delivery status. ClusterLogStatus *LogSyncStatus `json:"cluster_log_status,omitempty"` @@ -899,6 +901,9 @@ type ClusterLogConf struct { // the cluster iam role in `instance_profile_arn` has permission to write // data to the s3 destination. S3 *S3StorageInfo `json:"s3,omitempty"` + // destination needs to be provided. e.g. `{ "volumes" : { "destination" : + // "/Volumes/catalog/schema/volume/cluster_log" } }` + Volumes *VolumesStorageInfo `json:"volumes,omitempty"` } type ClusterPermission struct { @@ -1234,11 +1239,12 @@ type ClusterSpec struct { // specified at cluster creation, a set of default values will be used. AzureAttributes *AzureAttributes `json:"azure_attributes,omitempty"` // The configuration for delivering spark logs to a long-term storage - // destination. Two kinds of destinations (dbfs and s3) are supported. Only - // one destination can be specified for one cluster. If the conf is given, - // the logs will be delivered to the destination every `5 mins`. The - // destination of driver logs is `$destination/$clusterId/driver`, while the - // destination of executor logs is `$destination/$clusterId/executor`. + // destination. Three kinds of destinations (DBFS, S3 and Unity Catalog + // volumes) are supported. Only one destination can be specified for one + // cluster. If the conf is given, the logs will be delivered to the + // destination every `5 mins`. The destination of driver logs is + // `$destination/$clusterId/driver`, while the destination of executor logs + // is `$destination/$clusterId/executor`. ClusterLogConf *ClusterLogConf `json:"cluster_log_conf,omitempty"` // Cluster name requested by the user. This doesn't have to be unique. If // not specified at creation, the cluster name will be an empty string. @@ -1566,11 +1572,12 @@ type CreateCluster struct { // creation of a new cluster. CloneFrom *CloneCluster `json:"clone_from,omitempty"` // The configuration for delivering spark logs to a long-term storage - // destination. Two kinds of destinations (dbfs and s3) are supported. Only - // one destination can be specified for one cluster. If the conf is given, - // the logs will be delivered to the destination every `5 mins`. The - // destination of driver logs is `$destination/$clusterId/driver`, while the - // destination of executor logs is `$destination/$clusterId/executor`. + // destination. Three kinds of destinations (DBFS, S3 and Unity Catalog + // volumes) are supported. Only one destination can be specified for one + // cluster. If the conf is given, the logs will be delivered to the + // destination every `5 mins`. The destination of driver logs is + // `$destination/$clusterId/driver`, while the destination of executor logs + // is `$destination/$clusterId/executor`. ClusterLogConf *ClusterLogConf `json:"cluster_log_conf,omitempty"` // Cluster name requested by the user. This doesn't have to be unique. If // not specified at creation, the cluster name will be an empty string. @@ -2312,11 +2319,12 @@ type EditCluster struct { // ID of the cluster ClusterId string `json:"cluster_id"` // The configuration for delivering spark logs to a long-term storage - // destination. Two kinds of destinations (dbfs and s3) are supported. Only - // one destination can be specified for one cluster. If the conf is given, - // the logs will be delivered to the destination every `5 mins`. The - // destination of driver logs is `$destination/$clusterId/driver`, while the - // destination of executor logs is `$destination/$clusterId/executor`. + // destination. Three kinds of destinations (DBFS, S3 and Unity Catalog + // volumes) are supported. Only one destination can be specified for one + // cluster. If the conf is given, the logs will be delivered to the + // destination every `5 mins`. The destination of driver logs is + // `$destination/$clusterId/driver`, while the destination of executor logs + // is `$destination/$clusterId/executor`. ClusterLogConf *ClusterLogConf `json:"cluster_log_conf,omitempty"` // Cluster name requested by the user. This doesn't have to be unique. If // not specified at creation, the cluster name will be an empty string. @@ -5293,11 +5301,12 @@ type UpdateClusterResource struct { // specified at cluster creation, a set of default values will be used. AzureAttributes *AzureAttributes `json:"azure_attributes,omitempty"` // The configuration for delivering spark logs to a long-term storage - // destination. Two kinds of destinations (dbfs and s3) are supported. Only - // one destination can be specified for one cluster. If the conf is given, - // the logs will be delivered to the destination every `5 mins`. The - // destination of driver logs is `$destination/$clusterId/driver`, while the - // destination of executor logs is `$destination/$clusterId/executor`. + // destination. Three kinds of destinations (DBFS, S3 and Unity Catalog + // volumes) are supported. Only one destination can be specified for one + // cluster. If the conf is given, the logs will be delivered to the + // destination every `5 mins`. The destination of driver logs is + // `$destination/$clusterId/driver`, while the destination of executor logs + // is `$destination/$clusterId/executor`. ClusterLogConf *ClusterLogConf `json:"cluster_log_conf,omitempty"` // Cluster name requested by the user. This doesn't have to be unique. If // not specified at creation, the cluster name will be an empty string. @@ -5466,7 +5475,8 @@ type UpdateResponse struct { } type VolumesStorageInfo struct { - // Unity Catalog Volumes file destination, e.g. `/Volumes/my-init.sh` + // Unity Catalog volumes file destination, e.g. + // `/Volumes/catalog/schema/volume/dir/file` Destination string `json:"destination"` } diff --git a/dashboards/go.mod b/dashboards/go.mod index 2ab71029f..449049fe2 100644 --- a/dashboards/go.mod +++ b/dashboards/go.mod @@ -6,6 +6,7 @@ replace github.com/databricks/databricks-sdk-go/databricks => ../databricks require ( github.com/databricks/databricks-sdk-go/databricks v0.0.0-00010101000000-000000000000 + golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 golang.org/x/oauth2 v0.25.0 ) @@ -27,7 +28,6 @@ require ( go.opentelemetry.io/otel/metric v1.24.0 // indirect go.opentelemetry.io/otel/trace v1.24.0 // indirect golang.org/x/crypto v0.31.0 // indirect - golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.33.0 // indirect golang.org/x/sys v0.28.0 // indirect diff --git a/dashboards/v2/api.go b/dashboards/v2/api.go index 9e176ff81..461e13144 100755 --- a/dashboards/v2/api.go +++ b/dashboards/v2/api.go @@ -1,6 +1,6 @@ // Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. -// These APIs allow you to manage Genie, Lakeview, etc. +// These APIs allow you to manage Genie, Lakeview, Lakeview Embedded, Query Execution, etc. package dashboards import ( @@ -8,7 +8,6 @@ import ( "github.com/databricks/databricks-sdk-go/databricks/client" "github.com/databricks/databricks-sdk-go/databricks/listing" - "github.com/databricks/databricks-sdk-go/databricks/useragent" ) type GenieInterface interface { @@ -48,6 +47,18 @@ type GenieInterface interface { // `EXECUTING_QUERY`. GetMessageQueryResultBySpaceIdAndConversationIdAndMessageId(ctx context.Context, spaceId string, conversationId string, messageId string) (*GenieGetMessageQueryResultResponse, error) + // Get conversation message SQL query result by attachment id. + // + // Get the result of SQL query by attachment id This is only available if a + // message has a query attachment and the message status is `EXECUTING_QUERY`. + GetMessageQueryResultByAttachment(ctx context.Context, request GenieGetQueryResultByAttachmentRequest) (*GenieGetMessageQueryResultResponse, error) + + // Get conversation message SQL query result by attachment id. + // + // Get the result of SQL query by attachment id This is only available if a + // message has a query attachment and the message status is `EXECUTING_QUERY`. + GetMessageQueryResultByAttachmentBySpaceIdAndConversationIdAndMessageIdAndAttachmentId(ctx context.Context, spaceId string, conversationId string, messageId string, attachmentId string) (*GenieGetMessageQueryResultResponse, error) + // Start conversation. // // Start a new conversation. @@ -95,6 +106,19 @@ func (a *GenieAPI) GetMessageQueryResultBySpaceIdAndConversationIdAndMessageId(c }) } +// Get conversation message SQL query result by attachment id. +// +// Get the result of SQL query by attachment id This is only available if a +// message has a query attachment and the message status is `EXECUTING_QUERY`. +func (a *GenieAPI) GetMessageQueryResultByAttachmentBySpaceIdAndConversationIdAndMessageIdAndAttachmentId(ctx context.Context, spaceId string, conversationId string, messageId string, attachmentId string) (*GenieGetMessageQueryResultResponse, error) { + return a.genieImpl.GetMessageQueryResultByAttachment(ctx, GenieGetQueryResultByAttachmentRequest{ + SpaceId: spaceId, + ConversationId: conversationId, + MessageId: messageId, + AttachmentId: attachmentId, + }) +} + type LakeviewInterface interface { // Create dashboard. @@ -294,121 +318,16 @@ func (a *LakeviewAPI) GetSubscriptionByDashboardIdAndScheduleIdAndSubscriptionId }) } -// List dashboards. -// -// This method is generated by Databricks SDK Code Generator. -func (a *LakeviewAPI) List(ctx context.Context, request ListDashboardsRequest) listing.Iterator[Dashboard] { - - getNextPage := func(ctx context.Context, req ListDashboardsRequest) (*ListDashboardsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.lakeviewImpl.List(ctx, req) - } - getItems := func(resp *ListDashboardsResponse) []Dashboard { - return resp.Dashboards - } - getNextReq := func(resp *ListDashboardsResponse) *ListDashboardsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List dashboards. -// -// This method is generated by Databricks SDK Code Generator. -func (a *LakeviewAPI) ListAll(ctx context.Context, request ListDashboardsRequest) ([]Dashboard, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[Dashboard](ctx, iterator) -} - -// List dashboard schedules. -// -// This method is generated by Databricks SDK Code Generator. -func (a *LakeviewAPI) ListSchedules(ctx context.Context, request ListSchedulesRequest) listing.Iterator[Schedule] { - - getNextPage := func(ctx context.Context, req ListSchedulesRequest) (*ListSchedulesResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.lakeviewImpl.ListSchedules(ctx, req) - } - getItems := func(resp *ListSchedulesResponse) []Schedule { - return resp.Schedules - } - getNextReq := func(resp *ListSchedulesResponse) *ListSchedulesRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List dashboard schedules. -// -// This method is generated by Databricks SDK Code Generator. -func (a *LakeviewAPI) ListSchedulesAll(ctx context.Context, request ListSchedulesRequest) ([]Schedule, error) { - iterator := a.ListSchedules(ctx, request) - return listing.ToSlice[Schedule](ctx, iterator) -} - // List dashboard schedules. func (a *LakeviewAPI) ListSchedulesByDashboardId(ctx context.Context, dashboardId string) (*ListSchedulesResponse, error) { - return a.lakeviewImpl.ListSchedules(ctx, ListSchedulesRequest{ + return a.lakeviewImpl.internalListSchedules(ctx, ListSchedulesRequest{ DashboardId: dashboardId, }) } -// List schedule subscriptions. -// -// This method is generated by Databricks SDK Code Generator. -func (a *LakeviewAPI) ListSubscriptions(ctx context.Context, request ListSubscriptionsRequest) listing.Iterator[Subscription] { - - getNextPage := func(ctx context.Context, req ListSubscriptionsRequest) (*ListSubscriptionsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.lakeviewImpl.ListSubscriptions(ctx, req) - } - getItems := func(resp *ListSubscriptionsResponse) []Subscription { - return resp.Subscriptions - } - getNextReq := func(resp *ListSubscriptionsResponse) *ListSubscriptionsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List schedule subscriptions. -// -// This method is generated by Databricks SDK Code Generator. -func (a *LakeviewAPI) ListSubscriptionsAll(ctx context.Context, request ListSubscriptionsRequest) ([]Subscription, error) { - iterator := a.ListSubscriptions(ctx, request) - return listing.ToSlice[Subscription](ctx, iterator) -} - // List schedule subscriptions. func (a *LakeviewAPI) ListSubscriptionsByDashboardIdAndScheduleId(ctx context.Context, dashboardId string, scheduleId string) (*ListSubscriptionsResponse, error) { - return a.lakeviewImpl.ListSubscriptions(ctx, ListSubscriptionsRequest{ + return a.lakeviewImpl.internalListSubscriptions(ctx, ListSubscriptionsRequest{ DashboardId: dashboardId, ScheduleId: scheduleId, }) @@ -431,3 +350,63 @@ func (a *LakeviewAPI) UnpublishByDashboardId(ctx context.Context, dashboardId st DashboardId: dashboardId, }) } + +type LakeviewEmbeddedInterface interface { + + // Read a published dashboard in an embedded ui. + // + // Get the current published dashboard within an embedded context. + GetPublishedDashboardEmbedded(ctx context.Context, request GetPublishedDashboardEmbeddedRequest) error + + // Read a published dashboard in an embedded ui. + // + // Get the current published dashboard within an embedded context. + GetPublishedDashboardEmbeddedByDashboardId(ctx context.Context, dashboardId string) error +} + +func NewLakeviewEmbedded(client *client.DatabricksClient) *LakeviewEmbeddedAPI { + return &LakeviewEmbeddedAPI{ + lakeviewEmbeddedImpl: lakeviewEmbeddedImpl{ + client: client, + }, + } +} + +// Token-based Lakeview APIs for embedding dashboards in external applications. +type LakeviewEmbeddedAPI struct { + lakeviewEmbeddedImpl +} + +// Read a published dashboard in an embedded ui. +// +// Get the current published dashboard within an embedded context. +func (a *LakeviewEmbeddedAPI) GetPublishedDashboardEmbeddedByDashboardId(ctx context.Context, dashboardId string) error { + return a.lakeviewEmbeddedImpl.GetPublishedDashboardEmbedded(ctx, GetPublishedDashboardEmbeddedRequest{ + DashboardId: dashboardId, + }) +} + +type QueryExecutionInterface interface { + + // Cancel the results for the a query for a published, embedded dashboard. + CancelPublishedQueryExecution(ctx context.Context, request CancelPublishedQueryExecutionRequest) (*CancelQueryExecutionResponse, error) + + // Execute a query for a published dashboard. + ExecutePublishedDashboardQuery(ctx context.Context, request ExecutePublishedDashboardQueryRequest) error + + // Poll the results for the a query for a published, embedded dashboard. + PollPublishedQueryStatus(ctx context.Context, request PollPublishedQueryStatusRequest) (*PollQueryStatusResponse, error) +} + +func NewQueryExecution(client *client.DatabricksClient) *QueryExecutionAPI { + return &QueryExecutionAPI{ + queryExecutionImpl: queryExecutionImpl{ + client: client, + }, + } +} + +// Query execution APIs for AI / BI Dashboards +type QueryExecutionAPI struct { + queryExecutionImpl +} diff --git a/dashboards/v2/client.go b/dashboards/v2/client.go index 7fc5c0fa3..b272c3baf 100755 --- a/dashboards/v2/client.go +++ b/dashboards/v2/client.go @@ -77,3 +77,71 @@ func NewLakeviewClient(cfg *config.Config) (*LakeviewClient, error) { LakeviewInterface: NewLakeview(databricksClient), }, nil } + +type LakeviewEmbeddedClient struct { + LakeviewEmbeddedInterface + Config *config.Config + apiClient *httpclient.ApiClient +} + +func NewLakeviewEmbeddedClient(cfg *config.Config) (*LakeviewEmbeddedClient, error) { + if cfg == nil { + cfg = &config.Config{} + } + + err := cfg.EnsureResolved() + if err != nil { + return nil, err + } + if cfg.IsAccountClient() { + return nil, errors.New("invalid configuration: please provide a valid workspace config for the requested workspace service client") + } + apiClient, err := cfg.NewApiClient() + if err != nil { + return nil, err + } + databricksClient, err := client.NewWithClient(cfg, apiClient) + if err != nil { + return nil, err + } + + return &LakeviewEmbeddedClient{ + Config: cfg, + apiClient: apiClient, + LakeviewEmbeddedInterface: NewLakeviewEmbedded(databricksClient), + }, nil +} + +type QueryExecutionClient struct { + QueryExecutionInterface + Config *config.Config + apiClient *httpclient.ApiClient +} + +func NewQueryExecutionClient(cfg *config.Config) (*QueryExecutionClient, error) { + if cfg == nil { + cfg = &config.Config{} + } + + err := cfg.EnsureResolved() + if err != nil { + return nil, err + } + if cfg.IsAccountClient() { + return nil, errors.New("invalid configuration: please provide a valid workspace config for the requested workspace service client") + } + apiClient, err := cfg.NewApiClient() + if err != nil { + return nil, err + } + databricksClient, err := client.NewWithClient(cfg, apiClient) + if err != nil { + return nil, err + } + + return &QueryExecutionClient{ + Config: cfg, + apiClient: apiClient, + QueryExecutionInterface: NewQueryExecution(databricksClient), + }, nil +} diff --git a/dashboards/v2/impl.go b/dashboards/v2/impl.go index c95fe2023..e044ab055 100755 --- a/dashboards/v2/impl.go +++ b/dashboards/v2/impl.go @@ -8,6 +8,8 @@ import ( "net/http" "github.com/databricks/databricks-sdk-go/databricks/client" + "github.com/databricks/databricks-sdk-go/databricks/listing" + "github.com/databricks/databricks-sdk-go/databricks/useragent" ) // unexported type that holds implementations of just Genie API methods @@ -18,47 +20,62 @@ type genieImpl struct { func (a *genieImpl) CreateMessage(ctx context.Context, request GenieCreateConversationMessageRequest) (*GenieMessage, error) { var genieMessage GenieMessage path := fmt.Sprintf("/api/2.0/genie/spaces/%v/conversations/%v/messages", request.SpaceId, request.ConversationId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &genieMessage) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &genieMessage) return &genieMessage, err } func (a *genieImpl) ExecuteMessageQuery(ctx context.Context, request GenieExecuteMessageQueryRequest) (*GenieGetMessageQueryResultResponse, error) { var genieGetMessageQueryResultResponse GenieGetMessageQueryResultResponse path := fmt.Sprintf("/api/2.0/genie/spaces/%v/conversations/%v/messages/%v/execute-query", request.SpaceId, request.ConversationId, request.MessageId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, nil, &genieGetMessageQueryResultResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, nil, &genieGetMessageQueryResultResponse) return &genieGetMessageQueryResultResponse, err } func (a *genieImpl) GetMessage(ctx context.Context, request GenieGetConversationMessageRequest) (*GenieMessage, error) { var genieMessage GenieMessage path := fmt.Sprintf("/api/2.0/genie/spaces/%v/conversations/%v/messages/%v", request.SpaceId, request.ConversationId, request.MessageId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &genieMessage) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &genieMessage) return &genieMessage, err } func (a *genieImpl) GetMessageQueryResult(ctx context.Context, request GenieGetMessageQueryResultRequest) (*GenieGetMessageQueryResultResponse, error) { var genieGetMessageQueryResultResponse GenieGetMessageQueryResultResponse path := fmt.Sprintf("/api/2.0/genie/spaces/%v/conversations/%v/messages/%v/query-result", request.SpaceId, request.ConversationId, request.MessageId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &genieGetMessageQueryResultResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &genieGetMessageQueryResultResponse) + return &genieGetMessageQueryResultResponse, err +} + +func (a *genieImpl) GetMessageQueryResultByAttachment(ctx context.Context, request GenieGetQueryResultByAttachmentRequest) (*GenieGetMessageQueryResultResponse, error) { + var genieGetMessageQueryResultResponse GenieGetMessageQueryResultResponse + path := fmt.Sprintf("/api/2.0/genie/spaces/%v/conversations/%v/messages/%v/query-result/%v", request.SpaceId, request.ConversationId, request.MessageId, request.AttachmentId) + queryParams := make(map[string]any) + headers := make(map[string]string) + headers["Accept"] = "application/json" + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &genieGetMessageQueryResultResponse) return &genieGetMessageQueryResultResponse, err } func (a *genieImpl) StartConversation(ctx context.Context, request GenieStartConversationMessageRequest) (*GenieStartConversationResponse, error) { var genieStartConversationResponse GenieStartConversationResponse path := fmt.Sprintf("/api/2.0/genie/spaces/%v/start-conversation", request.SpaceId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &genieStartConversationResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &genieStartConversationResponse) return &genieStartConversationResponse, err } @@ -70,168 +87,327 @@ type lakeviewImpl struct { func (a *lakeviewImpl) Create(ctx context.Context, request CreateDashboardRequest) (*Dashboard, error) { var dashboard Dashboard path := "/api/2.0/lakeview/dashboards" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request.Dashboard, &dashboard) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request.Dashboard, &dashboard) return &dashboard, err } func (a *lakeviewImpl) CreateSchedule(ctx context.Context, request CreateScheduleRequest) (*Schedule, error) { var schedule Schedule path := fmt.Sprintf("/api/2.0/lakeview/dashboards/%v/schedules", request.DashboardId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request.Schedule, &schedule) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request.Schedule, &schedule) return &schedule, err } func (a *lakeviewImpl) CreateSubscription(ctx context.Context, request CreateSubscriptionRequest) (*Subscription, error) { var subscription Subscription path := fmt.Sprintf("/api/2.0/lakeview/dashboards/%v/schedules/%v/subscriptions", request.DashboardId, request.ScheduleId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request.Subscription, &subscription) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request.Subscription, &subscription) return &subscription, err } func (a *lakeviewImpl) DeleteSchedule(ctx context.Context, request DeleteScheduleRequest) error { var deleteScheduleResponse DeleteScheduleResponse path := fmt.Sprintf("/api/2.0/lakeview/dashboards/%v/schedules/%v", request.DashboardId, request.ScheduleId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteScheduleResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteScheduleResponse) return err } func (a *lakeviewImpl) DeleteSubscription(ctx context.Context, request DeleteSubscriptionRequest) error { var deleteSubscriptionResponse DeleteSubscriptionResponse path := fmt.Sprintf("/api/2.0/lakeview/dashboards/%v/schedules/%v/subscriptions/%v", request.DashboardId, request.ScheduleId, request.SubscriptionId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteSubscriptionResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteSubscriptionResponse) return err } func (a *lakeviewImpl) Get(ctx context.Context, request GetDashboardRequest) (*Dashboard, error) { var dashboard Dashboard path := fmt.Sprintf("/api/2.0/lakeview/dashboards/%v", request.DashboardId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &dashboard) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &dashboard) return &dashboard, err } func (a *lakeviewImpl) GetPublished(ctx context.Context, request GetPublishedDashboardRequest) (*PublishedDashboard, error) { var publishedDashboard PublishedDashboard path := fmt.Sprintf("/api/2.0/lakeview/dashboards/%v/published", request.DashboardId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &publishedDashboard) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &publishedDashboard) return &publishedDashboard, err } func (a *lakeviewImpl) GetSchedule(ctx context.Context, request GetScheduleRequest) (*Schedule, error) { var schedule Schedule path := fmt.Sprintf("/api/2.0/lakeview/dashboards/%v/schedules/%v", request.DashboardId, request.ScheduleId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &schedule) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &schedule) return &schedule, err } func (a *lakeviewImpl) GetSubscription(ctx context.Context, request GetSubscriptionRequest) (*Subscription, error) { var subscription Subscription path := fmt.Sprintf("/api/2.0/lakeview/dashboards/%v/schedules/%v/subscriptions/%v", request.DashboardId, request.ScheduleId, request.SubscriptionId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &subscription) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &subscription) return &subscription, err } -func (a *lakeviewImpl) List(ctx context.Context, request ListDashboardsRequest) (*ListDashboardsResponse, error) { +// List dashboards. +func (a *lakeviewImpl) List(ctx context.Context, request ListDashboardsRequest) listing.Iterator[Dashboard] { + + getNextPage := func(ctx context.Context, req ListDashboardsRequest) (*ListDashboardsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListDashboardsResponse) []Dashboard { + return resp.Dashboards + } + getNextReq := func(resp *ListDashboardsResponse) *ListDashboardsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List dashboards. +func (a *lakeviewImpl) ListAll(ctx context.Context, request ListDashboardsRequest) ([]Dashboard, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[Dashboard](ctx, iterator) +} +func (a *lakeviewImpl) internalList(ctx context.Context, request ListDashboardsRequest) (*ListDashboardsResponse, error) { var listDashboardsResponse ListDashboardsResponse path := "/api/2.0/lakeview/dashboards" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listDashboardsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listDashboardsResponse) return &listDashboardsResponse, err } -func (a *lakeviewImpl) ListSchedules(ctx context.Context, request ListSchedulesRequest) (*ListSchedulesResponse, error) { +// List dashboard schedules. +func (a *lakeviewImpl) ListSchedules(ctx context.Context, request ListSchedulesRequest) listing.Iterator[Schedule] { + + getNextPage := func(ctx context.Context, req ListSchedulesRequest) (*ListSchedulesResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalListSchedules(ctx, req) + } + getItems := func(resp *ListSchedulesResponse) []Schedule { + return resp.Schedules + } + getNextReq := func(resp *ListSchedulesResponse) *ListSchedulesRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List dashboard schedules. +func (a *lakeviewImpl) ListSchedulesAll(ctx context.Context, request ListSchedulesRequest) ([]Schedule, error) { + iterator := a.ListSchedules(ctx, request) + return listing.ToSlice[Schedule](ctx, iterator) +} +func (a *lakeviewImpl) internalListSchedules(ctx context.Context, request ListSchedulesRequest) (*ListSchedulesResponse, error) { var listSchedulesResponse ListSchedulesResponse path := fmt.Sprintf("/api/2.0/lakeview/dashboards/%v/schedules", request.DashboardId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listSchedulesResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listSchedulesResponse) return &listSchedulesResponse, err } -func (a *lakeviewImpl) ListSubscriptions(ctx context.Context, request ListSubscriptionsRequest) (*ListSubscriptionsResponse, error) { +// List schedule subscriptions. +func (a *lakeviewImpl) ListSubscriptions(ctx context.Context, request ListSubscriptionsRequest) listing.Iterator[Subscription] { + + getNextPage := func(ctx context.Context, req ListSubscriptionsRequest) (*ListSubscriptionsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalListSubscriptions(ctx, req) + } + getItems := func(resp *ListSubscriptionsResponse) []Subscription { + return resp.Subscriptions + } + getNextReq := func(resp *ListSubscriptionsResponse) *ListSubscriptionsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List schedule subscriptions. +func (a *lakeviewImpl) ListSubscriptionsAll(ctx context.Context, request ListSubscriptionsRequest) ([]Subscription, error) { + iterator := a.ListSubscriptions(ctx, request) + return listing.ToSlice[Subscription](ctx, iterator) +} +func (a *lakeviewImpl) internalListSubscriptions(ctx context.Context, request ListSubscriptionsRequest) (*ListSubscriptionsResponse, error) { var listSubscriptionsResponse ListSubscriptionsResponse path := fmt.Sprintf("/api/2.0/lakeview/dashboards/%v/schedules/%v/subscriptions", request.DashboardId, request.ScheduleId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listSubscriptionsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listSubscriptionsResponse) return &listSubscriptionsResponse, err } func (a *lakeviewImpl) Migrate(ctx context.Context, request MigrateDashboardRequest) (*Dashboard, error) { var dashboard Dashboard path := "/api/2.0/lakeview/dashboards/migrate" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &dashboard) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &dashboard) return &dashboard, err } func (a *lakeviewImpl) Publish(ctx context.Context, request PublishRequest) (*PublishedDashboard, error) { var publishedDashboard PublishedDashboard path := fmt.Sprintf("/api/2.0/lakeview/dashboards/%v/published", request.DashboardId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &publishedDashboard) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &publishedDashboard) return &publishedDashboard, err } func (a *lakeviewImpl) Trash(ctx context.Context, request TrashDashboardRequest) error { var trashDashboardResponse TrashDashboardResponse path := fmt.Sprintf("/api/2.0/lakeview/dashboards/%v", request.DashboardId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &trashDashboardResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &trashDashboardResponse) return err } func (a *lakeviewImpl) Unpublish(ctx context.Context, request UnpublishDashboardRequest) error { var unpublishDashboardResponse UnpublishDashboardResponse path := fmt.Sprintf("/api/2.0/lakeview/dashboards/%v/published", request.DashboardId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &unpublishDashboardResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &unpublishDashboardResponse) return err } func (a *lakeviewImpl) Update(ctx context.Context, request UpdateDashboardRequest) (*Dashboard, error) { var dashboard Dashboard path := fmt.Sprintf("/api/2.0/lakeview/dashboards/%v", request.DashboardId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request.Dashboard, &dashboard) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request.Dashboard, &dashboard) return &dashboard, err } func (a *lakeviewImpl) UpdateSchedule(ctx context.Context, request UpdateScheduleRequest) (*Schedule, error) { var schedule Schedule path := fmt.Sprintf("/api/2.0/lakeview/dashboards/%v/schedules/%v", request.DashboardId, request.ScheduleId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request.Schedule, &schedule) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request.Schedule, &schedule) return &schedule, err } + +// unexported type that holds implementations of just LakeviewEmbedded API methods +type lakeviewEmbeddedImpl struct { + client *client.DatabricksClient +} + +func (a *lakeviewEmbeddedImpl) GetPublishedDashboardEmbedded(ctx context.Context, request GetPublishedDashboardEmbeddedRequest) error { + var getPublishedDashboardEmbeddedResponse GetPublishedDashboardEmbeddedResponse + path := fmt.Sprintf("/api/2.0/lakeview/dashboards/%v/published/embedded", request.DashboardId) + queryParams := make(map[string]any) + headers := make(map[string]string) + headers["Accept"] = "application/json" + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getPublishedDashboardEmbeddedResponse) + return err +} + +// unexported type that holds implementations of just QueryExecution API methods +type queryExecutionImpl struct { + client *client.DatabricksClient +} + +func (a *queryExecutionImpl) CancelPublishedQueryExecution(ctx context.Context, request CancelPublishedQueryExecutionRequest) (*CancelQueryExecutionResponse, error) { + var cancelQueryExecutionResponse CancelQueryExecutionResponse + path := "/api/2.0/lakeview-query/query/published" + queryParams := make(map[string]any) + headers := make(map[string]string) + headers["Accept"] = "application/json" + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &cancelQueryExecutionResponse) + return &cancelQueryExecutionResponse, err +} + +func (a *queryExecutionImpl) ExecutePublishedDashboardQuery(ctx context.Context, request ExecutePublishedDashboardQueryRequest) error { + var executeQueryResponse ExecuteQueryResponse + path := "/api/2.0/lakeview-query/query/published" + queryParams := make(map[string]any) + headers := make(map[string]string) + headers["Accept"] = "application/json" + headers["Content-Type"] = "application/json" + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &executeQueryResponse) + return err +} + +func (a *queryExecutionImpl) PollPublishedQueryStatus(ctx context.Context, request PollPublishedQueryStatusRequest) (*PollQueryStatusResponse, error) { + var pollQueryStatusResponse PollQueryStatusResponse + path := "/api/2.0/lakeview-query/query/published" + queryParams := make(map[string]any) + headers := make(map[string]string) + headers["Accept"] = "application/json" + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &pollQueryStatusResponse) + return &pollQueryStatusResponse, err +} diff --git a/dashboards/v2/model.go b/dashboards/v2/model.go index 7f6213b0a..ecca2ecde 100755 --- a/dashboards/v2/model.go +++ b/dashboards/v2/model.go @@ -33,6 +33,32 @@ func (s BaseChunkInfo) MarshalJSON() ([]byte, error) { return marshal.Marshal(s) } +// Cancel the results for the a query for a published, embedded dashboard +type CancelPublishedQueryExecutionRequest struct { + DashboardName string `json:"-" url:"dashboard_name"` + + DashboardRevisionId string `json:"-" url:"dashboard_revision_id"` + // Example: + // EC0A..ChAB7WCEn_4Qo4vkLqEbXsxxEgh3Y2pbWw45WhoQXgZSQo9aS5q2ZvFcbvbx9CgA-PAEAQ + Tokens []string `json:"-" url:"tokens,omitempty"` +} + +type CancelQueryExecutionResponse struct { + Status []CancelQueryExecutionResponseStatus `json:"status,omitempty"` +} + +type CancelQueryExecutionResponseStatus struct { + // The token to poll for result asynchronously Example: + // EC0A..ChAB7WCEn_4Qo4vkLqEbXsxxEgh3Y2pbWw45WhoQXgZSQo9aS5q2ZvFcbvbx9CgA-PAEAQ + DataToken string `json:"data_token"` + // Represents an empty message, similar to google.protobuf.Empty, which is + // not available in the firm right now. + Pending *Empty `json:"pending,omitempty"` + // Represents an empty message, similar to google.protobuf.Empty, which is + // not available in the firm right now. + Success *Empty `json:"success,omitempty"` +} + type ColumnInfo struct { // The name of the column. Name string `json:"name,omitempty"` @@ -340,6 +366,40 @@ func (s DeleteSubscriptionRequest) MarshalJSON() ([]byte, error) { type DeleteSubscriptionResponse struct { } +// Represents an empty message, similar to google.protobuf.Empty, which is not +// available in the firm right now. +type Empty struct { +} + +// Execute query request for published Dashboards. Since published dashboards +// have the option of running as the publisher, the datasets, warehouse_id are +// excluded from the request and instead read from the source (lakeview-config) +// via the additional parameters (dashboardName and dashboardRevisionId) +type ExecutePublishedDashboardQueryRequest struct { + // Dashboard name and revision_id is required to retrieve + // PublishedDatasetDataModel which contains the list of datasets, + // warehouse_id, and embedded_credentials + DashboardName string `json:"dashboard_name"` + + DashboardRevisionId string `json:"dashboard_revision_id"` + // A dashboard schedule can override the warehouse used as compute for + // processing the published dashboard queries + OverrideWarehouseId string `json:"override_warehouse_id,omitempty"` + + ForceSendFields []string `json:"-"` +} + +func (s *ExecutePublishedDashboardQueryRequest) UnmarshalJSON(b []byte) error { + return marshal.Unmarshal(b, s) +} + +func (s ExecutePublishedDashboardQueryRequest) MarshalJSON() ([]byte, error) { + return marshal.Marshal(s) +} + +type ExecuteQueryResponse struct { +} + type ExternalLink struct { // The number of bytes in the result chunk. This field is not available when // using `INLINE` disposition. @@ -491,6 +551,18 @@ type GenieGetMessageQueryResultResponse struct { StatementResponse *StatementResponse `json:"statement_response,omitempty"` } +// Get conversation message SQL query result by attachment id +type GenieGetQueryResultByAttachmentRequest struct { + // Attachment ID + AttachmentId string `json:"-" url:"-"` + // Conversation ID + ConversationId string `json:"-" url:"-"` + // Message ID + MessageId string `json:"-" url:"-"` + // Genie space ID + SpaceId string `json:"-" url:"-"` +} + type GenieMessage struct { // AI produced response to the message Attachments []GenieAttachment `json:"attachments,omitempty"` @@ -567,6 +639,15 @@ type GetDashboardRequest struct { DashboardId string `json:"-" url:"-"` } +// Read a published dashboard in an embedded ui. +type GetPublishedDashboardEmbeddedRequest struct { + // UUID identifying the published dashboard. + DashboardId string `json:"-" url:"-"` +} + +type GetPublishedDashboardEmbeddedResponse struct { +} + // Get published dashboard type GetPublishedDashboardRequest struct { // UUID identifying the published dashboard. @@ -825,6 +906,8 @@ const MessageErrorTypeRetryableProcessingException MessageErrorType = `RETRYABLE const MessageErrorTypeSqlExecutionException MessageErrorType = `SQL_EXECUTION_EXCEPTION` +const MessageErrorTypeStopProcessDueToAutoRegenerate MessageErrorType = `STOP_PROCESS_DUE_TO_AUTO_REGENERATE` + const MessageErrorTypeTablesMissingException MessageErrorType = `TABLES_MISSING_EXCEPTION` const MessageErrorTypeTooManyCertifiedAnswersException MessageErrorType = `TOO_MANY_CERTIFIED_ANSWERS_EXCEPTION` @@ -847,11 +930,11 @@ func (f *MessageErrorType) String() string { // Set raw string value and validate it against allowed values func (f *MessageErrorType) Set(v string) error { switch v { - case `BLOCK_MULTIPLE_EXECUTIONS_EXCEPTION`, `CHAT_COMPLETION_CLIENT_EXCEPTION`, `CHAT_COMPLETION_CLIENT_TIMEOUT_EXCEPTION`, `CHAT_COMPLETION_NETWORK_EXCEPTION`, `CONTENT_FILTER_EXCEPTION`, `CONTEXT_EXCEEDED_EXCEPTION`, `COULD_NOT_GET_UC_SCHEMA_EXCEPTION`, `DEPLOYMENT_NOT_FOUND_EXCEPTION`, `FUNCTIONS_NOT_AVAILABLE_EXCEPTION`, `FUNCTION_ARGUMENTS_INVALID_EXCEPTION`, `FUNCTION_ARGUMENTS_INVALID_JSON_EXCEPTION`, `FUNCTION_CALL_MISSING_PARAMETER_EXCEPTION`, `GENERIC_CHAT_COMPLETION_EXCEPTION`, `GENERIC_CHAT_COMPLETION_SERVICE_EXCEPTION`, `GENERIC_SQL_EXEC_API_CALL_EXCEPTION`, `ILLEGAL_PARAMETER_DEFINITION_EXCEPTION`, `INVALID_CERTIFIED_ANSWER_FUNCTION_EXCEPTION`, `INVALID_CERTIFIED_ANSWER_IDENTIFIER_EXCEPTION`, `INVALID_CHAT_COMPLETION_JSON_EXCEPTION`, `INVALID_COMPLETION_REQUEST_EXCEPTION`, `INVALID_FUNCTION_CALL_EXCEPTION`, `INVALID_TABLE_IDENTIFIER_EXCEPTION`, `LOCAL_CONTEXT_EXCEEDED_EXCEPTION`, `MESSAGE_DELETED_WHILE_EXECUTING_EXCEPTION`, `MESSAGE_UPDATED_WHILE_EXECUTING_EXCEPTION`, `NO_DEPLOYMENTS_AVAILABLE_TO_WORKSPACE`, `NO_QUERY_TO_VISUALIZE_EXCEPTION`, `NO_TABLES_TO_QUERY_EXCEPTION`, `RATE_LIMIT_EXCEEDED_GENERIC_EXCEPTION`, `RATE_LIMIT_EXCEEDED_SPECIFIED_WAIT_EXCEPTION`, `REPLY_PROCESS_TIMEOUT_EXCEPTION`, `RETRYABLE_PROCESSING_EXCEPTION`, `SQL_EXECUTION_EXCEPTION`, `TABLES_MISSING_EXCEPTION`, `TOO_MANY_CERTIFIED_ANSWERS_EXCEPTION`, `TOO_MANY_TABLES_EXCEPTION`, `UNEXPECTED_REPLY_PROCESS_EXCEPTION`, `UNKNOWN_AI_MODEL`, `WAREHOUSE_ACCESS_MISSING_EXCEPTION`, `WAREHOUSE_NOT_FOUND_EXCEPTION`: + case `BLOCK_MULTIPLE_EXECUTIONS_EXCEPTION`, `CHAT_COMPLETION_CLIENT_EXCEPTION`, `CHAT_COMPLETION_CLIENT_TIMEOUT_EXCEPTION`, `CHAT_COMPLETION_NETWORK_EXCEPTION`, `CONTENT_FILTER_EXCEPTION`, `CONTEXT_EXCEEDED_EXCEPTION`, `COULD_NOT_GET_UC_SCHEMA_EXCEPTION`, `DEPLOYMENT_NOT_FOUND_EXCEPTION`, `FUNCTIONS_NOT_AVAILABLE_EXCEPTION`, `FUNCTION_ARGUMENTS_INVALID_EXCEPTION`, `FUNCTION_ARGUMENTS_INVALID_JSON_EXCEPTION`, `FUNCTION_CALL_MISSING_PARAMETER_EXCEPTION`, `GENERIC_CHAT_COMPLETION_EXCEPTION`, `GENERIC_CHAT_COMPLETION_SERVICE_EXCEPTION`, `GENERIC_SQL_EXEC_API_CALL_EXCEPTION`, `ILLEGAL_PARAMETER_DEFINITION_EXCEPTION`, `INVALID_CERTIFIED_ANSWER_FUNCTION_EXCEPTION`, `INVALID_CERTIFIED_ANSWER_IDENTIFIER_EXCEPTION`, `INVALID_CHAT_COMPLETION_JSON_EXCEPTION`, `INVALID_COMPLETION_REQUEST_EXCEPTION`, `INVALID_FUNCTION_CALL_EXCEPTION`, `INVALID_TABLE_IDENTIFIER_EXCEPTION`, `LOCAL_CONTEXT_EXCEEDED_EXCEPTION`, `MESSAGE_DELETED_WHILE_EXECUTING_EXCEPTION`, `MESSAGE_UPDATED_WHILE_EXECUTING_EXCEPTION`, `NO_DEPLOYMENTS_AVAILABLE_TO_WORKSPACE`, `NO_QUERY_TO_VISUALIZE_EXCEPTION`, `NO_TABLES_TO_QUERY_EXCEPTION`, `RATE_LIMIT_EXCEEDED_GENERIC_EXCEPTION`, `RATE_LIMIT_EXCEEDED_SPECIFIED_WAIT_EXCEPTION`, `REPLY_PROCESS_TIMEOUT_EXCEPTION`, `RETRYABLE_PROCESSING_EXCEPTION`, `SQL_EXECUTION_EXCEPTION`, `STOP_PROCESS_DUE_TO_AUTO_REGENERATE`, `TABLES_MISSING_EXCEPTION`, `TOO_MANY_CERTIFIED_ANSWERS_EXCEPTION`, `TOO_MANY_TABLES_EXCEPTION`, `UNEXPECTED_REPLY_PROCESS_EXCEPTION`, `UNKNOWN_AI_MODEL`, `WAREHOUSE_ACCESS_MISSING_EXCEPTION`, `WAREHOUSE_NOT_FOUND_EXCEPTION`: *f = MessageErrorType(v) return nil default: - return fmt.Errorf(`value "%s" is not one of "BLOCK_MULTIPLE_EXECUTIONS_EXCEPTION", "CHAT_COMPLETION_CLIENT_EXCEPTION", "CHAT_COMPLETION_CLIENT_TIMEOUT_EXCEPTION", "CHAT_COMPLETION_NETWORK_EXCEPTION", "CONTENT_FILTER_EXCEPTION", "CONTEXT_EXCEEDED_EXCEPTION", "COULD_NOT_GET_UC_SCHEMA_EXCEPTION", "DEPLOYMENT_NOT_FOUND_EXCEPTION", "FUNCTIONS_NOT_AVAILABLE_EXCEPTION", "FUNCTION_ARGUMENTS_INVALID_EXCEPTION", "FUNCTION_ARGUMENTS_INVALID_JSON_EXCEPTION", "FUNCTION_CALL_MISSING_PARAMETER_EXCEPTION", "GENERIC_CHAT_COMPLETION_EXCEPTION", "GENERIC_CHAT_COMPLETION_SERVICE_EXCEPTION", "GENERIC_SQL_EXEC_API_CALL_EXCEPTION", "ILLEGAL_PARAMETER_DEFINITION_EXCEPTION", "INVALID_CERTIFIED_ANSWER_FUNCTION_EXCEPTION", "INVALID_CERTIFIED_ANSWER_IDENTIFIER_EXCEPTION", "INVALID_CHAT_COMPLETION_JSON_EXCEPTION", "INVALID_COMPLETION_REQUEST_EXCEPTION", "INVALID_FUNCTION_CALL_EXCEPTION", "INVALID_TABLE_IDENTIFIER_EXCEPTION", "LOCAL_CONTEXT_EXCEEDED_EXCEPTION", "MESSAGE_DELETED_WHILE_EXECUTING_EXCEPTION", "MESSAGE_UPDATED_WHILE_EXECUTING_EXCEPTION", "NO_DEPLOYMENTS_AVAILABLE_TO_WORKSPACE", "NO_QUERY_TO_VISUALIZE_EXCEPTION", "NO_TABLES_TO_QUERY_EXCEPTION", "RATE_LIMIT_EXCEEDED_GENERIC_EXCEPTION", "RATE_LIMIT_EXCEEDED_SPECIFIED_WAIT_EXCEPTION", "REPLY_PROCESS_TIMEOUT_EXCEPTION", "RETRYABLE_PROCESSING_EXCEPTION", "SQL_EXECUTION_EXCEPTION", "TABLES_MISSING_EXCEPTION", "TOO_MANY_CERTIFIED_ANSWERS_EXCEPTION", "TOO_MANY_TABLES_EXCEPTION", "UNEXPECTED_REPLY_PROCESS_EXCEPTION", "UNKNOWN_AI_MODEL", "WAREHOUSE_ACCESS_MISSING_EXCEPTION", "WAREHOUSE_NOT_FOUND_EXCEPTION"`, v) + return fmt.Errorf(`value "%s" is not one of "BLOCK_MULTIPLE_EXECUTIONS_EXCEPTION", "CHAT_COMPLETION_CLIENT_EXCEPTION", "CHAT_COMPLETION_CLIENT_TIMEOUT_EXCEPTION", "CHAT_COMPLETION_NETWORK_EXCEPTION", "CONTENT_FILTER_EXCEPTION", "CONTEXT_EXCEEDED_EXCEPTION", "COULD_NOT_GET_UC_SCHEMA_EXCEPTION", "DEPLOYMENT_NOT_FOUND_EXCEPTION", "FUNCTIONS_NOT_AVAILABLE_EXCEPTION", "FUNCTION_ARGUMENTS_INVALID_EXCEPTION", "FUNCTION_ARGUMENTS_INVALID_JSON_EXCEPTION", "FUNCTION_CALL_MISSING_PARAMETER_EXCEPTION", "GENERIC_CHAT_COMPLETION_EXCEPTION", "GENERIC_CHAT_COMPLETION_SERVICE_EXCEPTION", "GENERIC_SQL_EXEC_API_CALL_EXCEPTION", "ILLEGAL_PARAMETER_DEFINITION_EXCEPTION", "INVALID_CERTIFIED_ANSWER_FUNCTION_EXCEPTION", "INVALID_CERTIFIED_ANSWER_IDENTIFIER_EXCEPTION", "INVALID_CHAT_COMPLETION_JSON_EXCEPTION", "INVALID_COMPLETION_REQUEST_EXCEPTION", "INVALID_FUNCTION_CALL_EXCEPTION", "INVALID_TABLE_IDENTIFIER_EXCEPTION", "LOCAL_CONTEXT_EXCEEDED_EXCEPTION", "MESSAGE_DELETED_WHILE_EXECUTING_EXCEPTION", "MESSAGE_UPDATED_WHILE_EXECUTING_EXCEPTION", "NO_DEPLOYMENTS_AVAILABLE_TO_WORKSPACE", "NO_QUERY_TO_VISUALIZE_EXCEPTION", "NO_TABLES_TO_QUERY_EXCEPTION", "RATE_LIMIT_EXCEEDED_GENERIC_EXCEPTION", "RATE_LIMIT_EXCEEDED_SPECIFIED_WAIT_EXCEPTION", "REPLY_PROCESS_TIMEOUT_EXCEPTION", "RETRYABLE_PROCESSING_EXCEPTION", "SQL_EXECUTION_EXCEPTION", "STOP_PROCESS_DUE_TO_AUTO_REGENERATE", "TABLES_MISSING_EXCEPTION", "TOO_MANY_CERTIFIED_ANSWERS_EXCEPTION", "TOO_MANY_TABLES_EXCEPTION", "UNEXPECTED_REPLY_PROCESS_EXCEPTION", "UNKNOWN_AI_MODEL", "WAREHOUSE_ACCESS_MISSING_EXCEPTION", "WAREHOUSE_NOT_FOUND_EXCEPTION"`, v) } } @@ -960,6 +1043,30 @@ func (s MigrateDashboardRequest) MarshalJSON() ([]byte, error) { return marshal.Marshal(s) } +type PendingStatus struct { + // The token to poll for result asynchronously Example: + // EC0A..ChAB7WCEn_4Qo4vkLqEbXsxxEgh3Y2pbWw45WhoQXgZSQo9aS5q2ZvFcbvbx9CgA-PAEAQ + DataToken string `json:"data_token"` +} + +// Poll the results for the a query for a published, embedded dashboard +type PollPublishedQueryStatusRequest struct { + DashboardName string `json:"-" url:"dashboard_name"` + + DashboardRevisionId string `json:"-" url:"dashboard_revision_id"` + // Example: + // EC0A..ChAB7WCEn_4Qo4vkLqEbXsxxEgh3Y2pbWw45WhoQXgZSQo9aS5q2ZvFcbvbx9CgA-PAEAQ + Tokens []string `json:"-" url:"tokens,omitempty"` +} + +type PollQueryStatusResponse struct { + Data []PollQueryStatusResponseData `json:"data,omitempty"` +} + +type PollQueryStatusResponseData struct { + Status QueryResponseStatus `json:"status"` +} + type PublishRequest struct { // UUID identifying the dashboard to be published. DashboardId string `json:"-" url:"-"` @@ -1035,6 +1142,34 @@ func (s QueryAttachment) MarshalJSON() ([]byte, error) { return marshal.Marshal(s) } +type QueryResponseStatus struct { + // Represents an empty message, similar to google.protobuf.Empty, which is + // not available in the firm right now. + Canceled *Empty `json:"canceled,omitempty"` + // Represents an empty message, similar to google.protobuf.Empty, which is + // not available in the firm right now. + Closed *Empty `json:"closed,omitempty"` + + Pending *PendingStatus `json:"pending,omitempty"` + // The statement id in format(01eef5da-c56e-1f36-bafa-21906587d6ba) The + // statement_id should be identical to data_token in SuccessStatus and + // PendingStatus. This field is created for audit logging purpose to record + // the statement_id of all QueryResponseStatus. + StatementId string `json:"statement_id,omitempty"` + + Success *SuccessStatus `json:"success,omitempty"` + + ForceSendFields []string `json:"-"` +} + +func (s *QueryResponseStatus) UnmarshalJSON(b []byte) error { + return marshal.Unmarshal(b, s) +} + +func (s QueryResponseStatus) MarshalJSON() ([]byte, error) { + return marshal.Marshal(s) +} + type QuerySchema struct { Columns []QuerySchemaColumn `json:"columns,omitempty"` // Used to determine if the stored query schema is compatible with the @@ -1435,6 +1570,24 @@ type SubscriptionSubscriberUser struct { UserId int64 `json:"user_id"` } +type SuccessStatus struct { + // The token to poll for result asynchronously Example: + // EC0A..ChAB7WCEn_4Qo4vkLqEbXsxxEgh3Y2pbWw45WhoQXgZSQo9aS5q2ZvFcbvbx9CgA-PAEAQ + DataToken string `json:"data_token"` + // Whether the query result is truncated (either by byte limit or row limit) + Truncated bool `json:"truncated,omitempty"` + + ForceSendFields []string `json:"-"` +} + +func (s *SuccessStatus) UnmarshalJSON(b []byte) error { + return marshal.Unmarshal(b, s) +} + +func (s SuccessStatus) MarshalJSON() ([]byte, error) { + return marshal.Marshal(s) +} + type TextAttachment struct { // AI generated message Content string `json:"content,omitempty"` diff --git a/databricks/client/client.go b/databricks/client/client.go index b9f22bba1..a1ee184ce 100644 --- a/databricks/client/client.go +++ b/databricks/client/client.go @@ -63,12 +63,13 @@ func (c *DatabricksClient) GetOAuthToken(ctx context.Context, authDetails string // Do sends an HTTP request against path. func (c *DatabricksClient) Do(ctx context.Context, method, path string, - headers map[string]string, request, response any, + headers map[string]string, queryParams map[string]any, request, response any, visitors ...func(*http.Request) error) error { opts := []httpclient.DoOption{} for _, v := range visitors { opts = append(opts, httpclient.WithRequestVisitor(v)) } + opts = append(opts, httpclient.WithQueryParameters(queryParams)) opts = append(opts, httpclient.WithRequestHeaders(headers)) opts = append(opts, httpclient.WithRequestData(request)) opts = append(opts, httpclient.WithResponseUnmarshal(response)) diff --git a/databricks/client/client_test.go b/databricks/client/client_test.go index c5d002d6c..bf344a01e 100644 --- a/databricks/client/client_test.go +++ b/databricks/client/client_test.go @@ -43,11 +43,15 @@ func TestSimpleRequestFailsURLError(t *testing.T) { }), }) require.NoError(t, err) - err = c.Do(context.Background(), "GET", "/a/b", map[string]string{ - "e": "f", - }, map[string]string{ - "c": "d", - }, nil) + err = c.Do( + context.Background(), + "GET", + "/a/b", + map[string]string{"e": "f"}, + nil, + map[string]string{"c": "d"}, + nil, + ) require.EqualError(t, err, `Get "https://some/a/b?c=d": nope`) } @@ -66,11 +70,15 @@ func TestSimpleRequestFailsAPIError(t *testing.T) { }), }) require.NoError(t, err) - err = c.Do(context.Background(), "GET", "/a/b", map[string]string{ - "e": "f", - }, map[string]string{ - "c": "d", - }, nil) + err = c.Do( + context.Background(), + "GET", + "/a/b", + map[string]string{"e": "f"}, + nil, + map[string]string{"c": "d"}, + nil, + ) require.EqualError(t, err, "nope") require.ErrorIs(t, err, apierr.ErrInvalidParameterValue) } @@ -115,11 +123,15 @@ func TestETag(t *testing.T) { }), }) require.NoError(t, err) - err = c.Do(context.Background(), "GET", "/a/b", map[string]string{ - "e": "f", - }, map[string]string{ - "c": "d", - }, nil) + err = c.Do( + context.Background(), + "GET", + "/a/b", + map[string]string{"e": "f"}, + nil, + map[string]string{"c": "d"}, + nil, + ) details := apierr.GetErrorInfo(err) require.Equal(t, 1, len(details)) errorDetails := details[0] @@ -148,7 +160,52 @@ func TestSimpleRequestSucceeds(t *testing.T) { }) require.NoError(t, err) var resp Dummy - err = c.Do(context.Background(), "POST", "/c", nil, Dummy{1}, &resp) + err = c.Do( + context.Background(), + "POST", + "/c", + nil, + nil, + Dummy{1}, + &resp, + ) + require.NoError(t, err) + require.Equal(t, 2, resp.Foo) +} + +func TestQueryParamsRequestSucceeds(t *testing.T) { + type Dummy struct { + Foo int `json:"foo"` + } + c, err := New(&config.Config{ + Host: "some", + Token: "token", + ConfigFile: "/dev/null", + HTTPTransport: hc(func(r *http.Request) (*http.Response, error) { + if r.URL.RawQuery != "a=b&c=1" { + return nil, fmt.Errorf("unexpected query params: %s", r.URL.RawQuery) + } + return &http.Response{ + StatusCode: 200, + Body: io.NopCloser(strings.NewReader(`{"foo": 2}`)), + Request: r, + }, nil + }), + }) + require.NoError(t, err) + var resp Dummy + err = c.Do( + context.Background(), + "POST", + "/c", + nil, + map[string]any{ + "a": "b", + "c": 1, + }, + Dummy{1}, + &resp, + ) require.NoError(t, err) require.Equal(t, 2, resp.Foo) } @@ -180,7 +237,15 @@ func TestSimpleRequestRetried(t *testing.T) { }) require.NoError(t, err) var resp Dummy - err = c.Do(context.Background(), "PATCH", "/a", nil, Dummy{1}, &resp) + err = c.Do( + context.Background(), + "PATCH", + "/a", + nil, + nil, + Dummy{1}, + &resp, + ) require.NoError(t, err) require.Equal(t, 2, resp.Foo) require.True(t, retried[0], "request was not retried") @@ -203,7 +268,15 @@ func TestSimpleRequestAPIError(t *testing.T) { }), }) require.NoError(t, err) - err = c.Do(context.Background(), "PATCH", "/a", nil, map[string]any{}, nil) + err = c.Do( + context.Background(), + "PATCH", + "/a", + nil, + nil, + map[string]any{}, + nil, + ) var aerr *apierr.APIError require.ErrorAs(t, err, &aerr) require.Equal(t, "NOT_FOUND", aerr.ErrorCode) @@ -223,7 +296,15 @@ func TestHttpTransport(t *testing.T) { client, err := New(cfg) require.NoError(t, err) - err = client.Do(context.Background(), "GET", "/a", nil, nil, bytes.Buffer{}) + err = client.Do( + context.Background(), + "GET", + "/a", + nil, + nil, + nil, + bytes.Buffer{}, + ) require.NoError(t, err) require.True(t, calledMock) } @@ -249,9 +330,25 @@ func TestDoRemovesDoubleSlashesFromFilesAPI(t *testing.T) { }), }) require.NoError(t, err) - err = c.Do(context.Background(), "GET", "/api/2.0/fs/files//Volumes/abc/def/ghi", nil, map[string]any{}, nil) + err = c.Do( + context.Background(), + "GET", + "/api/2.0/fs/files//Volumes/abc/def/ghi", + nil, + nil, + map[string]any{}, + nil, + ) require.NoError(t, err) - err = c.Do(context.Background(), "GET", "/api/2.0/anotherservice//test", nil, map[string]any{}, nil) + err = c.Do( + context.Background(), + "GET", + "/api/2.0/anotherservice//test", + nil, + nil, + map[string]any{}, + nil, + ) require.NoError(t, err) } @@ -340,7 +437,15 @@ func captureUserAgent(t *testing.T) string { }) require.NoError(t, err) - err = c.Do(context.Background(), "GET", "/a", nil, nil, nil) + err = c.Do( + context.Background(), + "GET", + "/a", + nil, + nil, + nil, + nil, + ) require.NoError(t, err) return userAgent @@ -450,7 +555,15 @@ func testNonJSONResponseIncludedInError(t *testing.T, statusCode int, status, er }) require.NoError(t, err) var m map[string]string - err = c.Do(context.Background(), "GET", "/a", nil, nil, &m) + err = c.Do( + context.Background(), + "GET", + "/a", + nil, + nil, + nil, + &m, + ) require.EqualError(t, err, errorMessage) } @@ -477,6 +590,14 @@ func TestRetryOn503(t *testing.T) { }), }) require.NoError(t, err) - err = c.Do(context.Background(), "GET", "/a/b", nil, map[string]any{}, nil) + err = c.Do( + context.Background(), + "GET", + "/a/b", + nil, + nil, + map[string]any{}, + nil, + ) require.NoError(t, err) } diff --git a/databricks/httpclient/api_client.go b/databricks/httpclient/api_client.go index a607b102f..40d45a550 100644 --- a/databricks/httpclient/api_client.go +++ b/databricks/httpclient/api_client.go @@ -111,13 +111,21 @@ type DoOption struct { body any contentType string isAuthOption bool + queryParams map[string]any } // Do sends an HTTP request against path. func (c *ApiClient) Do(ctx context.Context, method, path string, opts ...DoOption) error { var authVisitor RequestVisitor visitors := c.config.Visitors[:] + var explicitQueryParams map[string]any for _, o := range opts { + if o.queryParams != nil { + if explicitQueryParams != nil { + return fmt.Errorf("only one set of query params is allowed") + } + explicitQueryParams = o.queryParams + } if o.in == nil { continue } @@ -150,7 +158,7 @@ func (c *ApiClient) Do(ctx context.Context, method, path string, opts ...DoOptio data = o.body contentType = o.contentType } - requestBody, err := makeRequestBody(method, &path, data, contentType) + requestBody, err := makeRequestBody(method, &path, data, contentType, explicitQueryParams) if err != nil { return fmt.Errorf("request marshal: %w", err) } diff --git a/databricks/httpclient/api_client_test.go b/databricks/httpclient/api_client_test.go index 85ffc02df..dca370c8f 100644 --- a/databricks/httpclient/api_client_test.go +++ b/databricks/httpclient/api_client_test.go @@ -67,6 +67,24 @@ func TestSimpleRequestFailsURLError(t *testing.T) { require.EqualError(t, err, `Get "/a/b?c=d": nope`) } +func TestQueryParameters(t *testing.T) { + c := NewApiClient(ClientConfig{ + RetryTimeout: 1 * time.Millisecond, + Transport: hc(func(r *http.Request) (*http.Response, error) { + require.Equal(t, "POST", r.Method) + require.Equal(t, "/a/b", r.URL.Path) + require.Equal(t, "c=d&e=1", r.URL.RawQuery) + return nil, fmt.Errorf("nope") + }), + }) + err := c.Do(context.Background(), "POST", "/a/b", + WithQueryParameters(map[string]any{ + "c": "d", + "e": 1, + })) + require.EqualError(t, err, `Post "/a/b?c=d&e=1": nope`) +} + func TestSimpleRequestFailsAPIError(t *testing.T) { c := NewApiClient(ClientConfig{ Transport: hc(func(r *http.Request) (*http.Response, error) { diff --git a/databricks/httpclient/request.go b/databricks/httpclient/request.go index a67686fac..a7a97b37b 100644 --- a/databricks/httpclient/request.go +++ b/databricks/httpclient/request.go @@ -73,6 +73,18 @@ func WithRequestData(body any) DoOption { } } +// WithQueryParameters takes a map and sends it as query string for non GET/DELETE/HEAD calls. +// This is ignored for GET/DELETE/HEAD calls, as the query parameters are serialized from the body instead. +// +// Experimental: this method may eventually be split into more granular options. +func WithQueryParameters(queryParams map[string]any) DoOption { + // refactor this, so that we split JSON/query string serialization and make + // separate request visitors internally. + return DoOption{ + queryParams: queryParams, + } +} + // WithUrlEncodedData takes either a struct instance, map, string, bytes, or io.Reader plus // a content type, and sends it either as query string for GET and DELETE calls, or as request body // for POST, PUT, and PATCH calls. The content type is set to "application/x-www-form-urlencoded" @@ -148,24 +160,41 @@ func EncodeMultiSegmentPathParameter(p string) string { return b.String() } -func makeRequestBody(method string, requestURL *string, data interface{}, contentType string) (common.RequestBody, error) { - if data == nil { +// We used to not send any query parameters for non GET/DELETE/HEAD requests. +// Moreover, serialization for query paramters in GET/DELETE/HEAD requests depends on the `url` tag. +// This tag is wrongly generated and fixing it will have an unknown inpact on the SDK. +// So: +// * GET/DELETE/HEAD requests are sent with query parameters serialized from data using the `url` tag as before (no change). +// * The rest of the requests are sent with query parameters serialized from explicitQueryParams, which does not use the `url` tag. +// TODO: For SDK-Mod, refactor this and remove the `url` tag completely. +func makeRequestBody(method string, requestURL *string, data interface{}, contentType string, explicitQueryParams map[string]any) (common.RequestBody, error) { + if data == nil && len(explicitQueryParams) == 0 { return common.RequestBody{}, nil } - if method == "GET" || method == "DELETE" || method == "HEAD" { - qs, err := makeQueryString(data) - if err != nil { - return common.RequestBody{}, err + if data != nil { + if method == "GET" || method == "DELETE" || method == "HEAD" { + qs, err := makeQueryString(data) + if err != nil { + return common.RequestBody{}, err + } + *requestURL += "?" + qs + return common.NewRequestBody([]byte{}) + } + if contentType == UrlEncodedContentType { + qs, err := makeQueryString(data) + if err != nil { + return common.RequestBody{}, err + } + return common.NewRequestBody(qs) } - *requestURL += "?" + qs - return common.NewRequestBody([]byte{}) } - if contentType == UrlEncodedContentType { - qs, err := makeQueryString(data) + if len(explicitQueryParams) > 0 { + qs, err := makeQueryString(explicitQueryParams) if err != nil { return common.RequestBody{}, err } - return common.NewRequestBody(qs) + *requestURL += "?" + qs + return common.NewRequestBody(data) } return common.NewRequestBody(data) } diff --git a/databricks/httpclient/request_test.go b/databricks/httpclient/request_test.go index 6b388af53..9f06dcf26 100644 --- a/databricks/httpclient/request_test.go +++ b/databricks/httpclient/request_test.go @@ -20,7 +20,7 @@ func TestMakeRequestBody(t *testing.T) { Scope string `json:"scope" url:"scope"` } requestURL := "/a/b/c" - body, err := makeRequestBody("GET", &requestURL, x{"test"}, "") + body, err := makeRequestBody("GET", &requestURL, x{"test"}, "", nil) require.NoError(t, err) bodyBytes, err := io.ReadAll(body.Reader) require.NoError(t, err) @@ -28,7 +28,7 @@ func TestMakeRequestBody(t *testing.T) { require.Equal(t, 0, len(bodyBytes)) requestURL = "/a/b/c" - body, err = makeRequestBody("POST", &requestURL, x{"test"}, "") + body, err = makeRequestBody("POST", &requestURL, x{"test"}, "", nil) require.NoError(t, err) bodyBytes, err = io.ReadAll(body.Reader) require.NoError(t, err) @@ -37,7 +37,7 @@ func TestMakeRequestBody(t *testing.T) { require.Equal(t, []byte(x1), bodyBytes) requestURL = "/a/b/c" - body, err = makeRequestBody("HEAD", &requestURL, x{"test"}, "") + body, err = makeRequestBody("HEAD", &requestURL, x{"test"}, "", nil) require.NoError(t, err) bodyBytes, err = io.ReadAll(body.Reader) require.NoError(t, err) @@ -47,7 +47,7 @@ func TestMakeRequestBody(t *testing.T) { func TestMakeRequestBodyFromReader(t *testing.T) { requestURL := "/a/b/c" - body, err := makeRequestBody("PUT", &requestURL, strings.NewReader("abc"), "") + body, err := makeRequestBody("PUT", &requestURL, strings.NewReader("abc"), "", nil) require.NoError(t, err) bodyBytes, err := io.ReadAll(body.Reader) require.NoError(t, err) @@ -61,7 +61,7 @@ func TestUrlEncoding(t *testing.T) { GrantType: "grant", } requestURL := "/a/b/c" - body, err := makeRequestBody("POST", &requestURL, data, UrlEncodedContentType) + body, err := makeRequestBody("POST", &requestURL, data, UrlEncodedContentType, nil) require.NoError(t, err) bodyBytes, err := io.ReadAll(body.Reader) require.NoError(t, err) @@ -71,7 +71,7 @@ func TestUrlEncoding(t *testing.T) { func TestMakeRequestBodyReaderError(t *testing.T) { requestURL := "/a/b/c" - _, err := makeRequestBody("POST", &requestURL, errReader(false), "") + _, err := makeRequestBody("POST", &requestURL, errReader(false), "", nil) // The request body is only read once the request is sent, so no error // should be returned until then. require.NoError(t, err, "request body reader error should be ignored") @@ -82,7 +82,7 @@ func TestMakeRequestBodyJsonError(t *testing.T) { type x struct { Foo chan string `json:"foo"` } - _, err := makeRequestBody("POST", &requestURL, x{make(chan string)}, "") + _, err := makeRequestBody("POST", &requestURL, x{make(chan string)}, "", nil) require.EqualError(t, err, "request marshal failure: json: unsupported type: chan string") } @@ -97,13 +97,13 @@ func TestMakeRequestBodyQueryFailingEncode(t *testing.T) { type x struct { Foo failingUrlEncode `url:"foo"` } - _, err := makeRequestBody("GET", &requestURL, x{failingUrlEncode("always failing")}, "") + _, err := makeRequestBody("GET", &requestURL, x{failingUrlEncode("always failing")}, "", nil) require.EqualError(t, err, "cannot create query string: always failing") } func TestMakeRequestBodyQueryUnsupported(t *testing.T) { requestURL := "/a/b/c" - _, err := makeRequestBody("GET", &requestURL, true, "") + _, err := makeRequestBody("GET", &requestURL, true, "", nil) require.EqualError(t, err, "unsupported query string data: true") } @@ -141,3 +141,25 @@ func TestEncodeMultiSegmentPathParameter(t *testing.T) { // # and ? should be encoded. assert.Equal(t, "a%23b%3Fc", EncodeMultiSegmentPathParameter("a#b?c")) } + +func TestMakeRequestBodyExplicitQueryParams(t *testing.T) { + type x struct { + Scope string `json:"scope" url:"scope"` + } + requestURL := "/a/b/c" + // For GET, it should be ignored. + body, err := makeRequestBody("GET", &requestURL, x{"test"}, "", map[string]any{"foo": "bar"}) + require.NoError(t, err) + bodyBytes, err := io.ReadAll(body.Reader) + require.NoError(t, err) + require.Equal(t, "/a/b/c?scope=test", requestURL) + require.Equal(t, 0, len(bodyBytes)) + requestURL = "/a/b/c" + body, err = makeRequestBody("POST", &requestURL, x{"test"}, "", map[string]any{"foo": "bar"}) + require.NoError(t, err) + bodyBytes, err = io.ReadAll(body.Reader) + require.NoError(t, err) + require.Equal(t, "/a/b/c?foo=bar", requestURL) + x1 := `{"scope":"test"}` + require.Equal(t, []byte(x1), bodyBytes) +} diff --git a/databricks/version/version.go b/databricks/version/version.go index 142d27dac..61aa3beb4 100644 --- a/databricks/version/version.go +++ b/databricks/version/version.go @@ -1,4 +1,4 @@ package version // Version of the SDK, updated manually before every tag -const Version = "0.55.0" +const Version = "0.56.1" diff --git a/files/go.mod b/files/go.mod index 73c983768..5b9164a89 100644 --- a/files/go.mod +++ b/files/go.mod @@ -6,6 +6,7 @@ replace github.com/databricks/databricks-sdk-go/databricks => ../databricks require ( github.com/databricks/databricks-sdk-go/databricks v0.0.0-00010101000000-000000000000 + golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 golang.org/x/oauth2 v0.25.0 ) @@ -27,7 +28,6 @@ require ( go.opentelemetry.io/otel/metric v1.24.0 // indirect go.opentelemetry.io/otel/trace v1.24.0 // indirect golang.org/x/crypto v0.31.0 // indirect - golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.33.0 // indirect golang.org/x/sys v0.28.0 // indirect diff --git a/files/v2/api.go b/files/v2/api.go index 4fcd5ec79..9ea002811 100755 --- a/files/v2/api.go +++ b/files/v2/api.go @@ -8,7 +8,6 @@ import ( "github.com/databricks/databricks-sdk-go/databricks/client" "github.com/databricks/databricks-sdk-go/databricks/listing" - "github.com/databricks/databricks-sdk-go/databricks/useragent" ) type DbfsInterface interface { @@ -223,59 +222,6 @@ func (a *DbfsAPI) GetStatusByPath(ctx context.Context, path string) (*FileInfo, }) } -// List directory contents or file details. -// -// List the contents of a directory, or details of the file. If the file or -// directory does not exist, this call throws an exception with -// `RESOURCE_DOES_NOT_EXIST`. -// -// When calling list on a large directory, the list operation will time out -// after approximately 60 seconds. We strongly recommend using list only on -// directories containing less than 10K files and discourage using the DBFS REST -// API for operations that list more than 10K files. Instead, we recommend that -// you perform such operations in the context of a cluster, using the [File -// system utility (dbutils.fs)](/dev-tools/databricks-utils.html#dbutils-fs), -// which provides the same functionality without timing out. -// -// This method is generated by Databricks SDK Code Generator. -func (a *DbfsAPI) List(ctx context.Context, request ListDbfsRequest) listing.Iterator[FileInfo] { - - getNextPage := func(ctx context.Context, req ListDbfsRequest) (*ListStatusResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.dbfsImpl.List(ctx, req) - } - getItems := func(resp *ListStatusResponse) []FileInfo { - return resp.Files - } - - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - nil) - return iterator -} - -// List directory contents or file details. -// -// List the contents of a directory, or details of the file. If the file or -// directory does not exist, this call throws an exception with -// `RESOURCE_DOES_NOT_EXIST`. -// -// When calling list on a large directory, the list operation will time out -// after approximately 60 seconds. We strongly recommend using list only on -// directories containing less than 10K files and discourage using the DBFS REST -// API for operations that list more than 10K files. Instead, we recommend that -// you perform such operations in the context of a cluster, using the [File -// system utility (dbutils.fs)](/dev-tools/databricks-utils.html#dbutils-fs), -// which provides the same functionality without timing out. -// -// This method is generated by Databricks SDK Code Generator. -func (a *DbfsAPI) ListAll(ctx context.Context, request ListDbfsRequest) ([]FileInfo, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[FileInfo](ctx, iterator) -} - // List directory contents or file details. // // List the contents of a directory, or details of the file. If the file or @@ -290,7 +236,7 @@ func (a *DbfsAPI) ListAll(ctx context.Context, request ListDbfsRequest) ([]FileI // system utility (dbutils.fs)](/dev-tools/databricks-utils.html#dbutils-fs), // which provides the same functionality without timing out. func (a *DbfsAPI) ListByPath(ctx context.Context, path string) (*ListStatusResponse, error) { - return a.dbfsImpl.List(ctx, ListDbfsRequest{ + return a.dbfsImpl.internalList(ctx, ListDbfsRequest{ Path: path, }) } @@ -523,54 +469,12 @@ func (a *FilesAPI) GetMetadataByFilePath(ctx context.Context, filePath string) ( }) } -// List directory contents. -// -// Returns the contents of a directory. If there is no directory at the -// specified path, the API returns a HTTP 404 error. -// -// This method is generated by Databricks SDK Code Generator. -func (a *FilesAPI) ListDirectoryContents(ctx context.Context, request ListDirectoryContentsRequest) listing.Iterator[DirectoryEntry] { - - getNextPage := func(ctx context.Context, req ListDirectoryContentsRequest) (*ListDirectoryResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.filesImpl.ListDirectoryContents(ctx, req) - } - getItems := func(resp *ListDirectoryResponse) []DirectoryEntry { - return resp.Contents - } - getNextReq := func(resp *ListDirectoryResponse) *ListDirectoryContentsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List directory contents. -// -// Returns the contents of a directory. If there is no directory at the -// specified path, the API returns a HTTP 404 error. -// -// This method is generated by Databricks SDK Code Generator. -func (a *FilesAPI) ListDirectoryContentsAll(ctx context.Context, request ListDirectoryContentsRequest) ([]DirectoryEntry, error) { - iterator := a.ListDirectoryContents(ctx, request) - return listing.ToSliceN[DirectoryEntry, int64](ctx, iterator, request.PageSize) - -} - // List directory contents. // // Returns the contents of a directory. If there is no directory at the // specified path, the API returns a HTTP 404 error. func (a *FilesAPI) ListDirectoryContentsByDirectoryPath(ctx context.Context, directoryPath string) (*ListDirectoryResponse, error) { - return a.filesImpl.ListDirectoryContents(ctx, ListDirectoryContentsRequest{ + return a.filesImpl.internalListDirectoryContents(ctx, ListDirectoryContentsRequest{ DirectoryPath: directoryPath, }) } diff --git a/files/v2/impl.go b/files/v2/impl.go index 2ec276fa3..8e2c298e3 100755 --- a/files/v2/impl.go +++ b/files/v2/impl.go @@ -9,6 +9,9 @@ import ( "github.com/databricks/databricks-sdk-go/databricks/client" "github.com/databricks/databricks-sdk-go/databricks/httpclient" + "github.com/databricks/databricks-sdk-go/databricks/listing" + "github.com/databricks/databricks-sdk-go/databricks/useragent" + "golang.org/x/exp/slices" ) // unexported type that holds implementations of just Dbfs API methods @@ -19,97 +22,155 @@ type dbfsImpl struct { func (a *dbfsImpl) AddBlock(ctx context.Context, request AddBlock) error { var addBlockResponse AddBlockResponse path := "/api/2.0/dbfs/add-block" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &addBlockResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &addBlockResponse) return err } func (a *dbfsImpl) Close(ctx context.Context, request Close) error { var closeResponse CloseResponse path := "/api/2.0/dbfs/close" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &closeResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &closeResponse) return err } func (a *dbfsImpl) Create(ctx context.Context, request Create) (*CreateResponse, error) { var createResponse CreateResponse path := "/api/2.0/dbfs/create" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createResponse) return &createResponse, err } func (a *dbfsImpl) Delete(ctx context.Context, request Delete) error { var deleteResponse DeleteResponse path := "/api/2.0/dbfs/delete" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &deleteResponse) return err } func (a *dbfsImpl) GetStatus(ctx context.Context, request GetStatusRequest) (*FileInfo, error) { var fileInfo FileInfo path := "/api/2.0/dbfs/get-status" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &fileInfo) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &fileInfo) return &fileInfo, err } -func (a *dbfsImpl) List(ctx context.Context, request ListDbfsRequest) (*ListStatusResponse, error) { +// List directory contents or file details. +// +// List the contents of a directory, or details of the file. If the file or +// directory does not exist, this call throws an exception with +// `RESOURCE_DOES_NOT_EXIST`. +// +// When calling list on a large directory, the list operation will time out +// after approximately 60 seconds. We strongly recommend using list only on +// directories containing less than 10K files and discourage using the DBFS REST +// API for operations that list more than 10K files. Instead, we recommend that +// you perform such operations in the context of a cluster, using the [File +// system utility (dbutils.fs)](/dev-tools/databricks-utils.html#dbutils-fs), +// which provides the same functionality without timing out. +func (a *dbfsImpl) List(ctx context.Context, request ListDbfsRequest) listing.Iterator[FileInfo] { + + getNextPage := func(ctx context.Context, req ListDbfsRequest) (*ListStatusResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListStatusResponse) []FileInfo { + return resp.Files + } + + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + nil) + return iterator +} + +// List directory contents or file details. +// +// List the contents of a directory, or details of the file. If the file or +// directory does not exist, this call throws an exception with +// `RESOURCE_DOES_NOT_EXIST`. +// +// When calling list on a large directory, the list operation will time out +// after approximately 60 seconds. We strongly recommend using list only on +// directories containing less than 10K files and discourage using the DBFS REST +// API for operations that list more than 10K files. Instead, we recommend that +// you perform such operations in the context of a cluster, using the [File +// system utility (dbutils.fs)](/dev-tools/databricks-utils.html#dbutils-fs), +// which provides the same functionality without timing out. +func (a *dbfsImpl) ListAll(ctx context.Context, request ListDbfsRequest) ([]FileInfo, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[FileInfo](ctx, iterator) +} +func (a *dbfsImpl) internalList(ctx context.Context, request ListDbfsRequest) (*ListStatusResponse, error) { var listStatusResponse ListStatusResponse path := "/api/2.0/dbfs/list" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listStatusResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listStatusResponse) return &listStatusResponse, err } func (a *dbfsImpl) Mkdirs(ctx context.Context, request MkDirs) error { var mkDirsResponse MkDirsResponse path := "/api/2.0/dbfs/mkdirs" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &mkDirsResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &mkDirsResponse) return err } func (a *dbfsImpl) Move(ctx context.Context, request Move) error { var moveResponse MoveResponse path := "/api/2.0/dbfs/move" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &moveResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &moveResponse) return err } func (a *dbfsImpl) Put(ctx context.Context, request Put) error { var putResponse PutResponse path := "/api/2.0/dbfs/put" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &putResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &putResponse) return err } func (a *dbfsImpl) Read(ctx context.Context, request ReadDbfsRequest) (*ReadResponse, error) { var readResponse ReadResponse path := "/api/2.0/dbfs/read" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &readResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &readResponse) return &readResponse, err } @@ -121,66 +182,114 @@ type filesImpl struct { func (a *filesImpl) CreateDirectory(ctx context.Context, request CreateDirectoryRequest) error { var createDirectoryResponse CreateDirectoryResponse path := fmt.Sprintf("/api/2.0/fs/directories%v", httpclient.EncodeMultiSegmentPathParameter(request.DirectoryPath)) + queryParams := make(map[string]any) headers := make(map[string]string) - err := a.client.Do(ctx, http.MethodPut, path, headers, nil, &createDirectoryResponse) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, nil, &createDirectoryResponse) return err } func (a *filesImpl) Delete(ctx context.Context, request DeleteFileRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.0/fs/files%v", httpclient.EncodeMultiSegmentPathParameter(request.FilePath)) + queryParams := make(map[string]any) headers := make(map[string]string) - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *filesImpl) DeleteDirectory(ctx context.Context, request DeleteDirectoryRequest) error { var deleteDirectoryResponse DeleteDirectoryResponse path := fmt.Sprintf("/api/2.0/fs/directories%v", httpclient.EncodeMultiSegmentPathParameter(request.DirectoryPath)) + queryParams := make(map[string]any) headers := make(map[string]string) - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteDirectoryResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteDirectoryResponse) return err } func (a *filesImpl) Download(ctx context.Context, request DownloadRequest) (*DownloadResponse, error) { var downloadResponse DownloadResponse path := fmt.Sprintf("/api/2.0/fs/files%v", httpclient.EncodeMultiSegmentPathParameter(request.FilePath)) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/octet-stream" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &downloadResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &downloadResponse) return &downloadResponse, err } func (a *filesImpl) GetDirectoryMetadata(ctx context.Context, request GetDirectoryMetadataRequest) error { var getDirectoryMetadataResponse GetDirectoryMetadataResponse path := fmt.Sprintf("/api/2.0/fs/directories%v", httpclient.EncodeMultiSegmentPathParameter(request.DirectoryPath)) + queryParams := make(map[string]any) headers := make(map[string]string) - err := a.client.Do(ctx, http.MethodHead, path, headers, request, &getDirectoryMetadataResponse) + err := a.client.Do(ctx, http.MethodHead, path, headers, queryParams, request, &getDirectoryMetadataResponse) return err } func (a *filesImpl) GetMetadata(ctx context.Context, request GetMetadataRequest) (*GetMetadataResponse, error) { var getMetadataResponse GetMetadataResponse path := fmt.Sprintf("/api/2.0/fs/files%v", httpclient.EncodeMultiSegmentPathParameter(request.FilePath)) + queryParams := make(map[string]any) headers := make(map[string]string) - err := a.client.Do(ctx, http.MethodHead, path, headers, request, &getMetadataResponse) + err := a.client.Do(ctx, http.MethodHead, path, headers, queryParams, request, &getMetadataResponse) return &getMetadataResponse, err } -func (a *filesImpl) ListDirectoryContents(ctx context.Context, request ListDirectoryContentsRequest) (*ListDirectoryResponse, error) { +// List directory contents. +// +// Returns the contents of a directory. If there is no directory at the +// specified path, the API returns a HTTP 404 error. +func (a *filesImpl) ListDirectoryContents(ctx context.Context, request ListDirectoryContentsRequest) listing.Iterator[DirectoryEntry] { + + getNextPage := func(ctx context.Context, req ListDirectoryContentsRequest) (*ListDirectoryResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalListDirectoryContents(ctx, req) + } + getItems := func(resp *ListDirectoryResponse) []DirectoryEntry { + return resp.Contents + } + getNextReq := func(resp *ListDirectoryResponse) *ListDirectoryContentsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List directory contents. +// +// Returns the contents of a directory. If there is no directory at the +// specified path, the API returns a HTTP 404 error. +func (a *filesImpl) ListDirectoryContentsAll(ctx context.Context, request ListDirectoryContentsRequest) ([]DirectoryEntry, error) { + iterator := a.ListDirectoryContents(ctx, request) + return listing.ToSliceN[DirectoryEntry, int64](ctx, iterator, request.PageSize) + +} +func (a *filesImpl) internalListDirectoryContents(ctx context.Context, request ListDirectoryContentsRequest) (*ListDirectoryResponse, error) { var listDirectoryResponse ListDirectoryResponse path := fmt.Sprintf("/api/2.0/fs/directories%v", httpclient.EncodeMultiSegmentPathParameter(request.DirectoryPath)) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listDirectoryResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listDirectoryResponse) return &listDirectoryResponse, err } func (a *filesImpl) Upload(ctx context.Context, request UploadRequest) error { var uploadResponse UploadResponse path := fmt.Sprintf("/api/2.0/fs/files%v", httpclient.EncodeMultiSegmentPathParameter(request.FilePath)) + queryParams := make(map[string]any) + if request.Overwrite != false || slices.Contains(request.ForceSendFields, "Overwrite") { + queryParams["overwrite"] = request.Overwrite + } headers := make(map[string]string) headers["Content-Type"] = "application/octet-stream" - err := a.client.Do(ctx, http.MethodPut, path, headers, request.Contents, &uploadResponse) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request.Contents, &uploadResponse) return err } diff --git a/iam/go.mod b/iam/go.mod index 82278f541..158331e66 100644 --- a/iam/go.mod +++ b/iam/go.mod @@ -6,6 +6,7 @@ replace github.com/databricks/databricks-sdk-go/databricks => ../databricks require ( github.com/databricks/databricks-sdk-go/databricks v0.0.0-00010101000000-000000000000 + golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 golang.org/x/oauth2 v0.25.0 ) @@ -27,7 +28,6 @@ require ( go.opentelemetry.io/otel/metric v1.24.0 // indirect go.opentelemetry.io/otel/trace v1.24.0 // indirect golang.org/x/crypto v0.31.0 // indirect - golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.33.0 // indirect golang.org/x/sys v0.28.0 // indirect diff --git a/iam/v2/api.go b/iam/v2/api.go index 4e0be2521..0b274654c 100755 --- a/iam/v2/api.go +++ b/iam/v2/api.go @@ -218,55 +218,6 @@ func (a *AccountGroupsAPI) GetById(ctx context.Context, id string) (*Group, erro }) } -// List group details. -// -// Gets all details of the groups associated with the Databricks account. -// -// This method is generated by Databricks SDK Code Generator. -func (a *AccountGroupsAPI) List(ctx context.Context, request ListAccountGroupsRequest) listing.Iterator[Group] { - - request.StartIndex = 1 // SCIM offset starts from 1 - if request.Count == 0 { - request.Count = 100 - } - getNextPage := func(ctx context.Context, req ListAccountGroupsRequest) (*ListGroupsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.accountGroupsImpl.List(ctx, req) - } - getItems := func(resp *ListGroupsResponse) []Group { - return resp.Resources - } - getNextReq := func(resp *ListGroupsResponse) *ListAccountGroupsRequest { - if len(getItems(resp)) == 0 { - return nil - } - request.StartIndex = resp.StartIndex + int64(len(resp.Resources)) - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - dedupedIterator := listing.NewDedupeIterator[Group, string]( - iterator, - func(item Group) string { - return item.Id - }) - return dedupedIterator -} - -// List group details. -// -// Gets all details of the groups associated with the Databricks account. -// -// This method is generated by Databricks SDK Code Generator. -func (a *AccountGroupsAPI) ListAll(ctx context.Context, request ListAccountGroupsRequest) ([]Group, error) { - iterator := a.List(ctx, request) - return listing.ToSliceN[Group, int64](ctx, iterator, request.Count) - -} - // GroupDisplayNameToIdMap calls [AccountGroupsAPI.ListAll] and creates a map of results with [Group].DisplayName as key and [Group].Id as value. // // Returns an error if there's more than one [Group] with the same .DisplayName. @@ -432,55 +383,6 @@ func (a *AccountServicePrincipalsAPI) GetById(ctx context.Context, id string) (* }) } -// List service principals. -// -// Gets the set of service principals associated with a Databricks account. -// -// This method is generated by Databricks SDK Code Generator. -func (a *AccountServicePrincipalsAPI) List(ctx context.Context, request ListAccountServicePrincipalsRequest) listing.Iterator[ServicePrincipal] { - - request.StartIndex = 1 // SCIM offset starts from 1 - if request.Count == 0 { - request.Count = 100 - } - getNextPage := func(ctx context.Context, req ListAccountServicePrincipalsRequest) (*ListServicePrincipalResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.accountServicePrincipalsImpl.List(ctx, req) - } - getItems := func(resp *ListServicePrincipalResponse) []ServicePrincipal { - return resp.Resources - } - getNextReq := func(resp *ListServicePrincipalResponse) *ListAccountServicePrincipalsRequest { - if len(getItems(resp)) == 0 { - return nil - } - request.StartIndex = resp.StartIndex + int64(len(resp.Resources)) - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - dedupedIterator := listing.NewDedupeIterator[ServicePrincipal, string]( - iterator, - func(item ServicePrincipal) string { - return item.Id - }) - return dedupedIterator -} - -// List service principals. -// -// Gets the set of service principals associated with a Databricks account. -// -// This method is generated by Databricks SDK Code Generator. -func (a *AccountServicePrincipalsAPI) ListAll(ctx context.Context, request ListAccountServicePrincipalsRequest) ([]ServicePrincipal, error) { - iterator := a.List(ctx, request) - return listing.ToSliceN[ServicePrincipal, int64](ctx, iterator, request.Count) - -} - // ServicePrincipalDisplayNameToIdMap calls [AccountServicePrincipalsAPI.ListAll] and creates a map of results with [ServicePrincipal].DisplayName as key and [ServicePrincipal].Id as value. // // Returns an error if there's more than one [ServicePrincipal] with the same .DisplayName. @@ -650,55 +552,6 @@ func (a *AccountUsersAPI) GetById(ctx context.Context, id string) (*User, error) }) } -// List users. -// -// Gets details for all the users associated with a Databricks account. -// -// This method is generated by Databricks SDK Code Generator. -func (a *AccountUsersAPI) List(ctx context.Context, request ListAccountUsersRequest) listing.Iterator[User] { - - request.StartIndex = 1 // SCIM offset starts from 1 - if request.Count == 0 { - request.Count = 100 - } - getNextPage := func(ctx context.Context, req ListAccountUsersRequest) (*ListUsersResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.accountUsersImpl.List(ctx, req) - } - getItems := func(resp *ListUsersResponse) []User { - return resp.Resources - } - getNextReq := func(resp *ListUsersResponse) *ListAccountUsersRequest { - if len(getItems(resp)) == 0 { - return nil - } - request.StartIndex = resp.StartIndex + int64(len(resp.Resources)) - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - dedupedIterator := listing.NewDedupeIterator[User, string]( - iterator, - func(item User) string { - return item.Id - }) - return dedupedIterator -} - -// List users. -// -// Gets details for all the users associated with a Databricks account. -// -// This method is generated by Databricks SDK Code Generator. -func (a *AccountUsersAPI) ListAll(ctx context.Context, request ListAccountUsersRequest) ([]User, error) { - iterator := a.List(ctx, request) - return listing.ToSliceN[User, int64](ctx, iterator, request.Count) - -} - // UserUserNameToIdMap calls [AccountUsersAPI.ListAll] and creates a map of results with [User].UserName as key and [User].Id as value. // // Returns an error if there's more than one [User] with the same .UserName. @@ -882,55 +735,6 @@ func (a *GroupsAPI) GetById(ctx context.Context, id string) (*Group, error) { }) } -// List group details. -// -// Gets all details of the groups associated with the Databricks workspace. -// -// This method is generated by Databricks SDK Code Generator. -func (a *GroupsAPI) List(ctx context.Context, request ListGroupsRequest) listing.Iterator[Group] { - - request.StartIndex = 1 // SCIM offset starts from 1 - if request.Count == 0 { - request.Count = 100 - } - getNextPage := func(ctx context.Context, req ListGroupsRequest) (*ListGroupsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.groupsImpl.List(ctx, req) - } - getItems := func(resp *ListGroupsResponse) []Group { - return resp.Resources - } - getNextReq := func(resp *ListGroupsResponse) *ListGroupsRequest { - if len(getItems(resp)) == 0 { - return nil - } - request.StartIndex = resp.StartIndex + int64(len(resp.Resources)) - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - dedupedIterator := listing.NewDedupeIterator[Group, string]( - iterator, - func(item Group) string { - return item.Id - }) - return dedupedIterator -} - -// List group details. -// -// Gets all details of the groups associated with the Databricks workspace. -// -// This method is generated by Databricks SDK Code Generator. -func (a *GroupsAPI) ListAll(ctx context.Context, request ListGroupsRequest) ([]Group, error) { - iterator := a.List(ctx, request) - return listing.ToSliceN[Group, int64](ctx, iterator, request.Count) - -} - // GroupDisplayNameToIdMap calls [GroupsAPI.ListAll] and creates a map of results with [Group].DisplayName as key and [Group].Id as value. // // Returns an error if there's more than one [Group] with the same .DisplayName. @@ -1241,55 +1045,6 @@ func (a *ServicePrincipalsAPI) GetById(ctx context.Context, id string) (*Service }) } -// List service principals. -// -// Gets the set of service principals associated with a Databricks workspace. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ServicePrincipalsAPI) List(ctx context.Context, request ListServicePrincipalsRequest) listing.Iterator[ServicePrincipal] { - - request.StartIndex = 1 // SCIM offset starts from 1 - if request.Count == 0 { - request.Count = 100 - } - getNextPage := func(ctx context.Context, req ListServicePrincipalsRequest) (*ListServicePrincipalResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.servicePrincipalsImpl.List(ctx, req) - } - getItems := func(resp *ListServicePrincipalResponse) []ServicePrincipal { - return resp.Resources - } - getNextReq := func(resp *ListServicePrincipalResponse) *ListServicePrincipalsRequest { - if len(getItems(resp)) == 0 { - return nil - } - request.StartIndex = resp.StartIndex + int64(len(resp.Resources)) - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - dedupedIterator := listing.NewDedupeIterator[ServicePrincipal, string]( - iterator, - func(item ServicePrincipal) string { - return item.Id - }) - return dedupedIterator -} - -// List service principals. -// -// Gets the set of service principals associated with a Databricks workspace. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ServicePrincipalsAPI) ListAll(ctx context.Context, request ListServicePrincipalsRequest) ([]ServicePrincipal, error) { - iterator := a.List(ctx, request) - return listing.ToSliceN[ServicePrincipal, int64](ctx, iterator, request.Count) - -} - // ServicePrincipalDisplayNameToIdMap calls [ServicePrincipalsAPI.ListAll] and creates a map of results with [ServicePrincipal].DisplayName as key and [ServicePrincipal].Id as value. // // Returns an error if there's more than one [ServicePrincipal] with the same .DisplayName. @@ -1483,55 +1238,6 @@ func (a *UsersAPI) GetById(ctx context.Context, id string) (*User, error) { }) } -// List users. -// -// Gets details for all the users associated with a Databricks workspace. -// -// This method is generated by Databricks SDK Code Generator. -func (a *UsersAPI) List(ctx context.Context, request ListUsersRequest) listing.Iterator[User] { - - request.StartIndex = 1 // SCIM offset starts from 1 - if request.Count == 0 { - request.Count = 100 - } - getNextPage := func(ctx context.Context, req ListUsersRequest) (*ListUsersResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.usersImpl.List(ctx, req) - } - getItems := func(resp *ListUsersResponse) []User { - return resp.Resources - } - getNextReq := func(resp *ListUsersResponse) *ListUsersRequest { - if len(getItems(resp)) == 0 { - return nil - } - request.StartIndex = resp.StartIndex + int64(len(resp.Resources)) - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - dedupedIterator := listing.NewDedupeIterator[User, string]( - iterator, - func(item User) string { - return item.Id - }) - return dedupedIterator -} - -// List users. -// -// Gets details for all the users associated with a Databricks workspace. -// -// This method is generated by Databricks SDK Code Generator. -func (a *UsersAPI) ListAll(ctx context.Context, request ListUsersRequest) ([]User, error) { - iterator := a.List(ctx, request) - return listing.ToSliceN[User, int64](ctx, iterator, request.Count) - -} - // UserUserNameToIdMap calls [UsersAPI.ListAll] and creates a map of results with [User].UserName as key and [User].Id as value. // // Returns an error if there's more than one [User] with the same .UserName. @@ -1675,47 +1381,12 @@ func (a *WorkspaceAssignmentAPI) GetByWorkspaceId(ctx context.Context, workspace }) } -// Get permission assignments. -// -// Get the permission assignments for the specified Databricks account and -// Databricks workspace. -// -// This method is generated by Databricks SDK Code Generator. -func (a *WorkspaceAssignmentAPI) List(ctx context.Context, request ListWorkspaceAssignmentRequest) listing.Iterator[PermissionAssignment] { - - getNextPage := func(ctx context.Context, req ListWorkspaceAssignmentRequest) (*PermissionAssignments, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.workspaceAssignmentImpl.List(ctx, req) - } - getItems := func(resp *PermissionAssignments) []PermissionAssignment { - return resp.PermissionAssignments - } - - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - nil) - return iterator -} - -// Get permission assignments. -// -// Get the permission assignments for the specified Databricks account and -// Databricks workspace. -// -// This method is generated by Databricks SDK Code Generator. -func (a *WorkspaceAssignmentAPI) ListAll(ctx context.Context, request ListWorkspaceAssignmentRequest) ([]PermissionAssignment, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[PermissionAssignment](ctx, iterator) -} - // Get permission assignments. // // 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.workspaceAssignmentImpl.List(ctx, ListWorkspaceAssignmentRequest{ + return a.workspaceAssignmentImpl.internalList(ctx, ListWorkspaceAssignmentRequest{ WorkspaceId: workspaceId, }) } diff --git a/iam/v2/impl.go b/iam/v2/impl.go index 992d97732..f7cb977bf 100755 --- a/iam/v2/impl.go +++ b/iam/v2/impl.go @@ -8,6 +8,8 @@ import ( "net/http" "github.com/databricks/databricks-sdk-go/databricks/client" + "github.com/databricks/databricks-sdk-go/databricks/listing" + "github.com/databricks/databricks-sdk-go/databricks/useragent" ) // unexported type that holds implementations of just AccessControl API methods @@ -18,9 +20,10 @@ type accessControlImpl struct { func (a *accessControlImpl) CheckPolicy(ctx context.Context, request CheckPolicyRequest) (*CheckPolicyResponse, error) { var checkPolicyResponse CheckPolicyResponse path := "/api/2.0/access-control/check-policy-v2" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &checkPolicyResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &checkPolicyResponse) return &checkPolicyResponse, err } @@ -32,28 +35,31 @@ type accountAccessControlImpl struct { func (a *accountAccessControlImpl) GetAssignableRolesForResource(ctx context.Context, request GetAssignableRolesForResourceRequest) (*GetAssignableRolesForResourceResponse, error) { var getAssignableRolesForResourceResponse GetAssignableRolesForResourceResponse path := fmt.Sprintf("/api/2.0/preview/accounts/%v/access-control/assignable-roles", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getAssignableRolesForResourceResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getAssignableRolesForResourceResponse) return &getAssignableRolesForResourceResponse, err } func (a *accountAccessControlImpl) GetRuleSet(ctx context.Context, request GetRuleSetRequest) (*RuleSetResponse, error) { var ruleSetResponse RuleSetResponse path := fmt.Sprintf("/api/2.0/preview/accounts/%v/access-control/rule-sets", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &ruleSetResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &ruleSetResponse) return &ruleSetResponse, err } func (a *accountAccessControlImpl) UpdateRuleSet(ctx context.Context, request UpdateRuleSetRequest) (*RuleSetResponse, error) { var ruleSetResponse RuleSetResponse path := fmt.Sprintf("/api/2.0/preview/accounts/%v/access-control/rule-sets", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &ruleSetResponse) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &ruleSetResponse) return &ruleSetResponse, err } @@ -65,28 +71,31 @@ type accountAccessControlProxyImpl struct { func (a *accountAccessControlProxyImpl) GetAssignableRolesForResource(ctx context.Context, request GetAssignableRolesForResourceRequest) (*GetAssignableRolesForResourceResponse, error) { var getAssignableRolesForResourceResponse GetAssignableRolesForResourceResponse path := "/api/2.0/preview/accounts/access-control/assignable-roles" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getAssignableRolesForResourceResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getAssignableRolesForResourceResponse) return &getAssignableRolesForResourceResponse, err } func (a *accountAccessControlProxyImpl) GetRuleSet(ctx context.Context, request GetRuleSetRequest) (*RuleSetResponse, error) { var ruleSetResponse RuleSetResponse path := "/api/2.0/preview/accounts/access-control/rule-sets" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &ruleSetResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &ruleSetResponse) return &ruleSetResponse, err } func (a *accountAccessControlProxyImpl) UpdateRuleSet(ctx context.Context, request UpdateRuleSetRequest) (*RuleSetResponse, error) { var ruleSetResponse RuleSetResponse path := "/api/2.0/preview/accounts/access-control/rule-sets" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &ruleSetResponse) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &ruleSetResponse) return &ruleSetResponse, err } @@ -98,56 +107,106 @@ type accountGroupsImpl struct { func (a *accountGroupsImpl) Create(ctx context.Context, request Group) (*Group, error) { var group Group path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Groups", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &group) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &group) return &group, err } func (a *accountGroupsImpl) Delete(ctx context.Context, request DeleteAccountGroupRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Groups/%v", a.client.ConfiguredAccountID(), request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *accountGroupsImpl) Get(ctx context.Context, request GetAccountGroupRequest) (*Group, error) { var group Group path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Groups/%v", a.client.ConfiguredAccountID(), request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &group) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &group) return &group, err } -func (a *accountGroupsImpl) List(ctx context.Context, request ListAccountGroupsRequest) (*ListGroupsResponse, error) { +// List group details. +// +// Gets all details of the groups associated with the Databricks account. +func (a *accountGroupsImpl) List(ctx context.Context, request ListAccountGroupsRequest) listing.Iterator[Group] { + + request.StartIndex = 1 // SCIM offset starts from 1 + if request.Count == 0 { + request.Count = 100 + } + getNextPage := func(ctx context.Context, req ListAccountGroupsRequest) (*ListGroupsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListGroupsResponse) []Group { + return resp.Resources + } + getNextReq := func(resp *ListGroupsResponse) *ListAccountGroupsRequest { + if len(getItems(resp)) == 0 { + return nil + } + request.StartIndex = resp.StartIndex + int64(len(resp.Resources)) + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + dedupedIterator := listing.NewDedupeIterator[Group, string]( + iterator, + func(item Group) string { + return item.Id + }) + return dedupedIterator +} + +// List group details. +// +// Gets all details of the groups associated with the Databricks account. +func (a *accountGroupsImpl) ListAll(ctx context.Context, request ListAccountGroupsRequest) ([]Group, error) { + iterator := a.List(ctx, request) + return listing.ToSliceN[Group, int64](ctx, iterator, request.Count) + +} +func (a *accountGroupsImpl) internalList(ctx context.Context, request ListAccountGroupsRequest) (*ListGroupsResponse, error) { var listGroupsResponse ListGroupsResponse path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Groups", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listGroupsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listGroupsResponse) return &listGroupsResponse, err } func (a *accountGroupsImpl) Patch(ctx context.Context, request PartialUpdate) error { var patchResponse PatchResponse path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Groups/%v", a.client.ConfiguredAccountID(), request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &patchResponse) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &patchResponse) return err } func (a *accountGroupsImpl) Update(ctx context.Context, request Group) error { var updateResponse UpdateResponse path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Groups/%v", a.client.ConfiguredAccountID(), request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &updateResponse) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &updateResponse) return err } @@ -159,56 +218,106 @@ type accountServicePrincipalsImpl struct { func (a *accountServicePrincipalsImpl) Create(ctx context.Context, request ServicePrincipal) (*ServicePrincipal, error) { var servicePrincipal ServicePrincipal path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/ServicePrincipals", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &servicePrincipal) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &servicePrincipal) return &servicePrincipal, err } func (a *accountServicePrincipalsImpl) Delete(ctx context.Context, request DeleteAccountServicePrincipalRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/ServicePrincipals/%v", a.client.ConfiguredAccountID(), request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *accountServicePrincipalsImpl) Get(ctx context.Context, request GetAccountServicePrincipalRequest) (*ServicePrincipal, error) { var servicePrincipal ServicePrincipal path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/ServicePrincipals/%v", a.client.ConfiguredAccountID(), request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &servicePrincipal) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &servicePrincipal) return &servicePrincipal, err } -func (a *accountServicePrincipalsImpl) List(ctx context.Context, request ListAccountServicePrincipalsRequest) (*ListServicePrincipalResponse, error) { +// List service principals. +// +// Gets the set of service principals associated with a Databricks account. +func (a *accountServicePrincipalsImpl) List(ctx context.Context, request ListAccountServicePrincipalsRequest) listing.Iterator[ServicePrincipal] { + + request.StartIndex = 1 // SCIM offset starts from 1 + if request.Count == 0 { + request.Count = 100 + } + getNextPage := func(ctx context.Context, req ListAccountServicePrincipalsRequest) (*ListServicePrincipalResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListServicePrincipalResponse) []ServicePrincipal { + return resp.Resources + } + getNextReq := func(resp *ListServicePrincipalResponse) *ListAccountServicePrincipalsRequest { + if len(getItems(resp)) == 0 { + return nil + } + request.StartIndex = resp.StartIndex + int64(len(resp.Resources)) + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + dedupedIterator := listing.NewDedupeIterator[ServicePrincipal, string]( + iterator, + func(item ServicePrincipal) string { + return item.Id + }) + return dedupedIterator +} + +// List service principals. +// +// Gets the set of service principals associated with a Databricks account. +func (a *accountServicePrincipalsImpl) ListAll(ctx context.Context, request ListAccountServicePrincipalsRequest) ([]ServicePrincipal, error) { + iterator := a.List(ctx, request) + return listing.ToSliceN[ServicePrincipal, int64](ctx, iterator, request.Count) + +} +func (a *accountServicePrincipalsImpl) internalList(ctx context.Context, request ListAccountServicePrincipalsRequest) (*ListServicePrincipalResponse, error) { var listServicePrincipalResponse ListServicePrincipalResponse path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/ServicePrincipals", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listServicePrincipalResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listServicePrincipalResponse) return &listServicePrincipalResponse, err } func (a *accountServicePrincipalsImpl) Patch(ctx context.Context, request PartialUpdate) error { var patchResponse PatchResponse path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/ServicePrincipals/%v", a.client.ConfiguredAccountID(), request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &patchResponse) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &patchResponse) return err } func (a *accountServicePrincipalsImpl) Update(ctx context.Context, request ServicePrincipal) error { var updateResponse UpdateResponse path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/ServicePrincipals/%v", a.client.ConfiguredAccountID(), request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &updateResponse) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &updateResponse) return err } @@ -220,56 +329,106 @@ type accountUsersImpl struct { func (a *accountUsersImpl) Create(ctx context.Context, request User) (*User, error) { var user User path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Users", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &user) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &user) return &user, err } func (a *accountUsersImpl) Delete(ctx context.Context, request DeleteAccountUserRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Users/%v", a.client.ConfiguredAccountID(), request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *accountUsersImpl) Get(ctx context.Context, request GetAccountUserRequest) (*User, error) { var user User path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Users/%v", a.client.ConfiguredAccountID(), request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &user) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &user) return &user, err } -func (a *accountUsersImpl) List(ctx context.Context, request ListAccountUsersRequest) (*ListUsersResponse, error) { +// List users. +// +// Gets details for all the users associated with a Databricks account. +func (a *accountUsersImpl) List(ctx context.Context, request ListAccountUsersRequest) listing.Iterator[User] { + + request.StartIndex = 1 // SCIM offset starts from 1 + if request.Count == 0 { + request.Count = 100 + } + getNextPage := func(ctx context.Context, req ListAccountUsersRequest) (*ListUsersResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListUsersResponse) []User { + return resp.Resources + } + getNextReq := func(resp *ListUsersResponse) *ListAccountUsersRequest { + if len(getItems(resp)) == 0 { + return nil + } + request.StartIndex = resp.StartIndex + int64(len(resp.Resources)) + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + dedupedIterator := listing.NewDedupeIterator[User, string]( + iterator, + func(item User) string { + return item.Id + }) + return dedupedIterator +} + +// List users. +// +// Gets details for all the users associated with a Databricks account. +func (a *accountUsersImpl) ListAll(ctx context.Context, request ListAccountUsersRequest) ([]User, error) { + iterator := a.List(ctx, request) + return listing.ToSliceN[User, int64](ctx, iterator, request.Count) + +} +func (a *accountUsersImpl) internalList(ctx context.Context, request ListAccountUsersRequest) (*ListUsersResponse, error) { var listUsersResponse ListUsersResponse path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Users", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listUsersResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listUsersResponse) return &listUsersResponse, err } func (a *accountUsersImpl) Patch(ctx context.Context, request PartialUpdate) error { var patchResponse PatchResponse path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Users/%v", a.client.ConfiguredAccountID(), request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &patchResponse) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &patchResponse) return err } func (a *accountUsersImpl) Update(ctx context.Context, request User) error { var updateResponse UpdateResponse path := fmt.Sprintf("/api/2.0/accounts/%v/scim/v2/Users/%v", a.client.ConfiguredAccountID(), request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &updateResponse) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &updateResponse) return err } @@ -281,9 +440,10 @@ type currentUserImpl struct { func (a *currentUserImpl) Me(ctx context.Context) (*User, error) { var user User path := "/api/2.0/preview/scim/v2/Me" + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &user) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &user) return &user, err } @@ -295,56 +455,106 @@ type groupsImpl struct { func (a *groupsImpl) Create(ctx context.Context, request Group) (*Group, error) { var group Group path := "/api/2.0/preview/scim/v2/Groups" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &group) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &group) return &group, err } func (a *groupsImpl) Delete(ctx context.Context, request DeleteGroupRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.0/preview/scim/v2/Groups/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *groupsImpl) Get(ctx context.Context, request GetGroupRequest) (*Group, error) { var group Group path := fmt.Sprintf("/api/2.0/preview/scim/v2/Groups/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &group) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &group) return &group, err } -func (a *groupsImpl) List(ctx context.Context, request ListGroupsRequest) (*ListGroupsResponse, error) { +// List group details. +// +// Gets all details of the groups associated with the Databricks workspace. +func (a *groupsImpl) List(ctx context.Context, request ListGroupsRequest) listing.Iterator[Group] { + + request.StartIndex = 1 // SCIM offset starts from 1 + if request.Count == 0 { + request.Count = 100 + } + getNextPage := func(ctx context.Context, req ListGroupsRequest) (*ListGroupsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListGroupsResponse) []Group { + return resp.Resources + } + getNextReq := func(resp *ListGroupsResponse) *ListGroupsRequest { + if len(getItems(resp)) == 0 { + return nil + } + request.StartIndex = resp.StartIndex + int64(len(resp.Resources)) + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + dedupedIterator := listing.NewDedupeIterator[Group, string]( + iterator, + func(item Group) string { + return item.Id + }) + return dedupedIterator +} + +// List group details. +// +// Gets all details of the groups associated with the Databricks workspace. +func (a *groupsImpl) ListAll(ctx context.Context, request ListGroupsRequest) ([]Group, error) { + iterator := a.List(ctx, request) + return listing.ToSliceN[Group, int64](ctx, iterator, request.Count) + +} +func (a *groupsImpl) internalList(ctx context.Context, request ListGroupsRequest) (*ListGroupsResponse, error) { var listGroupsResponse ListGroupsResponse path := "/api/2.0/preview/scim/v2/Groups" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listGroupsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listGroupsResponse) return &listGroupsResponse, err } func (a *groupsImpl) Patch(ctx context.Context, request PartialUpdate) error { var patchResponse PatchResponse path := fmt.Sprintf("/api/2.0/preview/scim/v2/Groups/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &patchResponse) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &patchResponse) return err } func (a *groupsImpl) Update(ctx context.Context, request Group) error { var updateResponse UpdateResponse path := fmt.Sprintf("/api/2.0/preview/scim/v2/Groups/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &updateResponse) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &updateResponse) return err } @@ -356,10 +566,11 @@ type permissionMigrationImpl struct { func (a *permissionMigrationImpl) MigratePermissions(ctx context.Context, request MigratePermissionsRequest) (*MigratePermissionsResponse, error) { var migratePermissionsResponse MigratePermissionsResponse path := "/api/2.0/permissionmigration" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &migratePermissionsResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &migratePermissionsResponse) return &migratePermissionsResponse, err } @@ -371,38 +582,42 @@ type permissionsImpl struct { func (a *permissionsImpl) Get(ctx context.Context, request GetPermissionRequest) (*ObjectPermissions, error) { var objectPermissions ObjectPermissions path := fmt.Sprintf("/api/2.0/permissions/%v/%v", request.RequestObjectType, request.RequestObjectId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &objectPermissions) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, 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) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getPermissionLevelsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getPermissionLevelsResponse) return &getPermissionLevelsResponse, err } func (a *permissionsImpl) Set(ctx context.Context, request PermissionsRequest) (*ObjectPermissions, error) { var objectPermissions ObjectPermissions path := fmt.Sprintf("/api/2.0/permissions/%v/%v", request.RequestObjectType, request.RequestObjectId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &objectPermissions) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &objectPermissions) return &objectPermissions, err } func (a *permissionsImpl) Update(ctx context.Context, request PermissionsRequest) (*ObjectPermissions, error) { var objectPermissions ObjectPermissions path := fmt.Sprintf("/api/2.0/permissions/%v/%v", request.RequestObjectType, request.RequestObjectId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &objectPermissions) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &objectPermissions) return &objectPermissions, err } @@ -414,56 +629,106 @@ type servicePrincipalsImpl struct { func (a *servicePrincipalsImpl) Create(ctx context.Context, request ServicePrincipal) (*ServicePrincipal, error) { var servicePrincipal ServicePrincipal path := "/api/2.0/preview/scim/v2/ServicePrincipals" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &servicePrincipal) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &servicePrincipal) return &servicePrincipal, err } func (a *servicePrincipalsImpl) Delete(ctx context.Context, request DeleteServicePrincipalRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.0/preview/scim/v2/ServicePrincipals/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *servicePrincipalsImpl) Get(ctx context.Context, request GetServicePrincipalRequest) (*ServicePrincipal, error) { var servicePrincipal ServicePrincipal path := fmt.Sprintf("/api/2.0/preview/scim/v2/ServicePrincipals/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &servicePrincipal) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &servicePrincipal) return &servicePrincipal, err } -func (a *servicePrincipalsImpl) List(ctx context.Context, request ListServicePrincipalsRequest) (*ListServicePrincipalResponse, error) { +// List service principals. +// +// Gets the set of service principals associated with a Databricks workspace. +func (a *servicePrincipalsImpl) List(ctx context.Context, request ListServicePrincipalsRequest) listing.Iterator[ServicePrincipal] { + + request.StartIndex = 1 // SCIM offset starts from 1 + if request.Count == 0 { + request.Count = 100 + } + getNextPage := func(ctx context.Context, req ListServicePrincipalsRequest) (*ListServicePrincipalResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListServicePrincipalResponse) []ServicePrincipal { + return resp.Resources + } + getNextReq := func(resp *ListServicePrincipalResponse) *ListServicePrincipalsRequest { + if len(getItems(resp)) == 0 { + return nil + } + request.StartIndex = resp.StartIndex + int64(len(resp.Resources)) + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + dedupedIterator := listing.NewDedupeIterator[ServicePrincipal, string]( + iterator, + func(item ServicePrincipal) string { + return item.Id + }) + return dedupedIterator +} + +// List service principals. +// +// Gets the set of service principals associated with a Databricks workspace. +func (a *servicePrincipalsImpl) ListAll(ctx context.Context, request ListServicePrincipalsRequest) ([]ServicePrincipal, error) { + iterator := a.List(ctx, request) + return listing.ToSliceN[ServicePrincipal, int64](ctx, iterator, request.Count) + +} +func (a *servicePrincipalsImpl) internalList(ctx context.Context, request ListServicePrincipalsRequest) (*ListServicePrincipalResponse, error) { var listServicePrincipalResponse ListServicePrincipalResponse path := "/api/2.0/preview/scim/v2/ServicePrincipals" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listServicePrincipalResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listServicePrincipalResponse) return &listServicePrincipalResponse, err } func (a *servicePrincipalsImpl) Patch(ctx context.Context, request PartialUpdate) error { var patchResponse PatchResponse path := fmt.Sprintf("/api/2.0/preview/scim/v2/ServicePrincipals/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &patchResponse) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &patchResponse) return err } func (a *servicePrincipalsImpl) Update(ctx context.Context, request ServicePrincipal) error { var updateResponse UpdateResponse path := fmt.Sprintf("/api/2.0/preview/scim/v2/ServicePrincipals/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &updateResponse) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &updateResponse) return err } @@ -475,94 +740,148 @@ type usersImpl struct { func (a *usersImpl) Create(ctx context.Context, request User) (*User, error) { var user User path := "/api/2.0/preview/scim/v2/Users" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &user) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &user) return &user, err } func (a *usersImpl) Delete(ctx context.Context, request DeleteUserRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.0/preview/scim/v2/Users/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *usersImpl) Get(ctx context.Context, request GetUserRequest) (*User, error) { var user User path := fmt.Sprintf("/api/2.0/preview/scim/v2/Users/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &user) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &user) return &user, err } func (a *usersImpl) GetPermissionLevels(ctx context.Context) (*GetPasswordPermissionLevelsResponse, error) { var getPasswordPermissionLevelsResponse GetPasswordPermissionLevelsResponse path := "/api/2.0/permissions/authorization/passwords/permissionLevels" + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &getPasswordPermissionLevelsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &getPasswordPermissionLevelsResponse) return &getPasswordPermissionLevelsResponse, err } func (a *usersImpl) GetPermissions(ctx context.Context) (*PasswordPermissions, error) { var passwordPermissions PasswordPermissions path := "/api/2.0/permissions/authorization/passwords" + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &passwordPermissions) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &passwordPermissions) return &passwordPermissions, err } -func (a *usersImpl) List(ctx context.Context, request ListUsersRequest) (*ListUsersResponse, error) { +// List users. +// +// Gets details for all the users associated with a Databricks workspace. +func (a *usersImpl) List(ctx context.Context, request ListUsersRequest) listing.Iterator[User] { + + request.StartIndex = 1 // SCIM offset starts from 1 + if request.Count == 0 { + request.Count = 100 + } + getNextPage := func(ctx context.Context, req ListUsersRequest) (*ListUsersResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListUsersResponse) []User { + return resp.Resources + } + getNextReq := func(resp *ListUsersResponse) *ListUsersRequest { + if len(getItems(resp)) == 0 { + return nil + } + request.StartIndex = resp.StartIndex + int64(len(resp.Resources)) + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + dedupedIterator := listing.NewDedupeIterator[User, string]( + iterator, + func(item User) string { + return item.Id + }) + return dedupedIterator +} + +// List users. +// +// Gets details for all the users associated with a Databricks workspace. +func (a *usersImpl) ListAll(ctx context.Context, request ListUsersRequest) ([]User, error) { + iterator := a.List(ctx, request) + return listing.ToSliceN[User, int64](ctx, iterator, request.Count) + +} +func (a *usersImpl) internalList(ctx context.Context, request ListUsersRequest) (*ListUsersResponse, error) { var listUsersResponse ListUsersResponse path := "/api/2.0/preview/scim/v2/Users" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listUsersResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listUsersResponse) return &listUsersResponse, err } func (a *usersImpl) Patch(ctx context.Context, request PartialUpdate) error { var patchResponse PatchResponse path := fmt.Sprintf("/api/2.0/preview/scim/v2/Users/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &patchResponse) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &patchResponse) return err } func (a *usersImpl) SetPermissions(ctx context.Context, request PasswordPermissionsRequest) (*PasswordPermissions, error) { var passwordPermissions PasswordPermissions path := "/api/2.0/permissions/authorization/passwords" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &passwordPermissions) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &passwordPermissions) return &passwordPermissions, err } func (a *usersImpl) Update(ctx context.Context, request User) error { var updateResponse UpdateResponse path := fmt.Sprintf("/api/2.0/preview/scim/v2/Users/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &updateResponse) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &updateResponse) return err } func (a *usersImpl) UpdatePermissions(ctx context.Context, request PasswordPermissionsRequest) (*PasswordPermissions, error) { var passwordPermissions PasswordPermissions path := "/api/2.0/permissions/authorization/passwords" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &passwordPermissions) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &passwordPermissions) return &passwordPermissions, err } @@ -574,36 +893,70 @@ type workspaceAssignmentImpl struct { func (a *workspaceAssignmentImpl) Delete(ctx context.Context, request DeleteWorkspaceAssignmentRequest) error { var deleteWorkspacePermissionAssignmentResponse DeleteWorkspacePermissionAssignmentResponse path := fmt.Sprintf("/api/2.0/accounts/%v/workspaces/%v/permissionassignments/principals/%v", a.client.ConfiguredAccountID(), request.WorkspaceId, request.PrincipalId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteWorkspacePermissionAssignmentResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteWorkspacePermissionAssignmentResponse) return err } func (a *workspaceAssignmentImpl) Get(ctx context.Context, request GetWorkspaceAssignmentRequest) (*WorkspacePermissions, error) { var workspacePermissions WorkspacePermissions path := fmt.Sprintf("/api/2.0/accounts/%v/workspaces/%v/permissionassignments/permissions", a.client.ConfiguredAccountID(), request.WorkspaceId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &workspacePermissions) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &workspacePermissions) return &workspacePermissions, err } -func (a *workspaceAssignmentImpl) List(ctx context.Context, request ListWorkspaceAssignmentRequest) (*PermissionAssignments, error) { +// Get permission assignments. +// +// Get the permission assignments for the specified Databricks account and +// Databricks workspace. +func (a *workspaceAssignmentImpl) List(ctx context.Context, request ListWorkspaceAssignmentRequest) listing.Iterator[PermissionAssignment] { + + getNextPage := func(ctx context.Context, req ListWorkspaceAssignmentRequest) (*PermissionAssignments, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *PermissionAssignments) []PermissionAssignment { + return resp.PermissionAssignments + } + + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + nil) + return iterator +} + +// Get permission assignments. +// +// Get the permission assignments for the specified Databricks account and +// Databricks workspace. +func (a *workspaceAssignmentImpl) ListAll(ctx context.Context, request ListWorkspaceAssignmentRequest) ([]PermissionAssignment, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[PermissionAssignment](ctx, iterator) +} +func (a *workspaceAssignmentImpl) internalList(ctx context.Context, request ListWorkspaceAssignmentRequest) (*PermissionAssignments, error) { var permissionAssignments PermissionAssignments path := fmt.Sprintf("/api/2.0/accounts/%v/workspaces/%v/permissionassignments", a.client.ConfiguredAccountID(), request.WorkspaceId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &permissionAssignments) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &permissionAssignments) return &permissionAssignments, err } func (a *workspaceAssignmentImpl) Update(ctx context.Context, request UpdateWorkspaceAssignments) (*PermissionAssignment, error) { var permissionAssignment PermissionAssignment path := fmt.Sprintf("/api/2.0/accounts/%v/workspaces/%v/permissionassignments/principals/%v", a.client.ConfiguredAccountID(), request.WorkspaceId, request.PrincipalId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &permissionAssignment) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &permissionAssignment) return &permissionAssignment, err } diff --git a/integration/go.mod b/integration/go.mod index e5e6328ca..cf8f56fd2 100644 --- a/integration/go.mod +++ b/integration/go.mod @@ -84,7 +84,7 @@ require ( go.opentelemetry.io/otel/trace v1.24.0 // indirect golang.org/x/crypto v0.31.0 // indirect golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect - golang.org/x/mod v0.18.0 // indirect + golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.33.0 // indirect golang.org/x/oauth2 v0.25.0 // indirect golang.org/x/sys v0.28.0 // indirect diff --git a/integration/go.sum b/integration/go.sum index a4d27322b..07fab1718 100644 --- a/integration/go.sum +++ b/integration/go.sum @@ -89,8 +89,8 @@ golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0= -golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= diff --git a/jobs/go.mod b/jobs/go.mod index e9f77eacc..5ed337548 100644 --- a/jobs/go.mod +++ b/jobs/go.mod @@ -7,6 +7,7 @@ replace github.com/databricks/databricks-sdk-go/databricks => ../databricks require ( github.com/databricks/databricks-sdk-go/databricks v0.0.0-00010101000000-000000000000 github.com/stretchr/testify v1.10.0 + golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 golang.org/x/oauth2 v0.25.0 ) @@ -30,7 +31,6 @@ require ( go.opentelemetry.io/otel/metric v1.24.0 // indirect go.opentelemetry.io/otel/trace v1.24.0 // indirect golang.org/x/crypto v0.31.0 // indirect - golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.33.0 // indirect golang.org/x/sys v0.28.0 // indirect diff --git a/jobs/v2/api.go b/jobs/v2/api.go index 1aa196137..a27afe016 100755 --- a/jobs/v2/api.go +++ b/jobs/v2/api.go @@ -347,45 +347,6 @@ func (a *JobsAPI) GetRunOutputByRunId(ctx context.Context, runId int64) (*RunOut }) } -// List jobs. -// -// Retrieves a list of jobs. -// -// This method is generated by Databricks SDK Code Generator. -func (a *JobsAPI) List(ctx context.Context, request ListJobsRequest) listing.Iterator[BaseJob] { - - getNextPage := func(ctx context.Context, req ListJobsRequest) (*ListJobsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.jobsImpl.List(ctx, req) - } - getItems := func(resp *ListJobsResponse) []BaseJob { - return resp.Jobs - } - getNextReq := func(resp *ListJobsResponse) *ListJobsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List jobs. -// -// Retrieves a list of jobs. -// -// This method is generated by Databricks SDK Code Generator. -func (a *JobsAPI) ListAll(ctx context.Context, request ListJobsRequest) ([]BaseJob, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[BaseJob](ctx, iterator) -} - // BaseJobSettingsNameToJobIdMap calls [JobsAPI.ListAll] and creates a map of results with [BaseJob].Settings.Name as key and [BaseJob].JobId as value. // // Returns an error if there's more than one [BaseJob] with the same .Settings.Name. @@ -439,45 +400,6 @@ func (a *JobsAPI) GetBySettingsName(ctx context.Context, name string) (*BaseJob, return &alternatives[0], nil } -// List job runs. -// -// List runs in descending order by start time. -// -// This method is generated by Databricks SDK Code Generator. -func (a *JobsAPI) ListRuns(ctx context.Context, request ListRunsRequest) listing.Iterator[BaseRun] { - - getNextPage := func(ctx context.Context, req ListRunsRequest) (*ListRunsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.jobsImpl.ListRuns(ctx, req) - } - getItems := func(resp *ListRunsResponse) []BaseRun { - return resp.Runs - } - getNextReq := func(resp *ListRunsResponse) *ListRunsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List job runs. -// -// List runs in descending order by start time. -// -// This method is generated by Databricks SDK Code Generator. -func (a *JobsAPI) ListRunsAll(ctx context.Context, request ListRunsRequest) ([]BaseRun, error) { - iterator := a.ListRuns(ctx, request) - return listing.ToSlice[BaseRun](ctx, iterator) -} - type PolicyComplianceForJobsInterface interface { // Enforce job policy compliance. @@ -561,48 +483,3 @@ func (a *PolicyComplianceForJobsAPI) GetComplianceByJobId(ctx context.Context, j JobId: jobId, }) } - -// List job policy compliance. -// -// Returns the policy compliance status of all jobs that use a given policy. -// Jobs could be out of compliance if a cluster policy they use was updated -// after the job was last edited and its job clusters no longer comply with the -// updated policy. -// -// This method is generated by Databricks SDK Code Generator. -func (a *PolicyComplianceForJobsAPI) ListCompliance(ctx context.Context, request ListJobComplianceRequest) listing.Iterator[JobCompliance] { - - getNextPage := func(ctx context.Context, req ListJobComplianceRequest) (*ListJobComplianceForPolicyResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.policyComplianceForJobsImpl.ListCompliance(ctx, req) - } - getItems := func(resp *ListJobComplianceForPolicyResponse) []JobCompliance { - return resp.Jobs - } - getNextReq := func(resp *ListJobComplianceForPolicyResponse) *ListJobComplianceRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List job policy compliance. -// -// Returns the policy compliance status of all jobs that use a given policy. -// Jobs could be out of compliance if a cluster policy they use was updated -// after the job was last edited and its job clusters no longer comply with the -// updated policy. -// -// This method is generated by Databricks SDK Code Generator. -func (a *PolicyComplianceForJobsAPI) ListComplianceAll(ctx context.Context, request ListJobComplianceRequest) ([]JobCompliance, error) { - iterator := a.ListCompliance(ctx, request) - return listing.ToSlice[JobCompliance](ctx, iterator) -} diff --git a/jobs/v2/impl.go b/jobs/v2/impl.go index 52ba76298..0c94a3621 100755 --- a/jobs/v2/impl.go +++ b/jobs/v2/impl.go @@ -8,6 +8,8 @@ import ( "net/http" "github.com/databricks/databricks-sdk-go/databricks/client" + "github.com/databricks/databricks-sdk-go/databricks/listing" + "github.com/databricks/databricks-sdk-go/databricks/useragent" ) // unexported type that holds implementations of just Jobs API methods @@ -18,192 +20,280 @@ type jobsImpl struct { func (a *jobsImpl) CancelAllRuns(ctx context.Context, request CancelAllRuns) error { var cancelAllRunsResponse CancelAllRunsResponse path := "/api/2.1/jobs/runs/cancel-all" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &cancelAllRunsResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &cancelAllRunsResponse) return err } func (a *jobsImpl) CancelRun(ctx context.Context, request CancelRun) error { var cancelRunResponse CancelRunResponse path := "/api/2.1/jobs/runs/cancel" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &cancelRunResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &cancelRunResponse) return err } func (a *jobsImpl) Create(ctx context.Context, request CreateJob) (*CreateResponse, error) { var createResponse CreateResponse path := "/api/2.1/jobs/create" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createResponse) return &createResponse, err } func (a *jobsImpl) Delete(ctx context.Context, request DeleteJob) error { var deleteResponse DeleteResponse path := "/api/2.1/jobs/delete" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &deleteResponse) return err } func (a *jobsImpl) DeleteRun(ctx context.Context, request DeleteRun) error { var deleteRunResponse DeleteRunResponse path := "/api/2.1/jobs/runs/delete" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &deleteRunResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &deleteRunResponse) return err } func (a *jobsImpl) ExportRun(ctx context.Context, request ExportRunRequest) (*ExportRunOutput, error) { var exportRunOutput ExportRunOutput path := "/api/2.1/jobs/runs/export" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &exportRunOutput) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &exportRunOutput) return &exportRunOutput, err } func (a *jobsImpl) Get(ctx context.Context, request GetJobRequest) (*Job, error) { var job Job path := "/api/2.1/jobs/get" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &job) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &job) return &job, err } func (a *jobsImpl) GetPermissionLevels(ctx context.Context, request GetJobPermissionLevelsRequest) (*GetJobPermissionLevelsResponse, error) { var getJobPermissionLevelsResponse GetJobPermissionLevelsResponse path := fmt.Sprintf("/api/2.0/permissions/jobs/%v/permissionLevels", request.JobId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getJobPermissionLevelsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getJobPermissionLevelsResponse) return &getJobPermissionLevelsResponse, err } func (a *jobsImpl) GetPermissions(ctx context.Context, request GetJobPermissionsRequest) (*JobPermissions, error) { var jobPermissions JobPermissions path := fmt.Sprintf("/api/2.0/permissions/jobs/%v", request.JobId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &jobPermissions) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &jobPermissions) return &jobPermissions, err } func (a *jobsImpl) GetRun(ctx context.Context, request GetRunRequest) (*Run, error) { var run Run path := "/api/2.1/jobs/runs/get" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &run) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, 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" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &runOutput) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &runOutput) return &runOutput, err } -func (a *jobsImpl) List(ctx context.Context, request ListJobsRequest) (*ListJobsResponse, error) { +// List jobs. +// +// Retrieves a list of jobs. +func (a *jobsImpl) List(ctx context.Context, request ListJobsRequest) listing.Iterator[BaseJob] { + + getNextPage := func(ctx context.Context, req ListJobsRequest) (*ListJobsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListJobsResponse) []BaseJob { + return resp.Jobs + } + getNextReq := func(resp *ListJobsResponse) *ListJobsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List jobs. +// +// Retrieves a list of jobs. +func (a *jobsImpl) ListAll(ctx context.Context, request ListJobsRequest) ([]BaseJob, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[BaseJob](ctx, iterator) +} +func (a *jobsImpl) internalList(ctx context.Context, request ListJobsRequest) (*ListJobsResponse, error) { var listJobsResponse ListJobsResponse path := "/api/2.1/jobs/list" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listJobsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listJobsResponse) return &listJobsResponse, err } -func (a *jobsImpl) ListRuns(ctx context.Context, request ListRunsRequest) (*ListRunsResponse, error) { +// List job runs. +// +// List runs in descending order by start time. +func (a *jobsImpl) ListRuns(ctx context.Context, request ListRunsRequest) listing.Iterator[BaseRun] { + + getNextPage := func(ctx context.Context, req ListRunsRequest) (*ListRunsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalListRuns(ctx, req) + } + getItems := func(resp *ListRunsResponse) []BaseRun { + return resp.Runs + } + getNextReq := func(resp *ListRunsResponse) *ListRunsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List job runs. +// +// List runs in descending order by start time. +func (a *jobsImpl) ListRunsAll(ctx context.Context, request ListRunsRequest) ([]BaseRun, error) { + iterator := a.ListRuns(ctx, request) + return listing.ToSlice[BaseRun](ctx, iterator) +} +func (a *jobsImpl) internalListRuns(ctx context.Context, request ListRunsRequest) (*ListRunsResponse, error) { var listRunsResponse ListRunsResponse path := "/api/2.1/jobs/runs/list" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listRunsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, 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" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &repairRunResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &repairRunResponse) return &repairRunResponse, err } func (a *jobsImpl) Reset(ctx context.Context, request ResetJob) error { var resetResponse ResetResponse path := "/api/2.1/jobs/reset" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &resetResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &resetResponse) return err } func (a *jobsImpl) RunNow(ctx context.Context, request RunNow) (*RunNowResponse, error) { var runNowResponse RunNowResponse path := "/api/2.1/jobs/run-now" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &runNowResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &runNowResponse) return &runNowResponse, err } func (a *jobsImpl) SetPermissions(ctx context.Context, request JobPermissionsRequest) (*JobPermissions, error) { var jobPermissions JobPermissions path := fmt.Sprintf("/api/2.0/permissions/jobs/%v", request.JobId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &jobPermissions) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &jobPermissions) return &jobPermissions, err } func (a *jobsImpl) Submit(ctx context.Context, request SubmitRun) (*SubmitRunResponse, error) { var submitRunResponse SubmitRunResponse path := "/api/2.1/jobs/runs/submit" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &submitRunResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &submitRunResponse) return &submitRunResponse, err } func (a *jobsImpl) Update(ctx context.Context, request UpdateJob) error { var updateResponse UpdateResponse path := "/api/2.1/jobs/update" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &updateResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &updateResponse) return err } func (a *jobsImpl) UpdatePermissions(ctx context.Context, request JobPermissionsRequest) (*JobPermissions, error) { var jobPermissions JobPermissions path := fmt.Sprintf("/api/2.0/permissions/jobs/%v", request.JobId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &jobPermissions) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &jobPermissions) return &jobPermissions, err } @@ -215,27 +305,70 @@ type policyComplianceForJobsImpl struct { func (a *policyComplianceForJobsImpl) EnforceCompliance(ctx context.Context, request EnforcePolicyComplianceRequest) (*EnforcePolicyComplianceResponse, error) { var enforcePolicyComplianceResponse EnforcePolicyComplianceResponse path := "/api/2.0/policies/jobs/enforce-compliance" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &enforcePolicyComplianceResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &enforcePolicyComplianceResponse) return &enforcePolicyComplianceResponse, err } func (a *policyComplianceForJobsImpl) GetCompliance(ctx context.Context, request GetPolicyComplianceRequest) (*GetPolicyComplianceResponse, error) { var getPolicyComplianceResponse GetPolicyComplianceResponse path := "/api/2.0/policies/jobs/get-compliance" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getPolicyComplianceResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getPolicyComplianceResponse) return &getPolicyComplianceResponse, err } -func (a *policyComplianceForJobsImpl) ListCompliance(ctx context.Context, request ListJobComplianceRequest) (*ListJobComplianceForPolicyResponse, error) { +// List job policy compliance. +// +// Returns the policy compliance status of all jobs that use a given policy. +// Jobs could be out of compliance if a cluster policy they use was updated +// after the job was last edited and its job clusters no longer comply with the +// updated policy. +func (a *policyComplianceForJobsImpl) ListCompliance(ctx context.Context, request ListJobComplianceRequest) listing.Iterator[JobCompliance] { + + getNextPage := func(ctx context.Context, req ListJobComplianceRequest) (*ListJobComplianceForPolicyResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalListCompliance(ctx, req) + } + getItems := func(resp *ListJobComplianceForPolicyResponse) []JobCompliance { + return resp.Jobs + } + getNextReq := func(resp *ListJobComplianceForPolicyResponse) *ListJobComplianceRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List job policy compliance. +// +// Returns the policy compliance status of all jobs that use a given policy. +// Jobs could be out of compliance if a cluster policy they use was updated +// after the job was last edited and its job clusters no longer comply with the +// updated policy. +func (a *policyComplianceForJobsImpl) ListComplianceAll(ctx context.Context, request ListJobComplianceRequest) ([]JobCompliance, error) { + iterator := a.ListCompliance(ctx, request) + return listing.ToSlice[JobCompliance](ctx, iterator) +} +func (a *policyComplianceForJobsImpl) internalListCompliance(ctx context.Context, request ListJobComplianceRequest) (*ListJobComplianceForPolicyResponse, error) { var listJobComplianceForPolicyResponse ListJobComplianceForPolicyResponse path := "/api/2.0/policies/jobs/list-compliance" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listJobComplianceForPolicyResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listJobComplianceForPolicyResponse) return &listJobComplianceForPolicyResponse, err } diff --git a/jobs/v2/model.go b/jobs/v2/model.go index eae90edc9..4a12a91a8 100755 --- a/jobs/v2/model.go +++ b/jobs/v2/model.go @@ -8,231 +8,6 @@ import ( "github.com/databricks/databricks-sdk-go/databricks/marshal" ) -type Adlsgen2Info struct { - // abfss destination, e.g. - // `abfss://@.dfs.core.windows.net/`. - Destination string `json:"destination"` -} - -type AutoScale struct { - // The maximum number of workers to which the cluster can scale up when - // overloaded. Note that `max_workers` must be strictly greater than - // `min_workers`. - MaxWorkers int `json:"max_workers,omitempty"` - // The minimum number of workers to which the cluster can scale down when - // underutilized. It is also the initial number of workers the cluster will - // have after creation. - MinWorkers int `json:"min_workers,omitempty"` - - ForceSendFields []string `json:"-"` -} - -func (s *AutoScale) UnmarshalJSON(b []byte) error { - return marshal.Unmarshal(b, s) -} - -func (s AutoScale) MarshalJSON() ([]byte, error) { - return marshal.Marshal(s) -} - -type AwsAttributes struct { - // Availability type used for all subsequent nodes past the - // `first_on_demand` ones. - // - // Note: If `first_on_demand` is zero, this availability type will be used - // for the entire cluster. - Availability AwsAvailability `json:"availability,omitempty"` - // The number of volumes launched for each instance. Users can choose up to - // 10 volumes. This feature is only enabled for supported node types. Legacy - // node types cannot specify custom EBS volumes. For node types with no - // instance store, at least one EBS volume needs to be specified; otherwise, - // cluster creation will fail. - // - // These EBS volumes will be mounted at `/ebs0`, `/ebs1`, and etc. Instance - // store volumes will be mounted at `/local_disk0`, `/local_disk1`, and etc. - // - // If EBS volumes are attached, Databricks will configure Spark to use only - // the EBS volumes for scratch storage because heterogenously sized scratch - // devices can lead to inefficient disk utilization. If no EBS volumes are - // attached, Databricks will configure Spark to use instance store volumes. - // - // Please note that if EBS volumes are specified, then the Spark - // configuration `spark.local.dir` will be overridden. - EbsVolumeCount int `json:"ebs_volume_count,omitempty"` - // If using gp3 volumes, what IOPS to use for the disk. If this is not set, - // the maximum performance of a gp2 volume with the same volume size will be - // used. - EbsVolumeIops int `json:"ebs_volume_iops,omitempty"` - // The size of each EBS volume (in GiB) launched for each instance. For - // general purpose SSD, this value must be within the range 100 - 4096. For - // throughput optimized HDD, this value must be within the range 500 - 4096. - EbsVolumeSize int `json:"ebs_volume_size,omitempty"` - // If using gp3 volumes, what throughput to use for the disk. If this is not - // set, the maximum performance of a gp2 volume with the same volume size - // will be used. - EbsVolumeThroughput int `json:"ebs_volume_throughput,omitempty"` - // The type of EBS volumes that will be launched with this cluster. - EbsVolumeType EbsVolumeType `json:"ebs_volume_type,omitempty"` - // The first `first_on_demand` nodes of the cluster will be placed on - // on-demand instances. If this value is greater than 0, the cluster driver - // node in particular will be placed on an on-demand instance. If this value - // is greater than or equal to the current cluster size, all nodes will be - // placed on on-demand instances. If this value is less than the current - // cluster size, `first_on_demand` nodes will be placed on on-demand - // instances and the remainder will be placed on `availability` instances. - // Note that this value does not affect cluster size and cannot currently be - // mutated over the lifetime of a cluster. - FirstOnDemand int `json:"first_on_demand,omitempty"` - // Nodes for this cluster will only be placed on AWS instances with this - // instance profile. If ommitted, nodes will be placed on instances without - // an IAM instance profile. The instance profile must have previously been - // added to the Databricks environment by an account administrator. - // - // This feature may only be available to certain customer plans. - // - // If this field is ommitted, we will pull in the default from the conf if - // it exists. - InstanceProfileArn string `json:"instance_profile_arn,omitempty"` - // The bid price for AWS spot instances, as a percentage of the - // corresponding instance type's on-demand price. For example, if this field - // is set to 50, and the cluster needs a new `r3.xlarge` spot instance, then - // the bid price is half of the price of on-demand `r3.xlarge` instances. - // Similarly, if this field is set to 200, the bid price is twice the price - // of on-demand `r3.xlarge` instances. If not specified, the default value - // is 100. When spot instances are requested for this cluster, only spot - // instances whose bid price percentage matches this field will be - // considered. Note that, for safety, we enforce this field to be no more - // than 10000. - // - // The default value and documentation here should be kept consistent with - // CommonConf.defaultSpotBidPricePercent and - // CommonConf.maxSpotBidPricePercent. - SpotBidPricePercent int `json:"spot_bid_price_percent,omitempty"` - // Identifier for the availability zone/datacenter in which the cluster - // resides. This string will be of a form like "us-west-2a". The provided - // availability zone must be in the same region as the Databricks - // deployment. For example, "us-west-2a" is not a valid zone id if the - // Databricks deployment resides in the "us-east-1" region. This is an - // optional field at cluster creation, and if not specified, a default zone - // will be used. If the zone specified is "auto", will try to place cluster - // in a zone with high availability, and will retry placement in a different - // AZ if there is not enough capacity. The list of available zones as well - // as the default value can be found by using the `List Zones` method. - ZoneId string `json:"zone_id,omitempty"` - - ForceSendFields []string `json:"-"` -} - -func (s *AwsAttributes) UnmarshalJSON(b []byte) error { - return marshal.Unmarshal(b, s) -} - -func (s AwsAttributes) MarshalJSON() ([]byte, error) { - return marshal.Marshal(s) -} - -// Availability type used for all subsequent nodes past the `first_on_demand` -// ones. -// -// Note: If `first_on_demand` is zero, this availability type will be used for -// the entire cluster. -type AwsAvailability string - -const AwsAvailabilityOnDemand AwsAvailability = `ON_DEMAND` - -const AwsAvailabilitySpot AwsAvailability = `SPOT` - -const AwsAvailabilitySpotWithFallback AwsAvailability = `SPOT_WITH_FALLBACK` - -// String representation for [fmt.Print] -func (f *AwsAvailability) String() string { - return string(*f) -} - -// Set raw string value and validate it against allowed values -func (f *AwsAvailability) Set(v string) error { - switch v { - case `ON_DEMAND`, `SPOT`, `SPOT_WITH_FALLBACK`: - *f = AwsAvailability(v) - return nil - default: - return fmt.Errorf(`value "%s" is not one of "ON_DEMAND", "SPOT", "SPOT_WITH_FALLBACK"`, v) - } -} - -// Type always returns AwsAvailability to satisfy [pflag.Value] interface -func (f *AwsAvailability) Type() string { - return "AwsAvailability" -} - -type AzureAttributes struct { - // Availability type used for all subsequent nodes past the - // `first_on_demand` ones. Note: If `first_on_demand` is zero (which only - // happens on pool clusters), this availability type will be used for the - // entire cluster. - Availability AzureAvailability `json:"availability,omitempty"` - // The first `first_on_demand` nodes of the cluster will be placed on - // on-demand instances. This value should be greater than 0, to make sure - // the cluster driver node is placed on an on-demand instance. If this value - // is greater than or equal to the current cluster size, all nodes will be - // placed on on-demand instances. If this value is less than the current - // cluster size, `first_on_demand` nodes will be placed on on-demand - // instances and the remainder will be placed on `availability` instances. - // Note that this value does not affect cluster size and cannot currently be - // mutated over the lifetime of a cluster. - FirstOnDemand int `json:"first_on_demand,omitempty"` - // Defines values necessary to configure and run Azure Log Analytics agent - LogAnalyticsInfo *LogAnalyticsInfo `json:"log_analytics_info,omitempty"` - // The max bid price to be used for Azure spot instances. The Max price for - // the bid cannot be higher than the on-demand price of the instance. If not - // specified, the default value is -1, which specifies that the instance - // cannot be evicted on the basis of price, and only on the basis of - // availability. Further, the value should > 0 or -1. - SpotBidMaxPrice float64 `json:"spot_bid_max_price,omitempty"` - - ForceSendFields []string `json:"-"` -} - -func (s *AzureAttributes) UnmarshalJSON(b []byte) error { - return marshal.Unmarshal(b, s) -} - -func (s AzureAttributes) MarshalJSON() ([]byte, error) { - return marshal.Marshal(s) -} - -// Availability type used for all subsequent nodes past the `first_on_demand` -// ones. Note: If `first_on_demand` is zero (which only happens on pool -// clusters), this availability type will be used for the entire cluster. -type AzureAvailability string - -const AzureAvailabilityOnDemandAzure AzureAvailability = `ON_DEMAND_AZURE` - -const AzureAvailabilitySpotAzure AzureAvailability = `SPOT_AZURE` - -const AzureAvailabilitySpotWithFallbackAzure AzureAvailability = `SPOT_WITH_FALLBACK_AZURE` - -// String representation for [fmt.Print] -func (f *AzureAvailability) String() string { - return string(*f) -} - -// Set raw string value and validate it against allowed values -func (f *AzureAvailability) Set(v string) error { - switch v { - case `ON_DEMAND_AZURE`, `SPOT_AZURE`, `SPOT_WITH_FALLBACK_AZURE`: - *f = AzureAvailability(v) - return nil - default: - return fmt.Errorf(`value "%s" is not one of "ON_DEMAND_AZURE", "SPOT_AZURE", "SPOT_WITH_FALLBACK_AZURE"`, v) - } -} - -// Type always returns AzureAvailability to satisfy [pflag.Value] interface -func (f *AzureAvailability) Type() string { - return "AzureAvailability" -} - type BaseJob struct { // The time at which this job was created in epoch milliseconds // (milliseconds since 1/1/1970 UTC). @@ -594,23 +369,6 @@ type CleanRoomsNotebookTaskCleanRoomsNotebookTaskOutput struct { OutputSchemaInfo *OutputSchemaInfo `json:"output_schema_info,omitempty"` } -type ClientsTypes struct { - // With jobs set, the cluster can be used for jobs - Jobs bool `json:"jobs,omitempty"` - // With notebooks set, this cluster can be used for notebooks - Notebooks bool `json:"notebooks,omitempty"` - - ForceSendFields []string `json:"-"` -} - -func (s *ClientsTypes) UnmarshalJSON(b []byte) error { - return marshal.Unmarshal(b, s) -} - -func (s ClientsTypes) MarshalJSON() ([]byte, error) { - return marshal.Marshal(s) -} - type ClusterInstance struct { // The canonical identifier for the cluster used by a run. This field is // always available for runs on existing clusters. For runs on new clusters, @@ -642,18 +400,6 @@ func (s ClusterInstance) MarshalJSON() ([]byte, error) { return marshal.Marshal(s) } -type ClusterLogConf struct { - // destination needs to be provided. e.g. `{ "dbfs" : { "destination" : - // "dbfs:/home/cluster_log" } }` - Dbfs *DbfsStorageInfo `json:"dbfs,omitempty"` - // destination and either the region or endpoint need to be provided. e.g. - // `{ "s3": { "destination" : "s3://cluster_log_bucket/prefix", "region" : - // "us-west-2" } }` Cluster iam role is used to access s3, please make sure - // the cluster iam role in `instance_profile_arn` has permission to write - // data to the s3 destination. - S3 *S3StorageInfo `json:"s3,omitempty"` -} - type ClusterSpec struct { // If existing_cluster_id, the ID of an existing cluster that is used for // all runs. When running jobs or tasks on an existing cluster, you may need @@ -933,102 +679,6 @@ type CronSchedule struct { TimezoneId string `json:"timezone_id"` } -// Data security mode decides what data governance model to use when accessing -// data from a cluster. -// -// The following modes can only be used with `kind`. * -// `DATA_SECURITY_MODE_AUTO`: Databricks will choose the most appropriate access -// mode depending on your compute configuration. * -// `DATA_SECURITY_MODE_STANDARD`: Alias for `USER_ISOLATION`. * -// `DATA_SECURITY_MODE_DEDICATED`: Alias for `SINGLE_USER`. -// -// The following modes can be used regardless of `kind`. * `NONE`: No security -// isolation for multiple users sharing the cluster. Data governance features -// are not available in this mode. * `SINGLE_USER`: A secure cluster that can -// only be exclusively used by a single user specified in `single_user_name`. -// Most programming languages, cluster features and data governance features are -// available in this mode. * `USER_ISOLATION`: A secure cluster that can be -// shared by multiple users. Cluster users are fully isolated so that they -// cannot see each other's data and credentials. Most data governance features -// are supported in this mode. But programming languages and cluster features -// might be limited. -// -// The following modes are deprecated starting with Databricks Runtime 15.0 and -// will be removed for future Databricks Runtime versions: -// -// * `LEGACY_TABLE_ACL`: This mode is for users migrating from legacy Table ACL -// clusters. * `LEGACY_PASSTHROUGH`: This mode is for users migrating from -// legacy Passthrough on high concurrency clusters. * `LEGACY_SINGLE_USER`: This -// mode is for users migrating from legacy Passthrough on standard clusters. * -// `LEGACY_SINGLE_USER_STANDARD`: This mode provides a way that doesn’t have -// UC nor passthrough enabled. -type DataSecurityMode string - -// will choose the most appropriate access mode depending on your -// compute configuration. -const DataSecurityModeDataSecurityModeAuto DataSecurityMode = `DATA_SECURITY_MODE_AUTO` - -// Alias for `SINGLE_USER`. -const DataSecurityModeDataSecurityModeDedicated DataSecurityMode = `DATA_SECURITY_MODE_DEDICATED` - -// Alias for `USER_ISOLATION`. -const DataSecurityModeDataSecurityModeStandard DataSecurityMode = `DATA_SECURITY_MODE_STANDARD` - -// This mode is for users migrating from legacy Passthrough on high concurrency -// clusters. -const DataSecurityModeLegacyPassthrough DataSecurityMode = `LEGACY_PASSTHROUGH` - -// This mode is for users migrating from legacy Passthrough on standard -// clusters. -const DataSecurityModeLegacySingleUser DataSecurityMode = `LEGACY_SINGLE_USER` - -// This mode provides a way that doesn’t have UC nor passthrough enabled. -const DataSecurityModeLegacySingleUserStandard DataSecurityMode = `LEGACY_SINGLE_USER_STANDARD` - -// This mode is for users migrating from legacy Table ACL clusters. -const DataSecurityModeLegacyTableAcl DataSecurityMode = `LEGACY_TABLE_ACL` - -// No security isolation for multiple users sharing the cluster. Data governance -// features are not available in this mode. -const DataSecurityModeNone DataSecurityMode = `NONE` - -// A secure cluster that can only be exclusively used by a single user specified -// in `single_user_name`. Most programming languages, cluster features and data -// governance features are available in this mode. -const DataSecurityModeSingleUser DataSecurityMode = `SINGLE_USER` - -// A secure cluster that can be shared by multiple users. Cluster users are -// fully isolated so that they cannot see each other's data and credentials. -// Most data governance features are supported in this mode. But programming -// languages and cluster features might be limited. -const DataSecurityModeUserIsolation DataSecurityMode = `USER_ISOLATION` - -// String representation for [fmt.Print] -func (f *DataSecurityMode) String() string { - return string(*f) -} - -// Set raw string value and validate it against allowed values -func (f *DataSecurityMode) Set(v string) error { - switch v { - case `DATA_SECURITY_MODE_AUTO`, `DATA_SECURITY_MODE_DEDICATED`, `DATA_SECURITY_MODE_STANDARD`, `LEGACY_PASSTHROUGH`, `LEGACY_SINGLE_USER`, `LEGACY_SINGLE_USER_STANDARD`, `LEGACY_TABLE_ACL`, `NONE`, `SINGLE_USER`, `USER_ISOLATION`: - *f = DataSecurityMode(v) - return nil - default: - return fmt.Errorf(`value "%s" is not one of "DATA_SECURITY_MODE_AUTO", "DATA_SECURITY_MODE_DEDICATED", "DATA_SECURITY_MODE_STANDARD", "LEGACY_PASSTHROUGH", "LEGACY_SINGLE_USER", "LEGACY_SINGLE_USER_STANDARD", "LEGACY_TABLE_ACL", "NONE", "SINGLE_USER", "USER_ISOLATION"`, v) - } -} - -// Type always returns DataSecurityMode to satisfy [pflag.Value] interface -func (f *DataSecurityMode) Type() string { - return "DataSecurityMode" -} - -type DbfsStorageInfo struct { - // dbfs destination, e.g. `dbfs:/my/path` - Destination string `json:"destination"` -} - type DbtOutput struct { // An optional map of headers to send when retrieving the artifact from the // `artifacts_link`. @@ -1112,67 +762,6 @@ type DeleteRun struct { type DeleteRunResponse struct { } -type DockerBasicAuth struct { - // Password of the user - Password string `json:"password,omitempty"` - // Name of the user - Username string `json:"username,omitempty"` - - ForceSendFields []string `json:"-"` -} - -func (s *DockerBasicAuth) UnmarshalJSON(b []byte) error { - return marshal.Unmarshal(b, s) -} - -func (s DockerBasicAuth) MarshalJSON() ([]byte, error) { - return marshal.Marshal(s) -} - -type DockerImage struct { - BasicAuth *DockerBasicAuth `json:"basic_auth,omitempty"` - // URL of the docker image. - Url string `json:"url,omitempty"` - - ForceSendFields []string `json:"-"` -} - -func (s *DockerImage) UnmarshalJSON(b []byte) error { - return marshal.Unmarshal(b, s) -} - -func (s DockerImage) MarshalJSON() ([]byte, error) { - return marshal.Marshal(s) -} - -// The type of EBS volumes that will be launched with this cluster. -type EbsVolumeType string - -const EbsVolumeTypeGeneralPurposeSsd EbsVolumeType = `GENERAL_PURPOSE_SSD` - -const EbsVolumeTypeThroughputOptimizedHdd EbsVolumeType = `THROUGHPUT_OPTIMIZED_HDD` - -// String representation for [fmt.Print] -func (f *EbsVolumeType) String() string { - return string(*f) -} - -// Set raw string value and validate it against allowed values -func (f *EbsVolumeType) Set(v string) error { - switch v { - case `GENERAL_PURPOSE_SSD`, `THROUGHPUT_OPTIMIZED_HDD`: - *f = EbsVolumeType(v) - return nil - default: - return fmt.Errorf(`value "%s" is not one of "GENERAL_PURPOSE_SSD", "THROUGHPUT_OPTIMIZED_HDD"`, v) - } -} - -// Type always returns EbsVolumeType to satisfy [pflag.Value] interface -func (f *EbsVolumeType) Type() string { - return "EbsVolumeType" -} - // Represents a change to the job cluster's settings that would be required for // the job clusters to become compliant with their policies. type EnforcePolicyComplianceForJobResponseJobClusterSettingsChange struct { @@ -1409,87 +998,6 @@ func (f *Format) Type() string { return "Format" } -type GcpAttributes struct { - // This field determines whether the instance pool will contain preemptible - // VMs, on-demand VMs, or preemptible VMs with a fallback to on-demand VMs - // if the former is unavailable. - Availability GcpAvailability `json:"availability,omitempty"` - // boot disk size in GB - BootDiskSize int `json:"boot_disk_size,omitempty"` - // If provided, the cluster will impersonate the google service account when - // accessing gcloud services (like GCS). The google service account must - // have previously been added to the Databricks environment by an account - // administrator. - GoogleServiceAccount string `json:"google_service_account,omitempty"` - // If provided, each node (workers and driver) in the cluster will have this - // number of local SSDs attached. Each local SSD is 375GB in size. Refer to - // [GCP documentation] for the supported number of local SSDs for each - // instance type. - // - // [GCP documentation]: https://cloud.google.com/compute/docs/disks/local-ssd#choose_number_local_ssds - LocalSsdCount int `json:"local_ssd_count,omitempty"` - // This field determines whether the spark executors will be scheduled to - // run on preemptible VMs (when set to true) versus standard compute engine - // VMs (when set to false; default). Note: Soon to be deprecated, use the - // availability field instead. - UsePreemptibleExecutors bool `json:"use_preemptible_executors,omitempty"` - // Identifier for the availability zone in which the cluster resides. This - // can be one of the following: - "HA" => High availability, spread nodes - // across availability zones for a Databricks deployment region [default] - - // "AUTO" => Databricks picks an availability zone to schedule the cluster - // on. - A GCP availability zone => Pick One of the available zones for - // (machine type + region) from - // https://cloud.google.com/compute/docs/regions-zones. - ZoneId string `json:"zone_id,omitempty"` - - ForceSendFields []string `json:"-"` -} - -func (s *GcpAttributes) UnmarshalJSON(b []byte) error { - return marshal.Unmarshal(b, s) -} - -func (s GcpAttributes) MarshalJSON() ([]byte, error) { - return marshal.Marshal(s) -} - -// This field determines whether the instance pool will contain preemptible VMs, -// on-demand VMs, or preemptible VMs with a fallback to on-demand VMs if the -// former is unavailable. -type GcpAvailability string - -const GcpAvailabilityOnDemandGcp GcpAvailability = `ON_DEMAND_GCP` - -const GcpAvailabilityPreemptibleGcp GcpAvailability = `PREEMPTIBLE_GCP` - -const GcpAvailabilityPreemptibleWithFallbackGcp GcpAvailability = `PREEMPTIBLE_WITH_FALLBACK_GCP` - -// String representation for [fmt.Print] -func (f *GcpAvailability) String() string { - return string(*f) -} - -// Set raw string value and validate it against allowed values -func (f *GcpAvailability) Set(v string) error { - switch v { - case `ON_DEMAND_GCP`, `PREEMPTIBLE_GCP`, `PREEMPTIBLE_WITH_FALLBACK_GCP`: - *f = GcpAvailability(v) - return nil - default: - return fmt.Errorf(`value "%s" is not one of "ON_DEMAND_GCP", "PREEMPTIBLE_GCP", "PREEMPTIBLE_WITH_FALLBACK_GCP"`, v) - } -} - -// Type always returns GcpAvailability to satisfy [pflag.Value] interface -func (f *GcpAvailability) Type() string { - return "GcpAvailability" -} - -type GcsStorageInfo struct { - // GCS destination/URI, e.g. `gs://my-bucket/some-prefix` - Destination string `json:"destination"` -} - // Get job permission levels type GetJobPermissionLevelsRequest struct { // The job for which to get or manage permissions. @@ -1688,34 +1196,6 @@ func (s GitSource) MarshalJSON() ([]byte, error) { return marshal.Marshal(s) } -type InitScriptInfo struct { - // destination needs to be provided. e.g. `{ "abfss" : { "destination" : - // "abfss://@.dfs.core.windows.net/" - // } } - Abfss *Adlsgen2Info `json:"abfss,omitempty"` - // destination needs to be provided. e.g. `{ "dbfs" : { "destination" : - // "dbfs:/home/cluster_log" } }` - Dbfs *DbfsStorageInfo `json:"dbfs,omitempty"` - // destination needs to be provided. e.g. `{ "file" : { "destination" : - // "file:/my/local/file.sh" } }` - File *LocalFileInfo `json:"file,omitempty"` - // destination needs to be provided. e.g. `{ "gcs": { "destination": - // "gs://my-bucket/file.sh" } }` - Gcs *GcsStorageInfo `json:"gcs,omitempty"` - // destination and either the region or endpoint need to be provided. e.g. - // `{ "s3": { "destination" : "s3://cluster_log_bucket/prefix", "region" : - // "us-west-2" } }` Cluster iam role is used to access s3, please make sure - // the cluster iam role in `instance_profile_arn` has permission to write - // data to the s3 destination. - S3 *S3StorageInfo `json:"s3,omitempty"` - // destination needs to be provided. e.g. `{ "volumes" : { "destination" : - // "/Volumes/my-init.sh" } }` - Volumes *VolumesStorageInfo `json:"volumes,omitempty"` - // destination needs to be provided. e.g. `{ "workspace" : { "destination" : - // "/Users/user1@databricks.com/my-init.sh" } }` - Workspace *WorkspaceStorageInfo `json:"workspace,omitempty"` -} - // Job was retrieved successfully. type Job struct { // The time at which this job was created in epoch milliseconds @@ -1813,7 +1293,7 @@ type JobCluster struct { // determine which cluster to launch for the task execution. JobClusterKey string `json:"job_cluster_key"` // If new_cluster, a description of a cluster that is created for each task. - NewCluster JobsClusterSpec `json:"new_cluster"` + NewCluster ClusterSpec `json:"new_cluster"` } type JobCompliance struct { @@ -2313,194 +1793,6 @@ func (f *JobSourceDirtyState) Type() string { return "JobSourceDirtyState" } -type JobsClusterSpec struct { - // When set to true, fixed and default values from the policy will be used - // for fields that are omitted. When set to false, only fixed values from - // the policy will be applied. - ApplyPolicyDefaultValues bool `json:"apply_policy_default_values,omitempty"` - // Parameters needed in order to automatically scale clusters up and down - // based on load. Note: autoscaling works best with DB runtime versions 3.0 - // or later. - Autoscale *AutoScale `json:"autoscale,omitempty"` - // Automatically terminates the cluster after it is inactive for this time - // in minutes. If not set, this cluster will not be automatically - // terminated. If specified, the threshold must be between 10 and 10000 - // minutes. Users can also set this value to 0 to explicitly disable - // automatic termination. - AutoterminationMinutes int `json:"autotermination_minutes,omitempty"` - // Attributes related to clusters running on Amazon Web Services. If not - // specified at cluster creation, a set of default values will be used. - AwsAttributes *AwsAttributes `json:"aws_attributes,omitempty"` - // Attributes related to clusters running on Microsoft Azure. If not - // specified at cluster creation, a set of default values will be used. - AzureAttributes *AzureAttributes `json:"azure_attributes,omitempty"` - // The configuration for delivering spark logs to a long-term storage - // destination. Two kinds of destinations (dbfs and s3) are supported. Only - // one destination can be specified for one cluster. If the conf is given, - // the logs will be delivered to the destination every `5 mins`. The - // destination of driver logs is `$destination/$clusterId/driver`, while the - // destination of executor logs is `$destination/$clusterId/executor`. - ClusterLogConf *ClusterLogConf `json:"cluster_log_conf,omitempty"` - // Cluster name requested by the user. This doesn't have to be unique. If - // not specified at creation, the cluster name will be an empty string. - ClusterName string `json:"cluster_name,omitempty"` - // Additional tags for cluster resources. Databricks will tag all cluster - // resources (e.g., AWS instances and EBS volumes) with these tags in - // addition to `default_tags`. Notes: - // - // - Currently, Databricks allows at most 45 custom tags - // - // - Clusters can only reuse cloud resources if the resources' tags are a - // subset of the cluster tags - CustomTags map[string]string `json:"custom_tags,omitempty"` - // Data security mode decides what data governance model to use when - // accessing data from a cluster. - // - // The following modes can only be used with `kind`. * - // `DATA_SECURITY_MODE_AUTO`: Databricks will choose the most appropriate - // access mode depending on your compute configuration. * - // `DATA_SECURITY_MODE_STANDARD`: Alias for `USER_ISOLATION`. * - // `DATA_SECURITY_MODE_DEDICATED`: Alias for `SINGLE_USER`. - // - // The following modes can be used regardless of `kind`. * `NONE`: No - // security isolation for multiple users sharing the cluster. Data - // governance features are not available in this mode. * `SINGLE_USER`: A - // secure cluster that can only be exclusively used by a single user - // specified in `single_user_name`. Most programming languages, cluster - // features and data governance features are available in this mode. * - // `USER_ISOLATION`: A secure cluster that can be shared by multiple users. - // Cluster users are fully isolated so that they cannot see each other's - // data and credentials. Most data governance features are supported in this - // mode. But programming languages and cluster features might be limited. - // - // The following modes are deprecated starting with Databricks Runtime 15.0 - // and will be removed for future Databricks Runtime versions: - // - // * `LEGACY_TABLE_ACL`: This mode is for users migrating from legacy Table - // ACL clusters. * `LEGACY_PASSTHROUGH`: This mode is for users migrating - // from legacy Passthrough on high concurrency clusters. * - // `LEGACY_SINGLE_USER`: This mode is for users migrating from legacy - // Passthrough on standard clusters. * `LEGACY_SINGLE_USER_STANDARD`: This - // mode provides a way that doesn’t have UC nor passthrough enabled. - DataSecurityMode DataSecurityMode `json:"data_security_mode,omitempty"` - - DockerImage *DockerImage `json:"docker_image,omitempty"` - // The optional ID of the instance pool for the driver of the cluster - // belongs. The pool cluster uses the instance pool with id - // (instance_pool_id) if the driver pool is not assigned. - DriverInstancePoolId string `json:"driver_instance_pool_id,omitempty"` - // The node type of the Spark driver. Note that this field is optional; if - // unset, the driver node type will be set as the same value as - // `node_type_id` defined above. - DriverNodeTypeId string `json:"driver_node_type_id,omitempty"` - // Autoscaling Local Storage: when enabled, this cluster will dynamically - // acquire additional disk space when its Spark workers are running low on - // disk space. This feature requires specific AWS permissions to function - // correctly - refer to the User Guide for more details. - EnableElasticDisk bool `json:"enable_elastic_disk,omitempty"` - // Whether to enable LUKS on cluster VMs' local disks - EnableLocalDiskEncryption bool `json:"enable_local_disk_encryption,omitempty"` - // Attributes related to clusters running on Google Cloud Platform. If not - // specified at cluster creation, a set of default values will be used. - GcpAttributes *GcpAttributes `json:"gcp_attributes,omitempty"` - // The configuration for storing init scripts. Any number of destinations - // can be specified. The scripts are executed sequentially in the order - // provided. If `cluster_log_conf` is specified, init script logs are sent - // to `//init_scripts`. - InitScripts []InitScriptInfo `json:"init_scripts,omitempty"` - // The optional ID of the instance pool to which the cluster belongs. - InstancePoolId string `json:"instance_pool_id,omitempty"` - // This field can only be used with `kind`. - // - // When set to true, Databricks will automatically set single node related - // `custom_tags`, `spark_conf`, and `num_workers` - IsSingleNode bool `json:"is_single_node,omitempty"` - // The kind of compute described by this compute specification. - // - // Depending on `kind`, different validations and default values will be - // applied. - // - // The first usage of this value is for the simple cluster form where it - // sets `kind = CLASSIC_PREVIEW`. - Kind Kind `json:"kind,omitempty"` - // This field encodes, through a single value, the resources available to - // each of the Spark nodes in this cluster. For example, the Spark nodes can - // be provisioned and optimized for memory or compute intensive workloads. A - // list of available node types can be retrieved by using the - // :method:clusters/listNodeTypes API call. - NodeTypeId string `json:"node_type_id,omitempty"` - // Number of worker nodes that this cluster should have. A cluster has one - // Spark Driver and `num_workers` Executors for a total of `num_workers` + 1 - // Spark nodes. - // - // Note: When reading the properties of a cluster, this field reflects the - // desired number of workers rather than the actual current number of - // workers. For instance, if a cluster is resized from 5 to 10 workers, this - // field will immediately be updated to reflect the target size of 10 - // workers, whereas the workers listed in `spark_info` will gradually - // increase from 5 to 10 as the new nodes are provisioned. - NumWorkers int `json:"num_workers,omitempty"` - // The ID of the cluster policy used to create the cluster if applicable. - PolicyId string `json:"policy_id,omitempty"` - // Determines the cluster's runtime engine, either standard or Photon. - // - // This field is not compatible with legacy `spark_version` values that - // contain `-photon-`. Remove `-photon-` from the `spark_version` and set - // `runtime_engine` to `PHOTON`. - // - // If left unspecified, the runtime engine defaults to standard unless the - // spark_version contains -photon-, in which case Photon will be used. - RuntimeEngine RuntimeEngine `json:"runtime_engine,omitempty"` - // Single user name if data_security_mode is `SINGLE_USER` - SingleUserName string `json:"single_user_name,omitempty"` - // An object containing a set of optional, user-specified Spark - // configuration key-value pairs. Users can also pass in a string of extra - // JVM options to the driver and the executors via - // `spark.driver.extraJavaOptions` and `spark.executor.extraJavaOptions` - // respectively. - SparkConf map[string]string `json:"spark_conf,omitempty"` - // An object containing a set of optional, user-specified environment - // variable key-value pairs. Please note that key-value pair of the form - // (X,Y) will be exported as is (i.e., `export X='Y'`) while launching the - // driver and workers. - // - // In order to specify an additional set of `SPARK_DAEMON_JAVA_OPTS`, we - // recommend appending them to `$SPARK_DAEMON_JAVA_OPTS` as shown in the - // example below. This ensures that all default databricks managed - // environmental variables are included as well. - // - // Example Spark environment variables: `{"SPARK_WORKER_MEMORY": "28000m", - // "SPARK_LOCAL_DIRS": "/local_disk0"}` or `{"SPARK_DAEMON_JAVA_OPTS": - // "$SPARK_DAEMON_JAVA_OPTS -Dspark.shuffle.service.enabled=true"}` - SparkEnvVars map[string]string `json:"spark_env_vars,omitempty"` - // The Spark version of the cluster, e.g. `3.3.x-scala2.11`. A list of - // available Spark versions can be retrieved by using the - // :method:clusters/sparkVersions API call. - SparkVersion string `json:"spark_version,omitempty"` - // SSH public key contents that will be added to each Spark node in this - // cluster. The corresponding private keys can be used to login with the - // user name `ubuntu` on port `2200`. Up to 10 keys can be specified. - SshPublicKeys []string `json:"ssh_public_keys,omitempty"` - // This field can only be used with `kind`. - // - // `effective_spark_version` is determined by `spark_version` (DBR release), - // this field `use_ml_runtime`, and whether `node_type_id` is gpu node or - // not. - UseMlRuntime bool `json:"use_ml_runtime,omitempty"` - - WorkloadType *WorkloadType `json:"workload_type,omitempty"` - - ForceSendFields []string `json:"-"` -} - -func (s *JobsClusterSpec) UnmarshalJSON(b []byte) error { - return marshal.Unmarshal(b, s) -} - -func (s JobsClusterSpec) MarshalJSON() ([]byte, error) { - return marshal.Marshal(s) -} - // Specifies the health metric that is being evaluated for a particular health // rule. // @@ -2609,38 +1901,6 @@ type JobsHealthRules struct { Rules []JobsHealthRule `json:"rules,omitempty"` } -// The kind of compute described by this compute specification. -// -// Depending on `kind`, different validations and default values will be -// applied. -// -// The first usage of this value is for the simple cluster form where it sets -// `kind = CLASSIC_PREVIEW`. -type Kind string - -const KindClassicPreview Kind = `CLASSIC_PREVIEW` - -// String representation for [fmt.Print] -func (f *Kind) String() string { - return string(*f) -} - -// Set raw string value and validate it against allowed values -func (f *Kind) Set(v string) error { - switch v { - case `CLASSIC_PREVIEW`: - *f = Kind(v) - return nil - default: - return fmt.Errorf(`value "%s" is not one of "CLASSIC_PREVIEW"`, v) - } -} - -// Type always returns Kind to satisfy [pflag.Value] interface -func (f *Kind) Type() string { - return "Kind" -} - type Library struct { // Specification of a CRAN library to be installed as part of the library Cran *RCranLibrary `json:"cran,omitempty"` @@ -2865,28 +2125,6 @@ func (s ListRunsResponse) MarshalJSON() ([]byte, error) { return marshal.Marshal(s) } -type LocalFileInfo struct { - // local file destination, e.g. `file:/my/local/file.sh` - Destination string `json:"destination"` -} - -type LogAnalyticsInfo struct { - // - LogAnalyticsPrimaryKey string `json:"log_analytics_primary_key,omitempty"` - // - LogAnalyticsWorkspaceId string `json:"log_analytics_workspace_id,omitempty"` - - ForceSendFields []string `json:"-"` -} - -func (s *LogAnalyticsInfo) UnmarshalJSON(b []byte) error { - return marshal.Unmarshal(b, s) -} - -func (s LogAnalyticsInfo) MarshalJSON() ([]byte, error) { - return marshal.Marshal(s) -} - type MavenLibrary struct { // Gradle-style maven coordinates. For example: "org.jsoup:jsoup:1.7.2". Coordinates string `json:"coordinates"` @@ -4430,6 +3668,9 @@ type RunTask struct { DependsOn []TaskDependency `json:"depends_on,omitempty"` // An optional description for this task. Description string `json:"description,omitempty"` + // Denotes whether or not the task was disabled by the user. Disabled tasks + // do not execute and are immediately skipped as soon as they are unblocked. + Disabled bool `json:"disabled,omitempty"` // effective_performance_target is the actual performance target used by the // run during execution. effective_performance_target can differ from // performance_target depending on if the job was eligible to be @@ -4618,86 +3859,6 @@ func (f *RunType) Type() string { return "RunType" } -// Determines the cluster's runtime engine, either standard or Photon. -// -// This field is not compatible with legacy `spark_version` values that contain -// `-photon-`. Remove `-photon-` from the `spark_version` and set -// `runtime_engine` to `PHOTON`. -// -// If left unspecified, the runtime engine defaults to standard unless the -// spark_version contains -photon-, in which case Photon will be used. -type RuntimeEngine string - -const RuntimeEngineNull RuntimeEngine = `NULL` - -const RuntimeEnginePhoton RuntimeEngine = `PHOTON` - -const RuntimeEngineStandard RuntimeEngine = `STANDARD` - -// String representation for [fmt.Print] -func (f *RuntimeEngine) String() string { - return string(*f) -} - -// Set raw string value and validate it against allowed values -func (f *RuntimeEngine) Set(v string) error { - switch v { - case `NULL`, `PHOTON`, `STANDARD`: - *f = RuntimeEngine(v) - return nil - default: - return fmt.Errorf(`value "%s" is not one of "NULL", "PHOTON", "STANDARD"`, v) - } -} - -// Type always returns RuntimeEngine to satisfy [pflag.Value] interface -func (f *RuntimeEngine) Type() string { - return "RuntimeEngine" -} - -type S3StorageInfo struct { - // (Optional) Set canned access control list for the logs, e.g. - // `bucket-owner-full-control`. If `canned_cal` is set, please make sure the - // cluster iam role has `s3:PutObjectAcl` permission on the destination - // bucket and prefix. The full list of possible canned acl can be found at - // http://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl. - // Please also note that by default only the object owner gets full - // controls. If you are using cross account role for writing data, you may - // want to set `bucket-owner-full-control` to make bucket owner able to read - // the logs. - CannedAcl string `json:"canned_acl,omitempty"` - // S3 destination, e.g. `s3://my-bucket/some-prefix` Note that logs will be - // delivered using cluster iam role, please make sure you set cluster iam - // role and the role has write access to the destination. Please also note - // that you cannot use AWS keys to deliver logs. - Destination string `json:"destination"` - // (Optional) Flag to enable server side encryption, `false` by default. - EnableEncryption bool `json:"enable_encryption,omitempty"` - // (Optional) The encryption type, it could be `sse-s3` or `sse-kms`. It - // will be used only when encryption is enabled and the default type is - // `sse-s3`. - EncryptionType string `json:"encryption_type,omitempty"` - // S3 endpoint, e.g. `https://s3-us-west-2.amazonaws.com`. Either region or - // endpoint needs to be set. If both are set, endpoint will be used. - Endpoint string `json:"endpoint,omitempty"` - // (Optional) Kms key which will be used if encryption is enabled and - // encryption type is set to `sse-kms`. - KmsKey string `json:"kms_key,omitempty"` - // S3 region, e.g. `us-west-2`. Either region or endpoint needs to be set. - // If both are set, endpoint will be used. - Region string `json:"region,omitempty"` - - ForceSendFields []string `json:"-"` -} - -func (s *S3StorageInfo) UnmarshalJSON(b []byte) error { - return marshal.Unmarshal(b, s) -} - -func (s S3StorageInfo) MarshalJSON() ([]byte, error) { - return marshal.Marshal(s) -} - // Optional location type of the SQL file. When set to `WORKSPACE`, the SQL file // will be retrieved\ from the local Databricks workspace. When set to `GIT`, // the SQL file will be retrieved from a Git repository defined in `git_source`. @@ -5238,7 +4399,7 @@ type SubmitTask struct { Libraries []Library `json:"libraries,omitempty"` // If new_cluster, a description of a new cluster that is created for each // run. - NewCluster *JobsClusterSpec `json:"new_cluster,omitempty"` + NewCluster *ClusterSpec `json:"new_cluster,omitempty"` // The task runs a notebook when the `notebook_task` field is present. NotebookTask *NotebookTask `json:"notebook_task,omitempty"` // Optional notification settings that are used when sending notifications @@ -5395,7 +4556,7 @@ type Task struct { MinRetryIntervalMillis int `json:"min_retry_interval_millis,omitempty"` // If new_cluster, a description of a new cluster that is created for each // run. - NewCluster *JobsClusterSpec `json:"new_cluster,omitempty"` + NewCluster *ClusterSpec `json:"new_cluster,omitempty"` // The task runs a notebook when the `notebook_task` field is present. NotebookTask *NotebookTask `json:"notebook_task,omitempty"` // Optional notification settings that are used when sending notifications @@ -6030,11 +5191,6 @@ func (f *ViewsToExport) Type() string { return "ViewsToExport" } -type VolumesStorageInfo struct { - // Unity Catalog Volumes file destination, e.g. `/Volumes/my-init.sh` - Destination string `json:"destination"` -} - type Webhook struct { Id string `json:"id"` } @@ -6065,14 +5221,3 @@ type WebhookNotifications struct { // the `on_success` property. OnSuccess []Webhook `json:"on_success,omitempty"` } - -type WorkloadType struct { - // defined what type of clients can use the cluster. E.g. Notebooks, Jobs - Clients ClientsTypes `json:"clients"` -} - -type WorkspaceStorageInfo struct { - // workspace files destination, e.g. - // `/Users/user1@databricks.com/my-init.sh` - Destination string `json:"destination"` -} diff --git a/marketplace/go.mod b/marketplace/go.mod index 073722ae4..59d653187 100644 --- a/marketplace/go.mod +++ b/marketplace/go.mod @@ -6,6 +6,7 @@ replace github.com/databricks/databricks-sdk-go/databricks => ../databricks require ( github.com/databricks/databricks-sdk-go/databricks v0.0.0-00010101000000-000000000000 + golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 golang.org/x/oauth2 v0.25.0 ) @@ -27,7 +28,6 @@ require ( go.opentelemetry.io/otel/metric v1.24.0 // indirect go.opentelemetry.io/otel/trace v1.24.0 // indirect golang.org/x/crypto v0.31.0 // indirect - golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.33.0 // indirect golang.org/x/sys v0.28.0 // indirect diff --git a/marketplace/v2/api.go b/marketplace/v2/api.go index 6b3351245..dae44f5c4 100755 --- a/marketplace/v2/api.go +++ b/marketplace/v2/api.go @@ -78,101 +78,15 @@ type ConsumerFulfillmentsAPI struct { consumerFulfillmentsImpl } -// Get listing content metadata. -// -// Get a high level preview of the metadata of listing installable content. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ConsumerFulfillmentsAPI) Get(ctx context.Context, request GetListingContentMetadataRequest) listing.Iterator[SharedDataObject] { - - getNextPage := func(ctx context.Context, req GetListingContentMetadataRequest) (*GetListingContentMetadataResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.consumerFulfillmentsImpl.Get(ctx, req) - } - getItems := func(resp *GetListingContentMetadataResponse) []SharedDataObject { - return resp.SharedDataObjects - } - getNextReq := func(resp *GetListingContentMetadataResponse) *GetListingContentMetadataRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// Get listing content metadata. -// -// Get a high level preview of the metadata of listing installable content. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ConsumerFulfillmentsAPI) GetAll(ctx context.Context, request GetListingContentMetadataRequest) ([]SharedDataObject, error) { - iterator := a.Get(ctx, request) - return listing.ToSlice[SharedDataObject](ctx, iterator) -} - // Get listing content metadata. // // Get a high level preview of the metadata of listing installable content. func (a *ConsumerFulfillmentsAPI) GetByListingId(ctx context.Context, listingId string) (*GetListingContentMetadataResponse, error) { - return a.consumerFulfillmentsImpl.Get(ctx, GetListingContentMetadataRequest{ + return a.consumerFulfillmentsImpl.internalGet(ctx, GetListingContentMetadataRequest{ ListingId: listingId, }) } -// List all listing fulfillments. -// -// Get all listings fulfillments associated with a listing. A _fulfillment_ is a -// potential installation. Standard installations contain metadata about the -// attached share or git repo. Only one of these fields will be present. -// Personalized installations contain metadata about the attached share or git -// repo, as well as the Delta Sharing recipient type. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ConsumerFulfillmentsAPI) List(ctx context.Context, request ListFulfillmentsRequest) listing.Iterator[ListingFulfillment] { - - getNextPage := func(ctx context.Context, req ListFulfillmentsRequest) (*ListFulfillmentsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.consumerFulfillmentsImpl.List(ctx, req) - } - getItems := func(resp *ListFulfillmentsResponse) []ListingFulfillment { - return resp.Fulfillments - } - getNextReq := func(resp *ListFulfillmentsResponse) *ListFulfillmentsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List all listing fulfillments. -// -// Get all listings fulfillments associated with a listing. A _fulfillment_ is a -// potential installation. Standard installations contain metadata about the -// attached share or git repo. Only one of these fields will be present. -// Personalized installations contain metadata about the attached share or git -// repo, as well as the Delta Sharing recipient type. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ConsumerFulfillmentsAPI) ListAll(ctx context.Context, request ListFulfillmentsRequest) ([]ListingFulfillment, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[ListingFulfillment](ctx, iterator) -} - // List all listing fulfillments. // // Get all listings fulfillments associated with a listing. A _fulfillment_ is a @@ -181,7 +95,7 @@ func (a *ConsumerFulfillmentsAPI) ListAll(ctx context.Context, request ListFulfi // Personalized installations contain metadata about the attached share or git // repo, as well as the Delta Sharing recipient type. func (a *ConsumerFulfillmentsAPI) ListByListingId(ctx context.Context, listingId string) (*ListFulfillmentsResponse, error) { - return a.consumerFulfillmentsImpl.List(ctx, ListFulfillmentsRequest{ + return a.consumerFulfillmentsImpl.internalList(ctx, ListFulfillmentsRequest{ ListingId: listingId, }) } @@ -270,89 +184,11 @@ func (a *ConsumerInstallationsAPI) DeleteByListingIdAndInstallationId(ctx contex }) } -// List all installations. -// -// List all installations across all listings. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ConsumerInstallationsAPI) List(ctx context.Context, request ListAllInstallationsRequest) listing.Iterator[InstallationDetail] { - - getNextPage := func(ctx context.Context, req ListAllInstallationsRequest) (*ListAllInstallationsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.consumerInstallationsImpl.List(ctx, req) - } - getItems := func(resp *ListAllInstallationsResponse) []InstallationDetail { - return resp.Installations - } - getNextReq := func(resp *ListAllInstallationsResponse) *ListAllInstallationsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List all installations. -// -// List all installations across all listings. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ConsumerInstallationsAPI) ListAll(ctx context.Context, request ListAllInstallationsRequest) ([]InstallationDetail, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[InstallationDetail](ctx, iterator) -} - -// List installations for a listing. -// -// List all installations for a particular listing. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ConsumerInstallationsAPI) ListListingInstallations(ctx context.Context, request ListInstallationsRequest) listing.Iterator[InstallationDetail] { - - getNextPage := func(ctx context.Context, req ListInstallationsRequest) (*ListInstallationsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.consumerInstallationsImpl.ListListingInstallations(ctx, req) - } - getItems := func(resp *ListInstallationsResponse) []InstallationDetail { - return resp.Installations - } - getNextReq := func(resp *ListInstallationsResponse) *ListInstallationsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List installations for a listing. -// -// List all installations for a particular listing. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ConsumerInstallationsAPI) ListListingInstallationsAll(ctx context.Context, request ListInstallationsRequest) ([]InstallationDetail, error) { - iterator := a.ListListingInstallations(ctx, request) - return listing.ToSlice[InstallationDetail](ctx, iterator) -} - // List installations for a listing. // // List all installations for a particular listing. func (a *ConsumerInstallationsAPI) ListListingInstallationsByListingId(ctx context.Context, listingId string) (*ListInstallationsResponse, error) { - return a.consumerInstallationsImpl.ListListingInstallations(ctx, ListInstallationsRequest{ + return a.consumerInstallationsImpl.internalListListingInstallations(ctx, ListInstallationsRequest{ ListingId: listingId, }) } @@ -454,47 +290,6 @@ func (a *ConsumerListingsAPI) GetById(ctx context.Context, id string) (*GetListi }) } -// List listings. -// -// List all published listings in the Databricks Marketplace that the consumer -// has access to. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ConsumerListingsAPI) List(ctx context.Context, request ListListingsRequest) listing.Iterator[Listing] { - - getNextPage := func(ctx context.Context, req ListListingsRequest) (*ListListingsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.consumerListingsImpl.List(ctx, req) - } - getItems := func(resp *ListListingsResponse) []Listing { - return resp.Listings - } - getNextReq := func(resp *ListListingsResponse) *ListListingsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List listings. -// -// List all published listings in the Databricks Marketplace that the consumer -// has access to. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ConsumerListingsAPI) ListAll(ctx context.Context, request ListListingsRequest) ([]Listing, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[Listing](ctx, iterator) -} - // ListingSummaryNameToIdMap calls [ConsumerListingsAPI.ListAll] and creates a map of results with [Listing].Summary.Name as key and [Listing].Id as value. // // Returns an error if there's more than one [Listing] with the same .Summary.Name. @@ -548,49 +343,6 @@ func (a *ConsumerListingsAPI) GetBySummaryName(ctx context.Context, name string) return &alternatives[0], nil } -// Search listings. -// -// Search published listings in the Databricks Marketplace that the consumer has -// access to. This query supports a variety of different search parameters and -// performs fuzzy matching. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ConsumerListingsAPI) Search(ctx context.Context, request SearchListingsRequest) listing.Iterator[Listing] { - - getNextPage := func(ctx context.Context, req SearchListingsRequest) (*SearchListingsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.consumerListingsImpl.Search(ctx, req) - } - getItems := func(resp *SearchListingsResponse) []Listing { - return resp.Listings - } - getNextReq := func(resp *SearchListingsResponse) *SearchListingsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// Search listings. -// -// Search published listings in the Databricks Marketplace that the consumer has -// access to. This query supports a variety of different search parameters and -// performs fuzzy matching. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ConsumerListingsAPI) SearchAll(ctx context.Context, request SearchListingsRequest) ([]Listing, error) { - iterator := a.Search(ctx, request) - return listing.ToSlice[Listing](ctx, iterator) -} - type ConsumerPersonalizationRequestsInterface interface { // Create a personalization request. @@ -649,45 +401,6 @@ func (a *ConsumerPersonalizationRequestsAPI) GetByListingId(ctx context.Context, }) } -// List all personalization requests. -// -// List personalization requests for a consumer across all listings. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ConsumerPersonalizationRequestsAPI) List(ctx context.Context, request ListAllPersonalizationRequestsRequest) listing.Iterator[PersonalizationRequest] { - - getNextPage := func(ctx context.Context, req ListAllPersonalizationRequestsRequest) (*ListAllPersonalizationRequestsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.consumerPersonalizationRequestsImpl.List(ctx, req) - } - getItems := func(resp *ListAllPersonalizationRequestsResponse) []PersonalizationRequest { - return resp.PersonalizationRequests - } - getNextReq := func(resp *ListAllPersonalizationRequestsResponse) *ListAllPersonalizationRequestsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List all personalization requests. -// -// List personalization requests for a consumer across all listings. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ConsumerPersonalizationRequestsAPI) ListAll(ctx context.Context, request ListAllPersonalizationRequestsRequest) ([]PersonalizationRequest, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[PersonalizationRequest](ctx, iterator) -} - type ConsumerProvidersInterface interface { // Get one batch of providers. One may specify up to 50 IDs per request. @@ -766,47 +479,6 @@ func (a *ConsumerProvidersAPI) GetById(ctx context.Context, id string) (*GetProv }) } -// List providers. -// -// List all providers in the Databricks Marketplace with at least one visible -// listing. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ConsumerProvidersAPI) List(ctx context.Context, request ListProvidersRequest) listing.Iterator[ProviderInfo] { - - getNextPage := func(ctx context.Context, req ListProvidersRequest) (*ListProvidersResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.consumerProvidersImpl.List(ctx, req) - } - getItems := func(resp *ListProvidersResponse) []ProviderInfo { - return resp.Providers - } - getNextReq := func(resp *ListProvidersResponse) *ListProvidersRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List providers. -// -// List all providers in the Databricks Marketplace with at least one visible -// listing. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ConsumerProvidersAPI) ListAll(ctx context.Context, request ListProvidersRequest) ([]ProviderInfo, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[ProviderInfo](ctx, iterator) -} - // ProviderInfoNameToIdMap calls [ConsumerProvidersAPI.ListAll] and creates a map of results with [ProviderInfo].Name as key and [ProviderInfo].Id as value. // // Returns an error if there's more than one [ProviderInfo] with the same .Name. @@ -937,45 +609,6 @@ func (a *ProviderExchangeFiltersAPI) DeleteById(ctx context.Context, id string) }) } -// List exchange filters. -// -// # List exchange filter -// -// This method is generated by Databricks SDK Code Generator. -func (a *ProviderExchangeFiltersAPI) List(ctx context.Context, request ListExchangeFiltersRequest) listing.Iterator[ExchangeFilter] { - - getNextPage := func(ctx context.Context, req ListExchangeFiltersRequest) (*ListExchangeFiltersResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.providerExchangeFiltersImpl.List(ctx, req) - } - getItems := func(resp *ListExchangeFiltersResponse) []ExchangeFilter { - return resp.Filters - } - getNextReq := func(resp *ListExchangeFiltersResponse) *ListExchangeFiltersRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List exchange filters. -// -// # List exchange filter -// -// This method is generated by Databricks SDK Code Generator. -func (a *ProviderExchangeFiltersAPI) ListAll(ctx context.Context, request ListExchangeFiltersRequest) ([]ExchangeFilter, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[ExchangeFilter](ctx, iterator) -} - // ExchangeFilterNameToIdMap calls [ProviderExchangeFiltersAPI.ListAll] and creates a map of results with [ExchangeFilter].Name as key and [ExchangeFilter].Id as value. // // Returns an error if there's more than one [ExchangeFilter] with the same .Name. @@ -1214,45 +847,6 @@ func (a *ProviderExchangesAPI) GetById(ctx context.Context, id string) (*GetExch }) } -// List exchanges. -// -// # List exchanges visible to provider -// -// This method is generated by Databricks SDK Code Generator. -func (a *ProviderExchangesAPI) List(ctx context.Context, request ListExchangesRequest) listing.Iterator[Exchange] { - - getNextPage := func(ctx context.Context, req ListExchangesRequest) (*ListExchangesResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.providerExchangesImpl.List(ctx, req) - } - getItems := func(resp *ListExchangesResponse) []Exchange { - return resp.Exchanges - } - getNextReq := func(resp *ListExchangesResponse) *ListExchangesRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List exchanges. -// -// # List exchanges visible to provider -// -// This method is generated by Databricks SDK Code Generator. -func (a *ProviderExchangesAPI) ListAll(ctx context.Context, request ListExchangesRequest) ([]Exchange, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[Exchange](ctx, iterator) -} - // ExchangeNameToIdMap calls [ProviderExchangesAPI.ListAll] and creates a map of results with [Exchange].Name as key and [Exchange].Id as value. // // Returns an error if there's more than one [Exchange] with the same .Name. @@ -1306,45 +900,6 @@ func (a *ProviderExchangesAPI) GetByName(ctx context.Context, name string) (*Exc return &alternatives[0], nil } -// List exchanges for listing. -// -// # List exchanges associated with a listing -// -// This method is generated by Databricks SDK Code Generator. -func (a *ProviderExchangesAPI) ListExchangesForListing(ctx context.Context, request ListExchangesForListingRequest) listing.Iterator[ExchangeListing] { - - getNextPage := func(ctx context.Context, req ListExchangesForListingRequest) (*ListExchangesForListingResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.providerExchangesImpl.ListExchangesForListing(ctx, req) - } - getItems := func(resp *ListExchangesForListingResponse) []ExchangeListing { - return resp.ExchangeListing - } - getNextReq := func(resp *ListExchangesForListingResponse) *ListExchangesForListingRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List exchanges for listing. -// -// # List exchanges associated with a listing -// -// This method is generated by Databricks SDK Code Generator. -func (a *ProviderExchangesAPI) ListExchangesForListingAll(ctx context.Context, request ListExchangesForListingRequest) ([]ExchangeListing, error) { - iterator := a.ListExchangesForListing(ctx, request) - return listing.ToSlice[ExchangeListing](ctx, iterator) -} - // ExchangeListingExchangeNameToExchangeIdMap calls [ProviderExchangesAPI.ListExchangesForListingAll] and creates a map of results with [ExchangeListing].ExchangeName as key and [ExchangeListing].ExchangeId as value. // // Returns an error if there's more than one [ExchangeListing] with the same .ExchangeName. @@ -1398,45 +953,6 @@ func (a *ProviderExchangesAPI) GetByExchangeName(ctx context.Context, name strin return &alternatives[0], nil } -// List listings for exchange. -// -// # List listings associated with an exchange -// -// This method is generated by Databricks SDK Code Generator. -func (a *ProviderExchangesAPI) ListListingsForExchange(ctx context.Context, request ListListingsForExchangeRequest) listing.Iterator[ExchangeListing] { - - getNextPage := func(ctx context.Context, req ListListingsForExchangeRequest) (*ListListingsForExchangeResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.providerExchangesImpl.ListListingsForExchange(ctx, req) - } - getItems := func(resp *ListListingsForExchangeResponse) []ExchangeListing { - return resp.ExchangeListings - } - getNextReq := func(resp *ListListingsForExchangeResponse) *ListListingsForExchangeRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List listings for exchange. -// -// # List listings associated with an exchange -// -// This method is generated by Databricks SDK Code Generator. -func (a *ProviderExchangesAPI) ListListingsForExchangeAll(ctx context.Context, request ListListingsForExchangeRequest) ([]ExchangeListing, error) { - iterator := a.ListListingsForExchange(ctx, request) - return listing.ToSlice[ExchangeListing](ctx, iterator) -} - // ExchangeListingListingNameToListingIdMap calls [ProviderExchangesAPI.ListListingsForExchangeAll] and creates a map of results with [ExchangeListing].ListingName as key and [ExchangeListing].ListingId as value. // // Returns an error if there's more than one [ExchangeListing] with the same .ListingName. @@ -1583,45 +1099,6 @@ func (a *ProviderFilesAPI) GetByFileId(ctx context.Context, fileId string) (*Get }) } -// List files. -// -// List files attached to a parent entity. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ProviderFilesAPI) List(ctx context.Context, request ListFilesRequest) listing.Iterator[FileInfo] { - - getNextPage := func(ctx context.Context, req ListFilesRequest) (*ListFilesResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.providerFilesImpl.List(ctx, req) - } - getItems := func(resp *ListFilesResponse) []FileInfo { - return resp.FileInfos - } - getNextReq := func(resp *ListFilesResponse) *ListFilesRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List files. -// -// List files attached to a parent entity. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ProviderFilesAPI) ListAll(ctx context.Context, request ListFilesRequest) ([]FileInfo, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[FileInfo](ctx, iterator) -} - // FileInfoDisplayNameToIdMap calls [ProviderFilesAPI.ListAll] and creates a map of results with [FileInfo].DisplayName as key and [FileInfo].Id as value. // // Returns an error if there's more than one [FileInfo] with the same .DisplayName. @@ -1772,45 +1249,6 @@ func (a *ProviderListingsAPI) GetById(ctx context.Context, id string) (*GetListi }) } -// List listings. -// -// # List listings owned by this provider -// -// This method is generated by Databricks SDK Code Generator. -func (a *ProviderListingsAPI) List(ctx context.Context, request GetListingsRequest) listing.Iterator[Listing] { - - getNextPage := func(ctx context.Context, req GetListingsRequest) (*GetListingsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.providerListingsImpl.List(ctx, req) - } - getItems := func(resp *GetListingsResponse) []Listing { - return resp.Listings - } - getNextReq := func(resp *GetListingsResponse) *GetListingsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List listings. -// -// # List listings owned by this provider -// -// This method is generated by Databricks SDK Code Generator. -func (a *ProviderListingsAPI) ListAll(ctx context.Context, request GetListingsRequest) ([]Listing, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[Listing](ctx, iterator) -} - // ListingSummaryNameToIdMap calls [ProviderListingsAPI.ListAll] and creates a map of results with [Listing].Summary.Name as key and [Listing].Id as value. // // Returns an error if there's more than one [Listing] with the same .Summary.Name. @@ -1903,47 +1341,6 @@ type ProviderPersonalizationRequestsAPI struct { providerPersonalizationRequestsImpl } -// All personalization requests across all listings. -// -// List personalization requests to this provider. This will return all -// personalization requests, regardless of which listing they are for. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ProviderPersonalizationRequestsAPI) List(ctx context.Context, request ListAllPersonalizationRequestsRequest) listing.Iterator[PersonalizationRequest] { - - getNextPage := func(ctx context.Context, req ListAllPersonalizationRequestsRequest) (*ListAllPersonalizationRequestsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.providerPersonalizationRequestsImpl.List(ctx, req) - } - getItems := func(resp *ListAllPersonalizationRequestsResponse) []PersonalizationRequest { - return resp.PersonalizationRequests - } - getNextReq := func(resp *ListAllPersonalizationRequestsResponse) *ListAllPersonalizationRequestsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// All personalization requests across all listings. -// -// List personalization requests to this provider. This will return all -// personalization requests, regardless of which listing they are for. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ProviderPersonalizationRequestsAPI) ListAll(ctx context.Context, request ListAllPersonalizationRequestsRequest) ([]PersonalizationRequest, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[PersonalizationRequest](ctx, iterator) -} - type ProviderProviderAnalyticsDashboardsInterface interface { // Create provider analytics dashboard. @@ -2077,45 +1474,6 @@ func (a *ProviderProvidersAPI) GetById(ctx context.Context, id string) (*GetProv }) } -// List providers. -// -// List provider profiles for account. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ProviderProvidersAPI) List(ctx context.Context, request ListProvidersRequest) listing.Iterator[ProviderInfo] { - - getNextPage := func(ctx context.Context, req ListProvidersRequest) (*ListProvidersResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.providerProvidersImpl.List(ctx, req) - } - getItems := func(resp *ListProvidersResponse) []ProviderInfo { - return resp.Providers - } - getNextReq := func(resp *ListProvidersResponse) *ListProvidersRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List providers. -// -// List provider profiles for account. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ProviderProvidersAPI) ListAll(ctx context.Context, request ListProvidersRequest) ([]ProviderInfo, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[ProviderInfo](ctx, iterator) -} - // ProviderInfoNameToIdMap calls [ProviderProvidersAPI.ListAll] and creates a map of results with [ProviderInfo].Name as key and [ProviderInfo].Id as value. // // Returns an error if there's more than one [ProviderInfo] with the same .Name. diff --git a/marketplace/v2/impl.go b/marketplace/v2/impl.go index cc00e5cd5..9550228c4 100755 --- a/marketplace/v2/impl.go +++ b/marketplace/v2/impl.go @@ -8,6 +8,8 @@ import ( "net/http" "github.com/databricks/databricks-sdk-go/databricks/client" + "github.com/databricks/databricks-sdk-go/databricks/listing" + "github.com/databricks/databricks-sdk-go/databricks/useragent" ) // unexported type that holds implementations of just ConsumerFulfillments API methods @@ -15,21 +17,99 @@ type consumerFulfillmentsImpl struct { client *client.DatabricksClient } -func (a *consumerFulfillmentsImpl) Get(ctx context.Context, request GetListingContentMetadataRequest) (*GetListingContentMetadataResponse, error) { +// Get listing content metadata. +// +// Get a high level preview of the metadata of listing installable content. +func (a *consumerFulfillmentsImpl) Get(ctx context.Context, request GetListingContentMetadataRequest) listing.Iterator[SharedDataObject] { + + getNextPage := func(ctx context.Context, req GetListingContentMetadataRequest) (*GetListingContentMetadataResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalGet(ctx, req) + } + getItems := func(resp *GetListingContentMetadataResponse) []SharedDataObject { + return resp.SharedDataObjects + } + getNextReq := func(resp *GetListingContentMetadataResponse) *GetListingContentMetadataRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// Get listing content metadata. +// +// Get a high level preview of the metadata of listing installable content. +func (a *consumerFulfillmentsImpl) GetAll(ctx context.Context, request GetListingContentMetadataRequest) ([]SharedDataObject, error) { + iterator := a.Get(ctx, request) + return listing.ToSlice[SharedDataObject](ctx, iterator) +} +func (a *consumerFulfillmentsImpl) internalGet(ctx context.Context, request GetListingContentMetadataRequest) (*GetListingContentMetadataResponse, error) { var getListingContentMetadataResponse GetListingContentMetadataResponse path := fmt.Sprintf("/api/2.1/marketplace-consumer/listings/%v/content", request.ListingId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getListingContentMetadataResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getListingContentMetadataResponse) return &getListingContentMetadataResponse, err } -func (a *consumerFulfillmentsImpl) List(ctx context.Context, request ListFulfillmentsRequest) (*ListFulfillmentsResponse, error) { +// List all listing fulfillments. +// +// Get all listings fulfillments associated with a listing. A _fulfillment_ is a +// potential installation. Standard installations contain metadata about the +// attached share or git repo. Only one of these fields will be present. +// Personalized installations contain metadata about the attached share or git +// repo, as well as the Delta Sharing recipient type. +func (a *consumerFulfillmentsImpl) List(ctx context.Context, request ListFulfillmentsRequest) listing.Iterator[ListingFulfillment] { + + getNextPage := func(ctx context.Context, req ListFulfillmentsRequest) (*ListFulfillmentsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListFulfillmentsResponse) []ListingFulfillment { + return resp.Fulfillments + } + getNextReq := func(resp *ListFulfillmentsResponse) *ListFulfillmentsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List all listing fulfillments. +// +// Get all listings fulfillments associated with a listing. A _fulfillment_ is a +// potential installation. Standard installations contain metadata about the +// attached share or git repo. Only one of these fields will be present. +// Personalized installations contain metadata about the attached share or git +// repo, as well as the Delta Sharing recipient type. +func (a *consumerFulfillmentsImpl) ListAll(ctx context.Context, request ListFulfillmentsRequest) ([]ListingFulfillment, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[ListingFulfillment](ctx, iterator) +} +func (a *consumerFulfillmentsImpl) internalList(ctx context.Context, request ListFulfillmentsRequest) (*ListFulfillmentsResponse, error) { var listFulfillmentsResponse ListFulfillmentsResponse path := fmt.Sprintf("/api/2.1/marketplace-consumer/listings/%v/fulfillments", request.ListingId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listFulfillmentsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listFulfillmentsResponse) return &listFulfillmentsResponse, err } @@ -41,47 +121,120 @@ type consumerInstallationsImpl struct { func (a *consumerInstallationsImpl) Create(ctx context.Context, request CreateInstallationRequest) (*Installation, error) { var installation Installation path := fmt.Sprintf("/api/2.1/marketplace-consumer/listings/%v/installations", request.ListingId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &installation) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &installation) return &installation, err } func (a *consumerInstallationsImpl) Delete(ctx context.Context, request DeleteInstallationRequest) error { var deleteInstallationResponse DeleteInstallationResponse path := fmt.Sprintf("/api/2.1/marketplace-consumer/listings/%v/installations/%v", request.ListingId, request.InstallationId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteInstallationResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteInstallationResponse) return err } -func (a *consumerInstallationsImpl) List(ctx context.Context, request ListAllInstallationsRequest) (*ListAllInstallationsResponse, error) { +// List all installations. +// +// List all installations across all listings. +func (a *consumerInstallationsImpl) List(ctx context.Context, request ListAllInstallationsRequest) listing.Iterator[InstallationDetail] { + + getNextPage := func(ctx context.Context, req ListAllInstallationsRequest) (*ListAllInstallationsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListAllInstallationsResponse) []InstallationDetail { + return resp.Installations + } + getNextReq := func(resp *ListAllInstallationsResponse) *ListAllInstallationsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List all installations. +// +// List all installations across all listings. +func (a *consumerInstallationsImpl) ListAll(ctx context.Context, request ListAllInstallationsRequest) ([]InstallationDetail, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[InstallationDetail](ctx, iterator) +} +func (a *consumerInstallationsImpl) internalList(ctx context.Context, request ListAllInstallationsRequest) (*ListAllInstallationsResponse, error) { var listAllInstallationsResponse ListAllInstallationsResponse path := "/api/2.1/marketplace-consumer/installations" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listAllInstallationsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listAllInstallationsResponse) return &listAllInstallationsResponse, err } -func (a *consumerInstallationsImpl) ListListingInstallations(ctx context.Context, request ListInstallationsRequest) (*ListInstallationsResponse, error) { +// List installations for a listing. +// +// List all installations for a particular listing. +func (a *consumerInstallationsImpl) ListListingInstallations(ctx context.Context, request ListInstallationsRequest) listing.Iterator[InstallationDetail] { + + getNextPage := func(ctx context.Context, req ListInstallationsRequest) (*ListInstallationsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalListListingInstallations(ctx, req) + } + getItems := func(resp *ListInstallationsResponse) []InstallationDetail { + return resp.Installations + } + getNextReq := func(resp *ListInstallationsResponse) *ListInstallationsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List installations for a listing. +// +// List all installations for a particular listing. +func (a *consumerInstallationsImpl) ListListingInstallationsAll(ctx context.Context, request ListInstallationsRequest) ([]InstallationDetail, error) { + iterator := a.ListListingInstallations(ctx, request) + return listing.ToSlice[InstallationDetail](ctx, iterator) +} +func (a *consumerInstallationsImpl) internalListListingInstallations(ctx context.Context, request ListInstallationsRequest) (*ListInstallationsResponse, error) { var listInstallationsResponse ListInstallationsResponse path := fmt.Sprintf("/api/2.1/marketplace-consumer/listings/%v/installations", request.ListingId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listInstallationsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listInstallationsResponse) return &listInstallationsResponse, err } func (a *consumerInstallationsImpl) Update(ctx context.Context, request UpdateInstallationRequest) (*UpdateInstallationResponse, error) { var updateInstallationResponse UpdateInstallationResponse path := fmt.Sprintf("/api/2.1/marketplace-consumer/listings/%v/installations/%v", request.ListingId, request.InstallationId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &updateInstallationResponse) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &updateInstallationResponse) return &updateInstallationResponse, err } @@ -93,36 +246,114 @@ type consumerListingsImpl struct { func (a *consumerListingsImpl) BatchGet(ctx context.Context, request BatchGetListingsRequest) (*BatchGetListingsResponse, error) { var batchGetListingsResponse BatchGetListingsResponse path := "/api/2.1/marketplace-consumer/listings:batchGet" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &batchGetListingsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &batchGetListingsResponse) return &batchGetListingsResponse, err } func (a *consumerListingsImpl) Get(ctx context.Context, request GetListingRequest) (*GetListingResponse, error) { var getListingResponse GetListingResponse path := fmt.Sprintf("/api/2.1/marketplace-consumer/listings/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getListingResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getListingResponse) return &getListingResponse, err } -func (a *consumerListingsImpl) List(ctx context.Context, request ListListingsRequest) (*ListListingsResponse, error) { +// List listings. +// +// List all published listings in the Databricks Marketplace that the consumer +// has access to. +func (a *consumerListingsImpl) List(ctx context.Context, request ListListingsRequest) listing.Iterator[Listing] { + + getNextPage := func(ctx context.Context, req ListListingsRequest) (*ListListingsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListListingsResponse) []Listing { + return resp.Listings + } + getNextReq := func(resp *ListListingsResponse) *ListListingsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List listings. +// +// List all published listings in the Databricks Marketplace that the consumer +// has access to. +func (a *consumerListingsImpl) ListAll(ctx context.Context, request ListListingsRequest) ([]Listing, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[Listing](ctx, iterator) +} +func (a *consumerListingsImpl) internalList(ctx context.Context, request ListListingsRequest) (*ListListingsResponse, error) { var listListingsResponse ListListingsResponse path := "/api/2.1/marketplace-consumer/listings" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listListingsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listListingsResponse) return &listListingsResponse, err } -func (a *consumerListingsImpl) Search(ctx context.Context, request SearchListingsRequest) (*SearchListingsResponse, error) { +// Search listings. +// +// Search published listings in the Databricks Marketplace that the consumer has +// access to. This query supports a variety of different search parameters and +// performs fuzzy matching. +func (a *consumerListingsImpl) Search(ctx context.Context, request SearchListingsRequest) listing.Iterator[Listing] { + + getNextPage := func(ctx context.Context, req SearchListingsRequest) (*SearchListingsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalSearch(ctx, req) + } + getItems := func(resp *SearchListingsResponse) []Listing { + return resp.Listings + } + getNextReq := func(resp *SearchListingsResponse) *SearchListingsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// Search listings. +// +// Search published listings in the Databricks Marketplace that the consumer has +// access to. This query supports a variety of different search parameters and +// performs fuzzy matching. +func (a *consumerListingsImpl) SearchAll(ctx context.Context, request SearchListingsRequest) ([]Listing, error) { + iterator := a.Search(ctx, request) + return listing.ToSlice[Listing](ctx, iterator) +} +func (a *consumerListingsImpl) internalSearch(ctx context.Context, request SearchListingsRequest) (*SearchListingsResponse, error) { var searchListingsResponse SearchListingsResponse path := "/api/2.1/marketplace-consumer/search-listings" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &searchListingsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &searchListingsResponse) return &searchListingsResponse, err } @@ -134,28 +365,65 @@ type consumerPersonalizationRequestsImpl struct { func (a *consumerPersonalizationRequestsImpl) Create(ctx context.Context, request CreatePersonalizationRequest) (*CreatePersonalizationRequestResponse, error) { var createPersonalizationRequestResponse CreatePersonalizationRequestResponse path := fmt.Sprintf("/api/2.1/marketplace-consumer/listings/%v/personalization-requests", request.ListingId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createPersonalizationRequestResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createPersonalizationRequestResponse) return &createPersonalizationRequestResponse, err } func (a *consumerPersonalizationRequestsImpl) Get(ctx context.Context, request GetPersonalizationRequestRequest) (*GetPersonalizationRequestResponse, error) { var getPersonalizationRequestResponse GetPersonalizationRequestResponse path := fmt.Sprintf("/api/2.1/marketplace-consumer/listings/%v/personalization-requests", request.ListingId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getPersonalizationRequestResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getPersonalizationRequestResponse) return &getPersonalizationRequestResponse, err } -func (a *consumerPersonalizationRequestsImpl) List(ctx context.Context, request ListAllPersonalizationRequestsRequest) (*ListAllPersonalizationRequestsResponse, error) { +// List all personalization requests. +// +// List personalization requests for a consumer across all listings. +func (a *consumerPersonalizationRequestsImpl) List(ctx context.Context, request ListAllPersonalizationRequestsRequest) listing.Iterator[PersonalizationRequest] { + + getNextPage := func(ctx context.Context, req ListAllPersonalizationRequestsRequest) (*ListAllPersonalizationRequestsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListAllPersonalizationRequestsResponse) []PersonalizationRequest { + return resp.PersonalizationRequests + } + getNextReq := func(resp *ListAllPersonalizationRequestsResponse) *ListAllPersonalizationRequestsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List all personalization requests. +// +// List personalization requests for a consumer across all listings. +func (a *consumerPersonalizationRequestsImpl) ListAll(ctx context.Context, request ListAllPersonalizationRequestsRequest) ([]PersonalizationRequest, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[PersonalizationRequest](ctx, iterator) +} +func (a *consumerPersonalizationRequestsImpl) internalList(ctx context.Context, request ListAllPersonalizationRequestsRequest) (*ListAllPersonalizationRequestsResponse, error) { var listAllPersonalizationRequestsResponse ListAllPersonalizationRequestsResponse path := "/api/2.1/marketplace-consumer/personalization-requests" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listAllPersonalizationRequestsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listAllPersonalizationRequestsResponse) return &listAllPersonalizationRequestsResponse, err } @@ -167,27 +435,66 @@ type consumerProvidersImpl struct { func (a *consumerProvidersImpl) BatchGet(ctx context.Context, request BatchGetProvidersRequest) (*BatchGetProvidersResponse, error) { var batchGetProvidersResponse BatchGetProvidersResponse path := "/api/2.1/marketplace-consumer/providers:batchGet" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &batchGetProvidersResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &batchGetProvidersResponse) return &batchGetProvidersResponse, err } func (a *consumerProvidersImpl) Get(ctx context.Context, request GetProviderRequest) (*GetProviderResponse, error) { var getProviderResponse GetProviderResponse path := fmt.Sprintf("/api/2.1/marketplace-consumer/providers/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getProviderResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getProviderResponse) return &getProviderResponse, err } -func (a *consumerProvidersImpl) List(ctx context.Context, request ListProvidersRequest) (*ListProvidersResponse, error) { +// List providers. +// +// List all providers in the Databricks Marketplace with at least one visible +// listing. +func (a *consumerProvidersImpl) List(ctx context.Context, request ListProvidersRequest) listing.Iterator[ProviderInfo] { + + getNextPage := func(ctx context.Context, req ListProvidersRequest) (*ListProvidersResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListProvidersResponse) []ProviderInfo { + return resp.Providers + } + getNextReq := func(resp *ListProvidersResponse) *ListProvidersRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List providers. +// +// List all providers in the Databricks Marketplace with at least one visible +// listing. +func (a *consumerProvidersImpl) ListAll(ctx context.Context, request ListProvidersRequest) ([]ProviderInfo, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[ProviderInfo](ctx, iterator) +} +func (a *consumerProvidersImpl) internalList(ctx context.Context, request ListProvidersRequest) (*ListProvidersResponse, error) { var listProvidersResponse ListProvidersResponse path := "/api/2.1/marketplace-consumer/providers" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listProvidersResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listProvidersResponse) return &listProvidersResponse, err } @@ -199,38 +506,76 @@ type providerExchangeFiltersImpl struct { func (a *providerExchangeFiltersImpl) Create(ctx context.Context, request CreateExchangeFilterRequest) (*CreateExchangeFilterResponse, error) { var createExchangeFilterResponse CreateExchangeFilterResponse path := "/api/2.0/marketplace-exchange/filters" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createExchangeFilterResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createExchangeFilterResponse) return &createExchangeFilterResponse, err } func (a *providerExchangeFiltersImpl) Delete(ctx context.Context, request DeleteExchangeFilterRequest) error { var deleteExchangeFilterResponse DeleteExchangeFilterResponse path := fmt.Sprintf("/api/2.0/marketplace-exchange/filters/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteExchangeFilterResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteExchangeFilterResponse) return err } -func (a *providerExchangeFiltersImpl) List(ctx context.Context, request ListExchangeFiltersRequest) (*ListExchangeFiltersResponse, error) { +// List exchange filters. +// +// List exchange filter +func (a *providerExchangeFiltersImpl) List(ctx context.Context, request ListExchangeFiltersRequest) listing.Iterator[ExchangeFilter] { + + getNextPage := func(ctx context.Context, req ListExchangeFiltersRequest) (*ListExchangeFiltersResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListExchangeFiltersResponse) []ExchangeFilter { + return resp.Filters + } + getNextReq := func(resp *ListExchangeFiltersResponse) *ListExchangeFiltersRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List exchange filters. +// +// List exchange filter +func (a *providerExchangeFiltersImpl) ListAll(ctx context.Context, request ListExchangeFiltersRequest) ([]ExchangeFilter, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[ExchangeFilter](ctx, iterator) +} +func (a *providerExchangeFiltersImpl) internalList(ctx context.Context, request ListExchangeFiltersRequest) (*ListExchangeFiltersResponse, error) { var listExchangeFiltersResponse ListExchangeFiltersResponse path := "/api/2.0/marketplace-exchange/filters" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listExchangeFiltersResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listExchangeFiltersResponse) return &listExchangeFiltersResponse, err } func (a *providerExchangeFiltersImpl) Update(ctx context.Context, request UpdateExchangeFilterRequest) (*UpdateExchangeFilterResponse, error) { var updateExchangeFilterResponse UpdateExchangeFilterResponse path := fmt.Sprintf("/api/2.0/marketplace-exchange/filters/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &updateExchangeFilterResponse) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &updateExchangeFilterResponse) return &updateExchangeFilterResponse, err } @@ -242,84 +587,195 @@ type providerExchangesImpl struct { func (a *providerExchangesImpl) AddListingToExchange(ctx context.Context, request AddExchangeForListingRequest) (*AddExchangeForListingResponse, error) { var addExchangeForListingResponse AddExchangeForListingResponse path := "/api/2.0/marketplace-exchange/exchanges-for-listing" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &addExchangeForListingResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &addExchangeForListingResponse) return &addExchangeForListingResponse, err } func (a *providerExchangesImpl) Create(ctx context.Context, request CreateExchangeRequest) (*CreateExchangeResponse, error) { var createExchangeResponse CreateExchangeResponse path := "/api/2.0/marketplace-exchange/exchanges" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createExchangeResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createExchangeResponse) return &createExchangeResponse, err } func (a *providerExchangesImpl) Delete(ctx context.Context, request DeleteExchangeRequest) error { var deleteExchangeResponse DeleteExchangeResponse path := fmt.Sprintf("/api/2.0/marketplace-exchange/exchanges/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteExchangeResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteExchangeResponse) return err } func (a *providerExchangesImpl) DeleteListingFromExchange(ctx context.Context, request RemoveExchangeForListingRequest) error { var removeExchangeForListingResponse RemoveExchangeForListingResponse path := fmt.Sprintf("/api/2.0/marketplace-exchange/exchanges-for-listing/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &removeExchangeForListingResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &removeExchangeForListingResponse) return err } func (a *providerExchangesImpl) Get(ctx context.Context, request GetExchangeRequest) (*GetExchangeResponse, error) { var getExchangeResponse GetExchangeResponse path := fmt.Sprintf("/api/2.0/marketplace-exchange/exchanges/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getExchangeResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getExchangeResponse) return &getExchangeResponse, err } -func (a *providerExchangesImpl) List(ctx context.Context, request ListExchangesRequest) (*ListExchangesResponse, error) { +// List exchanges. +// +// List exchanges visible to provider +func (a *providerExchangesImpl) List(ctx context.Context, request ListExchangesRequest) listing.Iterator[Exchange] { + + getNextPage := func(ctx context.Context, req ListExchangesRequest) (*ListExchangesResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListExchangesResponse) []Exchange { + return resp.Exchanges + } + getNextReq := func(resp *ListExchangesResponse) *ListExchangesRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List exchanges. +// +// List exchanges visible to provider +func (a *providerExchangesImpl) ListAll(ctx context.Context, request ListExchangesRequest) ([]Exchange, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[Exchange](ctx, iterator) +} +func (a *providerExchangesImpl) internalList(ctx context.Context, request ListExchangesRequest) (*ListExchangesResponse, error) { var listExchangesResponse ListExchangesResponse path := "/api/2.0/marketplace-exchange/exchanges" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listExchangesResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listExchangesResponse) return &listExchangesResponse, err } -func (a *providerExchangesImpl) ListExchangesForListing(ctx context.Context, request ListExchangesForListingRequest) (*ListExchangesForListingResponse, error) { +// List exchanges for listing. +// +// List exchanges associated with a listing +func (a *providerExchangesImpl) ListExchangesForListing(ctx context.Context, request ListExchangesForListingRequest) listing.Iterator[ExchangeListing] { + + getNextPage := func(ctx context.Context, req ListExchangesForListingRequest) (*ListExchangesForListingResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalListExchangesForListing(ctx, req) + } + getItems := func(resp *ListExchangesForListingResponse) []ExchangeListing { + return resp.ExchangeListing + } + getNextReq := func(resp *ListExchangesForListingResponse) *ListExchangesForListingRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List exchanges for listing. +// +// List exchanges associated with a listing +func (a *providerExchangesImpl) ListExchangesForListingAll(ctx context.Context, request ListExchangesForListingRequest) ([]ExchangeListing, error) { + iterator := a.ListExchangesForListing(ctx, request) + return listing.ToSlice[ExchangeListing](ctx, iterator) +} +func (a *providerExchangesImpl) internalListExchangesForListing(ctx context.Context, request ListExchangesForListingRequest) (*ListExchangesForListingResponse, error) { var listExchangesForListingResponse ListExchangesForListingResponse path := "/api/2.0/marketplace-exchange/exchanges-for-listing" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listExchangesForListingResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listExchangesForListingResponse) return &listExchangesForListingResponse, err } -func (a *providerExchangesImpl) ListListingsForExchange(ctx context.Context, request ListListingsForExchangeRequest) (*ListListingsForExchangeResponse, error) { +// List listings for exchange. +// +// List listings associated with an exchange +func (a *providerExchangesImpl) ListListingsForExchange(ctx context.Context, request ListListingsForExchangeRequest) listing.Iterator[ExchangeListing] { + + getNextPage := func(ctx context.Context, req ListListingsForExchangeRequest) (*ListListingsForExchangeResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalListListingsForExchange(ctx, req) + } + getItems := func(resp *ListListingsForExchangeResponse) []ExchangeListing { + return resp.ExchangeListings + } + getNextReq := func(resp *ListListingsForExchangeResponse) *ListListingsForExchangeRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List listings for exchange. +// +// List listings associated with an exchange +func (a *providerExchangesImpl) ListListingsForExchangeAll(ctx context.Context, request ListListingsForExchangeRequest) ([]ExchangeListing, error) { + iterator := a.ListListingsForExchange(ctx, request) + return listing.ToSlice[ExchangeListing](ctx, iterator) +} +func (a *providerExchangesImpl) internalListListingsForExchange(ctx context.Context, request ListListingsForExchangeRequest) (*ListListingsForExchangeResponse, error) { var listListingsForExchangeResponse ListListingsForExchangeResponse path := "/api/2.0/marketplace-exchange/listings-for-exchange" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listListingsForExchangeResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listListingsForExchangeResponse) return &listListingsForExchangeResponse, err } func (a *providerExchangesImpl) Update(ctx context.Context, request UpdateExchangeRequest) (*UpdateExchangeResponse, error) { var updateExchangeResponse UpdateExchangeResponse path := fmt.Sprintf("/api/2.0/marketplace-exchange/exchanges/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &updateExchangeResponse) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &updateExchangeResponse) return &updateExchangeResponse, err } @@ -331,37 +787,75 @@ type providerFilesImpl struct { func (a *providerFilesImpl) Create(ctx context.Context, request CreateFileRequest) (*CreateFileResponse, error) { var createFileResponse CreateFileResponse path := "/api/2.0/marketplace-provider/files" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createFileResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createFileResponse) return &createFileResponse, err } func (a *providerFilesImpl) Delete(ctx context.Context, request DeleteFileRequest) error { var deleteFileResponse DeleteFileResponse path := fmt.Sprintf("/api/2.0/marketplace-provider/files/%v", request.FileId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteFileResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteFileResponse) return err } func (a *providerFilesImpl) Get(ctx context.Context, request GetFileRequest) (*GetFileResponse, error) { var getFileResponse GetFileResponse path := fmt.Sprintf("/api/2.0/marketplace-provider/files/%v", request.FileId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getFileResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getFileResponse) return &getFileResponse, err } -func (a *providerFilesImpl) List(ctx context.Context, request ListFilesRequest) (*ListFilesResponse, error) { +// List files. +// +// List files attached to a parent entity. +func (a *providerFilesImpl) List(ctx context.Context, request ListFilesRequest) listing.Iterator[FileInfo] { + + getNextPage := func(ctx context.Context, req ListFilesRequest) (*ListFilesResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListFilesResponse) []FileInfo { + return resp.FileInfos + } + getNextReq := func(resp *ListFilesResponse) *ListFilesRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List files. +// +// List files attached to a parent entity. +func (a *providerFilesImpl) ListAll(ctx context.Context, request ListFilesRequest) ([]FileInfo, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[FileInfo](ctx, iterator) +} +func (a *providerFilesImpl) internalList(ctx context.Context, request ListFilesRequest) (*ListFilesResponse, error) { var listFilesResponse ListFilesResponse path := "/api/2.0/marketplace-provider/files" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listFilesResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listFilesResponse) return &listFilesResponse, err } @@ -373,47 +867,86 @@ type providerListingsImpl struct { func (a *providerListingsImpl) Create(ctx context.Context, request CreateListingRequest) (*CreateListingResponse, error) { var createListingResponse CreateListingResponse path := "/api/2.0/marketplace-provider/listing" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createListingResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createListingResponse) return &createListingResponse, err } func (a *providerListingsImpl) Delete(ctx context.Context, request DeleteListingRequest) error { var deleteListingResponse DeleteListingResponse path := fmt.Sprintf("/api/2.0/marketplace-provider/listings/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteListingResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteListingResponse) return err } func (a *providerListingsImpl) Get(ctx context.Context, request GetListingRequest) (*GetListingResponse, error) { var getListingResponse GetListingResponse path := fmt.Sprintf("/api/2.0/marketplace-provider/listings/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getListingResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getListingResponse) return &getListingResponse, err } -func (a *providerListingsImpl) List(ctx context.Context, request GetListingsRequest) (*GetListingsResponse, error) { +// List listings. +// +// List listings owned by this provider +func (a *providerListingsImpl) List(ctx context.Context, request GetListingsRequest) listing.Iterator[Listing] { + + getNextPage := func(ctx context.Context, req GetListingsRequest) (*GetListingsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *GetListingsResponse) []Listing { + return resp.Listings + } + getNextReq := func(resp *GetListingsResponse) *GetListingsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List listings. +// +// List listings owned by this provider +func (a *providerListingsImpl) ListAll(ctx context.Context, request GetListingsRequest) ([]Listing, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[Listing](ctx, iterator) +} +func (a *providerListingsImpl) internalList(ctx context.Context, request GetListingsRequest) (*GetListingsResponse, error) { var getListingsResponse GetListingsResponse path := "/api/2.0/marketplace-provider/listings" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getListingsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getListingsResponse) return &getListingsResponse, err } func (a *providerListingsImpl) Update(ctx context.Context, request UpdateListingRequest) (*UpdateListingResponse, error) { var updateListingResponse UpdateListingResponse path := fmt.Sprintf("/api/2.0/marketplace-provider/listings/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &updateListingResponse) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &updateListingResponse) return &updateListingResponse, err } @@ -422,22 +955,60 @@ type providerPersonalizationRequestsImpl struct { client *client.DatabricksClient } -func (a *providerPersonalizationRequestsImpl) List(ctx context.Context, request ListAllPersonalizationRequestsRequest) (*ListAllPersonalizationRequestsResponse, error) { +// All personalization requests across all listings. +// +// List personalization requests to this provider. This will return all +// personalization requests, regardless of which listing they are for. +func (a *providerPersonalizationRequestsImpl) List(ctx context.Context, request ListAllPersonalizationRequestsRequest) listing.Iterator[PersonalizationRequest] { + + getNextPage := func(ctx context.Context, req ListAllPersonalizationRequestsRequest) (*ListAllPersonalizationRequestsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListAllPersonalizationRequestsResponse) []PersonalizationRequest { + return resp.PersonalizationRequests + } + getNextReq := func(resp *ListAllPersonalizationRequestsResponse) *ListAllPersonalizationRequestsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// All personalization requests across all listings. +// +// List personalization requests to this provider. This will return all +// personalization requests, regardless of which listing they are for. +func (a *providerPersonalizationRequestsImpl) ListAll(ctx context.Context, request ListAllPersonalizationRequestsRequest) ([]PersonalizationRequest, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[PersonalizationRequest](ctx, iterator) +} +func (a *providerPersonalizationRequestsImpl) internalList(ctx context.Context, request ListAllPersonalizationRequestsRequest) (*ListAllPersonalizationRequestsResponse, error) { var listAllPersonalizationRequestsResponse ListAllPersonalizationRequestsResponse path := "/api/2.0/marketplace-provider/personalization-requests" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listAllPersonalizationRequestsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listAllPersonalizationRequestsResponse) return &listAllPersonalizationRequestsResponse, err } func (a *providerPersonalizationRequestsImpl) Update(ctx context.Context, request UpdatePersonalizationRequestRequest) (*UpdatePersonalizationRequestResponse, error) { var updatePersonalizationRequestResponse UpdatePersonalizationRequestResponse path := fmt.Sprintf("/api/2.0/marketplace-provider/listings/%v/personalization-requests/%v/request-status", request.ListingId, request.RequestId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &updatePersonalizationRequestResponse) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &updatePersonalizationRequestResponse) return &updatePersonalizationRequestResponse, err } @@ -449,37 +1020,41 @@ type providerProviderAnalyticsDashboardsImpl struct { func (a *providerProviderAnalyticsDashboardsImpl) Create(ctx context.Context) (*ProviderAnalyticsDashboard, error) { var providerAnalyticsDashboard ProviderAnalyticsDashboard path := "/api/2.0/marketplace-provider/analytics_dashboard" + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, nil, &providerAnalyticsDashboard) + err := a.client.Do(ctx, http.MethodPost, path, headers, nil, nil, &providerAnalyticsDashboard) return &providerAnalyticsDashboard, err } func (a *providerProviderAnalyticsDashboardsImpl) Get(ctx context.Context) (*ListProviderAnalyticsDashboardResponse, error) { var listProviderAnalyticsDashboardResponse ListProviderAnalyticsDashboardResponse path := "/api/2.0/marketplace-provider/analytics_dashboard" + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &listProviderAnalyticsDashboardResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &listProviderAnalyticsDashboardResponse) return &listProviderAnalyticsDashboardResponse, err } func (a *providerProviderAnalyticsDashboardsImpl) GetLatestVersion(ctx context.Context) (*GetLatestVersionProviderAnalyticsDashboardResponse, error) { var getLatestVersionProviderAnalyticsDashboardResponse GetLatestVersionProviderAnalyticsDashboardResponse path := "/api/2.0/marketplace-provider/analytics_dashboard/latest" + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &getLatestVersionProviderAnalyticsDashboardResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &getLatestVersionProviderAnalyticsDashboardResponse) return &getLatestVersionProviderAnalyticsDashboardResponse, err } func (a *providerProviderAnalyticsDashboardsImpl) Update(ctx context.Context, request UpdateProviderAnalyticsDashboardRequest) (*UpdateProviderAnalyticsDashboardResponse, error) { var updateProviderAnalyticsDashboardResponse UpdateProviderAnalyticsDashboardResponse path := fmt.Sprintf("/api/2.0/marketplace-provider/analytics_dashboard/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &updateProviderAnalyticsDashboardResponse) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &updateProviderAnalyticsDashboardResponse) return &updateProviderAnalyticsDashboardResponse, err } @@ -491,46 +1066,85 @@ type providerProvidersImpl struct { func (a *providerProvidersImpl) Create(ctx context.Context, request CreateProviderRequest) (*CreateProviderResponse, error) { var createProviderResponse CreateProviderResponse path := "/api/2.0/marketplace-provider/provider" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createProviderResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createProviderResponse) return &createProviderResponse, err } func (a *providerProvidersImpl) Delete(ctx context.Context, request DeleteProviderRequest) error { var deleteProviderResponse DeleteProviderResponse path := fmt.Sprintf("/api/2.0/marketplace-provider/providers/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteProviderResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteProviderResponse) return err } func (a *providerProvidersImpl) Get(ctx context.Context, request GetProviderRequest) (*GetProviderResponse, error) { var getProviderResponse GetProviderResponse path := fmt.Sprintf("/api/2.0/marketplace-provider/providers/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getProviderResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getProviderResponse) return &getProviderResponse, err } -func (a *providerProvidersImpl) List(ctx context.Context, request ListProvidersRequest) (*ListProvidersResponse, error) { +// List providers. +// +// List provider profiles for account. +func (a *providerProvidersImpl) List(ctx context.Context, request ListProvidersRequest) listing.Iterator[ProviderInfo] { + + getNextPage := func(ctx context.Context, req ListProvidersRequest) (*ListProvidersResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListProvidersResponse) []ProviderInfo { + return resp.Providers + } + getNextReq := func(resp *ListProvidersResponse) *ListProvidersRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List providers. +// +// List provider profiles for account. +func (a *providerProvidersImpl) ListAll(ctx context.Context, request ListProvidersRequest) ([]ProviderInfo, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[ProviderInfo](ctx, iterator) +} +func (a *providerProvidersImpl) internalList(ctx context.Context, request ListProvidersRequest) (*ListProvidersResponse, error) { var listProvidersResponse ListProvidersResponse path := "/api/2.0/marketplace-provider/providers" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listProvidersResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listProvidersResponse) return &listProvidersResponse, err } func (a *providerProvidersImpl) Update(ctx context.Context, request UpdateProviderRequest) (*UpdateProviderResponse, error) { var updateProviderResponse UpdateProviderResponse path := fmt.Sprintf("/api/2.0/marketplace-provider/providers/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &updateProviderResponse) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &updateProviderResponse) return &updateProviderResponse, err } diff --git a/ml/go.mod b/ml/go.mod index 04f788614..ea1bd4749 100644 --- a/ml/go.mod +++ b/ml/go.mod @@ -6,6 +6,7 @@ replace github.com/databricks/databricks-sdk-go/databricks => ../databricks require ( github.com/databricks/databricks-sdk-go/databricks v0.0.0-00010101000000-000000000000 + golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 golang.org/x/oauth2 v0.25.0 ) @@ -27,7 +28,6 @@ require ( go.opentelemetry.io/otel/metric v1.24.0 // indirect go.opentelemetry.io/otel/trace v1.24.0 // indirect golang.org/x/crypto v0.31.0 // indirect - golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.33.0 // indirect golang.org/x/sys v0.28.0 // indirect diff --git a/ml/v2/api.go b/ml/v2/api.go index 39cc10d49..fe34f0635 100755 --- a/ml/v2/api.go +++ b/ml/v2/api.go @@ -8,7 +8,6 @@ import ( "github.com/databricks/databricks-sdk-go/databricks/client" "github.com/databricks/databricks-sdk-go/databricks/listing" - "github.com/databricks/databricks-sdk-go/databricks/useragent" ) type ExperimentsInterface interface { @@ -341,46 +340,6 @@ type ExperimentsAPI struct { experimentsImpl } -// Get history of a given metric within a run. -// -// Gets a list of all values for the specified metric for a given run. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ExperimentsAPI) GetHistory(ctx context.Context, request GetHistoryRequest) listing.Iterator[Metric] { - - getNextPage := func(ctx context.Context, req GetHistoryRequest) (*GetMetricHistoryResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.experimentsImpl.GetHistory(ctx, req) - } - getItems := func(resp *GetMetricHistoryResponse) []Metric { - return resp.Metrics - } - getNextReq := func(resp *GetMetricHistoryResponse) *GetHistoryRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// Get history of a given metric within a run. -// -// Gets a list of all values for the specified metric for a given run. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ExperimentsAPI) GetHistoryAll(ctx context.Context, request GetHistoryRequest) ([]Metric, error) { - iterator := a.GetHistory(ctx, request) - return listing.ToSliceN[Metric, int](ctx, iterator, request.MaxResults) - -} - // Get experiment permission levels. // // Gets the permission levels that a user can have on an object. @@ -400,179 +359,6 @@ func (a *ExperimentsAPI) GetPermissionsByExperimentId(ctx context.Context, exper }) } -// Get all artifacts. -// -// List artifacts for a run. Takes an optional `artifact_path` prefix. If it is -// specified, the response contains only artifacts with the specified prefix. -// This API does not support pagination when listing artifacts in UC Volumes. A -// maximum of 1000 artifacts will be retrieved for UC Volumes. Please call -// `/api/2.0/fs/directories{directory_path}` for listing artifacts in UC -// Volumes, which supports pagination. See [List directory contents | Files -// API](/api/workspace/files/listdirectorycontents). -// -// This method is generated by Databricks SDK Code Generator. -func (a *ExperimentsAPI) ListArtifacts(ctx context.Context, request ListArtifactsRequest) listing.Iterator[FileInfo] { - - getNextPage := func(ctx context.Context, req ListArtifactsRequest) (*ListArtifactsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.experimentsImpl.ListArtifacts(ctx, req) - } - getItems := func(resp *ListArtifactsResponse) []FileInfo { - return resp.Files - } - getNextReq := func(resp *ListArtifactsResponse) *ListArtifactsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// Get all artifacts. -// -// List artifacts for a run. Takes an optional `artifact_path` prefix. If it is -// specified, the response contains only artifacts with the specified prefix. -// This API does not support pagination when listing artifacts in UC Volumes. A -// maximum of 1000 artifacts will be retrieved for UC Volumes. Please call -// `/api/2.0/fs/directories{directory_path}` for listing artifacts in UC -// Volumes, which supports pagination. See [List directory contents | Files -// API](/api/workspace/files/listdirectorycontents). -// -// This method is generated by Databricks SDK Code Generator. -func (a *ExperimentsAPI) ListArtifactsAll(ctx context.Context, request ListArtifactsRequest) ([]FileInfo, error) { - iterator := a.ListArtifacts(ctx, request) - return listing.ToSlice[FileInfo](ctx, iterator) -} - -// List experiments. -// -// Gets a list of all experiments. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ExperimentsAPI) ListExperiments(ctx context.Context, request ListExperimentsRequest) listing.Iterator[Experiment] { - - getNextPage := func(ctx context.Context, req ListExperimentsRequest) (*ListExperimentsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.experimentsImpl.ListExperiments(ctx, req) - } - getItems := func(resp *ListExperimentsResponse) []Experiment { - return resp.Experiments - } - getNextReq := func(resp *ListExperimentsResponse) *ListExperimentsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List experiments. -// -// Gets a list of all experiments. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ExperimentsAPI) ListExperimentsAll(ctx context.Context, request ListExperimentsRequest) ([]Experiment, error) { - iterator := a.ListExperiments(ctx, request) - return listing.ToSliceN[Experiment, int](ctx, iterator, request.MaxResults) - -} - -// Search experiments. -// -// Searches for experiments that satisfy specified search criteria. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ExperimentsAPI) SearchExperiments(ctx context.Context, request SearchExperiments) listing.Iterator[Experiment] { - - getNextPage := func(ctx context.Context, req SearchExperiments) (*SearchExperimentsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.experimentsImpl.SearchExperiments(ctx, req) - } - getItems := func(resp *SearchExperimentsResponse) []Experiment { - return resp.Experiments - } - getNextReq := func(resp *SearchExperimentsResponse) *SearchExperiments { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// Search experiments. -// -// Searches for experiments that satisfy specified search criteria. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ExperimentsAPI) SearchExperimentsAll(ctx context.Context, request SearchExperiments) ([]Experiment, error) { - iterator := a.SearchExperiments(ctx, request) - return listing.ToSlice[Experiment](ctx, iterator) -} - -// Search for runs. -// -// Searches for runs that satisfy expressions. -// -// Search expressions can use `mlflowMetric` and `mlflowParam` keys.", -// -// This method is generated by Databricks SDK Code Generator. -func (a *ExperimentsAPI) SearchRuns(ctx context.Context, request SearchRuns) listing.Iterator[Run] { - - getNextPage := func(ctx context.Context, req SearchRuns) (*SearchRunsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.experimentsImpl.SearchRuns(ctx, req) - } - getItems := func(resp *SearchRunsResponse) []Run { - return resp.Runs - } - getNextReq := func(resp *SearchRunsResponse) *SearchRuns { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// Search for runs. -// -// Searches for runs that satisfy expressions. -// -// Search expressions can use `mlflowMetric` and `mlflowParam` keys.", -// -// This method is generated by Databricks SDK Code Generator. -func (a *ExperimentsAPI) SearchRunsAll(ctx context.Context, request SearchRuns) ([]Run, error) { - iterator := a.SearchRuns(ctx, request) - return listing.ToSlice[Run](ctx, iterator) -} - type ModelRegistryInterface interface { // Approve transition request. @@ -872,39 +658,6 @@ type ModelRegistryAPI struct { modelRegistryImpl } -// Get the latest version. -// -// Gets the latest version of a registered model. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ModelRegistryAPI) GetLatestVersions(ctx context.Context, request GetLatestVersionsRequest) listing.Iterator[ModelVersion] { - - getNextPage := func(ctx context.Context, req GetLatestVersionsRequest) (*GetLatestVersionsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.modelRegistryImpl.GetLatestVersions(ctx, req) - } - getItems := func(resp *GetLatestVersionsResponse) []ModelVersion { - return resp.ModelVersions - } - - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - nil) - return iterator -} - -// Get the latest version. -// -// Gets the latest version of a registered model. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ModelRegistryAPI) GetLatestVersionsAll(ctx context.Context, request GetLatestVersionsRequest) ([]ModelVersion, error) { - iterator := a.GetLatestVersions(ctx, request) - return listing.ToSlice[ModelVersion](ctx, iterator) -} - // Get registered model permission levels. // // Gets the permission levels that a user can have on an object. @@ -923,201 +676,3 @@ func (a *ModelRegistryAPI) GetPermissionsByRegisteredModelId(ctx context.Context RegisteredModelId: registeredModelId, }) } - -// List models. -// -// Lists all available registered models, up to the limit specified in -// __max_results__. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ModelRegistryAPI) ListModels(ctx context.Context, request ListModelsRequest) listing.Iterator[Model] { - - getNextPage := func(ctx context.Context, req ListModelsRequest) (*ListModelsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.modelRegistryImpl.ListModels(ctx, req) - } - getItems := func(resp *ListModelsResponse) []Model { - return resp.RegisteredModels - } - getNextReq := func(resp *ListModelsResponse) *ListModelsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List models. -// -// Lists all available registered models, up to the limit specified in -// __max_results__. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ModelRegistryAPI) ListModelsAll(ctx context.Context, request ListModelsRequest) ([]Model, error) { - iterator := a.ListModels(ctx, request) - return listing.ToSliceN[Model, int](ctx, iterator, request.MaxResults) - -} - -// List transition requests. -// -// Gets a list of all open stage transition requests for the model version. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ModelRegistryAPI) ListTransitionRequests(ctx context.Context, request ListTransitionRequestsRequest) listing.Iterator[Activity] { - - getNextPage := func(ctx context.Context, req ListTransitionRequestsRequest) (*ListTransitionRequestsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.modelRegistryImpl.ListTransitionRequests(ctx, req) - } - getItems := func(resp *ListTransitionRequestsResponse) []Activity { - return resp.Requests - } - - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - nil) - return iterator -} - -// List transition requests. -// -// Gets a list of all open stage transition requests for the model version. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ModelRegistryAPI) ListTransitionRequestsAll(ctx context.Context, request ListTransitionRequestsRequest) ([]Activity, error) { - iterator := a.ListTransitionRequests(ctx, request) - return listing.ToSlice[Activity](ctx, iterator) -} - -// List registry webhooks. -// -// **NOTE:** This endpoint is in Public Preview. -// -// Lists all registry webhooks. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ModelRegistryAPI) ListWebhooks(ctx context.Context, request ListWebhooksRequest) listing.Iterator[RegistryWebhook] { - - getNextPage := func(ctx context.Context, req ListWebhooksRequest) (*ListRegistryWebhooks, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.modelRegistryImpl.ListWebhooks(ctx, req) - } - getItems := func(resp *ListRegistryWebhooks) []RegistryWebhook { - return resp.Webhooks - } - getNextReq := func(resp *ListRegistryWebhooks) *ListWebhooksRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List registry webhooks. -// -// **NOTE:** This endpoint is in Public Preview. -// -// Lists all registry webhooks. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ModelRegistryAPI) ListWebhooksAll(ctx context.Context, request ListWebhooksRequest) ([]RegistryWebhook, error) { - iterator := a.ListWebhooks(ctx, request) - return listing.ToSlice[RegistryWebhook](ctx, iterator) -} - -// Searches model versions. -// -// Searches for specific model versions based on the supplied __filter__. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ModelRegistryAPI) SearchModelVersions(ctx context.Context, request SearchModelVersionsRequest) listing.Iterator[ModelVersion] { - - getNextPage := func(ctx context.Context, req SearchModelVersionsRequest) (*SearchModelVersionsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.modelRegistryImpl.SearchModelVersions(ctx, req) - } - getItems := func(resp *SearchModelVersionsResponse) []ModelVersion { - return resp.ModelVersions - } - getNextReq := func(resp *SearchModelVersionsResponse) *SearchModelVersionsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// Searches model versions. -// -// Searches for specific model versions based on the supplied __filter__. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ModelRegistryAPI) SearchModelVersionsAll(ctx context.Context, request SearchModelVersionsRequest) ([]ModelVersion, error) { - iterator := a.SearchModelVersions(ctx, request) - return listing.ToSliceN[ModelVersion, int](ctx, iterator, request.MaxResults) - -} - -// Search models. -// -// Search for registered models based on the specified __filter__. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ModelRegistryAPI) SearchModels(ctx context.Context, request SearchModelsRequest) listing.Iterator[Model] { - - getNextPage := func(ctx context.Context, req SearchModelsRequest) (*SearchModelsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.modelRegistryImpl.SearchModels(ctx, req) - } - getItems := func(resp *SearchModelsResponse) []Model { - return resp.RegisteredModels - } - getNextReq := func(resp *SearchModelsResponse) *SearchModelsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// Search models. -// -// Search for registered models based on the specified __filter__. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ModelRegistryAPI) SearchModelsAll(ctx context.Context, request SearchModelsRequest) ([]Model, error) { - iterator := a.SearchModels(ctx, request) - return listing.ToSliceN[Model, int](ctx, iterator, request.MaxResults) - -} diff --git a/ml/v2/impl.go b/ml/v2/impl.go index 7ec0f1ba9..bce1da7f6 100755 --- a/ml/v2/impl.go +++ b/ml/v2/impl.go @@ -8,6 +8,8 @@ import ( "net/http" "github.com/databricks/databricks-sdk-go/databricks/client" + "github.com/databricks/databricks-sdk-go/databricks/listing" + "github.com/databricks/databricks-sdk-go/databricks/useragent" ) // unexported type that holds implementations of just Experiments API methods @@ -18,292 +20,510 @@ type experimentsImpl struct { func (a *experimentsImpl) CreateExperiment(ctx context.Context, request CreateExperiment) (*CreateExperimentResponse, error) { var createExperimentResponse CreateExperimentResponse path := "/api/2.0/mlflow/experiments/create" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createExperimentResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createExperimentResponse) return &createExperimentResponse, err } func (a *experimentsImpl) CreateRun(ctx context.Context, request CreateRun) (*CreateRunResponse, error) { var createRunResponse CreateRunResponse path := "/api/2.0/mlflow/runs/create" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createRunResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createRunResponse) return &createRunResponse, err } func (a *experimentsImpl) DeleteExperiment(ctx context.Context, request DeleteExperiment) error { var deleteExperimentResponse DeleteExperimentResponse path := "/api/2.0/mlflow/experiments/delete" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &deleteExperimentResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &deleteExperimentResponse) return err } func (a *experimentsImpl) DeleteRun(ctx context.Context, request DeleteRun) error { var deleteRunResponse DeleteRunResponse path := "/api/2.0/mlflow/runs/delete" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &deleteRunResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &deleteRunResponse) return err } func (a *experimentsImpl) DeleteRuns(ctx context.Context, request DeleteRuns) (*DeleteRunsResponse, error) { var deleteRunsResponse DeleteRunsResponse path := "/api/2.0/mlflow/databricks/runs/delete-runs" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &deleteRunsResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &deleteRunsResponse) return &deleteRunsResponse, err } func (a *experimentsImpl) DeleteTag(ctx context.Context, request DeleteTag) error { var deleteTagResponse DeleteTagResponse path := "/api/2.0/mlflow/runs/delete-tag" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &deleteTagResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &deleteTagResponse) return err } func (a *experimentsImpl) GetByName(ctx context.Context, request GetByNameRequest) (*GetExperimentResponse, error) { var getExperimentResponse GetExperimentResponse path := "/api/2.0/mlflow/experiments/get-by-name" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getExperimentResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getExperimentResponse) return &getExperimentResponse, err } func (a *experimentsImpl) GetExperiment(ctx context.Context, request GetExperimentRequest) (*GetExperimentResponse, error) { var getExperimentResponse GetExperimentResponse path := "/api/2.0/mlflow/experiments/get" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getExperimentResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getExperimentResponse) return &getExperimentResponse, err } -func (a *experimentsImpl) GetHistory(ctx context.Context, request GetHistoryRequest) (*GetMetricHistoryResponse, error) { +// Get history of a given metric within a run. +// +// Gets a list of all values for the specified metric for a given run. +func (a *experimentsImpl) GetHistory(ctx context.Context, request GetHistoryRequest) listing.Iterator[Metric] { + + getNextPage := func(ctx context.Context, req GetHistoryRequest) (*GetMetricHistoryResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalGetHistory(ctx, req) + } + getItems := func(resp *GetMetricHistoryResponse) []Metric { + return resp.Metrics + } + getNextReq := func(resp *GetMetricHistoryResponse) *GetHistoryRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// Get history of a given metric within a run. +// +// Gets a list of all values for the specified metric for a given run. +func (a *experimentsImpl) GetHistoryAll(ctx context.Context, request GetHistoryRequest) ([]Metric, error) { + iterator := a.GetHistory(ctx, request) + return listing.ToSliceN[Metric, int](ctx, iterator, request.MaxResults) + +} +func (a *experimentsImpl) internalGetHistory(ctx context.Context, request GetHistoryRequest) (*GetMetricHistoryResponse, error) { var getMetricHistoryResponse GetMetricHistoryResponse path := "/api/2.0/mlflow/metrics/get-history" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getMetricHistoryResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getMetricHistoryResponse) return &getMetricHistoryResponse, err } func (a *experimentsImpl) GetPermissionLevels(ctx context.Context, request GetExperimentPermissionLevelsRequest) (*GetExperimentPermissionLevelsResponse, error) { var getExperimentPermissionLevelsResponse GetExperimentPermissionLevelsResponse path := fmt.Sprintf("/api/2.0/permissions/experiments/%v/permissionLevels", request.ExperimentId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getExperimentPermissionLevelsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getExperimentPermissionLevelsResponse) return &getExperimentPermissionLevelsResponse, err } func (a *experimentsImpl) GetPermissions(ctx context.Context, request GetExperimentPermissionsRequest) (*ExperimentPermissions, error) { var experimentPermissions ExperimentPermissions path := fmt.Sprintf("/api/2.0/permissions/experiments/%v", request.ExperimentId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &experimentPermissions) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &experimentPermissions) return &experimentPermissions, err } func (a *experimentsImpl) GetRun(ctx context.Context, request GetRunRequest) (*GetRunResponse, error) { var getRunResponse GetRunResponse path := "/api/2.0/mlflow/runs/get" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getRunResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getRunResponse) return &getRunResponse, err } -func (a *experimentsImpl) ListArtifacts(ctx context.Context, request ListArtifactsRequest) (*ListArtifactsResponse, error) { +// Get all artifacts. +// +// List artifacts for a run. Takes an optional `artifact_path` prefix. If it is +// specified, the response contains only artifacts with the specified prefix. +// This API does not support pagination when listing artifacts in UC Volumes. A +// maximum of 1000 artifacts will be retrieved for UC Volumes. Please call +// `/api/2.0/fs/directories{directory_path}` for listing artifacts in UC +// Volumes, which supports pagination. See [List directory contents | Files +// API](/api/workspace/files/listdirectorycontents). +func (a *experimentsImpl) ListArtifacts(ctx context.Context, request ListArtifactsRequest) listing.Iterator[FileInfo] { + + getNextPage := func(ctx context.Context, req ListArtifactsRequest) (*ListArtifactsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalListArtifacts(ctx, req) + } + getItems := func(resp *ListArtifactsResponse) []FileInfo { + return resp.Files + } + getNextReq := func(resp *ListArtifactsResponse) *ListArtifactsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// Get all artifacts. +// +// List artifacts for a run. Takes an optional `artifact_path` prefix. If it is +// specified, the response contains only artifacts with the specified prefix. +// This API does not support pagination when listing artifacts in UC Volumes. A +// maximum of 1000 artifacts will be retrieved for UC Volumes. Please call +// `/api/2.0/fs/directories{directory_path}` for listing artifacts in UC +// Volumes, which supports pagination. See [List directory contents | Files +// API](/api/workspace/files/listdirectorycontents). +func (a *experimentsImpl) ListArtifactsAll(ctx context.Context, request ListArtifactsRequest) ([]FileInfo, error) { + iterator := a.ListArtifacts(ctx, request) + return listing.ToSlice[FileInfo](ctx, iterator) +} +func (a *experimentsImpl) internalListArtifacts(ctx context.Context, request ListArtifactsRequest) (*ListArtifactsResponse, error) { var listArtifactsResponse ListArtifactsResponse path := "/api/2.0/mlflow/artifacts/list" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listArtifactsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listArtifactsResponse) return &listArtifactsResponse, err } -func (a *experimentsImpl) ListExperiments(ctx context.Context, request ListExperimentsRequest) (*ListExperimentsResponse, error) { +// List experiments. +// +// Gets a list of all experiments. +func (a *experimentsImpl) ListExperiments(ctx context.Context, request ListExperimentsRequest) listing.Iterator[Experiment] { + + getNextPage := func(ctx context.Context, req ListExperimentsRequest) (*ListExperimentsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalListExperiments(ctx, req) + } + getItems := func(resp *ListExperimentsResponse) []Experiment { + return resp.Experiments + } + getNextReq := func(resp *ListExperimentsResponse) *ListExperimentsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List experiments. +// +// Gets a list of all experiments. +func (a *experimentsImpl) ListExperimentsAll(ctx context.Context, request ListExperimentsRequest) ([]Experiment, error) { + iterator := a.ListExperiments(ctx, request) + return listing.ToSliceN[Experiment, int](ctx, iterator, request.MaxResults) + +} +func (a *experimentsImpl) internalListExperiments(ctx context.Context, request ListExperimentsRequest) (*ListExperimentsResponse, error) { var listExperimentsResponse ListExperimentsResponse path := "/api/2.0/mlflow/experiments/list" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listExperimentsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listExperimentsResponse) return &listExperimentsResponse, err } func (a *experimentsImpl) LogBatch(ctx context.Context, request LogBatch) error { var logBatchResponse LogBatchResponse path := "/api/2.0/mlflow/runs/log-batch" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &logBatchResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &logBatchResponse) return err } func (a *experimentsImpl) LogInputs(ctx context.Context, request LogInputs) error { var logInputsResponse LogInputsResponse path := "/api/2.0/mlflow/runs/log-inputs" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &logInputsResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &logInputsResponse) return err } func (a *experimentsImpl) LogMetric(ctx context.Context, request LogMetric) error { var logMetricResponse LogMetricResponse path := "/api/2.0/mlflow/runs/log-metric" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &logMetricResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &logMetricResponse) return err } func (a *experimentsImpl) LogModel(ctx context.Context, request LogModel) error { var logModelResponse LogModelResponse path := "/api/2.0/mlflow/runs/log-model" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &logModelResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &logModelResponse) return err } func (a *experimentsImpl) LogParam(ctx context.Context, request LogParam) error { var logParamResponse LogParamResponse path := "/api/2.0/mlflow/runs/log-parameter" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &logParamResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &logParamResponse) return err } func (a *experimentsImpl) RestoreExperiment(ctx context.Context, request RestoreExperiment) error { var restoreExperimentResponse RestoreExperimentResponse path := "/api/2.0/mlflow/experiments/restore" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &restoreExperimentResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &restoreExperimentResponse) return err } func (a *experimentsImpl) RestoreRun(ctx context.Context, request RestoreRun) error { var restoreRunResponse RestoreRunResponse path := "/api/2.0/mlflow/runs/restore" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &restoreRunResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &restoreRunResponse) return err } func (a *experimentsImpl) RestoreRuns(ctx context.Context, request RestoreRuns) (*RestoreRunsResponse, error) { var restoreRunsResponse RestoreRunsResponse path := "/api/2.0/mlflow/databricks/runs/restore-runs" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &restoreRunsResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &restoreRunsResponse) return &restoreRunsResponse, err } -func (a *experimentsImpl) SearchExperiments(ctx context.Context, request SearchExperiments) (*SearchExperimentsResponse, error) { +// Search experiments. +// +// Searches for experiments that satisfy specified search criteria. +func (a *experimentsImpl) SearchExperiments(ctx context.Context, request SearchExperiments) listing.Iterator[Experiment] { + + getNextPage := func(ctx context.Context, req SearchExperiments) (*SearchExperimentsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalSearchExperiments(ctx, req) + } + getItems := func(resp *SearchExperimentsResponse) []Experiment { + return resp.Experiments + } + getNextReq := func(resp *SearchExperimentsResponse) *SearchExperiments { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// Search experiments. +// +// Searches for experiments that satisfy specified search criteria. +func (a *experimentsImpl) SearchExperimentsAll(ctx context.Context, request SearchExperiments) ([]Experiment, error) { + iterator := a.SearchExperiments(ctx, request) + return listing.ToSlice[Experiment](ctx, iterator) +} +func (a *experimentsImpl) internalSearchExperiments(ctx context.Context, request SearchExperiments) (*SearchExperimentsResponse, error) { var searchExperimentsResponse SearchExperimentsResponse path := "/api/2.0/mlflow/experiments/search" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &searchExperimentsResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &searchExperimentsResponse) return &searchExperimentsResponse, err } -func (a *experimentsImpl) SearchRuns(ctx context.Context, request SearchRuns) (*SearchRunsResponse, error) { +// Search for runs. +// +// Searches for runs that satisfy expressions. +// +// Search expressions can use `mlflowMetric` and `mlflowParam` keys.", +func (a *experimentsImpl) SearchRuns(ctx context.Context, request SearchRuns) listing.Iterator[Run] { + + getNextPage := func(ctx context.Context, req SearchRuns) (*SearchRunsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalSearchRuns(ctx, req) + } + getItems := func(resp *SearchRunsResponse) []Run { + return resp.Runs + } + getNextReq := func(resp *SearchRunsResponse) *SearchRuns { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// Search for runs. +// +// Searches for runs that satisfy expressions. +// +// Search expressions can use `mlflowMetric` and `mlflowParam` keys.", +func (a *experimentsImpl) SearchRunsAll(ctx context.Context, request SearchRuns) ([]Run, error) { + iterator := a.SearchRuns(ctx, request) + return listing.ToSlice[Run](ctx, iterator) +} +func (a *experimentsImpl) internalSearchRuns(ctx context.Context, request SearchRuns) (*SearchRunsResponse, error) { var searchRunsResponse SearchRunsResponse path := "/api/2.0/mlflow/runs/search" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &searchRunsResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &searchRunsResponse) return &searchRunsResponse, err } func (a *experimentsImpl) SetExperimentTag(ctx context.Context, request SetExperimentTag) error { var setExperimentTagResponse SetExperimentTagResponse path := "/api/2.0/mlflow/experiments/set-experiment-tag" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &setExperimentTagResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &setExperimentTagResponse) return err } func (a *experimentsImpl) SetPermissions(ctx context.Context, request ExperimentPermissionsRequest) (*ExperimentPermissions, error) { var experimentPermissions ExperimentPermissions path := fmt.Sprintf("/api/2.0/permissions/experiments/%v", request.ExperimentId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &experimentPermissions) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &experimentPermissions) return &experimentPermissions, err } func (a *experimentsImpl) SetTag(ctx context.Context, request SetTag) error { var setTagResponse SetTagResponse path := "/api/2.0/mlflow/runs/set-tag" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &setTagResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &setTagResponse) return err } func (a *experimentsImpl) UpdateExperiment(ctx context.Context, request UpdateExperiment) error { var updateExperimentResponse UpdateExperimentResponse path := "/api/2.0/mlflow/experiments/update" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &updateExperimentResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &updateExperimentResponse) return err } func (a *experimentsImpl) UpdatePermissions(ctx context.Context, request ExperimentPermissionsRequest) (*ExperimentPermissions, error) { var experimentPermissions ExperimentPermissions path := fmt.Sprintf("/api/2.0/permissions/experiments/%v", request.ExperimentId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &experimentPermissions) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &experimentPermissions) return &experimentPermissions, err } func (a *experimentsImpl) UpdateRun(ctx context.Context, request UpdateRun) (*UpdateRunResponse, error) { var updateRunResponse UpdateRunResponse path := "/api/2.0/mlflow/runs/update" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &updateRunResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &updateRunResponse) return &updateRunResponse, err } @@ -315,342 +535,579 @@ type modelRegistryImpl struct { func (a *modelRegistryImpl) ApproveTransitionRequest(ctx context.Context, request ApproveTransitionRequest) (*ApproveTransitionRequestResponse, error) { var approveTransitionRequestResponse ApproveTransitionRequestResponse path := "/api/2.0/mlflow/transition-requests/approve" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &approveTransitionRequestResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &approveTransitionRequestResponse) return &approveTransitionRequestResponse, err } func (a *modelRegistryImpl) CreateComment(ctx context.Context, request CreateComment) (*CreateCommentResponse, error) { var createCommentResponse CreateCommentResponse path := "/api/2.0/mlflow/comments/create" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createCommentResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createCommentResponse) return &createCommentResponse, err } func (a *modelRegistryImpl) CreateModel(ctx context.Context, request CreateModelRequest) (*CreateModelResponse, error) { var createModelResponse CreateModelResponse path := "/api/2.0/mlflow/registered-models/create" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createModelResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createModelResponse) return &createModelResponse, err } func (a *modelRegistryImpl) CreateModelVersion(ctx context.Context, request CreateModelVersionRequest) (*CreateModelVersionResponse, error) { var createModelVersionResponse CreateModelVersionResponse path := "/api/2.0/mlflow/model-versions/create" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createModelVersionResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createModelVersionResponse) return &createModelVersionResponse, err } func (a *modelRegistryImpl) CreateTransitionRequest(ctx context.Context, request CreateTransitionRequest) (*CreateTransitionRequestResponse, error) { var createTransitionRequestResponse CreateTransitionRequestResponse path := "/api/2.0/mlflow/transition-requests/create" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createTransitionRequestResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createTransitionRequestResponse) return &createTransitionRequestResponse, err } func (a *modelRegistryImpl) CreateWebhook(ctx context.Context, request CreateRegistryWebhook) (*CreateWebhookResponse, error) { var createWebhookResponse CreateWebhookResponse path := "/api/2.0/mlflow/registry-webhooks/create" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createWebhookResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createWebhookResponse) return &createWebhookResponse, err } func (a *modelRegistryImpl) DeleteComment(ctx context.Context, request DeleteCommentRequest) error { var deleteCommentResponse DeleteCommentResponse path := "/api/2.0/mlflow/comments/delete" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteCommentResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteCommentResponse) return err } func (a *modelRegistryImpl) DeleteModel(ctx context.Context, request DeleteModelRequest) error { var deleteModelResponse DeleteModelResponse path := "/api/2.0/mlflow/registered-models/delete" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteModelResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteModelResponse) return err } func (a *modelRegistryImpl) DeleteModelTag(ctx context.Context, request DeleteModelTagRequest) error { var deleteModelTagResponse DeleteModelTagResponse path := "/api/2.0/mlflow/registered-models/delete-tag" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteModelTagResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteModelTagResponse) return err } func (a *modelRegistryImpl) DeleteModelVersion(ctx context.Context, request DeleteModelVersionRequest) error { var deleteModelVersionResponse DeleteModelVersionResponse path := "/api/2.0/mlflow/model-versions/delete" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteModelVersionResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteModelVersionResponse) return err } func (a *modelRegistryImpl) DeleteModelVersionTag(ctx context.Context, request DeleteModelVersionTagRequest) error { var deleteModelVersionTagResponse DeleteModelVersionTagResponse path := "/api/2.0/mlflow/model-versions/delete-tag" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteModelVersionTagResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteModelVersionTagResponse) return err } func (a *modelRegistryImpl) DeleteTransitionRequest(ctx context.Context, request DeleteTransitionRequestRequest) error { var deleteTransitionRequestResponse DeleteTransitionRequestResponse path := "/api/2.0/mlflow/transition-requests/delete" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteTransitionRequestResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteTransitionRequestResponse) return err } func (a *modelRegistryImpl) DeleteWebhook(ctx context.Context, request DeleteWebhookRequest) error { var deleteWebhookResponse DeleteWebhookResponse path := "/api/2.0/mlflow/registry-webhooks/delete" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteWebhookResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteWebhookResponse) return err } -func (a *modelRegistryImpl) GetLatestVersions(ctx context.Context, request GetLatestVersionsRequest) (*GetLatestVersionsResponse, error) { +// Get the latest version. +// +// Gets the latest version of a registered model. +func (a *modelRegistryImpl) GetLatestVersions(ctx context.Context, request GetLatestVersionsRequest) listing.Iterator[ModelVersion] { + + getNextPage := func(ctx context.Context, req GetLatestVersionsRequest) (*GetLatestVersionsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalGetLatestVersions(ctx, req) + } + getItems := func(resp *GetLatestVersionsResponse) []ModelVersion { + return resp.ModelVersions + } + + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + nil) + return iterator +} + +// Get the latest version. +// +// Gets the latest version of a registered model. +func (a *modelRegistryImpl) GetLatestVersionsAll(ctx context.Context, request GetLatestVersionsRequest) ([]ModelVersion, error) { + iterator := a.GetLatestVersions(ctx, request) + return listing.ToSlice[ModelVersion](ctx, iterator) +} +func (a *modelRegistryImpl) internalGetLatestVersions(ctx context.Context, request GetLatestVersionsRequest) (*GetLatestVersionsResponse, error) { var getLatestVersionsResponse GetLatestVersionsResponse path := "/api/2.0/mlflow/registered-models/get-latest-versions" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &getLatestVersionsResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &getLatestVersionsResponse) return &getLatestVersionsResponse, err } func (a *modelRegistryImpl) GetModel(ctx context.Context, request GetModelRequest) (*GetModelResponse, error) { var getModelResponse GetModelResponse path := "/api/2.0/mlflow/databricks/registered-models/get" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getModelResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getModelResponse) return &getModelResponse, err } func (a *modelRegistryImpl) GetModelVersion(ctx context.Context, request GetModelVersionRequest) (*GetModelVersionResponse, error) { var getModelVersionResponse GetModelVersionResponse path := "/api/2.0/mlflow/model-versions/get" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getModelVersionResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getModelVersionResponse) return &getModelVersionResponse, err } func (a *modelRegistryImpl) GetModelVersionDownloadUri(ctx context.Context, request GetModelVersionDownloadUriRequest) (*GetModelVersionDownloadUriResponse, error) { var getModelVersionDownloadUriResponse GetModelVersionDownloadUriResponse path := "/api/2.0/mlflow/model-versions/get-download-uri" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getModelVersionDownloadUriResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getModelVersionDownloadUriResponse) return &getModelVersionDownloadUriResponse, err } func (a *modelRegistryImpl) GetPermissionLevels(ctx context.Context, request GetRegisteredModelPermissionLevelsRequest) (*GetRegisteredModelPermissionLevelsResponse, error) { var getRegisteredModelPermissionLevelsResponse GetRegisteredModelPermissionLevelsResponse path := fmt.Sprintf("/api/2.0/permissions/registered-models/%v/permissionLevels", request.RegisteredModelId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getRegisteredModelPermissionLevelsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getRegisteredModelPermissionLevelsResponse) return &getRegisteredModelPermissionLevelsResponse, err } func (a *modelRegistryImpl) GetPermissions(ctx context.Context, request GetRegisteredModelPermissionsRequest) (*RegisteredModelPermissions, error) { var registeredModelPermissions RegisteredModelPermissions path := fmt.Sprintf("/api/2.0/permissions/registered-models/%v", request.RegisteredModelId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, ®isteredModelPermissions) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, ®isteredModelPermissions) return ®isteredModelPermissions, err } -func (a *modelRegistryImpl) ListModels(ctx context.Context, request ListModelsRequest) (*ListModelsResponse, error) { +// List models. +// +// Lists all available registered models, up to the limit specified in +// __max_results__. +func (a *modelRegistryImpl) ListModels(ctx context.Context, request ListModelsRequest) listing.Iterator[Model] { + + getNextPage := func(ctx context.Context, req ListModelsRequest) (*ListModelsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalListModels(ctx, req) + } + getItems := func(resp *ListModelsResponse) []Model { + return resp.RegisteredModels + } + getNextReq := func(resp *ListModelsResponse) *ListModelsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List models. +// +// Lists all available registered models, up to the limit specified in +// __max_results__. +func (a *modelRegistryImpl) ListModelsAll(ctx context.Context, request ListModelsRequest) ([]Model, error) { + iterator := a.ListModels(ctx, request) + return listing.ToSliceN[Model, int](ctx, iterator, request.MaxResults) + +} +func (a *modelRegistryImpl) internalListModels(ctx context.Context, request ListModelsRequest) (*ListModelsResponse, error) { var listModelsResponse ListModelsResponse path := "/api/2.0/mlflow/registered-models/list" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listModelsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listModelsResponse) return &listModelsResponse, err } -func (a *modelRegistryImpl) ListTransitionRequests(ctx context.Context, request ListTransitionRequestsRequest) (*ListTransitionRequestsResponse, error) { +// List transition requests. +// +// Gets a list of all open stage transition requests for the model version. +func (a *modelRegistryImpl) ListTransitionRequests(ctx context.Context, request ListTransitionRequestsRequest) listing.Iterator[Activity] { + + getNextPage := func(ctx context.Context, req ListTransitionRequestsRequest) (*ListTransitionRequestsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalListTransitionRequests(ctx, req) + } + getItems := func(resp *ListTransitionRequestsResponse) []Activity { + return resp.Requests + } + + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + nil) + return iterator +} + +// List transition requests. +// +// Gets a list of all open stage transition requests for the model version. +func (a *modelRegistryImpl) ListTransitionRequestsAll(ctx context.Context, request ListTransitionRequestsRequest) ([]Activity, error) { + iterator := a.ListTransitionRequests(ctx, request) + return listing.ToSlice[Activity](ctx, iterator) +} +func (a *modelRegistryImpl) internalListTransitionRequests(ctx context.Context, request ListTransitionRequestsRequest) (*ListTransitionRequestsResponse, error) { var listTransitionRequestsResponse ListTransitionRequestsResponse path := "/api/2.0/mlflow/transition-requests/list" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listTransitionRequestsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listTransitionRequestsResponse) return &listTransitionRequestsResponse, err } -func (a *modelRegistryImpl) ListWebhooks(ctx context.Context, request ListWebhooksRequest) (*ListRegistryWebhooks, error) { +// List registry webhooks. +// +// **NOTE:** This endpoint is in Public Preview. +// +// Lists all registry webhooks. +func (a *modelRegistryImpl) ListWebhooks(ctx context.Context, request ListWebhooksRequest) listing.Iterator[RegistryWebhook] { + + getNextPage := func(ctx context.Context, req ListWebhooksRequest) (*ListRegistryWebhooks, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalListWebhooks(ctx, req) + } + getItems := func(resp *ListRegistryWebhooks) []RegistryWebhook { + return resp.Webhooks + } + getNextReq := func(resp *ListRegistryWebhooks) *ListWebhooksRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List registry webhooks. +// +// **NOTE:** This endpoint is in Public Preview. +// +// Lists all registry webhooks. +func (a *modelRegistryImpl) ListWebhooksAll(ctx context.Context, request ListWebhooksRequest) ([]RegistryWebhook, error) { + iterator := a.ListWebhooks(ctx, request) + return listing.ToSlice[RegistryWebhook](ctx, iterator) +} +func (a *modelRegistryImpl) internalListWebhooks(ctx context.Context, request ListWebhooksRequest) (*ListRegistryWebhooks, error) { var listRegistryWebhooks ListRegistryWebhooks path := "/api/2.0/mlflow/registry-webhooks/list" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listRegistryWebhooks) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listRegistryWebhooks) return &listRegistryWebhooks, err } func (a *modelRegistryImpl) RejectTransitionRequest(ctx context.Context, request RejectTransitionRequest) (*RejectTransitionRequestResponse, error) { var rejectTransitionRequestResponse RejectTransitionRequestResponse path := "/api/2.0/mlflow/transition-requests/reject" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &rejectTransitionRequestResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &rejectTransitionRequestResponse) return &rejectTransitionRequestResponse, err } func (a *modelRegistryImpl) RenameModel(ctx context.Context, request RenameModelRequest) (*RenameModelResponse, error) { var renameModelResponse RenameModelResponse path := "/api/2.0/mlflow/registered-models/rename" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &renameModelResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &renameModelResponse) return &renameModelResponse, err } -func (a *modelRegistryImpl) SearchModelVersions(ctx context.Context, request SearchModelVersionsRequest) (*SearchModelVersionsResponse, error) { +// Searches model versions. +// +// Searches for specific model versions based on the supplied __filter__. +func (a *modelRegistryImpl) SearchModelVersions(ctx context.Context, request SearchModelVersionsRequest) listing.Iterator[ModelVersion] { + + getNextPage := func(ctx context.Context, req SearchModelVersionsRequest) (*SearchModelVersionsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalSearchModelVersions(ctx, req) + } + getItems := func(resp *SearchModelVersionsResponse) []ModelVersion { + return resp.ModelVersions + } + getNextReq := func(resp *SearchModelVersionsResponse) *SearchModelVersionsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// Searches model versions. +// +// Searches for specific model versions based on the supplied __filter__. +func (a *modelRegistryImpl) SearchModelVersionsAll(ctx context.Context, request SearchModelVersionsRequest) ([]ModelVersion, error) { + iterator := a.SearchModelVersions(ctx, request) + return listing.ToSliceN[ModelVersion, int](ctx, iterator, request.MaxResults) + +} +func (a *modelRegistryImpl) internalSearchModelVersions(ctx context.Context, request SearchModelVersionsRequest) (*SearchModelVersionsResponse, error) { var searchModelVersionsResponse SearchModelVersionsResponse path := "/api/2.0/mlflow/model-versions/search" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &searchModelVersionsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &searchModelVersionsResponse) return &searchModelVersionsResponse, err } -func (a *modelRegistryImpl) SearchModels(ctx context.Context, request SearchModelsRequest) (*SearchModelsResponse, error) { +// Search models. +// +// Search for registered models based on the specified __filter__. +func (a *modelRegistryImpl) SearchModels(ctx context.Context, request SearchModelsRequest) listing.Iterator[Model] { + + getNextPage := func(ctx context.Context, req SearchModelsRequest) (*SearchModelsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalSearchModels(ctx, req) + } + getItems := func(resp *SearchModelsResponse) []Model { + return resp.RegisteredModels + } + getNextReq := func(resp *SearchModelsResponse) *SearchModelsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// Search models. +// +// Search for registered models based on the specified __filter__. +func (a *modelRegistryImpl) SearchModelsAll(ctx context.Context, request SearchModelsRequest) ([]Model, error) { + iterator := a.SearchModels(ctx, request) + return listing.ToSliceN[Model, int](ctx, iterator, request.MaxResults) + +} +func (a *modelRegistryImpl) internalSearchModels(ctx context.Context, request SearchModelsRequest) (*SearchModelsResponse, error) { var searchModelsResponse SearchModelsResponse path := "/api/2.0/mlflow/registered-models/search" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &searchModelsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &searchModelsResponse) return &searchModelsResponse, err } func (a *modelRegistryImpl) SetModelTag(ctx context.Context, request SetModelTagRequest) error { var setModelTagResponse SetModelTagResponse path := "/api/2.0/mlflow/registered-models/set-tag" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &setModelTagResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &setModelTagResponse) return err } func (a *modelRegistryImpl) SetModelVersionTag(ctx context.Context, request SetModelVersionTagRequest) error { var setModelVersionTagResponse SetModelVersionTagResponse path := "/api/2.0/mlflow/model-versions/set-tag" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &setModelVersionTagResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &setModelVersionTagResponse) return err } func (a *modelRegistryImpl) SetPermissions(ctx context.Context, request RegisteredModelPermissionsRequest) (*RegisteredModelPermissions, error) { var registeredModelPermissions RegisteredModelPermissions path := fmt.Sprintf("/api/2.0/permissions/registered-models/%v", request.RegisteredModelId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, ®isteredModelPermissions) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, ®isteredModelPermissions) return ®isteredModelPermissions, err } func (a *modelRegistryImpl) TestRegistryWebhook(ctx context.Context, request TestRegistryWebhookRequest) (*TestRegistryWebhookResponse, error) { var testRegistryWebhookResponse TestRegistryWebhookResponse path := "/api/2.0/mlflow/registry-webhooks/test" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &testRegistryWebhookResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &testRegistryWebhookResponse) return &testRegistryWebhookResponse, err } func (a *modelRegistryImpl) TransitionStage(ctx context.Context, request TransitionModelVersionStageDatabricks) (*TransitionStageResponse, error) { var transitionStageResponse TransitionStageResponse path := "/api/2.0/mlflow/databricks/model-versions/transition-stage" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &transitionStageResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &transitionStageResponse) return &transitionStageResponse, err } func (a *modelRegistryImpl) UpdateComment(ctx context.Context, request UpdateComment) (*UpdateCommentResponse, error) { var updateCommentResponse UpdateCommentResponse path := "/api/2.0/mlflow/comments/update" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &updateCommentResponse) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &updateCommentResponse) return &updateCommentResponse, err } func (a *modelRegistryImpl) UpdateModel(ctx context.Context, request UpdateModelRequest) error { var updateModelResponse UpdateModelResponse path := "/api/2.0/mlflow/registered-models/update" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &updateModelResponse) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &updateModelResponse) return err } func (a *modelRegistryImpl) UpdateModelVersion(ctx context.Context, request UpdateModelVersionRequest) error { var updateModelVersionResponse UpdateModelVersionResponse path := "/api/2.0/mlflow/model-versions/update" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &updateModelVersionResponse) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &updateModelVersionResponse) return err } func (a *modelRegistryImpl) UpdatePermissions(ctx context.Context, request RegisteredModelPermissionsRequest) (*RegisteredModelPermissions, error) { var registeredModelPermissions RegisteredModelPermissions path := fmt.Sprintf("/api/2.0/permissions/registered-models/%v", request.RegisteredModelId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, ®isteredModelPermissions) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, ®isteredModelPermissions) return ®isteredModelPermissions, err } func (a *modelRegistryImpl) UpdateWebhook(ctx context.Context, request UpdateRegistryWebhook) error { var updateWebhookResponse UpdateWebhookResponse path := "/api/2.0/mlflow/registry-webhooks/update" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &updateWebhookResponse) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &updateWebhookResponse) return err } diff --git a/oauth2/go.mod b/oauth2/go.mod index 570765611..588e6da74 100644 --- a/oauth2/go.mod +++ b/oauth2/go.mod @@ -6,6 +6,7 @@ replace github.com/databricks/databricks-sdk-go/databricks => ../databricks require ( github.com/databricks/databricks-sdk-go/databricks v0.0.0-00010101000000-000000000000 + golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 golang.org/x/oauth2 v0.25.0 ) @@ -27,7 +28,6 @@ require ( go.opentelemetry.io/otel/metric v1.24.0 // indirect go.opentelemetry.io/otel/trace v1.24.0 // indirect golang.org/x/crypto v0.31.0 // indirect - golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.33.0 // indirect golang.org/x/sys v0.28.0 // indirect diff --git a/oauth2/v2/api.go b/oauth2/v2/api.go index da9544202..76b177e8d 100755 --- a/oauth2/v2/api.go +++ b/oauth2/v2/api.go @@ -8,7 +8,6 @@ import ( "github.com/databricks/databricks-sdk-go/databricks/client" "github.com/databricks/databricks-sdk-go/databricks/listing" - "github.com/databricks/databricks-sdk-go/databricks/useragent" ) type AccountFederationPolicyInterface interface { @@ -118,41 +117,6 @@ func (a *AccountFederationPolicyAPI) GetByPolicyId(ctx context.Context, policyId }) } -// List account federation policies. -// -// This method is generated by Databricks SDK Code Generator. -func (a *AccountFederationPolicyAPI) List(ctx context.Context, request ListAccountFederationPoliciesRequest) listing.Iterator[FederationPolicy] { - - getNextPage := func(ctx context.Context, req ListAccountFederationPoliciesRequest) (*ListFederationPoliciesResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.accountFederationPolicyImpl.List(ctx, req) - } - getItems := func(resp *ListFederationPoliciesResponse) []FederationPolicy { - return resp.Policies - } - getNextReq := func(resp *ListFederationPoliciesResponse) *ListAccountFederationPoliciesRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List account federation policies. -// -// This method is generated by Databricks SDK Code Generator. -func (a *AccountFederationPolicyAPI) ListAll(ctx context.Context, request ListAccountFederationPoliciesRequest) ([]FederationPolicy, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[FederationPolicy](ctx, iterator) -} - type CustomAppIntegrationInterface interface { // Create Custom OAuth App Integration. @@ -242,47 +206,6 @@ func (a *CustomAppIntegrationAPI) GetByIntegrationId(ctx context.Context, integr }) } -// Get custom oauth app integrations. -// -// Get the list of custom OAuth app integrations for the specified Databricks -// account -// -// This method is generated by Databricks SDK Code Generator. -func (a *CustomAppIntegrationAPI) List(ctx context.Context, request ListCustomAppIntegrationsRequest) listing.Iterator[GetCustomAppIntegrationOutput] { - - getNextPage := func(ctx context.Context, req ListCustomAppIntegrationsRequest) (*GetCustomAppIntegrationsOutput, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.customAppIntegrationImpl.List(ctx, req) - } - getItems := func(resp *GetCustomAppIntegrationsOutput) []GetCustomAppIntegrationOutput { - return resp.Apps - } - getNextReq := func(resp *GetCustomAppIntegrationsOutput) *ListCustomAppIntegrationsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// Get custom oauth app integrations. -// -// Get the list of custom OAuth app integrations for the specified Databricks -// account -// -// This method is generated by Databricks SDK Code Generator. -func (a *CustomAppIntegrationAPI) ListAll(ctx context.Context, request ListCustomAppIntegrationsRequest) ([]GetCustomAppIntegrationOutput, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[GetCustomAppIntegrationOutput](ctx, iterator) -} - type OAuthPublishedAppsInterface interface { // Get all the published OAuth apps. @@ -316,45 +239,6 @@ type OAuthPublishedAppsAPI struct { oAuthPublishedAppsImpl } -// Get all the published OAuth apps. -// -// Get all the available published OAuth apps in Databricks. -// -// This method is generated by Databricks SDK Code Generator. -func (a *OAuthPublishedAppsAPI) List(ctx context.Context, request ListOAuthPublishedAppsRequest) listing.Iterator[PublishedAppOutput] { - - getNextPage := func(ctx context.Context, req ListOAuthPublishedAppsRequest) (*GetPublishedAppsOutput, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.oAuthPublishedAppsImpl.List(ctx, req) - } - getItems := func(resp *GetPublishedAppsOutput) []PublishedAppOutput { - return resp.Apps - } - getNextReq := func(resp *GetPublishedAppsOutput) *ListOAuthPublishedAppsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// Get all the published OAuth apps. -// -// Get all the available published OAuth apps in Databricks. -// -// This method is generated by Databricks SDK Code Generator. -func (a *OAuthPublishedAppsAPI) ListAll(ctx context.Context, request ListOAuthPublishedAppsRequest) ([]PublishedAppOutput, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[PublishedAppOutput](ctx, iterator) -} - type PublishedAppIntegrationInterface interface { // Create Published OAuth App Integration. @@ -444,47 +328,6 @@ func (a *PublishedAppIntegrationAPI) GetByIntegrationId(ctx context.Context, int }) } -// Get published oauth app integrations. -// -// Get the list of published OAuth app integrations for the specified Databricks -// account -// -// This method is generated by Databricks SDK Code Generator. -func (a *PublishedAppIntegrationAPI) List(ctx context.Context, request ListPublishedAppIntegrationsRequest) listing.Iterator[GetPublishedAppIntegrationOutput] { - - getNextPage := func(ctx context.Context, req ListPublishedAppIntegrationsRequest) (*GetPublishedAppIntegrationsOutput, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.publishedAppIntegrationImpl.List(ctx, req) - } - getItems := func(resp *GetPublishedAppIntegrationsOutput) []GetPublishedAppIntegrationOutput { - return resp.Apps - } - getNextReq := func(resp *GetPublishedAppIntegrationsOutput) *ListPublishedAppIntegrationsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// Get published oauth app integrations. -// -// Get the list of published OAuth app integrations for the specified Databricks -// account -// -// This method is generated by Databricks SDK Code Generator. -func (a *PublishedAppIntegrationAPI) ListAll(ctx context.Context, request ListPublishedAppIntegrationsRequest) ([]GetPublishedAppIntegrationOutput, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[GetPublishedAppIntegrationOutput](ctx, iterator) -} - type ServicePrincipalFederationPolicyInterface interface { // Create service principal federation policy. @@ -601,44 +444,9 @@ func (a *ServicePrincipalFederationPolicyAPI) GetByServicePrincipalIdAndPolicyId }) } -// List service principal federation policies. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ServicePrincipalFederationPolicyAPI) List(ctx context.Context, request ListServicePrincipalFederationPoliciesRequest) listing.Iterator[FederationPolicy] { - - getNextPage := func(ctx context.Context, req ListServicePrincipalFederationPoliciesRequest) (*ListFederationPoliciesResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.servicePrincipalFederationPolicyImpl.List(ctx, req) - } - getItems := func(resp *ListFederationPoliciesResponse) []FederationPolicy { - return resp.Policies - } - getNextReq := func(resp *ListFederationPoliciesResponse) *ListServicePrincipalFederationPoliciesRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List service principal federation policies. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ServicePrincipalFederationPolicyAPI) ListAll(ctx context.Context, request ListServicePrincipalFederationPoliciesRequest) ([]FederationPolicy, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[FederationPolicy](ctx, iterator) -} - // List service principal federation policies. func (a *ServicePrincipalFederationPolicyAPI) ListByServicePrincipalId(ctx context.Context, servicePrincipalId int64) (*ListFederationPoliciesResponse, error) { - return a.servicePrincipalFederationPolicyImpl.List(ctx, ListServicePrincipalFederationPoliciesRequest{ + return a.servicePrincipalFederationPolicyImpl.internalList(ctx, ListServicePrincipalFederationPoliciesRequest{ ServicePrincipalId: servicePrincipalId, }) } @@ -721,56 +529,13 @@ func (a *ServicePrincipalSecretsAPI) DeleteByServicePrincipalIdAndSecretId(ctx c }) } -// List service principal secrets. -// -// List all secrets associated with the given service principal. This operation -// only returns information about the secrets themselves and does not include -// the secret values. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ServicePrincipalSecretsAPI) List(ctx context.Context, request ListServicePrincipalSecretsRequest) listing.Iterator[SecretInfo] { - - getNextPage := func(ctx context.Context, req ListServicePrincipalSecretsRequest) (*ListServicePrincipalSecretsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.servicePrincipalSecretsImpl.List(ctx, req) - } - getItems := func(resp *ListServicePrincipalSecretsResponse) []SecretInfo { - return resp.Secrets - } - getNextReq := func(resp *ListServicePrincipalSecretsResponse) *ListServicePrincipalSecretsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List service principal secrets. -// -// List all secrets associated with the given service principal. This operation -// only returns information about the secrets themselves and does not include -// the secret values. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ServicePrincipalSecretsAPI) ListAll(ctx context.Context, request ListServicePrincipalSecretsRequest) ([]SecretInfo, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[SecretInfo](ctx, iterator) -} - // List service principal secrets. // // List all secrets associated with the given service principal. This operation // only returns information about the secrets themselves and does not include // the secret values. func (a *ServicePrincipalSecretsAPI) ListByServicePrincipalId(ctx context.Context, servicePrincipalId int64) (*ListServicePrincipalSecretsResponse, error) { - return a.servicePrincipalSecretsImpl.List(ctx, ListServicePrincipalSecretsRequest{ + return a.servicePrincipalSecretsImpl.internalList(ctx, ListServicePrincipalSecretsRequest{ ServicePrincipalId: servicePrincipalId, }) } diff --git a/oauth2/v2/impl.go b/oauth2/v2/impl.go index ef39e446c..765c52080 100755 --- a/oauth2/v2/impl.go +++ b/oauth2/v2/impl.go @@ -8,6 +8,9 @@ import ( "net/http" "github.com/databricks/databricks-sdk-go/databricks/client" + "github.com/databricks/databricks-sdk-go/databricks/listing" + "github.com/databricks/databricks-sdk-go/databricks/useragent" + "golang.org/x/exp/slices" ) // unexported type that holds implementations of just AccountFederationPolicy API methods @@ -18,47 +21,88 @@ type accountFederationPolicyImpl struct { func (a *accountFederationPolicyImpl) Create(ctx context.Context, request CreateAccountFederationPolicyRequest) (*FederationPolicy, error) { var federationPolicy FederationPolicy path := fmt.Sprintf("/api/2.0/accounts/%v/federationPolicies", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) + if request.PolicyId != "" || slices.Contains(request.ForceSendFields, "PolicyId") { + queryParams["policy_id"] = request.PolicyId + } headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request.Policy, &federationPolicy) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request.Policy, &federationPolicy) return &federationPolicy, err } func (a *accountFederationPolicyImpl) Delete(ctx context.Context, request DeleteAccountFederationPolicyRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.0/accounts/%v/federationPolicies/%v", a.client.ConfiguredAccountID(), request.PolicyId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *accountFederationPolicyImpl) Get(ctx context.Context, request GetAccountFederationPolicyRequest) (*FederationPolicy, error) { var federationPolicy FederationPolicy path := fmt.Sprintf("/api/2.0/accounts/%v/federationPolicies/%v", a.client.ConfiguredAccountID(), request.PolicyId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &federationPolicy) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &federationPolicy) return &federationPolicy, err } -func (a *accountFederationPolicyImpl) List(ctx context.Context, request ListAccountFederationPoliciesRequest) (*ListFederationPoliciesResponse, error) { +// List account federation policies. +func (a *accountFederationPolicyImpl) List(ctx context.Context, request ListAccountFederationPoliciesRequest) listing.Iterator[FederationPolicy] { + + getNextPage := func(ctx context.Context, req ListAccountFederationPoliciesRequest) (*ListFederationPoliciesResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListFederationPoliciesResponse) []FederationPolicy { + return resp.Policies + } + getNextReq := func(resp *ListFederationPoliciesResponse) *ListAccountFederationPoliciesRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List account federation policies. +func (a *accountFederationPolicyImpl) ListAll(ctx context.Context, request ListAccountFederationPoliciesRequest) ([]FederationPolicy, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[FederationPolicy](ctx, iterator) +} +func (a *accountFederationPolicyImpl) internalList(ctx context.Context, request ListAccountFederationPoliciesRequest) (*ListFederationPoliciesResponse, error) { var listFederationPoliciesResponse ListFederationPoliciesResponse path := fmt.Sprintf("/api/2.0/accounts/%v/federationPolicies", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listFederationPoliciesResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listFederationPoliciesResponse) return &listFederationPoliciesResponse, err } func (a *accountFederationPolicyImpl) Update(ctx context.Context, request UpdateAccountFederationPolicyRequest) (*FederationPolicy, error) { var federationPolicy FederationPolicy path := fmt.Sprintf("/api/2.0/accounts/%v/federationPolicies/%v", a.client.ConfiguredAccountID(), request.PolicyId) + queryParams := make(map[string]any) + if request.UpdateMask != "" || slices.Contains(request.ForceSendFields, "UpdateMask") { + queryParams["update_mask"] = request.UpdateMask + } headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request.Policy, &federationPolicy) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request.Policy, &federationPolicy) return &federationPolicy, err } @@ -70,47 +114,88 @@ type customAppIntegrationImpl struct { func (a *customAppIntegrationImpl) Create(ctx context.Context, request CreateCustomAppIntegration) (*CreateCustomAppIntegrationOutput, error) { var createCustomAppIntegrationOutput CreateCustomAppIntegrationOutput path := fmt.Sprintf("/api/2.0/accounts/%v/oauth2/custom-app-integrations", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createCustomAppIntegrationOutput) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createCustomAppIntegrationOutput) return &createCustomAppIntegrationOutput, err } func (a *customAppIntegrationImpl) Delete(ctx context.Context, request DeleteCustomAppIntegrationRequest) error { var deleteCustomAppIntegrationOutput DeleteCustomAppIntegrationOutput path := fmt.Sprintf("/api/2.0/accounts/%v/oauth2/custom-app-integrations/%v", a.client.ConfiguredAccountID(), request.IntegrationId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteCustomAppIntegrationOutput) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteCustomAppIntegrationOutput) return err } func (a *customAppIntegrationImpl) Get(ctx context.Context, request GetCustomAppIntegrationRequest) (*GetCustomAppIntegrationOutput, error) { var getCustomAppIntegrationOutput GetCustomAppIntegrationOutput path := fmt.Sprintf("/api/2.0/accounts/%v/oauth2/custom-app-integrations/%v", a.client.ConfiguredAccountID(), request.IntegrationId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getCustomAppIntegrationOutput) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getCustomAppIntegrationOutput) return &getCustomAppIntegrationOutput, err } -func (a *customAppIntegrationImpl) List(ctx context.Context, request ListCustomAppIntegrationsRequest) (*GetCustomAppIntegrationsOutput, error) { +// Get custom oauth app integrations. +// +// Get the list of custom OAuth app integrations for the specified Databricks +// account +func (a *customAppIntegrationImpl) List(ctx context.Context, request ListCustomAppIntegrationsRequest) listing.Iterator[GetCustomAppIntegrationOutput] { + + getNextPage := func(ctx context.Context, req ListCustomAppIntegrationsRequest) (*GetCustomAppIntegrationsOutput, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *GetCustomAppIntegrationsOutput) []GetCustomAppIntegrationOutput { + return resp.Apps + } + getNextReq := func(resp *GetCustomAppIntegrationsOutput) *ListCustomAppIntegrationsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// Get custom oauth app integrations. +// +// Get the list of custom OAuth app integrations for the specified Databricks +// account +func (a *customAppIntegrationImpl) ListAll(ctx context.Context, request ListCustomAppIntegrationsRequest) ([]GetCustomAppIntegrationOutput, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[GetCustomAppIntegrationOutput](ctx, iterator) +} +func (a *customAppIntegrationImpl) internalList(ctx context.Context, request ListCustomAppIntegrationsRequest) (*GetCustomAppIntegrationsOutput, error) { var getCustomAppIntegrationsOutput GetCustomAppIntegrationsOutput path := fmt.Sprintf("/api/2.0/accounts/%v/oauth2/custom-app-integrations", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getCustomAppIntegrationsOutput) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getCustomAppIntegrationsOutput) return &getCustomAppIntegrationsOutput, err } func (a *customAppIntegrationImpl) Update(ctx context.Context, request UpdateCustomAppIntegration) error { var updateCustomAppIntegrationOutput UpdateCustomAppIntegrationOutput path := fmt.Sprintf("/api/2.0/accounts/%v/oauth2/custom-app-integrations/%v", a.client.ConfiguredAccountID(), request.IntegrationId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &updateCustomAppIntegrationOutput) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &updateCustomAppIntegrationOutput) return err } @@ -119,12 +204,47 @@ type oAuthPublishedAppsImpl struct { client *client.DatabricksClient } -func (a *oAuthPublishedAppsImpl) List(ctx context.Context, request ListOAuthPublishedAppsRequest) (*GetPublishedAppsOutput, error) { +// Get all the published OAuth apps. +// +// Get all the available published OAuth apps in Databricks. +func (a *oAuthPublishedAppsImpl) List(ctx context.Context, request ListOAuthPublishedAppsRequest) listing.Iterator[PublishedAppOutput] { + + getNextPage := func(ctx context.Context, req ListOAuthPublishedAppsRequest) (*GetPublishedAppsOutput, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *GetPublishedAppsOutput) []PublishedAppOutput { + return resp.Apps + } + getNextReq := func(resp *GetPublishedAppsOutput) *ListOAuthPublishedAppsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// Get all the published OAuth apps. +// +// Get all the available published OAuth apps in Databricks. +func (a *oAuthPublishedAppsImpl) ListAll(ctx context.Context, request ListOAuthPublishedAppsRequest) ([]PublishedAppOutput, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[PublishedAppOutput](ctx, iterator) +} +func (a *oAuthPublishedAppsImpl) internalList(ctx context.Context, request ListOAuthPublishedAppsRequest) (*GetPublishedAppsOutput, error) { var getPublishedAppsOutput GetPublishedAppsOutput path := fmt.Sprintf("/api/2.0/accounts/%v/oauth2/published-apps", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getPublishedAppsOutput) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getPublishedAppsOutput) return &getPublishedAppsOutput, err } @@ -136,47 +256,88 @@ type publishedAppIntegrationImpl struct { func (a *publishedAppIntegrationImpl) Create(ctx context.Context, request CreatePublishedAppIntegration) (*CreatePublishedAppIntegrationOutput, error) { var createPublishedAppIntegrationOutput CreatePublishedAppIntegrationOutput path := fmt.Sprintf("/api/2.0/accounts/%v/oauth2/published-app-integrations", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createPublishedAppIntegrationOutput) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createPublishedAppIntegrationOutput) return &createPublishedAppIntegrationOutput, err } func (a *publishedAppIntegrationImpl) Delete(ctx context.Context, request DeletePublishedAppIntegrationRequest) error { var deletePublishedAppIntegrationOutput DeletePublishedAppIntegrationOutput path := fmt.Sprintf("/api/2.0/accounts/%v/oauth2/published-app-integrations/%v", a.client.ConfiguredAccountID(), request.IntegrationId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deletePublishedAppIntegrationOutput) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deletePublishedAppIntegrationOutput) return err } func (a *publishedAppIntegrationImpl) Get(ctx context.Context, request GetPublishedAppIntegrationRequest) (*GetPublishedAppIntegrationOutput, error) { var getPublishedAppIntegrationOutput GetPublishedAppIntegrationOutput path := fmt.Sprintf("/api/2.0/accounts/%v/oauth2/published-app-integrations/%v", a.client.ConfiguredAccountID(), request.IntegrationId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getPublishedAppIntegrationOutput) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getPublishedAppIntegrationOutput) return &getPublishedAppIntegrationOutput, err } -func (a *publishedAppIntegrationImpl) List(ctx context.Context, request ListPublishedAppIntegrationsRequest) (*GetPublishedAppIntegrationsOutput, error) { +// Get published oauth app integrations. +// +// Get the list of published OAuth app integrations for the specified Databricks +// account +func (a *publishedAppIntegrationImpl) List(ctx context.Context, request ListPublishedAppIntegrationsRequest) listing.Iterator[GetPublishedAppIntegrationOutput] { + + getNextPage := func(ctx context.Context, req ListPublishedAppIntegrationsRequest) (*GetPublishedAppIntegrationsOutput, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *GetPublishedAppIntegrationsOutput) []GetPublishedAppIntegrationOutput { + return resp.Apps + } + getNextReq := func(resp *GetPublishedAppIntegrationsOutput) *ListPublishedAppIntegrationsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// Get published oauth app integrations. +// +// Get the list of published OAuth app integrations for the specified Databricks +// account +func (a *publishedAppIntegrationImpl) ListAll(ctx context.Context, request ListPublishedAppIntegrationsRequest) ([]GetPublishedAppIntegrationOutput, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[GetPublishedAppIntegrationOutput](ctx, iterator) +} +func (a *publishedAppIntegrationImpl) internalList(ctx context.Context, request ListPublishedAppIntegrationsRequest) (*GetPublishedAppIntegrationsOutput, error) { var getPublishedAppIntegrationsOutput GetPublishedAppIntegrationsOutput path := fmt.Sprintf("/api/2.0/accounts/%v/oauth2/published-app-integrations", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getPublishedAppIntegrationsOutput) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getPublishedAppIntegrationsOutput) return &getPublishedAppIntegrationsOutput, err } func (a *publishedAppIntegrationImpl) Update(ctx context.Context, request UpdatePublishedAppIntegration) error { var updatePublishedAppIntegrationOutput UpdatePublishedAppIntegrationOutput path := fmt.Sprintf("/api/2.0/accounts/%v/oauth2/published-app-integrations/%v", a.client.ConfiguredAccountID(), request.IntegrationId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &updatePublishedAppIntegrationOutput) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &updatePublishedAppIntegrationOutput) return err } @@ -188,47 +349,88 @@ type servicePrincipalFederationPolicyImpl struct { func (a *servicePrincipalFederationPolicyImpl) Create(ctx context.Context, request CreateServicePrincipalFederationPolicyRequest) (*FederationPolicy, error) { var federationPolicy FederationPolicy path := fmt.Sprintf("/api/2.0/accounts/%v/servicePrincipals/%v/federationPolicies", a.client.ConfiguredAccountID(), request.ServicePrincipalId) + queryParams := make(map[string]any) + if request.PolicyId != "" || slices.Contains(request.ForceSendFields, "PolicyId") { + queryParams["policy_id"] = request.PolicyId + } headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request.Policy, &federationPolicy) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request.Policy, &federationPolicy) return &federationPolicy, err } func (a *servicePrincipalFederationPolicyImpl) Delete(ctx context.Context, request DeleteServicePrincipalFederationPolicyRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.0/accounts/%v/servicePrincipals/%v/federationPolicies/%v", a.client.ConfiguredAccountID(), request.ServicePrincipalId, request.PolicyId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *servicePrincipalFederationPolicyImpl) Get(ctx context.Context, request GetServicePrincipalFederationPolicyRequest) (*FederationPolicy, error) { var federationPolicy FederationPolicy path := fmt.Sprintf("/api/2.0/accounts/%v/servicePrincipals/%v/federationPolicies/%v", a.client.ConfiguredAccountID(), request.ServicePrincipalId, request.PolicyId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &federationPolicy) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &federationPolicy) return &federationPolicy, err } -func (a *servicePrincipalFederationPolicyImpl) List(ctx context.Context, request ListServicePrincipalFederationPoliciesRequest) (*ListFederationPoliciesResponse, error) { +// List service principal federation policies. +func (a *servicePrincipalFederationPolicyImpl) List(ctx context.Context, request ListServicePrincipalFederationPoliciesRequest) listing.Iterator[FederationPolicy] { + + getNextPage := func(ctx context.Context, req ListServicePrincipalFederationPoliciesRequest) (*ListFederationPoliciesResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListFederationPoliciesResponse) []FederationPolicy { + return resp.Policies + } + getNextReq := func(resp *ListFederationPoliciesResponse) *ListServicePrincipalFederationPoliciesRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List service principal federation policies. +func (a *servicePrincipalFederationPolicyImpl) ListAll(ctx context.Context, request ListServicePrincipalFederationPoliciesRequest) ([]FederationPolicy, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[FederationPolicy](ctx, iterator) +} +func (a *servicePrincipalFederationPolicyImpl) internalList(ctx context.Context, request ListServicePrincipalFederationPoliciesRequest) (*ListFederationPoliciesResponse, error) { var listFederationPoliciesResponse ListFederationPoliciesResponse path := fmt.Sprintf("/api/2.0/accounts/%v/servicePrincipals/%v/federationPolicies", a.client.ConfiguredAccountID(), request.ServicePrincipalId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listFederationPoliciesResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listFederationPoliciesResponse) return &listFederationPoliciesResponse, err } func (a *servicePrincipalFederationPolicyImpl) Update(ctx context.Context, request UpdateServicePrincipalFederationPolicyRequest) (*FederationPolicy, error) { var federationPolicy FederationPolicy path := fmt.Sprintf("/api/2.0/accounts/%v/servicePrincipals/%v/federationPolicies/%v", a.client.ConfiguredAccountID(), request.ServicePrincipalId, request.PolicyId) + queryParams := make(map[string]any) + if request.UpdateMask != "" || slices.Contains(request.ForceSendFields, "UpdateMask") { + queryParams["update_mask"] = request.UpdateMask + } headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request.Policy, &federationPolicy) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request.Policy, &federationPolicy) return &federationPolicy, err } @@ -240,25 +442,66 @@ type servicePrincipalSecretsImpl struct { func (a *servicePrincipalSecretsImpl) Create(ctx context.Context, request CreateServicePrincipalSecretRequest) (*CreateServicePrincipalSecretResponse, error) { var createServicePrincipalSecretResponse CreateServicePrincipalSecretResponse path := fmt.Sprintf("/api/2.0/accounts/%v/servicePrincipals/%v/credentials/secrets", a.client.ConfiguredAccountID(), request.ServicePrincipalId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, nil, &createServicePrincipalSecretResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, nil, &createServicePrincipalSecretResponse) return &createServicePrincipalSecretResponse, err } func (a *servicePrincipalSecretsImpl) Delete(ctx context.Context, request DeleteServicePrincipalSecretRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.0/accounts/%v/servicePrincipals/%v/credentials/secrets/%v", a.client.ConfiguredAccountID(), request.ServicePrincipalId, request.SecretId) + queryParams := make(map[string]any) headers := make(map[string]string) - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } -func (a *servicePrincipalSecretsImpl) List(ctx context.Context, request ListServicePrincipalSecretsRequest) (*ListServicePrincipalSecretsResponse, error) { +// List service principal secrets. +// +// List all secrets associated with the given service principal. This operation +// only returns information about the secrets themselves and does not include +// the secret values. +func (a *servicePrincipalSecretsImpl) List(ctx context.Context, request ListServicePrincipalSecretsRequest) listing.Iterator[SecretInfo] { + + getNextPage := func(ctx context.Context, req ListServicePrincipalSecretsRequest) (*ListServicePrincipalSecretsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListServicePrincipalSecretsResponse) []SecretInfo { + return resp.Secrets + } + getNextReq := func(resp *ListServicePrincipalSecretsResponse) *ListServicePrincipalSecretsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List service principal secrets. +// +// List all secrets associated with the given service principal. This operation +// only returns information about the secrets themselves and does not include +// the secret values. +func (a *servicePrincipalSecretsImpl) ListAll(ctx context.Context, request ListServicePrincipalSecretsRequest) ([]SecretInfo, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[SecretInfo](ctx, iterator) +} +func (a *servicePrincipalSecretsImpl) internalList(ctx context.Context, request ListServicePrincipalSecretsRequest) (*ListServicePrincipalSecretsResponse, error) { var listServicePrincipalSecretsResponse ListServicePrincipalSecretsResponse path := fmt.Sprintf("/api/2.0/accounts/%v/servicePrincipals/%v/credentials/secrets", a.client.ConfiguredAccountID(), request.ServicePrincipalId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listServicePrincipalSecretsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listServicePrincipalSecretsResponse) return &listServicePrincipalSecretsResponse, err } diff --git a/pipelines/go.mod b/pipelines/go.mod index 8cc0f3956..1b2079faf 100644 --- a/pipelines/go.mod +++ b/pipelines/go.mod @@ -6,6 +6,7 @@ replace github.com/databricks/databricks-sdk-go/databricks => ../databricks require ( github.com/databricks/databricks-sdk-go/databricks v0.0.0-00010101000000-000000000000 + golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 golang.org/x/oauth2 v0.25.0 ) @@ -27,7 +28,6 @@ require ( go.opentelemetry.io/otel/metric v1.24.0 // indirect go.opentelemetry.io/otel/trace v1.24.0 // indirect golang.org/x/crypto v0.31.0 // indirect - golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.33.0 // indirect golang.org/x/sys v0.28.0 // indirect diff --git a/pipelines/v2/api.go b/pipelines/v2/api.go index 7ba721982..be187b07f 100755 --- a/pipelines/v2/api.go +++ b/pipelines/v2/api.go @@ -232,95 +232,15 @@ func (a *PipelinesAPI) GetUpdateByPipelineIdAndUpdateId(ctx context.Context, pip }) } -// List pipeline events. -// -// Retrieves events for a pipeline. -// -// This method is generated by Databricks SDK Code Generator. -func (a *PipelinesAPI) ListPipelineEvents(ctx context.Context, request ListPipelineEventsRequest) listing.Iterator[PipelineEvent] { - - getNextPage := func(ctx context.Context, req ListPipelineEventsRequest) (*ListPipelineEventsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.pipelinesImpl.ListPipelineEvents(ctx, req) - } - getItems := func(resp *ListPipelineEventsResponse) []PipelineEvent { - return resp.Events - } - getNextReq := func(resp *ListPipelineEventsResponse) *ListPipelineEventsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List pipeline events. -// -// Retrieves events for a pipeline. -// -// This method is generated by Databricks SDK Code Generator. -func (a *PipelinesAPI) ListPipelineEventsAll(ctx context.Context, request ListPipelineEventsRequest) ([]PipelineEvent, error) { - iterator := a.ListPipelineEvents(ctx, request) - return listing.ToSliceN[PipelineEvent, int](ctx, iterator, request.MaxResults) - -} - // List pipeline events. // // Retrieves events for a pipeline. func (a *PipelinesAPI) ListPipelineEventsByPipelineId(ctx context.Context, pipelineId string) (*ListPipelineEventsResponse, error) { - return a.pipelinesImpl.ListPipelineEvents(ctx, ListPipelineEventsRequest{ + return a.pipelinesImpl.internalListPipelineEvents(ctx, ListPipelineEventsRequest{ PipelineId: pipelineId, }) } -// List pipelines. -// -// Lists pipelines defined in the Delta Live Tables system. -// -// This method is generated by Databricks SDK Code Generator. -func (a *PipelinesAPI) ListPipelines(ctx context.Context, request ListPipelinesRequest) listing.Iterator[PipelineStateInfo] { - - getNextPage := func(ctx context.Context, req ListPipelinesRequest) (*ListPipelinesResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.pipelinesImpl.ListPipelines(ctx, req) - } - getItems := func(resp *ListPipelinesResponse) []PipelineStateInfo { - return resp.Statuses - } - getNextReq := func(resp *ListPipelinesResponse) *ListPipelinesRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List pipelines. -// -// Lists pipelines defined in the Delta Live Tables system. -// -// This method is generated by Databricks SDK Code Generator. -func (a *PipelinesAPI) ListPipelinesAll(ctx context.Context, request ListPipelinesRequest) ([]PipelineStateInfo, error) { - iterator := a.ListPipelines(ctx, request) - return listing.ToSliceN[PipelineStateInfo, int](ctx, iterator, request.MaxResults) - -} - // PipelineStateInfoNameToPipelineIdMap calls [PipelinesAPI.ListPipelinesAll] and creates a map of results with [PipelineStateInfo].Name as key and [PipelineStateInfo].PipelineId as value. // // Returns an error if there's more than one [PipelineStateInfo] with the same .Name. diff --git a/pipelines/v2/impl.go b/pipelines/v2/impl.go index 24632cf2e..402609f44 100755 --- a/pipelines/v2/impl.go +++ b/pipelines/v2/impl.go @@ -8,6 +8,8 @@ import ( "net/http" "github.com/databricks/databricks-sdk-go/databricks/client" + "github.com/databricks/databricks-sdk-go/databricks/listing" + "github.com/databricks/databricks-sdk-go/databricks/useragent" ) // unexported type that holds implementations of just Pipelines API methods @@ -18,130 +20,214 @@ type pipelinesImpl struct { func (a *pipelinesImpl) Create(ctx context.Context, request CreatePipeline) (*CreatePipelineResponse, error) { var createPipelineResponse CreatePipelineResponse path := "/api/2.0/pipelines" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createPipelineResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createPipelineResponse) return &createPipelineResponse, err } func (a *pipelinesImpl) Delete(ctx context.Context, request DeletePipelineRequest) error { var deletePipelineResponse DeletePipelineResponse path := fmt.Sprintf("/api/2.0/pipelines/%v", request.PipelineId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deletePipelineResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deletePipelineResponse) return err } func (a *pipelinesImpl) Get(ctx context.Context, request GetPipelineRequest) (*GetPipelineResponse, error) { var getPipelineResponse GetPipelineResponse path := fmt.Sprintf("/api/2.0/pipelines/%v", request.PipelineId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getPipelineResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getPipelineResponse) return &getPipelineResponse, err } func (a *pipelinesImpl) GetPermissionLevels(ctx context.Context, request GetPipelinePermissionLevelsRequest) (*GetPipelinePermissionLevelsResponse, error) { var getPipelinePermissionLevelsResponse GetPipelinePermissionLevelsResponse path := fmt.Sprintf("/api/2.0/permissions/pipelines/%v/permissionLevels", request.PipelineId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getPipelinePermissionLevelsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getPipelinePermissionLevelsResponse) return &getPipelinePermissionLevelsResponse, err } func (a *pipelinesImpl) GetPermissions(ctx context.Context, request GetPipelinePermissionsRequest) (*PipelinePermissions, error) { var pipelinePermissions PipelinePermissions path := fmt.Sprintf("/api/2.0/permissions/pipelines/%v", request.PipelineId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &pipelinePermissions) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &pipelinePermissions) return &pipelinePermissions, 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) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getUpdateResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getUpdateResponse) return &getUpdateResponse, err } -func (a *pipelinesImpl) ListPipelineEvents(ctx context.Context, request ListPipelineEventsRequest) (*ListPipelineEventsResponse, error) { +// List pipeline events. +// +// Retrieves events for a pipeline. +func (a *pipelinesImpl) ListPipelineEvents(ctx context.Context, request ListPipelineEventsRequest) listing.Iterator[PipelineEvent] { + + getNextPage := func(ctx context.Context, req ListPipelineEventsRequest) (*ListPipelineEventsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalListPipelineEvents(ctx, req) + } + getItems := func(resp *ListPipelineEventsResponse) []PipelineEvent { + return resp.Events + } + getNextReq := func(resp *ListPipelineEventsResponse) *ListPipelineEventsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List pipeline events. +// +// Retrieves events for a pipeline. +func (a *pipelinesImpl) ListPipelineEventsAll(ctx context.Context, request ListPipelineEventsRequest) ([]PipelineEvent, error) { + iterator := a.ListPipelineEvents(ctx, request) + return listing.ToSliceN[PipelineEvent, int](ctx, iterator, request.MaxResults) + +} +func (a *pipelinesImpl) internalListPipelineEvents(ctx context.Context, request ListPipelineEventsRequest) (*ListPipelineEventsResponse, error) { var listPipelineEventsResponse ListPipelineEventsResponse path := fmt.Sprintf("/api/2.0/pipelines/%v/events", request.PipelineId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listPipelineEventsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listPipelineEventsResponse) return &listPipelineEventsResponse, err } -func (a *pipelinesImpl) ListPipelines(ctx context.Context, request ListPipelinesRequest) (*ListPipelinesResponse, error) { +// List pipelines. +// +// Lists pipelines defined in the Delta Live Tables system. +func (a *pipelinesImpl) ListPipelines(ctx context.Context, request ListPipelinesRequest) listing.Iterator[PipelineStateInfo] { + + getNextPage := func(ctx context.Context, req ListPipelinesRequest) (*ListPipelinesResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalListPipelines(ctx, req) + } + getItems := func(resp *ListPipelinesResponse) []PipelineStateInfo { + return resp.Statuses + } + getNextReq := func(resp *ListPipelinesResponse) *ListPipelinesRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List pipelines. +// +// Lists pipelines defined in the Delta Live Tables system. +func (a *pipelinesImpl) ListPipelinesAll(ctx context.Context, request ListPipelinesRequest) ([]PipelineStateInfo, error) { + iterator := a.ListPipelines(ctx, request) + return listing.ToSliceN[PipelineStateInfo, int](ctx, iterator, request.MaxResults) + +} +func (a *pipelinesImpl) internalListPipelines(ctx context.Context, request ListPipelinesRequest) (*ListPipelinesResponse, error) { var listPipelinesResponse ListPipelinesResponse path := "/api/2.0/pipelines" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listPipelinesResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listPipelinesResponse) return &listPipelinesResponse, 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) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listUpdatesResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listUpdatesResponse) return &listUpdatesResponse, err } func (a *pipelinesImpl) SetPermissions(ctx context.Context, request PipelinePermissionsRequest) (*PipelinePermissions, error) { var pipelinePermissions PipelinePermissions path := fmt.Sprintf("/api/2.0/permissions/pipelines/%v", request.PipelineId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &pipelinePermissions) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &pipelinePermissions) return &pipelinePermissions, 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) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &startUpdateResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &startUpdateResponse) return &startUpdateResponse, err } func (a *pipelinesImpl) Stop(ctx context.Context, request StopRequest) error { var stopPipelineResponse StopPipelineResponse path := fmt.Sprintf("/api/2.0/pipelines/%v/stop", request.PipelineId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, nil, &stopPipelineResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, nil, &stopPipelineResponse) return err } func (a *pipelinesImpl) Update(ctx context.Context, request EditPipeline) error { var editPipelineResponse EditPipelineResponse path := fmt.Sprintf("/api/2.0/pipelines/%v", request.PipelineId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &editPipelineResponse) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &editPipelineResponse) return err } func (a *pipelinesImpl) UpdatePermissions(ctx context.Context, request PipelinePermissionsRequest) (*PipelinePermissions, error) { var pipelinePermissions PipelinePermissions path := fmt.Sprintf("/api/2.0/permissions/pipelines/%v", request.PipelineId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &pipelinePermissions) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &pipelinePermissions) return &pipelinePermissions, err } diff --git a/pipelines/v2/model.go b/pipelines/v2/model.go index 7587f2732..dcc58431f 100755 --- a/pipelines/v2/model.go +++ b/pipelines/v2/model.go @@ -222,6 +222,9 @@ type ClusterLogConf struct { // the cluster iam role in `instance_profile_arn` has permission to write // data to the s3 destination. S3 *S3StorageInfo `json:"s3,omitempty"` + // destination needs to be provided. e.g. `{ "volumes" : { "destination" : + // "/Volumes/catalog/schema/volume/cluster_log" } }` + Volumes *VolumesStorageInfo `json:"volumes,omitempty"` } type CreatePipeline struct { @@ -2306,7 +2309,8 @@ func (f *UpdateStateInfoState) Type() string { } type VolumesStorageInfo struct { - // Unity Catalog Volumes file destination, e.g. `/Volumes/my-init.sh` + // Unity Catalog volumes file destination, e.g. + // `/Volumes/catalog/schema/volume/dir/file` Destination string `json:"destination"` } diff --git a/provisioning/go.mod b/provisioning/go.mod index a8b58cbf0..10b9007ca 100644 --- a/provisioning/go.mod +++ b/provisioning/go.mod @@ -7,6 +7,7 @@ replace github.com/databricks/databricks-sdk-go/databricks => ../databricks require ( github.com/databricks/databricks-sdk-go/databricks v0.0.0-00010101000000-000000000000 github.com/stretchr/testify v1.10.0 + golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 golang.org/x/oauth2 v0.25.0 ) @@ -30,7 +31,6 @@ require ( go.opentelemetry.io/otel/metric v1.24.0 // indirect go.opentelemetry.io/otel/trace v1.24.0 // indirect golang.org/x/crypto v0.31.0 // indirect - golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.33.0 // indirect golang.org/x/sys v0.28.0 // indirect diff --git a/provisioning/v2/impl.go b/provisioning/v2/impl.go index 0dffec941..ef9403dbd 100755 --- a/provisioning/v2/impl.go +++ b/provisioning/v2/impl.go @@ -18,37 +18,41 @@ type credentialsImpl struct { func (a *credentialsImpl) Create(ctx context.Context, request CreateCredentialRequest) (*Credential, error) { var credential Credential path := fmt.Sprintf("/api/2.0/accounts/%v/credentials", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &credential) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &credential) return &credential, err } func (a *credentialsImpl) Delete(ctx context.Context, request DeleteCredentialRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.0/accounts/%v/credentials/%v", a.client.ConfiguredAccountID(), request.CredentialsId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *credentialsImpl) Get(ctx context.Context, request GetCredentialRequest) (*Credential, error) { var credential Credential path := fmt.Sprintf("/api/2.0/accounts/%v/credentials/%v", a.client.ConfiguredAccountID(), request.CredentialsId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &credential) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &credential) return &credential, err } func (a *credentialsImpl) List(ctx context.Context) ([]Credential, error) { var credentialList []Credential path := fmt.Sprintf("/api/2.0/accounts/%v/credentials", a.client.ConfiguredAccountID()) + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &credentialList) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &credentialList) return credentialList, err } @@ -60,37 +64,41 @@ type encryptionKeysImpl struct { func (a *encryptionKeysImpl) Create(ctx context.Context, request CreateCustomerManagedKeyRequest) (*CustomerManagedKey, error) { var customerManagedKey CustomerManagedKey path := fmt.Sprintf("/api/2.0/accounts/%v/customer-managed-keys", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &customerManagedKey) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &customerManagedKey) return &customerManagedKey, err } func (a *encryptionKeysImpl) Delete(ctx context.Context, request DeleteEncryptionKeyRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.0/accounts/%v/customer-managed-keys/%v", a.client.ConfiguredAccountID(), request.CustomerManagedKeyId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *encryptionKeysImpl) Get(ctx context.Context, request GetEncryptionKeyRequest) (*CustomerManagedKey, error) { var customerManagedKey CustomerManagedKey path := fmt.Sprintf("/api/2.0/accounts/%v/customer-managed-keys/%v", a.client.ConfiguredAccountID(), request.CustomerManagedKeyId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &customerManagedKey) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &customerManagedKey) return &customerManagedKey, err } func (a *encryptionKeysImpl) List(ctx context.Context) ([]CustomerManagedKey, error) { var customerManagedKeyList []CustomerManagedKey path := fmt.Sprintf("/api/2.0/accounts/%v/customer-managed-keys", a.client.ConfiguredAccountID()) + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &customerManagedKeyList) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &customerManagedKeyList) return customerManagedKeyList, err } @@ -102,37 +110,41 @@ type networksImpl struct { func (a *networksImpl) Create(ctx context.Context, request CreateNetworkRequest) (*Network, error) { var network Network path := fmt.Sprintf("/api/2.0/accounts/%v/networks", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &network) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &network) return &network, err } func (a *networksImpl) Delete(ctx context.Context, request DeleteNetworkRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.0/accounts/%v/networks/%v", a.client.ConfiguredAccountID(), request.NetworkId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *networksImpl) Get(ctx context.Context, request GetNetworkRequest) (*Network, error) { var network Network path := fmt.Sprintf("/api/2.0/accounts/%v/networks/%v", a.client.ConfiguredAccountID(), request.NetworkId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &network) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &network) return &network, err } func (a *networksImpl) List(ctx context.Context) ([]Network, error) { var networkList []Network path := fmt.Sprintf("/api/2.0/accounts/%v/networks", a.client.ConfiguredAccountID()) + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &networkList) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &networkList) return networkList, err } @@ -144,47 +156,52 @@ type privateAccessImpl struct { func (a *privateAccessImpl) Create(ctx context.Context, request UpsertPrivateAccessSettingsRequest) (*PrivateAccessSettings, error) { var privateAccessSettings PrivateAccessSettings path := fmt.Sprintf("/api/2.0/accounts/%v/private-access-settings", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &privateAccessSettings) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &privateAccessSettings) return &privateAccessSettings, err } func (a *privateAccessImpl) Delete(ctx context.Context, request DeletePrivateAccesRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.0/accounts/%v/private-access-settings/%v", a.client.ConfiguredAccountID(), request.PrivateAccessSettingsId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *privateAccessImpl) Get(ctx context.Context, request GetPrivateAccesRequest) (*PrivateAccessSettings, error) { var privateAccessSettings PrivateAccessSettings path := fmt.Sprintf("/api/2.0/accounts/%v/private-access-settings/%v", a.client.ConfiguredAccountID(), request.PrivateAccessSettingsId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &privateAccessSettings) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &privateAccessSettings) return &privateAccessSettings, err } func (a *privateAccessImpl) List(ctx context.Context) ([]PrivateAccessSettings, error) { var privateAccessSettingsList []PrivateAccessSettings path := fmt.Sprintf("/api/2.0/accounts/%v/private-access-settings", a.client.ConfiguredAccountID()) + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &privateAccessSettingsList) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &privateAccessSettingsList) return privateAccessSettingsList, err } func (a *privateAccessImpl) Replace(ctx context.Context, request UpsertPrivateAccessSettingsRequest) error { var replaceResponse ReplaceResponse path := fmt.Sprintf("/api/2.0/accounts/%v/private-access-settings/%v", a.client.ConfiguredAccountID(), request.PrivateAccessSettingsId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &replaceResponse) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &replaceResponse) return err } @@ -196,37 +213,41 @@ type storageImpl struct { func (a *storageImpl) Create(ctx context.Context, request CreateStorageConfigurationRequest) (*StorageConfiguration, error) { var storageConfiguration StorageConfiguration path := fmt.Sprintf("/api/2.0/accounts/%v/storage-configurations", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &storageConfiguration) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &storageConfiguration) return &storageConfiguration, err } func (a *storageImpl) Delete(ctx context.Context, request DeleteStorageRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.0/accounts/%v/storage-configurations/%v", a.client.ConfiguredAccountID(), request.StorageConfigurationId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *storageImpl) Get(ctx context.Context, request GetStorageRequest) (*StorageConfiguration, error) { var storageConfiguration StorageConfiguration path := fmt.Sprintf("/api/2.0/accounts/%v/storage-configurations/%v", a.client.ConfiguredAccountID(), request.StorageConfigurationId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &storageConfiguration) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &storageConfiguration) return &storageConfiguration, err } func (a *storageImpl) List(ctx context.Context) ([]StorageConfiguration, error) { var storageConfigurationList []StorageConfiguration path := fmt.Sprintf("/api/2.0/accounts/%v/storage-configurations", a.client.ConfiguredAccountID()) + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &storageConfigurationList) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &storageConfigurationList) return storageConfigurationList, err } @@ -238,37 +259,41 @@ type vpcEndpointsImpl struct { func (a *vpcEndpointsImpl) Create(ctx context.Context, request CreateVpcEndpointRequest) (*VpcEndpoint, error) { var vpcEndpoint VpcEndpoint path := fmt.Sprintf("/api/2.0/accounts/%v/vpc-endpoints", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &vpcEndpoint) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &vpcEndpoint) return &vpcEndpoint, err } func (a *vpcEndpointsImpl) Delete(ctx context.Context, request DeleteVpcEndpointRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.0/accounts/%v/vpc-endpoints/%v", a.client.ConfiguredAccountID(), request.VpcEndpointId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *vpcEndpointsImpl) Get(ctx context.Context, request GetVpcEndpointRequest) (*VpcEndpoint, error) { var vpcEndpoint VpcEndpoint path := fmt.Sprintf("/api/2.0/accounts/%v/vpc-endpoints/%v", a.client.ConfiguredAccountID(), request.VpcEndpointId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &vpcEndpoint) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &vpcEndpoint) return &vpcEndpoint, err } func (a *vpcEndpointsImpl) List(ctx context.Context) ([]VpcEndpoint, error) { var vpcEndpointList []VpcEndpoint path := fmt.Sprintf("/api/2.0/accounts/%v/vpc-endpoints", a.client.ConfiguredAccountID()) + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &vpcEndpointList) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &vpcEndpointList) return vpcEndpointList, err } @@ -280,46 +305,51 @@ type workspacesImpl struct { func (a *workspacesImpl) Create(ctx context.Context, request CreateWorkspaceRequest) (*Workspace, error) { var workspace Workspace path := fmt.Sprintf("/api/2.0/accounts/%v/workspaces", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &workspace) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &workspace) return &workspace, err } func (a *workspacesImpl) Delete(ctx context.Context, request DeleteWorkspaceRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.0/accounts/%v/workspaces/%v", a.client.ConfiguredAccountID(), request.WorkspaceId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *workspacesImpl) Get(ctx context.Context, request GetWorkspaceRequest) (*Workspace, error) { var workspace Workspace path := fmt.Sprintf("/api/2.0/accounts/%v/workspaces/%v", a.client.ConfiguredAccountID(), request.WorkspaceId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &workspace) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &workspace) return &workspace, err } func (a *workspacesImpl) List(ctx context.Context) ([]Workspace, error) { var workspaceList []Workspace path := fmt.Sprintf("/api/2.0/accounts/%v/workspaces", a.client.ConfiguredAccountID()) + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &workspaceList) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &workspaceList) return workspaceList, err } func (a *workspacesImpl) Update(ctx context.Context, request UpdateWorkspaceRequest) error { var updateResponse UpdateResponse path := fmt.Sprintf("/api/2.0/accounts/%v/workspaces/%v", a.client.ConfiguredAccountID(), request.WorkspaceId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &updateResponse) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &updateResponse) return err } diff --git a/serving/go.mod b/serving/go.mod index 30581ea8e..749e6e79a 100644 --- a/serving/go.mod +++ b/serving/go.mod @@ -7,6 +7,7 @@ replace github.com/databricks/databricks-sdk-go/databricks => ../databricks require ( github.com/databricks/databricks-sdk-go/databricks v0.0.0-00010101000000-000000000000 github.com/stretchr/testify v1.10.0 + golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 golang.org/x/oauth2 v0.25.0 ) @@ -30,7 +31,6 @@ require ( go.opentelemetry.io/otel/metric v1.24.0 // indirect go.opentelemetry.io/otel/trace v1.24.0 // indirect golang.org/x/crypto v0.31.0 // indirect - golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.33.0 // indirect golang.org/x/sys v0.28.0 // indirect diff --git a/serving/v2/api.go b/serving/v2/api.go index 4ac2d3068..774a1d451 100755 --- a/serving/v2/api.go +++ b/serving/v2/api.go @@ -8,7 +8,6 @@ import ( "github.com/databricks/databricks-sdk-go/databricks/client" "github.com/databricks/databricks-sdk-go/databricks/listing" - "github.com/databricks/databricks-sdk-go/databricks/useragent" ) type ServingEndpointsInterface interface { @@ -248,36 +247,6 @@ func (a *ServingEndpointsAPI) GetPermissionsByServingEndpointId(ctx context.Cont }) } -// Get all serving endpoints. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ServingEndpointsAPI) List(ctx context.Context) listing.Iterator[ServingEndpoint] { - request := struct{}{} - - getNextPage := func(ctx context.Context, req struct{}) (*ListEndpointsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.servingEndpointsImpl.List(ctx) - } - getItems := func(resp *ListEndpointsResponse) []ServingEndpoint { - return resp.Endpoints - } - - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - nil) - return iterator -} - -// Get all serving endpoints. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ServingEndpointsAPI) ListAll(ctx context.Context) ([]ServingEndpoint, error) { - iterator := a.List(ctx) - return listing.ToSlice[ServingEndpoint](ctx, iterator) -} - // Get the latest logs for a served model. // // Retrieves the service logs associated with the provided served model. diff --git a/serving/v2/impl.go b/serving/v2/impl.go index ba2c030ce..a046dec78 100755 --- a/serving/v2/impl.go +++ b/serving/v2/impl.go @@ -8,6 +8,8 @@ import ( "net/http" "github.com/databricks/databricks-sdk-go/databricks/client" + "github.com/databricks/databricks-sdk-go/databricks/listing" + "github.com/databricks/databricks-sdk-go/databricks/useragent" ) // unexported type that holds implementations of just ServingEndpoints API methods @@ -18,171 +20,214 @@ type servingEndpointsImpl struct { func (a *servingEndpointsImpl) BuildLogs(ctx context.Context, request BuildLogsRequest) (*BuildLogsResponse, error) { var buildLogsResponse BuildLogsResponse path := fmt.Sprintf("/api/2.0/serving-endpoints/%v/served-models/%v/build-logs", request.Name, request.ServedModelName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &buildLogsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &buildLogsResponse) return &buildLogsResponse, err } func (a *servingEndpointsImpl) Create(ctx context.Context, request CreateServingEndpoint) (*ServingEndpointDetailed, error) { var servingEndpointDetailed ServingEndpointDetailed path := "/api/2.0/serving-endpoints" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &servingEndpointDetailed) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &servingEndpointDetailed) return &servingEndpointDetailed, err } func (a *servingEndpointsImpl) Delete(ctx context.Context, request DeleteServingEndpointRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.0/serving-endpoints/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *servingEndpointsImpl) ExportMetrics(ctx context.Context, request ExportMetricsRequest) (*ExportMetricsResponse, error) { var exportMetricsResponse ExportMetricsResponse path := fmt.Sprintf("/api/2.0/serving-endpoints/%v/metrics", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "text/plain" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &exportMetricsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &exportMetricsResponse) return &exportMetricsResponse, err } func (a *servingEndpointsImpl) Get(ctx context.Context, request GetServingEndpointRequest) (*ServingEndpointDetailed, error) { var servingEndpointDetailed ServingEndpointDetailed path := fmt.Sprintf("/api/2.0/serving-endpoints/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &servingEndpointDetailed) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &servingEndpointDetailed) return &servingEndpointDetailed, err } func (a *servingEndpointsImpl) GetOpenApi(ctx context.Context, request GetOpenApiRequest) (*GetOpenApiResponse, error) { var getOpenApiResponse GetOpenApiResponse path := fmt.Sprintf("/api/2.0/serving-endpoints/%v/openapi", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "text/plain" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getOpenApiResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getOpenApiResponse) return &getOpenApiResponse, err } func (a *servingEndpointsImpl) GetPermissionLevels(ctx context.Context, request GetServingEndpointPermissionLevelsRequest) (*GetServingEndpointPermissionLevelsResponse, error) { var getServingEndpointPermissionLevelsResponse GetServingEndpointPermissionLevelsResponse path := fmt.Sprintf("/api/2.0/permissions/serving-endpoints/%v/permissionLevels", request.ServingEndpointId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getServingEndpointPermissionLevelsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getServingEndpointPermissionLevelsResponse) return &getServingEndpointPermissionLevelsResponse, err } func (a *servingEndpointsImpl) GetPermissions(ctx context.Context, request GetServingEndpointPermissionsRequest) (*ServingEndpointPermissions, error) { var servingEndpointPermissions ServingEndpointPermissions path := fmt.Sprintf("/api/2.0/permissions/serving-endpoints/%v", request.ServingEndpointId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &servingEndpointPermissions) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &servingEndpointPermissions) return &servingEndpointPermissions, err } func (a *servingEndpointsImpl) HttpRequest(ctx context.Context, request ExternalFunctionRequest) (*HttpRequestResponse, error) { var httpRequestResponse HttpRequestResponse path := "/api/2.0/external-function" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "text/plain" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &httpRequestResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &httpRequestResponse) return &httpRequestResponse, err } -func (a *servingEndpointsImpl) List(ctx context.Context) (*ListEndpointsResponse, error) { +// Get all serving endpoints. +func (a *servingEndpointsImpl) List(ctx context.Context) listing.Iterator[ServingEndpoint] { + request := struct{}{} + + getNextPage := func(ctx context.Context, req struct{}) (*ListEndpointsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx) + } + getItems := func(resp *ListEndpointsResponse) []ServingEndpoint { + return resp.Endpoints + } + + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + nil) + return iterator +} + +// Get all serving endpoints. +func (a *servingEndpointsImpl) ListAll(ctx context.Context) ([]ServingEndpoint, error) { + iterator := a.List(ctx) + return listing.ToSlice[ServingEndpoint](ctx, iterator) +} +func (a *servingEndpointsImpl) internalList(ctx context.Context) (*ListEndpointsResponse, error) { var listEndpointsResponse ListEndpointsResponse path := "/api/2.0/serving-endpoints" + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &listEndpointsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &listEndpointsResponse) return &listEndpointsResponse, err } func (a *servingEndpointsImpl) Logs(ctx context.Context, request LogsRequest) (*ServerLogsResponse, error) { var serverLogsResponse ServerLogsResponse path := fmt.Sprintf("/api/2.0/serving-endpoints/%v/served-models/%v/logs", request.Name, request.ServedModelName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &serverLogsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &serverLogsResponse) return &serverLogsResponse, err } func (a *servingEndpointsImpl) Patch(ctx context.Context, request PatchServingEndpointTags) (*EndpointTags, error) { var endpointTags EndpointTags path := fmt.Sprintf("/api/2.0/serving-endpoints/%v/tags", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &endpointTags) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &endpointTags) return &endpointTags, err } func (a *servingEndpointsImpl) Put(ctx context.Context, request PutRequest) (*PutResponse, error) { var putResponse PutResponse path := fmt.Sprintf("/api/2.0/serving-endpoints/%v/rate-limits", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &putResponse) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &putResponse) return &putResponse, err } func (a *servingEndpointsImpl) PutAiGateway(ctx context.Context, request PutAiGatewayRequest) (*PutAiGatewayResponse, error) { var putAiGatewayResponse PutAiGatewayResponse path := fmt.Sprintf("/api/2.0/serving-endpoints/%v/ai-gateway", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &putAiGatewayResponse) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &putAiGatewayResponse) return &putAiGatewayResponse, err } func (a *servingEndpointsImpl) Query(ctx context.Context, request QueryEndpointInput) (*QueryEndpointResponse, error) { var queryEndpointResponse QueryEndpointResponse path := fmt.Sprintf("/serving-endpoints/%v/invocations", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &queryEndpointResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &queryEndpointResponse) return &queryEndpointResponse, err } func (a *servingEndpointsImpl) SetPermissions(ctx context.Context, request ServingEndpointPermissionsRequest) (*ServingEndpointPermissions, error) { var servingEndpointPermissions ServingEndpointPermissions path := fmt.Sprintf("/api/2.0/permissions/serving-endpoints/%v", request.ServingEndpointId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &servingEndpointPermissions) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &servingEndpointPermissions) return &servingEndpointPermissions, err } func (a *servingEndpointsImpl) UpdateConfig(ctx context.Context, request EndpointCoreConfigInput) (*ServingEndpointDetailed, error) { var servingEndpointDetailed ServingEndpointDetailed path := fmt.Sprintf("/api/2.0/serving-endpoints/%v/config", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &servingEndpointDetailed) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &servingEndpointDetailed) return &servingEndpointDetailed, err } func (a *servingEndpointsImpl) UpdatePermissions(ctx context.Context, request ServingEndpointPermissionsRequest) (*ServingEndpointPermissions, error) { var servingEndpointPermissions ServingEndpointPermissions path := fmt.Sprintf("/api/2.0/permissions/serving-endpoints/%v", request.ServingEndpointId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &servingEndpointPermissions) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &servingEndpointPermissions) return &servingEndpointPermissions, err } @@ -194,9 +239,10 @@ type servingEndpointsDataPlaneImpl struct { func (a *servingEndpointsDataPlaneImpl) Query(ctx context.Context, request QueryEndpointInput) (*QueryEndpointResponse, error) { var queryEndpointResponse QueryEndpointResponse path := fmt.Sprintf("/serving-endpoints/%v/invocations", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &queryEndpointResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &queryEndpointResponse) return &queryEndpointResponse, err } diff --git a/serving/v2/model.go b/serving/v2/model.go index 256439c68..4dcb80c75 100755 --- a/serving/v2/model.go +++ b/serving/v2/model.go @@ -868,8 +868,8 @@ type ExternalModel struct { PalmConfig *PaLmConfig `json:"palm_config,omitempty"` // The name of the provider for the external model. Currently, the supported // providers are 'ai21labs', 'anthropic', 'amazon-bedrock', 'cohere', - // 'databricks-model-serving', 'google-cloud-vertex-ai', 'openai', and - // 'palm'. + // 'databricks-model-serving', 'google-cloud-vertex-ai', 'openai', 'palm', + // and 'custom'. Provider ExternalModelProvider `json:"provider"` // The task type of the external model. Task string `json:"task"` diff --git a/settings/go.mod b/settings/go.mod index acc5889d6..4a921b156 100644 --- a/settings/go.mod +++ b/settings/go.mod @@ -6,6 +6,7 @@ replace github.com/databricks/databricks-sdk-go/databricks => ../databricks require ( github.com/databricks/databricks-sdk-go/databricks v0.0.0-00010101000000-000000000000 + golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 golang.org/x/oauth2 v0.25.0 ) @@ -27,7 +28,6 @@ require ( go.opentelemetry.io/otel/metric v1.24.0 // indirect go.opentelemetry.io/otel/trace v1.24.0 // indirect golang.org/x/crypto v0.31.0 // indirect - golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.33.0 // indirect golang.org/x/sys v0.28.0 // indirect diff --git a/settings/v2/api.go b/settings/v2/api.go index dea2d557e..35737d0b2 100755 --- a/settings/v2/api.go +++ b/settings/v2/api.go @@ -170,40 +170,6 @@ func (a *AccountIpAccessListsAPI) GetByIpAccessListId(ctx context.Context, ipAcc }) } -// Get access lists. -// -// Gets all IP access lists for the specified account. -// -// This method is generated by Databricks SDK Code Generator. -func (a *AccountIpAccessListsAPI) List(ctx context.Context) listing.Iterator[IpAccessListInfo] { - request := struct{}{} - - getNextPage := func(ctx context.Context, req struct{}) (*GetIpAccessListsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.accountIpAccessListsImpl.List(ctx) - } - getItems := func(resp *GetIpAccessListsResponse) []IpAccessListInfo { - return resp.IpAccessLists - } - - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - nil) - return iterator -} - -// Get access lists. -// -// Gets all IP access lists for the specified account. -// -// This method is generated by Databricks SDK Code Generator. -func (a *AccountIpAccessListsAPI) ListAll(ctx context.Context) ([]IpAccessListInfo, error) { - iterator := a.List(ctx) - return listing.ToSlice[IpAccessListInfo](ctx, iterator) -} - // IpAccessListInfoLabelToListIdMap calls [AccountIpAccessListsAPI.ListAll] and creates a map of results with [IpAccessListInfo].Label as key and [IpAccessListInfo].ListId as value. // // Returns an error if there's more than one [IpAccessListInfo] with the same .Label. @@ -888,40 +854,6 @@ func (a *IpAccessListsAPI) GetByIpAccessListId(ctx context.Context, ipAccessList }) } -// Get access lists. -// -// Gets all IP access lists for the specified workspace. -// -// This method is generated by Databricks SDK Code Generator. -func (a *IpAccessListsAPI) List(ctx context.Context) listing.Iterator[IpAccessListInfo] { - request := struct{}{} - - getNextPage := func(ctx context.Context, req struct{}) (*ListIpAccessListResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.ipAccessListsImpl.List(ctx) - } - getItems := func(resp *ListIpAccessListResponse) []IpAccessListInfo { - return resp.IpAccessLists - } - - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - nil) - return iterator -} - -// Get access lists. -// -// Gets all IP access lists for the specified workspace. -// -// This method is generated by Databricks SDK Code Generator. -func (a *IpAccessListsAPI) ListAll(ctx context.Context) ([]IpAccessListInfo, error) { - iterator := a.List(ctx) - return listing.ToSlice[IpAccessListInfo](ctx, iterator) -} - // IpAccessListInfoLabelToListIdMap calls [IpAccessListsAPI.ListAll] and creates a map of results with [IpAccessListInfo].Label as key and [IpAccessListInfo].ListId as value. // // Returns an error if there's more than one [IpAccessListInfo] with the same .Label. @@ -1135,89 +1067,11 @@ func (a *NetworkConnectivityAPI) GetPrivateEndpointRuleByNetworkConnectivityConf }) } -// List network connectivity configurations. -// -// Gets an array of network connectivity configurations. -// -// This method is generated by Databricks SDK Code Generator. -func (a *NetworkConnectivityAPI) ListNetworkConnectivityConfigurations(ctx context.Context, request ListNetworkConnectivityConfigurationsRequest) listing.Iterator[NetworkConnectivityConfiguration] { - - getNextPage := func(ctx context.Context, req ListNetworkConnectivityConfigurationsRequest) (*ListNetworkConnectivityConfigurationsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.networkConnectivityImpl.ListNetworkConnectivityConfigurations(ctx, req) - } - getItems := func(resp *ListNetworkConnectivityConfigurationsResponse) []NetworkConnectivityConfiguration { - return resp.Items - } - getNextReq := func(resp *ListNetworkConnectivityConfigurationsResponse) *ListNetworkConnectivityConfigurationsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List network connectivity configurations. -// -// Gets an array of network connectivity configurations. -// -// This method is generated by Databricks SDK Code Generator. -func (a *NetworkConnectivityAPI) ListNetworkConnectivityConfigurationsAll(ctx context.Context, request ListNetworkConnectivityConfigurationsRequest) ([]NetworkConnectivityConfiguration, error) { - iterator := a.ListNetworkConnectivityConfigurations(ctx, request) - return listing.ToSlice[NetworkConnectivityConfiguration](ctx, iterator) -} - -// List private endpoint rules. -// -// Gets an array of private endpoint rules. -// -// This method is generated by Databricks SDK Code Generator. -func (a *NetworkConnectivityAPI) ListPrivateEndpointRules(ctx context.Context, request ListPrivateEndpointRulesRequest) listing.Iterator[NccAzurePrivateEndpointRule] { - - getNextPage := func(ctx context.Context, req ListPrivateEndpointRulesRequest) (*ListNccAzurePrivateEndpointRulesResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.networkConnectivityImpl.ListPrivateEndpointRules(ctx, req) - } - getItems := func(resp *ListNccAzurePrivateEndpointRulesResponse) []NccAzurePrivateEndpointRule { - return resp.Items - } - getNextReq := func(resp *ListNccAzurePrivateEndpointRulesResponse) *ListPrivateEndpointRulesRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List private endpoint rules. -// -// Gets an array of private endpoint rules. -// -// This method is generated by Databricks SDK Code Generator. -func (a *NetworkConnectivityAPI) ListPrivateEndpointRulesAll(ctx context.Context, request ListPrivateEndpointRulesRequest) ([]NccAzurePrivateEndpointRule, error) { - iterator := a.ListPrivateEndpointRules(ctx, request) - return listing.ToSlice[NccAzurePrivateEndpointRule](ctx, iterator) -} - // List private endpoint rules. // // Gets an array of private endpoint rules. func (a *NetworkConnectivityAPI) ListPrivateEndpointRulesByNetworkConnectivityConfigId(ctx context.Context, networkConnectivityConfigId string) (*ListNccAzurePrivateEndpointRulesResponse, error) { - return a.networkConnectivityImpl.ListPrivateEndpointRules(ctx, ListPrivateEndpointRulesRequest{ + return a.networkConnectivityImpl.internalListPrivateEndpointRules(ctx, ListPrivateEndpointRulesRequest{ NetworkConnectivityConfigId: networkConnectivityConfigId, }) } @@ -1305,45 +1159,6 @@ func (a *NotificationDestinationsAPI) GetById(ctx context.Context, id string) (* }) } -// List notification destinations. -// -// Lists notification destinations. -// -// This method is generated by Databricks SDK Code Generator. -func (a *NotificationDestinationsAPI) List(ctx context.Context, request ListNotificationDestinationsRequest) listing.Iterator[ListNotificationDestinationsResult] { - - getNextPage := func(ctx context.Context, req ListNotificationDestinationsRequest) (*ListNotificationDestinationsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.notificationDestinationsImpl.List(ctx, req) - } - getItems := func(resp *ListNotificationDestinationsResponse) []ListNotificationDestinationsResult { - return resp.Results - } - getNextReq := func(resp *ListNotificationDestinationsResponse) *ListNotificationDestinationsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List notification destinations. -// -// Lists notification destinations. -// -// This method is generated by Databricks SDK Code Generator. -func (a *NotificationDestinationsAPI) ListAll(ctx context.Context, request ListNotificationDestinationsRequest) ([]ListNotificationDestinationsResult, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[ListNotificationDestinationsResult](ctx, iterator) -} - type PersonalComputeInterface interface { // Delete Personal Compute setting. @@ -1568,39 +1383,6 @@ func (a *TokenManagementAPI) GetByTokenId(ctx context.Context, tokenId string) ( }) } -// List all tokens. -// -// Lists all tokens associated with the specified workspace or user. -// -// This method is generated by Databricks SDK Code Generator. -func (a *TokenManagementAPI) List(ctx context.Context, request ListTokenManagementRequest) listing.Iterator[TokenInfo] { - - getNextPage := func(ctx context.Context, req ListTokenManagementRequest) (*ListTokensResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.tokenManagementImpl.List(ctx, req) - } - getItems := func(resp *ListTokensResponse) []TokenInfo { - return resp.TokenInfos - } - - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - nil) - return iterator -} - -// List all tokens. -// -// Lists all tokens associated with the specified workspace or user. -// -// This method is generated by Databricks SDK Code Generator. -func (a *TokenManagementAPI) ListAll(ctx context.Context, request ListTokenManagementRequest) ([]TokenInfo, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[TokenInfo](ctx, iterator) -} - // TokenInfoCommentToTokenIdMap calls [TokenManagementAPI.ListAll] and creates a map of results with [TokenInfo].Comment as key and [TokenInfo].TokenId as value. // // Returns an error if there's more than one [TokenInfo] with the same .Comment. @@ -1739,40 +1521,6 @@ func (a *TokensAPI) DeleteByTokenId(ctx context.Context, tokenId string) error { }) } -// List tokens. -// -// Lists all the valid tokens for a user-workspace pair. -// -// This method is generated by Databricks SDK Code Generator. -func (a *TokensAPI) List(ctx context.Context) listing.Iterator[PublicTokenInfo] { - request := struct{}{} - - getNextPage := func(ctx context.Context, req struct{}) (*ListPublicTokensResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.tokensImpl.List(ctx) - } - getItems := func(resp *ListPublicTokensResponse) []PublicTokenInfo { - return resp.TokenInfos - } - - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - nil) - return iterator -} - -// List tokens. -// -// Lists all the valid tokens for a user-workspace pair. -// -// This method is generated by Databricks SDK Code Generator. -func (a *TokensAPI) ListAll(ctx context.Context) ([]PublicTokenInfo, error) { - iterator := a.List(ctx) - return listing.ToSlice[PublicTokenInfo](ctx, iterator) -} - // PublicTokenInfoCommentToTokenIdMap calls [TokensAPI.ListAll] and creates a map of results with [PublicTokenInfo].Comment as key and [PublicTokenInfo].TokenId as value. // // Returns an error if there's more than one [PublicTokenInfo] with the same .Comment. diff --git a/settings/v2/impl.go b/settings/v2/impl.go index 14aabf9fb..b53236ebf 100755 --- a/settings/v2/impl.go +++ b/settings/v2/impl.go @@ -8,6 +8,8 @@ import ( "net/http" "github.com/databricks/databricks-sdk-go/databricks/client" + "github.com/databricks/databricks-sdk-go/databricks/listing" + "github.com/databricks/databricks-sdk-go/databricks/useragent" ) // unexported type that holds implementations of just AccountIpAccessLists API methods @@ -18,57 +20,92 @@ type accountIpAccessListsImpl struct { func (a *accountIpAccessListsImpl) Create(ctx context.Context, request CreateIpAccessList) (*CreateIpAccessListResponse, error) { var createIpAccessListResponse CreateIpAccessListResponse path := fmt.Sprintf("/api/2.0/accounts/%v/ip-access-lists", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createIpAccessListResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createIpAccessListResponse) return &createIpAccessListResponse, err } func (a *accountIpAccessListsImpl) Delete(ctx context.Context, request DeleteAccountIpAccessListRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.0/accounts/%v/ip-access-lists/%v", a.client.ConfiguredAccountID(), request.IpAccessListId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *accountIpAccessListsImpl) Get(ctx context.Context, request GetAccountIpAccessListRequest) (*GetIpAccessListResponse, error) { var getIpAccessListResponse GetIpAccessListResponse path := fmt.Sprintf("/api/2.0/accounts/%v/ip-access-lists/%v", a.client.ConfiguredAccountID(), request.IpAccessListId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getIpAccessListResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getIpAccessListResponse) return &getIpAccessListResponse, err } -func (a *accountIpAccessListsImpl) List(ctx context.Context) (*GetIpAccessListsResponse, error) { +// Get access lists. +// +// Gets all IP access lists for the specified account. +func (a *accountIpAccessListsImpl) List(ctx context.Context) listing.Iterator[IpAccessListInfo] { + request := struct{}{} + + getNextPage := func(ctx context.Context, req struct{}) (*GetIpAccessListsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx) + } + getItems := func(resp *GetIpAccessListsResponse) []IpAccessListInfo { + return resp.IpAccessLists + } + + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + nil) + return iterator +} + +// Get access lists. +// +// Gets all IP access lists for the specified account. +func (a *accountIpAccessListsImpl) ListAll(ctx context.Context) ([]IpAccessListInfo, error) { + iterator := a.List(ctx) + return listing.ToSlice[IpAccessListInfo](ctx, iterator) +} +func (a *accountIpAccessListsImpl) internalList(ctx context.Context) (*GetIpAccessListsResponse, error) { var getIpAccessListsResponse GetIpAccessListsResponse path := fmt.Sprintf("/api/2.0/accounts/%v/ip-access-lists", a.client.ConfiguredAccountID()) + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &getIpAccessListsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &getIpAccessListsResponse) return &getIpAccessListsResponse, err } func (a *accountIpAccessListsImpl) Replace(ctx context.Context, request ReplaceIpAccessList) error { var replaceResponse ReplaceResponse path := fmt.Sprintf("/api/2.0/accounts/%v/ip-access-lists/%v", a.client.ConfiguredAccountID(), request.IpAccessListId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &replaceResponse) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &replaceResponse) return err } func (a *accountIpAccessListsImpl) Update(ctx context.Context, request UpdateIpAccessList) error { var updateResponse UpdateResponse path := fmt.Sprintf("/api/2.0/accounts/%v/ip-access-lists/%v", a.client.ConfiguredAccountID(), request.IpAccessListId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &updateResponse) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &updateResponse) return err } @@ -85,28 +122,31 @@ type aibiDashboardEmbeddingAccessPolicyImpl struct { func (a *aibiDashboardEmbeddingAccessPolicyImpl) Delete(ctx context.Context, request DeleteAibiDashboardEmbeddingAccessPolicySettingRequest) (*DeleteAibiDashboardEmbeddingAccessPolicySettingResponse, error) { var deleteAibiDashboardEmbeddingAccessPolicySettingResponse DeleteAibiDashboardEmbeddingAccessPolicySettingResponse path := "/api/2.0/settings/types/aibi_dash_embed_ws_acc_policy/names/default" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteAibiDashboardEmbeddingAccessPolicySettingResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteAibiDashboardEmbeddingAccessPolicySettingResponse) return &deleteAibiDashboardEmbeddingAccessPolicySettingResponse, err } func (a *aibiDashboardEmbeddingAccessPolicyImpl) Get(ctx context.Context, request GetAibiDashboardEmbeddingAccessPolicySettingRequest) (*AibiDashboardEmbeddingAccessPolicySetting, error) { var aibiDashboardEmbeddingAccessPolicySetting AibiDashboardEmbeddingAccessPolicySetting path := "/api/2.0/settings/types/aibi_dash_embed_ws_acc_policy/names/default" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &aibiDashboardEmbeddingAccessPolicySetting) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &aibiDashboardEmbeddingAccessPolicySetting) return &aibiDashboardEmbeddingAccessPolicySetting, err } func (a *aibiDashboardEmbeddingAccessPolicyImpl) Update(ctx context.Context, request UpdateAibiDashboardEmbeddingAccessPolicySettingRequest) (*AibiDashboardEmbeddingAccessPolicySetting, error) { var aibiDashboardEmbeddingAccessPolicySetting AibiDashboardEmbeddingAccessPolicySetting path := "/api/2.0/settings/types/aibi_dash_embed_ws_acc_policy/names/default" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &aibiDashboardEmbeddingAccessPolicySetting) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &aibiDashboardEmbeddingAccessPolicySetting) return &aibiDashboardEmbeddingAccessPolicySetting, err } @@ -118,28 +158,31 @@ type aibiDashboardEmbeddingApprovedDomainsImpl struct { func (a *aibiDashboardEmbeddingApprovedDomainsImpl) Delete(ctx context.Context, request DeleteAibiDashboardEmbeddingApprovedDomainsSettingRequest) (*DeleteAibiDashboardEmbeddingApprovedDomainsSettingResponse, error) { var deleteAibiDashboardEmbeddingApprovedDomainsSettingResponse DeleteAibiDashboardEmbeddingApprovedDomainsSettingResponse path := "/api/2.0/settings/types/aibi_dash_embed_ws_apprvd_domains/names/default" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteAibiDashboardEmbeddingApprovedDomainsSettingResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteAibiDashboardEmbeddingApprovedDomainsSettingResponse) return &deleteAibiDashboardEmbeddingApprovedDomainsSettingResponse, err } func (a *aibiDashboardEmbeddingApprovedDomainsImpl) Get(ctx context.Context, request GetAibiDashboardEmbeddingApprovedDomainsSettingRequest) (*AibiDashboardEmbeddingApprovedDomainsSetting, error) { var aibiDashboardEmbeddingApprovedDomainsSetting AibiDashboardEmbeddingApprovedDomainsSetting path := "/api/2.0/settings/types/aibi_dash_embed_ws_apprvd_domains/names/default" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &aibiDashboardEmbeddingApprovedDomainsSetting) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &aibiDashboardEmbeddingApprovedDomainsSetting) return &aibiDashboardEmbeddingApprovedDomainsSetting, err } func (a *aibiDashboardEmbeddingApprovedDomainsImpl) Update(ctx context.Context, request UpdateAibiDashboardEmbeddingApprovedDomainsSettingRequest) (*AibiDashboardEmbeddingApprovedDomainsSetting, error) { var aibiDashboardEmbeddingApprovedDomainsSetting AibiDashboardEmbeddingApprovedDomainsSetting path := "/api/2.0/settings/types/aibi_dash_embed_ws_apprvd_domains/names/default" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &aibiDashboardEmbeddingApprovedDomainsSetting) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &aibiDashboardEmbeddingApprovedDomainsSetting) return &aibiDashboardEmbeddingApprovedDomainsSetting, err } @@ -151,19 +194,21 @@ type automaticClusterUpdateImpl struct { func (a *automaticClusterUpdateImpl) Get(ctx context.Context, request GetAutomaticClusterUpdateSettingRequest) (*AutomaticClusterUpdateSetting, error) { var automaticClusterUpdateSetting AutomaticClusterUpdateSetting path := "/api/2.0/settings/types/automatic_cluster_update/names/default" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &automaticClusterUpdateSetting) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &automaticClusterUpdateSetting) return &automaticClusterUpdateSetting, err } func (a *automaticClusterUpdateImpl) Update(ctx context.Context, request UpdateAutomaticClusterUpdateSettingRequest) (*AutomaticClusterUpdateSetting, error) { var automaticClusterUpdateSetting AutomaticClusterUpdateSetting path := "/api/2.0/settings/types/automatic_cluster_update/names/default" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &automaticClusterUpdateSetting) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &automaticClusterUpdateSetting) return &automaticClusterUpdateSetting, err } @@ -175,19 +220,21 @@ type complianceSecurityProfileImpl struct { func (a *complianceSecurityProfileImpl) Get(ctx context.Context, request GetComplianceSecurityProfileSettingRequest) (*ComplianceSecurityProfileSetting, error) { var complianceSecurityProfileSetting ComplianceSecurityProfileSetting path := "/api/2.0/settings/types/shield_csp_enablement_ws_db/names/default" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &complianceSecurityProfileSetting) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &complianceSecurityProfileSetting) return &complianceSecurityProfileSetting, err } func (a *complianceSecurityProfileImpl) Update(ctx context.Context, request UpdateComplianceSecurityProfileSettingRequest) (*ComplianceSecurityProfileSetting, error) { var complianceSecurityProfileSetting ComplianceSecurityProfileSetting path := "/api/2.0/settings/types/shield_csp_enablement_ws_db/names/default" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &complianceSecurityProfileSetting) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &complianceSecurityProfileSetting) return &complianceSecurityProfileSetting, err } @@ -199,10 +246,11 @@ type credentialsManagerImpl struct { func (a *credentialsManagerImpl) ExchangeToken(ctx context.Context, request ExchangeTokenRequest) (*ExchangeTokenResponse, error) { var exchangeTokenResponse ExchangeTokenResponse path := "/api/2.0/credentials-manager/exchange-tokens/token" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &exchangeTokenResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &exchangeTokenResponse) return &exchangeTokenResponse, err } @@ -214,19 +262,21 @@ type cspEnablementAccountImpl struct { func (a *cspEnablementAccountImpl) Get(ctx context.Context, request GetCspEnablementAccountSettingRequest) (*CspEnablementAccountSetting, error) { var cspEnablementAccountSetting CspEnablementAccountSetting path := fmt.Sprintf("/api/2.0/accounts/%v/settings/types/shield_csp_enablement_ac/names/default", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &cspEnablementAccountSetting) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &cspEnablementAccountSetting) return &cspEnablementAccountSetting, err } func (a *cspEnablementAccountImpl) Update(ctx context.Context, request UpdateCspEnablementAccountSettingRequest) (*CspEnablementAccountSetting, error) { var cspEnablementAccountSetting CspEnablementAccountSetting path := fmt.Sprintf("/api/2.0/accounts/%v/settings/types/shield_csp_enablement_ac/names/default", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &cspEnablementAccountSetting) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &cspEnablementAccountSetting) return &cspEnablementAccountSetting, err } @@ -238,28 +288,31 @@ type defaultNamespaceImpl struct { func (a *defaultNamespaceImpl) Delete(ctx context.Context, request DeleteDefaultNamespaceSettingRequest) (*DeleteDefaultNamespaceSettingResponse, error) { var deleteDefaultNamespaceSettingResponse DeleteDefaultNamespaceSettingResponse path := "/api/2.0/settings/types/default_namespace_ws/names/default" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteDefaultNamespaceSettingResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteDefaultNamespaceSettingResponse) return &deleteDefaultNamespaceSettingResponse, err } func (a *defaultNamespaceImpl) Get(ctx context.Context, request GetDefaultNamespaceSettingRequest) (*DefaultNamespaceSetting, error) { var defaultNamespaceSetting DefaultNamespaceSetting path := "/api/2.0/settings/types/default_namespace_ws/names/default" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &defaultNamespaceSetting) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &defaultNamespaceSetting) return &defaultNamespaceSetting, err } func (a *defaultNamespaceImpl) Update(ctx context.Context, request UpdateDefaultNamespaceSettingRequest) (*DefaultNamespaceSetting, error) { var defaultNamespaceSetting DefaultNamespaceSetting path := "/api/2.0/settings/types/default_namespace_ws/names/default" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &defaultNamespaceSetting) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &defaultNamespaceSetting) return &defaultNamespaceSetting, err } @@ -271,28 +324,31 @@ type disableLegacyAccessImpl struct { func (a *disableLegacyAccessImpl) Delete(ctx context.Context, request DeleteDisableLegacyAccessRequest) (*DeleteDisableLegacyAccessResponse, error) { var deleteDisableLegacyAccessResponse DeleteDisableLegacyAccessResponse path := "/api/2.0/settings/types/disable_legacy_access/names/default" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteDisableLegacyAccessResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteDisableLegacyAccessResponse) return &deleteDisableLegacyAccessResponse, err } func (a *disableLegacyAccessImpl) Get(ctx context.Context, request GetDisableLegacyAccessRequest) (*DisableLegacyAccess, error) { var disableLegacyAccess DisableLegacyAccess path := "/api/2.0/settings/types/disable_legacy_access/names/default" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &disableLegacyAccess) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &disableLegacyAccess) return &disableLegacyAccess, err } func (a *disableLegacyAccessImpl) Update(ctx context.Context, request UpdateDisableLegacyAccessRequest) (*DisableLegacyAccess, error) { var disableLegacyAccess DisableLegacyAccess path := "/api/2.0/settings/types/disable_legacy_access/names/default" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &disableLegacyAccess) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &disableLegacyAccess) return &disableLegacyAccess, err } @@ -304,28 +360,31 @@ type disableLegacyDbfsImpl struct { func (a *disableLegacyDbfsImpl) Delete(ctx context.Context, request DeleteDisableLegacyDbfsRequest) (*DeleteDisableLegacyDbfsResponse, error) { var deleteDisableLegacyDbfsResponse DeleteDisableLegacyDbfsResponse path := "/api/2.0/settings/types/disable_legacy_dbfs/names/default" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteDisableLegacyDbfsResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteDisableLegacyDbfsResponse) return &deleteDisableLegacyDbfsResponse, err } func (a *disableLegacyDbfsImpl) Get(ctx context.Context, request GetDisableLegacyDbfsRequest) (*DisableLegacyDbfs, error) { var disableLegacyDbfs DisableLegacyDbfs path := "/api/2.0/settings/types/disable_legacy_dbfs/names/default" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &disableLegacyDbfs) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &disableLegacyDbfs) return &disableLegacyDbfs, err } func (a *disableLegacyDbfsImpl) Update(ctx context.Context, request UpdateDisableLegacyDbfsRequest) (*DisableLegacyDbfs, error) { var disableLegacyDbfs DisableLegacyDbfs path := "/api/2.0/settings/types/disable_legacy_dbfs/names/default" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &disableLegacyDbfs) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &disableLegacyDbfs) return &disableLegacyDbfs, err } @@ -337,28 +396,31 @@ type disableLegacyFeaturesImpl struct { func (a *disableLegacyFeaturesImpl) Delete(ctx context.Context, request DeleteDisableLegacyFeaturesRequest) (*DeleteDisableLegacyFeaturesResponse, error) { var deleteDisableLegacyFeaturesResponse DeleteDisableLegacyFeaturesResponse path := fmt.Sprintf("/api/2.0/accounts/%v/settings/types/disable_legacy_features/names/default", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteDisableLegacyFeaturesResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteDisableLegacyFeaturesResponse) return &deleteDisableLegacyFeaturesResponse, err } func (a *disableLegacyFeaturesImpl) Get(ctx context.Context, request GetDisableLegacyFeaturesRequest) (*DisableLegacyFeatures, error) { var disableLegacyFeatures DisableLegacyFeatures path := fmt.Sprintf("/api/2.0/accounts/%v/settings/types/disable_legacy_features/names/default", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &disableLegacyFeatures) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &disableLegacyFeatures) return &disableLegacyFeatures, err } func (a *disableLegacyFeaturesImpl) Update(ctx context.Context, request UpdateDisableLegacyFeaturesRequest) (*DisableLegacyFeatures, error) { var disableLegacyFeatures DisableLegacyFeatures path := fmt.Sprintf("/api/2.0/accounts/%v/settings/types/disable_legacy_features/names/default", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &disableLegacyFeatures) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &disableLegacyFeatures) return &disableLegacyFeatures, err } @@ -370,28 +432,31 @@ type enableIpAccessListsImpl struct { func (a *enableIpAccessListsImpl) Delete(ctx context.Context, request DeleteAccountIpAccessEnableRequest) (*DeleteAccountIpAccessEnableResponse, error) { var deleteAccountIpAccessEnableResponse DeleteAccountIpAccessEnableResponse path := fmt.Sprintf("/api/2.0/accounts/%v/settings/types/acct_ip_acl_enable/names/default", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteAccountIpAccessEnableResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteAccountIpAccessEnableResponse) return &deleteAccountIpAccessEnableResponse, err } func (a *enableIpAccessListsImpl) Get(ctx context.Context, request GetAccountIpAccessEnableRequest) (*AccountIpAccessEnable, error) { var accountIpAccessEnable AccountIpAccessEnable path := fmt.Sprintf("/api/2.0/accounts/%v/settings/types/acct_ip_acl_enable/names/default", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &accountIpAccessEnable) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &accountIpAccessEnable) return &accountIpAccessEnable, err } func (a *enableIpAccessListsImpl) Update(ctx context.Context, request UpdateAccountIpAccessEnableRequest) (*AccountIpAccessEnable, error) { var accountIpAccessEnable AccountIpAccessEnable path := fmt.Sprintf("/api/2.0/accounts/%v/settings/types/acct_ip_acl_enable/names/default", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &accountIpAccessEnable) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &accountIpAccessEnable) return &accountIpAccessEnable, err } @@ -403,19 +468,21 @@ type enhancedSecurityMonitoringImpl struct { func (a *enhancedSecurityMonitoringImpl) Get(ctx context.Context, request GetEnhancedSecurityMonitoringSettingRequest) (*EnhancedSecurityMonitoringSetting, error) { var enhancedSecurityMonitoringSetting EnhancedSecurityMonitoringSetting path := "/api/2.0/settings/types/shield_esm_enablement_ws_db/names/default" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &enhancedSecurityMonitoringSetting) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &enhancedSecurityMonitoringSetting) return &enhancedSecurityMonitoringSetting, err } func (a *enhancedSecurityMonitoringImpl) Update(ctx context.Context, request UpdateEnhancedSecurityMonitoringSettingRequest) (*EnhancedSecurityMonitoringSetting, error) { var enhancedSecurityMonitoringSetting EnhancedSecurityMonitoringSetting path := "/api/2.0/settings/types/shield_esm_enablement_ws_db/names/default" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &enhancedSecurityMonitoringSetting) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &enhancedSecurityMonitoringSetting) return &enhancedSecurityMonitoringSetting, err } @@ -427,19 +494,21 @@ type esmEnablementAccountImpl struct { func (a *esmEnablementAccountImpl) Get(ctx context.Context, request GetEsmEnablementAccountSettingRequest) (*EsmEnablementAccountSetting, error) { var esmEnablementAccountSetting EsmEnablementAccountSetting path := fmt.Sprintf("/api/2.0/accounts/%v/settings/types/shield_esm_enablement_ac/names/default", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &esmEnablementAccountSetting) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &esmEnablementAccountSetting) return &esmEnablementAccountSetting, err } func (a *esmEnablementAccountImpl) Update(ctx context.Context, request UpdateEsmEnablementAccountSettingRequest) (*EsmEnablementAccountSetting, error) { var esmEnablementAccountSetting EsmEnablementAccountSetting path := fmt.Sprintf("/api/2.0/accounts/%v/settings/types/shield_esm_enablement_ac/names/default", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &esmEnablementAccountSetting) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &esmEnablementAccountSetting) return &esmEnablementAccountSetting, err } @@ -451,57 +520,92 @@ type ipAccessListsImpl struct { func (a *ipAccessListsImpl) Create(ctx context.Context, request CreateIpAccessList) (*CreateIpAccessListResponse, error) { var createIpAccessListResponse CreateIpAccessListResponse path := "/api/2.0/ip-access-lists" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createIpAccessListResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createIpAccessListResponse) return &createIpAccessListResponse, err } func (a *ipAccessListsImpl) Delete(ctx context.Context, request DeleteIpAccessListRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.0/ip-access-lists/%v", request.IpAccessListId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *ipAccessListsImpl) Get(ctx context.Context, request GetIpAccessListRequest) (*FetchIpAccessListResponse, error) { var fetchIpAccessListResponse FetchIpAccessListResponse path := fmt.Sprintf("/api/2.0/ip-access-lists/%v", request.IpAccessListId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &fetchIpAccessListResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &fetchIpAccessListResponse) return &fetchIpAccessListResponse, err } -func (a *ipAccessListsImpl) List(ctx context.Context) (*ListIpAccessListResponse, error) { +// Get access lists. +// +// Gets all IP access lists for the specified workspace. +func (a *ipAccessListsImpl) List(ctx context.Context) listing.Iterator[IpAccessListInfo] { + request := struct{}{} + + getNextPage := func(ctx context.Context, req struct{}) (*ListIpAccessListResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx) + } + getItems := func(resp *ListIpAccessListResponse) []IpAccessListInfo { + return resp.IpAccessLists + } + + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + nil) + return iterator +} + +// Get access lists. +// +// Gets all IP access lists for the specified workspace. +func (a *ipAccessListsImpl) ListAll(ctx context.Context) ([]IpAccessListInfo, error) { + iterator := a.List(ctx) + return listing.ToSlice[IpAccessListInfo](ctx, iterator) +} +func (a *ipAccessListsImpl) internalList(ctx context.Context) (*ListIpAccessListResponse, error) { var listIpAccessListResponse ListIpAccessListResponse path := "/api/2.0/ip-access-lists" + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &listIpAccessListResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &listIpAccessListResponse) return &listIpAccessListResponse, err } func (a *ipAccessListsImpl) Replace(ctx context.Context, request ReplaceIpAccessList) error { var replaceResponse ReplaceResponse path := fmt.Sprintf("/api/2.0/ip-access-lists/%v", request.IpAccessListId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &replaceResponse) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &replaceResponse) return err } func (a *ipAccessListsImpl) Update(ctx context.Context, request UpdateIpAccessList) error { var updateResponse UpdateResponse path := fmt.Sprintf("/api/2.0/ip-access-lists/%v", request.IpAccessListId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &updateResponse) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &updateResponse) return err } @@ -513,74 +617,150 @@ type networkConnectivityImpl struct { func (a *networkConnectivityImpl) CreateNetworkConnectivityConfiguration(ctx context.Context, request CreateNetworkConnectivityConfigRequest) (*NetworkConnectivityConfiguration, error) { var networkConnectivityConfiguration NetworkConnectivityConfiguration path := fmt.Sprintf("/api/2.0/accounts/%v/network-connectivity-configs", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &networkConnectivityConfiguration) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &networkConnectivityConfiguration) return &networkConnectivityConfiguration, err } func (a *networkConnectivityImpl) CreatePrivateEndpointRule(ctx context.Context, request CreatePrivateEndpointRuleRequest) (*NccAzurePrivateEndpointRule, error) { var nccAzurePrivateEndpointRule NccAzurePrivateEndpointRule path := fmt.Sprintf("/api/2.0/accounts/%v/network-connectivity-configs/%v/private-endpoint-rules", a.client.ConfiguredAccountID(), request.NetworkConnectivityConfigId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &nccAzurePrivateEndpointRule) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &nccAzurePrivateEndpointRule) return &nccAzurePrivateEndpointRule, err } func (a *networkConnectivityImpl) DeleteNetworkConnectivityConfiguration(ctx context.Context, request DeleteNetworkConnectivityConfigurationRequest) error { var deleteNetworkConnectivityConfigurationResponse DeleteNetworkConnectivityConfigurationResponse path := fmt.Sprintf("/api/2.0/accounts/%v/network-connectivity-configs/%v", a.client.ConfiguredAccountID(), request.NetworkConnectivityConfigId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteNetworkConnectivityConfigurationResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteNetworkConnectivityConfigurationResponse) return err } func (a *networkConnectivityImpl) DeletePrivateEndpointRule(ctx context.Context, request DeletePrivateEndpointRuleRequest) (*NccAzurePrivateEndpointRule, error) { var nccAzurePrivateEndpointRule NccAzurePrivateEndpointRule path := fmt.Sprintf("/api/2.0/accounts/%v/network-connectivity-configs/%v/private-endpoint-rules/%v", a.client.ConfiguredAccountID(), request.NetworkConnectivityConfigId, request.PrivateEndpointRuleId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &nccAzurePrivateEndpointRule) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &nccAzurePrivateEndpointRule) return &nccAzurePrivateEndpointRule, err } func (a *networkConnectivityImpl) GetNetworkConnectivityConfiguration(ctx context.Context, request GetNetworkConnectivityConfigurationRequest) (*NetworkConnectivityConfiguration, error) { var networkConnectivityConfiguration NetworkConnectivityConfiguration path := fmt.Sprintf("/api/2.0/accounts/%v/network-connectivity-configs/%v", a.client.ConfiguredAccountID(), request.NetworkConnectivityConfigId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &networkConnectivityConfiguration) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &networkConnectivityConfiguration) return &networkConnectivityConfiguration, err } func (a *networkConnectivityImpl) GetPrivateEndpointRule(ctx context.Context, request GetPrivateEndpointRuleRequest) (*NccAzurePrivateEndpointRule, error) { var nccAzurePrivateEndpointRule NccAzurePrivateEndpointRule path := fmt.Sprintf("/api/2.0/accounts/%v/network-connectivity-configs/%v/private-endpoint-rules/%v", a.client.ConfiguredAccountID(), request.NetworkConnectivityConfigId, request.PrivateEndpointRuleId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &nccAzurePrivateEndpointRule) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &nccAzurePrivateEndpointRule) return &nccAzurePrivateEndpointRule, err } -func (a *networkConnectivityImpl) ListNetworkConnectivityConfigurations(ctx context.Context, request ListNetworkConnectivityConfigurationsRequest) (*ListNetworkConnectivityConfigurationsResponse, error) { +// List network connectivity configurations. +// +// Gets an array of network connectivity configurations. +func (a *networkConnectivityImpl) ListNetworkConnectivityConfigurations(ctx context.Context, request ListNetworkConnectivityConfigurationsRequest) listing.Iterator[NetworkConnectivityConfiguration] { + + getNextPage := func(ctx context.Context, req ListNetworkConnectivityConfigurationsRequest) (*ListNetworkConnectivityConfigurationsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalListNetworkConnectivityConfigurations(ctx, req) + } + getItems := func(resp *ListNetworkConnectivityConfigurationsResponse) []NetworkConnectivityConfiguration { + return resp.Items + } + getNextReq := func(resp *ListNetworkConnectivityConfigurationsResponse) *ListNetworkConnectivityConfigurationsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List network connectivity configurations. +// +// Gets an array of network connectivity configurations. +func (a *networkConnectivityImpl) ListNetworkConnectivityConfigurationsAll(ctx context.Context, request ListNetworkConnectivityConfigurationsRequest) ([]NetworkConnectivityConfiguration, error) { + iterator := a.ListNetworkConnectivityConfigurations(ctx, request) + return listing.ToSlice[NetworkConnectivityConfiguration](ctx, iterator) +} +func (a *networkConnectivityImpl) internalListNetworkConnectivityConfigurations(ctx context.Context, request ListNetworkConnectivityConfigurationsRequest) (*ListNetworkConnectivityConfigurationsResponse, error) { var listNetworkConnectivityConfigurationsResponse ListNetworkConnectivityConfigurationsResponse path := fmt.Sprintf("/api/2.0/accounts/%v/network-connectivity-configs", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listNetworkConnectivityConfigurationsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listNetworkConnectivityConfigurationsResponse) return &listNetworkConnectivityConfigurationsResponse, err } -func (a *networkConnectivityImpl) ListPrivateEndpointRules(ctx context.Context, request ListPrivateEndpointRulesRequest) (*ListNccAzurePrivateEndpointRulesResponse, error) { +// List private endpoint rules. +// +// Gets an array of private endpoint rules. +func (a *networkConnectivityImpl) ListPrivateEndpointRules(ctx context.Context, request ListPrivateEndpointRulesRequest) listing.Iterator[NccAzurePrivateEndpointRule] { + + getNextPage := func(ctx context.Context, req ListPrivateEndpointRulesRequest) (*ListNccAzurePrivateEndpointRulesResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalListPrivateEndpointRules(ctx, req) + } + getItems := func(resp *ListNccAzurePrivateEndpointRulesResponse) []NccAzurePrivateEndpointRule { + return resp.Items + } + getNextReq := func(resp *ListNccAzurePrivateEndpointRulesResponse) *ListPrivateEndpointRulesRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List private endpoint rules. +// +// Gets an array of private endpoint rules. +func (a *networkConnectivityImpl) ListPrivateEndpointRulesAll(ctx context.Context, request ListPrivateEndpointRulesRequest) ([]NccAzurePrivateEndpointRule, error) { + iterator := a.ListPrivateEndpointRules(ctx, request) + return listing.ToSlice[NccAzurePrivateEndpointRule](ctx, iterator) +} +func (a *networkConnectivityImpl) internalListPrivateEndpointRules(ctx context.Context, request ListPrivateEndpointRulesRequest) (*ListNccAzurePrivateEndpointRulesResponse, error) { var listNccAzurePrivateEndpointRulesResponse ListNccAzurePrivateEndpointRulesResponse path := fmt.Sprintf("/api/2.0/accounts/%v/network-connectivity-configs/%v/private-endpoint-rules", a.client.ConfiguredAccountID(), request.NetworkConnectivityConfigId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listNccAzurePrivateEndpointRulesResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listNccAzurePrivateEndpointRulesResponse) return &listNccAzurePrivateEndpointRulesResponse, err } @@ -592,47 +772,86 @@ type notificationDestinationsImpl struct { func (a *notificationDestinationsImpl) Create(ctx context.Context, request CreateNotificationDestinationRequest) (*NotificationDestination, error) { var notificationDestination NotificationDestination path := "/api/2.0/notification-destinations" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, ¬ificationDestination) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, ¬ificationDestination) return ¬ificationDestination, err } func (a *notificationDestinationsImpl) Delete(ctx context.Context, request DeleteNotificationDestinationRequest) error { var empty Empty path := fmt.Sprintf("/api/2.0/notification-destinations/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &empty) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &empty) return err } func (a *notificationDestinationsImpl) Get(ctx context.Context, request GetNotificationDestinationRequest) (*NotificationDestination, error) { var notificationDestination NotificationDestination path := fmt.Sprintf("/api/2.0/notification-destinations/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, ¬ificationDestination) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, ¬ificationDestination) return ¬ificationDestination, err } -func (a *notificationDestinationsImpl) List(ctx context.Context, request ListNotificationDestinationsRequest) (*ListNotificationDestinationsResponse, error) { +// List notification destinations. +// +// Lists notification destinations. +func (a *notificationDestinationsImpl) List(ctx context.Context, request ListNotificationDestinationsRequest) listing.Iterator[ListNotificationDestinationsResult] { + + getNextPage := func(ctx context.Context, req ListNotificationDestinationsRequest) (*ListNotificationDestinationsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListNotificationDestinationsResponse) []ListNotificationDestinationsResult { + return resp.Results + } + getNextReq := func(resp *ListNotificationDestinationsResponse) *ListNotificationDestinationsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List notification destinations. +// +// Lists notification destinations. +func (a *notificationDestinationsImpl) ListAll(ctx context.Context, request ListNotificationDestinationsRequest) ([]ListNotificationDestinationsResult, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[ListNotificationDestinationsResult](ctx, iterator) +} +func (a *notificationDestinationsImpl) internalList(ctx context.Context, request ListNotificationDestinationsRequest) (*ListNotificationDestinationsResponse, error) { var listNotificationDestinationsResponse ListNotificationDestinationsResponse path := "/api/2.0/notification-destinations" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listNotificationDestinationsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listNotificationDestinationsResponse) return &listNotificationDestinationsResponse, err } func (a *notificationDestinationsImpl) Update(ctx context.Context, request UpdateNotificationDestinationRequest) (*NotificationDestination, error) { var notificationDestination NotificationDestination path := fmt.Sprintf("/api/2.0/notification-destinations/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, ¬ificationDestination) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, ¬ificationDestination) return ¬ificationDestination, err } @@ -644,28 +863,31 @@ type personalComputeImpl struct { func (a *personalComputeImpl) Delete(ctx context.Context, request DeletePersonalComputeSettingRequest) (*DeletePersonalComputeSettingResponse, error) { var deletePersonalComputeSettingResponse DeletePersonalComputeSettingResponse path := fmt.Sprintf("/api/2.0/accounts/%v/settings/types/dcp_acct_enable/names/default", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deletePersonalComputeSettingResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deletePersonalComputeSettingResponse) return &deletePersonalComputeSettingResponse, err } func (a *personalComputeImpl) Get(ctx context.Context, request GetPersonalComputeSettingRequest) (*PersonalComputeSetting, error) { var personalComputeSetting PersonalComputeSetting path := fmt.Sprintf("/api/2.0/accounts/%v/settings/types/dcp_acct_enable/names/default", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &personalComputeSetting) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &personalComputeSetting) return &personalComputeSetting, err } func (a *personalComputeImpl) Update(ctx context.Context, request UpdatePersonalComputeSettingRequest) (*PersonalComputeSetting, error) { var personalComputeSetting PersonalComputeSetting path := fmt.Sprintf("/api/2.0/accounts/%v/settings/types/dcp_acct_enable/names/default", a.client.ConfiguredAccountID()) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &personalComputeSetting) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &personalComputeSetting) return &personalComputeSetting, err } @@ -677,28 +899,31 @@ type restrictWorkspaceAdminsImpl struct { func (a *restrictWorkspaceAdminsImpl) Delete(ctx context.Context, request DeleteRestrictWorkspaceAdminsSettingRequest) (*DeleteRestrictWorkspaceAdminsSettingResponse, error) { var deleteRestrictWorkspaceAdminsSettingResponse DeleteRestrictWorkspaceAdminsSettingResponse path := "/api/2.0/settings/types/restrict_workspace_admins/names/default" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteRestrictWorkspaceAdminsSettingResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteRestrictWorkspaceAdminsSettingResponse) return &deleteRestrictWorkspaceAdminsSettingResponse, err } func (a *restrictWorkspaceAdminsImpl) Get(ctx context.Context, request GetRestrictWorkspaceAdminsSettingRequest) (*RestrictWorkspaceAdminsSetting, error) { var restrictWorkspaceAdminsSetting RestrictWorkspaceAdminsSetting path := "/api/2.0/settings/types/restrict_workspace_admins/names/default" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &restrictWorkspaceAdminsSetting) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &restrictWorkspaceAdminsSetting) return &restrictWorkspaceAdminsSetting, err } func (a *restrictWorkspaceAdminsImpl) Update(ctx context.Context, request UpdateRestrictWorkspaceAdminsSettingRequest) (*RestrictWorkspaceAdminsSetting, error) { var restrictWorkspaceAdminsSetting RestrictWorkspaceAdminsSetting path := "/api/2.0/settings/types/restrict_workspace_admins/names/default" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &restrictWorkspaceAdminsSetting) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &restrictWorkspaceAdminsSetting) return &restrictWorkspaceAdminsSetting, err } @@ -715,75 +940,111 @@ type tokenManagementImpl struct { func (a *tokenManagementImpl) CreateOboToken(ctx context.Context, request CreateOboTokenRequest) (*CreateOboTokenResponse, error) { var createOboTokenResponse CreateOboTokenResponse path := "/api/2.0/token-management/on-behalf-of/tokens" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createOboTokenResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createOboTokenResponse) return &createOboTokenResponse, err } func (a *tokenManagementImpl) Delete(ctx context.Context, request DeleteTokenManagementRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.0/token-management/tokens/%v", request.TokenId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *tokenManagementImpl) Get(ctx context.Context, request GetTokenManagementRequest) (*GetTokenResponse, error) { var getTokenResponse GetTokenResponse path := fmt.Sprintf("/api/2.0/token-management/tokens/%v", request.TokenId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getTokenResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getTokenResponse) return &getTokenResponse, err } func (a *tokenManagementImpl) GetPermissionLevels(ctx context.Context) (*GetTokenPermissionLevelsResponse, error) { var getTokenPermissionLevelsResponse GetTokenPermissionLevelsResponse path := "/api/2.0/permissions/authorization/tokens/permissionLevels" + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &getTokenPermissionLevelsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &getTokenPermissionLevelsResponse) return &getTokenPermissionLevelsResponse, err } func (a *tokenManagementImpl) GetPermissions(ctx context.Context) (*TokenPermissions, error) { var tokenPermissions TokenPermissions path := "/api/2.0/permissions/authorization/tokens" + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &tokenPermissions) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &tokenPermissions) return &tokenPermissions, err } -func (a *tokenManagementImpl) List(ctx context.Context, request ListTokenManagementRequest) (*ListTokensResponse, error) { +// List all tokens. +// +// Lists all tokens associated with the specified workspace or user. +func (a *tokenManagementImpl) List(ctx context.Context, request ListTokenManagementRequest) listing.Iterator[TokenInfo] { + + getNextPage := func(ctx context.Context, req ListTokenManagementRequest) (*ListTokensResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListTokensResponse) []TokenInfo { + return resp.TokenInfos + } + + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + nil) + return iterator +} + +// List all tokens. +// +// Lists all tokens associated with the specified workspace or user. +func (a *tokenManagementImpl) ListAll(ctx context.Context, request ListTokenManagementRequest) ([]TokenInfo, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[TokenInfo](ctx, iterator) +} +func (a *tokenManagementImpl) internalList(ctx context.Context, request ListTokenManagementRequest) (*ListTokensResponse, error) { var listTokensResponse ListTokensResponse path := "/api/2.0/token-management/tokens" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listTokensResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listTokensResponse) return &listTokensResponse, err } func (a *tokenManagementImpl) SetPermissions(ctx context.Context, request TokenPermissionsRequest) (*TokenPermissions, error) { var tokenPermissions TokenPermissions path := "/api/2.0/permissions/authorization/tokens" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &tokenPermissions) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &tokenPermissions) return &tokenPermissions, err } func (a *tokenManagementImpl) UpdatePermissions(ctx context.Context, request TokenPermissionsRequest) (*TokenPermissions, error) { var tokenPermissions TokenPermissions path := "/api/2.0/permissions/authorization/tokens" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &tokenPermissions) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &tokenPermissions) return &tokenPermissions, err } @@ -795,29 +1056,61 @@ type tokensImpl struct { func (a *tokensImpl) Create(ctx context.Context, request CreateTokenRequest) (*CreateTokenResponse, error) { var createTokenResponse CreateTokenResponse path := "/api/2.0/token/create" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createTokenResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createTokenResponse) return &createTokenResponse, err } func (a *tokensImpl) Delete(ctx context.Context, request RevokeTokenRequest) error { var revokeTokenResponse RevokeTokenResponse path := "/api/2.0/token/delete" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &revokeTokenResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &revokeTokenResponse) return err } -func (a *tokensImpl) List(ctx context.Context) (*ListPublicTokensResponse, error) { +// List tokens. +// +// Lists all the valid tokens for a user-workspace pair. +func (a *tokensImpl) List(ctx context.Context) listing.Iterator[PublicTokenInfo] { + request := struct{}{} + + getNextPage := func(ctx context.Context, req struct{}) (*ListPublicTokensResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx) + } + getItems := func(resp *ListPublicTokensResponse) []PublicTokenInfo { + return resp.TokenInfos + } + + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + nil) + return iterator +} + +// List tokens. +// +// Lists all the valid tokens for a user-workspace pair. +func (a *tokensImpl) ListAll(ctx context.Context) ([]PublicTokenInfo, error) { + iterator := a.List(ctx) + return listing.ToSlice[PublicTokenInfo](ctx, iterator) +} +func (a *tokensImpl) internalList(ctx context.Context) (*ListPublicTokensResponse, error) { var listPublicTokensResponse ListPublicTokensResponse path := "/api/2.0/token/list" + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &listPublicTokensResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &listPublicTokensResponse) return &listPublicTokensResponse, err } @@ -829,17 +1122,19 @@ type workspaceConfImpl struct { func (a *workspaceConfImpl) GetStatus(ctx context.Context, request GetStatusRequest) (*map[string]string, error) { var workspaceConf map[string]string path := "/api/2.0/workspace-conf" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &workspaceConf) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &workspaceConf) return &workspaceConf, err } func (a *workspaceConfImpl) SetStatus(ctx context.Context, request WorkspaceConf) error { var setStatusResponse SetStatusResponse path := "/api/2.0/workspace-conf" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &setStatusResponse) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &setStatusResponse) return err } diff --git a/settings/v2/model.go b/settings/v2/model.go index 56f6b0c93..aeb2dfbf4 100755 --- a/settings/v2/model.go +++ b/settings/v2/model.go @@ -388,8 +388,12 @@ const ComplianceStandardFedrampModerate ComplianceStandard = `FEDRAMP_MODERATE` const ComplianceStandardHipaa ComplianceStandard = `HIPAA` +const ComplianceStandardHitrust ComplianceStandard = `HITRUST` + const ComplianceStandardIrapProtected ComplianceStandard = `IRAP_PROTECTED` +const ComplianceStandardIsmap ComplianceStandard = `ISMAP` + const ComplianceStandardItarEar ComplianceStandard = `ITAR_EAR` const ComplianceStandardNone ComplianceStandard = `NONE` @@ -404,11 +408,11 @@ func (f *ComplianceStandard) String() string { // Set raw string value and validate it against allowed values func (f *ComplianceStandard) Set(v string) error { switch v { - case `CANADA_PROTECTED_B`, `CYBER_ESSENTIAL_PLUS`, `FEDRAMP_HIGH`, `FEDRAMP_IL5`, `FEDRAMP_MODERATE`, `HIPAA`, `IRAP_PROTECTED`, `ITAR_EAR`, `NONE`, `PCI_DSS`: + case `CANADA_PROTECTED_B`, `CYBER_ESSENTIAL_PLUS`, `FEDRAMP_HIGH`, `FEDRAMP_IL5`, `FEDRAMP_MODERATE`, `HIPAA`, `HITRUST`, `IRAP_PROTECTED`, `ISMAP`, `ITAR_EAR`, `NONE`, `PCI_DSS`: *f = ComplianceStandard(v) return nil default: - return fmt.Errorf(`value "%s" is not one of "CANADA_PROTECTED_B", "CYBER_ESSENTIAL_PLUS", "FEDRAMP_HIGH", "FEDRAMP_IL5", "FEDRAMP_MODERATE", "HIPAA", "IRAP_PROTECTED", "ITAR_EAR", "NONE", "PCI_DSS"`, v) + return fmt.Errorf(`value "%s" is not one of "CANADA_PROTECTED_B", "CYBER_ESSENTIAL_PLUS", "FEDRAMP_HIGH", "FEDRAMP_IL5", "FEDRAMP_MODERATE", "HIPAA", "HITRUST", "IRAP_PROTECTED", "ISMAP", "ITAR_EAR", "NONE", "PCI_DSS"`, v) } } @@ -2628,10 +2632,17 @@ type UpdateAccountIpAccessEnableRequest struct { // This should always be set to true for Settings API. Added for AIP // compliance. AllowMissing bool `json:"allow_missing"` - // Field mask is required to be passed into the PATCH request. Field mask - // specifies which fields of the setting payload will be updated. The field - // mask needs to be supplied as single string. To specify multiple fields in - // the field mask, use comma as the separator (no space). + // The field mask must be a single string, with multiple fields separated by + // commas (no spaces). The field path is relative to the resource object, + // using a dot (`.`) to navigate sub-fields (e.g., `author.given_name`). + // Specification of elements in sequence or map fields is not allowed, as + // only the entire collection field can be specified. Field names must + // exactly match the resource field names. + // + // A field mask of `*` indicates full replacement. It’s recommended to + // always explicitly list the fields being updated and avoid using `*` + // wildcards, as it can lead to unintended results if the API changes in the + // future. FieldMask string `json:"field_mask"` Setting AccountIpAccessEnable `json:"setting"` @@ -2642,10 +2653,17 @@ type UpdateAibiDashboardEmbeddingAccessPolicySettingRequest struct { // This should always be set to true for Settings API. Added for AIP // compliance. AllowMissing bool `json:"allow_missing"` - // Field mask is required to be passed into the PATCH request. Field mask - // specifies which fields of the setting payload will be updated. The field - // mask needs to be supplied as single string. To specify multiple fields in - // the field mask, use comma as the separator (no space). + // The field mask must be a single string, with multiple fields separated by + // commas (no spaces). The field path is relative to the resource object, + // using a dot (`.`) to navigate sub-fields (e.g., `author.given_name`). + // Specification of elements in sequence or map fields is not allowed, as + // only the entire collection field can be specified. Field names must + // exactly match the resource field names. + // + // A field mask of `*` indicates full replacement. It’s recommended to + // always explicitly list the fields being updated and avoid using `*` + // wildcards, as it can lead to unintended results if the API changes in the + // future. FieldMask string `json:"field_mask"` Setting AibiDashboardEmbeddingAccessPolicySetting `json:"setting"` @@ -2656,10 +2674,17 @@ type UpdateAibiDashboardEmbeddingApprovedDomainsSettingRequest struct { // This should always be set to true for Settings API. Added for AIP // compliance. AllowMissing bool `json:"allow_missing"` - // Field mask is required to be passed into the PATCH request. Field mask - // specifies which fields of the setting payload will be updated. The field - // mask needs to be supplied as single string. To specify multiple fields in - // the field mask, use comma as the separator (no space). + // The field mask must be a single string, with multiple fields separated by + // commas (no spaces). The field path is relative to the resource object, + // using a dot (`.`) to navigate sub-fields (e.g., `author.given_name`). + // Specification of elements in sequence or map fields is not allowed, as + // only the entire collection field can be specified. Field names must + // exactly match the resource field names. + // + // A field mask of `*` indicates full replacement. It’s recommended to + // always explicitly list the fields being updated and avoid using `*` + // wildcards, as it can lead to unintended results if the API changes in the + // future. FieldMask string `json:"field_mask"` Setting AibiDashboardEmbeddingApprovedDomainsSetting `json:"setting"` @@ -2670,10 +2695,17 @@ type UpdateAutomaticClusterUpdateSettingRequest struct { // This should always be set to true for Settings API. Added for AIP // compliance. AllowMissing bool `json:"allow_missing"` - // Field mask is required to be passed into the PATCH request. Field mask - // specifies which fields of the setting payload will be updated. The field - // mask needs to be supplied as single string. To specify multiple fields in - // the field mask, use comma as the separator (no space). + // The field mask must be a single string, with multiple fields separated by + // commas (no spaces). The field path is relative to the resource object, + // using a dot (`.`) to navigate sub-fields (e.g., `author.given_name`). + // Specification of elements in sequence or map fields is not allowed, as + // only the entire collection field can be specified. Field names must + // exactly match the resource field names. + // + // A field mask of `*` indicates full replacement. It’s recommended to + // always explicitly list the fields being updated and avoid using `*` + // wildcards, as it can lead to unintended results if the API changes in the + // future. FieldMask string `json:"field_mask"` Setting AutomaticClusterUpdateSetting `json:"setting"` @@ -2684,10 +2716,17 @@ type UpdateComplianceSecurityProfileSettingRequest struct { // This should always be set to true for Settings API. Added for AIP // compliance. AllowMissing bool `json:"allow_missing"` - // Field mask is required to be passed into the PATCH request. Field mask - // specifies which fields of the setting payload will be updated. The field - // mask needs to be supplied as single string. To specify multiple fields in - // the field mask, use comma as the separator (no space). + // The field mask must be a single string, with multiple fields separated by + // commas (no spaces). The field path is relative to the resource object, + // using a dot (`.`) to navigate sub-fields (e.g., `author.given_name`). + // Specification of elements in sequence or map fields is not allowed, as + // only the entire collection field can be specified. Field names must + // exactly match the resource field names. + // + // A field mask of `*` indicates full replacement. It’s recommended to + // always explicitly list the fields being updated and avoid using `*` + // wildcards, as it can lead to unintended results if the API changes in the + // future. FieldMask string `json:"field_mask"` Setting ComplianceSecurityProfileSetting `json:"setting"` @@ -2698,10 +2737,17 @@ type UpdateCspEnablementAccountSettingRequest struct { // This should always be set to true for Settings API. Added for AIP // compliance. AllowMissing bool `json:"allow_missing"` - // Field mask is required to be passed into the PATCH request. Field mask - // specifies which fields of the setting payload will be updated. The field - // mask needs to be supplied as single string. To specify multiple fields in - // the field mask, use comma as the separator (no space). + // The field mask must be a single string, with multiple fields separated by + // commas (no spaces). The field path is relative to the resource object, + // using a dot (`.`) to navigate sub-fields (e.g., `author.given_name`). + // Specification of elements in sequence or map fields is not allowed, as + // only the entire collection field can be specified. Field names must + // exactly match the resource field names. + // + // A field mask of `*` indicates full replacement. It’s recommended to + // always explicitly list the fields being updated and avoid using `*` + // wildcards, as it can lead to unintended results if the API changes in the + // future. FieldMask string `json:"field_mask"` Setting CspEnablementAccountSetting `json:"setting"` @@ -2712,10 +2758,17 @@ type UpdateDefaultNamespaceSettingRequest struct { // This should always be set to true for Settings API. Added for AIP // compliance. AllowMissing bool `json:"allow_missing"` - // Field mask is required to be passed into the PATCH request. Field mask - // specifies which fields of the setting payload will be updated. The field - // mask needs to be supplied as single string. To specify multiple fields in - // the field mask, use comma as the separator (no space). + // The field mask must be a single string, with multiple fields separated by + // commas (no spaces). The field path is relative to the resource object, + // using a dot (`.`) to navigate sub-fields (e.g., `author.given_name`). + // Specification of elements in sequence or map fields is not allowed, as + // only the entire collection field can be specified. Field names must + // exactly match the resource field names. + // + // A field mask of `*` indicates full replacement. It’s recommended to + // always explicitly list the fields being updated and avoid using `*` + // wildcards, as it can lead to unintended results if the API changes in the + // future. FieldMask string `json:"field_mask"` // This represents the setting configuration for the default namespace in // the Databricks workspace. Setting the default catalog for the workspace @@ -2734,10 +2787,17 @@ type UpdateDisableLegacyAccessRequest struct { // This should always be set to true for Settings API. Added for AIP // compliance. AllowMissing bool `json:"allow_missing"` - // Field mask is required to be passed into the PATCH request. Field mask - // specifies which fields of the setting payload will be updated. The field - // mask needs to be supplied as single string. To specify multiple fields in - // the field mask, use comma as the separator (no space). + // The field mask must be a single string, with multiple fields separated by + // commas (no spaces). The field path is relative to the resource object, + // using a dot (`.`) to navigate sub-fields (e.g., `author.given_name`). + // Specification of elements in sequence or map fields is not allowed, as + // only the entire collection field can be specified. Field names must + // exactly match the resource field names. + // + // A field mask of `*` indicates full replacement. It’s recommended to + // always explicitly list the fields being updated and avoid using `*` + // wildcards, as it can lead to unintended results if the API changes in the + // future. FieldMask string `json:"field_mask"` Setting DisableLegacyAccess `json:"setting"` @@ -2748,10 +2808,17 @@ type UpdateDisableLegacyDbfsRequest struct { // This should always be set to true for Settings API. Added for AIP // compliance. AllowMissing bool `json:"allow_missing"` - // Field mask is required to be passed into the PATCH request. Field mask - // specifies which fields of the setting payload will be updated. The field - // mask needs to be supplied as single string. To specify multiple fields in - // the field mask, use comma as the separator (no space). + // The field mask must be a single string, with multiple fields separated by + // commas (no spaces). The field path is relative to the resource object, + // using a dot (`.`) to navigate sub-fields (e.g., `author.given_name`). + // Specification of elements in sequence or map fields is not allowed, as + // only the entire collection field can be specified. Field names must + // exactly match the resource field names. + // + // A field mask of `*` indicates full replacement. It’s recommended to + // always explicitly list the fields being updated and avoid using `*` + // wildcards, as it can lead to unintended results if the API changes in the + // future. FieldMask string `json:"field_mask"` Setting DisableLegacyDbfs `json:"setting"` @@ -2762,10 +2829,17 @@ type UpdateDisableLegacyFeaturesRequest struct { // This should always be set to true for Settings API. Added for AIP // compliance. AllowMissing bool `json:"allow_missing"` - // Field mask is required to be passed into the PATCH request. Field mask - // specifies which fields of the setting payload will be updated. The field - // mask needs to be supplied as single string. To specify multiple fields in - // the field mask, use comma as the separator (no space). + // The field mask must be a single string, with multiple fields separated by + // commas (no spaces). The field path is relative to the resource object, + // using a dot (`.`) to navigate sub-fields (e.g., `author.given_name`). + // Specification of elements in sequence or map fields is not allowed, as + // only the entire collection field can be specified. Field names must + // exactly match the resource field names. + // + // A field mask of `*` indicates full replacement. It’s recommended to + // always explicitly list the fields being updated and avoid using `*` + // wildcards, as it can lead to unintended results if the API changes in the + // future. FieldMask string `json:"field_mask"` Setting DisableLegacyFeatures `json:"setting"` @@ -2776,10 +2850,17 @@ type UpdateEnhancedSecurityMonitoringSettingRequest struct { // This should always be set to true for Settings API. Added for AIP // compliance. AllowMissing bool `json:"allow_missing"` - // Field mask is required to be passed into the PATCH request. Field mask - // specifies which fields of the setting payload will be updated. The field - // mask needs to be supplied as single string. To specify multiple fields in - // the field mask, use comma as the separator (no space). + // The field mask must be a single string, with multiple fields separated by + // commas (no spaces). The field path is relative to the resource object, + // using a dot (`.`) to navigate sub-fields (e.g., `author.given_name`). + // Specification of elements in sequence or map fields is not allowed, as + // only the entire collection field can be specified. Field names must + // exactly match the resource field names. + // + // A field mask of `*` indicates full replacement. It’s recommended to + // always explicitly list the fields being updated and avoid using `*` + // wildcards, as it can lead to unintended results if the API changes in the + // future. FieldMask string `json:"field_mask"` Setting EnhancedSecurityMonitoringSetting `json:"setting"` @@ -2790,10 +2871,17 @@ type UpdateEsmEnablementAccountSettingRequest struct { // This should always be set to true for Settings API. Added for AIP // compliance. AllowMissing bool `json:"allow_missing"` - // Field mask is required to be passed into the PATCH request. Field mask - // specifies which fields of the setting payload will be updated. The field - // mask needs to be supplied as single string. To specify multiple fields in - // the field mask, use comma as the separator (no space). + // The field mask must be a single string, with multiple fields separated by + // commas (no spaces). The field path is relative to the resource object, + // using a dot (`.`) to navigate sub-fields (e.g., `author.given_name`). + // Specification of elements in sequence or map fields is not allowed, as + // only the entire collection field can be specified. Field names must + // exactly match the resource field names. + // + // A field mask of `*` indicates full replacement. It’s recommended to + // always explicitly list the fields being updated and avoid using `*` + // wildcards, as it can lead to unintended results if the API changes in the + // future. FieldMask string `json:"field_mask"` Setting EsmEnablementAccountSetting `json:"setting"` @@ -2853,10 +2941,17 @@ type UpdatePersonalComputeSettingRequest struct { // This should always be set to true for Settings API. Added for AIP // compliance. AllowMissing bool `json:"allow_missing"` - // Field mask is required to be passed into the PATCH request. Field mask - // specifies which fields of the setting payload will be updated. The field - // mask needs to be supplied as single string. To specify multiple fields in - // the field mask, use comma as the separator (no space). + // The field mask must be a single string, with multiple fields separated by + // commas (no spaces). The field path is relative to the resource object, + // using a dot (`.`) to navigate sub-fields (e.g., `author.given_name`). + // Specification of elements in sequence or map fields is not allowed, as + // only the entire collection field can be specified. Field names must + // exactly match the resource field names. + // + // A field mask of `*` indicates full replacement. It’s recommended to + // always explicitly list the fields being updated and avoid using `*` + // wildcards, as it can lead to unintended results if the API changes in the + // future. FieldMask string `json:"field_mask"` Setting PersonalComputeSetting `json:"setting"` @@ -2870,10 +2965,17 @@ type UpdateRestrictWorkspaceAdminsSettingRequest struct { // This should always be set to true for Settings API. Added for AIP // compliance. AllowMissing bool `json:"allow_missing"` - // Field mask is required to be passed into the PATCH request. Field mask - // specifies which fields of the setting payload will be updated. The field - // mask needs to be supplied as single string. To specify multiple fields in - // the field mask, use comma as the separator (no space). + // The field mask must be a single string, with multiple fields separated by + // commas (no spaces). The field path is relative to the resource object, + // using a dot (`.`) to navigate sub-fields (e.g., `author.given_name`). + // Specification of elements in sequence or map fields is not allowed, as + // only the entire collection field can be specified. Field names must + // exactly match the resource field names. + // + // A field mask of `*` indicates full replacement. It’s recommended to + // always explicitly list the fields being updated and avoid using `*` + // wildcards, as it can lead to unintended results if the API changes in the + // future. FieldMask string `json:"field_mask"` Setting RestrictWorkspaceAdminsSetting `json:"setting"` diff --git a/sharing/go.mod b/sharing/go.mod index c4cd162e4..a57b5ecd4 100644 --- a/sharing/go.mod +++ b/sharing/go.mod @@ -6,6 +6,7 @@ replace github.com/databricks/databricks-sdk-go/databricks => ../databricks require ( github.com/databricks/databricks-sdk-go/databricks v0.0.0-00010101000000-000000000000 + golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 golang.org/x/oauth2 v0.25.0 ) @@ -27,7 +28,6 @@ require ( go.opentelemetry.io/otel/metric v1.24.0 // indirect go.opentelemetry.io/otel/trace v1.24.0 // indirect golang.org/x/crypto v0.31.0 // indirect - golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.33.0 // indirect golang.org/x/sys v0.28.0 // indirect diff --git a/sharing/v2/api.go b/sharing/v2/api.go index 4f106ceea..3ff151c57 100755 --- a/sharing/v2/api.go +++ b/sharing/v2/api.go @@ -145,51 +145,6 @@ func (a *ProvidersAPI) GetByName(ctx context.Context, name string) (*ProviderInf }) } -// List providers. -// -// Gets an array of available authentication providers. The caller must either -// be a metastore admin or the owner of the providers. Providers not owned by -// the caller are not included in the response. There is no guarantee of a -// specific ordering of the elements in the array. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ProvidersAPI) List(ctx context.Context, request ListProvidersRequest) listing.Iterator[ProviderInfo] { - - getNextPage := func(ctx context.Context, req ListProvidersRequest) (*ListProvidersResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.providersImpl.List(ctx, req) - } - getItems := func(resp *ListProvidersResponse) []ProviderInfo { - return resp.Providers - } - getNextReq := func(resp *ListProvidersResponse) *ListProvidersRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List providers. -// -// Gets an array of available authentication providers. The caller must either -// be a metastore admin or the owner of the providers. Providers not owned by -// the caller are not included in the response. There is no guarantee of a -// specific ordering of the elements in the array. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ProvidersAPI) ListAll(ctx context.Context, request ListProvidersRequest) ([]ProviderInfo, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[ProviderInfo](ctx, iterator) -} - // ProviderInfoNameToMetastoreIdMap calls [ProvidersAPI.ListAll] and creates a map of results with [ProviderInfo].Name as key and [ProviderInfo].MetastoreId as value. // // Returns an error if there's more than one [ProviderInfo] with the same .Name. @@ -215,50 +170,13 @@ func (a *ProvidersAPI) ProviderInfoNameToMetastoreIdMap(ctx context.Context, req return mapping, nil } -// List shares by Provider. -// -// Gets an array of a specified provider's shares within the metastore where: -// -// * the caller is a metastore admin, or * the caller is the owner. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ProvidersAPI) ListShares(ctx context.Context, request ListSharesRequest) listing.Iterator[ProviderShare] { - - getNextPage := func(ctx context.Context, req ListSharesRequest) (*ListProviderSharesResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.providersImpl.ListShares(ctx, req) - } - getItems := func(resp *ListProviderSharesResponse) []ProviderShare { - return resp.Shares - } - - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - nil) - return iterator -} - -// List shares by Provider. -// -// Gets an array of a specified provider's shares within the metastore where: -// -// * the caller is a metastore admin, or * the caller is the owner. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ProvidersAPI) ListSharesAll(ctx context.Context, request ListSharesRequest) ([]ProviderShare, error) { - iterator := a.ListShares(ctx, request) - return listing.ToSlice[ProviderShare](ctx, iterator) -} - // List shares by Provider. // // Gets an array of a specified provider's shares within the metastore where: // // * 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.providersImpl.ListShares(ctx, ListSharesRequest{ + return a.providersImpl.internalListShares(ctx, ListSharesRequest{ Name: name, }) } @@ -461,51 +379,6 @@ func (a *RecipientsAPI) GetByName(ctx context.Context, name string) (*RecipientI }) } -// List share recipients. -// -// Gets an array of all share recipients within the current metastore where: -// -// * the caller is a metastore admin, or * the caller is the owner. There is no -// guarantee of a specific ordering of the elements in the array. -// -// This method is generated by Databricks SDK Code Generator. -func (a *RecipientsAPI) List(ctx context.Context, request ListRecipientsRequest) listing.Iterator[RecipientInfo] { - - getNextPage := func(ctx context.Context, req ListRecipientsRequest) (*ListRecipientsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.recipientsImpl.List(ctx, req) - } - getItems := func(resp *ListRecipientsResponse) []RecipientInfo { - return resp.Recipients - } - getNextReq := func(resp *ListRecipientsResponse) *ListRecipientsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List share recipients. -// -// Gets an array of all share recipients within the current metastore where: -// -// * the caller is a metastore admin, or * the caller is the owner. There is no -// guarantee of a specific ordering of the elements in the array. -// -// This method is generated by Databricks SDK Code Generator. -func (a *RecipientsAPI) ListAll(ctx context.Context, request ListRecipientsRequest) ([]RecipientInfo, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[RecipientInfo](ctx, iterator) -} - // Get recipient share permissions. // // Gets the share permissions for the specified Recipient. The caller must be a @@ -648,49 +521,6 @@ func (a *SharesAPI) GetByName(ctx context.Context, name string) (*ShareInfo, err }) } -// List shares. -// -// Gets an array of data object shares from the metastore. The caller must be a -// metastore admin or the owner of the share. There is no guarantee of a -// specific ordering of the elements in the array. -// -// This method is generated by Databricks SDK Code Generator. -func (a *SharesAPI) List(ctx context.Context, request ListSharesRequest) listing.Iterator[ShareInfo] { - - getNextPage := func(ctx context.Context, req ListSharesRequest) (*ListSharesResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.sharesImpl.List(ctx, req) - } - getItems := func(resp *ListSharesResponse) []ShareInfo { - return resp.Shares - } - getNextReq := func(resp *ListSharesResponse) *ListSharesRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List shares. -// -// Gets an array of data object shares from the metastore. The caller must be a -// metastore admin or the owner of the share. There is no guarantee of a -// specific ordering of the elements in the array. -// -// This method is generated by Databricks SDK Code Generator. -func (a *SharesAPI) ListAll(ctx context.Context, request ListSharesRequest) ([]ShareInfo, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[ShareInfo](ctx, iterator) -} - // Get permissions. // // Gets the permissions for a data share from the metastore. The caller must be diff --git a/sharing/v2/impl.go b/sharing/v2/impl.go index f4b5e95fe..eda35a23f 100755 --- a/sharing/v2/impl.go +++ b/sharing/v2/impl.go @@ -8,6 +8,9 @@ import ( "net/http" "github.com/databricks/databricks-sdk-go/databricks/client" + "github.com/databricks/databricks-sdk-go/databricks/listing" + "github.com/databricks/databricks-sdk-go/databricks/useragent" + "golang.org/x/exp/slices" ) // unexported type that holds implementations of just Providers API methods @@ -18,56 +21,140 @@ type providersImpl struct { func (a *providersImpl) Create(ctx context.Context, request CreateProvider) (*ProviderInfo, error) { var providerInfo ProviderInfo path := "/api/2.1/unity-catalog/providers" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &providerInfo) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &providerInfo) return &providerInfo, err } func (a *providersImpl) Delete(ctx context.Context, request DeleteProviderRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.1/unity-catalog/providers/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *providersImpl) Get(ctx context.Context, request GetProviderRequest) (*ProviderInfo, error) { var providerInfo ProviderInfo path := fmt.Sprintf("/api/2.1/unity-catalog/providers/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &providerInfo) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &providerInfo) return &providerInfo, err } -func (a *providersImpl) List(ctx context.Context, request ListProvidersRequest) (*ListProvidersResponse, error) { +// List providers. +// +// Gets an array of available authentication providers. The caller must either +// be a metastore admin or the owner of the providers. Providers not owned by +// the caller are not included in the response. There is no guarantee of a +// specific ordering of the elements in the array. +func (a *providersImpl) List(ctx context.Context, request ListProvidersRequest) listing.Iterator[ProviderInfo] { + + getNextPage := func(ctx context.Context, req ListProvidersRequest) (*ListProvidersResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListProvidersResponse) []ProviderInfo { + return resp.Providers + } + getNextReq := func(resp *ListProvidersResponse) *ListProvidersRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List providers. +// +// Gets an array of available authentication providers. The caller must either +// be a metastore admin or the owner of the providers. Providers not owned by +// the caller are not included in the response. There is no guarantee of a +// specific ordering of the elements in the array. +func (a *providersImpl) ListAll(ctx context.Context, request ListProvidersRequest) ([]ProviderInfo, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[ProviderInfo](ctx, iterator) +} +func (a *providersImpl) internalList(ctx context.Context, request ListProvidersRequest) (*ListProvidersResponse, error) { var listProvidersResponse ListProvidersResponse path := "/api/2.1/unity-catalog/providers" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listProvidersResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listProvidersResponse) return &listProvidersResponse, err } -func (a *providersImpl) ListShares(ctx context.Context, request ListSharesRequest) (*ListProviderSharesResponse, error) { +// List shares by Provider. +// +// Gets an array of a specified provider's shares within the metastore where: +// +// * the caller is a metastore admin, or * the caller is the owner. +func (a *providersImpl) ListShares(ctx context.Context, request ListSharesRequest) listing.Iterator[ProviderShare] { + + getNextPage := func(ctx context.Context, req ListSharesRequest) (*ListProviderSharesResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalListShares(ctx, req) + } + getItems := func(resp *ListProviderSharesResponse) []ProviderShare { + return resp.Shares + } + getNextReq := func(resp *ListProviderSharesResponse) *ListSharesRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List shares by Provider. +// +// Gets an array of a specified provider's shares within the metastore where: +// +// * the caller is a metastore admin, or * the caller is the owner. +func (a *providersImpl) ListSharesAll(ctx context.Context, request ListSharesRequest) ([]ProviderShare, error) { + iterator := a.ListShares(ctx, request) + return listing.ToSlice[ProviderShare](ctx, iterator) +} +func (a *providersImpl) internalListShares(ctx context.Context, request ListSharesRequest) (*ListProviderSharesResponse, error) { var listProviderSharesResponse ListProviderSharesResponse path := fmt.Sprintf("/api/2.1/unity-catalog/providers/%v/shares", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listProviderSharesResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listProviderSharesResponse) return &listProviderSharesResponse, err } func (a *providersImpl) Update(ctx context.Context, request UpdateProvider) (*ProviderInfo, error) { var providerInfo ProviderInfo path := fmt.Sprintf("/api/2.1/unity-catalog/providers/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &providerInfo) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &providerInfo) return &providerInfo, err } @@ -79,18 +166,20 @@ type recipientActivationImpl struct { func (a *recipientActivationImpl) GetActivationUrlInfo(ctx context.Context, request GetActivationUrlInfoRequest) error { var getActivationUrlInfoResponse GetActivationUrlInfoResponse path := fmt.Sprintf("/api/2.1/unity-catalog/public/data_sharing_activation_info/%v", request.ActivationUrl) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getActivationUrlInfoResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getActivationUrlInfoResponse) 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) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &retrieveTokenResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &retrieveTokenResponse) return &retrieveTokenResponse, err } @@ -102,66 +191,113 @@ type recipientsImpl struct { func (a *recipientsImpl) Create(ctx context.Context, request CreateRecipient) (*RecipientInfo, error) { var recipientInfo RecipientInfo path := "/api/2.1/unity-catalog/recipients" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &recipientInfo) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &recipientInfo) return &recipientInfo, err } func (a *recipientsImpl) Delete(ctx context.Context, request DeleteRecipientRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.1/unity-catalog/recipients/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *recipientsImpl) Get(ctx context.Context, request GetRecipientRequest) (*RecipientInfo, error) { var recipientInfo RecipientInfo path := fmt.Sprintf("/api/2.1/unity-catalog/recipients/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &recipientInfo) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &recipientInfo) return &recipientInfo, err } -func (a *recipientsImpl) List(ctx context.Context, request ListRecipientsRequest) (*ListRecipientsResponse, error) { +// List share recipients. +// +// Gets an array of all share recipients within the current metastore where: +// +// * the caller is a metastore admin, or * the caller is the owner. There is no +// guarantee of a specific ordering of the elements in the array. +func (a *recipientsImpl) List(ctx context.Context, request ListRecipientsRequest) listing.Iterator[RecipientInfo] { + + getNextPage := func(ctx context.Context, req ListRecipientsRequest) (*ListRecipientsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListRecipientsResponse) []RecipientInfo { + return resp.Recipients + } + getNextReq := func(resp *ListRecipientsResponse) *ListRecipientsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List share recipients. +// +// Gets an array of all share recipients within the current metastore where: +// +// * the caller is a metastore admin, or * the caller is the owner. There is no +// guarantee of a specific ordering of the elements in the array. +func (a *recipientsImpl) ListAll(ctx context.Context, request ListRecipientsRequest) ([]RecipientInfo, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[RecipientInfo](ctx, iterator) +} +func (a *recipientsImpl) internalList(ctx context.Context, request ListRecipientsRequest) (*ListRecipientsResponse, error) { var listRecipientsResponse ListRecipientsResponse path := "/api/2.1/unity-catalog/recipients" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listRecipientsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listRecipientsResponse) return &listRecipientsResponse, err } func (a *recipientsImpl) RotateToken(ctx context.Context, request RotateRecipientToken) (*RecipientInfo, error) { var recipientInfo RecipientInfo path := fmt.Sprintf("/api/2.1/unity-catalog/recipients/%v/rotate-token", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &recipientInfo) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &recipientInfo) return &recipientInfo, err } func (a *recipientsImpl) SharePermissions(ctx context.Context, request SharePermissionsRequest) (*GetRecipientSharePermissionsResponse, error) { var getRecipientSharePermissionsResponse GetRecipientSharePermissionsResponse path := fmt.Sprintf("/api/2.1/unity-catalog/recipients/%v/share-permissions", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getRecipientSharePermissionsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getRecipientSharePermissionsResponse) return &getRecipientSharePermissionsResponse, err } func (a *recipientsImpl) Update(ctx context.Context, request UpdateRecipient) (*RecipientInfo, error) { var recipientInfo RecipientInfo path := fmt.Sprintf("/api/2.1/unity-catalog/recipients/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &recipientInfo) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &recipientInfo) return &recipientInfo, err } @@ -173,65 +309,116 @@ type sharesImpl struct { func (a *sharesImpl) Create(ctx context.Context, request CreateShare) (*ShareInfo, error) { var shareInfo ShareInfo path := "/api/2.1/unity-catalog/shares" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &shareInfo) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &shareInfo) return &shareInfo, err } func (a *sharesImpl) Delete(ctx context.Context, request DeleteShareRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.1/unity-catalog/shares/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *sharesImpl) Get(ctx context.Context, request GetShareRequest) (*ShareInfo, error) { var shareInfo ShareInfo path := fmt.Sprintf("/api/2.1/unity-catalog/shares/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &shareInfo) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &shareInfo) return &shareInfo, err } -func (a *sharesImpl) List(ctx context.Context, request ListSharesRequest) (*ListSharesResponse, error) { +// List shares. +// +// Gets an array of data object shares from the metastore. The caller must be a +// metastore admin or the owner of the share. There is no guarantee of a +// specific ordering of the elements in the array. +func (a *sharesImpl) List(ctx context.Context, request ListSharesRequest) listing.Iterator[ShareInfo] { + + getNextPage := func(ctx context.Context, req ListSharesRequest) (*ListSharesResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListSharesResponse) []ShareInfo { + return resp.Shares + } + getNextReq := func(resp *ListSharesResponse) *ListSharesRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List shares. +// +// Gets an array of data object shares from the metastore. The caller must be a +// metastore admin or the owner of the share. There is no guarantee of a +// specific ordering of the elements in the array. +func (a *sharesImpl) ListAll(ctx context.Context, request ListSharesRequest) ([]ShareInfo, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[ShareInfo](ctx, iterator) +} +func (a *sharesImpl) internalList(ctx context.Context, request ListSharesRequest) (*ListSharesResponse, error) { var listSharesResponse ListSharesResponse path := "/api/2.1/unity-catalog/shares" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listSharesResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listSharesResponse) return &listSharesResponse, err } func (a *sharesImpl) SharePermissions(ctx context.Context, request SharePermissionsRequest) (*PermissionsList, error) { var permissionsList PermissionsList path := fmt.Sprintf("/api/2.1/unity-catalog/shares/%v/permissions", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &permissionsList) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &permissionsList) return &permissionsList, err } func (a *sharesImpl) Update(ctx context.Context, request UpdateShare) (*ShareInfo, error) { var shareInfo ShareInfo path := fmt.Sprintf("/api/2.1/unity-catalog/shares/%v", request.Name) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &shareInfo) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &shareInfo) return &shareInfo, err } func (a *sharesImpl) UpdatePermissions(ctx context.Context, request UpdateSharePermissions) error { var updatePermissionsResponse UpdatePermissionsResponse path := fmt.Sprintf("/api/2.1/unity-catalog/shares/%v/permissions", request.Name) + queryParams := make(map[string]any) + if request.MaxResults != 0 || slices.Contains(request.ForceSendFields, "MaxResults") { + queryParams["max_results"] = request.MaxResults + } + if request.PageToken != "" || slices.Contains(request.ForceSendFields, "PageToken") { + queryParams["page_token"] = request.PageToken + } headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &updatePermissionsResponse) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &updatePermissionsResponse) return err } diff --git a/sharing/v2/model.go b/sharing/v2/model.go index b0d2e4fac..bce3827a2 100755 --- a/sharing/v2/model.go +++ b/sharing/v2/model.go @@ -420,11 +420,11 @@ func (f *PartitionValueOp) Type() string { type PermissionsChange struct { // The set of privileges to add. - Add []SharingPrivilege `json:"add,omitempty"` + Add []Privilege `json:"add,omitempty"` // The principal whose privileges we are changing. Principal string `json:"principal,omitempty"` // The set of privileges to remove. - Remove []SharingPrivilege `json:"remove,omitempty"` + Remove []Privilege `json:"remove,omitempty"` ForceSendFields []string `json:"-"` } @@ -439,7 +439,7 @@ func (s PermissionsChange) MarshalJSON() ([]byte, error) { type PermissionsList struct { // The privileges assigned to each principal - PrivilegeAssignments []SharingPrivilegeAssignment `json:"privilege_assignments,omitempty"` + PrivilegeAssignments []PrivilegeAssignment `json:"privilege_assignments,omitempty"` } type Privilege string @@ -1063,136 +1063,6 @@ func (f *SharedDataObjectUpdateAction) Type() string { return "SharedDataObjectUpdateAction" } -type SharingPrivilege string - -const SharingPrivilegeAccess SharingPrivilege = `ACCESS` - -const SharingPrivilegeAllPrivileges SharingPrivilege = `ALL_PRIVILEGES` - -const SharingPrivilegeApplyTag SharingPrivilege = `APPLY_TAG` - -const SharingPrivilegeCreate SharingPrivilege = `CREATE` - -const SharingPrivilegeCreateCatalog SharingPrivilege = `CREATE_CATALOG` - -const SharingPrivilegeCreateConnection SharingPrivilege = `CREATE_CONNECTION` - -const SharingPrivilegeCreateExternalLocation SharingPrivilege = `CREATE_EXTERNAL_LOCATION` - -const SharingPrivilegeCreateExternalTable SharingPrivilege = `CREATE_EXTERNAL_TABLE` - -const SharingPrivilegeCreateExternalVolume SharingPrivilege = `CREATE_EXTERNAL_VOLUME` - -const SharingPrivilegeCreateForeignCatalog SharingPrivilege = `CREATE_FOREIGN_CATALOG` - -const SharingPrivilegeCreateForeignSecurable SharingPrivilege = `CREATE_FOREIGN_SECURABLE` - -const SharingPrivilegeCreateFunction SharingPrivilege = `CREATE_FUNCTION` - -const SharingPrivilegeCreateManagedStorage SharingPrivilege = `CREATE_MANAGED_STORAGE` - -const SharingPrivilegeCreateMaterializedView SharingPrivilege = `CREATE_MATERIALIZED_VIEW` - -const SharingPrivilegeCreateModel SharingPrivilege = `CREATE_MODEL` - -const SharingPrivilegeCreateProvider SharingPrivilege = `CREATE_PROVIDER` - -const SharingPrivilegeCreateRecipient SharingPrivilege = `CREATE_RECIPIENT` - -const SharingPrivilegeCreateSchema SharingPrivilege = `CREATE_SCHEMA` - -const SharingPrivilegeCreateServiceCredential SharingPrivilege = `CREATE_SERVICE_CREDENTIAL` - -const SharingPrivilegeCreateShare SharingPrivilege = `CREATE_SHARE` - -const SharingPrivilegeCreateStorageCredential SharingPrivilege = `CREATE_STORAGE_CREDENTIAL` - -const SharingPrivilegeCreateTable SharingPrivilege = `CREATE_TABLE` - -const SharingPrivilegeCreateView SharingPrivilege = `CREATE_VIEW` - -const SharingPrivilegeCreateVolume SharingPrivilege = `CREATE_VOLUME` - -const SharingPrivilegeExecute SharingPrivilege = `EXECUTE` - -const SharingPrivilegeManage SharingPrivilege = `MANAGE` - -const SharingPrivilegeManageAllowlist SharingPrivilege = `MANAGE_ALLOWLIST` - -const SharingPrivilegeModify SharingPrivilege = `MODIFY` - -const SharingPrivilegeReadFiles SharingPrivilege = `READ_FILES` - -const SharingPrivilegeReadPrivateFiles SharingPrivilege = `READ_PRIVATE_FILES` - -const SharingPrivilegeReadVolume SharingPrivilege = `READ_VOLUME` - -const SharingPrivilegeRefresh SharingPrivilege = `REFRESH` - -const SharingPrivilegeSelect SharingPrivilege = `SELECT` - -const SharingPrivilegeSetSharePermission SharingPrivilege = `SET_SHARE_PERMISSION` - -const SharingPrivilegeUsage SharingPrivilege = `USAGE` - -const SharingPrivilegeUseCatalog SharingPrivilege = `USE_CATALOG` - -const SharingPrivilegeUseConnection SharingPrivilege = `USE_CONNECTION` - -const SharingPrivilegeUseMarketplaceAssets SharingPrivilege = `USE_MARKETPLACE_ASSETS` - -const SharingPrivilegeUseProvider SharingPrivilege = `USE_PROVIDER` - -const SharingPrivilegeUseRecipient SharingPrivilege = `USE_RECIPIENT` - -const SharingPrivilegeUseSchema SharingPrivilege = `USE_SCHEMA` - -const SharingPrivilegeUseShare SharingPrivilege = `USE_SHARE` - -const SharingPrivilegeWriteFiles SharingPrivilege = `WRITE_FILES` - -const SharingPrivilegeWritePrivateFiles SharingPrivilege = `WRITE_PRIVATE_FILES` - -const SharingPrivilegeWriteVolume SharingPrivilege = `WRITE_VOLUME` - -// String representation for [fmt.Print] -func (f *SharingPrivilege) String() string { - return string(*f) -} - -// Set raw string value and validate it against allowed values -func (f *SharingPrivilege) Set(v string) error { - switch v { - case `ACCESS`, `ALL_PRIVILEGES`, `APPLY_TAG`, `CREATE`, `CREATE_CATALOG`, `CREATE_CONNECTION`, `CREATE_EXTERNAL_LOCATION`, `CREATE_EXTERNAL_TABLE`, `CREATE_EXTERNAL_VOLUME`, `CREATE_FOREIGN_CATALOG`, `CREATE_FOREIGN_SECURABLE`, `CREATE_FUNCTION`, `CREATE_MANAGED_STORAGE`, `CREATE_MATERIALIZED_VIEW`, `CREATE_MODEL`, `CREATE_PROVIDER`, `CREATE_RECIPIENT`, `CREATE_SCHEMA`, `CREATE_SERVICE_CREDENTIAL`, `CREATE_SHARE`, `CREATE_STORAGE_CREDENTIAL`, `CREATE_TABLE`, `CREATE_VIEW`, `CREATE_VOLUME`, `EXECUTE`, `MANAGE`, `MANAGE_ALLOWLIST`, `MODIFY`, `READ_FILES`, `READ_PRIVATE_FILES`, `READ_VOLUME`, `REFRESH`, `SELECT`, `SET_SHARE_PERMISSION`, `USAGE`, `USE_CATALOG`, `USE_CONNECTION`, `USE_MARKETPLACE_ASSETS`, `USE_PROVIDER`, `USE_RECIPIENT`, `USE_SCHEMA`, `USE_SHARE`, `WRITE_FILES`, `WRITE_PRIVATE_FILES`, `WRITE_VOLUME`: - *f = SharingPrivilege(v) - return nil - default: - return fmt.Errorf(`value "%s" is not one of "ACCESS", "ALL_PRIVILEGES", "APPLY_TAG", "CREATE", "CREATE_CATALOG", "CREATE_CONNECTION", "CREATE_EXTERNAL_LOCATION", "CREATE_EXTERNAL_TABLE", "CREATE_EXTERNAL_VOLUME", "CREATE_FOREIGN_CATALOG", "CREATE_FOREIGN_SECURABLE", "CREATE_FUNCTION", "CREATE_MANAGED_STORAGE", "CREATE_MATERIALIZED_VIEW", "CREATE_MODEL", "CREATE_PROVIDER", "CREATE_RECIPIENT", "CREATE_SCHEMA", "CREATE_SERVICE_CREDENTIAL", "CREATE_SHARE", "CREATE_STORAGE_CREDENTIAL", "CREATE_TABLE", "CREATE_VIEW", "CREATE_VOLUME", "EXECUTE", "MANAGE", "MANAGE_ALLOWLIST", "MODIFY", "READ_FILES", "READ_PRIVATE_FILES", "READ_VOLUME", "REFRESH", "SELECT", "SET_SHARE_PERMISSION", "USAGE", "USE_CATALOG", "USE_CONNECTION", "USE_MARKETPLACE_ASSETS", "USE_PROVIDER", "USE_RECIPIENT", "USE_SCHEMA", "USE_SHARE", "WRITE_FILES", "WRITE_PRIVATE_FILES", "WRITE_VOLUME"`, v) - } -} - -// Type always returns SharingPrivilege to satisfy [pflag.Value] interface -func (f *SharingPrivilege) Type() string { - return "SharingPrivilege" -} - -type SharingPrivilegeAssignment struct { - // The principal (user email address or group name). - Principal string `json:"principal,omitempty"` - // The privileges assigned to the principal. - Privileges []SharingPrivilege `json:"privileges,omitempty"` - - ForceSendFields []string `json:"-"` -} - -func (s *SharingPrivilegeAssignment) UnmarshalJSON(b []byte) error { - return marshal.Unmarshal(b, s) -} - -func (s SharingPrivilegeAssignment) MarshalJSON() ([]byte, error) { - return marshal.Marshal(s) -} - type UpdatePermissionsResponse struct { } diff --git a/sql/go.mod b/sql/go.mod index ec209f254..0c730c527 100644 --- a/sql/go.mod +++ b/sql/go.mod @@ -6,6 +6,7 @@ replace github.com/databricks/databricks-sdk-go/databricks => ../databricks require ( github.com/databricks/databricks-sdk-go/databricks v0.0.0-00010101000000-000000000000 + golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 golang.org/x/oauth2 v0.25.0 ) @@ -27,7 +28,6 @@ require ( go.opentelemetry.io/otel/metric v1.24.0 // indirect go.opentelemetry.io/otel/trace v1.24.0 // indirect golang.org/x/crypto v0.31.0 // indirect - golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.33.0 // indirect golang.org/x/sys v0.28.0 // indirect diff --git a/sql/v2/api.go b/sql/v2/api.go index 1f8a15ef2..b6cfc00bb 100755 --- a/sql/v2/api.go +++ b/sql/v2/api.go @@ -1,6 +1,6 @@ // Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. -// These APIs allow you to manage Alerts, Alerts Legacy, Dashboard Widgets, Dashboards, Data Sources, Dbsql Permissions, Queries, Queries Legacy, Query History, Query Visualizations, Query Visualizations Legacy, Statement Execution, Warehouses, etc. +// These APIs allow you to manage Alerts, Alerts Legacy, Dashboard Widgets, Dashboards, Data Sources, Dbsql Permissions, Queries, Queries Legacy, Query History, Query Visualizations, Query Visualizations Legacy, Redash Config, Statement Execution, Warehouses, etc. package sql import ( @@ -122,49 +122,6 @@ func (a *AlertsAPI) GetById(ctx context.Context, id string) (*Alert, error) { }) } -// List alerts. -// -// Gets a list of alerts accessible to the user, ordered by creation time. -// **Warning:** Calling this API concurrently 10 or more times could result in -// throttling, service degradation, or a temporary ban. -// -// This method is generated by Databricks SDK Code Generator. -func (a *AlertsAPI) List(ctx context.Context, request ListAlertsRequest) listing.Iterator[ListAlertsResponseAlert] { - - getNextPage := func(ctx context.Context, req ListAlertsRequest) (*ListAlertsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.alertsImpl.List(ctx, req) - } - getItems := func(resp *ListAlertsResponse) []ListAlertsResponseAlert { - return resp.Results - } - getNextReq := func(resp *ListAlertsResponse) *ListAlertsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List alerts. -// -// Gets a list of alerts accessible to the user, ordered by creation time. -// **Warning:** Calling this API concurrently 10 or more times could result in -// throttling, service degradation, or a temporary ban. -// -// This method is generated by Databricks SDK Code Generator. -func (a *AlertsAPI) ListAll(ctx context.Context, request ListAlertsRequest) ([]ListAlertsResponseAlert, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[ListAlertsResponseAlert](ctx, iterator) -} - // ListAlertsResponseAlertDisplayNameToIdMap calls [AlertsAPI.ListAll] and creates a map of results with [ListAlertsResponseAlert].DisplayName as key and [ListAlertsResponseAlert].Id as value. // // Returns an error if there's more than one [ListAlertsResponseAlert] with the same .DisplayName. @@ -576,59 +533,6 @@ func (a *DashboardsAPI) GetByDashboardId(ctx context.Context, dashboardId string }) } -// Get dashboard objects. -// -// Fetch a paginated list of dashboard objects. -// -// **Warning**: Calling this API concurrently 10 or more times could result in -// throttling, service degradation, or a temporary ban. -// -// This method is generated by Databricks SDK Code Generator. -func (a *DashboardsAPI) List(ctx context.Context, request ListDashboardsRequest) listing.Iterator[Dashboard] { - - request.Page = 1 // start iterating from the first page - - getNextPage := func(ctx context.Context, req ListDashboardsRequest) (*ListResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.dashboardsImpl.List(ctx, req) - } - getItems := func(resp *ListResponse) []Dashboard { - return resp.Results - } - getNextReq := func(resp *ListResponse) *ListDashboardsRequest { - if len(getItems(resp)) == 0 { - return nil - } - request.Page = resp.Page + 1 - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - dedupedIterator := listing.NewDedupeIterator[Dashboard, string]( - iterator, - func(item Dashboard) string { - return item.Id - }) - return dedupedIterator -} - -// Get dashboard objects. -// -// Fetch a paginated list of dashboard objects. -// -// **Warning**: Calling this API concurrently 10 or more times could result in -// throttling, service degradation, or a temporary ban. -// -// This method is generated by Databricks SDK Code Generator. -func (a *DashboardsAPI) ListAll(ctx context.Context, request ListDashboardsRequest) ([]Dashboard, error) { - iterator := a.List(ctx, request) - return listing.ToSliceN[Dashboard, int](ctx, iterator, request.PageSize) - -} - // DashboardNameToIdMap calls [DashboardsAPI.ListAll] and creates a map of results with [Dashboard].Name as key and [Dashboard].Id as value. // // Returns an error if there's more than one [Dashboard] with the same .Name. @@ -1020,49 +924,6 @@ func (a *QueriesAPI) GetById(ctx context.Context, id string) (*Query, error) { }) } -// List queries. -// -// Gets a list of queries accessible to the user, ordered by creation time. -// **Warning:** Calling this API concurrently 10 or more times could result in -// throttling, service degradation, or a temporary ban. -// -// This method is generated by Databricks SDK Code Generator. -func (a *QueriesAPI) List(ctx context.Context, request ListQueriesRequest) listing.Iterator[ListQueryObjectsResponseQuery] { - - getNextPage := func(ctx context.Context, req ListQueriesRequest) (*ListQueryObjectsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.queriesImpl.List(ctx, req) - } - getItems := func(resp *ListQueryObjectsResponse) []ListQueryObjectsResponseQuery { - return resp.Results - } - getNextReq := func(resp *ListQueryObjectsResponse) *ListQueriesRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List queries. -// -// Gets a list of queries accessible to the user, ordered by creation time. -// **Warning:** Calling this API concurrently 10 or more times could result in -// throttling, service degradation, or a temporary ban. -// -// This method is generated by Databricks SDK Code Generator. -func (a *QueriesAPI) ListAll(ctx context.Context, request ListQueriesRequest) ([]ListQueryObjectsResponseQuery, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[ListQueryObjectsResponseQuery](ctx, iterator) -} - // ListQueryObjectsResponseQueryDisplayNameToIdMap calls [QueriesAPI.ListAll] and creates a map of results with [ListQueryObjectsResponseQuery].DisplayName as key and [ListQueryObjectsResponseQuery].Id as value. // // Returns an error if there's more than one [ListQueryObjectsResponseQuery] with the same .DisplayName. @@ -1116,50 +977,11 @@ func (a *QueriesAPI) GetByDisplayName(ctx context.Context, name string) (*ListQu return &alternatives[0], nil } -// List visualizations on a query. -// -// Gets a list of visualizations on a query. -// -// This method is generated by Databricks SDK Code Generator. -func (a *QueriesAPI) ListVisualizations(ctx context.Context, request ListVisualizationsForQueryRequest) listing.Iterator[Visualization] { - - getNextPage := func(ctx context.Context, req ListVisualizationsForQueryRequest) (*ListVisualizationsForQueryResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.queriesImpl.ListVisualizations(ctx, req) - } - getItems := func(resp *ListVisualizationsForQueryResponse) []Visualization { - return resp.Results - } - getNextReq := func(resp *ListVisualizationsForQueryResponse) *ListVisualizationsForQueryRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List visualizations on a query. -// -// Gets a list of visualizations on a query. -// -// This method is generated by Databricks SDK Code Generator. -func (a *QueriesAPI) ListVisualizationsAll(ctx context.Context, request ListVisualizationsForQueryRequest) ([]Visualization, error) { - iterator := a.ListVisualizations(ctx, request) - return listing.ToSlice[Visualization](ctx, iterator) -} - // List visualizations on a query. // // Gets a list of visualizations on a query. func (a *QueriesAPI) ListVisualizationsById(ctx context.Context, id string) (*ListVisualizationsForQueryResponse, error) { - return a.queriesImpl.ListVisualizations(ctx, ListVisualizationsForQueryRequest{ + return a.queriesImpl.internalListVisualizations(ctx, ListVisualizationsForQueryRequest{ Id: id, }) } @@ -1356,71 +1178,6 @@ func (a *QueriesLegacyAPI) GetByQueryId(ctx context.Context, queryId string) (*L }) } -// Get a list of queries. -// -// Gets a list of queries. Optionally, this list can be filtered by a search -// term. -// -// **Warning**: Calling this API concurrently 10 or more times could result in -// throttling, service degradation, or a temporary ban. -// -// **Note**: A new version of the Databricks SQL API is now available. Please -// use :method:queries/list instead. [Learn more] -// -// This method is generated by Databricks SDK Code Generator. -// -// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html -func (a *QueriesLegacyAPI) List(ctx context.Context, request ListQueriesLegacyRequest) listing.Iterator[LegacyQuery] { - - request.Page = 1 // start iterating from the first page - - getNextPage := func(ctx context.Context, req ListQueriesLegacyRequest) (*QueryList, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.queriesLegacyImpl.List(ctx, req) - } - getItems := func(resp *QueryList) []LegacyQuery { - return resp.Results - } - getNextReq := func(resp *QueryList) *ListQueriesLegacyRequest { - if len(getItems(resp)) == 0 { - return nil - } - request.Page = resp.Page + 1 - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - dedupedIterator := listing.NewDedupeIterator[LegacyQuery, string]( - iterator, - func(item LegacyQuery) string { - return item.Id - }) - return dedupedIterator -} - -// Get a list of queries. -// -// Gets a list of queries. Optionally, this list can be filtered by a search -// term. -// -// **Warning**: Calling this API concurrently 10 or more times could result in -// throttling, service degradation, or a temporary ban. -// -// **Note**: A new version of the Databricks SQL API is now available. Please -// use :method:queries/list instead. [Learn more] -// -// This method is generated by Databricks SDK Code Generator. -// -// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html -func (a *QueriesLegacyAPI) ListAll(ctx context.Context, request ListQueriesLegacyRequest) ([]LegacyQuery, error) { - iterator := a.List(ctx, request) - return listing.ToSliceN[LegacyQuery, int](ctx, iterator, request.PageSize) - -} - // LegacyQueryNameToIdMap calls [QueriesLegacyAPI.ListAll] and creates a map of results with [LegacyQuery].Name as key and [LegacyQuery].Id as value. // // Returns an error if there's more than one [LegacyQuery] with the same .Name. @@ -1625,6 +1382,25 @@ func (a *QueryVisualizationsLegacyAPI) DeleteById(ctx context.Context, id string }) } +type RedashConfigInterface interface { + + // Read workspace configuration for Redash-v2. + GetConfig(ctx context.Context) (*ClientConfig, error) +} + +func NewRedashConfig(client *client.DatabricksClient) *RedashConfigAPI { + return &RedashConfigAPI{ + redashConfigImpl: redashConfigImpl{ + client: client, + }, + } +} + +// Redash V2 service for workspace configurations (internal) +type RedashConfigAPI struct { + redashConfigImpl +} + type StatementExecutionInterface interface { statementExecutionAPIUtilities @@ -2013,39 +1789,6 @@ func (a *WarehousesAPI) GetPermissionsByWarehouseId(ctx context.Context, warehou }) } -// List warehouses. -// -// Lists all SQL warehouses that a user has manager permissions on. -// -// This method is generated by Databricks SDK Code Generator. -func (a *WarehousesAPI) List(ctx context.Context, request ListWarehousesRequest) listing.Iterator[EndpointInfo] { - - getNextPage := func(ctx context.Context, req ListWarehousesRequest) (*ListWarehousesResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.warehousesImpl.List(ctx, req) - } - getItems := func(resp *ListWarehousesResponse) []EndpointInfo { - return resp.Warehouses - } - - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - nil) - return iterator -} - -// List warehouses. -// -// Lists all SQL warehouses that a user has manager permissions on. -// -// This method is generated by Databricks SDK Code Generator. -func (a *WarehousesAPI) ListAll(ctx context.Context, request ListWarehousesRequest) ([]EndpointInfo, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[EndpointInfo](ctx, iterator) -} - // EndpointInfoNameToIdMap calls [WarehousesAPI.ListAll] and creates a map of results with [EndpointInfo].Name as key and [EndpointInfo].Id as value. // // Returns an error if there's more than one [EndpointInfo] with the same .Name. diff --git a/sql/v2/client.go b/sql/v2/client.go index 405997a65..61cff2e15 100755 --- a/sql/v2/client.go +++ b/sql/v2/client.go @@ -384,6 +384,40 @@ func NewQueryVisualizationsLegacyClient(cfg *config.Config) (*QueryVisualization }, nil } +type RedashConfigClient struct { + RedashConfigInterface + Config *config.Config + apiClient *httpclient.ApiClient +} + +func NewRedashConfigClient(cfg *config.Config) (*RedashConfigClient, error) { + if cfg == nil { + cfg = &config.Config{} + } + + err := cfg.EnsureResolved() + if err != nil { + return nil, err + } + if cfg.IsAccountClient() { + return nil, errors.New("invalid configuration: please provide a valid workspace config for the requested workspace service client") + } + apiClient, err := cfg.NewApiClient() + if err != nil { + return nil, err + } + databricksClient, err := client.NewWithClient(cfg, apiClient) + if err != nil { + return nil, err + } + + return &RedashConfigClient{ + Config: cfg, + apiClient: apiClient, + RedashConfigInterface: NewRedashConfig(databricksClient), + }, nil +} + type StatementExecutionClient struct { StatementExecutionInterface Config *config.Config diff --git a/sql/v2/impl.go b/sql/v2/impl.go index c007a4698..db202e18e 100755 --- a/sql/v2/impl.go +++ b/sql/v2/impl.go @@ -8,6 +8,8 @@ import ( "net/http" "github.com/databricks/databricks-sdk-go/databricks/client" + "github.com/databricks/databricks-sdk-go/databricks/listing" + "github.com/databricks/databricks-sdk-go/databricks/useragent" ) // unexported type that holds implementations of just Alerts API methods @@ -18,47 +20,90 @@ type alertsImpl struct { func (a *alertsImpl) Create(ctx context.Context, request CreateAlertRequest) (*Alert, error) { var alert Alert path := "/api/2.0/sql/alerts" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &alert) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &alert) return &alert, err } func (a *alertsImpl) Delete(ctx context.Context, request TrashAlertRequest) error { var empty Empty path := fmt.Sprintf("/api/2.0/sql/alerts/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &empty) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &empty) return err } func (a *alertsImpl) Get(ctx context.Context, request GetAlertRequest) (*Alert, error) { var alert Alert path := fmt.Sprintf("/api/2.0/sql/alerts/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &alert) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &alert) return &alert, err } -func (a *alertsImpl) List(ctx context.Context, request ListAlertsRequest) (*ListAlertsResponse, error) { +// List alerts. +// +// Gets a list of alerts accessible to the user, ordered by creation time. +// **Warning:** Calling this API concurrently 10 or more times could result in +// throttling, service degradation, or a temporary ban. +func (a *alertsImpl) List(ctx context.Context, request ListAlertsRequest) listing.Iterator[ListAlertsResponseAlert] { + + getNextPage := func(ctx context.Context, req ListAlertsRequest) (*ListAlertsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListAlertsResponse) []ListAlertsResponseAlert { + return resp.Results + } + getNextReq := func(resp *ListAlertsResponse) *ListAlertsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List alerts. +// +// Gets a list of alerts accessible to the user, ordered by creation time. +// **Warning:** Calling this API concurrently 10 or more times could result in +// throttling, service degradation, or a temporary ban. +func (a *alertsImpl) ListAll(ctx context.Context, request ListAlertsRequest) ([]ListAlertsResponseAlert, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[ListAlertsResponseAlert](ctx, iterator) +} +func (a *alertsImpl) internalList(ctx context.Context, request ListAlertsRequest) (*ListAlertsResponse, error) { var listAlertsResponse ListAlertsResponse path := "/api/2.0/sql/alerts" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listAlertsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listAlertsResponse) return &listAlertsResponse, err } func (a *alertsImpl) Update(ctx context.Context, request UpdateAlertRequest) (*Alert, error) { var alert Alert path := fmt.Sprintf("/api/2.0/sql/alerts/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &alert) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &alert) return &alert, err } @@ -70,47 +115,52 @@ type alertsLegacyImpl struct { func (a *alertsLegacyImpl) Create(ctx context.Context, request CreateAlert) (*LegacyAlert, error) { var legacyAlert LegacyAlert path := "/api/2.0/preview/sql/alerts" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &legacyAlert) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &legacyAlert) return &legacyAlert, err } func (a *alertsLegacyImpl) Delete(ctx context.Context, request DeleteAlertsLegacyRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.0/preview/sql/alerts/%v", request.AlertId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *alertsLegacyImpl) Get(ctx context.Context, request GetAlertsLegacyRequest) (*LegacyAlert, error) { var legacyAlert LegacyAlert path := fmt.Sprintf("/api/2.0/preview/sql/alerts/%v", request.AlertId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &legacyAlert) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &legacyAlert) return &legacyAlert, err } func (a *alertsLegacyImpl) List(ctx context.Context) ([]LegacyAlert, error) { var legacyAlertList []LegacyAlert path := "/api/2.0/preview/sql/alerts" + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &legacyAlertList) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &legacyAlertList) return legacyAlertList, err } func (a *alertsLegacyImpl) Update(ctx context.Context, request EditAlert) error { var updateResponse UpdateResponse path := fmt.Sprintf("/api/2.0/preview/sql/alerts/%v", request.AlertId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &updateResponse) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &updateResponse) return err } @@ -122,29 +172,32 @@ type dashboardWidgetsImpl struct { func (a *dashboardWidgetsImpl) Create(ctx context.Context, request CreateWidget) (*Widget, error) { var widget Widget path := "/api/2.0/preview/sql/widgets" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &widget) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &widget) return &widget, err } func (a *dashboardWidgetsImpl) Delete(ctx context.Context, request DeleteDashboardWidgetRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.0/preview/sql/widgets/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *dashboardWidgetsImpl) Update(ctx context.Context, request CreateWidget) (*Widget, error) { var widget Widget path := fmt.Sprintf("/api/2.0/preview/sql/widgets/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &widget) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &widget) return &widget, err } @@ -156,56 +209,110 @@ type dashboardsImpl struct { func (a *dashboardsImpl) Create(ctx context.Context, request DashboardPostContent) (*Dashboard, error) { var dashboard Dashboard path := "/api/2.0/preview/sql/dashboards" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &dashboard) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &dashboard) return &dashboard, err } func (a *dashboardsImpl) Delete(ctx context.Context, request DeleteDashboardRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.0/preview/sql/dashboards/%v", request.DashboardId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *dashboardsImpl) Get(ctx context.Context, request GetDashboardRequest) (*Dashboard, error) { var dashboard Dashboard path := fmt.Sprintf("/api/2.0/preview/sql/dashboards/%v", request.DashboardId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &dashboard) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &dashboard) return &dashboard, err } -func (a *dashboardsImpl) List(ctx context.Context, request ListDashboardsRequest) (*ListResponse, error) { +// Get dashboard objects. +// +// Fetch a paginated list of dashboard objects. +// +// **Warning**: Calling this API concurrently 10 or more times could result in +// throttling, service degradation, or a temporary ban. +func (a *dashboardsImpl) List(ctx context.Context, request ListDashboardsRequest) listing.Iterator[Dashboard] { + + request.Page = 1 // start iterating from the first page + + getNextPage := func(ctx context.Context, req ListDashboardsRequest) (*ListResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListResponse) []Dashboard { + return resp.Results + } + getNextReq := func(resp *ListResponse) *ListDashboardsRequest { + if len(getItems(resp)) == 0 { + return nil + } + request.Page = resp.Page + 1 + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + dedupedIterator := listing.NewDedupeIterator[Dashboard, string]( + iterator, + func(item Dashboard) string { + return item.Id + }) + return dedupedIterator +} + +// Get dashboard objects. +// +// Fetch a paginated list of dashboard objects. +// +// **Warning**: Calling this API concurrently 10 or more times could result in +// throttling, service degradation, or a temporary ban. +func (a *dashboardsImpl) ListAll(ctx context.Context, request ListDashboardsRequest) ([]Dashboard, error) { + iterator := a.List(ctx, request) + return listing.ToSliceN[Dashboard, int](ctx, iterator, request.PageSize) + +} +func (a *dashboardsImpl) internalList(ctx context.Context, request ListDashboardsRequest) (*ListResponse, error) { var listResponse ListResponse path := "/api/2.0/preview/sql/dashboards" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listResponse) return &listResponse, err } func (a *dashboardsImpl) Restore(ctx context.Context, request RestoreDashboardRequest) error { var restoreResponse RestoreResponse path := fmt.Sprintf("/api/2.0/preview/sql/dashboards/trash/%v", request.DashboardId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, nil, &restoreResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, nil, &restoreResponse) return err } func (a *dashboardsImpl) Update(ctx context.Context, request DashboardEditContent) (*Dashboard, error) { var dashboard Dashboard path := fmt.Sprintf("/api/2.0/preview/sql/dashboards/%v", request.DashboardId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &dashboard) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &dashboard) return &dashboard, err } @@ -217,9 +324,10 @@ type dataSourcesImpl struct { func (a *dataSourcesImpl) List(ctx context.Context) ([]DataSource, error) { var dataSourceList []DataSource path := "/api/2.0/preview/sql/data_sources" + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &dataSourceList) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &dataSourceList) return dataSourceList, err } @@ -231,29 +339,32 @@ type dbsqlPermissionsImpl struct { func (a *dbsqlPermissionsImpl) Get(ctx context.Context, request GetDbsqlPermissionRequest) (*GetResponse, error) { var getResponse GetResponse path := fmt.Sprintf("/api/2.0/preview/sql/permissions/%v/%v", request.ObjectType, request.ObjectId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getResponse) return &getResponse, err } func (a *dbsqlPermissionsImpl) Set(ctx context.Context, request SetRequest) (*SetResponse, error) { var setResponse SetResponse path := fmt.Sprintf("/api/2.0/preview/sql/permissions/%v/%v", request.ObjectType, request.ObjectId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &setResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &setResponse) return &setResponse, 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) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &success) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &success) return &success, err } @@ -265,56 +376,134 @@ type queriesImpl struct { func (a *queriesImpl) Create(ctx context.Context, request CreateQueryRequest) (*Query, error) { var query Query path := "/api/2.0/sql/queries" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &query) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &query) return &query, err } func (a *queriesImpl) Delete(ctx context.Context, request TrashQueryRequest) error { var empty Empty path := fmt.Sprintf("/api/2.0/sql/queries/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &empty) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &empty) return err } func (a *queriesImpl) Get(ctx context.Context, request GetQueryRequest) (*Query, error) { var query Query path := fmt.Sprintf("/api/2.0/sql/queries/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &query) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &query) return &query, err } -func (a *queriesImpl) List(ctx context.Context, request ListQueriesRequest) (*ListQueryObjectsResponse, error) { +// List queries. +// +// Gets a list of queries accessible to the user, ordered by creation time. +// **Warning:** Calling this API concurrently 10 or more times could result in +// throttling, service degradation, or a temporary ban. +func (a *queriesImpl) List(ctx context.Context, request ListQueriesRequest) listing.Iterator[ListQueryObjectsResponseQuery] { + + getNextPage := func(ctx context.Context, req ListQueriesRequest) (*ListQueryObjectsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListQueryObjectsResponse) []ListQueryObjectsResponseQuery { + return resp.Results + } + getNextReq := func(resp *ListQueryObjectsResponse) *ListQueriesRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List queries. +// +// Gets a list of queries accessible to the user, ordered by creation time. +// **Warning:** Calling this API concurrently 10 or more times could result in +// throttling, service degradation, or a temporary ban. +func (a *queriesImpl) ListAll(ctx context.Context, request ListQueriesRequest) ([]ListQueryObjectsResponseQuery, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[ListQueryObjectsResponseQuery](ctx, iterator) +} +func (a *queriesImpl) internalList(ctx context.Context, request ListQueriesRequest) (*ListQueryObjectsResponse, error) { var listQueryObjectsResponse ListQueryObjectsResponse path := "/api/2.0/sql/queries" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listQueryObjectsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listQueryObjectsResponse) return &listQueryObjectsResponse, err } -func (a *queriesImpl) ListVisualizations(ctx context.Context, request ListVisualizationsForQueryRequest) (*ListVisualizationsForQueryResponse, error) { +// List visualizations on a query. +// +// Gets a list of visualizations on a query. +func (a *queriesImpl) ListVisualizations(ctx context.Context, request ListVisualizationsForQueryRequest) listing.Iterator[Visualization] { + + getNextPage := func(ctx context.Context, req ListVisualizationsForQueryRequest) (*ListVisualizationsForQueryResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalListVisualizations(ctx, req) + } + getItems := func(resp *ListVisualizationsForQueryResponse) []Visualization { + return resp.Results + } + getNextReq := func(resp *ListVisualizationsForQueryResponse) *ListVisualizationsForQueryRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List visualizations on a query. +// +// Gets a list of visualizations on a query. +func (a *queriesImpl) ListVisualizationsAll(ctx context.Context, request ListVisualizationsForQueryRequest) ([]Visualization, error) { + iterator := a.ListVisualizations(ctx, request) + return listing.ToSlice[Visualization](ctx, iterator) +} +func (a *queriesImpl) internalListVisualizations(ctx context.Context, request ListVisualizationsForQueryRequest) (*ListVisualizationsForQueryResponse, error) { var listVisualizationsForQueryResponse ListVisualizationsForQueryResponse path := fmt.Sprintf("/api/2.0/sql/queries/%v/visualizations", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listVisualizationsForQueryResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listVisualizationsForQueryResponse) return &listVisualizationsForQueryResponse, err } func (a *queriesImpl) Update(ctx context.Context, request UpdateQueryRequest) (*Query, error) { var query Query path := fmt.Sprintf("/api/2.0/sql/queries/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &query) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &query) return &query, err } @@ -326,56 +515,122 @@ type queriesLegacyImpl struct { func (a *queriesLegacyImpl) Create(ctx context.Context, request QueryPostContent) (*LegacyQuery, error) { var legacyQuery LegacyQuery path := "/api/2.0/preview/sql/queries" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &legacyQuery) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &legacyQuery) return &legacyQuery, err } func (a *queriesLegacyImpl) Delete(ctx context.Context, request DeleteQueriesLegacyRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.0/preview/sql/queries/%v", request.QueryId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *queriesLegacyImpl) Get(ctx context.Context, request GetQueriesLegacyRequest) (*LegacyQuery, error) { var legacyQuery LegacyQuery path := fmt.Sprintf("/api/2.0/preview/sql/queries/%v", request.QueryId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &legacyQuery) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &legacyQuery) return &legacyQuery, err } -func (a *queriesLegacyImpl) List(ctx context.Context, request ListQueriesLegacyRequest) (*QueryList, error) { +// Get a list of queries. +// +// Gets a list of queries. Optionally, this list can be filtered by a search +// term. +// +// **Warning**: Calling this API concurrently 10 or more times could result in +// throttling, service degradation, or a temporary ban. +// +// **Note**: A new version of the Databricks SQL API is now available. Please +// use :method:queries/list instead. [Learn more] +// +// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html +func (a *queriesLegacyImpl) List(ctx context.Context, request ListQueriesLegacyRequest) listing.Iterator[LegacyQuery] { + + request.Page = 1 // start iterating from the first page + + getNextPage := func(ctx context.Context, req ListQueriesLegacyRequest) (*QueryList, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *QueryList) []LegacyQuery { + return resp.Results + } + getNextReq := func(resp *QueryList) *ListQueriesLegacyRequest { + if len(getItems(resp)) == 0 { + return nil + } + request.Page = resp.Page + 1 + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + dedupedIterator := listing.NewDedupeIterator[LegacyQuery, string]( + iterator, + func(item LegacyQuery) string { + return item.Id + }) + return dedupedIterator +} + +// Get a list of queries. +// +// Gets a list of queries. Optionally, this list can be filtered by a search +// term. +// +// **Warning**: Calling this API concurrently 10 or more times could result in +// throttling, service degradation, or a temporary ban. +// +// **Note**: A new version of the Databricks SQL API is now available. Please +// use :method:queries/list instead. [Learn more] +// +// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html +func (a *queriesLegacyImpl) ListAll(ctx context.Context, request ListQueriesLegacyRequest) ([]LegacyQuery, error) { + iterator := a.List(ctx, request) + return listing.ToSliceN[LegacyQuery, int](ctx, iterator, request.PageSize) + +} +func (a *queriesLegacyImpl) internalList(ctx context.Context, request ListQueriesLegacyRequest) (*QueryList, error) { var queryList QueryList path := "/api/2.0/preview/sql/queries" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &queryList) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &queryList) return &queryList, err } func (a *queriesLegacyImpl) Restore(ctx context.Context, request RestoreQueriesLegacyRequest) error { var restoreResponse RestoreResponse path := fmt.Sprintf("/api/2.0/preview/sql/queries/trash/%v", request.QueryId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, nil, &restoreResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, nil, &restoreResponse) return err } func (a *queriesLegacyImpl) Update(ctx context.Context, request QueryEditContent) (*LegacyQuery, error) { var legacyQuery LegacyQuery path := fmt.Sprintf("/api/2.0/preview/sql/queries/%v", request.QueryId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &legacyQuery) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &legacyQuery) return &legacyQuery, err } @@ -387,9 +642,10 @@ type queryHistoryImpl struct { func (a *queryHistoryImpl) List(ctx context.Context, request ListQueryHistoryRequest) (*ListQueriesResponse, error) { var listQueriesResponse ListQueriesResponse path := "/api/2.0/sql/history/queries" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listQueriesResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listQueriesResponse) return &listQueriesResponse, err } @@ -401,29 +657,32 @@ type queryVisualizationsImpl struct { func (a *queryVisualizationsImpl) Create(ctx context.Context, request CreateVisualizationRequest) (*Visualization, error) { var visualization Visualization path := "/api/2.0/sql/visualizations" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &visualization) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &visualization) return &visualization, err } func (a *queryVisualizationsImpl) Delete(ctx context.Context, request DeleteVisualizationRequest) error { var empty Empty path := fmt.Sprintf("/api/2.0/sql/visualizations/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &empty) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &empty) return err } func (a *queryVisualizationsImpl) Update(ctx context.Context, request UpdateVisualizationRequest) (*Visualization, error) { var visualization Visualization path := fmt.Sprintf("/api/2.0/sql/visualizations/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &visualization) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &visualization) return &visualization, err } @@ -435,32 +694,50 @@ type queryVisualizationsLegacyImpl struct { func (a *queryVisualizationsLegacyImpl) Create(ctx context.Context, request CreateQueryVisualizationsLegacyRequest) (*LegacyVisualization, error) { var legacyVisualization LegacyVisualization path := "/api/2.0/preview/sql/visualizations" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &legacyVisualization) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &legacyVisualization) return &legacyVisualization, err } func (a *queryVisualizationsLegacyImpl) Delete(ctx context.Context, request DeleteQueryVisualizationsLegacyRequest) error { var deleteResponse DeleteResponse path := fmt.Sprintf("/api/2.0/preview/sql/visualizations/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteResponse) return err } func (a *queryVisualizationsLegacyImpl) Update(ctx context.Context, request LegacyVisualization) (*LegacyVisualization, error) { var legacyVisualization LegacyVisualization path := fmt.Sprintf("/api/2.0/preview/sql/visualizations/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &legacyVisualization) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &legacyVisualization) return &legacyVisualization, err } +// unexported type that holds implementations of just RedashConfig API methods +type redashConfigImpl struct { + client *client.DatabricksClient +} + +func (a *redashConfigImpl) GetConfig(ctx context.Context) (*ClientConfig, error) { + var clientConfig ClientConfig + path := "/api/2.0/redash-v2/config" + + headers := make(map[string]string) + headers["Accept"] = "application/json" + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &clientConfig) + return &clientConfig, err +} + // unexported type that holds implementations of just StatementExecution API methods type statementExecutionImpl struct { client *client.DatabricksClient @@ -469,36 +746,40 @@ type statementExecutionImpl struct { func (a *statementExecutionImpl) CancelExecution(ctx context.Context, request CancelExecutionRequest) error { var cancelExecutionResponse CancelExecutionResponse path := fmt.Sprintf("/api/2.0/sql/statements/%v/cancel", request.StatementId) + queryParams := make(map[string]any) headers := make(map[string]string) - err := a.client.Do(ctx, http.MethodPost, path, headers, nil, &cancelExecutionResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, nil, &cancelExecutionResponse) return err } func (a *statementExecutionImpl) ExecuteStatement(ctx context.Context, request ExecuteStatementRequest) (*StatementResponse, error) { var statementResponse StatementResponse path := "/api/2.0/sql/statements/" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &statementResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &statementResponse) return &statementResponse, err } func (a *statementExecutionImpl) GetStatement(ctx context.Context, request GetStatementRequest) (*StatementResponse, error) { var statementResponse StatementResponse path := fmt.Sprintf("/api/2.0/sql/statements/%v", request.StatementId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &statementResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &statementResponse) return &statementResponse, err } func (a *statementExecutionImpl) GetStatementResultChunkN(ctx context.Context, request GetStatementResultChunkNRequest) (*ResultData, error) { var resultData ResultData path := fmt.Sprintf("/api/2.0/sql/statements/%v/result/chunks/%v", request.StatementId, request.ChunkIndex) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &resultData) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &resultData) return &resultData, err } @@ -510,121 +791,162 @@ type warehousesImpl struct { func (a *warehousesImpl) Create(ctx context.Context, request CreateWarehouseRequest) (*CreateWarehouseResponse, error) { var createWarehouseResponse CreateWarehouseResponse path := "/api/2.0/sql/warehouses" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createWarehouseResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createWarehouseResponse) return &createWarehouseResponse, err } func (a *warehousesImpl) Delete(ctx context.Context, request DeleteWarehouseRequest) error { var deleteWarehouseResponse DeleteWarehouseResponse path := fmt.Sprintf("/api/2.0/sql/warehouses/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteWarehouseResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteWarehouseResponse) return err } func (a *warehousesImpl) Edit(ctx context.Context, request EditWarehouseRequest) error { var editWarehouseResponse EditWarehouseResponse path := fmt.Sprintf("/api/2.0/sql/warehouses/%v/edit", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &editWarehouseResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &editWarehouseResponse) return err } func (a *warehousesImpl) Get(ctx context.Context, request GetWarehouseRequest) (*GetWarehouseResponse, error) { var getWarehouseResponse GetWarehouseResponse path := fmt.Sprintf("/api/2.0/sql/warehouses/%v", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getWarehouseResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getWarehouseResponse) return &getWarehouseResponse, err } func (a *warehousesImpl) GetPermissionLevels(ctx context.Context, request GetWarehousePermissionLevelsRequest) (*GetWarehousePermissionLevelsResponse, error) { var getWarehousePermissionLevelsResponse GetWarehousePermissionLevelsResponse path := fmt.Sprintf("/api/2.0/permissions/warehouses/%v/permissionLevels", request.WarehouseId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getWarehousePermissionLevelsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getWarehousePermissionLevelsResponse) return &getWarehousePermissionLevelsResponse, err } func (a *warehousesImpl) GetPermissions(ctx context.Context, request GetWarehousePermissionsRequest) (*WarehousePermissions, error) { var warehousePermissions WarehousePermissions path := fmt.Sprintf("/api/2.0/permissions/warehouses/%v", request.WarehouseId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &warehousePermissions) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &warehousePermissions) return &warehousePermissions, err } func (a *warehousesImpl) GetWorkspaceWarehouseConfig(ctx context.Context) (*GetWorkspaceWarehouseConfigResponse, error) { var getWorkspaceWarehouseConfigResponse GetWorkspaceWarehouseConfigResponse path := "/api/2.0/sql/config/warehouses" + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &getWorkspaceWarehouseConfigResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &getWorkspaceWarehouseConfigResponse) return &getWorkspaceWarehouseConfigResponse, err } -func (a *warehousesImpl) List(ctx context.Context, request ListWarehousesRequest) (*ListWarehousesResponse, error) { +// List warehouses. +// +// Lists all SQL warehouses that a user has manager permissions on. +func (a *warehousesImpl) List(ctx context.Context, request ListWarehousesRequest) listing.Iterator[EndpointInfo] { + + getNextPage := func(ctx context.Context, req ListWarehousesRequest) (*ListWarehousesResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListWarehousesResponse) []EndpointInfo { + return resp.Warehouses + } + + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + nil) + return iterator +} + +// List warehouses. +// +// Lists all SQL warehouses that a user has manager permissions on. +func (a *warehousesImpl) ListAll(ctx context.Context, request ListWarehousesRequest) ([]EndpointInfo, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[EndpointInfo](ctx, iterator) +} +func (a *warehousesImpl) internalList(ctx context.Context, request ListWarehousesRequest) (*ListWarehousesResponse, error) { var listWarehousesResponse ListWarehousesResponse path := "/api/2.0/sql/warehouses" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listWarehousesResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listWarehousesResponse) return &listWarehousesResponse, err } func (a *warehousesImpl) SetPermissions(ctx context.Context, request WarehousePermissionsRequest) (*WarehousePermissions, error) { var warehousePermissions WarehousePermissions path := fmt.Sprintf("/api/2.0/permissions/warehouses/%v", request.WarehouseId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &warehousePermissions) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &warehousePermissions) return &warehousePermissions, err } func (a *warehousesImpl) SetWorkspaceWarehouseConfig(ctx context.Context, request SetWorkspaceWarehouseConfigRequest) error { var setWorkspaceWarehouseConfigResponse SetWorkspaceWarehouseConfigResponse path := "/api/2.0/sql/config/warehouses" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &setWorkspaceWarehouseConfigResponse) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &setWorkspaceWarehouseConfigResponse) return err } func (a *warehousesImpl) Start(ctx context.Context, request StartRequest) error { var startWarehouseResponse StartWarehouseResponse path := fmt.Sprintf("/api/2.0/sql/warehouses/%v/start", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, nil, &startWarehouseResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, nil, &startWarehouseResponse) return err } func (a *warehousesImpl) Stop(ctx context.Context, request StopRequest) error { var stopWarehouseResponse StopWarehouseResponse path := fmt.Sprintf("/api/2.0/sql/warehouses/%v/stop", request.Id) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, nil, &stopWarehouseResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, nil, &stopWarehouseResponse) return err } func (a *warehousesImpl) UpdatePermissions(ctx context.Context, request WarehousePermissionsRequest) (*WarehousePermissions, error) { var warehousePermissions WarehousePermissions path := fmt.Sprintf("/api/2.0/permissions/warehouses/%v", request.WarehouseId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &warehousePermissions) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &warehousePermissions) return &warehousePermissions, err } diff --git a/sql/v2/model.go b/sql/v2/model.go index c0e287e78..348f92b6a 100755 --- a/sql/v2/model.go +++ b/sql/v2/model.go @@ -423,6 +423,38 @@ func (f *ChannelName) Type() string { return "ChannelName" } +type ClientConfig struct { + AllowCustomJsVisualizations bool `json:"allow_custom_js_visualizations,omitempty"` + + AllowDownloads bool `json:"allow_downloads,omitempty"` + + AllowExternalShares bool `json:"allow_external_shares,omitempty"` + + AllowSubscriptions bool `json:"allow_subscriptions,omitempty"` + + DateFormat string `json:"date_format,omitempty"` + + DateTimeFormat string `json:"date_time_format,omitempty"` + + DisablePublish bool `json:"disable_publish,omitempty"` + + EnableLegacyAutodetectTypes bool `json:"enable_legacy_autodetect_types,omitempty"` + + FeatureShowPermissionsControl bool `json:"feature_show_permissions_control,omitempty"` + + HidePlotlyModeBar bool `json:"hide_plotly_mode_bar,omitempty"` + + ForceSendFields []string `json:"-"` +} + +func (s *ClientConfig) UnmarshalJSON(b []byte) error { + return marshal.Unmarshal(b, s) +} + +func (s ClientConfig) MarshalJSON() ([]byte, error) { + return marshal.Marshal(s) +} + type ColumnInfo struct { // The name of the column. Name string `json:"name,omitempty"` @@ -4323,10 +4355,17 @@ type UpdateAlertRequest struct { Alert *UpdateAlertRequestAlert `json:"alert,omitempty"` Id string `json:"-" url:"-"` - // Field mask is required to be passed into the PATCH request. Field mask - // specifies which fields of the setting payload will be updated. The field - // mask needs to be supplied as single string. To specify multiple fields in - // the field mask, use comma as the separator (no space). + // The field mask must be a single string, with multiple fields separated by + // commas (no spaces). The field path is relative to the resource object, + // using a dot (`.`) to navigate sub-fields (e.g., `author.given_name`). + // Specification of elements in sequence or map fields is not allowed, as + // only the entire collection field can be specified. Field names must + // exactly match the resource field names. + // + // A field mask of `*` indicates full replacement. It’s recommended to + // always explicitly list the fields being updated and avoid using `*` + // wildcards, as it can lead to unintended results if the API changes in the + // future. UpdateMask string `json:"update_mask"` } @@ -4373,10 +4412,17 @@ type UpdateQueryRequest struct { Id string `json:"-" url:"-"` Query *UpdateQueryRequestQuery `json:"query,omitempty"` - // Field mask is required to be passed into the PATCH request. Field mask - // specifies which fields of the setting payload will be updated. The field - // mask needs to be supplied as single string. To specify multiple fields in - // the field mask, use comma as the separator (no space). + // The field mask must be a single string, with multiple fields separated by + // commas (no spaces). The field path is relative to the resource object, + // using a dot (`.`) to navigate sub-fields (e.g., `author.given_name`). + // Specification of elements in sequence or map fields is not allowed, as + // only the entire collection field can be specified. Field names must + // exactly match the resource field names. + // + // A field mask of `*` indicates full replacement. It’s recommended to + // always explicitly list the fields being updated and avoid using `*` + // wildcards, as it can lead to unintended results if the API changes in the + // future. UpdateMask string `json:"update_mask"` } @@ -4422,10 +4468,17 @@ type UpdateResponse struct { type UpdateVisualizationRequest struct { Id string `json:"-" url:"-"` - // Field mask is required to be passed into the PATCH request. Field mask - // specifies which fields of the setting payload will be updated. The field - // mask needs to be supplied as single string. To specify multiple fields in - // the field mask, use comma as the separator (no space). + // The field mask must be a single string, with multiple fields separated by + // commas (no spaces). The field path is relative to the resource object, + // using a dot (`.`) to navigate sub-fields (e.g., `author.given_name`). + // Specification of elements in sequence or map fields is not allowed, as + // only the entire collection field can be specified. Field names must + // exactly match the resource field names. + // + // A field mask of `*` indicates full replacement. It’s recommended to + // always explicitly list the fields being updated and avoid using `*` + // wildcards, as it can lead to unintended results if the API changes in the + // future. UpdateMask string `json:"update_mask"` Visualization *UpdateVisualizationRequestVisualization `json:"visualization,omitempty"` diff --git a/vectorsearch/go.mod b/vectorsearch/go.mod index 0d7f0ad0e..1de741dd4 100644 --- a/vectorsearch/go.mod +++ b/vectorsearch/go.mod @@ -6,6 +6,7 @@ replace github.com/databricks/databricks-sdk-go/databricks => ../databricks require ( github.com/databricks/databricks-sdk-go/databricks v0.0.0-00010101000000-000000000000 + golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 golang.org/x/oauth2 v0.25.0 ) @@ -27,7 +28,6 @@ require ( go.opentelemetry.io/otel/metric v1.24.0 // indirect go.opentelemetry.io/otel/trace v1.24.0 // indirect golang.org/x/crypto v0.31.0 // indirect - golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.33.0 // indirect golang.org/x/sys v0.28.0 // indirect diff --git a/vectorsearch/v2/api.go b/vectorsearch/v2/api.go index 35feb2ccc..137e94664 100755 --- a/vectorsearch/v2/api.go +++ b/vectorsearch/v2/api.go @@ -8,7 +8,6 @@ import ( "github.com/databricks/databricks-sdk-go/databricks/client" "github.com/databricks/databricks-sdk-go/databricks/listing" - "github.com/databricks/databricks-sdk-go/databricks/useragent" ) type VectorSearchEndpointsInterface interface { @@ -68,41 +67,6 @@ func (a *VectorSearchEndpointsAPI) GetEndpointByEndpointName(ctx context.Context }) } -// List all endpoints. -// -// This method is generated by Databricks SDK Code Generator. -func (a *VectorSearchEndpointsAPI) ListEndpoints(ctx context.Context, request ListEndpointsRequest) listing.Iterator[EndpointInfo] { - - getNextPage := func(ctx context.Context, req ListEndpointsRequest) (*ListEndpointResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.vectorSearchEndpointsImpl.ListEndpoints(ctx, req) - } - getItems := func(resp *ListEndpointResponse) []EndpointInfo { - return resp.Endpoints - } - getNextReq := func(resp *ListEndpointResponse) *ListEndpointsRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List all endpoints. -// -// This method is generated by Databricks SDK Code Generator. -func (a *VectorSearchEndpointsAPI) ListEndpointsAll(ctx context.Context, request ListEndpointsRequest) ([]EndpointInfo, error) { - iterator := a.ListEndpoints(ctx, request) - return listing.ToSlice[EndpointInfo](ctx, iterator) -} - type VectorSearchIndexesInterface interface { // Create an index. @@ -216,42 +180,3 @@ func (a *VectorSearchIndexesAPI) GetIndexByIndexName(ctx context.Context, indexN IndexName: indexName, }) } - -// List indexes. -// -// List all indexes in the given endpoint. -// -// This method is generated by Databricks SDK Code Generator. -func (a *VectorSearchIndexesAPI) ListIndexes(ctx context.Context, request ListIndexesRequest) listing.Iterator[MiniVectorIndex] { - - getNextPage := func(ctx context.Context, req ListIndexesRequest) (*ListVectorIndexesResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.vectorSearchIndexesImpl.ListIndexes(ctx, req) - } - getItems := func(resp *ListVectorIndexesResponse) []MiniVectorIndex { - return resp.VectorIndexes - } - getNextReq := func(resp *ListVectorIndexesResponse) *ListIndexesRequest { - if resp.NextPageToken == "" { - return nil - } - request.PageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// List indexes. -// -// List all indexes in the given endpoint. -// -// This method is generated by Databricks SDK Code Generator. -func (a *VectorSearchIndexesAPI) ListIndexesAll(ctx context.Context, request ListIndexesRequest) ([]MiniVectorIndex, error) { - iterator := a.ListIndexes(ctx, request) - return listing.ToSlice[MiniVectorIndex](ctx, iterator) -} diff --git a/vectorsearch/v2/impl.go b/vectorsearch/v2/impl.go index 321b8b8bf..4a9ffa6e3 100755 --- a/vectorsearch/v2/impl.go +++ b/vectorsearch/v2/impl.go @@ -8,6 +8,8 @@ import ( "net/http" "github.com/databricks/databricks-sdk-go/databricks/client" + "github.com/databricks/databricks-sdk-go/databricks/listing" + "github.com/databricks/databricks-sdk-go/databricks/useragent" ) // unexported type that holds implementations of just VectorSearchEndpoints API methods @@ -18,36 +20,70 @@ type vectorSearchEndpointsImpl struct { func (a *vectorSearchEndpointsImpl) CreateEndpoint(ctx context.Context, request CreateEndpoint) (*EndpointInfo, error) { var endpointInfo EndpointInfo path := "/api/2.0/vector-search/endpoints" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &endpointInfo) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &endpointInfo) return &endpointInfo, err } func (a *vectorSearchEndpointsImpl) DeleteEndpoint(ctx context.Context, request DeleteEndpointRequest) error { var deleteEndpointResponse DeleteEndpointResponse path := fmt.Sprintf("/api/2.0/vector-search/endpoints/%v", request.EndpointName) + queryParams := make(map[string]any) headers := make(map[string]string) - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteEndpointResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteEndpointResponse) return err } func (a *vectorSearchEndpointsImpl) GetEndpoint(ctx context.Context, request GetEndpointRequest) (*EndpointInfo, error) { var endpointInfo EndpointInfo path := fmt.Sprintf("/api/2.0/vector-search/endpoints/%v", request.EndpointName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &endpointInfo) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &endpointInfo) return &endpointInfo, err } -func (a *vectorSearchEndpointsImpl) ListEndpoints(ctx context.Context, request ListEndpointsRequest) (*ListEndpointResponse, error) { +// List all endpoints. +func (a *vectorSearchEndpointsImpl) ListEndpoints(ctx context.Context, request ListEndpointsRequest) listing.Iterator[EndpointInfo] { + + getNextPage := func(ctx context.Context, req ListEndpointsRequest) (*ListEndpointResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalListEndpoints(ctx, req) + } + getItems := func(resp *ListEndpointResponse) []EndpointInfo { + return resp.Endpoints + } + getNextReq := func(resp *ListEndpointResponse) *ListEndpointsRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List all endpoints. +func (a *vectorSearchEndpointsImpl) ListEndpointsAll(ctx context.Context, request ListEndpointsRequest) ([]EndpointInfo, error) { + iterator := a.ListEndpoints(ctx, request) + return listing.ToSlice[EndpointInfo](ctx, iterator) +} +func (a *vectorSearchEndpointsImpl) internalListEndpoints(ctx context.Context, request ListEndpointsRequest) (*ListEndpointResponse, error) { var listEndpointResponse ListEndpointResponse path := "/api/2.0/vector-search/endpoints" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listEndpointResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listEndpointResponse) return &listEndpointResponse, err } @@ -59,93 +95,137 @@ type vectorSearchIndexesImpl struct { func (a *vectorSearchIndexesImpl) CreateIndex(ctx context.Context, request CreateVectorIndexRequest) (*CreateVectorIndexResponse, error) { var createVectorIndexResponse CreateVectorIndexResponse path := "/api/2.0/vector-search/indexes" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createVectorIndexResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createVectorIndexResponse) return &createVectorIndexResponse, err } func (a *vectorSearchIndexesImpl) DeleteDataVectorIndex(ctx context.Context, request DeleteDataVectorIndexRequest) (*DeleteDataVectorIndexResponse, error) { var deleteDataVectorIndexResponse DeleteDataVectorIndexResponse path := fmt.Sprintf("/api/2.0/vector-search/indexes/%v/delete-data", request.IndexName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &deleteDataVectorIndexResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &deleteDataVectorIndexResponse) return &deleteDataVectorIndexResponse, err } func (a *vectorSearchIndexesImpl) DeleteIndex(ctx context.Context, request DeleteIndexRequest) error { var deleteIndexResponse DeleteIndexResponse path := fmt.Sprintf("/api/2.0/vector-search/indexes/%v", request.IndexName) + queryParams := make(map[string]any) headers := make(map[string]string) - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteIndexResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteIndexResponse) return err } func (a *vectorSearchIndexesImpl) GetIndex(ctx context.Context, request GetIndexRequest) (*VectorIndex, error) { var vectorIndex VectorIndex path := fmt.Sprintf("/api/2.0/vector-search/indexes/%v", request.IndexName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &vectorIndex) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &vectorIndex) return &vectorIndex, err } -func (a *vectorSearchIndexesImpl) ListIndexes(ctx context.Context, request ListIndexesRequest) (*ListVectorIndexesResponse, error) { +// List indexes. +// +// List all indexes in the given endpoint. +func (a *vectorSearchIndexesImpl) ListIndexes(ctx context.Context, request ListIndexesRequest) listing.Iterator[MiniVectorIndex] { + + getNextPage := func(ctx context.Context, req ListIndexesRequest) (*ListVectorIndexesResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalListIndexes(ctx, req) + } + getItems := func(resp *ListVectorIndexesResponse) []MiniVectorIndex { + return resp.VectorIndexes + } + getNextReq := func(resp *ListVectorIndexesResponse) *ListIndexesRequest { + if resp.NextPageToken == "" { + return nil + } + request.PageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// List indexes. +// +// List all indexes in the given endpoint. +func (a *vectorSearchIndexesImpl) ListIndexesAll(ctx context.Context, request ListIndexesRequest) ([]MiniVectorIndex, error) { + iterator := a.ListIndexes(ctx, request) + return listing.ToSlice[MiniVectorIndex](ctx, iterator) +} +func (a *vectorSearchIndexesImpl) internalListIndexes(ctx context.Context, request ListIndexesRequest) (*ListVectorIndexesResponse, error) { var listVectorIndexesResponse ListVectorIndexesResponse path := "/api/2.0/vector-search/indexes" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listVectorIndexesResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listVectorIndexesResponse) return &listVectorIndexesResponse, err } func (a *vectorSearchIndexesImpl) QueryIndex(ctx context.Context, request QueryVectorIndexRequest) (*QueryVectorIndexResponse, error) { var queryVectorIndexResponse QueryVectorIndexResponse path := fmt.Sprintf("/api/2.0/vector-search/indexes/%v/query", request.IndexName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &queryVectorIndexResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &queryVectorIndexResponse) return &queryVectorIndexResponse, err } func (a *vectorSearchIndexesImpl) QueryNextPage(ctx context.Context, request QueryVectorIndexNextPageRequest) (*QueryVectorIndexResponse, error) { var queryVectorIndexResponse QueryVectorIndexResponse path := fmt.Sprintf("/api/2.0/vector-search/indexes/%v/query-next-page", request.IndexName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &queryVectorIndexResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &queryVectorIndexResponse) return &queryVectorIndexResponse, err } func (a *vectorSearchIndexesImpl) ScanIndex(ctx context.Context, request ScanVectorIndexRequest) (*ScanVectorIndexResponse, error) { var scanVectorIndexResponse ScanVectorIndexResponse path := fmt.Sprintf("/api/2.0/vector-search/indexes/%v/scan", request.IndexName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &scanVectorIndexResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &scanVectorIndexResponse) return &scanVectorIndexResponse, err } func (a *vectorSearchIndexesImpl) SyncIndex(ctx context.Context, request SyncIndexRequest) error { var syncIndexResponse SyncIndexResponse path := fmt.Sprintf("/api/2.0/vector-search/indexes/%v/sync", request.IndexName) + queryParams := make(map[string]any) headers := make(map[string]string) - err := a.client.Do(ctx, http.MethodPost, path, headers, nil, &syncIndexResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, nil, &syncIndexResponse) return err } func (a *vectorSearchIndexesImpl) UpsertDataVectorIndex(ctx context.Context, request UpsertDataVectorIndexRequest) (*UpsertDataVectorIndexResponse, error) { var upsertDataVectorIndexResponse UpsertDataVectorIndexResponse path := fmt.Sprintf("/api/2.0/vector-search/indexes/%v/upsert-data", request.IndexName) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &upsertDataVectorIndexResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &upsertDataVectorIndexResponse) return &upsertDataVectorIndexResponse, err } diff --git a/workspace/go.mod b/workspace/go.mod index c7a16b848..88cd2e61f 100644 --- a/workspace/go.mod +++ b/workspace/go.mod @@ -6,6 +6,7 @@ replace github.com/databricks/databricks-sdk-go/databricks => ../databricks require ( github.com/databricks/databricks-sdk-go/databricks v0.0.0-00010101000000-000000000000 + golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 golang.org/x/oauth2 v0.25.0 ) @@ -27,7 +28,6 @@ require ( go.opentelemetry.io/otel/metric v1.24.0 // indirect go.opentelemetry.io/otel/trace v1.24.0 // indirect golang.org/x/crypto v0.31.0 // indirect - golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.33.0 // indirect golang.org/x/sys v0.28.0 // indirect diff --git a/workspace/v2/api.go b/workspace/v2/api.go index 9d25695ea..43ef00cb2 100755 --- a/workspace/v2/api.go +++ b/workspace/v2/api.go @@ -118,42 +118,6 @@ func (a *GitCredentialsAPI) GetByCredentialId(ctx context.Context, credentialId }) } -// Get Git credentials. -// -// Lists the calling user's Git credentials. One credential per user is -// supported. -// -// This method is generated by Databricks SDK Code Generator. -func (a *GitCredentialsAPI) List(ctx context.Context) listing.Iterator[CredentialInfo] { - request := struct{}{} - - getNextPage := func(ctx context.Context, req struct{}) (*ListCredentialsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.gitCredentialsImpl.List(ctx) - } - getItems := func(resp *ListCredentialsResponse) []CredentialInfo { - return resp.Credentials - } - - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - nil) - return iterator -} - -// Get Git credentials. -// -// Lists the calling user's Git credentials. One credential per user is -// supported. -// -// This method is generated by Databricks SDK Code Generator. -func (a *GitCredentialsAPI) ListAll(ctx context.Context) ([]CredentialInfo, error) { - iterator := a.List(ctx) - return listing.ToSlice[CredentialInfo](ctx, iterator) -} - // CredentialInfoGitProviderToCredentialIdMap calls [GitCredentialsAPI.ListAll] and creates a map of results with [CredentialInfo].GitProvider as key and [CredentialInfo].CredentialId as value. // // Returns an error if there's more than one [CredentialInfo] with the same .GitProvider. @@ -371,47 +335,6 @@ func (a *ReposAPI) GetPermissionsByRepoId(ctx context.Context, repoId string) (* }) } -// Get repos. -// -// Returns repos that the calling user has Manage permissions on. Use -// `next_page_token` to iterate through additional pages. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ReposAPI) List(ctx context.Context, request ListReposRequest) listing.Iterator[RepoInfo] { - - getNextPage := func(ctx context.Context, req ListReposRequest) (*ListReposResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.reposImpl.List(ctx, req) - } - getItems := func(resp *ListReposResponse) []RepoInfo { - return resp.Repos - } - getNextReq := func(resp *ListReposResponse) *ListReposRequest { - if resp.NextPageToken == "" { - return nil - } - request.NextPageToken = resp.NextPageToken - return &request - } - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - getNextReq) - return iterator -} - -// Get repos. -// -// Returns repos that the calling user has Manage permissions on. Use -// `next_page_token` to iterate through additional pages. -// -// This method is generated by Databricks SDK Code Generator. -func (a *ReposAPI) ListAll(ctx context.Context, request ListReposRequest) ([]RepoInfo, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[RepoInfo](ctx, iterator) -} - // RepoInfoPathToIdMap calls [ReposAPI.ListAll] and creates a map of results with [RepoInfo].Path as key and [RepoInfo].Id as value. // // Returns an error if there's more than one [RepoInfo] with the same .Path. @@ -722,49 +645,6 @@ func (a *SecretsAPI) DeleteScopeByScope(ctx context.Context, scope string) error }) } -// Lists ACLs. -// -// List the ACLs for a given secret scope. Users must have the `MANAGE` -// permission to invoke this API. -// -// Throws `RESOURCE_DOES_NOT_EXIST` if no such secret scope exists. Throws -// `PERMISSION_DENIED` if the user does not have permission to make this API -// call. -// -// This method is generated by Databricks SDK Code Generator. -func (a *SecretsAPI) ListAcls(ctx context.Context, request ListAclsRequest) listing.Iterator[AclItem] { - - getNextPage := func(ctx context.Context, req ListAclsRequest) (*ListAclsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.secretsImpl.ListAcls(ctx, req) - } - getItems := func(resp *ListAclsResponse) []AclItem { - return resp.Items - } - - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - nil) - return iterator -} - -// Lists ACLs. -// -// List the ACLs for a given secret scope. Users must have the `MANAGE` -// permission to invoke this API. -// -// Throws `RESOURCE_DOES_NOT_EXIST` if no such secret scope exists. Throws -// `PERMISSION_DENIED` if the user does not have permission to make this API -// call. -// -// This method is generated by Databricks SDK Code Generator. -func (a *SecretsAPI) ListAclsAll(ctx context.Context, request ListAclsRequest) ([]AclItem, error) { - iterator := a.ListAcls(ctx, request) - return listing.ToSlice[AclItem](ctx, iterator) -} - // Lists ACLs. // // List the ACLs for a given secret scope. Users must have the `MANAGE` @@ -774,98 +654,11 @@ 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.secretsImpl.ListAcls(ctx, ListAclsRequest{ + return a.secretsImpl.internalListAcls(ctx, ListAclsRequest{ Scope: scope, }) } -// List all scopes. -// -// Lists all secret scopes available in the workspace. -// -// Throws `PERMISSION_DENIED` if the user does not have permission to make this -// API call. -// -// This method is generated by Databricks SDK Code Generator. -func (a *SecretsAPI) ListScopes(ctx context.Context) listing.Iterator[SecretScope] { - request := struct{}{} - - getNextPage := func(ctx context.Context, req struct{}) (*ListScopesResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.secretsImpl.ListScopes(ctx) - } - getItems := func(resp *ListScopesResponse) []SecretScope { - return resp.Scopes - } - - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - nil) - return iterator -} - -// List all scopes. -// -// Lists all secret scopes available in the workspace. -// -// Throws `PERMISSION_DENIED` if the user does not have permission to make this -// API call. -// -// This method is generated by Databricks SDK Code Generator. -func (a *SecretsAPI) ListScopesAll(ctx context.Context) ([]SecretScope, error) { - iterator := a.ListScopes(ctx) - return listing.ToSlice[SecretScope](ctx, iterator) -} - -// List secret keys. -// -// Lists the secret keys that are stored at this scope. This is a metadata-only -// operation; secret data cannot be retrieved using this API. Users need the -// READ permission to make this call. -// -// The lastUpdatedTimestamp returned is in milliseconds since epoch. Throws -// `RESOURCE_DOES_NOT_EXIST` if no such secret scope exists. Throws -// `PERMISSION_DENIED` if the user does not have permission to make this API -// call. -// -// This method is generated by Databricks SDK Code Generator. -func (a *SecretsAPI) ListSecrets(ctx context.Context, request ListSecretsRequest) listing.Iterator[SecretMetadata] { - - getNextPage := func(ctx context.Context, req ListSecretsRequest) (*ListSecretsResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.secretsImpl.ListSecrets(ctx, req) - } - getItems := func(resp *ListSecretsResponse) []SecretMetadata { - return resp.Secrets - } - - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - nil) - return iterator -} - -// List secret keys. -// -// Lists the secret keys that are stored at this scope. This is a metadata-only -// operation; secret data cannot be retrieved using this API. Users need the -// READ permission to make this call. -// -// The lastUpdatedTimestamp returned is in milliseconds since epoch. Throws -// `RESOURCE_DOES_NOT_EXIST` if no such secret scope exists. Throws -// `PERMISSION_DENIED` if the user does not have permission to make this API -// call. -// -// This method is generated by Databricks SDK Code Generator. -func (a *SecretsAPI) ListSecretsAll(ctx context.Context, request ListSecretsRequest) ([]SecretMetadata, error) { - iterator := a.ListSecrets(ctx, request) - return listing.ToSlice[SecretMetadata](ctx, iterator) -} - // List secret keys. // // Lists the secret keys that are stored at this scope. This is a metadata-only @@ -877,7 +670,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.secretsImpl.ListSecrets(ctx, ListSecretsRequest{ + return a.secretsImpl.internalListSecrets(ctx, ListSecretsRequest{ Scope: scope, }) } @@ -1071,43 +864,6 @@ func (a *WorkspaceAPI) GetStatusByPath(ctx context.Context, path string) (*Objec }) } -// List contents. -// -// Lists the contents of a directory, or the object if it is not a directory. If -// the input path does not exist, this call returns an error -// `RESOURCE_DOES_NOT_EXIST`. -// -// This method is generated by Databricks SDK Code Generator. -func (a *WorkspaceAPI) List(ctx context.Context, request ListWorkspaceRequest) listing.Iterator[ObjectInfo] { - - getNextPage := func(ctx context.Context, req ListWorkspaceRequest) (*ListResponse, error) { - ctx = useragent.InContext(ctx, "sdk-feature", "pagination") - return a.workspaceImpl.List(ctx, req) - } - getItems := func(resp *ListResponse) []ObjectInfo { - return resp.Objects - } - - iterator := listing.NewIterator( - &request, - getNextPage, - getItems, - nil) - return iterator -} - -// List contents. -// -// Lists the contents of a directory, or the object if it is not a directory. If -// the input path does not exist, this call returns an error -// `RESOURCE_DOES_NOT_EXIST`. -// -// This method is generated by Databricks SDK Code Generator. -func (a *WorkspaceAPI) ListAll(ctx context.Context, request ListWorkspaceRequest) ([]ObjectInfo, error) { - iterator := a.List(ctx, request) - return listing.ToSlice[ObjectInfo](ctx, iterator) -} - // ObjectInfoPathToObjectIdMap calls [WorkspaceAPI.ListAll] and creates a map of results with [ObjectInfo].Path as key and [ObjectInfo].ObjectId as value. // // Returns an error if there's more than one [ObjectInfo] with the same .Path. diff --git a/workspace/v2/ext_utilities.go b/workspace/v2/ext_utilities.go index 6166ea78d..ecea36227 100644 --- a/workspace/v2/ext_utilities.go +++ b/workspace/v2/ext_utilities.go @@ -238,7 +238,7 @@ func (a *WorkspaceAPI) Upload(ctx context.Context, path string, r io.Reader, opt headers := map[string]string{ "Content-Type": w.FormDataContentType(), } - return a.workspaceImpl.client.Do(ctx, "POST", "/api/2.0/workspace/import", headers, buf.Bytes(), nil) + return a.workspaceImpl.client.Do(ctx, "POST", "/api/2.0/workspace/import", headers, nil, buf.Bytes(), nil) } // WriteFile is identical to [os.WriteFile] but for Workspace File. @@ -272,7 +272,7 @@ func (a *WorkspaceAPI) Download(ctx context.Context, path string, opts ...Downlo v(query) } headers := map[string]string{"Content-Type": "application/json"} - err := a.workspaceImpl.client.Do(ctx, "GET", "/api/2.0/workspace/export", headers, query, &buf) + err := a.workspaceImpl.client.Do(ctx, "GET", "/api/2.0/workspace/export", headers, nil, query, &buf) if err != nil { return nil, err } diff --git a/workspace/v2/impl.go b/workspace/v2/impl.go index d85728448..c556208bf 100755 --- a/workspace/v2/impl.go +++ b/workspace/v2/impl.go @@ -8,6 +8,8 @@ import ( "net/http" "github.com/databricks/databricks-sdk-go/databricks/client" + "github.com/databricks/databricks-sdk-go/databricks/listing" + "github.com/databricks/databricks-sdk-go/databricks/useragent" ) // unexported type that holds implementations of just GitCredentials API methods @@ -18,47 +20,83 @@ type gitCredentialsImpl struct { func (a *gitCredentialsImpl) Create(ctx context.Context, request CreateCredentialsRequest) (*CreateCredentialsResponse, error) { var createCredentialsResponse CreateCredentialsResponse path := "/api/2.0/git-credentials" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createCredentialsResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createCredentialsResponse) return &createCredentialsResponse, err } func (a *gitCredentialsImpl) Delete(ctx context.Context, request DeleteCredentialsRequest) error { var deleteCredentialsResponse DeleteCredentialsResponse path := fmt.Sprintf("/api/2.0/git-credentials/%v", request.CredentialId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteCredentialsResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteCredentialsResponse) return err } func (a *gitCredentialsImpl) Get(ctx context.Context, request GetCredentialsRequest) (*GetCredentialsResponse, error) { var getCredentialsResponse GetCredentialsResponse path := fmt.Sprintf("/api/2.0/git-credentials/%v", request.CredentialId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getCredentialsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getCredentialsResponse) return &getCredentialsResponse, err } -func (a *gitCredentialsImpl) List(ctx context.Context) (*ListCredentialsResponse, error) { +// Get Git credentials. +// +// Lists the calling user's Git credentials. One credential per user is +// supported. +func (a *gitCredentialsImpl) List(ctx context.Context) listing.Iterator[CredentialInfo] { + request := struct{}{} + + getNextPage := func(ctx context.Context, req struct{}) (*ListCredentialsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx) + } + getItems := func(resp *ListCredentialsResponse) []CredentialInfo { + return resp.Credentials + } + + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + nil) + return iterator +} + +// Get Git credentials. +// +// Lists the calling user's Git credentials. One credential per user is +// supported. +func (a *gitCredentialsImpl) ListAll(ctx context.Context) ([]CredentialInfo, error) { + iterator := a.List(ctx) + return listing.ToSlice[CredentialInfo](ctx, iterator) +} +func (a *gitCredentialsImpl) internalList(ctx context.Context) (*ListCredentialsResponse, error) { var listCredentialsResponse ListCredentialsResponse path := "/api/2.0/git-credentials" + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &listCredentialsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &listCredentialsResponse) return &listCredentialsResponse, err } func (a *gitCredentialsImpl) Update(ctx context.Context, request UpdateCredentialsRequest) error { var updateCredentialsResponse UpdateCredentialsResponse path := fmt.Sprintf("/api/2.0/git-credentials/%v", request.CredentialId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &updateCredentialsResponse) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &updateCredentialsResponse) return err } @@ -70,85 +108,130 @@ type reposImpl struct { func (a *reposImpl) Create(ctx context.Context, request CreateRepoRequest) (*CreateRepoResponse, error) { var createRepoResponse CreateRepoResponse path := "/api/2.0/repos" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createRepoResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createRepoResponse) return &createRepoResponse, err } func (a *reposImpl) Delete(ctx context.Context, request DeleteRepoRequest) error { var deleteRepoResponse DeleteRepoResponse path := fmt.Sprintf("/api/2.0/repos/%v", request.RepoId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodDelete, path, headers, request, &deleteRepoResponse) + err := a.client.Do(ctx, http.MethodDelete, path, headers, queryParams, request, &deleteRepoResponse) return err } func (a *reposImpl) Get(ctx context.Context, request GetRepoRequest) (*GetRepoResponse, error) { var getRepoResponse GetRepoResponse path := fmt.Sprintf("/api/2.0/repos/%v", request.RepoId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getRepoResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getRepoResponse) return &getRepoResponse, err } func (a *reposImpl) GetPermissionLevels(ctx context.Context, request GetRepoPermissionLevelsRequest) (*GetRepoPermissionLevelsResponse, error) { var getRepoPermissionLevelsResponse GetRepoPermissionLevelsResponse path := fmt.Sprintf("/api/2.0/permissions/repos/%v/permissionLevels", request.RepoId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getRepoPermissionLevelsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getRepoPermissionLevelsResponse) return &getRepoPermissionLevelsResponse, err } func (a *reposImpl) GetPermissions(ctx context.Context, request GetRepoPermissionsRequest) (*RepoPermissions, error) { var repoPermissions RepoPermissions path := fmt.Sprintf("/api/2.0/permissions/repos/%v", request.RepoId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &repoPermissions) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &repoPermissions) return &repoPermissions, err } -func (a *reposImpl) List(ctx context.Context, request ListReposRequest) (*ListReposResponse, error) { +// Get repos. +// +// Returns repos that the calling user has Manage permissions on. Use +// `next_page_token` to iterate through additional pages. +func (a *reposImpl) List(ctx context.Context, request ListReposRequest) listing.Iterator[RepoInfo] { + + getNextPage := func(ctx context.Context, req ListReposRequest) (*ListReposResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListReposResponse) []RepoInfo { + return resp.Repos + } + getNextReq := func(resp *ListReposResponse) *ListReposRequest { + if resp.NextPageToken == "" { + return nil + } + request.NextPageToken = resp.NextPageToken + return &request + } + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + getNextReq) + return iterator +} + +// Get repos. +// +// Returns repos that the calling user has Manage permissions on. Use +// `next_page_token` to iterate through additional pages. +func (a *reposImpl) ListAll(ctx context.Context, request ListReposRequest) ([]RepoInfo, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[RepoInfo](ctx, iterator) +} +func (a *reposImpl) internalList(ctx context.Context, request ListReposRequest) (*ListReposResponse, error) { var listReposResponse ListReposResponse path := "/api/2.0/repos" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listReposResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listReposResponse) return &listReposResponse, err } func (a *reposImpl) SetPermissions(ctx context.Context, request RepoPermissionsRequest) (*RepoPermissions, error) { var repoPermissions RepoPermissions path := fmt.Sprintf("/api/2.0/permissions/repos/%v", request.RepoId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &repoPermissions) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &repoPermissions) return &repoPermissions, err } func (a *reposImpl) Update(ctx context.Context, request UpdateRepoRequest) error { var updateRepoResponse UpdateRepoResponse path := fmt.Sprintf("/api/2.0/repos/%v", request.RepoId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &updateRepoResponse) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &updateRepoResponse) return err } func (a *reposImpl) UpdatePermissions(ctx context.Context, request RepoPermissionsRequest) (*RepoPermissions, error) { var repoPermissions RepoPermissions path := fmt.Sprintf("/api/2.0/permissions/repos/%v", request.RepoId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &repoPermissions) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &repoPermissions) return &repoPermissions, err } @@ -160,105 +243,231 @@ type secretsImpl struct { func (a *secretsImpl) CreateScope(ctx context.Context, request CreateScope) error { var createScopeResponse CreateScopeResponse path := "/api/2.0/secrets/scopes/create" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &createScopeResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &createScopeResponse) return err } func (a *secretsImpl) DeleteAcl(ctx context.Context, request DeleteAcl) error { var deleteAclResponse DeleteAclResponse path := "/api/2.0/secrets/acls/delete" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &deleteAclResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &deleteAclResponse) return err } func (a *secretsImpl) DeleteScope(ctx context.Context, request DeleteScope) error { var deleteScopeResponse DeleteScopeResponse path := "/api/2.0/secrets/scopes/delete" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &deleteScopeResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &deleteScopeResponse) return err } func (a *secretsImpl) DeleteSecret(ctx context.Context, request DeleteSecret) error { var deleteSecretResponse DeleteSecretResponse path := "/api/2.0/secrets/delete" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &deleteSecretResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &deleteSecretResponse) return err } func (a *secretsImpl) GetAcl(ctx context.Context, request GetAclRequest) (*AclItem, error) { var aclItem AclItem path := "/api/2.0/secrets/acls/get" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &aclItem) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &aclItem) return &aclItem, err } func (a *secretsImpl) GetSecret(ctx context.Context, request GetSecretRequest) (*GetSecretResponse, error) { var getSecretResponse GetSecretResponse path := "/api/2.0/secrets/get" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getSecretResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getSecretResponse) return &getSecretResponse, err } -func (a *secretsImpl) ListAcls(ctx context.Context, request ListAclsRequest) (*ListAclsResponse, error) { +// Lists ACLs. +// +// List the ACLs for a given secret scope. Users must have the `MANAGE` +// permission to invoke this API. +// +// Throws `RESOURCE_DOES_NOT_EXIST` if no such secret scope exists. Throws +// `PERMISSION_DENIED` if the user does not have permission to make this API +// call. +func (a *secretsImpl) ListAcls(ctx context.Context, request ListAclsRequest) listing.Iterator[AclItem] { + + getNextPage := func(ctx context.Context, req ListAclsRequest) (*ListAclsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalListAcls(ctx, req) + } + getItems := func(resp *ListAclsResponse) []AclItem { + return resp.Items + } + + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + nil) + return iterator +} + +// Lists ACLs. +// +// List the ACLs for a given secret scope. Users must have the `MANAGE` +// permission to invoke this API. +// +// Throws `RESOURCE_DOES_NOT_EXIST` if no such secret scope exists. Throws +// `PERMISSION_DENIED` if the user does not have permission to make this API +// call. +func (a *secretsImpl) ListAclsAll(ctx context.Context, request ListAclsRequest) ([]AclItem, error) { + iterator := a.ListAcls(ctx, request) + return listing.ToSlice[AclItem](ctx, iterator) +} +func (a *secretsImpl) internalListAcls(ctx context.Context, request ListAclsRequest) (*ListAclsResponse, error) { var listAclsResponse ListAclsResponse path := "/api/2.0/secrets/acls/list" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listAclsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listAclsResponse) return &listAclsResponse, err } -func (a *secretsImpl) ListScopes(ctx context.Context) (*ListScopesResponse, error) { +// List all scopes. +// +// Lists all secret scopes available in the workspace. +// +// Throws `PERMISSION_DENIED` if the user does not have permission to make this +// API call. +func (a *secretsImpl) ListScopes(ctx context.Context) listing.Iterator[SecretScope] { + request := struct{}{} + + getNextPage := func(ctx context.Context, req struct{}) (*ListScopesResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalListScopes(ctx) + } + getItems := func(resp *ListScopesResponse) []SecretScope { + return resp.Scopes + } + + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + nil) + return iterator +} + +// List all scopes. +// +// Lists all secret scopes available in the workspace. +// +// Throws `PERMISSION_DENIED` if the user does not have permission to make this +// API call. +func (a *secretsImpl) ListScopesAll(ctx context.Context) ([]SecretScope, error) { + iterator := a.ListScopes(ctx) + return listing.ToSlice[SecretScope](ctx, iterator) +} +func (a *secretsImpl) internalListScopes(ctx context.Context) (*ListScopesResponse, error) { var listScopesResponse ListScopesResponse path := "/api/2.0/secrets/scopes/list" + headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, nil, &listScopesResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, nil, nil, &listScopesResponse) return &listScopesResponse, err } -func (a *secretsImpl) ListSecrets(ctx context.Context, request ListSecretsRequest) (*ListSecretsResponse, error) { +// List secret keys. +// +// Lists the secret keys that are stored at this scope. This is a metadata-only +// operation; secret data cannot be retrieved using this API. Users need the +// READ permission to make this call. +// +// The lastUpdatedTimestamp returned is in milliseconds since epoch. Throws +// `RESOURCE_DOES_NOT_EXIST` if no such secret scope exists. Throws +// `PERMISSION_DENIED` if the user does not have permission to make this API +// call. +func (a *secretsImpl) ListSecrets(ctx context.Context, request ListSecretsRequest) listing.Iterator[SecretMetadata] { + + getNextPage := func(ctx context.Context, req ListSecretsRequest) (*ListSecretsResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalListSecrets(ctx, req) + } + getItems := func(resp *ListSecretsResponse) []SecretMetadata { + return resp.Secrets + } + + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + nil) + return iterator +} + +// List secret keys. +// +// Lists the secret keys that are stored at this scope. This is a metadata-only +// operation; secret data cannot be retrieved using this API. Users need the +// READ permission to make this call. +// +// The lastUpdatedTimestamp returned is in milliseconds since epoch. Throws +// `RESOURCE_DOES_NOT_EXIST` if no such secret scope exists. Throws +// `PERMISSION_DENIED` if the user does not have permission to make this API +// call. +func (a *secretsImpl) ListSecretsAll(ctx context.Context, request ListSecretsRequest) ([]SecretMetadata, error) { + iterator := a.ListSecrets(ctx, request) + return listing.ToSlice[SecretMetadata](ctx, iterator) +} +func (a *secretsImpl) internalListSecrets(ctx context.Context, request ListSecretsRequest) (*ListSecretsResponse, error) { var listSecretsResponse ListSecretsResponse path := "/api/2.0/secrets/list" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listSecretsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listSecretsResponse) return &listSecretsResponse, err } func (a *secretsImpl) PutAcl(ctx context.Context, request PutAcl) error { var putAclResponse PutAclResponse path := "/api/2.0/secrets/acls/put" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &putAclResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &putAclResponse) return err } func (a *secretsImpl) PutSecret(ctx context.Context, request PutSecret) error { var putSecretResponse PutSecretResponse path := "/api/2.0/secrets/put" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &putSecretResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &putSecretResponse) return err } @@ -270,94 +479,136 @@ type workspaceImpl struct { func (a *workspaceImpl) Delete(ctx context.Context, request Delete) error { var deleteResponse DeleteResponse path := "/api/2.0/workspace/delete" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &deleteResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &deleteResponse) return err } func (a *workspaceImpl) Export(ctx context.Context, request ExportRequest) (*ExportResponse, error) { var exportResponse ExportResponse path := "/api/2.0/workspace/export" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &exportResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &exportResponse) return &exportResponse, err } func (a *workspaceImpl) GetPermissionLevels(ctx context.Context, request GetWorkspaceObjectPermissionLevelsRequest) (*GetWorkspaceObjectPermissionLevelsResponse, error) { var getWorkspaceObjectPermissionLevelsResponse GetWorkspaceObjectPermissionLevelsResponse path := fmt.Sprintf("/api/2.0/permissions/%v/%v/permissionLevels", request.WorkspaceObjectType, request.WorkspaceObjectId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &getWorkspaceObjectPermissionLevelsResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &getWorkspaceObjectPermissionLevelsResponse) return &getWorkspaceObjectPermissionLevelsResponse, err } func (a *workspaceImpl) GetPermissions(ctx context.Context, request GetWorkspaceObjectPermissionsRequest) (*WorkspaceObjectPermissions, error) { var workspaceObjectPermissions WorkspaceObjectPermissions path := fmt.Sprintf("/api/2.0/permissions/%v/%v", request.WorkspaceObjectType, request.WorkspaceObjectId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &workspaceObjectPermissions) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &workspaceObjectPermissions) return &workspaceObjectPermissions, err } func (a *workspaceImpl) GetStatus(ctx context.Context, request GetStatusRequest) (*ObjectInfo, error) { var objectInfo ObjectInfo path := "/api/2.0/workspace/get-status" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &objectInfo) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &objectInfo) return &objectInfo, err } func (a *workspaceImpl) Import(ctx context.Context, request Import) error { var importResponse ImportResponse path := "/api/2.0/workspace/import" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &importResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &importResponse) return err } -func (a *workspaceImpl) List(ctx context.Context, request ListWorkspaceRequest) (*ListResponse, error) { +// List contents. +// +// Lists the contents of a directory, or the object if it is not a directory. If +// the input path does not exist, this call returns an error +// `RESOURCE_DOES_NOT_EXIST`. +func (a *workspaceImpl) List(ctx context.Context, request ListWorkspaceRequest) listing.Iterator[ObjectInfo] { + + getNextPage := func(ctx context.Context, req ListWorkspaceRequest) (*ListResponse, error) { + ctx = useragent.InContext(ctx, "sdk-feature", "pagination") + return a.internalList(ctx, req) + } + getItems := func(resp *ListResponse) []ObjectInfo { + return resp.Objects + } + + iterator := listing.NewIterator( + &request, + getNextPage, + getItems, + nil) + return iterator +} + +// List contents. +// +// Lists the contents of a directory, or the object if it is not a directory. If +// the input path does not exist, this call returns an error +// `RESOURCE_DOES_NOT_EXIST`. +func (a *workspaceImpl) ListAll(ctx context.Context, request ListWorkspaceRequest) ([]ObjectInfo, error) { + iterator := a.List(ctx, request) + return listing.ToSlice[ObjectInfo](ctx, iterator) +} +func (a *workspaceImpl) internalList(ctx context.Context, request ListWorkspaceRequest) (*ListResponse, error) { var listResponse ListResponse path := "/api/2.0/workspace/list" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" - err := a.client.Do(ctx, http.MethodGet, path, headers, request, &listResponse) + err := a.client.Do(ctx, http.MethodGet, path, headers, queryParams, request, &listResponse) return &listResponse, err } func (a *workspaceImpl) Mkdirs(ctx context.Context, request Mkdirs) error { var mkdirsResponse MkdirsResponse path := "/api/2.0/workspace/mkdirs" + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPost, path, headers, request, &mkdirsResponse) + err := a.client.Do(ctx, http.MethodPost, path, headers, queryParams, request, &mkdirsResponse) return err } func (a *workspaceImpl) SetPermissions(ctx context.Context, request WorkspaceObjectPermissionsRequest) (*WorkspaceObjectPermissions, error) { var workspaceObjectPermissions WorkspaceObjectPermissions path := fmt.Sprintf("/api/2.0/permissions/%v/%v", request.WorkspaceObjectType, request.WorkspaceObjectId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPut, path, headers, request, &workspaceObjectPermissions) + err := a.client.Do(ctx, http.MethodPut, path, headers, queryParams, request, &workspaceObjectPermissions) return &workspaceObjectPermissions, err } func (a *workspaceImpl) UpdatePermissions(ctx context.Context, request WorkspaceObjectPermissionsRequest) (*WorkspaceObjectPermissions, error) { var workspaceObjectPermissions WorkspaceObjectPermissions path := fmt.Sprintf("/api/2.0/permissions/%v/%v", request.WorkspaceObjectType, request.WorkspaceObjectId) + queryParams := make(map[string]any) headers := make(map[string]string) headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" - err := a.client.Do(ctx, http.MethodPatch, path, headers, request, &workspaceObjectPermissions) + err := a.client.Do(ctx, http.MethodPatch, path, headers, queryParams, request, &workspaceObjectPermissions) return &workspaceObjectPermissions, err }