mirror of
https://github.com/LukeHagar/sailpoint-cli.git
synced 2025-12-06 12:47:44 +00:00
* 🪵 Implemented an Improved Global logger solution * 🥈 Removed duplicate APIClient inits * 🐛 Corrected an issue with the payload for spconfig import * 🚤 Significantly improved the Speed of Parsing log files with sail va parse * 🎢 Improved error handling for all VA commands * 💻 Added a VA List Command, along with Get and Set commands for VA Log Config
79 lines
2.0 KiB
Go
79 lines
2.0 KiB
Go
// Copyright (c) 2021, SailPoint Technologies, Inc. All rights reserved.
|
|
package transform
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/charmbracelet/log"
|
|
sailpointsdk "github.com/sailpoint-oss/golang-sdk/v3"
|
|
"github.com/sailpoint-oss/sailpoint-cli/internal/config"
|
|
"github.com/sailpoint-oss/sailpoint-cli/internal/sdk"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func newCreateCmd() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "create",
|
|
Short: "Create an IdentityNow Transform from a file",
|
|
Long: "\nCreate an IdentityNow Transform from a file\n\n",
|
|
Example: "sail transform c -f /path/to/transform.json\nsail transform c < /path/to/transform.json\necho /path/to/transform.json | sail transform c",
|
|
Aliases: []string{"c"},
|
|
Args: cobra.NoArgs,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
var data map[string]interface{}
|
|
|
|
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(&data)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
} else {
|
|
err := json.NewDecoder(os.Stdin).Decode(&data)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if data["name"] == nil {
|
|
return fmt.Errorf("the transform must have a name")
|
|
}
|
|
|
|
if data["id"] != nil {
|
|
return fmt.Errorf("the transform cannot have an ID")
|
|
}
|
|
|
|
transform := sailpointsdk.NewTransform(data["name"].(string), data["type"].(string), data["attributes"].(map[string]interface{}))
|
|
|
|
apiClient, err := config.InitAPIClient()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
transformObj, resp, err := apiClient.V3.TransformsApi.CreateTransform(context.TODO()).Transform(*transform).Execute()
|
|
if err != nil {
|
|
return sdk.HandleSDKError(resp, err)
|
|
}
|
|
|
|
log.Info("Transform created successfully")
|
|
|
|
cmd.Print(*transformObj.Id)
|
|
|
|
return nil
|
|
},
|
|
}
|
|
|
|
cmd.Flags().StringP("file", "f", "", "The path to the transform file")
|
|
|
|
return cmd
|
|
}
|