Skip to content

Commit 4438c0a

Browse files
Merge pull request #171 from sailpoint-oss/hackathon2024
Hackathon2024
2 parents a12e989 + 4c1c681 commit 4438c0a

File tree

7 files changed

+126
-1
lines changed

7 files changed

+126
-1
lines changed

cmd/jsonpath/eval.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright (c) 2021, SailPoint Technologies, Inc. All rights reserved.
2+
package jsonpath
3+
4+
import (
5+
"fmt"
6+
"os"
7+
8+
"github.com/bhmj/jsonslice"
9+
"github.com/charmbracelet/log"
10+
"github.com/spf13/cobra"
11+
"github.com/tidwall/pretty"
12+
)
13+
14+
func newEvalCommand() *cobra.Command {
15+
var filepath string
16+
var path string
17+
18+
cmd := &cobra.Command{
19+
Use: "eval",
20+
Short: "Evaluate a jsonpath against a json file",
21+
Long: "\nEvaluate a jsonpath against a json file\n\n",
22+
Example: "sail jsonpath eval | sail jsonpath e",
23+
Aliases: []string{"e"},
24+
Args: cobra.OnlyValidArgs,
25+
RunE: func(cmd *cobra.Command, args []string) error {
26+
27+
var data []byte
28+
var err error
29+
30+
if filepath != "" {
31+
data, err = os.ReadFile(filepath)
32+
if err != nil {
33+
return err
34+
}
35+
} else {
36+
log.Error("You must provide a file to preview")
37+
}
38+
39+
result, err := jsonslice.Get(data, path)
40+
41+
if err != nil {
42+
return err
43+
}
44+
45+
// Format the JSON
46+
formattedJSON := pretty.Pretty([]byte(result))
47+
48+
// Color the JSON
49+
coloredJSON := pretty.Color(formattedJSON, nil)
50+
51+
// Print formatted and colored JSON
52+
fmt.Print(string(coloredJSON))
53+
54+
return nil
55+
56+
},
57+
}
58+
59+
cmd.Flags().StringVarP(&filepath, "file", "f", "", "The path to the json you wish to evaluate")
60+
cmd.Flags().StringVarP(&path, "path", "p", "", "The json path to evaluate against the file provided")
61+
62+
return cmd
63+
}

cmd/jsonpath/jsonpath.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package jsonpath
2+
3+
import (
4+
_ "embed"
5+
6+
"github.com/sailpoint-oss/sailpoint-cli/internal/util"
7+
"github.com/spf13/cobra"
8+
)
9+
10+
//go:embed jsonpath.md
11+
var jsonpathHelp string
12+
13+
func NewJSONPathCmd() *cobra.Command {
14+
help := util.ParseHelp(jsonpathHelp)
15+
cmd := &cobra.Command{
16+
Use: "jsonpath",
17+
Short: "JSONPath validation for workflows and event triggers",
18+
Long: help.Long,
19+
Example: help.Example,
20+
Aliases: []string{"jp"},
21+
Args: cobra.MaximumNArgs(1),
22+
23+
Run: func(cmd *cobra.Command, args []string) {
24+
cmd.Help()
25+
},
26+
}
27+
28+
cmd.AddCommand(
29+
newEvalCommand(),
30+
)
31+
32+
// log.Info("Hello World!")
33+
34+
return cmd
35+
}

cmd/jsonpath/jsonpath.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
==Long==
2+
# JSONPath Validator
3+
JSONPath validation for workflows and event triggers.
4+
5+
References:
6+
- https://developer.sailpoint.com/docs/extensibility/event-triggers/filtering-events
7+
- https://documentation.sailpoint.com/saas/help/workflows/workflow-basics.html#trigger_filter
8+
====
9+
10+
==Example==
11+
12+
```bash
13+
sail spconfig jsonpath
14+
```
15+
16+
====

cmd/root/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/sailpoint-oss/sailpoint-cli/cmd/cluster"
77
"github.com/sailpoint-oss/sailpoint-cli/cmd/connector"
88
"github.com/sailpoint-oss/sailpoint-cli/cmd/environment"
9+
"github.com/sailpoint-oss/sailpoint-cli/cmd/jsonpath"
910
"github.com/sailpoint-oss/sailpoint-cli/cmd/report"
1011
"github.com/sailpoint-oss/sailpoint-cli/cmd/rule"
1112
"github.com/sailpoint-oss/sailpoint-cli/cmd/sanitize"
@@ -53,6 +54,7 @@ func NewRootCommand() *cobra.Command {
5354
cluster.NewClusterCommand(),
5455
connector.NewConnCmd(t),
5556
environment.NewEnvironmentCommand(),
57+
jsonpath.NewJSONPathCmd(),
5658
report.NewReportCommand(),
5759
sdk.NewSDKCommand(),
5860
search.NewSearchCommand(),

cmd/root/root_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
// Expected number of subcommands to `sail` root command
1515
const (
16-
numRootSubcommands = 13
16+
numRootSubcommands = 14
1717
)
1818

1919
func TestNewRootCmd_noArgs(t *testing.T) {

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/sailpoint-oss/sailpoint-cli
33
go 1.21
44

55
require (
6+
github.com/bhmj/jsonslice v1.1.3
67
github.com/charmbracelet/bubbles v0.16.1
78
github.com/charmbracelet/bubbletea v0.24.2
89
github.com/charmbracelet/glamour v0.6.0
@@ -45,6 +46,7 @@ require (
4546
github.com/atotto/clipboard v0.1.4 // indirect
4647
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
4748
github.com/aymerick/douceur v0.2.0 // indirect
49+
github.com/bhmj/xpression v0.9.1 // indirect
4850
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
4951
github.com/danieljoos/wincred v1.2.0 // indirect
5052
github.com/dlclark/regexp2 v1.10.0 // indirect
@@ -78,6 +80,7 @@ require (
7880
github.com/spf13/afero v1.11.0 // indirect
7981
github.com/spf13/cast v1.6.0 // indirect
8082
github.com/subosito/gotenv v1.6.0 // indirect
83+
github.com/tidwall/pretty v1.2.1 // indirect
8184
github.com/yuin/goldmark v1.5.6 // indirect
8285
github.com/yuin/goldmark-emoji v1.0.2 // indirect
8386
go.uber.org/multierr v1.11.0 // indirect

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiE
1313
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
1414
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
1515
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
16+
github.com/bhmj/jsonslice v1.1.3 h1:aVYmtuQ8Gg1L3mAOFq3NMtfip8teUvC+DNArhv7IRDY=
17+
github.com/bhmj/jsonslice v1.1.3/go.mod h1:O3ZoA0zdEefdbk1dkU5aWPOA36zQhhS/HV6RQFLTlnU=
18+
github.com/bhmj/xpression v0.9.1 h1:N7bX/nWx9oFi/zsiMTx2ehoRApTDAWdQadq/5o2wMGk=
19+
github.com/bhmj/xpression v0.9.1/go.mod h1:j9oYmEXJjeL9mrgW1+ZDBKJXnbupsCPGhlO9J5YhS1Q=
1620
github.com/charmbracelet/bubbles v0.16.1 h1:6uzpAAaT9ZqKssntbvZMlksWHruQLNxg49H5WdeuYSY=
1721
github.com/charmbracelet/bubbles v0.16.1/go.mod h1:2QCp9LFlEsBQMvIYERr7Ww2H2bA7xen1idUDIzm/+Xc=
1822
github.com/charmbracelet/bubbletea v0.24.2 h1:uaQIKx9Ai6Gdh5zpTbGiWpytMU+CfsPp06RaW2cx/SY=
@@ -162,6 +166,8 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
162166
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
163167
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
164168
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
169+
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
170+
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
165171
github.com/vbauerster/mpb/v8 v8.6.1 h1:XbBpIbJxJOO9yMcKPpI4oEFPW6tLAptefNQJNcGWri8=
166172
github.com/vbauerster/mpb/v8 v8.6.1/go.mod h1:S0tuIjikxlLxCeNijNhwAuD/BB3UE/d2nygG8SOldk0=
167173
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=

0 commit comments

Comments
 (0)