@@ -191,31 +191,35 @@ type creationRule struct {
191191
192192// Helper methods to safely extract keys as []string
193193func (c * creationRule ) GetKMSKeys () ([]string , error ) {
194- return parseKeyField (c .KMS )
194+ return parseKeyField (c .KMS , "kms" )
195195}
196196
197197func (c * creationRule ) GetAgeKeys () ([]string , error ) {
198- return parseKeyField (c .Age )
198+ return parseKeyField (c .Age , "age" )
199199}
200200
201201func (c * creationRule ) GetPGPKeys () ([]string , error ) {
202- return parseKeyField (c .PGP )
202+ return parseKeyField (c .PGP , "pgp" )
203203}
204204
205205func (c * creationRule ) GetGCPKMSKeys () ([]string , error ) {
206- return parseKeyField (c .GCPKMS )
206+ return parseKeyField (c .GCPKMS , "gcp_kms" )
207207}
208208
209209func (c * creationRule ) GetAzureKeyVaultKeys () ([]string , error ) {
210- return parseKeyField (c .AzureKeyVault )
210+ return parseKeyField (c .AzureKeyVault , "azure_keyvault" )
211211}
212212
213213func (c * creationRule ) GetVaultURIs () ([]string , error ) {
214- return parseKeyField (c .VaultURI )
214+ return parseKeyField (c .VaultURI , "hc_vault_transit_uri" )
215215}
216216
217217// Utility function to handle both string and []string
218- func parseKeyField (field interface {}) ([]string , error ) {
218+ func parseKeyField (field interface {}, fieldName string ) ([]string , error ) {
219+ if field == nil {
220+ return []string {}, nil
221+ }
222+
219223 switch v := field .(type ) {
220224 case string :
221225 if v == "" {
@@ -234,13 +238,17 @@ func parseKeyField(field interface{}) ([]string, error) {
234238 case []interface {}:
235239 result := make ([]string , len (v ))
236240 for i , item := range v {
237- result [i ] = fmt .Sprintf ("%v" , item )
241+ if str , ok := item .(string ); ok {
242+ result [i ] = str
243+ } else {
244+ return nil , fmt .Errorf ("invalid %s key configuration: expected string in list, got %T" , fieldName , item )
245+ }
238246 }
239247 return result , nil
240248 case []string :
241249 return v , nil
242250 default :
243- return nil , fmt .Errorf ("invalid key field type : expected string, []string, or nil, got %T" , field )
251+ return nil , fmt .Errorf ("invalid %s key configuration : expected string, []string, or nil, got %T" , fieldName , field )
244252 }
245253}
246254
@@ -359,7 +367,7 @@ func getKeyGroupsFromCreationRule(cRule *creationRule, kmsEncryptionContext map[
359367 return nil , err
360368 }
361369
362- if cRule . Age != "" {
370+ if len ( ageKeys ) > 0 {
363371 ageKeys , err := age .MasterKeysFromRecipients (strings .Join (ageKeys , "," ))
364372 if err != nil {
365373 return nil , err
@@ -390,7 +398,7 @@ func getKeyGroupsFromCreationRule(cRule *creationRule, kmsEncryptionContext map[
390398 for _ , k := range gcpkms .MasterKeysFromResourceIDString (strings .Join (gcpkmsKeys , "," )) {
391399 keyGroup = append (keyGroup , k )
392400 }
393- azKeys , err := getKeysWithValidation (cRule .GetAzureKeyVaultKeys , "axkeyvault " )
401+ azKeys , err := getKeysWithValidation (cRule .GetAzureKeyVaultKeys , "azure_keyvault " )
394402 if err != nil {
395403 return nil , err
396404 }
0 commit comments