databricks-cli/cmd/workspace/metastores/metastores.go

448 lines
12 KiB
Go
Raw Normal View History

Added OpenAPI command coverage (#357) This PR adds the following command groups: ## Workspace-level command groups * `bricks alerts` - The alerts API can be used to perform CRUD operations on alerts. * `bricks catalogs` - A catalog is the first layer of Unity Catalog’s three-level namespace. * `bricks cluster-policies` - Cluster policy limits the ability to configure clusters based on a set of rules. * `bricks clusters` - The Clusters API allows you to create, start, edit, list, terminate, and delete clusters. * `bricks current-user` - This API allows retrieving information about currently authenticated user or service principal. * `bricks dashboards` - In general, there is little need to modify dashboards using the API. * `bricks data-sources` - This API is provided to assist you in making new query objects. * `bricks experiments` - MLflow Experiment tracking. * `bricks external-locations` - An external location is an object that combines a cloud storage path with a storage credential that authorizes access to the cloud storage path. * `bricks functions` - Functions implement User-Defined Functions (UDFs) in Unity Catalog. * `bricks git-credentials` - Registers personal access token for Databricks to do operations on behalf of the user. * `bricks global-init-scripts` - The Global Init Scripts API enables Workspace administrators to configure global initialization scripts for their workspace. * `bricks grants` - In Unity Catalog, data is secure by default. * `bricks groups` - Groups simplify identity management, making it easier to assign access to Databricks Workspace, data, and other securable objects. * `bricks instance-pools` - Instance Pools API are used to create, edit, delete and list instance pools by using ready-to-use cloud instances which reduces a cluster start and auto-scaling times. * `bricks instance-profiles` - The Instance Profiles API allows admins to add, list, and remove instance profiles that users can launch clusters with. * `bricks ip-access-lists` - IP Access List enables admins to configure IP access lists. * `bricks jobs` - The Jobs API allows you to create, edit, and delete jobs. * `bricks libraries` - The Libraries API allows you to install and uninstall libraries and get the status of libraries on a cluster. * `bricks metastores` - A metastore is the top-level container of objects in Unity Catalog. * `bricks model-registry` - MLflow Model Registry commands. * `bricks permissions` - Permissions API are used to create read, write, edit, update and manage access for various users on different objects and endpoints. * `bricks pipelines` - The Delta Live Tables API allows you to create, edit, delete, start, and view details about pipelines. * `bricks policy-families` - View available policy families. * `bricks providers` - Databricks Providers REST API. * `bricks queries` - These endpoints are used for CRUD operations on query definitions. * `bricks query-history` - Access the history of queries through SQL warehouses. * `bricks recipient-activation` - Databricks Recipient Activation REST API. * `bricks recipients` - Databricks Recipients REST API. * `bricks repos` - The Repos API allows users to manage their git repos. * `bricks schemas` - A schema (also called a database) is the second layer of Unity Catalog’s three-level namespace. * `bricks secrets` - The Secrets API allows you to manage secrets, secret scopes, and access permissions. * `bricks service-principals` - Identities for use with jobs, automated tools, and systems such as scripts, apps, and CI/CD platforms. * `bricks serving-endpoints` - The Serving Endpoints API allows you to create, update, and delete model serving endpoints. * `bricks shares` - Databricks Shares REST API. * `bricks storage-credentials` - A storage credential represents an authentication and authorization mechanism for accessing data stored on your cloud tenant. * `bricks table-constraints` - Primary key and foreign key constraints encode relationships between fields in tables. * `bricks tables` - A table resides in the third layer of Unity Catalog’s three-level namespace. * `bricks token-management` - Enables administrators to get all tokens and delete tokens for other users. * `bricks tokens` - The Token API allows you to create, list, and revoke tokens that can be used to authenticate and access Databricks REST APIs. * `bricks users` - User identities recognized by Databricks and represented by email addresses. * `bricks volumes` - Volumes are a Unity Catalog (UC) capability for accessing, storing, governing, organizing and processing files. * `bricks warehouses` - A SQL warehouse is a compute resource that lets you run SQL commands on data objects within Databricks SQL. * `bricks workspace` - The Workspace API allows you to list, import, export, and delete notebooks and folders. * `bricks workspace-conf` - This API allows updating known workspace settings for advanced users. ## Account-level command groups * `bricks account billable-usage` - This API allows you to download billable usage logs for the specified account and date range. * `bricks account budgets` - These APIs manage budget configuration including notifications for exceeding a budget for a period. * `bricks account credentials` - These APIs manage credential configurations for this workspace. * `bricks account custom-app-integration` - These APIs enable administrators to manage custom oauth app integrations, which is required for adding/using Custom OAuth App Integration like Tableau Cloud for Databricks in AWS cloud. * `bricks account encryption-keys` - These APIs manage encryption key configurations for this workspace (optional). * `bricks account groups` - Groups simplify identity management, making it easier to assign access to Databricks Account, data, and other securable objects. * `bricks account ip-access-lists` - The Accounts IP Access List API enables account admins to configure IP access lists for access to the account console. * `bricks account log-delivery` - These APIs manage log delivery configurations for this account. * `bricks account metastore-assignments` - These APIs manage metastore assignments to a workspace. * `bricks account metastores` - These APIs manage Unity Catalog metastores for an account. * `bricks account networks` - These APIs manage network configurations for customer-managed VPCs (optional). * `bricks account o-auth-enrollment` - These APIs enable administrators to enroll OAuth for their accounts, which is required for adding/using any OAuth published/custom application integration. * `bricks account private-access` - These APIs manage private access settings for this account. * `bricks account published-app-integration` - These APIs enable administrators to manage published oauth app integrations, which is required for adding/using Published OAuth App Integration like Tableau Cloud for Databricks in AWS cloud. * `bricks account service-principals` - Identities for use with jobs, automated tools, and systems such as scripts, apps, and CI/CD platforms. * `bricks account storage` - These APIs manage storage configurations for this workspace. * `bricks account storage-credentials` - These APIs manage storage credentials for a particular metastore. * `bricks account users` - User identities recognized by Databricks and represented by email addresses. * `bricks account vpc-endpoints` - These APIs manage VPC endpoint configurations for this account. * `bricks account workspace-assignment` - The Workspace Permission Assignment API allows you to manage workspace permissions for principals in your account. * `bricks account workspaces` - These APIs manage workspaces for this account.
2023-04-26 11:06:16 +00:00
// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT.
package metastores
import (
"fmt"
"github.com/databricks/bricks/cmd/root"
"github.com/databricks/bricks/libs/cmdio"
"github.com/databricks/databricks-sdk-go/service/catalog"
"github.com/spf13/cobra"
)
var Cmd = &cobra.Command{
Use: "metastores",
Short: `A metastore is the top-level container of objects in Unity Catalog.`,
Long: `A metastore is the top-level container of objects in Unity Catalog. It stores
data assets (tables and views) and the permissions that govern access to them.
Databricks account admins can create metastores and assign them to Databricks
workspaces to control which workloads use each metastore. For a workspace to
use Unity Catalog, it must have a Unity Catalog metastore attached.
Each metastore is configured with a root storage location in a cloud storage
account. This storage location is used for metadata and managed tables data.
NOTE: This metastore is distinct from the metastore included in Databricks
workspaces created before Unity Catalog was released. If your workspace
includes a legacy Hive metastore, the data in that metastore is available in a
catalog named hive_metastore.`,
}
// start assign command
var assignReq catalog.CreateMetastoreAssignment
func init() {
Cmd.AddCommand(assignCmd)
// TODO: short flags
}
var assignCmd = &cobra.Command{
Use: "assign METASTORE_ID DEFAULT_CATALOG_NAME WORKSPACE_ID",
Short: `Create an assignment.`,
Long: `Create an assignment.
Creates a new metastore assignment. If an assignment for the same
__workspace_id__ exists, it will be overwritten by the new __metastore_id__
and __default_catalog_name__. The caller must be an account admin.`,
Annotations: map[string]string{},
Args: cobra.ExactArgs(3),
PreRunE: root.MustWorkspaceClient,
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
assignReq.MetastoreId = args[0]
assignReq.DefaultCatalogName = args[1]
_, err = fmt.Sscan(args[2], &assignReq.WorkspaceId)
if err != nil {
return fmt.Errorf("invalid WORKSPACE_ID: %s", args[2])
}
err = w.Metastores.Assign(ctx, assignReq)
if err != nil {
return err
}
return nil
},
}
// start create command
var createReq catalog.CreateMetastore
func init() {
Cmd.AddCommand(createCmd)
// TODO: short flags
createCmd.Flags().StringVar(&createReq.Region, "region", createReq.Region, `Cloud region which the metastore serves (e.g., us-west-2, westus).`)
}
var createCmd = &cobra.Command{
Use: "create NAME STORAGE_ROOT",
Short: `Create a metastore.`,
Long: `Create a metastore.
Creates a new metastore based on a provided name and storage root path.`,
Annotations: map[string]string{},
Args: cobra.ExactArgs(2),
PreRunE: root.MustWorkspaceClient,
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
createReq.Name = args[0]
createReq.StorageRoot = args[1]
response, err := w.Metastores.Create(ctx, createReq)
if err != nil {
return err
}
return cmdio.Render(ctx, response)
},
}
// start current command
func init() {
Cmd.AddCommand(currentCmd)
}
var currentCmd = &cobra.Command{
Use: "current",
Short: `Get metastore assignment for workspace.`,
Long: `Get metastore assignment for workspace.
Gets the metastore assignment for the workspace being accessed.`,
Annotations: map[string]string{},
PreRunE: root.MustWorkspaceClient,
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
response, err := w.Metastores.Current(ctx)
if err != nil {
return err
}
return cmdio.Render(ctx, response)
},
}
// start delete command
var deleteReq catalog.DeleteMetastoreRequest
func init() {
Cmd.AddCommand(deleteCmd)
// TODO: short flags
deleteCmd.Flags().BoolVar(&deleteReq.Force, "force", deleteReq.Force, `Force deletion even if the metastore is not empty.`)
}
var deleteCmd = &cobra.Command{
Use: "delete ID",
Short: `Delete a metastore.`,
Long: `Delete a metastore.
Deletes a metastore. The caller must be a metastore admin.`,
Annotations: map[string]string{},
PreRunE: root.MustWorkspaceClient,
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if len(args) == 0 {
names, err := w.Metastores.MetastoreInfoNameToMetastoreIdMap(ctx)
if err != nil {
return err
}
id, err := cmdio.Select(ctx, names, "Unique ID of the metastore")
if err != nil {
return err
}
args = append(args, id)
}
if len(args) != 1 {
return fmt.Errorf("expected to have unique id of the metastore")
}
deleteReq.Id = args[0]
err = w.Metastores.Delete(ctx, deleteReq)
if err != nil {
return err
}
return nil
},
}
// start get command
var getReq catalog.GetMetastoreRequest
func init() {
Cmd.AddCommand(getCmd)
// TODO: short flags
}
var getCmd = &cobra.Command{
Use: "get ID",
Short: `Get a metastore.`,
Long: `Get a metastore.
Gets a metastore that matches the supplied ID. The caller must be a metastore
admin to retrieve this info.`,
Annotations: map[string]string{},
PreRunE: root.MustWorkspaceClient,
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
if len(args) == 0 {
names, err := w.Metastores.MetastoreInfoNameToMetastoreIdMap(ctx)
if err != nil {
return err
}
id, err := cmdio.Select(ctx, names, "Unique ID of the metastore")
if err != nil {
return err
}
args = append(args, id)
}
if len(args) != 1 {
return fmt.Errorf("expected to have unique id of the metastore")
}
getReq.Id = args[0]
response, err := w.Metastores.Get(ctx, getReq)
if err != nil {
return err
}
return cmdio.Render(ctx, response)
},
}
// start list command
func init() {
Cmd.AddCommand(listCmd)
}
var listCmd = &cobra.Command{
Use: "list",
Short: `List metastores.`,
Long: `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.`,
Annotations: map[string]string{},
PreRunE: root.MustWorkspaceClient,
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
response, err := w.Metastores.ListAll(ctx)
if err != nil {
return err
}
return cmdio.Render(ctx, response)
},
}
// start maintenance command
var maintenanceReq catalog.UpdateAutoMaintenance
func init() {
Cmd.AddCommand(maintenanceCmd)
// TODO: short flags
}
var maintenanceCmd = &cobra.Command{
Use: "maintenance METASTORE_ID ENABLE",
Short: `Enables or disables auto maintenance on the metastore.`,
Long: `Enables or disables auto maintenance on the metastore.
Enables or disables auto maintenance on the metastore.`,
Annotations: map[string]string{},
Args: cobra.ExactArgs(2),
PreRunE: root.MustWorkspaceClient,
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
maintenanceReq.MetastoreId = args[0]
_, err = fmt.Sscan(args[1], &maintenanceReq.Enable)
if err != nil {
return fmt.Errorf("invalid ENABLE: %s", args[1])
}
response, err := w.Metastores.Maintenance(ctx, maintenanceReq)
if err != nil {
return err
}
return cmdio.Render(ctx, response)
},
}
// start summary command
func init() {
Cmd.AddCommand(summaryCmd)
}
var summaryCmd = &cobra.Command{
Use: "summary",
Short: `Get a metastore summary.`,
Long: `Get a metastore summary.
Gets information about a metastore. This summary includes the storage
credential, the cloud vendor, the cloud region, and the global metastore ID.`,
Annotations: map[string]string{},
PreRunE: root.MustWorkspaceClient,
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
response, err := w.Metastores.Summary(ctx)
if err != nil {
return err
}
return cmdio.Render(ctx, response)
},
}
// start unassign command
var unassignReq catalog.UnassignRequest
func init() {
Cmd.AddCommand(unassignCmd)
// TODO: short flags
}
var unassignCmd = &cobra.Command{
Use: "unassign WORKSPACE_ID METASTORE_ID",
Short: `Delete an assignment.`,
Long: `Delete an assignment.
Deletes a metastore assignment. The caller must be an account administrator.`,
Annotations: map[string]string{},
Args: cobra.ExactArgs(2),
PreRunE: root.MustWorkspaceClient,
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
_, err = fmt.Sscan(args[0], &unassignReq.WorkspaceId)
if err != nil {
return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0])
}
unassignReq.MetastoreId = args[1]
err = w.Metastores.Unassign(ctx, unassignReq)
if err != nil {
return err
}
return nil
},
}
// start update command
var updateReq catalog.UpdateMetastore
func init() {
Cmd.AddCommand(updateCmd)
// TODO: short flags
updateCmd.Flags().StringVar(&updateReq.DeltaSharingOrganizationName, "delta-sharing-organization-name", updateReq.DeltaSharingOrganizationName, `The organization name of a Delta Sharing entity, to be used in Databricks-to-Databricks Delta Sharing as the official name.`)
updateCmd.Flags().Int64Var(&updateReq.DeltaSharingRecipientTokenLifetimeInSeconds, "delta-sharing-recipient-token-lifetime-in-seconds", updateReq.DeltaSharingRecipientTokenLifetimeInSeconds, `The lifetime of delta sharing recipient token in seconds.`)
updateCmd.Flags().Var(&updateReq.DeltaSharingScope, "delta-sharing-scope", `The scope of Delta Sharing enabled for the metastore.`)
updateCmd.Flags().StringVar(&updateReq.Name, "name", updateReq.Name, `The user-specified name of the metastore.`)
updateCmd.Flags().StringVar(&updateReq.Owner, "owner", updateReq.Owner, `The owner of the metastore.`)
updateCmd.Flags().StringVar(&updateReq.PrivilegeModelVersion, "privilege-model-version", updateReq.PrivilegeModelVersion, `Privilege model version of the metastore, of the form major.minor (e.g., 1.0).`)
updateCmd.Flags().StringVar(&updateReq.StorageRootCredentialId, "storage-root-credential-id", updateReq.StorageRootCredentialId, `UUID of storage credential to access the metastore storage_root.`)
}
var updateCmd = &cobra.Command{
Use: "update METASTORE_ID ID",
Short: `Update a metastore.`,
Long: `Update a metastore.
Updates information for a specific metastore. The caller must be a metastore
admin.`,
Annotations: map[string]string{},
Args: cobra.ExactArgs(2),
PreRunE: root.MustWorkspaceClient,
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
updateReq.MetastoreId = args[0]
updateReq.Id = args[1]
response, err := w.Metastores.Update(ctx, updateReq)
if err != nil {
return err
}
return cmdio.Render(ctx, response)
},
}
// start update-assignment command
var updateAssignmentReq catalog.UpdateMetastoreAssignment
func init() {
Cmd.AddCommand(updateAssignmentCmd)
// TODO: short flags
updateAssignmentCmd.Flags().StringVar(&updateAssignmentReq.DefaultCatalogName, "default-catalog-name", updateAssignmentReq.DefaultCatalogName, `The name of the default catalog for the metastore.`)
updateAssignmentCmd.Flags().StringVar(&updateAssignmentReq.MetastoreId, "metastore-id", updateAssignmentReq.MetastoreId, `The unique ID of the metastore.`)
}
var updateAssignmentCmd = &cobra.Command{
Use: "update-assignment WORKSPACE_ID METASTORE_ID",
Short: `Update an assignment.`,
Long: `Update an assignment.
Updates a metastore assignment. This operation can be used to update
__metastore_id__ or __default_catalog_name__ for a specified Workspace, if the
Workspace is already assigned a metastore. The caller must be an account admin
to update __metastore_id__; otherwise, the caller can be a Workspace admin.`,
Annotations: map[string]string{},
Args: cobra.ExactArgs(2),
PreRunE: root.MustWorkspaceClient,
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
w := root.WorkspaceClient(ctx)
_, err = fmt.Sscan(args[0], &updateAssignmentReq.WorkspaceId)
if err != nil {
return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0])
}
updateAssignmentReq.MetastoreId = args[1]
err = w.Metastores.UpdateAssignment(ctx, updateAssignmentReq)
if err != nil {
return err
}
return nil
},
}
// end service Metastores