2023-06-12 12:23:21 +00:00
|
|
|
// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT.
|
|
|
|
|
|
|
|
package system_schemas
|
|
|
|
|
|
|
|
import (
|
2023-07-03 09:46:45 +00:00
|
|
|
"fmt"
|
|
|
|
|
2023-06-12 12:23:21 +00:00
|
|
|
"github.com/databricks/cli/cmd/root"
|
|
|
|
"github.com/databricks/cli/libs/cmdio"
|
|
|
|
"github.com/databricks/databricks-sdk-go/service/catalog"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2023-07-25 18:19:07 +00:00
|
|
|
// Slice with functions to override default command behavior.
|
|
|
|
// Functions can be added from the `init()` function in manually curated files in this directory.
|
|
|
|
var cmdOverrides []func(*cobra.Command)
|
|
|
|
|
|
|
|
func New() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "system-schemas",
|
|
|
|
Short: `A system schema is a schema that lives within the system catalog.`,
|
|
|
|
Long: `A system schema is a schema that lives within the system catalog. A system
|
2023-06-12 12:23:21 +00:00
|
|
|
schema may contain information about customer usage of Unity Catalog such as
|
|
|
|
audit-logs, billing-logs, lineage information, etc.`,
|
2023-07-25 18:19:07 +00:00
|
|
|
GroupID: "catalog",
|
|
|
|
Annotations: map[string]string{
|
|
|
|
"package": "catalog",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply optional overrides to this command.
|
|
|
|
for _, fn := range cmdOverrides {
|
|
|
|
fn(cmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmd
|
2023-06-12 12:23:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// start disable command
|
|
|
|
|
2023-07-25 18:19:07 +00:00
|
|
|
// Slice with functions to override default command behavior.
|
|
|
|
// Functions can be added from the `init()` function in manually curated files in this directory.
|
|
|
|
var disableOverrides []func(
|
|
|
|
*cobra.Command,
|
|
|
|
*catalog.DisableRequest,
|
|
|
|
)
|
2023-06-12 12:23:21 +00:00
|
|
|
|
2023-07-25 18:19:07 +00:00
|
|
|
func newDisable() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{}
|
2023-06-12 12:23:21 +00:00
|
|
|
|
2023-07-25 18:19:07 +00:00
|
|
|
var disableReq catalog.DisableRequest
|
|
|
|
|
|
|
|
// TODO: short flags
|
|
|
|
|
|
|
|
cmd.Use = "disable METASTORE_ID SCHEMA_NAME"
|
|
|
|
cmd.Short = `Disable a system schema.`
|
|
|
|
cmd.Long = `Disable a system schema.
|
2023-06-12 12:23:21 +00:00
|
|
|
|
|
|
|
Disables the system schema and removes it from the system catalog. The caller
|
2023-11-30 16:22:23 +00:00
|
|
|
must be an account admin or a metastore admin.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
METASTORE_ID: The metastore ID under which the system schema lives.
|
|
|
|
SCHEMA_NAME: Full name of the system schema.`
|
2023-06-12 12:23:21 +00:00
|
|
|
|
2023-07-25 18:19:07 +00:00
|
|
|
cmd.Annotations = make(map[string]string)
|
|
|
|
|
|
|
|
cmd.Args = func(cmd *cobra.Command, args []string) error {
|
2023-06-12 12:23:21 +00:00
|
|
|
check := cobra.ExactArgs(2)
|
|
|
|
return check(cmd, args)
|
2023-07-25 18:19:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd.PreRunE = root.MustWorkspaceClient
|
|
|
|
cmd.RunE = func(cmd *cobra.Command, args []string) (err error) {
|
2023-06-12 12:23:21 +00:00
|
|
|
ctx := cmd.Context()
|
|
|
|
w := root.WorkspaceClient(ctx)
|
2023-07-03 11:20:30 +00:00
|
|
|
|
|
|
|
disableReq.MetastoreId = args[0]
|
|
|
|
_, err = fmt.Sscan(args[1], &disableReq.SchemaName)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("invalid SCHEMA_NAME: %s", args[1])
|
2023-06-12 12:23:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = w.SystemSchemas.Disable(ctx, disableReq)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
2023-07-25 18:19:07 +00:00
|
|
|
}
|
|
|
|
|
2023-06-15 14:56:36 +00:00
|
|
|
// Disable completions since they are not applicable.
|
|
|
|
// Can be overridden by manual implementation in `override.go`.
|
2023-07-25 18:19:07 +00:00
|
|
|
cmd.ValidArgsFunction = cobra.NoFileCompletions
|
|
|
|
|
|
|
|
// Apply optional overrides to this command.
|
|
|
|
for _, fn := range disableOverrides {
|
|
|
|
fn(cmd, &disableReq)
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
cmdOverrides = append(cmdOverrides, func(cmd *cobra.Command) {
|
|
|
|
cmd.AddCommand(newDisable())
|
|
|
|
})
|
2023-06-12 12:23:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// start enable command
|
2023-07-03 09:46:45 +00:00
|
|
|
|
2023-07-25 18:19:07 +00:00
|
|
|
// Slice with functions to override default command behavior.
|
|
|
|
// Functions can be added from the `init()` function in manually curated files in this directory.
|
|
|
|
var enableOverrides []func(
|
|
|
|
*cobra.Command,
|
|
|
|
*catalog.EnableRequest,
|
|
|
|
)
|
2023-06-12 12:23:21 +00:00
|
|
|
|
2023-07-25 18:19:07 +00:00
|
|
|
func newEnable() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{}
|
|
|
|
|
|
|
|
var enableReq catalog.EnableRequest
|
|
|
|
|
|
|
|
// TODO: short flags
|
2023-06-12 12:23:21 +00:00
|
|
|
|
2023-07-25 18:19:07 +00:00
|
|
|
cmd.Use = "enable METASTORE_ID SCHEMA_NAME"
|
|
|
|
cmd.Short = `Enable a system schema.`
|
|
|
|
cmd.Long = `Enable a system schema.
|
2023-06-12 12:23:21 +00:00
|
|
|
|
|
|
|
Enables the system schema and adds it to the system catalog. The caller must
|
2023-11-30 16:22:23 +00:00
|
|
|
be an account admin or a metastore admin.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
METASTORE_ID: The metastore ID under which the system schema lives.
|
|
|
|
SCHEMA_NAME: Full name of the system schema.`
|
2023-06-12 12:23:21 +00:00
|
|
|
|
2023-07-25 18:19:07 +00:00
|
|
|
cmd.Annotations = make(map[string]string)
|
|
|
|
|
|
|
|
cmd.Args = func(cmd *cobra.Command, args []string) error {
|
2023-07-03 09:46:45 +00:00
|
|
|
check := cobra.ExactArgs(2)
|
|
|
|
return check(cmd, args)
|
2023-07-25 18:19:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd.PreRunE = root.MustWorkspaceClient
|
|
|
|
cmd.RunE = func(cmd *cobra.Command, args []string) (err error) {
|
2023-06-12 12:23:21 +00:00
|
|
|
ctx := cmd.Context()
|
|
|
|
w := root.WorkspaceClient(ctx)
|
2023-07-03 11:20:30 +00:00
|
|
|
|
|
|
|
enableReq.MetastoreId = args[0]
|
|
|
|
_, err = fmt.Sscan(args[1], &enableReq.SchemaName)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("invalid SCHEMA_NAME: %s", args[1])
|
2023-07-03 09:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = w.SystemSchemas.Enable(ctx, enableReq)
|
2023-06-12 12:23:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
2023-07-25 18:19:07 +00:00
|
|
|
}
|
|
|
|
|
2023-06-15 14:56:36 +00:00
|
|
|
// Disable completions since they are not applicable.
|
|
|
|
// Can be overridden by manual implementation in `override.go`.
|
2023-07-25 18:19:07 +00:00
|
|
|
cmd.ValidArgsFunction = cobra.NoFileCompletions
|
|
|
|
|
|
|
|
// Apply optional overrides to this command.
|
|
|
|
for _, fn := range enableOverrides {
|
|
|
|
fn(cmd, &enableReq)
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
cmdOverrides = append(cmdOverrides, func(cmd *cobra.Command) {
|
|
|
|
cmd.AddCommand(newEnable())
|
|
|
|
})
|
2023-06-12 12:23:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// start list command
|
|
|
|
|
2023-07-25 18:19:07 +00:00
|
|
|
// Slice with functions to override default command behavior.
|
|
|
|
// Functions can be added from the `init()` function in manually curated files in this directory.
|
|
|
|
var listOverrides []func(
|
|
|
|
*cobra.Command,
|
|
|
|
*catalog.ListSystemSchemasRequest,
|
|
|
|
)
|
2023-06-12 12:23:21 +00:00
|
|
|
|
2023-07-25 18:19:07 +00:00
|
|
|
func newList() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{}
|
2023-06-12 12:23:21 +00:00
|
|
|
|
2023-07-25 18:19:07 +00:00
|
|
|
var listReq catalog.ListSystemSchemasRequest
|
|
|
|
|
|
|
|
// TODO: short flags
|
|
|
|
|
|
|
|
cmd.Use = "list METASTORE_ID"
|
|
|
|
cmd.Short = `List system schemas.`
|
|
|
|
cmd.Long = `List system schemas.
|
2023-06-12 12:23:21 +00:00
|
|
|
|
|
|
|
Gets an array of system schemas for a metastore. The caller must be an account
|
2023-11-30 16:22:23 +00:00
|
|
|
admin or a metastore admin.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
METASTORE_ID: The ID for the metastore in which the system schema resides.`
|
2023-06-12 12:23:21 +00:00
|
|
|
|
2023-07-25 18:19:07 +00:00
|
|
|
cmd.Annotations = make(map[string]string)
|
|
|
|
|
|
|
|
cmd.Args = func(cmd *cobra.Command, args []string) error {
|
2023-06-12 12:23:21 +00:00
|
|
|
check := cobra.ExactArgs(1)
|
|
|
|
return check(cmd, args)
|
2023-07-25 18:19:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd.PreRunE = root.MustWorkspaceClient
|
|
|
|
cmd.RunE = func(cmd *cobra.Command, args []string) (err error) {
|
2023-06-12 12:23:21 +00:00
|
|
|
ctx := cmd.Context()
|
|
|
|
w := root.WorkspaceClient(ctx)
|
2023-07-03 11:20:30 +00:00
|
|
|
|
|
|
|
listReq.MetastoreId = args[0]
|
2023-06-12 12:23:21 +00:00
|
|
|
|
|
|
|
response, err := w.SystemSchemas.ListAll(ctx, listReq)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return cmdio.Render(ctx, response)
|
2023-07-25 18:19:07 +00:00
|
|
|
}
|
|
|
|
|
2023-06-15 14:56:36 +00:00
|
|
|
// Disable completions since they are not applicable.
|
|
|
|
// Can be overridden by manual implementation in `override.go`.
|
2023-07-25 18:19:07 +00:00
|
|
|
cmd.ValidArgsFunction = cobra.NoFileCompletions
|
|
|
|
|
|
|
|
// Apply optional overrides to this command.
|
|
|
|
for _, fn := range listOverrides {
|
|
|
|
fn(cmd, &listReq)
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
cmdOverrides = append(cmdOverrides, func(cmd *cobra.Command) {
|
|
|
|
cmd.AddCommand(newList())
|
|
|
|
})
|
2023-06-12 12:23:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// end service SystemSchemas
|