Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pkg/cmd/create/accesspolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -130,24 +134,21 @@ 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)
}

func (o *accessPolicyOptions) createAccessPolicyWithData(cmd *cobra.Command, data []byte) error {
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
}
Expand All @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/create/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/create/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions pkg/cmd/create/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
15 changes: 8 additions & 7 deletions pkg/cmd/create/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/cmd/create/identity_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/cmd/create/identity_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -138,17 +142,15 @@ func (o *identitySourceOptions) createIdentitySource(cmd *cobra.Command) error {
return err
}

// create identitySource with data
return o.createIdentitySourceWithData(cmd, b)
}

func (o *identitySourceOptions) createIdentitySourceWithData(cmd *cobra.Command, data []byte) error {
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
}
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/create/password_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
),
)
)
Expand Down
10 changes: 7 additions & 3 deletions pkg/cmd/create/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/cmd/delete/accesspolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
110 changes: 110 additions & 0 deletions pkg/cmd/delete/attribute.go
Original file line number Diff line number Diff line change
@@ -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
}
Loading