2023-05-22 19:27:22 +00:00
|
|
|
// 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"
|
|
|
|
)
|
|
|
|
|
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: "service-principal-secrets",
|
|
|
|
Short: `These APIs enable administrators to manage service principal secrets.`,
|
|
|
|
Long: `These APIs enable administrators to manage service principal secrets.
|
2023-05-22 19:27:22 +00:00
|
|
|
|
|
|
|
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`,
|
2023-07-25 18:19:07 +00:00
|
|
|
GroupID: "oauth2",
|
|
|
|
Annotations: map[string]string{
|
|
|
|
"package": "oauth2",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply optional overrides to this command.
|
|
|
|
for _, fn := range cmdOverrides {
|
|
|
|
fn(cmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmd
|
2023-05-22 19:27:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// start create 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 createOverrides []func(
|
|
|
|
*cobra.Command,
|
|
|
|
*oauth2.CreateServicePrincipalSecretRequest,
|
|
|
|
)
|
2023-05-22 19:27:22 +00:00
|
|
|
|
2023-07-25 18:19:07 +00:00
|
|
|
func newCreate() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{}
|
|
|
|
|
|
|
|
var createReq oauth2.CreateServicePrincipalSecretRequest
|
|
|
|
|
|
|
|
// TODO: short flags
|
2023-05-22 19:27:22 +00:00
|
|
|
|
2023-07-25 18:19:07 +00:00
|
|
|
cmd.Use = "create SERVICE_PRINCIPAL_ID"
|
|
|
|
cmd.Short = `Create service principal secret.`
|
|
|
|
cmd.Long = `Create service principal secret.
|
2023-05-22 19:27:22 +00:00
|
|
|
|
2023-11-30 16:22:23 +00:00
|
|
|
Create a secret for the given service principal.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
SERVICE_PRINCIPAL_ID: The service principal ID.`
|
2023-07-25 18:19:07 +00:00
|
|
|
|
|
|
|
cmd.Annotations = make(map[string]string)
|
2023-05-22 19:27:22 +00:00
|
|
|
|
2023-07-25 18:19:07 +00:00
|
|
|
cmd.Args = func(cmd *cobra.Command, args []string) error {
|
2023-05-26 12:46:08 +00:00
|
|
|
check := cobra.ExactArgs(1)
|
|
|
|
return check(cmd, args)
|
2023-07-25 18:19:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd.PreRunE = root.MustAccountClient
|
|
|
|
cmd.RunE = func(cmd *cobra.Command, args []string) (err error) {
|
2023-05-22 19:27:22 +00:00
|
|
|
ctx := cmd.Context()
|
|
|
|
a := root.AccountClient(ctx)
|
2023-07-03 11:20:30 +00:00
|
|
|
|
|
|
|
_, err = fmt.Sscan(args[0], &createReq.ServicePrincipalId)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("invalid SERVICE_PRINCIPAL_ID: %s", args[0])
|
2023-05-22 19:27:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
response, err := a.ServicePrincipalSecrets.Create(ctx, createReq)
|
|
|
|
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 createOverrides {
|
|
|
|
fn(cmd, &createReq)
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
cmdOverrides = append(cmdOverrides, func(cmd *cobra.Command) {
|
|
|
|
cmd.AddCommand(newCreate())
|
|
|
|
})
|
2023-05-22 19:27:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// start delete 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 deleteOverrides []func(
|
|
|
|
*cobra.Command,
|
|
|
|
*oauth2.DeleteServicePrincipalSecretRequest,
|
|
|
|
)
|
2023-05-22 19:27:22 +00:00
|
|
|
|
2023-07-25 18:19:07 +00:00
|
|
|
func newDelete() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{}
|
|
|
|
|
|
|
|
var deleteReq oauth2.DeleteServicePrincipalSecretRequest
|
2023-05-22 19:27:22 +00:00
|
|
|
|
2023-07-25 18:19:07 +00:00
|
|
|
// TODO: short flags
|
|
|
|
|
|
|
|
cmd.Use = "delete SERVICE_PRINCIPAL_ID SECRET_ID"
|
|
|
|
cmd.Short = `Delete service principal secret.`
|
|
|
|
cmd.Long = `Delete service principal secret.
|
2023-05-22 19:27:22 +00:00
|
|
|
|
2023-11-30 16:22:23 +00:00
|
|
|
Delete a secret from the given service principal.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
SERVICE_PRINCIPAL_ID: The service principal ID.
|
|
|
|
SECRET_ID: The secret ID.`
|
2023-07-25 18:19:07 +00:00
|
|
|
|
|
|
|
cmd.Annotations = make(map[string]string)
|
2023-05-22 19:27:22 +00:00
|
|
|
|
2023-07-25 18:19:07 +00:00
|
|
|
cmd.Args = func(cmd *cobra.Command, args []string) error {
|
2023-05-26 12:46:08 +00:00
|
|
|
check := cobra.ExactArgs(2)
|
|
|
|
return check(cmd, args)
|
2023-07-25 18:19:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd.PreRunE = root.MustAccountClient
|
|
|
|
cmd.RunE = func(cmd *cobra.Command, args []string) (err error) {
|
2023-05-22 19:27:22 +00:00
|
|
|
ctx := cmd.Context()
|
|
|
|
a := root.AccountClient(ctx)
|
2023-07-03 11:20:30 +00:00
|
|
|
|
|
|
|
_, err = fmt.Sscan(args[0], &deleteReq.ServicePrincipalId)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("invalid SERVICE_PRINCIPAL_ID: %s", args[0])
|
2023-05-22 19:27:22 +00:00
|
|
|
}
|
2023-07-03 11:20:30 +00:00
|
|
|
deleteReq.SecretId = args[1]
|
2023-05-22 19:27:22 +00:00
|
|
|
|
|
|
|
err = a.ServicePrincipalSecrets.Delete(ctx, deleteReq)
|
|
|
|
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 deleteOverrides {
|
|
|
|
fn(cmd, &deleteReq)
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
cmdOverrides = append(cmdOverrides, func(cmd *cobra.Command) {
|
|
|
|
cmd.AddCommand(newDelete())
|
|
|
|
})
|
2023-05-22 19:27:22 +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,
|
|
|
|
*oauth2.ListServicePrincipalSecretsRequest,
|
|
|
|
)
|
2023-05-22 19:27:22 +00:00
|
|
|
|
2023-07-25 18:19:07 +00:00
|
|
|
func newList() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{}
|
2023-05-22 19:27:22 +00:00
|
|
|
|
2023-07-25 18:19:07 +00:00
|
|
|
var listReq oauth2.ListServicePrincipalSecretsRequest
|
|
|
|
|
|
|
|
// TODO: short flags
|
|
|
|
|
|
|
|
cmd.Use = "list SERVICE_PRINCIPAL_ID"
|
|
|
|
cmd.Short = `List service principal secrets.`
|
|
|
|
cmd.Long = `List service principal secrets.
|
2023-05-22 19:27:22 +00:00
|
|
|
|
|
|
|
List all secrets associated with the given service principal. This operation
|
|
|
|
only returns information about the secrets themselves and does not include the
|
2023-11-30 16:22:23 +00:00
|
|
|
secret values.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
SERVICE_PRINCIPAL_ID: The service principal ID.`
|
2023-05-22 19:27:22 +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-05-26 12:46:08 +00:00
|
|
|
check := cobra.ExactArgs(1)
|
|
|
|
return check(cmd, args)
|
2023-07-25 18:19:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd.PreRunE = root.MustAccountClient
|
|
|
|
cmd.RunE = func(cmd *cobra.Command, args []string) (err error) {
|
2023-05-22 19:27:22 +00:00
|
|
|
ctx := cmd.Context()
|
|
|
|
a := root.AccountClient(ctx)
|
2023-07-03 11:20:30 +00:00
|
|
|
|
|
|
|
_, err = fmt.Sscan(args[0], &listReq.ServicePrincipalId)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("invalid SERVICE_PRINCIPAL_ID: %s", args[0])
|
2023-05-22 19:27:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
response, err := a.ServicePrincipalSecrets.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-05-22 19:27:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// end service ServicePrincipalSecrets
|