@@ -80,9 +80,20 @@ func (r *RequestHandler) CreateKey() Response {
8080 body .Policy = & policy
8181 }
8282
83- if body .CustomerMasterKeySpec == nil {
83+ if body .KeySpec != nil && body .CustomerMasterKeySpec != nil {
84+ // Both values cannot be set
85+
86+ msg := fmt .Sprintf ("You cannot specify KeySpec and CustomerMasterKeySpec in the same request. CustomerMasterKeySpec is deprecated." )
87+ r .logger .Warnf (msg )
88+ return NewValidationExceptionResponse (msg )
89+ } else if body .KeySpec == nil && body .CustomerMasterKeySpec != nil {
90+ // If we only have CustomerMasterKeySpec, copy it over to KeySpec
91+ body .KeySpec = body .CustomerMasterKeySpec
92+
93+ } else if body .KeySpec == nil && body .CustomerMasterKeySpec == nil {
94+ // If neither are set, the default is SYMMETRIC_DEFAULT
8495 sd := "SYMMETRIC_DEFAULT"
85- body .CustomerMasterKeySpec = & sd
96+ body .KeySpec = & sd
8697 }
8798
8899 if body .Origin != nil {
@@ -91,8 +102,8 @@ func (r *RequestHandler) CreateKey() Response {
91102 // nop
92103 case "EXTERNAL" :
93104
94- if * body .CustomerMasterKeySpec != "SYMMETRIC_DEFAULT" {
95- msg := fmt .Sprintf ("KeySpec %s is not supported for Origin %s" , * body .CustomerMasterKeySpec , * body .Origin )
105+ if * body .KeySpec != "SYMMETRIC_DEFAULT" {
106+ msg := fmt .Sprintf ("KeySpec %s is not supported for Origin %s" , * body .KeySpec , * body .Origin )
96107
97108 r .logger .Warnf (msg )
98109 return NewValidationExceptionResponse (msg )
@@ -122,7 +133,7 @@ func (r *RequestHandler) CreateKey() Response {
122133
123134 var key cmk.Key
124135
125- switch * body .CustomerMasterKeySpec {
136+ switch * body .KeySpec {
126137 case "SYMMETRIC_DEFAULT" :
127138
128139 if body .KeyUsage != nil && * body .KeyUsage != "ENCRYPT_DECRYPT" {
@@ -142,12 +153,12 @@ func (r *RequestHandler) CreateKey() Response {
142153 }
143154
144155 if * body .KeyUsage != "SIGN_VERIFY" {
145- msg := fmt .Sprintf ("KeyUsage ENCRYPT_DECRYPT is not compatible with KeySpec %s" , * body .CustomerMasterKeySpec )
156+ msg := fmt .Sprintf ("KeyUsage ENCRYPT_DECRYPT is not compatible with KeySpec %s" , * body .KeySpec )
146157 r .logger .Warnf (msg )
147158 return NewValidationExceptionResponse (msg )
148159 }
149160
150- key , err = cmk .NewEccKey (cmk .CustomerMasterKeySpec (* body .CustomerMasterKeySpec ), metadata , * body .Policy )
161+ key , err = cmk .NewEccKey (cmk .KeySpec (* body .KeySpec ), metadata , * body .Policy )
151162 if err != nil {
152163 r .logger .Error (err )
153164 return NewInternalFailureExceptionResponse (err .Error ())
@@ -162,22 +173,22 @@ func (r *RequestHandler) CreateKey() Response {
162173 }
163174
164175 if ! (* body .KeyUsage == "SIGN_VERIFY" || * body .KeyUsage == "ENCRYPT_DECRYPT" ) {
165- msg := fmt .Sprintf ("KeyUsage %s is not compatible with KeySpec %s" , * body .KeyUsage , * body .CustomerMasterKeySpec )
176+ msg := fmt .Sprintf ("KeyUsage %s is not compatible with KeySpec %s" , * body .KeyUsage , * body .KeySpec )
166177 r .logger .Warnf (msg )
167178 return NewValidationExceptionResponse (msg )
168179 }
169180
170- key , err = cmk .NewRsaKey (cmk .CustomerMasterKeySpec (* body .CustomerMasterKeySpec ), cmk .KeyUsage (* body .KeyUsage ), metadata , * body .Policy )
181+ key , err = cmk .NewRsaKey (cmk .KeySpec (* body .KeySpec ), cmk .KeyUsage (* body .KeyUsage ), metadata , * body .Policy )
171182 if err != nil {
172183 r .logger .Error (err )
173184 return NewInternalFailureExceptionResponse (err .Error ())
174185 }
175186
176187 default :
177188
178- msg := fmt .Sprintf ("1 validation error detected: Value '%s' at 'customerMasterKeySpec ' " +
189+ msg := fmt .Sprintf ("1 validation error detected: Value '%s' at 'KeySpec ' " +
179190 "failed to satisfy constraint: Member must satisfy enum value set: [RSA_2048, ECC_NIST_P384, " +
180- "ECC_NIST_P256, ECC_NIST_P521, RSA_3072, ECC_SECG_P256K1, RSA_4096, SYMMETRIC_DEFAULT]" , * body .CustomerMasterKeySpec )
191+ "ECC_NIST_P256, ECC_NIST_P521, RSA_3072, ECC_SECG_P256K1, RSA_4096, SYMMETRIC_DEFAULT]" , * body .KeySpec )
181192
182193 r .logger .Warnf (msg )
183194
@@ -193,7 +204,7 @@ func (r *RequestHandler) CreateKey() Response {
193204 return NewInternalFailureExceptionResponse (err .Error ())
194205 }
195206
196- r .logger .Infof ("New key created: %s\n " , key .GetArn ())
207+ r .logger .Infof ("New %s key created: %s\n " , key . GetMetadata (). KeySpec , key .GetArn ())
197208
198209 //--------------------------------
199210 // Create the tags
0 commit comments