mirror of
https://github.com/LukeHagar/sailpoint-cli.git
synced 2025-12-09 20:57:44 +00:00
Tests are working again
This commit is contained in:
@@ -2,20 +2,22 @@
|
||||
package transform
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/charmbracelet/log"
|
||||
sailpointbetasdk "github.com/sailpoint-oss/golang-sdk/beta"
|
||||
"github.com/sailpoint-oss/sailpoint-cli/internal/config"
|
||||
"github.com/sailpoint-oss/sailpoint-cli/internal/sdk"
|
||||
"github.com/sailpoint-oss/sailpoint-cli/internal/util"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func newCreateCmd() *cobra.Command {
|
||||
var filepath string
|
||||
cmd := &cobra.Command{
|
||||
Use: "create",
|
||||
Short: "Create an IdentityNow Transform from a file",
|
||||
@@ -25,44 +27,44 @@ func newCreateCmd() *cobra.Command {
|
||||
Args: cobra.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
var transform sailpointbetasdk.Transform
|
||||
var decoder *json.Decoder
|
||||
|
||||
filepath := cmd.Flags().Lookup("file").Value.String()
|
||||
if filepath != "" {
|
||||
file, err := os.Open(filepath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
err = json.NewDecoder(file).Decode(&transform)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
decoder = json.NewDecoder(bufio.NewReader(file))
|
||||
} else {
|
||||
err := json.NewDecoder(os.Stdin).Decode(&transform)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
decoder = json.NewDecoder(bufio.NewReader(os.Stdin))
|
||||
}
|
||||
|
||||
log.Debug("Transform", "transform", util.PrettyPrint(transform))
|
||||
if err := decoder.Decode(&transform); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if transform.Name == "" {
|
||||
log.Debug("Filepath", "path", filepath)
|
||||
|
||||
log.Debug("Transform", "transform", transform)
|
||||
|
||||
if transform.GetName() == "" {
|
||||
return fmt.Errorf("the transform must have a name")
|
||||
}
|
||||
|
||||
if transform.Id != nil {
|
||||
if transform.GetId() != "" {
|
||||
return fmt.Errorf("the transform cannot have an ID")
|
||||
}
|
||||
|
||||
createTransform := sailpointbetasdk.NewTransform(transform.Name, transform.Type, transform.Attributes)
|
||||
|
||||
apiClient, err := config.InitAPIClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
transformObj, resp, err := apiClient.Beta.TransformsApi.CreateTransform(context.TODO()).Transform(*createTransform).Execute()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
|
||||
defer cancel()
|
||||
|
||||
transformObj, resp, err := apiClient.Beta.TransformsApi.CreateTransform(ctx).Transform(transform).Execute()
|
||||
if err != nil {
|
||||
return sdk.HandleSDKError(resp, err)
|
||||
}
|
||||
@@ -75,7 +77,7 @@ func newCreateCmd() *cobra.Command {
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().StringP("file", "f", "", "The path to the transform file")
|
||||
cmd.Flags().StringVarP(&filepath, "file", "f", "", "The path to the transform file")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user