feat(cli): Add support for Scope Storage Policy
This commit is contained in:
1 parent
45de26bfe9
commit
20897640cd
4 files changed
+66
-3
No files matched your search
@@ -942,6 +942,16 @@ func initCommands(ui, serverCmdUi cli.Ui, runOpts *RunOptions) {
|
||||
&scopescmd.DestroyKeyVersionCommand{
|
||||
Command: base.NewCommand(ui),
|
||||
}),
|
||||
"scopes attach-storage-policy": clientCacheWrapper(
|
||||
&scopescmd.Command{
|
||||
Command: base.NewCommand(ui),
|
||||
Func: "attach-storage-policy",
|
||||
}),
|
||||
"scopes detach-storage-policy": clientCacheWrapper(
|
||||
&scopescmd.Command{
|
||||
Command: base.NewCommand(ui),
|
||||
Func: "detach-storage-policy",
|
||||
}),
|
||||
|
||||
"search": func() (cli.Command, error) {
|
||||
return &unsupported.UnsupportedCommand{
|
||||
|
||||
@@ -17,18 +17,22 @@ const (
|
||||
flagPrimaryAuthMethodIdName = "primary-auth-method-id"
|
||||
flagSkipAdminRoleCreationName = "skip-admin-role-creation"
|
||||
flagSkipDefaultRoleCreationName = "skip-default-role-creation"
|
||||
flagStoragePolicyIdName = "storage-policy-id"
|
||||
)
|
||||
|
||||
func init() {
|
||||
extraActionsFlagsMapFunc = extraActionsFlagsMapFuncImpl
|
||||
extraFlagsFunc = extraFlagsFuncImpl
|
||||
extraFlagsHandlingFunc = extraFlagsHandlingFuncImpl
|
||||
executeExtraActions = executeExtraActionsImpl
|
||||
}
|
||||
|
||||
func extraActionsFlagsMapFuncImpl() map[string][]string {
|
||||
return map[string][]string{
|
||||
"create": {flagSkipAdminRoleCreationName, flagSkipDefaultRoleCreationName},
|
||||
"update": {flagPrimaryAuthMethodIdName},
|
||||
"create": {flagSkipAdminRoleCreationName, flagSkipDefaultRoleCreationName},
|
||||
"update": {flagPrimaryAuthMethodIdName},
|
||||
"attach-storage-policy": {"id", "version", flagStoragePolicyIdName},
|
||||
"detach-storage-policy": {"id", "version"},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +40,7 @@ type extraCmdVars struct {
|
||||
flagSkipAdminRoleCreation bool
|
||||
flagSkipDefaultRoleCreation bool
|
||||
flagPrimaryAuthMethodId string
|
||||
flagStoragePolicyId string
|
||||
}
|
||||
|
||||
func extraFlagsFuncImpl(c *Command, set *base.FlagSets, f *base.FlagSet) {
|
||||
@@ -59,6 +64,12 @@ func extraFlagsFuncImpl(c *Command, set *base.FlagSets, f *base.FlagSet) {
|
||||
Target: &c.flagPrimaryAuthMethodId,
|
||||
Usage: "If set, the primary auth method id for the scope. A primary auth method is allowed to create users on first login and is also used as a source for account full name and email for a scope's users",
|
||||
})
|
||||
case flagStoragePolicyIdName:
|
||||
f.StringVar(&base.StringVar{
|
||||
Name: flagStoragePolicyIdName,
|
||||
Target: &c.flagStoragePolicyId,
|
||||
Usage: "The public ID of the Storage Policy to attach to this scope. Can only attach to the global scope and an Org scope.",
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,6 +88,24 @@ func extraFlagsHandlingFuncImpl(c *Command, _ *base.FlagSets, opts *[]scopes.Opt
|
||||
return true
|
||||
}
|
||||
|
||||
func executeExtraActionsImpl(c *Command, origResp *api.Response, origItem *scopes.Scope, origItems []*scopes.Scope, origError error, scopeClient *scopes.Client, version uint32, opts []scopes.Option) (*api.Response, *scopes.Scope, []*scopes.Scope, error) {
|
||||
switch c.Func {
|
||||
case "attach-storage-policy":
|
||||
result, err := scopeClient.AttachStoragePolicy(c.Context, c.FlagId, version, c.flagStoragePolicyId, opts...)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
return result.GetResponse(), result.GetItem(), nil, err
|
||||
case "detach-storage-policy":
|
||||
result, err := scopeClient.DetachStoragePolicy(c.Context, c.FlagId, version, opts...)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
return result.GetResponse(), result.GetItem(), nil, err
|
||||
}
|
||||
return origResp, origItem, origItems, origError
|
||||
}
|
||||
|
||||
func (c *Command) printListTable(items []*scopes.Scope) string {
|
||||
if len(items) == 0 {
|
||||
return "No child scopes found"
|
||||
@@ -120,6 +149,11 @@ func (c *Command) printListTable(items []*scopes.Scope) string {
|
||||
fmt.Sprintf(" PrimaryAuthMethodId: %s", item.PrimaryAuthMethodId),
|
||||
)
|
||||
}
|
||||
if item.StoragePolicyId != "" {
|
||||
output = append(output,
|
||||
fmt.Sprintf(" StoragePolicyId: %s", item.StoragePolicyId),
|
||||
)
|
||||
}
|
||||
if len(item.AuthorizedActions) > 0 {
|
||||
output = append(output,
|
||||
" Authorized Actions:",
|
||||
@@ -154,6 +188,9 @@ func printItemTable(item *scopes.Scope, resp *api.Response) string {
|
||||
if item.PrimaryAuthMethodId != "" {
|
||||
nonAttributeMap["Primary Auth Method ID"] = item.PrimaryAuthMethodId
|
||||
}
|
||||
if item.StoragePolicyId != "" {
|
||||
nonAttributeMap["Storage Policy ID"] = item.StoragePolicyId
|
||||
}
|
||||
|
||||
maxLength := base.MaxAttributesLength(nonAttributeMap, nil, nil)
|
||||
|
||||
|
||||
@@ -221,6 +221,22 @@ func (c *Command) Run(args []string) int {
|
||||
version = uint32(c.FlagVersion)
|
||||
}
|
||||
|
||||
case "attach-storage-policy":
|
||||
switch c.FlagVersion {
|
||||
case 0:
|
||||
opts = append(opts, scopes.WithAutomaticVersioning(true))
|
||||
default:
|
||||
version = uint32(c.FlagVersion)
|
||||
}
|
||||
|
||||
case "detach-storage-policy":
|
||||
switch c.FlagVersion {
|
||||
case 0:
|
||||
opts = append(opts, scopes.WithAutomaticVersioning(true))
|
||||
default:
|
||||
version = uint32(c.FlagVersion)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ok := extraFlagsHandlingFunc(c, f, &opts); !ok {
|
||||
|
||||
@@ -580,7 +580,7 @@ var inputStructs = map[string][]*cmdInfo{
|
||||
Container: "Scope",
|
||||
HasName: true,
|
||||
HasDescription: true,
|
||||
VersionedActions: []string{"update"},
|
||||
VersionedActions: []string{"update", "attach-storage-policy", "detach-storage-policy"},
|
||||
},
|
||||
},
|
||||
"sessions": {
|
||||
|
||||
Reference in new issue
Block a user