databricks-cli/cmd/account/service-principal-secrets/service-principal-secrets.go

165 lines
4.8 KiB
Go
Raw Permalink Normal View History

// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT.
package service_principal_secrets
import (
"fmt"
"github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/databricks-sdk-go/service/oauth2"
"github.com/spf13/cobra"
)
var Cmd = &cobra.Command{
Use: "service-principal-secrets",
Short: `These APIs enable administrators to manage service principal secrets.`,
Long: `These APIs enable administrators to manage service principal secrets.
You can use the generated secrets to obtain OAuth access tokens for a service
principal, which can then be used to access Databricks Accounts and Workspace
APIs. For more information, see [Authentication using OAuth tokens for service
principals],
In addition, the generated secrets can be used to configure the Databricks
Terraform Provider to authenticate with the service principal. For more
information, see [Databricks Terraform Provider].
[Authentication using OAuth tokens for service principals]: https://docs.databricks.com/dev-tools/authentication-oauth.html
[Databricks Terraform Provider]: https://github.com/databricks/terraform-provider-databricks/blob/master/docs/index.md#authenticating-with-service-principal`,
Annotations: map[string]string{
"package": "oauth2",
},
}
// start create command
var createReq oauth2.CreateServicePrincipalSecretRequest
func init() {
Cmd.AddCommand(createCmd)
// TODO: short flags
}
var createCmd = &cobra.Command{
Use: "create SERVICE_PRINCIPAL_ID",
Short: `Create service principal secret.`,
Long: `Create service principal secret.
Create a secret for the given service principal.`,
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)
_, err = fmt.Sscan(args[0], &createReq.ServicePrincipalId)
if err != nil {
return fmt.Errorf("invalid SERVICE_PRINCIPAL_ID: %s", args[0])
}
response, err := a.ServicePrincipalSecrets.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 oauth2.DeleteServicePrincipalSecretRequest
func init() {
Cmd.AddCommand(deleteCmd)
// TODO: short flags
}
var deleteCmd = &cobra.Command{
Use: "delete SERVICE_PRINCIPAL_ID SECRET_ID",
Short: `Delete service principal secret.`,
Long: `Delete service principal secret.
Delete a secret from the given service principal.`,
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)
_, err = fmt.Sscan(args[0], &deleteReq.ServicePrincipalId)
if err != nil {
return fmt.Errorf("invalid SERVICE_PRINCIPAL_ID: %s", args[0])
}
deleteReq.SecretId = args[1]
err = a.ServicePrincipalSecrets.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 list command
var listReq oauth2.ListServicePrincipalSecretsRequest
func init() {
Cmd.AddCommand(listCmd)
// TODO: short flags
}
var listCmd = &cobra.Command{
Use: "list SERVICE_PRINCIPAL_ID",
Short: `List service principal secrets.`,
Long: `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.`,
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)
_, err = fmt.Sscan(args[0], &listReq.ServicePrincipalId)
if err != nil {
return fmt.Errorf("invalid SERVICE_PRINCIPAL_ID: %s", args[0])
}
response, err := a.ServicePrincipalSecrets.ListAll(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,
}
// end service ServicePrincipalSecrets