Files
sailpoint-cli/cmd/connector/conn_invoke_account_create.go
2023-05-17 22:28:02 -05:00

58 lines
1.4 KiB
Go

// Copyright (c) 2021, SailPoint Technologies, Inc. All rights reserved.
package connector
import (
"encoding/json"
"fmt"
"github.com/sailpoint-oss/sailpoint-cli/internal/client"
"github.com/spf13/cobra"
)
func newConnInvokeAccountCreateCmd(client client.Client) *cobra.Command {
cmd := &cobra.Command{
Use: "account-create [identity] [--attributes <value>]",
Short: "Invoke a std:account:create command",
Example: `sail connectors invoke account-create john.doe --attributes '{"email": "john.doe@example.com"}'`,
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
cc, err := connClient(cmd, client)
if err != nil {
return err
}
var identity *string = nil
if len(args) > 0 {
identity = &args[0]
}
attributesRaw := cmd.Flags().Lookup("attributes").Value.String()
var attributes map[string]interface{}
if err := json.Unmarshal([]byte(attributesRaw), &attributes); err != nil {
return err
}
schema, err := getSchemaFromCommand(cmd)
if err != nil {
return err
}
_, rawResponse, err := cc.AccountCreate(ctx, identity, attributes, schema)
if err != nil {
return err
}
_, _ = fmt.Fprintln(cmd.OutOrStdout(), string(rawResponse))
return nil
},
}
cmd.Flags().StringP("attributes", "a", "{}", "Attributes")
cmd.Flags().String("schema", "", "Optional - Custom account schema")
return cmd
}