Skip to content

Commit 897b5e6

Browse files
committed
fix: fix secrets commands
1 parent 7f6a315 commit 897b5e6

File tree

3 files changed

+42
-31
lines changed

3 files changed

+42
-31
lines changed

cmd/okms/secrets/secrets.go

+36-24
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ import (
2121

2222
func kvGetCmd() *cobra.Command {
2323
var (
24-
version int32
24+
version uint32
2525
)
2626

2727
cmd := &cobra.Command{
2828
Use: "get PATH",
2929
Short: "Retrieves the value from KMS's key-value store at the given key name",
3030
Args: cobra.ExactArgs(1),
3131
Run: func(cmd *cobra.Command, args []string) {
32-
var v *int32
32+
var v *uint32
3333
if version != 0 {
3434
v = &version
3535
}
@@ -56,7 +56,7 @@ func kvGetCmd() *cobra.Command {
5656
},
5757
}
5858

59-
cmd.Flags().Int32Var(&version, "version", 0, "If passed, the value at the version number will be returned")
59+
cmd.Flags().Uint32Var(&version, "version", 0, "If passed, the value at the version number will be returned")
6060
return cmd
6161
}
6262

@@ -78,14 +78,14 @@ func kvPutCmd() *cobra.Command {
7878
os.Exit(1)
7979
}
8080

81-
var c *int32
81+
var c uint32
8282
if cas != -1 {
83-
c = &cas
83+
c = utils.ToUint32(c)
8484
}
8585
body := types.PostSecretRequest{
8686
Data: new(any),
8787
Options: &types.PostSecretOptions{
88-
Cas: c,
88+
Cas: &c,
8989
},
9090
}
9191

@@ -122,14 +122,14 @@ func kvPatchCmd() *cobra.Command {
122122
os.Exit(1)
123123
}
124124

125-
var c *int32
125+
var c uint32
126126
if cas != -1 {
127-
c = &cas
127+
c = utils.ToUint32(cas)
128128
}
129129
body := types.PostSecretRequest{
130130
Data: new(any),
131131
Options: &types.PostSecretOptions{
132-
Cas: c,
132+
Cas: &c,
133133
},
134134
}
135135

@@ -150,7 +150,7 @@ func kvPatchCmd() *cobra.Command {
150150

151151
func kvDeleteCmd() *cobra.Command {
152152
var (
153-
versions []int32
153+
versions []uint
154154
)
155155

156156
cmd := &cobra.Command{
@@ -161,70 +161,82 @@ func kvDeleteCmd() *cobra.Command {
161161
if len(versions) == 0 {
162162
exit.OnErr(common.Client().DeleteSecretRequest(cmd.Context(), args[0]))
163163
} else {
164-
exit.OnErr(common.Client().DeleteSecretVersions(cmd.Context(), args[0], versions))
164+
var v []uint32
165+
for _, val := range versions {
166+
v = append(v, utils.ToUint32(val))
167+
}
168+
exit.OnErr(common.Client().DeleteSecretVersions(cmd.Context(), args[0], v))
165169
}
166170
},
167171
}
168172

169-
cmd.Flags().Int32SliceVar(&versions, "versions", []int32{}, "Specifies the version numbers to delete. (Comma separated list of versions)")
173+
cmd.Flags().UintSliceVar(&versions, "versions", []uint{}, "Specifies the version numbers to delete. (Comma separated list of versions)")
170174
return cmd
171175
}
172176

173177
func kvUndeleteCmd() *cobra.Command {
174178
var (
175-
versions []int32
179+
versions []uint
176180
)
177181

178182
cmd := &cobra.Command{
179183
Use: "undelete PATH",
180184
Short: "Undeletes the data for the provided version and path in the key-value store.",
181185
Args: cobra.ExactArgs(1),
182186
Run: func(cmd *cobra.Command, args []string) {
183-
exit.OnErr(common.Client().PostSecretUndelete(cmd.Context(), args[0], versions))
187+
var v []uint32
188+
for _, val := range versions {
189+
v = append(v, utils.ToUint32(val))
190+
}
191+
exit.OnErr(common.Client().PostSecretUndelete(cmd.Context(), args[0], v))
184192
},
185193
}
186194

187-
cmd.Flags().Int32SliceVar(&versions, "versions", []int32{}, "Specifies the version numbers to delete. (Comma separated list of versions)")
195+
cmd.Flags().UintSliceVar(&versions, "versions", []uint{}, "Specifies the version numbers to delete. (Comma separated list of versions)")
188196
_ = cmd.MarkFlagRequired("versions")
189197
return cmd
190198
}
191199

192200
func kvDestroyCmd() *cobra.Command {
193201
var (
194-
versions []int32
202+
versions []uint
195203
)
196204

197205
cmd := &cobra.Command{
198206
Use: "destroy PATH",
199207
Short: "Permanently removes the specified versions' data from the key-value store.",
200208
Args: cobra.ExactArgs(1),
201209
Run: func(cmd *cobra.Command, args []string) {
202-
exit.OnErr(common.Client().PostSecretDestroy(cmd.Context(), args[0], versions))
210+
var v []uint32
211+
for _, val := range versions {
212+
v = append(v, utils.ToUint32(val))
213+
}
214+
exit.OnErr(common.Client().PostSecretDestroy(cmd.Context(), args[0], v))
203215
},
204216
}
205217

206-
cmd.Flags().Int32SliceVar(&versions, "versions", []int32{}, "Specifies the version numbers to delete. (Comma separated list of versions)")
218+
cmd.Flags().UintSliceVar(&versions, "versions", []uint{}, "Specifies the version numbers to delete. (Comma separated list of versions)")
207219
_ = cmd.MarkFlagRequired("versions")
208220
return cmd
209221
}
210222

211223
func kvSubkeysCmd() *cobra.Command {
212224
var (
213-
version int32
214-
depth int32
225+
version uint32
226+
depth uint32
215227
)
216228

217229
cmd := &cobra.Command{
218230
Use: "subkeys PATH",
219231
Short: "Provides the subkeys within a secret entry that exists at the requested path.",
220232
Args: cobra.ExactArgs(1),
221233
Run: func(cmd *cobra.Command, args []string) {
222-
var v *int32
234+
var v *uint32
223235
if cmd.Flag("version").Changed {
224236
v = &version
225237
}
226238

227-
var d *int32
239+
var d *uint32
228240
if cmd.Flag("depth").Changed {
229241
d = &depth
230242
}
@@ -251,8 +263,8 @@ func kvSubkeysCmd() *cobra.Command {
251263
},
252264
}
253265

254-
cmd.Flags().Int32Var(&version, "version", 0, "The version to return")
255-
cmd.Flags().Int32Var(&depth, "depth", 0, "Deepest nesting level to provide in the output")
266+
cmd.Flags().Uint32Var(&version, "version", 0, "The version to return")
267+
cmd.Flags().Uint32Var(&depth, "depth", 0, "Deepest nesting level to provide in the output")
256268
return cmd
257269
}
258270

common/flagsmgmt/kmipflags/object_type.go

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const (
1616
ObjectTypePublicKey = ObjectType(kmip.ObjectTypePublicKey)
1717
ObjectTypePrivateKey = ObjectType(kmip.ObjectTypePrivateKey)
1818
ObjectTypeSplitKey = ObjectType(kmip.ObjectTypeSplitKey)
19-
//nolint:staticcheck // Needed to support legacy templates
2019
ObjectTypeTemplate = ObjectType(kmip.ObjectTypeTemplate)
2120
ObjectTypeSecretData = ObjectType(kmip.ObjectTypeSecretData)
2221
ObjectTypeOpaqueObject = ObjectType(kmip.ObjectTypeOpaqueObject)

common/utils/int.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ func ToUint64[N Integer](n N) uint64 {
2828
return uint64(n)
2929
}
3030

31-
// func ToUint32[N Integer](n N) uint32 {
32-
// if n < 0 || uint64(n) > math.MaxUint32 {
33-
// panic("Integer overflow")
34-
// }
35-
// return uint32(n)
36-
// }
31+
func ToUint32[N Integer](n N) uint32 {
32+
if n < 0 || uint64(n) > math.MaxUint32 {
33+
panic("Integer overflow")
34+
}
35+
return uint32(n)
36+
}
3737

3838
// func ToUint16[N Integer](n N) uint16 {
3939
// if n < 0 || uint64(n) > math.MaxUint16 {

0 commit comments

Comments
 (0)