databricks-cli/cmd/account/storage-credentials/storage-credentials.go

255 lines
6.9 KiB
Go
Executable File

// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT.
package storage_credentials
import (
"github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/flags"
"github.com/databricks/databricks-sdk-go/service/catalog"
"github.com/spf13/cobra"
)
var Cmd = &cobra.Command{
Use: "storage-credentials",
Short: `These APIs manage storage credentials for a particular metastore.`,
Long: `These APIs manage storage credentials for a particular metastore.`,
Annotations: map[string]string{
"package": "catalog",
},
}
// start create command
var createReq catalog.AccountsCreateStorageCredential
var createJson flags.JsonFlag
func init() {
Cmd.AddCommand(createCmd)
// TODO: short flags
createCmd.Flags().Var(&createJson, "json", `either inline JSON string or @path/to/file.json with request body`)
// TODO: complex arg: credential_info
}
var createCmd = &cobra.Command{
Use: "create METASTORE_ID",
Short: `Create a storage credential.`,
Long: `Create a storage credential.
Creates a new storage credential. The request object is specific to the cloud:
* **AwsIamRole** for AWS credentials * **AzureServicePrincipal** for Azure
credentials * **GcpServiceAcountKey** for GCP credentials.
The caller must be a metastore admin and have the
**CREATE_STORAGE_CREDENTIAL** privilege on the metastore.`,
Annotations: map[string]string{},
Args: func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(1)
return check(cmd, args)
},
PreRunE: root.MustAccountClient,
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") {
err = createJson.Unmarshal(&createReq)
if err != nil {
return err
}
}
createReq.MetastoreId = args[0]
response, err := a.StorageCredentials.Create(ctx, createReq)
if err != nil {
return err
}
return cmdio.Render(ctx, response)
},
// Disable completions since they are not applicable.
// Can be overridden by manual implementation in `override.go`.
ValidArgsFunction: cobra.NoFileCompletions,
}
// start delete command
var deleteReq catalog.DeleteAccountStorageCredentialRequest
func init() {
Cmd.AddCommand(deleteCmd)
// TODO: short flags
deleteCmd.Flags().BoolVar(&deleteReq.Force, "force", deleteReq.Force, `Force deletion even if the Storage Credential is not empty.`)
}
var deleteCmd = &cobra.Command{
Use: "delete METASTORE_ID NAME",
Short: `Delete a storage credential.`,
Long: `Delete a storage credential.
Deletes a storage credential from the metastore. The caller must be an owner
of the storage credential.`,
Annotations: map[string]string{},
Args: func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
return check(cmd, args)
},
PreRunE: root.MustAccountClient,
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
a := root.AccountClient(ctx)
deleteReq.MetastoreId = args[0]
deleteReq.Name = args[1]
err = a.StorageCredentials.Delete(ctx, deleteReq)
if err != nil {
return err
}
return nil
},
// Disable completions since they are not applicable.
// Can be overridden by manual implementation in `override.go`.
ValidArgsFunction: cobra.NoFileCompletions,
}
// start get command
var getReq catalog.GetAccountStorageCredentialRequest
func init() {
Cmd.AddCommand(getCmd)
// TODO: short flags
}
var getCmd = &cobra.Command{
Use: "get METASTORE_ID NAME",
Short: `Gets the named storage credential.`,
Long: `Gets the named storage credential.
Gets a storage credential from the metastore. The caller must be a metastore
admin, the owner of the storage credential, or have a level of privilege on
the storage credential.`,
Annotations: map[string]string{},
Args: func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
return check(cmd, args)
},
PreRunE: root.MustAccountClient,
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
a := root.AccountClient(ctx)
getReq.MetastoreId = args[0]
getReq.Name = args[1]
response, err := a.StorageCredentials.Get(ctx, getReq)
if err != nil {
return err
}
return cmdio.Render(ctx, response)
},
// Disable completions since they are not applicable.
// Can be overridden by manual implementation in `override.go`.
ValidArgsFunction: cobra.NoFileCompletions,
}
// start list command
var listReq catalog.ListAccountStorageCredentialsRequest
func init() {
Cmd.AddCommand(listCmd)
// TODO: short flags
}
var listCmd = &cobra.Command{
Use: "list METASTORE_ID",
Short: `Get all storage credentials assigned to a metastore.`,
Long: `Get all storage credentials assigned to a metastore.
Gets a list of all storage credentials that have been assigned to given
metastore.`,
Annotations: map[string]string{},
Args: func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(1)
return check(cmd, args)
},
PreRunE: root.MustAccountClient,
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
a := root.AccountClient(ctx)
listReq.MetastoreId = args[0]
response, err := a.StorageCredentials.List(ctx, listReq)
if err != nil {
return err
}
return cmdio.Render(ctx, response)
},
// Disable completions since they are not applicable.
// Can be overridden by manual implementation in `override.go`.
ValidArgsFunction: cobra.NoFileCompletions,
}
// start update command
var updateReq catalog.AccountsUpdateStorageCredential
var updateJson flags.JsonFlag
func init() {
Cmd.AddCommand(updateCmd)
// TODO: short flags
updateCmd.Flags().Var(&updateJson, "json", `either inline JSON string or @path/to/file.json with request body`)
// TODO: complex arg: credential_info
}
var updateCmd = &cobra.Command{
Use: "update METASTORE_ID NAME",
Short: `Updates a storage credential.`,
Long: `Updates a storage credential.
Updates a storage credential on the metastore. The caller must be the owner of
the storage credential. If the caller is a metastore admin, only the __owner__
credential can be changed.`,
Annotations: map[string]string{},
Args: func(cmd *cobra.Command, args []string) error {
check := cobra.ExactArgs(2)
return check(cmd, args)
},
PreRunE: root.MustAccountClient,
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
a := root.AccountClient(ctx)
if cmd.Flags().Changed("json") {
err = updateJson.Unmarshal(&updateReq)
if err != nil {
return err
}
}
updateReq.MetastoreId = args[0]
updateReq.Name = args[1]
response, err := a.StorageCredentials.Update(ctx, updateReq)
if err != nil {
return err
}
return cmdio.Render(ctx, response)
},
// Disable completions since they are not applicable.
// Can be overridden by manual implementation in `override.go`.
ValidArgsFunction: cobra.NoFileCompletions,
}
// end service AccountStorageCredentials