2023-06-12 12:23:21 +00:00
|
|
|
// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT.
|
|
|
|
|
|
|
|
package access_control
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"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/iam"
|
|
|
|
"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: "access-control",
|
|
|
|
Short: `These APIs manage access rules on resources in an account.`,
|
|
|
|
Long: `These APIs manage access rules on resources in an account. Currently, only
|
2023-06-12 12:23:21 +00:00
|
|
|
grant rules are supported. A grant rule specifies a role assigned to a set of
|
|
|
|
principals. A list of rules attached to a resource is called a rule set.`,
|
2023-07-25 18:19:07 +00:00
|
|
|
GroupID: "iam",
|
|
|
|
Annotations: map[string]string{
|
|
|
|
"package": "iam",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply optional overrides to this command.
|
|
|
|
for _, fn := range cmdOverrides {
|
|
|
|
fn(cmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmd
|
2023-06-12 12:23:21 +00:00
|
|
|
}
|
|
|
|
|
2023-06-21 07:43:07 +00:00
|
|
|
// start get-assignable-roles-for-resource command
|
2023-06-12 12:23:21 +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 getAssignableRolesForResourceOverrides []func(
|
|
|
|
*cobra.Command,
|
|
|
|
*iam.GetAssignableRolesForResourceRequest,
|
|
|
|
)
|
2023-06-12 12:23:21 +00:00
|
|
|
|
2023-07-25 18:19:07 +00:00
|
|
|
func newGetAssignableRolesForResource() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{}
|
|
|
|
|
|
|
|
var getAssignableRolesForResourceReq iam.GetAssignableRolesForResourceRequest
|
2023-06-12 12:23:21 +00:00
|
|
|
|
2023-07-25 18:19:07 +00:00
|
|
|
// TODO: short flags
|
|
|
|
|
|
|
|
cmd.Use = "get-assignable-roles-for-resource RESOURCE"
|
|
|
|
cmd.Short = `Get assignable roles for a resource.`
|
|
|
|
cmd.Long = `Get assignable roles for a resource.
|
2023-06-12 12:23:21 +00:00
|
|
|
|
2023-06-21 07:43:07 +00:00
|
|
|
Gets all the roles that can be granted on an account level resource. A role is
|
|
|
|
grantable if the rule set on the resource can contain an access rule of the
|
2023-07-25 18:19:07 +00:00
|
|
|
role.`
|
|
|
|
|
|
|
|
cmd.Annotations = make(map[string]string)
|
2023-06-12 12:23:21 +00:00
|
|
|
|
2023-07-25 18:19:07 +00:00
|
|
|
cmd.Args = func(cmd *cobra.Command, args []string) error {
|
2023-06-21 07:43:07 +00:00
|
|
|
check := cobra.ExactArgs(1)
|
2023-06-12 12:23:21 +00:00
|
|
|
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-06-12 12:23:21 +00:00
|
|
|
ctx := cmd.Context()
|
|
|
|
a := root.AccountClient(ctx)
|
2023-07-03 11:20:30 +00:00
|
|
|
|
|
|
|
getAssignableRolesForResourceReq.Resource = args[0]
|
2023-06-12 12:23:21 +00:00
|
|
|
|
2023-06-21 07:43:07 +00:00
|
|
|
response, err := a.AccessControl.GetAssignableRolesForResource(ctx, getAssignableRolesForResourceReq)
|
2023-06-12 12:23:21 +00:00
|
|
|
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 getAssignableRolesForResourceOverrides {
|
|
|
|
fn(cmd, &getAssignableRolesForResourceReq)
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
cmdOverrides = append(cmdOverrides, func(cmd *cobra.Command) {
|
|
|
|
cmd.AddCommand(newGetAssignableRolesForResource())
|
|
|
|
})
|
2023-06-12 12:23:21 +00:00
|
|
|
}
|
|
|
|
|
2023-06-21 07:43:07 +00:00
|
|
|
// start get-rule-set command
|
2023-06-12 12:23:21 +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 getRuleSetOverrides []func(
|
|
|
|
*cobra.Command,
|
|
|
|
*iam.GetRuleSetRequest,
|
|
|
|
)
|
2023-06-12 12:23:21 +00:00
|
|
|
|
2023-07-25 18:19:07 +00:00
|
|
|
func newGetRuleSet() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{}
|
|
|
|
|
|
|
|
var getRuleSetReq iam.GetRuleSetRequest
|
|
|
|
|
|
|
|
// TODO: short flags
|
2023-06-12 12:23:21 +00:00
|
|
|
|
2023-07-25 18:19:07 +00:00
|
|
|
cmd.Use = "get-rule-set NAME ETAG"
|
|
|
|
cmd.Short = `Get a rule set.`
|
|
|
|
cmd.Long = `Get a rule set.
|
2023-06-12 12:23:21 +00:00
|
|
|
|
2023-06-21 07:43:07 +00:00
|
|
|
Get a rule set by its name. A rule set is always attached to a resource and
|
|
|
|
contains a list of access rules on the said resource. Currently only a default
|
2023-07-25 18:19:07 +00:00
|
|
|
rule set for each resource is supported.`
|
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-21 07:43:07 +00:00
|
|
|
check := cobra.ExactArgs(2)
|
2023-06-12 12:23:21 +00:00
|
|
|
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-06-12 12:23:21 +00:00
|
|
|
ctx := cmd.Context()
|
|
|
|
a := root.AccountClient(ctx)
|
2023-07-03 11:20:30 +00:00
|
|
|
|
|
|
|
getRuleSetReq.Name = args[0]
|
|
|
|
getRuleSetReq.Etag = args[1]
|
2023-06-12 12:23:21 +00:00
|
|
|
|
2023-06-21 07:43:07 +00:00
|
|
|
response, err := a.AccessControl.GetRuleSet(ctx, getRuleSetReq)
|
2023-06-12 12:23:21 +00:00
|
|
|
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 getRuleSetOverrides {
|
|
|
|
fn(cmd, &getRuleSetReq)
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
cmdOverrides = append(cmdOverrides, func(cmd *cobra.Command) {
|
|
|
|
cmd.AddCommand(newGetRuleSet())
|
|
|
|
})
|
2023-06-12 12:23:21 +00:00
|
|
|
}
|
|
|
|
|
2023-06-21 07:43:07 +00:00
|
|
|
// start update-rule-set command
|
2023-06-12 12:23:21 +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 updateRuleSetOverrides []func(
|
|
|
|
*cobra.Command,
|
|
|
|
*iam.UpdateRuleSetRequest,
|
|
|
|
)
|
2023-06-12 12:23:21 +00:00
|
|
|
|
2023-07-25 18:19:07 +00:00
|
|
|
func newUpdateRuleSet() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{}
|
|
|
|
|
|
|
|
var updateRuleSetReq iam.UpdateRuleSetRequest
|
|
|
|
var updateRuleSetJson flags.JsonFlag
|
|
|
|
|
|
|
|
// TODO: short flags
|
|
|
|
cmd.Flags().Var(&updateRuleSetJson, "json", `either inline JSON string or @path/to/file.json with request body`)
|
2023-06-12 12:23:21 +00:00
|
|
|
|
2023-07-25 18:19:07 +00:00
|
|
|
cmd.Use = "update-rule-set"
|
|
|
|
cmd.Short = `Update a rule set.`
|
|
|
|
cmd.Long = `Update a rule set.
|
2023-06-12 12:23:21 +00:00
|
|
|
|
|
|
|
Replace the rules of a rule set. First, use get to read the current version of
|
|
|
|
the rule set before modifying it. This pattern helps prevent conflicts between
|
2023-07-25 18:19:07 +00:00
|
|
|
concurrent updates.`
|
|
|
|
|
|
|
|
cmd.Annotations = make(map[string]string)
|
2023-06-12 12:23:21 +00:00
|
|
|
|
2023-07-25 18:19:07 +00:00
|
|
|
cmd.PreRunE = root.MustAccountClient
|
|
|
|
cmd.RunE = func(cmd *cobra.Command, args []string) (err error) {
|
2023-06-12 12:23:21 +00:00
|
|
|
ctx := cmd.Context()
|
|
|
|
a := root.AccountClient(ctx)
|
2023-07-03 11:20:30 +00:00
|
|
|
|
2023-06-12 12:23:21 +00:00
|
|
|
if cmd.Flags().Changed("json") {
|
2023-06-21 07:43:07 +00:00
|
|
|
err = updateRuleSetJson.Unmarshal(&updateRuleSetReq)
|
2023-06-12 12:23:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
2023-06-21 07:43:07 +00:00
|
|
|
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
|
2023-06-12 12:23:21 +00:00
|
|
|
}
|
|
|
|
|
2023-06-21 07:43:07 +00:00
|
|
|
response, err := a.AccessControl.UpdateRuleSet(ctx, updateRuleSetReq)
|
2023-06-12 12:23:21 +00:00
|
|
|
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 updateRuleSetOverrides {
|
|
|
|
fn(cmd, &updateRuleSetReq)
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
cmdOverrides = append(cmdOverrides, func(cmd *cobra.Command) {
|
|
|
|
cmd.AddCommand(newUpdateRuleSet())
|
|
|
|
})
|
2023-06-12 12:23:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// end service AccountAccessControl
|