mirror of https://github.com/databricks/cli.git
305 lines
8.7 KiB
Go
305 lines
8.7 KiB
Go
|
// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT.
|
|||
|
|
|||
|
package users
|
|||
|
|
|||
|
import (
|
|||
|
"fmt"
|
|||
|
|
|||
|
"github.com/databricks/bricks/cmd/root"
|
|||
|
"github.com/databricks/bricks/libs/cmdio"
|
|||
|
"github.com/databricks/bricks/libs/flags"
|
|||
|
"github.com/databricks/databricks-sdk-go/service/iam"
|
|||
|
"github.com/spf13/cobra"
|
|||
|
)
|
|||
|
|
|||
|
var Cmd = &cobra.Command{
|
|||
|
Use: "users",
|
|||
|
Short: `User identities recognized by Databricks and represented by email addresses.`,
|
|||
|
Long: `User identities recognized by Databricks and represented by email addresses.
|
|||
|
|
|||
|
Databricks recommends using SCIM provisioning to sync users and groups
|
|||
|
automatically from your identity provider to your Databricks Workspace. SCIM
|
|||
|
streamlines onboarding a new employee or team by using your identity provider
|
|||
|
to create users and groups in Databricks Workspace and give them the proper
|
|||
|
level of access. When a user leaves your organization or no longer needs
|
|||
|
access to Databricks Workspace, admins can terminate the user in your identity
|
|||
|
provider and that user’s account will also be removed from Databricks
|
|||
|
Workspace. This ensures a consistent offboarding process and prevents
|
|||
|
unauthorized users from accessing sensitive data.`,
|
|||
|
}
|
|||
|
|
|||
|
// start create command
|
|||
|
|
|||
|
var createReq iam.User
|
|||
|
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`)
|
|||
|
|
|||
|
createCmd.Flags().BoolVar(&createReq.Active, "active", createReq.Active, `If this user is active.`)
|
|||
|
createCmd.Flags().StringVar(&createReq.DisplayName, "display-name", createReq.DisplayName, `String that represents a concatenation of given and family names.`)
|
|||
|
// TODO: array: emails
|
|||
|
// TODO: array: entitlements
|
|||
|
createCmd.Flags().StringVar(&createReq.ExternalId, "external-id", createReq.ExternalId, ``)
|
|||
|
// TODO: array: groups
|
|||
|
createCmd.Flags().StringVar(&createReq.Id, "id", createReq.Id, `Databricks user ID.`)
|
|||
|
// TODO: complex arg: name
|
|||
|
// TODO: array: roles
|
|||
|
createCmd.Flags().StringVar(&createReq.UserName, "user-name", createReq.UserName, `Email address of the Databricks user.`)
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
var createCmd = &cobra.Command{
|
|||
|
Use: "create",
|
|||
|
Short: `Create a new user.`,
|
|||
|
Long: `Create a new user.
|
|||
|
|
|||
|
Creates a new user in the Databricks Workspace. This new user will also be
|
|||
|
added to the Databricks account.`,
|
|||
|
|
|||
|
Annotations: map[string]string{},
|
|||
|
PreRunE: root.MustWorkspaceClient,
|
|||
|
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
|||
|
ctx := cmd.Context()
|
|||
|
w := root.WorkspaceClient(ctx)
|
|||
|
err = createJson.Unmarshal(&createReq)
|
|||
|
if err != nil {
|
|||
|
return err
|
|||
|
}
|
|||
|
createReq.Id = args[0]
|
|||
|
|
|||
|
response, err := w.Users.Create(ctx, createReq)
|
|||
|
if err != nil {
|
|||
|
return err
|
|||
|
}
|
|||
|
return cmdio.Render(ctx, response)
|
|||
|
},
|
|||
|
}
|
|||
|
|
|||
|
// start delete command
|
|||
|
|
|||
|
var deleteReq iam.DeleteUserRequest
|
|||
|
|
|||
|
func init() {
|
|||
|
Cmd.AddCommand(deleteCmd)
|
|||
|
// TODO: short flags
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
var deleteCmd = &cobra.Command{
|
|||
|
Use: "delete ID",
|
|||
|
Short: `Delete a user.`,
|
|||
|
Long: `Delete a user.
|
|||
|
|
|||
|
Deletes a user. Deleting a user from a Databricks Workspace also removes
|
|||
|
objects associated with the user.`,
|
|||
|
|
|||
|
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.Users.UserUserNameToIdMap(ctx, iam.ListUsersRequest{})
|
|||
|
if err != nil {
|
|||
|
return err
|
|||
|
}
|
|||
|
id, err := cmdio.Select(ctx, names, "Unique ID for a user in the Databricks Workspace")
|
|||
|
if err != nil {
|
|||
|
return err
|
|||
|
}
|
|||
|
args = append(args, id)
|
|||
|
}
|
|||
|
if len(args) != 1 {
|
|||
|
return fmt.Errorf("expected to have unique id for a user in the databricks workspace")
|
|||
|
}
|
|||
|
deleteReq.Id = args[0]
|
|||
|
|
|||
|
err = w.Users.Delete(ctx, deleteReq)
|
|||
|
if err != nil {
|
|||
|
return err
|
|||
|
}
|
|||
|
return nil
|
|||
|
},
|
|||
|
}
|
|||
|
|
|||
|
// start get command
|
|||
|
|
|||
|
var getReq iam.GetUserRequest
|
|||
|
|
|||
|
func init() {
|
|||
|
Cmd.AddCommand(getCmd)
|
|||
|
// TODO: short flags
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
var getCmd = &cobra.Command{
|
|||
|
Use: "get ID",
|
|||
|
Short: `Get user details.`,
|
|||
|
Long: `Get user details.
|
|||
|
|
|||
|
Gets information for a specific user in Databricks Workspace.`,
|
|||
|
|
|||
|
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.Users.UserUserNameToIdMap(ctx, iam.ListUsersRequest{})
|
|||
|
if err != nil {
|
|||
|
return err
|
|||
|
}
|
|||
|
id, err := cmdio.Select(ctx, names, "Unique ID for a user in the Databricks Workspace")
|
|||
|
if err != nil {
|
|||
|
return err
|
|||
|
}
|
|||
|
args = append(args, id)
|
|||
|
}
|
|||
|
if len(args) != 1 {
|
|||
|
return fmt.Errorf("expected to have unique id for a user in the databricks workspace")
|
|||
|
}
|
|||
|
getReq.Id = args[0]
|
|||
|
|
|||
|
response, err := w.Users.Get(ctx, getReq)
|
|||
|
if err != nil {
|
|||
|
return err
|
|||
|
}
|
|||
|
return cmdio.Render(ctx, response)
|
|||
|
},
|
|||
|
}
|
|||
|
|
|||
|
// start list command
|
|||
|
|
|||
|
var listReq iam.ListUsersRequest
|
|||
|
|
|||
|
func init() {
|
|||
|
Cmd.AddCommand(listCmd)
|
|||
|
// TODO: short flags
|
|||
|
|
|||
|
listCmd.Flags().StringVar(&listReq.Attributes, "attributes", listReq.Attributes, `Comma-separated list of attributes to return in response.`)
|
|||
|
listCmd.Flags().IntVar(&listReq.Count, "count", listReq.Count, `Desired number of results per page.`)
|
|||
|
listCmd.Flags().StringVar(&listReq.ExcludedAttributes, "excluded-attributes", listReq.ExcludedAttributes, `Comma-separated list of attributes to exclude in response.`)
|
|||
|
listCmd.Flags().StringVar(&listReq.Filter, "filter", listReq.Filter, `Query by which the results have to be filtered.`)
|
|||
|
listCmd.Flags().StringVar(&listReq.SortBy, "sort-by", listReq.SortBy, `Attribute to sort the results.`)
|
|||
|
listCmd.Flags().Var(&listReq.SortOrder, "sort-order", `The order to sort the results.`)
|
|||
|
listCmd.Flags().IntVar(&listReq.StartIndex, "start-index", listReq.StartIndex, `Specifies the index of the first result.`)
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
var listCmd = &cobra.Command{
|
|||
|
Use: "list",
|
|||
|
Short: `List users.`,
|
|||
|
Long: `List users.
|
|||
|
|
|||
|
Gets details for all the users associated with a Databricks Workspace.`,
|
|||
|
|
|||
|
Annotations: map[string]string{},
|
|||
|
Args: cobra.ExactArgs(0),
|
|||
|
PreRunE: root.MustWorkspaceClient,
|
|||
|
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
|||
|
ctx := cmd.Context()
|
|||
|
w := root.WorkspaceClient(ctx)
|
|||
|
|
|||
|
response, err := w.Users.ListAll(ctx, listReq)
|
|||
|
if err != nil {
|
|||
|
return err
|
|||
|
}
|
|||
|
return cmdio.Render(ctx, response)
|
|||
|
},
|
|||
|
}
|
|||
|
|
|||
|
// start patch command
|
|||
|
|
|||
|
var patchReq iam.PartialUpdate
|
|||
|
var patchJson flags.JsonFlag
|
|||
|
|
|||
|
func init() {
|
|||
|
Cmd.AddCommand(patchCmd)
|
|||
|
// TODO: short flags
|
|||
|
patchCmd.Flags().Var(&patchJson, "json", `either inline JSON string or @path/to/file.json with request body`)
|
|||
|
|
|||
|
// TODO: array: operations
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
var patchCmd = &cobra.Command{
|
|||
|
Use: "patch",
|
|||
|
Short: `Update user details.`,
|
|||
|
Long: `Update user details.
|
|||
|
|
|||
|
Partially updates a user resource by applying the supplied operations on
|
|||
|
specific user attributes.`,
|
|||
|
|
|||
|
Annotations: map[string]string{},
|
|||
|
PreRunE: root.MustWorkspaceClient,
|
|||
|
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
|||
|
ctx := cmd.Context()
|
|||
|
w := root.WorkspaceClient(ctx)
|
|||
|
err = patchJson.Unmarshal(&patchReq)
|
|||
|
if err != nil {
|
|||
|
return err
|
|||
|
}
|
|||
|
patchReq.Id = args[0]
|
|||
|
|
|||
|
err = w.Users.Patch(ctx, patchReq)
|
|||
|
if err != nil {
|
|||
|
return err
|
|||
|
}
|
|||
|
return nil
|
|||
|
},
|
|||
|
}
|
|||
|
|
|||
|
// start update command
|
|||
|
|
|||
|
var updateReq iam.User
|
|||
|
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`)
|
|||
|
|
|||
|
updateCmd.Flags().BoolVar(&updateReq.Active, "active", updateReq.Active, `If this user is active.`)
|
|||
|
updateCmd.Flags().StringVar(&updateReq.DisplayName, "display-name", updateReq.DisplayName, `String that represents a concatenation of given and family names.`)
|
|||
|
// TODO: array: emails
|
|||
|
// TODO: array: entitlements
|
|||
|
updateCmd.Flags().StringVar(&updateReq.ExternalId, "external-id", updateReq.ExternalId, ``)
|
|||
|
// TODO: array: groups
|
|||
|
updateCmd.Flags().StringVar(&updateReq.Id, "id", updateReq.Id, `Databricks user ID.`)
|
|||
|
// TODO: complex arg: name
|
|||
|
// TODO: array: roles
|
|||
|
updateCmd.Flags().StringVar(&updateReq.UserName, "user-name", updateReq.UserName, `Email address of the Databricks user.`)
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
var updateCmd = &cobra.Command{
|
|||
|
Use: "update",
|
|||
|
Short: `Replace a user.`,
|
|||
|
Long: `Replace a user.
|
|||
|
|
|||
|
Replaces a user's information with the data supplied in request.`,
|
|||
|
|
|||
|
Annotations: map[string]string{},
|
|||
|
PreRunE: root.MustWorkspaceClient,
|
|||
|
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
|||
|
ctx := cmd.Context()
|
|||
|
w := root.WorkspaceClient(ctx)
|
|||
|
err = updateJson.Unmarshal(&updateReq)
|
|||
|
if err != nil {
|
|||
|
return err
|
|||
|
}
|
|||
|
updateReq.Id = args[0]
|
|||
|
|
|||
|
err = w.Users.Update(ctx, updateReq)
|
|||
|
if err != nil {
|
|||
|
return err
|
|||
|
}
|
|||
|
return nil
|
|||
|
},
|
|||
|
}
|
|||
|
|
|||
|
// end service Users
|