Skip to content

Commit 74be880

Browse files
committed
add filters; docs improvements
1 parent 47e6113 commit 74be880

8 files changed

Lines changed: 129 additions & 20 deletions

File tree

egress_webhooks.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ func egressWebhooksList() *cobra.Command {
3232
metadata := cmd.Flags().String("metadata", "", "webhook metadata")
3333

3434
cmd.RunE = func(cmd *cobra.Command, args []string) error {
35-
if md := *metadata; md != "" {
36-
out, err := klient.EgressWebhooks.Find(cmd.Context(), md)
35+
if cmd.Flags().Changed("metadata") {
36+
out, err := klient.EgressWebhooks.Find(cmd.Context(), *metadata)
3737
return output(out, err)
3838
} else {
3939
out, err := klient.EgressWebhooks.List(cmd.Context())
@@ -72,7 +72,7 @@ func egressWebhooksCreate() *cobra.Command {
7272

7373
func egressWebhooksGet() *cobra.Command {
7474
return &cobra.Command{
75-
Use: "get",
75+
Use: "get <egress-webhook-id>",
7676
Short: "get an egress webhook",
7777
Args: cobra.ExactArgs(1),
7878
RunE: func(cmd *cobra.Command, args []string) error {
@@ -84,7 +84,7 @@ func egressWebhooksGet() *cobra.Command {
8484

8585
func egressWebhooksRotate() *cobra.Command {
8686
cmd := &cobra.Command{
87-
Use: "rotate",
87+
Use: "rotate <egress-webhook-id>",
8888
Short: "rotate egress webhook secret",
8989
Args: cobra.ExactArgs(1),
9090
}
@@ -103,7 +103,7 @@ func egressWebhooksRotate() *cobra.Command {
103103

104104
func egressWebhooksStatus() *cobra.Command {
105105
return &cobra.Command{
106-
Use: "status",
106+
Use: "status <egress-webhook-id>",
107107
Short: "status an egress webhook",
108108
Args: cobra.ExactArgs(1),
109109
RunE: func(cmd *cobra.Command, args []string) error {
@@ -115,7 +115,7 @@ func egressWebhooksStatus() *cobra.Command {
115115

116116
func egressWebhooksDelete() *cobra.Command {
117117
return &cobra.Command{
118-
Use: "delete",
118+
Use: "delete <egress-webhook-id>",
119119
Short: "delete an egress webhook",
120120
Args: cobra.ExactArgs(1),
121121
RunE: func(cmd *cobra.Command, args []string) error {

filters.go

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package main
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
6+
"github.com/klev-dev/klev-api-go/filters"
7+
"github.com/klev-dev/klev-api-go/logs"
8+
)
9+
10+
func filtersRoot() *cobra.Command {
11+
cmd := &cobra.Command{
12+
Use: "filters",
13+
Short: "interact with filters",
14+
}
15+
16+
cmd.AddCommand(filtersList())
17+
cmd.AddCommand(filtersCreate())
18+
cmd.AddCommand(filtersGet())
19+
cmd.AddCommand(filtersStatus())
20+
cmd.AddCommand(filtersDelete())
21+
22+
return cmd
23+
}
24+
25+
func filtersList() *cobra.Command {
26+
cmd := &cobra.Command{
27+
Use: "list",
28+
Short: "list filters",
29+
}
30+
31+
metadata := cmd.Flags().String("metadata", "", "webhook metadata")
32+
33+
cmd.RunE = func(cmd *cobra.Command, args []string) error {
34+
if cmd.Flags().Changed("metadata") {
35+
out, err := klient.Filters.Find(cmd.Context(), *metadata)
36+
return output(out, err)
37+
} else {
38+
out, err := klient.Filters.List(cmd.Context())
39+
return output(out, err)
40+
}
41+
}
42+
43+
return cmd
44+
}
45+
46+
func filtersCreate() *cobra.Command {
47+
cmd := &cobra.Command{
48+
Use: "create",
49+
Short: "create new filter",
50+
}
51+
52+
var in filters.CreateParams
53+
54+
sourceID := cmd.Flags().String("source-id", "", "source log id of the filter")
55+
targetID := cmd.Flags().String("target-id", "", "target log id of the filter")
56+
cmd.Flags().StringVar(&in.Metadata, "metadata", "", "machine readable metadata")
57+
cmd.Flags().StringVar(&in.Expression, "expression", "", "expression to eval")
58+
59+
cmd.MarkFlagRequired("source-id")
60+
cmd.MarkFlagRequired("target-id")
61+
cmd.MarkFlagRequired("expression")
62+
63+
cmd.RunE = func(cmd *cobra.Command, args []string) error {
64+
in.SourceID = logs.LogID(*sourceID)
65+
in.TargetID = logs.LogID(*targetID)
66+
67+
out, err := klient.Filters.Create(cmd.Context(), in)
68+
return output(out, err)
69+
}
70+
71+
return cmd
72+
}
73+
74+
func filtersGet() *cobra.Command {
75+
return &cobra.Command{
76+
Use: "get <filter-id>",
77+
Short: "get a filter",
78+
Args: cobra.ExactArgs(1),
79+
RunE: func(cmd *cobra.Command, args []string) error {
80+
out, err := klient.Filters.Get(cmd.Context(), filters.FilterID(args[0]))
81+
return output(out, err)
82+
},
83+
}
84+
}
85+
86+
func filtersStatus() *cobra.Command {
87+
return &cobra.Command{
88+
Use: "status <filter-id>",
89+
Short: "status of a filter",
90+
Args: cobra.ExactArgs(1),
91+
RunE: func(cmd *cobra.Command, args []string) error {
92+
out, err := klient.Filters.Status(cmd.Context(), filters.FilterID(args[0]))
93+
return output(out, err)
94+
},
95+
}
96+
}
97+
98+
func filtersDelete() *cobra.Command {
99+
return &cobra.Command{
100+
Use: "delete <filter-id>",
101+
Short: "delete a filter",
102+
Args: cobra.ExactArgs(1),
103+
RunE: func(cmd *cobra.Command, args []string) error {
104+
out, err := klient.Filters.Delete(cmd.Context(), filters.FilterID(args[0]))
105+
return output(out, err)
106+
},
107+
}
108+
}

ingress_webhooks.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ func ingressWebhooksList() *cobra.Command {
3131
metadata := cmd.Flags().String("metadata", "", "webhook metadata")
3232

3333
cmd.RunE = func(cmd *cobra.Command, args []string) error {
34-
if md := *metadata; md != "" {
35-
out, err := klient.IngressWebhooks.Find(cmd.Context(), md)
34+
if cmd.Flags().Changed("metadata") {
35+
out, err := klient.IngressWebhooks.Find(cmd.Context(), *metadata)
3636
return output(out, err)
3737
} else {
3838
out, err := klient.IngressWebhooks.List(cmd.Context())
@@ -72,7 +72,7 @@ func ingressWebhooksCreate() *cobra.Command {
7272

7373
func ingressWebhooksGet() *cobra.Command {
7474
return &cobra.Command{
75-
Use: "get",
75+
Use: "get <ingress-webhook-id>",
7676
Short: "get an ingress webhook",
7777
Args: cobra.ExactArgs(1),
7878
RunE: func(cmd *cobra.Command, args []string) error {
@@ -84,7 +84,7 @@ func ingressWebhooksGet() *cobra.Command {
8484

8585
func ingressWebhooksRotate() *cobra.Command {
8686
cmd := &cobra.Command{
87-
Use: "rotate",
87+
Use: "rotate <ingress-webhook-id>",
8888
Short: "rotate ingress webhook secret",
8989
}
9090

@@ -104,7 +104,7 @@ func ingressWebhooksRotate() *cobra.Command {
104104

105105
func ingressWebhooksDelete() *cobra.Command {
106106
return &cobra.Command{
107-
Use: "delete",
107+
Use: "delete <ingress-webhook-id>",
108108
Short: "delete an ingress webhook",
109109
Args: cobra.ExactArgs(1),
110110
RunE: func(cmd *cobra.Command, args []string) error {

logs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func logsCreate() *cobra.Command {
6565

6666
func logsGet() *cobra.Command {
6767
return &cobra.Command{
68-
Use: "get log_id",
68+
Use: "get <log-id>",
6969
Short: "get a log",
7070
Args: cobra.ExactArgs(1),
7171
RunE: func(cmd *cobra.Command, args []string) error {
@@ -77,7 +77,7 @@ func logsGet() *cobra.Command {
7777

7878
func logsDelete() *cobra.Command {
7979
return &cobra.Command{
80-
Use: "delete log_id",
80+
Use: "delete <log-id>",
8181
Short: "delete a log",
8282
Args: cobra.ExactArgs(1),
8383
RunE: func(cmd *cobra.Command, args []string) error {

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func main() {
2626
rootCmd.AddCommand(tokensRoot())
2727
rootCmd.AddCommand(ingressWebhooksRoot())
2828
rootCmd.AddCommand(egressWebhooksRoot())
29+
rootCmd.AddCommand(filtersRoot())
2930

3031
if err := rootCmd.Execute(); err != nil {
3132
fmt.Fprintln(os.Stderr, err)

messages.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717

1818
func publish() *cobra.Command {
1919
cmd := &cobra.Command{
20-
Use: "publish log_id",
20+
Use: "publish <log-id>",
2121
Short: "publish a message",
2222
Args: cobra.ExactArgs(1),
2323
}
@@ -75,7 +75,7 @@ func publish() *cobra.Command {
7575

7676
func consume() *cobra.Command {
7777
cmd := &cobra.Command{
78-
Use: "consume log_id",
78+
Use: "consume <log-id>",
7979
Short: "consumes messages",
8080
Args: cobra.ExactArgs(1),
8181
}

offsets.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func offsetsCreate() *cobra.Command {
6666

6767
func offsetsGet() *cobra.Command {
6868
return &cobra.Command{
69-
Use: "get offset_id",
69+
Use: "get <offset-id>",
7070
Short: "get an offset",
7171
Args: cobra.ExactArgs(1),
7272
RunE: func(cmd *cobra.Command, args []string) error {
@@ -78,7 +78,7 @@ func offsetsGet() *cobra.Command {
7878

7979
func offsetsSet() *cobra.Command {
8080
cmd := &cobra.Command{
81-
Use: "set offset_id",
81+
Use: "set <offset-id>",
8282
Short: "set log offset",
8383
Args: cobra.ExactArgs(1),
8484
}
@@ -99,7 +99,7 @@ func offsetsSet() *cobra.Command {
9999

100100
func offsetsDelete() *cobra.Command {
101101
return &cobra.Command{
102-
Use: "delete offset_id",
102+
Use: "delete <offset-id>",
103103
Short: "delete an offset",
104104
Args: cobra.ExactArgs(1),
105105
RunE: func(cmd *cobra.Command, args []string) error {

tokens.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func tokensCreate() *cobra.Command {
6161

6262
func tokensGet() *cobra.Command {
6363
return &cobra.Command{
64-
Use: "get token_id",
64+
Use: "get <token-id>",
6565
Short: "get a token",
6666
Args: cobra.ExactArgs(1),
6767
RunE: func(cmd *cobra.Command, args []string) error {
@@ -73,7 +73,7 @@ func tokensGet() *cobra.Command {
7373

7474
func tokensDelete() *cobra.Command {
7575
return &cobra.Command{
76-
Use: "delete token_id",
76+
Use: "delete <token-id>",
7777
Short: "delete a token",
7878
Args: cobra.ExactArgs(1),
7979
RunE: func(cmd *cobra.Command, args []string) error {

0 commit comments

Comments
 (0)