Resolved Bugs, Corrected formatting, Improved some visuals

This commit is contained in:
luke-hagar-sp
2023-10-05 22:27:07 -05:00
parent aafe6318a3
commit d8c2e919dd
8 changed files with 36 additions and 69 deletions

View File

@@ -2,21 +2,17 @@
package search
import (
"fmt"
"github.com/charmbracelet/log"
"github.com/sailpoint-oss/sailpoint-cli/internal/config"
"github.com/sailpoint-oss/sailpoint-cli/internal/search"
"github.com/sailpoint-oss/sailpoint-cli/internal/util"
"github.com/spf13/cobra"
)
func newQueryCmd(folderPath string, save bool) *cobra.Command {
func newQueryCmd() *cobra.Command {
var indices []string
var sort []string
var searchQuery string
var folderPath string
cmd := &cobra.Command{
Use: "query",
Short: "Manually Search using a specific Query and Indicies",
@@ -24,12 +20,6 @@ func newQueryCmd(folderPath string, save bool) *cobra.Command {
Example: "sail search query \"(type:provisioning AND created:[now-90d TO now])\" --indices events",
Aliases: []string{"que"},
Args: cobra.ExactArgs(1),
PreRun: func(cmd *cobra.Command, args []string) {
folderPath, _ := cmd.Flags().GetString("folderPath")
if folderPath == "" {
cmd.MarkFlagRequired("save")
}
},
RunE: func(cmd *cobra.Command, args []string) error {
err := config.InitConfig()
@@ -43,7 +33,7 @@ func newQueryCmd(folderPath string, save bool) *cobra.Command {
}
searchQuery = args[0]
fmt.Println(searchQuery)
// fmt.Println(searchQuery)
searchObj, err := search.BuildSearch(searchQuery, sort, indices)
if err != nil {
@@ -57,19 +47,16 @@ func newQueryCmd(folderPath string, save bool) *cobra.Command {
return err
}
if save {
err = search.IterateIndices(formattedResponse, searchQuery, folderPath, []string{"json"})
if err != nil {
return err
}
} else {
cmd.Println(util.PrettyPrint(formattedResponse))
err = search.IterateIndices(formattedResponse, searchQuery, folderPath, []string{"json"})
if err != nil {
return err
}
return nil
},
}
cmd.Flags().StringVarP(&folderPath, "folderPath", "f", "search_results", "Folder path to save the search results to. If the directory doesn't exist, then it will be created. (defaults to the current working directory)")
cmd.Flags().StringArrayVar(&indices, "indices", []string{}, "indices to perform the search query on (accessprofiles, accountactivities, entitlements, events, identities, roles)")
cmd.Flags().StringArrayVar(&sort, "sort", []string{}, "the sort value for the api call (displayName, +id...)")
cmd.MarkFlagRequired("indices")

View File

@@ -6,8 +6,6 @@ import (
)
func NewSearchCommand() *cobra.Command {
var folderPath string
var save bool
cmd := &cobra.Command{
Use: "search",
Short: "Perform Search operations in IdentityNow with a specific query or a template",
@@ -21,13 +19,10 @@ func NewSearchCommand() *cobra.Command {
}
cmd.AddCommand(
newQueryCmd(folderPath, save),
newTemplateCmd(folderPath, save),
newQueryCmd(),
newTemplateCmd(),
)
cmd.PersistentFlags().StringVarP(&folderPath, "folderPath", "f", "", "Folder path to save the search results to. If the directory doesn't exist, then it will be created. (defaults to the current working directory)")
cmd.PersistentFlags().BoolVarP(&save, "save", "s", false, "Save the search results to a file")
return cmd
}

View File

@@ -12,11 +12,11 @@ import (
"github.com/sailpoint-oss/sailpoint-cli/internal/templates"
"github.com/sailpoint-oss/sailpoint-cli/internal/terminal"
"github.com/sailpoint-oss/sailpoint-cli/internal/types"
"github.com/sailpoint-oss/sailpoint-cli/internal/util"
"github.com/spf13/cobra"
)
func newTemplateCmd(folderPath string, save bool) *cobra.Command {
func newTemplateCmd() *cobra.Command {
var folderPath string
var template string
cmd := &cobra.Command{
Use: "template",
@@ -90,17 +90,16 @@ func newTemplateCmd(folderPath string, save bool) *cobra.Command {
return err
}
if save {
err = search.IterateIndices(formattedResponse, selectedTemplate.SearchQuery.Query.GetQuery(), folderPath, []string{"json"})
if err != nil {
return err
}
} else {
cmd.Println(util.PrettyPrint(formattedResponse))
err = search.IterateIndices(formattedResponse, selectedTemplate.SearchQuery.Query.GetQuery(), folderPath, []string{"json"})
if err != nil {
return err
}
return nil
},
}
cmd.Flags().StringVarP(&folderPath, "folderPath", "f", "search_results", "Folder path to save the search results to. If the directory doesn't exist, then it will be created. (defaults to the current working directory)")
return cmd
}

View File

@@ -19,7 +19,7 @@ func TestNewTemplateCommand(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
cmd := newTemplateCmd("", false)
cmd := newTemplateCmd()
b := new(bytes.Buffer)
cmd.SetOut(b)

View File

@@ -3,15 +3,13 @@ package transform
import (
"context"
"encoding/json"
"os"
"path/filepath"
"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"
)
@@ -22,7 +20,7 @@ func newDownloadCommand() *cobra.Command {
Use: "download",
Short: "Download all Transforms from IdentityNow",
Long: "\nDownload all Transforms from IdentityNow\n\n",
Example: "sail transform downlooad -d transform_files | sail transform dl",
Example: "sail transform download -d transform_files | sail transform dl",
Aliases: []string{"dl"},
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
@@ -32,33 +30,15 @@ func newDownloadCommand() *cobra.Command {
return err
}
transforms, resp, err := sailpoint.PaginateWithDefaults[v3.Transform](apiClient.V3.TransformsApi.ListTransforms(context.TODO()))
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, " ", "") + ".json"
content, _ := json.MarshalIndent(v, "", " ")
var err error
// Make sure the output dir exists first
err = os.MkdirAll(destination, os.ModePerm)
if err != nil {
return err
}
// Make sure to create the files if they dont exist
file, err := os.OpenFile((filepath.Join(destination, filename)), os.O_RDWR|os.O_CREATE, 0777)
if err != nil {
return err
}
_, err = file.Write(content)
if err != nil {
return err
}
filename := strings.ReplaceAll(v.Name, " ", "")
err := output.SaveJSONFile(v, filename, destination)
if err != nil {
return err
}

View File

@@ -52,15 +52,17 @@ func newCollectCommand(term terminal.Terminal) *cobra.Command {
}
var wg sync.WaitGroup
p := mpb.New(mpb.WithWidth(60),
p := mpb.New(
mpb.PopCompletedMode(),
mpb.WithRefreshRate(180*time.Millisecond),
mpb.WithWaitGroup(&wg))
log.SetOutput(p)
for i, endpoint := range args {
var password string
if len(credentials) >= i-1 {
if len(credentials) > i {
password = credentials[i]
}

View File

@@ -38,8 +38,11 @@ func newUpdateCommand(term terminal.Terminal) *cobra.Command {
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
for i, endpoint := range args {
var password string
password := credentials[i]
if len(credentials) > i {
password = credentials[i]
}
if password == "" {
password, _ = term.PromptPassword("Enter Password for " + endpoint + ":")

View File

@@ -123,7 +123,8 @@ func CollectVAFiles(endpoint string, password string, output string, files []str
err := collectFile(sftp, filePath, outputFolder, endpoint, p)
if err != nil {
log.Warn("Error collecting file", "file", filePath, "VA", endpoint, "err", err)
log.Warn("Skipping file", "file", filePath, "VA", endpoint)
log.Debug("Error collecting file", "file", filePath, "VA", endpoint, "err", err)
}
}(filePath)
}
@@ -153,9 +154,9 @@ func collectFile(sftp *sftp.Client, filePath, outputFolder, endpoint string, p *
bar := p.AddBar(remoteFileStats.Size(),
mpb.BarFillerClearOnComplete(),
mpb.PrependDecorators(
decor.Name(name, decor.WCSyncSpaceR),
decor.Name(":", decor.WCSyncSpaceR),
decor.OnComplete(decor.CountersKiloByte("% .2f / % .2f", decor.WCSyncSpaceR), "Complete"),
decor.Name(name, decor.WCSyncWidthR),
decor.Name(" : ", decor.WCSyncWidthR),
// decor.OnComplete(decor.CountersKiloByte("% .2f / % .2f", decor.WCSyncSpaceR), "Complete"),
decor.TotalKiloByte("% .2f", decor.WCSyncSpaceR),
),
mpb.AppendDecorators(