mirror of
https://github.com/LukeHagar/sailpoint-cli.git
synced 2025-12-10 04:21:26 +00:00
Added support for implicit and explicit transform preview
This commit is contained in:
@@ -7,6 +7,9 @@ type transform struct {
|
|||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type operation struct {
|
||||||
|
}
|
||||||
|
|
||||||
func (t transform) transformToColumns() []string {
|
func (t transform) transformToColumns() []string {
|
||||||
return []string{t.ID, t.Name}
|
return []string{t.ID, t.Name}
|
||||||
}
|
}
|
||||||
@@ -49,10 +52,14 @@ type attributeTransformPreview struct {
|
|||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type previewBody struct {
|
type previewBodyImplicit struct {
|
||||||
AttributeTransforms []attributeTransformPreview `json:"attributeTransforms"`
|
AttributeTransforms []attributeTransformPreview `json:"attributeTransforms"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type previewBodyExplicit struct {
|
||||||
|
AttributeTransforms []map[string]interface{} `json:"attributeTransforms"`
|
||||||
|
}
|
||||||
|
|
||||||
type identityAttributeConfig struct {
|
type identityAttributeConfig struct {
|
||||||
AttributeTransforms []attributeTransform `json:"attributeTransforms"`
|
AttributeTransforms []attributeTransform `json:"attributeTransforms"`
|
||||||
}
|
}
|
||||||
@@ -104,7 +111,7 @@ func makeReference(data interface{}) attributesOfReference {
|
|||||||
return reference
|
return reference
|
||||||
}
|
}
|
||||||
|
|
||||||
func makePreviewBody(identityAttribute string, transformName string, accountAttribute string, sourceName string) previewBody {
|
func makePreviewBodyImplicit(identityAttribute string, transformName string, accountAttribute string, sourceName string) previewBodyImplicit {
|
||||||
attributeTransform := attributeTransformPreview{}
|
attributeTransform := attributeTransformPreview{}
|
||||||
attributeTransform.AttributeName = identityAttribute
|
attributeTransform.AttributeName = identityAttribute
|
||||||
attributeTransform.Attributes.Id = transformName
|
attributeTransform.Attributes.Id = transformName
|
||||||
@@ -113,8 +120,17 @@ func makePreviewBody(identityAttribute string, transformName string, accountAttr
|
|||||||
attributeTransform.Attributes.Input.Attributes.SourceName = sourceName
|
attributeTransform.Attributes.Input.Attributes.SourceName = sourceName
|
||||||
attributeTransform.Type = "reference"
|
attributeTransform.Type = "reference"
|
||||||
|
|
||||||
previewBody := previewBody{}
|
previewBody := previewBodyImplicit{}
|
||||||
previewBody.AttributeTransforms = append(previewBody.AttributeTransforms, attributeTransform)
|
previewBody.AttributeTransforms = append(previewBody.AttributeTransforms, attributeTransform)
|
||||||
|
|
||||||
return previewBody
|
return previewBody
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func makePreviewBodyExplicit(identityAttribute string, transformData map[string]interface{}) previewBodyExplicit {
|
||||||
|
transformData["attributeName"] = identityAttribute
|
||||||
|
|
||||||
|
previewBody := previewBodyExplicit{}
|
||||||
|
previewBody.AttributeTransforms = append(previewBody.AttributeTransforms, transformData)
|
||||||
|
|
||||||
|
return previewBody
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,18 +9,21 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/sailpoint-oss/sp-cli/client"
|
"github.com/sailpoint-oss/sp-cli/client"
|
||||||
"github.com/sailpoint-oss/sp-cli/util"
|
"github.com/sailpoint-oss/sp-cli/util"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var implicitInput bool
|
||||||
|
|
||||||
func newPreviewCmd(client client.Client) *cobra.Command {
|
func newPreviewCmd(client client.Client) *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "preview -i <identity-profile-id> -a <attribute-name> -n <transform-name>",
|
Use: "preview -i <identity-profile-id> -a <attribute-name> --implicit <transform data>",
|
||||||
Short: "Preview transform",
|
Short: "Preview transform",
|
||||||
Long: "Preview the final output of a transform",
|
Long: "Preview the final output of a transform",
|
||||||
Example: "sp transforms preview -i 12a199b967b64ffe992ef4ecfd076728 -a lastname -n ToLower",
|
Example: "sp transforms preview -i 12a199b967b64ffe992ef4ecfd076728 -a lastname < /path/to/transform.json",
|
||||||
Aliases: []string{"p"},
|
Aliases: []string{"p"},
|
||||||
Args: cobra.NoArgs,
|
Args: cobra.NoArgs,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
@@ -34,9 +37,13 @@ func newPreviewCmd(client client.Client) *cobra.Command {
|
|||||||
return fmt.Errorf("attribute must be specified")
|
return fmt.Errorf("attribute must be specified")
|
||||||
}
|
}
|
||||||
|
|
||||||
name := cmd.Flags().Lookup("name").Value.String()
|
var transform map[string]interface{}
|
||||||
if name == "" {
|
|
||||||
return fmt.Errorf("name must be specified")
|
if !implicitInput {
|
||||||
|
err := json.NewDecoder(os.Stdin).Decode(&transform)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the identity profile so we can obtain the authoritative source and
|
// Get the identity profile so we can obtain the authoritative source and
|
||||||
@@ -109,37 +116,53 @@ func newPreviewCmd(client client.Client) *cobra.Command {
|
|||||||
// log.Fatal(err)
|
// log.Fatal(err)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// Form the request body that will be sent to the preview endpoint
|
var previewBodyRaw []byte
|
||||||
var accountAttName string
|
// If using implicit input, then attempt to grab the implicit
|
||||||
var sourceName string
|
// input from the identity profile mapping.
|
||||||
for _, t := range profile.IdentityAttributeConfig.AttributeTransforms {
|
if implicitInput {
|
||||||
if t.IdentityAttributeName == attribute {
|
var accountAttName string
|
||||||
transType := t.TransformDefinition.Type
|
var sourceName string
|
||||||
if transType == "accountAttribute" {
|
for _, t := range profile.IdentityAttributeConfig.AttributeTransforms {
|
||||||
def := makeAttributesOfAccount(t.TransformDefinition.Attributes)
|
if t.IdentityAttributeName == attribute {
|
||||||
accountAttName = def.AttributeName
|
transType := t.TransformDefinition.Type
|
||||||
sourceName = def.SourceName
|
if transType == "accountAttribute" {
|
||||||
} else if transType == "reference" {
|
def := makeAttributesOfAccount(t.TransformDefinition.Attributes)
|
||||||
def := makeReference(t.TransformDefinition.Attributes)
|
accountAttName = def.AttributeName
|
||||||
accountAttName = def.Input.Attributes.AttributeName
|
sourceName = def.SourceName
|
||||||
sourceName = def.Input.Attributes.SourceName
|
} else if transType == "reference" {
|
||||||
} else {
|
def := makeReference(t.TransformDefinition.Attributes)
|
||||||
log.Fatal("Unknown transform definition encountered when parsing identity profile: " + transType)
|
accountAttName = def.Input.Attributes.AttributeName
|
||||||
return nil
|
sourceName = def.Input.Attributes.SourceName
|
||||||
|
} else {
|
||||||
|
log.Fatal("Unknown transform definition encountered when parsing identity profile: " + transType)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
previewBody := makePreviewBody(attribute, name, accountAttName, sourceName)
|
name := cmd.Flags().Lookup("name").Value.String()
|
||||||
|
if name == "" {
|
||||||
|
return fmt.Errorf("The transform name must be specified when previewing with implicit input.")
|
||||||
|
}
|
||||||
|
|
||||||
raw, err = json.Marshal(previewBody)
|
previewBody := makePreviewBodyImplicit(attribute, name, accountAttName, sourceName)
|
||||||
if err != nil {
|
|
||||||
return err
|
previewBodyRaw, err = json.Marshal(previewBody)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
previewBody := makePreviewBodyExplicit(attribute, transform)
|
||||||
|
|
||||||
|
previewBodyRaw, err = json.Marshal(previewBody)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call the preview endpoint to get the raw and transformed attribute values
|
// Call the preview endpoint to get the raw and transformed attribute values
|
||||||
endpoint = cmd.Flags().Lookup("preview-endpoint").Value.String()
|
endpoint = cmd.Flags().Lookup("preview-endpoint").Value.String()
|
||||||
resp, err = client.Post(cmd.Context(), util.ResourceUrl(endpoint, user[0].Id), "application/json", bytes.NewReader(raw))
|
resp, err = client.Post(cmd.Context(), util.ResourceUrl(endpoint, user[0].Id), "application/json", bytes.NewReader(previewBodyRaw))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -175,12 +198,12 @@ func newPreviewCmd(client client.Client) *cobra.Command {
|
|||||||
|
|
||||||
cmd.Flags().StringP("identity-profile", "i", "", "The GUID of an identity profile (required)")
|
cmd.Flags().StringP("identity-profile", "i", "", "The GUID of an identity profile (required)")
|
||||||
cmd.Flags().StringP("attribute", "a", "", "Attribute name (required)")
|
cmd.Flags().StringP("attribute", "a", "", "Attribute name (required)")
|
||||||
cmd.Flags().StringP("name", "n", "", "Transform name (required)")
|
cmd.Flags().StringP("name", "n", "", "Transform name if using implicit input. The transform must be uploaded to IDN.")
|
||||||
|
cmd.Flags().BoolVar(&implicitInput, "implicit", false, "Use implicit input. Default is explicit input defined by the transform.")
|
||||||
// cmd.Flags().StringP("file", "f", "", "The path to the transform file (required)")
|
// cmd.Flags().StringP("file", "f", "", "The path to the transform file (required)")
|
||||||
|
|
||||||
cmd.MarkFlagRequired("identity-profile")
|
cmd.MarkFlagRequired("identity-profile")
|
||||||
cmd.MarkFlagRequired("attribute")
|
cmd.MarkFlagRequired("attribute")
|
||||||
cmd.MarkFlagRequired("name")
|
|
||||||
// cmd.MarkFlagRequired("file")
|
// cmd.MarkFlagRequired("file")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ func NewTransformCmd(client client.Client) *cobra.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmd.PersistentFlags().StringP("transforms-endpoint", "e", viper.GetString("baseurl")+transformsEndpoint, "Override transforms endpoint")
|
cmd.PersistentFlags().StringP("transforms-endpoint", "e", viper.GetString("baseurl")+transformsEndpoint, "Override transforms endpoint")
|
||||||
cmd.PersistentFlags().StringP("preview-endpoint", "", viper.GetString("baseurl")+previewEndpoint, "Override preview endpoint")
|
cmd.PersistentFlags().String("preview-endpoint", viper.GetString("baseurl")+previewEndpoint, "Override preview endpoint")
|
||||||
cmd.PersistentFlags().StringP("identity-profile-endpoint", "", viper.GetString("baseurl")+identityProfileEndpoint, "Override identity profile endpoint")
|
cmd.PersistentFlags().String("identity-profile-endpoint", viper.GetString("baseurl")+identityProfileEndpoint, "Override identity profile endpoint")
|
||||||
cmd.PersistentFlags().StringP("user-endpoint", "", viper.GetString("baseurl")+userEndpoint, "Override user endpoint")
|
cmd.PersistentFlags().String("user-endpoint", viper.GetString("baseurl")+userEndpoint, "Override user endpoint")
|
||||||
|
|
||||||
cmd.AddCommand(
|
cmd.AddCommand(
|
||||||
newListCmd(client),
|
newListCmd(client),
|
||||||
|
|||||||
Reference in New Issue
Block a user