diff --git a/pkg/cmd/create/accesspolicy.go b/pkg/cmd/create/accesspolicy.go index 1bf8d55..38b64d7 100644 --- a/pkg/cmd/create/accesspolicy.go +++ b/pkg/cmd/create/accesspolicy.go @@ -7,6 +7,7 @@ import ( "github.com/ibm-verify/verifyctl/pkg/cmd/resource" "github.com/ibm-verify/verifyctl/pkg/config" + "gopkg.in/yaml.v3" "github.com/ibm-verify/verify-sdk-go/pkg/config/security" contextx "github.com/ibm-verify/verify-sdk-go/pkg/core/context" @@ -44,8 +45,11 @@ You can identify the entitlement required by running: # Create an empty accessPolicy resource. This can be piped into a file. verifyctl create accesspolicy --boilerplate + # Create a accessPolicy using a YAML file. + verifyctl create -f=./accesspolicy.yaml + # Create a accessPolicy using a JSON file. - verifyctl create accesspolicy -f=./accesspolicy.json`)) + verifyctl create -f=./accesspolicy.json`)) ) type accessPolicyOptions struct { @@ -130,14 +134,12 @@ func (o *accessPolicyOptions) createAccessPolicy(cmd *cobra.Command) error { ctx := cmd.Context() vc := contextx.GetVerifyContext(ctx) - // get the contents of the file b, err := os.ReadFile(o.file) if err != nil { vc.Logger.Errorf("unable to read file; filename=%s, err=%v", o.file, err) return err } - // create accessPolicy with data return o.createAccessPolicyWithData(cmd, b) } @@ -145,9 +147,8 @@ func (o *accessPolicyOptions) createAccessPolicyWithData(cmd *cobra.Command, dat ctx := cmd.Context() vc := contextx.GetVerifyContext(ctx) - // unmarshal to accessPolicy accessPolicy := &security.Policy{} - if err := json.Unmarshal(data, &accessPolicy); err != nil { + if err := yaml.Unmarshal(data, &accessPolicy); err != nil { vc.Logger.Errorf("unable to unmarshal the accessPolicy; err=%v", err) return err } @@ -166,7 +167,6 @@ func (o *accessPolicyOptions) createAccessPolicyFromDataMap(cmd *cobra.Command, ctx := cmd.Context() vc := contextx.GetVerifyContext(ctx) - // unmarshal to accessPolicy accessPolicy := &security.Policy{} b, err := json.Marshal(data) if err != nil { diff --git a/pkg/cmd/create/api_client.go b/pkg/cmd/create/api_client.go index ad956fe..a2fc450 100644 --- a/pkg/cmd/create/api_client.go +++ b/pkg/cmd/create/api_client.go @@ -45,8 +45,7 @@ var ( # Create an empty API client resource. verifyctl create apiclient --boilerplate - - # Create an API client using a YAML file. + # Create an API client using a YAML file. verifyctl create -f=./apiclient.yaml # Create an API client using a JSON file. diff --git a/pkg/cmd/create/application.go b/pkg/cmd/create/application.go index 5dc0369..cf6b745 100644 --- a/pkg/cmd/create/application.go +++ b/pkg/cmd/create/application.go @@ -36,7 +36,7 @@ var ( verifyctl create application --boilerplate # Create an application using a YAML file. - verifyctl create application -f=./application.yaml`)) + verifyctl create -f=./application.yaml`)) ) type applicationOptions struct { diff --git a/pkg/cmd/create/attribute.go b/pkg/cmd/create/attribute.go index e05ea99..2143e3f 100644 --- a/pkg/cmd/create/attribute.go +++ b/pkg/cmd/create/attribute.go @@ -12,6 +12,7 @@ import ( cmdutil "github.com/ibm-verify/verifyctl/pkg/util/cmd" "github.com/ibm-verify/verifyctl/pkg/util/templates" "github.com/spf13/cobra" + "gopkg.in/yaml.v3" contextx "github.com/ibm-verify/verify-sdk-go/pkg/core/context" errorsx "github.com/ibm-verify/verify-sdk-go/pkg/core/errors" @@ -46,7 +47,7 @@ You can identify the entitlement required by running: verifyctl create attribute --boilerplate # Create an attribute using the API model in JSON format. - verifyctl create attribute -f=./customEmail.json`)) + verifyctl create -f=./customEmail.json`)) ) type attributeOptions struct { @@ -150,7 +151,7 @@ func (o *attributeOptions) createAttributeWithData(cmd *cobra.Command, data []by // unmarshal to attribute attribute := &directory.Attribute{} - if err := json.Unmarshal(data, &attribute); err != nil { + if err := yaml.Unmarshal(data, &attribute); err != nil { vc.Logger.Errorf("unable to unmarshal the attribute; err=%v", err) return err } diff --git a/pkg/cmd/create/group.go b/pkg/cmd/create/group.go index d0ea0e7..ed56a7e 100644 --- a/pkg/cmd/create/group.go +++ b/pkg/cmd/create/group.go @@ -7,6 +7,7 @@ import ( "github.com/ibm-verify/verifyctl/pkg/cmd/resource" "github.com/ibm-verify/verifyctl/pkg/config" + "gopkg.in/yaml.v3" "github.com/ibm-verify/verify-sdk-go/pkg/config/directory" cmdutil "github.com/ibm-verify/verifyctl/pkg/util/cmd" @@ -46,7 +47,7 @@ You can identify the entitlement required by running: verifyctl create group --boilerplate # Create a group using a JSON file. - verifyctl create group -f=./group.json`)) + verifyctl create -f=./group.json`)) ) type groupOptions struct { @@ -134,7 +135,7 @@ func (o *groupOptions) createGroup(cmd *cobra.Command) error { // get the contents of the file b, err := os.ReadFile(o.file) if err != nil { - vc.Logger.Errorf("unable to read file; filename=%s, err=%v", o.file, err) + vc.Logger.Errorf("Unable to read file; filename=%s, err=%v", o.file, err) return err } @@ -148,8 +149,8 @@ func (o *groupOptions) createGroupWithData(cmd *cobra.Command, data []byte) erro // unmarshal to group group := &directory.Group{} - if err := json.Unmarshal(data, &group); err != nil { - vc.Logger.Errorf("unable to unmarshal the group; err=%v", err) + if err := yaml.Unmarshal(data, &group); err != nil { + vc.Logger.Errorf("Unable to unmarshal the group; err=%v", err) return err } @@ -171,19 +172,19 @@ func (o *groupOptions) createGroupFromDataMap(cmd *cobra.Command, data map[strin group := &directory.Group{} b, err := json.Marshal(data) if err != nil { - vc.Logger.Errorf("failed to marshal the data map; err=%v", err) + vc.Logger.Errorf("Failed to marshal the data map; err=%v", err) return err } if err := json.Unmarshal(b, group); err != nil { - vc.Logger.Errorf("unable to unmarshal to an group; err=%v", err) + vc.Logger.Errorf("Unable to unmarshal to an group; err=%v", err) return err } client := directory.NewGroupClient() resourceURI, err := client.CreateGroup(ctx, group) if err != nil { - vc.Logger.Errorf("unable to create the group; err=%v, group=%+v", err, group) + vc.Logger.Errorf("Unable to create the group; err=%v, group=%+v", err, group) return err } diff --git a/pkg/cmd/create/identity_agent.go b/pkg/cmd/create/identity_agent.go index 9e7225a..3bfe6ee 100644 --- a/pkg/cmd/create/identity_agent.go +++ b/pkg/cmd/create/identity_agent.go @@ -10,6 +10,7 @@ import ( "github.com/ibm-verify/verifyctl/pkg/config" cmdutil "github.com/ibm-verify/verifyctl/pkg/util/cmd" "github.com/ibm-verify/verifyctl/pkg/util/templates" + "gopkg.in/yaml.v3" contextx "github.com/ibm-verify/verify-sdk-go/pkg/core/context" errorsx "github.com/ibm-verify/verify-sdk-go/pkg/core/errors" @@ -149,7 +150,7 @@ func (o *identityAgentOptions) createIdentityAgentWithData(cmd *cobra.Command, d vc := contextx.GetVerifyContext(ctx) identityAgentConfig := &integrations.IdentityAgentConfig{} - if err := json.Unmarshal(data, &identityAgentConfig); err != nil { + if err := yaml.Unmarshal(data, &identityAgentConfig); err != nil { vc.Logger.Errorf("unable to unmarshal Identity Agent; err=%v", err) return err } diff --git a/pkg/cmd/create/identity_provider.go b/pkg/cmd/create/identity_provider.go index d129eb0..2025487 100644 --- a/pkg/cmd/create/identity_provider.go +++ b/pkg/cmd/create/identity_provider.go @@ -8,6 +8,7 @@ import ( "github.com/ibm-verify/verify-sdk-go/pkg/config/authentication" "github.com/ibm-verify/verifyctl/pkg/cmd/resource" "github.com/ibm-verify/verifyctl/pkg/config" + "gopkg.in/yaml.v3" cmdutil "github.com/ibm-verify/verifyctl/pkg/util/cmd" "github.com/ibm-verify/verifyctl/pkg/util/templates" @@ -45,8 +46,11 @@ You can identify the entitlement required by running: # Create an empty identitySource resource. This can be piped into a file. verifyctl create identitysource --boilerplate + # Create a identitySource using a YAML file. + verifyctl create -f=./identitysource.yaml + # Create a identitySource using a JSON file. - verifyctl create identitysource -f=./identitysource.json`)) + verifyctl create -f=./identitysource.json`)) ) type identitySourceOptions struct { @@ -138,7 +142,6 @@ func (o *identitySourceOptions) createIdentitySource(cmd *cobra.Command) error { return err } - // create identitySource with data return o.createIdentitySourceWithData(cmd, b) } @@ -146,9 +149,8 @@ func (o *identitySourceOptions) createIdentitySourceWithData(cmd *cobra.Command, ctx := cmd.Context() vc := contextx.GetVerifyContext(ctx) - // unmarshal to identitySource identitySource := &authentication.IdentitySource{} - if err := json.Unmarshal(data, &identitySource); err != nil { + if err := yaml.Unmarshal(data, &identitySource); err != nil { vc.Logger.Errorf("unable to unmarshal the Identity Source err=%v", err) return err } @@ -167,7 +169,6 @@ func (o *identitySourceOptions) createIdentitySourceFromDataMap(cmd *cobra.Comma ctx := cmd.Context() vc := contextx.GetVerifyContext(ctx) - // unmarshal to identitySource identitySource := &authentication.IdentitySource{} b, err := json.Marshal(data) if err != nil { diff --git a/pkg/cmd/create/password_policy.go b/pkg/cmd/create/password_policy.go index 6f49474..a2f5e89 100644 --- a/pkg/cmd/create/password_policy.go +++ b/pkg/cmd/create/password_policy.go @@ -50,7 +50,7 @@ You can identify the entitlement required by running: verifyctl create passwordpolicy --boilerplate # Create a password policy using the API model in YAML format. -verifyctl create passwordpolicy -f=./password_Policy.yaml`, +verifyctl create -f=./password_Policy.yaml`, ), ) ) diff --git a/pkg/cmd/create/user.go b/pkg/cmd/create/user.go index bb3fe5f..0989ebf 100644 --- a/pkg/cmd/create/user.go +++ b/pkg/cmd/create/user.go @@ -7,6 +7,7 @@ import ( "github.com/ibm-verify/verifyctl/pkg/cmd/resource" "github.com/ibm-verify/verifyctl/pkg/config" + "gopkg.in/yaml.v3" "github.com/ibm-verify/verify-sdk-go/pkg/config/directory" cmdutil "github.com/ibm-verify/verifyctl/pkg/util/cmd" @@ -45,8 +46,11 @@ You can identify the entitlement required by running: # Create an empty user resource. This can be piped into a file. verifyctl create user --boilerplate + # Create a user using a YAML file. + verifyctl create -f "./user.yaml + # Create a user using a JSON file. - verifyctl create user -f=./user.json`)) + verifyctl create -f "./user.json"`)) ) type userOptions struct { @@ -134,7 +138,7 @@ func (o *userOptions) createUser(cmd *cobra.Command) error { // get the contents of the file b, err := os.ReadFile(o.file) if err != nil { - vc.Logger.Errorf("unable to read file; filename=%s, err=%v", o.file, err) + vc.Logger.Errorf("Unable to read file; filename=%s, err=%v", o.file, err) return err } @@ -148,7 +152,7 @@ func (o *userOptions) createUserWithData(cmd *cobra.Command, data []byte) error // unmarshal to user user := &directory.User{} - if err := json.Unmarshal(data, &user); err != nil { + if err := yaml.Unmarshal(data, &user); err != nil { vc.Logger.Errorf("unable to unmarshal the user; err=%v", err) return err } diff --git a/pkg/cmd/delete/accesspolicy.go b/pkg/cmd/delete/accesspolicy.go index 509f1af..8e12b2b 100644 --- a/pkg/cmd/delete/accesspolicy.go +++ b/pkg/cmd/delete/accesspolicy.go @@ -101,9 +101,7 @@ func (o *accessPoliciesOptions) Run(cmd *cobra.Command, args []string) error { return err } - // invoke the operation if cmd.CalledAs() == "accesspolicy" || len(o.accessPolicyID) > 0 { - // deal with single accessPolicy return o.handleSingleAccessPolicy(cmd, args) } return nil diff --git a/pkg/cmd/delete/attribute.go b/pkg/cmd/delete/attribute.go new file mode 100644 index 0000000..b95804d --- /dev/null +++ b/pkg/cmd/delete/attribute.go @@ -0,0 +1,110 @@ +package delete + +import ( + "io" + + "github.com/ibm-verify/verify-sdk-go/pkg/config/directory" + errorsx "github.com/ibm-verify/verify-sdk-go/pkg/core/errors" + "github.com/ibm-verify/verify-sdk-go/pkg/i18n" + "github.com/ibm-verify/verifyctl/pkg/config" + cmdutil "github.com/ibm-verify/verifyctl/pkg/util/cmd" + "github.com/ibm-verify/verifyctl/pkg/util/templates" + "github.com/spf13/cobra" +) + +const ( + attributeUsage = "attribute [options]" + attributeMessagePrefix = "DeleteAttribute" + attributeEntitlements = "Manage attributes" + attributeResourceName = "attribute" +) + +var ( + attributeLongDesc = templates.LongDesc(cmdutil.TranslateLongDesc(attributeMessagePrefix, ` + Delete an attribute in IBM Security Verify based on attribute ID. + Resources managed on Verify have specific entitlements, so ensure that the + application or API client used with the 'auth' command is configured with + the appropriate entitlements. + + You can identify the entitlement required by running: + verifyctl delete attribute --entitlements`)) + + attributeExamples = templates.Examples(cmdutil.TranslateExamples(attributeMessagePrefix, ` + # Delete an attribute by ID + verifyctl delete attribute --id=some-attribute-id + `)) +) + +type attributeOptions struct { + options + id string + config *config.CLIConfig +} + +func NewAttributeCommand(config *config.CLIConfig, streams io.ReadWriter) *cobra.Command { + o := &attributeOptions{ + config: config, + } + cmd := &cobra.Command{ + Use: attributeUsage, + Short: cmdutil.TranslateShortDesc(attributeMessagePrefix, "Delete Verify attribute based on attribute ID."), + Long: attributeLongDesc, + Example: attributeExamples, + DisableFlagsInUseLine: true, + Run: func(cmd *cobra.Command, args []string) { + cmdutil.ExitOnError(cmd, o.Complete(cmd, args)) + cmdutil.ExitOnError(cmd, o.Validate(cmd, args)) + cmdutil.ExitOnError(cmd, o.Run(cmd, args)) + }, + } + cmd.SetOut(streams) + cmd.SetErr(streams) + cmd.SetIn(streams) + o.AddFlags(cmd) + return cmd +} + +func (o *attributeOptions) AddFlags(cmd *cobra.Command) { + o.addCommonFlags(cmd) + cmd.Flags().StringVar(&o.id, "id", o.id, i18n.Translate("Identifier of the attribute to delete. (Required)")) +} + +func (o *attributeOptions) Complete(cmd *cobra.Command, args []string) error { + return nil +} + +func (o *attributeOptions) Validate(cmd *cobra.Command, args []string) error { + if o.entitlements { + return nil + } + calledAs := cmd.CalledAs() + if calledAs == "attribute" && o.id == "" { + return errorsx.G11NError(i18n.Translate("The 'id' flag is required to delete an attribute")) + } + return nil +} + +func (o *attributeOptions) Run(cmd *cobra.Command, args []string) error { + if o.entitlements { + cmdutil.WriteString(cmd, entitlementsMessage+" "+attributeEntitlements) + return nil + } + _, err := o.config.SetAuthToContext(cmd.Context()) + if err != nil { + return err + } + if cmd.CalledAs() == "attribute" || len(o.id) > 0 { + return o.handleSingleAttribute(cmd, args) + } + return nil +} + +func (o *attributeOptions) handleSingleAttribute(cmd *cobra.Command, _ []string) error { + c := directory.NewAttributeClient() + err := c.DeleteAttributeByID(cmd.Context(), o.id) + if err != nil { + return err + } + cmdutil.WriteString(cmd, "Resource deleted: "+o.id) + return nil +} diff --git a/pkg/cmd/delete/delete.go b/pkg/cmd/delete/delete.go index 310de9a..11ff5ad 100644 --- a/pkg/cmd/delete/delete.go +++ b/pkg/cmd/delete/delete.go @@ -77,6 +77,7 @@ func NewCommand(config *config.CLIConfig, streams io.ReadWriter, groupID string) cmd.AddCommand(NewApplicationCommand(config, streams)) cmd.AddCommand(NewIdentityAgentCommand(config, streams)) cmd.AddCommand(NewPasswordPolicyCommand(config, streams)) + cmd.AddCommand(NewAttributeCommand(config, streams)) cmd.AddCommand(NewPersonalCertCommand(config, streams)) cmd.AddCommand(NewSignerCertCommand(config, streams)) diff --git a/pkg/cmd/delete/identity_provider.go b/pkg/cmd/delete/identity_provider.go index 0c01964..b451c87 100644 --- a/pkg/cmd/delete/identity_provider.go +++ b/pkg/cmd/delete/identity_provider.go @@ -101,9 +101,7 @@ func (o *identitySourcesOptions) Run(cmd *cobra.Command, args []string) error { return err } - // invoke the operation if cmd.CalledAs() == "identitysource" || len(o.identitySourceID) > 0 { - // deal with single identitySource return o.handleSingleIdentitySource(cmd, args) } return nil diff --git a/pkg/cmd/delete/user.go b/pkg/cmd/delete/user.go index 9ebec25..fec63fa 100644 --- a/pkg/cmd/delete/user.go +++ b/pkg/cmd/delete/user.go @@ -32,7 +32,7 @@ You can identify the entitlement required by running: usersExamples = templates.Examples(cmdutil.TranslateExamples(messagePrefix, ` # Delete an user - verifyctl delete user --name=userName`, + verifyctl delete user --userName=userName`, )) ) diff --git a/pkg/cmd/get/accesspolicy.go b/pkg/cmd/get/accesspolicy.go index 8f64545..c955e4d 100644 --- a/pkg/cmd/get/accesspolicy.go +++ b/pkg/cmd/get/accesspolicy.go @@ -35,8 +35,8 @@ You can identify the entitlement required by running: # Get an accessPolicy and print the output in yaml verifyctl get accesspolicy -o=yaml --ID=testAccesspolicyID - # Get 10 accessPolicies based on a given search criteria and sort it in the ascending order by name. - verifyctl get accesspolicies --count=2 --sort=accessPolicyName -o=yaml`)) + # Get 2 accessPolicies . + verifyctl get accesspolicies --limit=2 --page=1 -o=yaml`)) ) type accessPoliciesOptions struct { @@ -76,7 +76,8 @@ func NewAccesspoliciesCommand(config *config.CLIConfig, streams io.ReadWriter) * func (o *accessPoliciesOptions) AddFlags(cmd *cobra.Command) { o.addCommonFlags(cmd, accessPolicyResourceName) cmd.Flags().StringVar(&o.accessPolicyID, "accessPolicyID", o.accessPolicyID, i18n.Translate("accessPolicyID to get details")) - + o.addSortFlags(cmd, accessPolicyResourceName) + o.addPaginationFlags(cmd, accessPolicyResourceName) } func (o *accessPoliciesOptions) Complete(cmd *cobra.Command, args []string) error { @@ -108,7 +109,6 @@ func (o *accessPoliciesOptions) Run(cmd *cobra.Command, args []string) error { // invoke the operation if cmd.CalledAs() == "accesspolicy" || len(o.accessPolicyID) > 0 { - // deal with single accessPolicy return o.handleSingleAccesspolicy(cmd, args) } @@ -151,7 +151,7 @@ func (o *accessPoliciesOptions) handleSingleAccesspolicy(cmd *cobra.Command, _ [ func (o *accessPoliciesOptions) handleAccesspolicyList(cmd *cobra.Command, _ []string) error { c := security.NewAccessPolicyClient() - accessPolicies, uri, err := c.GetAccessPolicies(cmd.Context(), 0, 0) + accessPolicies, uri, err := c.GetAccessPolicies(cmd.Context(), o.page, o.limit) if err != nil { return err } @@ -179,7 +179,7 @@ func (o *accessPoliciesOptions) handleAccesspolicyList(cmd *cobra.Command, _ []s APIVersion: "5.0", Metadata: &resource.ResourceObjectMetadata{ URI: uri, - Total: int(accessPolicies.Total), + Total: len(items), }, Items: items, } diff --git a/pkg/cmd/get/api_client.go b/pkg/cmd/get/api_client.go index b60c67f..d880d4a 100644 --- a/pkg/cmd/get/api_client.go +++ b/pkg/cmd/get/api_client.go @@ -36,9 +36,8 @@ You can identify the entitlement required by running: verifyctl get apiclient -o=yaml --clientName=testApiclient verifyctl get apiclient -o=yaml --clientID=12345 - - # Get 2 apiclients based on a given search criteria and sort it in the ascending order by name. - verifyctl get apiclients --count=2 --sort=apiclientName -o=yaml`)) + # Get 2 apiclients + verifyctl get apiclients --limit=2 --page=1 -o=yaml`)) ) type apiclientsOptions struct { @@ -80,7 +79,7 @@ func (o *apiclientsOptions) AddFlags(cmd *cobra.Command) { cmd.Flags().StringVar(&o.name, "clientName", o.name, i18n.Translate("clientName to get details")) cmd.Flags().StringVar(&o.id, "clientID", o.id, i18n.Translate("clientID to get details")) o.addSortFlags(cmd, apiclientResourceName) - o.addCountFlags(cmd, apiclientResourceName) + o.addPaginationFlags(cmd, apiclientResourceName) } func (o *apiclientsOptions) Complete(cmd *cobra.Command, args []string) error { @@ -192,7 +191,7 @@ func (o *apiclientsOptions) handleAPIClientList(cmd *cobra.Command, _ []string) APIVersion: "1.0", Metadata: &resource.ResourceObjectMetadata{ URI: uri, - Total: int(*apiclis.Total), + Total: len(items), }, Items: items, } diff --git a/pkg/cmd/get/application.go b/pkg/cmd/get/application.go index b4ccb55..9da1f89 100644 --- a/pkg/cmd/get/application.go +++ b/pkg/cmd/get/application.go @@ -30,8 +30,8 @@ var ( # Get an application and print the output in yaml verifyctl get application -o=yaml --applicationID=testApplicationID - # Get 10 applications based on a given search criteria and sort it in the ascending order by name. - verifyctl get applications --count=2 --sort=applicationName -o=yaml`)) + # Get 2 applications + verifyctl get applications --limit=2 --page=1 -o=yaml`)) ) type applicationsOptions struct { @@ -68,7 +68,7 @@ func (o *applicationsOptions) AddFlags(cmd *cobra.Command) { o.addCommonFlags(cmd, applicationResourceName) cmd.Flags().StringVar(&o.applicationID, "applicationID", o.applicationID, i18n.Translate("applicationID to get details")) o.addSortFlags(cmd, applicationResourceName) - o.addCountFlags(cmd, applicationResourceName) + o.addPaginationFlags(cmd, applicationResourceName) } func (o *applicationsOptions) Complete(cmd *cobra.Command, args []string) error { @@ -164,7 +164,7 @@ func (o *applicationsOptions) handleApplicationClientList(cmd *cobra.Command, _ APIVersion: "1.0", Metadata: &resource.ResourceObjectMetadata{ URI: uri, - Total: int(*appls.TotalCount), + Total: len(items), }, Items: items, } diff --git a/pkg/cmd/get/attributes.go b/pkg/cmd/get/attributes.go index 55a020b..48b4cd6 100644 --- a/pkg/cmd/get/attributes.go +++ b/pkg/cmd/get/attributes.go @@ -35,7 +35,7 @@ You can identify the entitlement required by running: # Get an attribute and print the output in yaml verifyctl get attribute -o=yaml --id=work_email - # Get 10 attributes based on a given search criteria and sort it in the ascending order by name. + # Get 2 attributes based on a given search criteria and sort it in the ascending order by name. verifyctl get attributes --search="tags=\"sso\"" --limit=10 --page=1 --sort=+name -o=yaml`)) ) @@ -108,9 +108,7 @@ func (o *attributesOptions) Run(cmd *cobra.Command, args []string) error { return err } - // invoke the operation if cmd.CalledAs() == "attribute" || len(o.id) > 0 { - // deal with single attribute return o.handleSingleAttribute(cmd, args) } @@ -183,7 +181,7 @@ func (o *attributesOptions) handleAttributeList(cmd *cobra.Command, _ []string) URI: uri, Limit: attrs.Limit, Count: attrs.Count, - Total: attrs.Total, + Total: len(items), Page: attrs.Page, }, Items: items, diff --git a/pkg/cmd/get/get.go b/pkg/cmd/get/get.go index c6d13a9..3e13315 100644 --- a/pkg/cmd/get/get.go +++ b/pkg/cmd/get/get.go @@ -98,7 +98,7 @@ func NewCommand(config *config.CLIConfig, streams io.ReadWriter, groupID string) func (o *options) addCommonFlags(cmd *cobra.Command, resourceName string) { cmd.Flags().BoolVar(&o.entitlements, "entitlements", o.entitlements, i18n.TranslateWithArgs("List the entitlements that can be configured to grant access to the %s. This is useful to know what to configure on the application or API client used to generate the login token. When this flag is used, the others are ignored.", resourceName)) - cmd.Flags().StringVarP(&o.output, "output", "o", "", i18n.Translate("Select the format of the output. The values supported are 'json' , 'yaml' and 'raw'. Default: 'json'.")) + cmd.Flags().StringVarP(&o.output, "output", "o", "", i18n.Translate("Select the format of the output. The values supported are 'json' , 'yaml' and 'raw'. Default: 'yaml'.")) } func (o *options) addIdFlag(cmd *cobra.Command, resourceName string) { diff --git a/pkg/cmd/get/group.go b/pkg/cmd/get/group.go index 887e030..091ef35 100644 --- a/pkg/cmd/get/group.go +++ b/pkg/cmd/get/group.go @@ -35,7 +35,7 @@ You can identify the entitlement required by running: # Get an group and print the output in yaml verifyctl get group -o=yaml --displayName=admin - # Get 10 groups based on a given search criteria and sort it in the ascending order by name. + # Get 2 groups based on a given search criteria and sort it in the ascending order by name. verifyctl get groups --count=2 --sort=groupName -o=yaml`)) ) @@ -107,9 +107,7 @@ func (o *groupsOptions) Run(cmd *cobra.Command, args []string) error { return err } - // invoke the operation if cmd.CalledAs() == "group" || len(o.name) > 0 { - // deal with single group return o.handleSingleGroup(cmd, args) } @@ -178,7 +176,7 @@ func (o *groupsOptions) handleGroupList(cmd *cobra.Command, _ []string) error { APIVersion: "2.0", Metadata: &resource.ResourceObjectMetadata{ URI: uri, - Total: int(grps.TotalResults), + Total: len(items), }, Items: items, } diff --git a/pkg/cmd/get/identity_agents.go b/pkg/cmd/get/identity_agents.go index e0786fe..ccb89cf 100644 --- a/pkg/cmd/get/identity_agents.go +++ b/pkg/cmd/get/identity_agents.go @@ -35,8 +35,11 @@ You can identify the entitlement required by running: # Get an identityAgent and print the output in yaml verifyctl get identityagent -o=yaml --identityAgentID=testIdentityAgent - # Get 10 identityAgents based on a given search criteria and sort it in the ascending order by name. - verifyctl get identityagents --count=2 --sort=identityAgentName -o=yaml`)) + #get all identityAgents + verifyctl get identityagents + + # Get 2 identityAgents based on a given page and limit number. + verifyctl get identityagents --limit=2 --page=1 -o=yaml`)) ) type identityAgentsOptions struct { @@ -77,7 +80,7 @@ func (o *identityAgentsOptions) AddFlags(cmd *cobra.Command) { o.addCommonFlags(cmd, identityAgentResourceName) cmd.Flags().StringVar(&o.identityAgentID, "identityAgentID", o.identityAgentID, i18n.Translate("identityAgentID to get details")) o.addSortFlags(cmd, identityAgentResourceName) - o.addCountFlags(cmd, identityAgentResourceName) + o.addPaginationFlags(cmd, identityAgentResourceName) } func (o *identityAgentsOptions) Complete(cmd *cobra.Command, args []string) error { @@ -178,7 +181,7 @@ func (o *identityAgentsOptions) handleIdentityAgentList(cmd *cobra.Command, _ [] APIVersion: "1.0", Metadata: &resource.ResourceObjectMetadata{ URI: uri, - Total: 10, + Total: len(items), }, Items: items, } diff --git a/pkg/cmd/get/identity_provider.go b/pkg/cmd/get/identity_provider.go index 7ae99a5..3064b30 100644 --- a/pkg/cmd/get/identity_provider.go +++ b/pkg/cmd/get/identity_provider.go @@ -35,8 +35,8 @@ You can identify the entitlement required by running: # Get an identitySource and print the output in yaml verifyctl get identitysource -o=yaml --identitySourceID="identitySourceID" - # Get 10 identitySources based on a given search criteria and sort it in the ascending order by name. - verifyctl get identitysources --count=2 --sort=identitysourceName -o=yaml`)) + # Get 2 identitySources + verifyctl get identitysources --limit=1 --page=1 -o=yaml`)) ) type identitySourcesOptions struct { @@ -78,6 +78,7 @@ func (o *identitySourcesOptions) AddFlags(cmd *cobra.Command) { cmd.Flags().StringVar(&o.identitySourceID, "identitySourceID", o.identitySourceID, i18n.Translate("IdentitySourceID to get details")) o.addSortFlags(cmd, identitySourceResourceName) o.addCountFlags(cmd, identitySourceResourceName) + o.addPaginationFlags(cmd, identitySourceResourceName) } func (o *identitySourcesOptions) Complete(cmd *cobra.Command, args []string) error { @@ -107,9 +108,7 @@ func (o *identitySourcesOptions) Run(cmd *cobra.Command, args []string) error { return err } - // invoke the operation if cmd.CalledAs() == "identitysource" || len(o.identitySourceID) > 0 { - // deal with single identitySource return o.handleSingleIdentitySource(cmd, args) } @@ -151,7 +150,7 @@ func (o *identitySourcesOptions) handleSingleIdentitySource(cmd *cobra.Command, func (o *identitySourcesOptions) handleIdentitySourceList(cmd *cobra.Command, _ []string) error { c := authentication.NewIdentitySourceClient() - iss, uri, err := c.GetIdentitySources(cmd.Context(), o.sort, o.count, 0, 0) + iss, uri, err := c.GetIdentitySources(cmd.Context(), o.sort, o.count, o.page, o.limit) if err != nil { return err } @@ -178,7 +177,7 @@ func (o *identitySourcesOptions) handleIdentitySourceList(cmd *cobra.Command, _ APIVersion: "2.0", Metadata: &resource.ResourceObjectMetadata{ URI: uri, - Total: int(iss.Total), + Total: len(items), }, Items: items, } diff --git a/pkg/cmd/get/password_policy.go b/pkg/cmd/get/password_policy.go index a471121..46e4fde 100644 --- a/pkg/cmd/get/password_policy.go +++ b/pkg/cmd/get/password_policy.go @@ -35,8 +35,8 @@ verifyctl get passwordpolicy --entitlements`)) # Get a specific password policy by ID verifyctl get passwordpolicy -o=yaml --passwordPolicyID=testPasswordPolicyID -# Get 10 policies based on a given search criteria and sort it in the ascending order by name. - verifyctl get password-policies --count=2 --sort=policyName -o=yaml +# Get all policies + verifyctl get passwordpolicies -o=yaml `)) ) @@ -77,8 +77,6 @@ func newPasswordPolicyCommand(config *config.CLIConfig, streams io.ReadWriter) * func (o *passwordPolicyOptions) AddFlags(cmd *cobra.Command) { o.addCommonFlags(cmd, passwordPolicyResourceName) cmd.Flags().StringVar(&o.passwordPolicyID, "passwordPolicyID", o.passwordPolicyID, i18n.Translate("passwordPolicyID to get details")) - o.addSortFlags(cmd, passwordPolicyResourceName) - o.addCountFlags(cmd, passwordPolicyResourceName) } func (o *passwordPolicyOptions) Complete(cmd *cobra.Command, args []string) error { @@ -151,7 +149,7 @@ func (o *passwordPolicyOptions) handleSinglePasswordPolicy(cmd *cobra.Command, _ func (o *passwordPolicyOptions) handlePasswordPolicyList(cmd *cobra.Command, _ []string) error { c := security.NewPasswordPolicyClient() - pwds, uri, err := c.GetPasswordPolicies(cmd.Context(), o.sort, o.count) + pwds, uri, err := c.GetPasswordPolicies(cmd.Context(), "", "") if err != nil { return err } @@ -179,7 +177,7 @@ func (o *passwordPolicyOptions) handlePasswordPolicyList(cmd *cobra.Command, _ [ APIVersion: "3.0", Metadata: &resource.ResourceObjectMetadata{ URI: uri, - Total: pwds.TotalResults, + Total: len(items), }, Items: items, } diff --git a/pkg/cmd/get/personal_cert.go b/pkg/cmd/get/personal_cert.go index 50629ed..8271c75 100644 --- a/pkg/cmd/get/personal_cert.go +++ b/pkg/cmd/get/personal_cert.go @@ -32,9 +32,8 @@ var ( # Get a specific personal certificate by lable verifyctl get personalCert -o=yaml --personalCertLabel=testpersonalCert - # Get 2 policies based on a given search criteria and sort it in the ascending order by name. - verifyctl get personalCerts --count=2 --sort=personalCertLabel -o=yaml - `)) + # Get all certificates + verifyctl get personalCerts -o=yaml `)) ) type personalCertOptions struct { @@ -70,8 +69,6 @@ func newPersonalCertCommand(config *config.CLIConfig, streams io.ReadWriter) *co func (o *personalCertOptions) AddFlags(cmd *cobra.Command) { o.addCommonFlags(cmd, personalCertResourceName) cmd.Flags().StringVar(&o.label, "personalCertLabel", o.label, i18n.Translate("personalCertName to get details")) - o.addSortFlags(cmd, personalCertResourceName) - o.addCountFlags(cmd, personalCertResourceName) } func (o *personalCertOptions) Complete(cmd *cobra.Command, args []string) error { @@ -179,7 +176,8 @@ func (o *personalCertOptions) handlePersonalCertList(cmd *cobra.Command, _ []str Kind: resource.ResourceTypePrefix + "List", APIVersion: "1.0", Metadata: &resource.ResourceObjectMetadata{ - URI: uri, + URI: uri, + Total: len(items), }, Items: items, } diff --git a/pkg/cmd/get/signer_cert.go b/pkg/cmd/get/signer_cert.go index 252a51f..f8be2b0 100644 --- a/pkg/cmd/get/signer_cert.go +++ b/pkg/cmd/get/signer_cert.go @@ -32,8 +32,8 @@ var ( # Get a specific Signer certificate by lable verifyctl get signerCert -o=yaml --signerCertLabel=testsignerCert - # Get 2 policies based on a given search criteria and sort it in the ascending order by name. - verifyctl get signerCerts --count=2 --sort=signerCertLabel -o=yaml + # Get all certificates + verifyctl get signerCerts -o=yaml `)) ) @@ -70,8 +70,7 @@ func newSignerCertCommand(config *config.CLIConfig, streams io.ReadWriter) *cobr func (o *signerCertOptions) AddFlags(cmd *cobra.Command) { o.addCommonFlags(cmd, signerCertResourceName) cmd.Flags().StringVar(&o.label, "signerCertLabel", o.label, i18n.Translate("signerCertName to get details")) - o.addSortFlags(cmd, signerCertResourceName) - o.addCountFlags(cmd, signerCertResourceName) + } func (o *signerCertOptions) Complete(cmd *cobra.Command, args []string) error { @@ -183,7 +182,8 @@ func (o *signerCertOptions) handleSignerCertList(cmd *cobra.Command, _ []string) Kind: resource.ResourceTypePrefix + "List", APIVersion: "1.0", Metadata: &resource.ResourceObjectMetadata{ - URI: uri, + URI: uri, + Total: len(items), }, Items: items, } diff --git a/pkg/cmd/get/user.go b/pkg/cmd/get/user.go index 4f936bc..b73e851 100644 --- a/pkg/cmd/get/user.go +++ b/pkg/cmd/get/user.go @@ -35,7 +35,7 @@ You can identify the entitlement required by running: # Get an user and print the output in yaml verifyctl get user -o=yaml --userName=testUser - # Get 10 users based on a given search criteria and sort it in the ascending order by name. + # Get 2 users based on a given search criteria and sort it in the ascending order by name. verifyctl get users --count=2 --sort=userName -o=yaml`)) ) @@ -180,7 +180,7 @@ func (o *usersOptions) handleUserList(cmd *cobra.Command, _ []string) error { APIVersion: "2.0", Metadata: &resource.ResourceObjectMetadata{ URI: uri, - Total: int(usrs.TotalResults), + Total: len(items), }, Items: items, } diff --git a/pkg/cmd/replace/accesspolicy.go b/pkg/cmd/replace/accesspolicy.go index 6cad2d1..7c0ac8d 100644 --- a/pkg/cmd/replace/accesspolicy.go +++ b/pkg/cmd/replace/accesspolicy.go @@ -44,8 +44,8 @@ You can identify the entitlement required by running: # Generate an empty accessPolicy resource template verifyctl replace accesspolicy --boilerplate - # Update a accessPolicy from a JSON file - verifyctl replace accesspolicy -f=./accesspolicy-12345.json`)) + # Update a accessPolicy from a YAML file + verifyctl replace -f=./accesspolicy-12345.yaml`)) ) type accessPolicyOptions struct { diff --git a/pkg/cmd/replace/application.go b/pkg/cmd/replace/application.go index eddaf7d..6bbf369 100644 --- a/pkg/cmd/replace/application.go +++ b/pkg/cmd/replace/application.go @@ -41,7 +41,8 @@ var ( verifyctl replace application --boilerplate # Update an application from a YAML file - verifyctl replace application -f=./application.yml`)) + verifyctl replace application --applicationID 98765 -f "application2.yaml" +`)) ) type applicationOptions struct { diff --git a/pkg/cmd/replace/attribute.go b/pkg/cmd/replace/attribute.go index fc67380..54a3a3e 100644 --- a/pkg/cmd/replace/attribute.go +++ b/pkg/cmd/replace/attribute.go @@ -46,7 +46,7 @@ You can identify the entitlement required by running: verifyctl replace attribute --boilerplate # Create an attribute using the API model in JSON format. - verifyctl replace attribute -f=./customEmail.json`)) + verifyctl replace -f=./customEmail.json`)) ) type attributeOptions struct { diff --git a/pkg/cmd/replace/group.go b/pkg/cmd/replace/group.go index 20d0524..b01a14c 100644 --- a/pkg/cmd/replace/group.go +++ b/pkg/cmd/replace/group.go @@ -46,7 +46,7 @@ You can identify the entitlement required by running: verifyctl replace group --boilerplate # Update a group from a JSON file - verifyctl replace group -f=./group-12345.json`)) + verifyctl replace -f=./group-12345.json`)) ) type groupOptions struct { diff --git a/pkg/cmd/replace/identity_agent.go b/pkg/cmd/replace/identity_agent.go index 360e9de..effddea 100644 --- a/pkg/cmd/replace/identity_agent.go +++ b/pkg/cmd/replace/identity_agent.go @@ -45,8 +45,8 @@ You can identify the entitlement required by running: # Generate an empty identityAgent resource template verifyctl replace identityagent --boilerplate - # Update a identity agent from a JSON file - verifyctl replace identityagent -f=./identity_agent.json`)) + # Update a identity agent from a YAML file + verifyctl replace -f=./identity_agent.yaml`)) ) type identityAgentOptions struct { diff --git a/pkg/cmd/replace/identity_provider.go b/pkg/cmd/replace/identity_provider.go index 7ea9bb2..e2ecc0b 100644 --- a/pkg/cmd/replace/identity_provider.go +++ b/pkg/cmd/replace/identity_provider.go @@ -47,7 +47,7 @@ You can identify the entitlement required by running: verifyctl replace identitysource --boilerplate # Update a identitySource from a JSON file - verifyctl replace identitysource -f=./identitysource-12345.json --identitySourceID=identitySourceID`)) + verifyctl replace identitysource --identitySourceID 1234 -f "identitySource.yaml"`)) ) type identitySourceOptions struct { @@ -67,6 +67,7 @@ func newIdentitySourceCommand(config *config.CLIConfig, streams io.ReadWriter) * Long: identitySourceLongDesc, Example: identitySourceExamples, DisableFlagsInUseLine: true, + SilenceUsage: true, Run: func(cmd *cobra.Command, args []string) { cmdutil.ExitOnError(cmd, o.Complete(cmd, args)) cmdutil.ExitOnError(cmd, o.Validate(cmd, args)) diff --git a/pkg/cmd/replace/password_policy.go b/pkg/cmd/replace/password_policy.go index b7e08be..f70380b 100644 --- a/pkg/cmd/replace/password_policy.go +++ b/pkg/cmd/replace/password_policy.go @@ -46,7 +46,7 @@ You can identify the entitlement required by running: verifyctl replace passwordPolicy --boilerplate # Update a password policy from a JSON file - verifyctl replace passwordPolicy -f=./password_policy.json`)) + verifyctl.go replace passwordPolicy -f "password_Policy_update.yaml"`)) ) type passwordPolicyOptions struct { diff --git a/pkg/cmd/replace/signInOptions.go b/pkg/cmd/replace/signInOptions.go index 124ba0d..d3902e3 100644 --- a/pkg/cmd/replace/signInOptions.go +++ b/pkg/cmd/replace/signInOptions.go @@ -35,10 +35,10 @@ var ( signInOptionsExamples = templates.Examples(cmdutil.TranslateExamples(signInOptionsMessagePrefix, ` # Generate an empty sign-in options template - verifyctl replace sign-in-options --boilerplate + verifyctl replace --boilerplate - # Update sign-in options for an identity provider from a JSON file - verifyctl replace sign-in-options -f=./signin-options.json`)) + # Update sign-in options for an identity provider from a YAML file + verifyctl replace -f=./signin-options.yaml`)) ) type signInOptions struct { diff --git a/pkg/cmd/replace/user.go b/pkg/cmd/replace/user.go index 89fe43a..80e11ae 100644 --- a/pkg/cmd/replace/user.go +++ b/pkg/cmd/replace/user.go @@ -46,7 +46,7 @@ You can identify the entitlement required by running: verifyctl replace user --boilerplate # Update a user from a JSON file - verifyctl replace user -f=./user-12345.json`)) + verifyctl replace -f=./user-12345.json`)) ) type userOptions struct { diff --git a/pkg/util/cmd/exec.go b/pkg/util/cmd/exec.go index 23c8efe..d3ab75d 100644 --- a/pkg/util/cmd/exec.go +++ b/pkg/util/cmd/exec.go @@ -23,7 +23,6 @@ func ExitOnError(cmd *cobra.Command, err error) { } _, _ = io.WriteString(cmd.ErrOrStderr(), err.Error()+"\n") - _ = cmd.Usage() os.Exit(1) }