mirror of
https://github.com/LukeHagar/sailpoint-cli.git
synced 2025-12-10 04:21:26 +00:00
Documentation lessons learned
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -12,3 +12,7 @@ sailpoint-cli
|
|||||||
|
|
||||||
data
|
data
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
assets/demo_create.json
|
||||||
|
assets/demo_update.json
|
||||||
|
cmd/transform/test_data/test_create.json
|
||||||
|
cmd/transform/test_data/test_update.json
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func NewConfigureCmd() *cobra.Command {
|
func NewConfigureCmd() *cobra.Command {
|
||||||
|
var ClientID string
|
||||||
|
var ClientSecret string
|
||||||
|
var err error
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "configure",
|
Use: "configure",
|
||||||
Short: "Configure PAT Authentication for the currently active environment",
|
Short: "Configure PAT Authentication for the currently active environment",
|
||||||
@@ -16,15 +19,30 @@ func NewConfigureCmd() *cobra.Command {
|
|||||||
Args: cobra.NoArgs,
|
Args: cobra.NoArgs,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
|
||||||
ClientID := terminal.InputPrompt("Personal Access Token Client ID:")
|
if ClientID == "" {
|
||||||
|
ClientID, err = terminal.PromptPassword("Personal Access Token Client ID:")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
config.SetPatClientID(ClientID)
|
config.SetPatClientID(ClientID)
|
||||||
|
|
||||||
ClientSecret := terminal.InputPrompt("Personal Access Token Client Secret:")
|
if ClientSecret == "" {
|
||||||
|
ClientSecret, err = terminal.PromptPassword("Personal Access Token Client Secret:")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
config.SetPatClientSecret(ClientSecret)
|
config.SetPatClientSecret(ClientSecret)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd.Flags().StringVarP(&ClientID, "ClientID", "id", "", "The client id to use for PAT authentication")
|
||||||
|
cmd.Flags().StringVarP(&ClientSecret, "ClientSecret", "secret", "", "The client secret to use for PAT authentication")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,13 +5,17 @@ import (
|
|||||||
"github.com/sailpoint-oss/sailpoint-cli/internal/log"
|
"github.com/sailpoint-oss/sailpoint-cli/internal/log"
|
||||||
"github.com/sailpoint-oss/sailpoint-cli/internal/terminal"
|
"github.com/sailpoint-oss/sailpoint-cli/internal/terminal"
|
||||||
"github.com/sailpoint-oss/sailpoint-cli/internal/tui"
|
"github.com/sailpoint-oss/sailpoint-cli/internal/tui"
|
||||||
|
"github.com/sailpoint-oss/sailpoint-cli/internal/util"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
"golang.org/x/exp/maps"
|
"golang.org/x/exp/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewEnvironmentCommand() *cobra.Command {
|
func NewEnvironmentCommand() *cobra.Command {
|
||||||
var env string
|
var env string
|
||||||
var overwrite bool
|
var overwrite bool
|
||||||
|
var erase bool
|
||||||
|
var show bool
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "environment",
|
Use: "environment",
|
||||||
Short: "change currently active environment",
|
Short: "change currently active environment",
|
||||||
@@ -41,9 +45,16 @@ func NewEnvironmentCommand() *cobra.Command {
|
|||||||
if env != "" {
|
if env != "" {
|
||||||
config.SetActiveEnvironment(env)
|
config.SetActiveEnvironment(env)
|
||||||
|
|
||||||
if _, exists := environments[env]; exists && !overwrite && config.GetTenantUrl() != "" && config.GetBaseUrl() != "" {
|
if foundEnv, exists := environments[env]; exists && !overwrite && config.GetTenantUrl() != "" && config.GetBaseUrl() != "" {
|
||||||
|
if show {
|
||||||
log.Log.Info("Environment changed", "env", env)
|
log.Log.Warn("printing env", "env", env)
|
||||||
|
util.PrettyPrint(foundEnv)
|
||||||
|
} else if erase {
|
||||||
|
log.Log.Warn("erasing env", "env", env)
|
||||||
|
viper.Set("environments."+config.GetActiveEnvironment(), config.Environment{})
|
||||||
|
} else {
|
||||||
|
log.Log.Info("Environment changed", "env", env)
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@@ -63,6 +74,9 @@ func NewEnvironmentCommand() *cobra.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmd.Flags().BoolVarP(&overwrite, "overwrite", "o", false, "use to overwrite an existing environments configuration")
|
cmd.Flags().BoolVarP(&overwrite, "overwrite", "o", false, "use to overwrite an existing environments configuration")
|
||||||
|
cmd.Flags().BoolVarP(&erase, "erase", "e", false, "use to erase an existing environments configuration")
|
||||||
|
cmd.Flags().BoolVarP(&show, "show", "s", false, "use to show an existing environments configuration")
|
||||||
|
cmd.MarkFlagsMutuallyExclusive("overwrite", "erase", "show")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
|
||||||
"github.com/sailpoint-oss/sailpoint-cli/internal/config"
|
"github.com/sailpoint-oss/sailpoint-cli/internal/config"
|
||||||
"github.com/sailpoint-oss/sailpoint-cli/internal/log"
|
"github.com/sailpoint-oss/sailpoint-cli/internal/log"
|
||||||
"github.com/sailpoint-oss/sailpoint-cli/internal/search"
|
"github.com/sailpoint-oss/sailpoint-cli/internal/search"
|
||||||
@@ -57,21 +56,21 @@ func newTemplateCmd() *cobra.Command {
|
|||||||
return fmt.Errorf("no template specified")
|
return fmt.Errorf("no template specified")
|
||||||
}
|
}
|
||||||
|
|
||||||
color.Blue("Selected Template: %s\n", template)
|
log.Log.Info("Selected Template", "template", template)
|
||||||
|
|
||||||
matches := types.Filter(searchTemplates, func(st templates.SearchTemplate) bool { return st.Name == template })
|
matches := types.Filter(searchTemplates, func(st templates.SearchTemplate) bool { return st.Name == template })
|
||||||
if len(matches) < 1 {
|
if len(matches) < 1 {
|
||||||
return fmt.Errorf("no template matches for %s", template)
|
return fmt.Errorf("no template matches for %s", template)
|
||||||
} else if len(matches) > 1 {
|
} else if len(matches) > 1 {
|
||||||
color.Yellow("multiple template matches for %s", template)
|
log.Log.Warn("multiple template matches, the first match will be used", "template", template)
|
||||||
}
|
}
|
||||||
selectedTemplate = matches[0]
|
selectedTemplate = matches[0]
|
||||||
varCount := len(selectedTemplate.Variables)
|
varCount := len(selectedTemplate.Variables)
|
||||||
if varCount > 0 {
|
if varCount > 0 {
|
||||||
for i := 0; i < varCount; i++ {
|
for i := 0; i < varCount; i++ {
|
||||||
varEntry := selectedTemplate.Variables[i]
|
varEntry := selectedTemplate.Variables[i]
|
||||||
resp := terminal.InputPrompt(fmt.Sprintf("Input %s:", varEntry.Prompt))
|
resp := terminal.InputPrompt("Input " + varEntry.Prompt + ":")
|
||||||
selectedTemplate.Raw = []byte(strings.ReplaceAll(string(selectedTemplate.Raw), fmt.Sprintf("{{%s}}", varEntry.Name), resp))
|
selectedTemplate.Raw = []byte(strings.ReplaceAll(string(selectedTemplate.Raw), "{{"+varEntry.Name+"}}", resp))
|
||||||
}
|
}
|
||||||
err := json.Unmarshal(selectedTemplate.Raw, &selectedTemplate.SearchQuery)
|
err := json.Unmarshal(selectedTemplate.Raw, &selectedTemplate.SearchQuery)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -55,8 +55,8 @@ func newExportCmd() *cobra.Command {
|
|||||||
|
|
||||||
cmd.Flags().StringVarP(&folderPath, "folderPath", "f", "spconfig-exports", "folder path to save the search results in. If the directory doesn't exist, then it will be automatically created. (default is the current working directory)")
|
cmd.Flags().StringVarP(&folderPath, "folderPath", "f", "spconfig-exports", "folder path to save the search results in. If the directory doesn't exist, then it will be automatically created. (default is the current working directory)")
|
||||||
cmd.Flags().StringVarP(&description, "description", "d", "", "optional description for the export job")
|
cmd.Flags().StringVarP(&description, "description", "d", "", "optional description for the export job")
|
||||||
cmd.Flags().StringArrayVarP(&includeTypes, "includTypes", "i", []string{}, "types to include in export job")
|
cmd.Flags().StringArrayVarP(&includeTypes, "include", "i", []string{}, "types to include in export job")
|
||||||
cmd.Flags().StringArrayVarP(&excludeTypes, "excludeTypes", "e", []string{}, "types to exclude in export job")
|
cmd.Flags().StringArrayVarP(&excludeTypes, "exclude", "e", []string{}, "types to exclude in export job")
|
||||||
cmd.Flags().BoolVarP(&wait, "wait", "w", false, "wait for the export job to finish, and download the results")
|
cmd.Flags().BoolVarP(&wait, "wait", "w", false, "wait for the export job to finish, and download the results")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
|||||||
@@ -50,8 +50,8 @@ func newExportStatusCmd() *cobra.Command {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Flags().StringArrayVarP(&importJobs, "import jobs", "i", []string{}, "a list of import job ids to check the status of")
|
cmd.Flags().StringArrayVarP(&importJobs, "import", "i", []string{}, "a list of import job ids to check the status of")
|
||||||
cmd.Flags().StringArrayVarP(&exportJobs, "export jobs", "e", []string{}, "a list of export job ids to check the status of")
|
cmd.Flags().StringArrayVarP(&exportJobs, "export", "e", []string{}, "a list of export job ids to check the status of")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,14 +84,14 @@ func newTemplateCmd() *cobra.Command {
|
|||||||
|
|
||||||
if wait {
|
if wait {
|
||||||
log.Log.Info("Checking Export Job", "JobID", job.JobId)
|
log.Log.Info("Checking Export Job", "JobID", job.JobId)
|
||||||
spconfig.DownloadExport(job.JobId, "spconfig-export-"+template+job.JobId+".json", folderPath)
|
spconfig.DownloadExport(job.JobId, "spconfig-export-"+template+"-"+job.JobId+".json", folderPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Flags().StringArrayVarP(&outputTypes, "output types", "o", []string{"json"}, "the sort value for the api call (examples)")
|
cmd.Flags().StringArrayVarP(&outputTypes, "outputTypes", "o", []string{"json"}, "the sort value for the api call (examples)")
|
||||||
cmd.Flags().StringVarP(&folderPath, "folderPath", "f", "spconfig-exports", "folder path to save the search results in. If the directory doesn't exist, then it will be automatically created. (default is the current working directory)")
|
cmd.Flags().StringVarP(&folderPath, "folderPath", "f", "spconfig-exports", "folder path to save the search results in. If the directory doesn't exist, then it will be automatically created. (default is the current working directory)")
|
||||||
cmd.Flags().BoolVarP(&wait, "wait", "w", false, "wait for the export job to finish, and download the results")
|
cmd.Flags().BoolVarP(&wait, "wait", "w", false, "wait for the export job to finish, and download the results")
|
||||||
|
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ func newDeleteCmd() *cobra.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
columns := []table.Column{
|
columns := []table.Column{
|
||||||
{Title: "Name", Width: 25},
|
|
||||||
{Title: "ID", Width: 40},
|
{Title: "ID", Width: 40},
|
||||||
|
{Title: "Name", Width: 25},
|
||||||
{Title: "Type", Width: 25},
|
{Title: "Type", Width: 25},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ func newDeleteCmd() *cobra.Command {
|
|||||||
|
|
||||||
for i := 0; i < len(transforms); i++ {
|
for i := 0; i < len(transforms); i++ {
|
||||||
transform := transforms[i]
|
transform := transforms[i]
|
||||||
rows = append(rows, []string{*transform.Id, transform.Name})
|
rows = append(rows, []string{*transform.Id, transform.Name, transform.Type})
|
||||||
}
|
}
|
||||||
|
|
||||||
t := table.New(
|
t := table.New(
|
||||||
@@ -73,7 +73,7 @@ func newDeleteCmd() *cobra.Command {
|
|||||||
tempRow := m.Retrieve()
|
tempRow := m.Retrieve()
|
||||||
|
|
||||||
if len(tempRow) > 0 {
|
if len(tempRow) > 0 {
|
||||||
id = append(id, m.Retrieve()[1])
|
id = append(id, m.Retrieve()[0])
|
||||||
} else {
|
} else {
|
||||||
return fmt.Errorf("no transform selected")
|
return fmt.Errorf("no transform selected")
|
||||||
}
|
}
|
||||||
@@ -98,11 +98,6 @@ func newDeleteCmd() *cobra.Command {
|
|||||||
log.Log.Info("Transform successfully deleted", "TransformID", transformID)
|
log.Log.Info("Transform successfully deleted", "TransformID", transformID)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := transform.ListTransforms()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ func newDownloadCmd() *cobra.Command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Log.Info("Transforms downloaded successfully", "Path", destination)
|
log.Log.Info("Transforms downloaded successfully", "path", destination)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
{"attributes":{"substring":"admin_"},"name":"gToJfU","type":"indexOf"}
|
{"attributes":{"substring":"admin_"},"name":"XWwLDi","type":"indexOf"}
|
||||||
@@ -1 +1 @@
|
|||||||
{"attributes":{"substring":"jlVDuHNDDnnAGbgTefISNwTY"},"id":"71f3d4d5-baf4-4b76-bbd3-93ee8660e9fc","name":"gToJfU","type":"indexOf"}
|
{"attributes":{"substring":"WxrnOBHyejgSKnPpgnSchJpe"},"id":"a6697db7-d561-4967-a89a-9fe4ae161374","name":"XWwLDi","type":"indexOf"}
|
||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
sailpointsdk "github.com/sailpoint-oss/golang-sdk/sdk-output/v3"
|
sailpointsdk "github.com/sailpoint-oss/golang-sdk/sdk-output/v3"
|
||||||
"github.com/sailpoint-oss/sailpoint-cli/internal/config"
|
"github.com/sailpoint-oss/sailpoint-cli/internal/config"
|
||||||
|
"github.com/sailpoint-oss/sailpoint-cli/internal/log"
|
||||||
"github.com/sailpoint-oss/sailpoint-cli/internal/sdk"
|
"github.com/sailpoint-oss/sailpoint-cli/internal/sdk"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@@ -50,6 +51,8 @@ func newUpdateCmd() *cobra.Command {
|
|||||||
id := data["id"].(string)
|
id := data["id"].(string)
|
||||||
delete(data, "id") // ID can't be present in the update payload
|
delete(data, "id") // ID can't be present in the update payload
|
||||||
|
|
||||||
|
log.Log.Info("Updating Transaform", "transformID", id)
|
||||||
|
|
||||||
transform := sailpointsdk.NewTransform(data["name"].(string), data["type"].(string), data["attributes"].(map[string]interface{}))
|
transform := sailpointsdk.NewTransform(data["name"].(string), data["type"].(string), data["attributes"].(map[string]interface{}))
|
||||||
|
|
||||||
apiClient, err := config.InitAPIClient()
|
apiClient, err := config.InitAPIClient()
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -10,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
sailpoint "github.com/sailpoint-oss/golang-sdk/sdk-output"
|
sailpoint "github.com/sailpoint-oss/golang-sdk/sdk-output"
|
||||||
|
"github.com/sailpoint-oss/sailpoint-cli/internal/log"
|
||||||
"github.com/sailpoint-oss/sailpoint-cli/internal/types"
|
"github.com/sailpoint-oss/sailpoint-cli/internal/types"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
@@ -241,7 +241,7 @@ func SaveConfig() error {
|
|||||||
if _, err := os.Stat(filepath.Join(home, configFolder)); os.IsNotExist(err) {
|
if _, err := os.Stat(filepath.Join(home, configFolder)); os.IsNotExist(err) {
|
||||||
err = os.Mkdir(filepath.Join(home, configFolder), 0777)
|
err = os.Mkdir(filepath.Join(home, configFolder), 0777)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("failed to create %s folder for config. %v", configFolder, err)
|
log.Log.Warn("failed to create %s folder for config. %v", configFolder, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,6 +260,7 @@ func SaveConfig() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Validate() error {
|
func Validate() error {
|
||||||
|
var errors int
|
||||||
authType := GetAuthType()
|
authType := GetAuthType()
|
||||||
|
|
||||||
switch authType {
|
switch authType {
|
||||||
@@ -267,21 +268,24 @@ func Validate() error {
|
|||||||
case "pat":
|
case "pat":
|
||||||
|
|
||||||
if GetBaseUrl() == "" {
|
if GetBaseUrl() == "" {
|
||||||
return fmt.Errorf("configured environment is missing BaseURL")
|
log.Log.Error("configured environment is missing BaseURL")
|
||||||
|
errors++
|
||||||
}
|
}
|
||||||
|
|
||||||
if GetPatClientID() == "" {
|
if GetPatClientID() == "" {
|
||||||
return fmt.Errorf("configured environment is missing PAT ClientID")
|
log.Log.Error("configured environment is missing PAT ClientID")
|
||||||
|
errors++
|
||||||
}
|
}
|
||||||
|
|
||||||
if GetPatClientSecret() == "" {
|
if GetPatClientSecret() == "" {
|
||||||
return fmt.Errorf("configured environment is missing PAT ClientSecret")
|
log.Log.Error("configured environment is missing PAT ClientSecret")
|
||||||
|
errors++
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
|
|
||||||
case "oauth":
|
case "oauth":
|
||||||
return fmt.Errorf("oauth is not currently supported")
|
|
||||||
|
log.Log.Error("oauth is not currently supported")
|
||||||
|
errors++
|
||||||
|
|
||||||
// if config.Environments[config.ActiveEnvironment].BaseURL == "" {
|
// if config.Environments[config.ActiveEnvironment].BaseURL == "" {
|
||||||
// return fmt.Errorf("configured environment is missing BaseURL")
|
// return fmt.Errorf("configured environment is missing BaseURL")
|
||||||
@@ -291,11 +295,16 @@ func Validate() error {
|
|||||||
// return fmt.Errorf("configured environment is missing TenantURL")
|
// return fmt.Errorf("configured environment is missing TenantURL")
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// return nil
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
return fmt.Errorf("invalid authtype '%s' configured", authType)
|
log.Log.Error("invalid authtype '%s' configured", authType)
|
||||||
|
errors++
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if errors > 0 {
|
||||||
|
return fmt.Errorf("configuration invalid, errors: %v", errors)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/gocarina/gocsv"
|
"github.com/gocarina/gocsv"
|
||||||
)
|
)
|
||||||
@@ -40,7 +41,7 @@ func SaveJSONFile[T any](formattedResponse T, fileName string, folderPath string
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SaveCSVFile[T any](formattedResponse T, fileName string, folderPath string) error {
|
func SaveCSVFile[T any](formattedResponse T, fileName string, folderPath string) error {
|
||||||
savePath := path.Join(folderPath, fileName)
|
savePath := filepath.Join(folderPath, fileName)
|
||||||
|
|
||||||
// Make sure the output dir exists first
|
// Make sure the output dir exists first
|
||||||
err := os.MkdirAll(folderPath, os.ModePerm)
|
err := os.MkdirAll(folderPath, os.ModePerm)
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
sailpoint "github.com/sailpoint-oss/golang-sdk/sdk-output"
|
sailpoint "github.com/sailpoint-oss/golang-sdk/sdk-output"
|
||||||
sailpointsdk "github.com/sailpoint-oss/golang-sdk/sdk-output/v3"
|
sailpointsdk "github.com/sailpoint-oss/golang-sdk/sdk-output/v3"
|
||||||
|
"github.com/sailpoint-oss/sailpoint-cli/internal/log"
|
||||||
"github.com/sailpoint-oss/sailpoint-cli/internal/output"
|
"github.com/sailpoint-oss/sailpoint-cli/internal/output"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ func PerformSearch(apiClient sailpoint.APIClient, search sailpointsdk.Search) (S
|
|||||||
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
|
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
|
||||||
}
|
}
|
||||||
|
|
||||||
color.Green("Search complete, saving results")
|
log.Log.Info("Search complete")
|
||||||
|
|
||||||
for i := 0; i < len(resp); i++ {
|
for i := 0; i < len(resp); i++ {
|
||||||
entry := resp[i]
|
entry := resp[i]
|
||||||
@@ -123,42 +123,42 @@ func PerformSearch(apiClient sailpoint.APIClient, search sailpointsdk.Search) (S
|
|||||||
func IterateIndicies(SearchResults SearchResults, searchQuery string, folderPath string, outputTypes []string) error {
|
func IterateIndicies(SearchResults SearchResults, searchQuery string, folderPath string, outputTypes []string) error {
|
||||||
var err error
|
var err error
|
||||||
if len(SearchResults.AccountActivities) > 0 {
|
if len(SearchResults.AccountActivities) > 0 {
|
||||||
fileName := fmt.Sprintf("query=%s&indicie=%s", searchQuery, "AccountActivities")
|
fileName := "query=" + searchQuery + "&indicie=AccountActivities"
|
||||||
err = SaveResults(SearchResults.AccountActivities, fileName, folderPath, outputTypes)
|
err = SaveResults(SearchResults.AccountActivities, fileName, folderPath, outputTypes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(SearchResults.AccessProfiles) > 0 {
|
if len(SearchResults.AccessProfiles) > 0 {
|
||||||
fileName := fmt.Sprintf("query=%s&indicie=%s", searchQuery, "AccessProfiles")
|
fileName := "query=" + searchQuery + "&indicie=AccessProfiles"
|
||||||
err = SaveResults(SearchResults.AccessProfiles, fileName, folderPath, outputTypes)
|
err = SaveResults(SearchResults.AccessProfiles, fileName, folderPath, outputTypes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(SearchResults.Entitlements) > 0 {
|
if len(SearchResults.Entitlements) > 0 {
|
||||||
fileName := fmt.Sprintf("query=%s&indicie=%s", searchQuery, "Entitlements")
|
fileName := "query=" + searchQuery + "&indicie=Entitlements"
|
||||||
err = SaveResults(SearchResults.Entitlements, fileName, folderPath, outputTypes)
|
err = SaveResults(SearchResults.Entitlements, fileName, folderPath, outputTypes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(SearchResults.Events) > 0 {
|
if len(SearchResults.Events) > 0 {
|
||||||
fileName := fmt.Sprintf("query=%s&indicie=%s", searchQuery, "Events")
|
fileName := "query=" + searchQuery + "&indicie=Events"
|
||||||
err = SaveResults(SearchResults.Events, fileName, folderPath, outputTypes)
|
err = SaveResults(SearchResults.Events, fileName, folderPath, outputTypes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(SearchResults.Identities) > 0 {
|
if len(SearchResults.Identities) > 0 {
|
||||||
fileName := fmt.Sprintf("query=%s&indicie=%s", searchQuery, "Identities")
|
fileName := "query=" + searchQuery + "&indicie=Identities"
|
||||||
err = SaveResults(SearchResults.Identities, fileName, folderPath, outputTypes)
|
err = SaveResults(SearchResults.Identities, fileName, folderPath, outputTypes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(SearchResults.Roles) > 0 {
|
if len(SearchResults.Roles) > 0 {
|
||||||
fileName := fmt.Sprintf("query=%s&indicie=%s", searchQuery, "Roles")
|
fileName := "query=" + searchQuery + "&indicie=Roles"
|
||||||
err = SaveResults(SearchResults.Roles, fileName, folderPath, outputTypes)
|
err = SaveResults(SearchResults.Roles, fileName, folderPath, outputTypes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -174,19 +174,19 @@ func SaveResults[T any](formattedResponse []T, fileName string, filePath string,
|
|||||||
case "json":
|
case "json":
|
||||||
fileName = fileName + ".json"
|
fileName = fileName + ".json"
|
||||||
savePath := path.Join(filePath, fileName)
|
savePath := path.Join(filePath, fileName)
|
||||||
|
log.Log.Info("Saving Results", "file", savePath)
|
||||||
err := output.SaveJSONFile(formattedResponse, fileName, filePath)
|
err := output.SaveJSONFile(formattedResponse, fileName, filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
color.Green("Saving file: %s", savePath)
|
|
||||||
case "csv":
|
case "csv":
|
||||||
fileName = fileName + ".csv"
|
fileName = fileName + ".csv"
|
||||||
savePath := path.Join(filePath, fileName)
|
savePath := path.Join(filePath, fileName)
|
||||||
|
log.Log.Info("Saving Results", "file", savePath)
|
||||||
err := output.SaveCSVFile(formattedResponse, fileName, filePath)
|
err := output.SaveCSVFile(formattedResponse, fileName, filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
color.Green("Saving file: %s", savePath)
|
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("invalid output type provided %s", outputType)
|
return fmt.Errorf("invalid output type provided %s", outputType)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ package spconfig
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
sailpointbetasdk "github.com/sailpoint-oss/golang-sdk/sdk-output/beta"
|
sailpointbetasdk "github.com/sailpoint-oss/golang-sdk/sdk-output/beta"
|
||||||
"github.com/sailpoint-oss/sailpoint-cli/internal/config"
|
"github.com/sailpoint-oss/sailpoint-cli/internal/config"
|
||||||
|
"github.com/sailpoint-oss/sailpoint-cli/internal/log"
|
||||||
"github.com/sailpoint-oss/sailpoint-cli/internal/output"
|
"github.com/sailpoint-oss/sailpoint-cli/internal/output"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -33,11 +35,12 @@ func DownloadExport(jobId string, fileName string, folderPath string) error {
|
|||||||
} else {
|
} else {
|
||||||
switch response.Status {
|
switch response.Status {
|
||||||
case "COMPLETE":
|
case "COMPLETE":
|
||||||
color.Green("Downloading Export Data")
|
log.Log.Info("Job Complete")
|
||||||
exportData, _, err := apiClient.Beta.SPConfigApi.ExportSpConfigDownload(context.TODO(), jobId).Execute()
|
exportData, _, err := apiClient.Beta.SPConfigApi.ExportSpConfigDownload(context.TODO(), jobId).Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
log.Log.Info("Saving export data", "filePath", path.Join(folderPath, fileName))
|
||||||
err = output.SaveJSONFile(exportData, fileName, folderPath)
|
err = output.SaveJSONFile(exportData, fileName, folderPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -2,13 +2,13 @@ package templates
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/sailpoint-oss/sailpoint-cli/internal/config"
|
"github.com/sailpoint-oss/sailpoint-cli/internal/config"
|
||||||
|
"github.com/sailpoint-oss/sailpoint-cli/internal/log"
|
||||||
"github.com/sailpoint-oss/sailpoint-cli/internal/tui"
|
"github.com/sailpoint-oss/sailpoint-cli/internal/tui"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ func GetSearchTemplates() ([]SearchTemplate, error) {
|
|||||||
file, err := os.OpenFile(templateFile, os.O_RDWR, 0777)
|
file, err := os.OpenFile(templateFile, os.O_RDWR, 0777)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if config.GetDebug() {
|
if config.GetDebug() {
|
||||||
color.Yellow("error opening file %s", templateFile)
|
log.Log.Error("error opening file %s", templateFile)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ func GetSearchTemplates() ([]SearchTemplate, error) {
|
|||||||
|
|
||||||
err = json.Unmarshal(raw, &templates)
|
err = json.Unmarshal(raw, &templates)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
color.Red("an error occured while parsing the file: %s", templateFile)
|
log.Log.Error("an error occured while parsing the file: %s", templateFile)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ func GetExportTemplates() ([]ExportTemplate, error) {
|
|||||||
file, err := os.OpenFile(templateFile, os.O_RDWR, 0777)
|
file, err := os.OpenFile(templateFile, os.O_RDWR, 0777)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if config.GetDebug() {
|
if config.GetDebug() {
|
||||||
color.Yellow("error opening file %s", templateFile)
|
log.Log.Error("error opening file %s", templateFile)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ func GetExportTemplates() ([]ExportTemplate, error) {
|
|||||||
|
|
||||||
err = json.Unmarshal(raw, &templates)
|
err = json.Unmarshal(raw, &templates)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
color.Red("an error occured while parsing the file: %s", templateFile)
|
log.Log.Error("an error occured while parsing the file: %s", templateFile)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ func GetExportTemplates() ([]ExportTemplate, error) {
|
|||||||
|
|
||||||
err = json.Unmarshal([]byte(builtInExportTemplates), &templates)
|
err = json.Unmarshal([]byte(builtInExportTemplates), &templates)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
color.Red("an error occured while parsing the built in templates")
|
log.Log.Error("an error occured while parsing the built in templates")
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,7 +145,7 @@ func SelectTemplate[T Template](templates []T) (string, error) {
|
|||||||
|
|
||||||
var description string
|
var description string
|
||||||
if temp.GetVariableCount() > 0 {
|
if temp.GetVariableCount() > 0 {
|
||||||
description = fmt.Sprintf("%s - Accepts Input", temp.GetDescription())
|
description = temp.GetDescription() + " - Accepts Input"
|
||||||
} else {
|
} else {
|
||||||
description = temp.GetDescription()
|
description = temp.GetDescription()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1,14 @@
|
|||||||
package util
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func PrettyPrint(v interface{}) {
|
||||||
|
b, err := json.MarshalIndent(v, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("error:", err)
|
||||||
|
}
|
||||||
|
fmt.Print(string(b))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user