mirror of
https://github.com/LukeHagar/sailpoint-cli.git
synced 2025-12-06 04:21:15 +00:00
57 lines
1.7 KiB
Go
57 lines
1.7 KiB
Go
// Copyright (c) 2021, SailPoint Technologies, Inc. All rights reserved.
|
|
package transform
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"github.com/charmbracelet/log"
|
|
sailpoint "github.com/sailpoint-oss/golang-sdk"
|
|
v3 "github.com/sailpoint-oss/golang-sdk/v3"
|
|
"github.com/sailpoint-oss/sailpoint-cli/internal/config"
|
|
"github.com/sailpoint-oss/sailpoint-cli/internal/output"
|
|
"github.com/sailpoint-oss/sailpoint-cli/internal/sdk"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func newDownloadCommand() *cobra.Command {
|
|
var destination string
|
|
cmd := &cobra.Command{
|
|
Use: "download",
|
|
Short: "Download all Transforms from IdentityNow",
|
|
Long: "\nDownload all Transforms from IdentityNow\n\n",
|
|
Example: "sail transform download -d transform_files | sail transform dl",
|
|
Aliases: []string{"dl"},
|
|
Args: cobra.NoArgs,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
apiClient, err := config.InitAPIClient()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
transforms, resp, err := sailpoint.PaginateWithDefaults[v3.TransformRead](apiClient.V3.TransformsApi.ListTransforms(context.TODO()))
|
|
if err != nil {
|
|
return sdk.HandleSDKError(resp, err)
|
|
}
|
|
|
|
for _, v := range transforms {
|
|
filename := strings.ReplaceAll(v.Name, " ", "")
|
|
|
|
err := output.SaveJSONFile(v, filename, destination)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
log.Info("Transforms downloaded successfully", "path", destination)
|
|
|
|
return nil
|
|
},
|
|
}
|
|
|
|
cmd.Flags().StringVarP(&destination, "destination", "d", "transform_files", "The path to the directory to save the files in (default current working directory). If the directory doesn't exist, then it will be automatically created.")
|
|
|
|
return cmd
|
|
}
|