@@ -74,21 +74,26 @@ func (c *command) newCreateCommand() *cobra.Command {
7474
7575 cmd .Flags ().String ("key-vault" , "" , "The ID of the Azure Key Vault where the key is stored." )
7676 cmd .Flags ().String ("tenant" , "" , "The ID of the Azure Active Directory tenant that the key vault belongs to." )
77+ cmd .Flags ().String ("display-name" , "" , "A human-readable name for the self-managed key." )
7778 pcmd .AddOutputFlag (cmd )
7879
7980 cmd .MarkFlagsRequiredTogether ("key-vault" , "tenant" )
8081
8182 return cmd
8283}
8384
84- func (c * command ) createAwsKeyRequest (keyArn string ) byokv1.ByokV1Key {
85- return byokv1.ByokV1Key {Key : & byokv1.ByokV1KeyKeyOneOf {ByokV1AwsKey : & byokv1.ByokV1AwsKey {
85+ func (c * command ) createAwsKeyRequest (keyArn , displayName string ) byokv1.ByokV1Key {
86+ key := byokv1.ByokV1Key {Key : & byokv1.ByokV1KeyKeyOneOf {ByokV1AwsKey : & byokv1.ByokV1AwsKey {
8687 KeyArn : keyArn ,
8788 Kind : "AwsKey" ,
8889 }}}
90+ if displayName != "" {
91+ key .SetDisplayName (displayName )
92+ }
93+ return key
8994}
9095
91- func (c * command ) createAzureKeyRequest (cmd * cobra.Command , keyString string ) (byokv1.ByokV1Key , error ) {
96+ func (c * command ) createAzureKeyRequest (cmd * cobra.Command , keyString , displayName string ) (byokv1.ByokV1Key , error ) {
9297 keyVault , err := cmd .Flags ().GetString ("key-vault" )
9398 if err != nil {
9499 return byokv1.ByokV1Key {}, err
@@ -106,33 +111,46 @@ func (c *command) createAzureKeyRequest(cmd *cobra.Command, keyString string) (b
106111 Kind : "AzureKey" ,
107112 }}}
108113
114+ if displayName != "" {
115+ keyReq .SetDisplayName (displayName )
116+ }
117+
109118 return keyReq , nil
110119}
111120
112- func (c * command ) createGcpKeyRequest (keyString string ) byokv1.ByokV1Key {
113- return byokv1.ByokV1Key {Key : & byokv1.ByokV1KeyKeyOneOf {ByokV1GcpKey : & byokv1.ByokV1GcpKey {
121+ func (c * command ) createGcpKeyRequest (keyString , displayName string ) byokv1.ByokV1Key {
122+ key := byokv1.ByokV1Key {Key : & byokv1.ByokV1KeyKeyOneOf {ByokV1GcpKey : & byokv1.ByokV1GcpKey {
114123 KeyId : keyString ,
115124 Kind : "GcpKey" ,
116125 }}}
126+ if displayName != "" {
127+ key .SetDisplayName (displayName )
128+ }
129+ return key
117130}
118131
119132func (c * command ) create (cmd * cobra.Command , args []string ) error {
120133 keyString := args [0 ]
121134 var keyReq byokv1.ByokV1Key
122135
136+ displayName , err := cmd .Flags ().GetString ("display-name" )
137+ if err != nil {
138+ return err
139+ }
140+
123141 switch {
124142 case cmd .Flags ().Changed ("key-vault" ) && cmd .Flags ().Changed ("tenant" ):
125143 keyString = removeKeyVersionFromAzureKeyId (keyString )
126144
127- request , err := c .createAzureKeyRequest (cmd , keyString )
145+ request , err := c .createAzureKeyRequest (cmd , keyString , displayName )
128146 if err != nil {
129147 return err
130148 }
131149 keyReq = request
132150 case isAWSKey (keyString ):
133- keyReq = c .createAwsKeyRequest (keyString )
151+ keyReq = c .createAwsKeyRequest (keyString , displayName )
134152 case isGcpKey (keyString ):
135- keyReq = c .createGcpKeyRequest (keyString )
153+ keyReq = c .createGcpKeyRequest (keyString , displayName )
136154 default :
137155 return fmt .Errorf ("invalid key format: %s" , keyString )
138156 }
0 commit comments