mirror of
https://github.com/LukeHagar/sailpoint-cli.git
synced 2025-12-10 04:21:26 +00:00
validate moved to initapiclient defaults restored
This commit is contained in:
@@ -23,6 +23,11 @@ func NewEnvironmentCommand() *cobra.Command {
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
|
||||
err := config.InitConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
environments := config.GetEnvironments()
|
||||
envKeys := maps.Keys(environments)
|
||||
|
||||
|
||||
@@ -30,7 +30,10 @@ func newQueryCmd() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
apiClient := config.InitAPIClient()
|
||||
apiClient, err := config.InitAPIClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
searchQuery = args[0]
|
||||
fmt.Println(searchQuery)
|
||||
|
||||
@@ -33,7 +33,10 @@ func newTemplateCmd() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
apiClient := config.InitAPIClient()
|
||||
apiClient, err := config.InitAPIClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var selectedTemplate templates.SearchTemplate
|
||||
searchTemplates, err := templates.GetSearchTemplates()
|
||||
|
||||
@@ -32,10 +32,14 @@ func newAuthCommand() *cobra.Command {
|
||||
Example: "sail auth pat | sail auth pat | sail auth pipeline",
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
|
||||
var selection string
|
||||
var err error
|
||||
|
||||
err = config.InitConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(args) > 0 {
|
||||
selection = args[0]
|
||||
} else {
|
||||
|
||||
@@ -3,6 +3,7 @@ package set
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/sailpoint-oss/sailpoint-cli/internal/config"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
@@ -16,6 +17,11 @@ func newDebugCommand() *cobra.Command {
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
|
||||
err := config.InitConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch strings.ToLower(args[0]) {
|
||||
case "enable":
|
||||
viper.Set("debug", true)
|
||||
|
||||
@@ -15,6 +15,11 @@ func newExportTemplateCommand() *cobra.Command {
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
|
||||
err := config.InitConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
config.SetCustomExportTemplatePath(args[0])
|
||||
|
||||
return nil
|
||||
|
||||
@@ -15,6 +15,11 @@ func newSearchTemplateCommand() *cobra.Command {
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
|
||||
err := config.InitConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
config.SetCustomSearchTemplatePath(args[0])
|
||||
|
||||
return nil
|
||||
|
||||
@@ -32,7 +32,10 @@ func newExportCmd() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
apiClient := config.InitAPIClient()
|
||||
apiClient, err := config.InitAPIClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ctx := context.TODO()
|
||||
|
||||
|
||||
@@ -26,7 +26,10 @@ func newImportCommand() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
apiClient := config.InitAPIClient()
|
||||
apiClient, err := config.InitAPIClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ctx := context.TODO()
|
||||
|
||||
|
||||
@@ -26,7 +26,10 @@ func newExportStatusCmd() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
apiClient := config.InitAPIClient()
|
||||
apiClient, err := config.InitAPIClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for i := 0; i < len(exportJobs); i++ {
|
||||
job := exportJobs[i]
|
||||
|
||||
@@ -35,7 +35,10 @@ func newTemplateCmd() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
apiClient := config.InitAPIClient()
|
||||
apiClient, err := config.InitAPIClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if folderPath == "" {
|
||||
folderPath = "search_results"
|
||||
|
||||
@@ -59,7 +59,10 @@ func newCreateCmd() *cobra.Command {
|
||||
|
||||
transform := sailpointsdk.NewTransform(data["name"].(string), data["type"].(string), data["attributes"].(map[string]interface{}))
|
||||
|
||||
apiClient := config.InitAPIClient()
|
||||
apiClient, err := config.InitAPIClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
transformObj, resp, err := apiClient.V3.TransformsApi.CreateTransform(context.TODO()).Transform(*transform).Execute()
|
||||
if err != nil {
|
||||
|
||||
@@ -90,8 +90,12 @@ func newDeleteCmd() *cobra.Command {
|
||||
|
||||
transformID := id[i]
|
||||
|
||||
apiClient := config.InitAPIClient()
|
||||
_, err := apiClient.V3.TransformsApi.DeleteTransform(context.TODO(), transformID).Execute()
|
||||
apiClient, err := config.InitAPIClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = apiClient.V3.TransformsApi.DeleteTransform(context.TODO(), transformID).Execute()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -57,7 +57,11 @@ func newUpdateCmd() *cobra.Command {
|
||||
|
||||
transform := sailpointsdk.NewTransform(data["name"].(string), data["type"].(string), data["attributes"].(map[string]interface{}))
|
||||
|
||||
apiClient := config.InitAPIClient()
|
||||
apiClient, err := config.InitAPIClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, resp, err := apiClient.V3.TransformsApi.UpdateTransform(context.TODO(), id).Transform(*transform).Execute()
|
||||
if err != nil {
|
||||
return sdk.HandleSDKError(resp, err)
|
||||
|
||||
@@ -113,6 +113,11 @@ func InitConfig() error {
|
||||
viper.SetConfigType("yaml")
|
||||
viper.SetEnvPrefix("sail")
|
||||
|
||||
viper.SetDefault("authtype", "pat")
|
||||
viper.SetDefault("customexporttemplatespath", "")
|
||||
viper.SetDefault("customsearchtemplatespath", "")
|
||||
viper.SetDefault("debug", false)
|
||||
|
||||
viper.AutomaticEnv()
|
||||
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
@@ -125,29 +130,31 @@ func InitConfig() error {
|
||||
}
|
||||
}
|
||||
|
||||
err = Validate()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func InitAPIClient() *sailpoint.APIClient {
|
||||
func InitAPIClient() (*sailpoint.APIClient, error) {
|
||||
var apiClient *sailpoint.APIClient
|
||||
|
||||
err := Validate()
|
||||
if err != nil {
|
||||
return apiClient, err
|
||||
}
|
||||
|
||||
token, err := GetAuthToken()
|
||||
if err != nil && GetDebug() {
|
||||
color.Yellow("unable to retrieve accesstoken: %s ", err)
|
||||
}
|
||||
|
||||
configuration := sailpoint.NewConfiguration(sailpoint.ClientConfiguration{Token: token, BaseURL: GetBaseUrl()})
|
||||
apiClient := sailpoint.NewAPIClient(configuration)
|
||||
apiClient = sailpoint.NewAPIClient(configuration)
|
||||
if !GetDebug() {
|
||||
var DevNull types.DevNull
|
||||
apiClient.V3.GetConfig().HTTPClient.Logger = DevNull
|
||||
apiClient.Beta.GetConfig().HTTPClient.Logger = DevNull
|
||||
}
|
||||
|
||||
return apiClient
|
||||
return apiClient, nil
|
||||
}
|
||||
|
||||
func GetAuthToken() (string, error) {
|
||||
|
||||
@@ -16,7 +16,11 @@ func PrintJob(job sailpointbetasdk.SpConfigJob) {
|
||||
}
|
||||
|
||||
func DownloadExport(jobId string, fileName string, folderPath string) error {
|
||||
apiClient := config.InitAPIClient()
|
||||
|
||||
apiClient, err := config.InitAPIClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for {
|
||||
response, _, err := apiClient.Beta.SPConfigApi.ExportSpConfigJobStatus(context.TODO(), jobId).Execute()
|
||||
|
||||
@@ -13,7 +13,13 @@ import (
|
||||
)
|
||||
|
||||
func GetTransforms() ([]sailpointsdk.Transform, error) {
|
||||
apiClient := config.InitAPIClient()
|
||||
var transforms []sailpointsdk.Transform
|
||||
|
||||
apiClient, err := config.InitAPIClient()
|
||||
if err != nil {
|
||||
return transforms, err
|
||||
}
|
||||
|
||||
transforms, resp, err := sailpoint.PaginateWithDefaults[sailpointsdk.Transform](apiClient.V3.TransformsApi.ListTransforms(context.TODO()))
|
||||
if err != nil {
|
||||
return transforms, sdk.HandleSDKError(resp, err)
|
||||
|
||||
Reference in New Issue
Block a user