Skip to content

Commit e362023

Browse files
committed
update api to 0.5.0
1 parent 41ab83a commit e362023

10 files changed

Lines changed: 81 additions & 67 deletions

File tree

egress_webhooks.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ package main
33
import (
44
"github.com/spf13/cobra"
55

6-
"github.com/klev-dev/klev-api-go/egress_webhooks"
7-
"github.com/klev-dev/klev-api-go/logs"
6+
"github.com/klev-dev/klev-api-go"
87
)
98

109
func egressWebhooksRoot() *cobra.Command {
@@ -50,7 +49,7 @@ func egressWebhooksCreate() *cobra.Command {
5049
Short: "create new egress webhook",
5150
}
5251

53-
var in egress_webhooks.CreateParams
52+
var in klev.EgressWebhookCreateParams
5453

5554
logID := cmd.Flags().String("log-id", "", "log id that will store webhook data")
5655
cmd.Flags().StringVar(&in.Metadata, "metadata", "", "machine readable metadata")
@@ -61,7 +60,7 @@ func egressWebhooksCreate() *cobra.Command {
6160
cmd.MarkFlagRequired("destination")
6261

6362
cmd.RunE = func(cmd *cobra.Command, args []string) error {
64-
in.LogID = logs.LogID(*logID)
63+
in.LogID = klev.LogID(*logID)
6564

6665
out, err := klient.EgressWebhooks.Create(cmd.Context(), in)
6766
return output(out, err)
@@ -76,7 +75,8 @@ func egressWebhooksGet() *cobra.Command {
7675
Short: "get an egress webhook",
7776
Args: cobra.ExactArgs(1),
7877
RunE: func(cmd *cobra.Command, args []string) error {
79-
out, err := klient.EgressWebhooks.Get(cmd.Context(), egress_webhooks.EgressWebhookID(args[0]))
78+
id := klev.EgressWebhookID(args[0])
79+
out, err := klient.EgressWebhooks.Get(cmd.Context(), id)
8080
return output(out, err)
8181
},
8282
}
@@ -89,12 +89,13 @@ func egressWebhooksRotate() *cobra.Command {
8989
Args: cobra.ExactArgs(1),
9090
}
9191

92-
var in egress_webhooks.RotateParams
92+
var in klev.EgressWebhookRotateParams
9393

9494
cmd.Flags().Int64Var(&in.ExpireSeconds, "expire-seconds", 0, "for how long the old secret is valid")
9595

9696
cmd.RunE = func(cmd *cobra.Command, args []string) error {
97-
out, err := klient.EgressWebhooks.RotateRaw(cmd.Context(), egress_webhooks.EgressWebhookID(args[0]), in)
97+
id := klev.EgressWebhookID(args[0])
98+
out, err := klient.EgressWebhooks.RotateRaw(cmd.Context(), id, in)
9899
return output(out, err)
99100
}
100101

@@ -107,7 +108,8 @@ func egressWebhooksStatus() *cobra.Command {
107108
Short: "status an egress webhook",
108109
Args: cobra.ExactArgs(1),
109110
RunE: func(cmd *cobra.Command, args []string) error {
110-
out, err := klient.EgressWebhooks.Status(cmd.Context(), egress_webhooks.EgressWebhookID(args[0]))
111+
id := klev.EgressWebhookID(args[0])
112+
out, err := klient.EgressWebhooks.Status(cmd.Context(), id)
111113
return output(out, err)
112114
},
113115
}
@@ -119,7 +121,8 @@ func egressWebhooksDelete() *cobra.Command {
119121
Short: "delete an egress webhook",
120122
Args: cobra.ExactArgs(1),
121123
RunE: func(cmd *cobra.Command, args []string) error {
122-
out, err := klient.EgressWebhooks.Delete(cmd.Context(), egress_webhooks.EgressWebhookID(args[0]))
124+
id := klev.EgressWebhookID(args[0])
125+
out, err := klient.EgressWebhooks.Delete(cmd.Context(), id)
123126
return output(out, err)
124127
},
125128
}

filters.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ package main
33
import (
44
"github.com/spf13/cobra"
55

6-
"github.com/klev-dev/klev-api-go/filters"
7-
"github.com/klev-dev/klev-api-go/logs"
6+
"github.com/klev-dev/klev-api-go"
87
)
98

109
func filtersRoot() *cobra.Command {
@@ -49,7 +48,7 @@ func filtersCreate() *cobra.Command {
4948
Short: "create new filter",
5049
}
5150

52-
var in filters.CreateParams
51+
var in klev.FilterCreateParams
5352

5453
sourceID := cmd.Flags().String("source-id", "", "source log id of the filter")
5554
targetID := cmd.Flags().String("target-id", "", "target log id of the filter")
@@ -61,8 +60,8 @@ func filtersCreate() *cobra.Command {
6160
cmd.MarkFlagRequired("expression")
6261

6362
cmd.RunE = func(cmd *cobra.Command, args []string) error {
64-
in.SourceID = logs.LogID(*sourceID)
65-
in.TargetID = logs.LogID(*targetID)
63+
in.SourceID = klev.LogID(*sourceID)
64+
in.TargetID = klev.LogID(*targetID)
6665

6766
out, err := klient.Filters.Create(cmd.Context(), in)
6867
return output(out, err)
@@ -77,7 +76,8 @@ func filtersGet() *cobra.Command {
7776
Short: "get a filter",
7877
Args: cobra.ExactArgs(1),
7978
RunE: func(cmd *cobra.Command, args []string) error {
80-
out, err := klient.Filters.Get(cmd.Context(), filters.FilterID(args[0]))
79+
id := klev.FilterID(args[0])
80+
out, err := klient.Filters.Get(cmd.Context(), id)
8181
return output(out, err)
8282
},
8383
}
@@ -89,7 +89,8 @@ func filtersStatus() *cobra.Command {
8989
Short: "status of a filter",
9090
Args: cobra.ExactArgs(1),
9191
RunE: func(cmd *cobra.Command, args []string) error {
92-
out, err := klient.Filters.Status(cmd.Context(), filters.FilterID(args[0]))
92+
id := klev.FilterID(args[0])
93+
out, err := klient.Filters.Status(cmd.Context(), id)
9394
return output(out, err)
9495
},
9596
}
@@ -101,7 +102,8 @@ func filtersDelete() *cobra.Command {
101102
Short: "delete a filter",
102103
Args: cobra.ExactArgs(1),
103104
RunE: func(cmd *cobra.Command, args []string) error {
104-
out, err := klient.Filters.Delete(cmd.Context(), filters.FilterID(args[0]))
105+
id := klev.FilterID(args[0])
106+
out, err := klient.Filters.Delete(cmd.Context(), id)
105107
return output(out, err)
106108
},
107109
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/klev-dev/klev-cli
33
go 1.19
44

55
require (
6-
github.com/klev-dev/klev-api-go v0.4.1
6+
github.com/klev-dev/klev-api-go v0.5.0
77
github.com/spf13/cobra v1.6.1
88
)
99

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7P
44
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
55
github.com/klev-dev/klev-api-go v0.4.1 h1:yvE09kZD6rBKwtaZPlbO1dOstrPhJo+b6JLBY7RoA+U=
66
github.com/klev-dev/klev-api-go v0.4.1/go.mod h1:RNe/KNgqBRjY/VYp87CwCS4wIsQMTNmdIvICEAeETR8=
7+
github.com/klev-dev/klev-api-go v0.5.0 h1:4R45xsYlIdg+8Cz/hyxgTXHaF/SRhAUdIvv1JeI/zRI=
8+
github.com/klev-dev/klev-api-go v0.5.0/go.mod h1:RNe/KNgqBRjY/VYp87CwCS4wIsQMTNmdIvICEAeETR8=
79
github.com/klev-dev/kleverr v0.0.0-20230327002055-63b8717d8103 h1:QTdI0Ut6fvND4SCeuJqsuAY9FajkkmNL+okMFO9UuaU=
810
github.com/klev-dev/kleverr v0.0.0-20230327002055-63b8717d8103/go.mod h1:DV1tEcfsgAzKraeb/7nux27wOJs8w9P8fLB6GT7DmGM=
911
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

ingress_webhooks.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ package main
33
import (
44
"github.com/spf13/cobra"
55

6-
"github.com/klev-dev/klev-api-go/ingress_webhooks"
7-
"github.com/klev-dev/klev-api-go/logs"
6+
"github.com/klev-dev/klev-api-go"
87
)
98

109
func ingressWebhooksRoot() *cobra.Command {
@@ -49,7 +48,7 @@ func ingressWebhooksCreate() *cobra.Command {
4948
Short: "create new ingress webhook",
5049
}
5150

52-
var in ingress_webhooks.CreateParams
51+
var in klev.IngressWebhookCreateParams
5352

5453
logID := cmd.Flags().String("log-id", "", "log id that will store webhook data")
5554
cmd.Flags().StringVar(&in.Metadata, "metadata", "", "machine readable metadata")
@@ -61,7 +60,7 @@ func ingressWebhooksCreate() *cobra.Command {
6160
cmd.MarkFlagRequired("secret")
6261

6362
cmd.RunE = func(cmd *cobra.Command, args []string) error {
64-
in.LogID = logs.LogID(*logID)
63+
in.LogID = klev.LogID(*logID)
6564

6665
out, err := klient.IngressWebhooks.Create(cmd.Context(), in)
6766
return output(out, err)
@@ -76,7 +75,8 @@ func ingressWebhooksGet() *cobra.Command {
7675
Short: "get an ingress webhook",
7776
Args: cobra.ExactArgs(1),
7877
RunE: func(cmd *cobra.Command, args []string) error {
79-
out, err := klient.IngressWebhooks.Get(cmd.Context(), ingress_webhooks.IngressWebhookID(args[0]))
78+
id := klev.IngressWebhookID(args[0])
79+
out, err := klient.IngressWebhooks.Get(cmd.Context(), id)
8080
return output(out, err)
8181
},
8282
}
@@ -88,14 +88,15 @@ func ingressWebhooksRotate() *cobra.Command {
8888
Short: "rotate ingress webhook secret",
8989
}
9090

91-
var in ingress_webhooks.RotateParams
91+
var in klev.IngressWebhookRotateParams
9292

9393
cmd.Flags().StringVar(&in.Secret, "secret", "", "the secret to validate webhook messages")
9494

9595
cmd.MarkFlagRequired("secret")
9696

9797
cmd.RunE = func(cmd *cobra.Command, args []string) error {
98-
out, err := klient.IngressWebhooks.RotateRaw(cmd.Context(), ingress_webhooks.IngressWebhookID(args[0]), in)
98+
id := klev.IngressWebhookID(args[0])
99+
out, err := klient.IngressWebhooks.RotateRaw(cmd.Context(), id, in)
99100
return output(out, err)
100101
}
101102

@@ -108,7 +109,8 @@ func ingressWebhooksDelete() *cobra.Command {
108109
Short: "delete an ingress webhook",
109110
Args: cobra.ExactArgs(1),
110111
RunE: func(cmd *cobra.Command, args []string) error {
111-
out, err := klient.IngressWebhooks.Delete(cmd.Context(), ingress_webhooks.IngressWebhookID(args[0]))
112+
id := klev.IngressWebhookID(args[0])
113+
out, err := klient.IngressWebhooks.Delete(cmd.Context(), id)
112114
return output(out, err)
113115
},
114116
}

logs.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package main
22

33
import (
4-
"github.com/klev-dev/klev-api-go/logs"
4+
"github.com/klev-dev/klev-api-go"
55
"github.com/spf13/cobra"
66
)
77

@@ -46,7 +46,7 @@ func logsCreate() *cobra.Command {
4646
Short: "create new log",
4747
}
4848

49-
var in logs.CreateParams
49+
var in klev.LogCreateParams
5050

5151
cmd.Flags().StringVar(&in.Metadata, "metadata", "", "machine readable metadata")
5252
cmd.Flags().BoolVar(&in.Compacting, "compacting", false, "if the log is compacting")
@@ -69,7 +69,8 @@ func logsGet() *cobra.Command {
6969
Short: "get a log",
7070
Args: cobra.ExactArgs(1),
7171
RunE: func(cmd *cobra.Command, args []string) error {
72-
out, err := klient.Logs.Get(cmd.Context(), logs.LogID(args[0]))
72+
id := klev.LogID(args[0])
73+
out, err := klient.Logs.Get(cmd.Context(), id)
7374
return output(out, err)
7475
},
7576
}
@@ -81,7 +82,8 @@ func logsDelete() *cobra.Command {
8182
Short: "delete a log",
8283
Args: cobra.ExactArgs(1),
8384
RunE: func(cmd *cobra.Command, args []string) error {
84-
out, err := klient.Logs.Delete(cmd.Context(), logs.LogID(args[0]))
85+
id := klev.LogID(args[0])
86+
out, err := klient.Logs.Delete(cmd.Context(), id)
8587
return output(out, err)
8688
},
8789
}

main.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ import (
88

99
"github.com/spf13/cobra"
1010

11-
api "github.com/klev-dev/klev-api-go"
12-
"github.com/klev-dev/klev-api-go/client"
13-
"github.com/klev-dev/klev-api-go/errors"
11+
"github.com/klev-dev/klev-api-go"
12+
"github.com/klev-dev/klev-api-go/clients"
1413
)
1514

16-
var klient *api.Clients
15+
var klient *clients.Clients
1716

1817
func main() {
1918
rootCmd := root()
@@ -54,13 +53,13 @@ func root() *cobra.Command {
5453
return fmt.Errorf("authtoken is missing. pass with with '--authtoken' or via KLEV_TOKEN env variable. get it from https://dash.klev.dev")
5554
}
5655

57-
cfg := client.NewConfig(auth)
56+
cfg := klev.NewConfig(auth)
5857
if cmd.Flags().Changed("base-url") {
5958
cfg.BaseURL = *base
6059
} else if base := os.Getenv("KLEV_URL"); base != "" {
6160
cfg.BaseURL = base
6261
}
63-
klient = api.New(cfg)
62+
klient = clients.New(cfg)
6463
return nil
6564
}
6665

@@ -79,7 +78,7 @@ func paths() *cobra.Command {
7978
}
8079

8180
func output(v any, err error) error {
82-
if err := errors.GetError(err); err != nil {
81+
if err := klev.GetError(err); err != nil {
8382
return outputValue(os.Stderr, err)
8483
} else if err != nil {
8584
return err

0 commit comments

Comments
 (0)