Skip to content

Commit

Permalink
validate ids locally
Browse files Browse the repository at this point in the history
  • Loading branch information
ingon committed Feb 5, 2024
1 parent 1ec0806 commit 1a0beb2
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 25 deletions.
30 changes: 25 additions & 5 deletions egress_webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ func egressWebhooksGet() *cobra.Command {
Short: "get an egress webhook",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
id := klev.EgressWebhookID(args[0])
id, err := klev.ParseEgressWebhookID(args[0])
if err != nil {
return err
}

out, err := klient.EgressWebhooks.Get(cmd.Context(), id)
return output(out, err)
},
Expand All @@ -97,7 +101,11 @@ func egressWebhooksRotate() *cobra.Command {
cmd.Flags().Int64Var(&in.ExpireSeconds, "expire-seconds", 0, "for how long the old secret is valid")

cmd.RunE = func(cmd *cobra.Command, args []string) error {
id := klev.EgressWebhookID(args[0])
id, err := klev.ParseEgressWebhookID(args[0])
if err != nil {
return err
}

out, err := klient.EgressWebhooks.RotateRaw(cmd.Context(), id, in)
return output(out, err)
}
Expand All @@ -111,7 +119,11 @@ func egressWebhooksStatus() *cobra.Command {
Short: "status an egress webhook",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
id := klev.EgressWebhookID(args[0])
id, err := klev.ParseEgressWebhookID(args[0])
if err != nil {
return err
}

out, err := klient.EgressWebhooks.Status(cmd.Context(), id)
return output(out, err)
},
Expand All @@ -129,6 +141,11 @@ func egressWebhooksUpdate() *cobra.Command {
destination := cmd.Flags().String("destination", "", "where to deliver data")

cmd.RunE = func(cmd *cobra.Command, args []string) error {
id, err := klev.ParseEgressWebhookID(args[0])
if err != nil {
return err
}

var in klev.EgressWebhookUpdateParams

if cmd.Flags().Changed("metadata") {
Expand All @@ -138,7 +155,6 @@ func egressWebhooksUpdate() *cobra.Command {
in.Destination = destination
}

id := klev.EgressWebhookID(args[0])
out, err := klient.EgressWebhooks.UpdateRaw(cmd.Context(), id, in)
return output(out, err)
}
Expand All @@ -152,7 +168,11 @@ func egressWebhooksDelete() *cobra.Command {
Short: "delete an egress webhook",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
id := klev.EgressWebhookID(args[0])
id, err := klev.ParseEgressWebhookID(args[0])
if err != nil {
return err
}

out, err := klient.EgressWebhooks.Delete(cmd.Context(), id)
return output(out, err)
},
Expand Down
24 changes: 20 additions & 4 deletions filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ func filtersGet() *cobra.Command {
Short: "get a filter",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
id := klev.FilterID(args[0])
id, err := klev.ParseFilterID(args[0])
if err != nil {
return err
}

out, err := klient.Filters.Get(cmd.Context(), id)
return output(out, err)
},
Expand All @@ -92,7 +96,11 @@ func filtersStatus() *cobra.Command {
Short: "status of a filter",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
id := klev.FilterID(args[0])
id, err := klev.ParseFilterID(args[0])
if err != nil {
return err
}

out, err := klient.Filters.Status(cmd.Context(), id)
return output(out, err)
},
Expand All @@ -110,6 +118,11 @@ func filtersUpdate() *cobra.Command {
expression := cmd.Flags().String("expression", "", "expression to eval")

cmd.RunE = func(cmd *cobra.Command, args []string) error {
id, err := klev.ParseFilterID(args[0])
if err != nil {
return err
}

var in klev.FilterUpdateParams

if cmd.Flags().Changed("metadata") {
Expand All @@ -119,7 +132,6 @@ func filtersUpdate() *cobra.Command {
in.Expression = expression
}

id := klev.FilterID(args[0])
out, err := klient.Filters.UpdateRaw(cmd.Context(), id, in)
return output(out, err)
}
Expand All @@ -132,7 +144,11 @@ func filtersDelete() *cobra.Command {
Short: "delete a filter",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
id := klev.FilterID(args[0])
id, err := klev.ParseFilterID(args[0])
if err != nil {
return err
}

out, err := klient.Filters.Delete(cmd.Context(), id)
return output(out, err)
},
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/klev-dev/klev-cli
go 1.19

require (
github.com/klev-dev/klev-api-go v0.7.0
github.com/klev-dev/klev-api-go v0.7.1
github.com/spf13/cobra v1.6.1
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/klev-dev/klev-api-go v0.7.0 h1:nZt3yRmoMsVbCM2lTXcL1smh8/3wb64JZteK+wm8a5o=
github.com/klev-dev/klev-api-go v0.7.0/go.mod h1:RNe/KNgqBRjY/VYp87CwCS4wIsQMTNmdIvICEAeETR8=
github.com/klev-dev/klev-api-go v0.7.1 h1:ybhgX5FPbeffhgEbHx4XAwO38LzHRD/0JefLe8KrfUc=
github.com/klev-dev/klev-api-go v0.7.1/go.mod h1:RNe/KNgqBRjY/VYp87CwCS4wIsQMTNmdIvICEAeETR8=
github.com/klev-dev/kleverr v0.0.0-20230327002055-63b8717d8103 h1:QTdI0Ut6fvND4SCeuJqsuAY9FajkkmNL+okMFO9UuaU=
github.com/klev-dev/kleverr v0.0.0-20230327002055-63b8717d8103/go.mod h1:DV1tEcfsgAzKraeb/7nux27wOJs8w9P8fLB6GT7DmGM=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
18 changes: 15 additions & 3 deletions ingress_webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ func ingressWebhooksGet() *cobra.Command {
Short: "get an ingress webhook",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
id := klev.IngressWebhookID(args[0])
id, err := klev.ParseIngressWebhookID(args[0])
if err != nil {
return err
}

out, err := klient.IngressWebhooks.Get(cmd.Context(), id)
return output(out, err)
},
Expand All @@ -95,6 +99,11 @@ func ingressWebhooksUpdate() *cobra.Command {
secret := cmd.Flags().String("secret", "", "the secret to validate webhook messages")

cmd.RunE = func(cmd *cobra.Command, args []string) error {
id, err := klev.ParseIngressWebhookID(args[0])
if err != nil {
return err
}

var in klev.IngressWebhookUpdateParams

if cmd.Flags().Changed("metadata") {
Expand All @@ -104,7 +113,6 @@ func ingressWebhooksUpdate() *cobra.Command {
in.Secret = secret
}

id := klev.IngressWebhookID(args[0])
out, err := klient.IngressWebhooks.UpdateRaw(cmd.Context(), id, in)
return output(out, err)
}
Expand All @@ -118,7 +126,11 @@ func ingressWebhooksDelete() *cobra.Command {
Short: "delete an ingress webhook",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
id := klev.IngressWebhookID(args[0])
id, err := klev.ParseIngressWebhookID(args[0])
if err != nil {
return err
}

out, err := klient.IngressWebhooks.Delete(cmd.Context(), id)
return output(out, err)
},
Expand Down
24 changes: 20 additions & 4 deletions logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ func logsGet() *cobra.Command {
Short: "get a log",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
id := klev.LogID(args[0])
id, err := klev.ParseLogID(args[0])
if err != nil {
return err
}

out, err := klient.Logs.Get(cmd.Context(), id)
return output(out, err)
},
Expand All @@ -87,7 +91,11 @@ func logsStats() *cobra.Command {
Short: "stats a log",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
id := klev.LogID(args[0])
id, err := klev.ParseLogID(args[0])
if err != nil {
return err
}

out, err := klient.Logs.Stats(cmd.Context(), id)
return output(out, err)
},
Expand All @@ -109,6 +117,11 @@ func logsUpdate() *cobra.Command {
expireSeconds := cmd.Flags().Int64("expire-seconds", 0, "age of the log to expire")

cmd.RunE = func(cmd *cobra.Command, args []string) error {
id, err := klev.ParseLogID(args[0])
if err != nil {
return err
}

var in klev.LogUpdateParams

if cmd.Flags().Changed("metadata") {
Expand All @@ -130,7 +143,6 @@ func logsUpdate() *cobra.Command {
in.ExpireSeconds = expireSeconds
}

id := klev.LogID(args[0])
out, err := klient.Logs.UpdateRaw(cmd.Context(), id, in)
return output(out, err)
}
Expand All @@ -144,7 +156,11 @@ func logsDelete() *cobra.Command {
Short: "delete a log",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
id := klev.LogID(args[0])
id, err := klev.ParseLogID(args[0])
if err != nil {
return err
}

out, err := klient.Logs.Delete(cmd.Context(), id)
return output(out, err)
},
Expand Down
18 changes: 15 additions & 3 deletions offsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ func offsetsGet() *cobra.Command {
Short: "get an offset",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
id := klev.OffsetID(args[0])
id, err := klev.ParseOffsetID(args[0])
if err != nil {
return err
}

out, err := klient.Offsets.Get(cmd.Context(), id)
return output(out, err)
},
Expand All @@ -90,6 +94,11 @@ func offsetsUpdate() *cobra.Command {
valueMetadata := cmd.Flags().String("value-metadata", "", "machine readable metadata for the value")

cmd.RunE = func(cmd *cobra.Command, args []string) error {
id, err := klev.ParseOffsetID(args[0])
if err != nil {
return err
}

var in klev.OffsetUpdateParams

if cmd.Flags().Changed("metadata") {
Expand All @@ -102,7 +111,6 @@ func offsetsUpdate() *cobra.Command {
in.ValueMetadata = valueMetadata
}

id := klev.OffsetID(args[0])
out, err := klient.Offsets.UpdateRaw(cmd.Context(), id, in)
return output(out, err)
}
Expand All @@ -116,7 +124,11 @@ func offsetsDelete() *cobra.Command {
Short: "delete an offset",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
id := klev.OffsetID(args[0])
id, err := klev.ParseOffsetID(args[0])
if err != nil {
return err
}

out, err := klient.Offsets.Delete(cmd.Context(), id)
return output(out, err)
},
Expand Down
18 changes: 15 additions & 3 deletions tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ func tokensGet() *cobra.Command {
Short: "get a token",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
id := klev.TokenID(args[0])
id, err := klev.ParseTokenID(args[0])
if err != nil {
return err
}

out, err := klient.Tokens.Get(cmd.Context(), id)
return output(out, err)
},
Expand All @@ -86,6 +90,11 @@ func tokensUpdate() *cobra.Command {
acl := cmd.Flags().StringArray("acl", nil, "token acl")

cmd.RunE = func(cmd *cobra.Command, args []string) error {
id, err := klev.ParseTokenID(args[0])
if err != nil {
return err
}

var in klev.TokenUpdateParams

if cmd.Flags().Changed("metadata") {
Expand All @@ -95,7 +104,6 @@ func tokensUpdate() *cobra.Command {
in.ACL = acl
}

id := klev.TokenID(args[0])
out, err := klient.Tokens.UpdateRaw(cmd.Context(), id, in)
return output(out, err)
}
Expand All @@ -109,7 +117,11 @@ func tokensDelete() *cobra.Command {
Short: "delete a token",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
id := klev.TokenID(args[0])
id, err := klev.ParseTokenID(args[0])
if err != nil {
return err
}

out, err := klient.Tokens.Delete(cmd.Context(), id)
return output(out, err)
},
Expand Down

0 comments on commit 1a0beb2

Please sign in to comment.