Skip to content

Commit 84b5008

Browse files
authored
chore: add kmip 'Modify Attribute' and 'Delete Attribute' operation (#229)
1 parent 10958a0 commit 84b5008

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

cmd/okms/kmip/attributes.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,69 @@ func getAttributesCommand() *cobra.Command {
7373
}
7474
}
7575

76+
func deleteAttributeCommand() *cobra.Command {
77+
cmd := &cobra.Command{
78+
Use: "delete ID ATTRIBUTE_NAME",
79+
Short: "Delete an existing attribute of an object",
80+
Args: cobra.ExactArgs(2),
81+
Run: func(cmd *cobra.Command, args []string) {
82+
id := args[0]
83+
attrName := kmip.AttributeName(args[1])
84+
85+
req := kmipClient.DeleteAttribute(id, attrName)
86+
if idx, err := cmd.Flags().GetInt32("index"); err == nil && cmd.Flags().Changed("index") {
87+
req = req.WithIndex(idx)
88+
}
89+
90+
resp := exit.OnErr2(req.ExecContext(cmd.Context()))
91+
if cmd.Flag("output").Value.String() == string(flagsmgmt.JSON_OUTPUT_FORMAT) {
92+
output.JsonPrint(resp)
93+
return
94+
}
95+
printAttributeTable([]kmip.Attribute{resp.Attribute})
96+
},
97+
}
98+
cmd.Flags().Int32("index", 0, "Index of the attribute instance to delete (default 0)")
99+
return cmd
100+
}
101+
102+
func modifyAttributeCommand() *cobra.Command {
103+
cmd := &cobra.Command{
104+
Use: "modify ID ATTRIBUTE_NAME VALUE",
105+
Short: "Modify an existing attribute of an object",
106+
Long: `Modify an existing attribute of a KMIP managed object.
107+
108+
For the "Name" attribute, VALUE is passed as an 'Uninterpreted Text String'.
109+
For all other standard attributes, VALUE is passed as a plain 'Text String'.
110+
Therefore, only attributes with a 'Text String' encoding are supported with this command.`,
111+
Args: cobra.ExactArgs(3),
112+
Run: func(cmd *cobra.Command, args []string) {
113+
id := args[0]
114+
attrName := kmip.AttributeName(args[1])
115+
rawValue := args[2]
116+
117+
var value any
118+
switch attrName {
119+
case kmip.AttributeNameName:
120+
value = kmip.Name{
121+
NameValue: rawValue,
122+
NameType: kmip.NameTypeUninterpretedTextString,
123+
}
124+
default:
125+
value = rawValue
126+
}
127+
128+
resp := exit.OnErr2(kmipClient.ModifyAttribute(id, attrName, value).ExecContext(cmd.Context()))
129+
if cmd.Flag("output").Value.String() == string(flagsmgmt.JSON_OUTPUT_FORMAT) {
130+
output.JsonPrint(resp)
131+
return
132+
}
133+
printAttributeTable([]kmip.Attribute{resp.Attribute})
134+
},
135+
}
136+
return cmd
137+
}
138+
76139
func attributesCommand() *cobra.Command {
77140
cmd := &cobra.Command{
78141
Use: "attributes",
@@ -81,6 +144,8 @@ func attributesCommand() *cobra.Command {
81144
}
82145
cmd.AddCommand(
83146
getAttributesCommand(),
147+
modifyAttributeCommand(),
148+
deleteAttributeCommand(),
84149
)
85150
return cmd
86151
}

0 commit comments

Comments
 (0)