diff --git a/README.md b/README.md index 39ea708..2210402 100644 --- a/README.md +++ b/README.md @@ -173,15 +173,15 @@ response format: response format: ```json { - "ContentType": "...", - "ETag": "...", - "IsReadOnly": false, - "Key":" ...", - "Label": null, - "LastModified": null, - "SyncToken": "...", - "Tags": {}, - "Value": "..." + "contentType": "...", + "eTag": "...", + "isReadOnly": false, + "key":" ...", + "label": null, + "lastModified": null, + "syncToken": "...", + "tags": {}, + "value": "..." } ``` diff --git a/azuretpl/azure.appconfig.go b/azuretpl/azure.appconfig.go index 7986a82..47f0666 100644 --- a/azuretpl/azure.appconfig.go +++ b/azuretpl/azure.appconfig.go @@ -10,6 +10,8 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/data/azappconfig" "github.com/webdevops/go-common/azuresdk/cloudconfig" "github.com/webdevops/go-common/utils/to" + + "github.com/webdevops/helm-azure-tpl/azuretpl/models" ) // buildAppConfigUrl builds Azure AppConfig url in case value is supplied as AppConfig name only @@ -108,6 +110,6 @@ func (e *AzureTemplateExecutor) azAppConfigSetting(appConfigUrl string, settingN appConfigValue.Value = to.StringPtr(secretMap["value"].(string)) } - return transformToInterface(appConfigValue) + return transformToInterface(models.NewAzAppconfigSettingFromReponse(appConfigValue)) }) } diff --git a/azuretpl/azure.keyvault.go b/azuretpl/azure.keyvault.go index 894d81e..5d910ae 100644 --- a/azuretpl/azure.keyvault.go +++ b/azuretpl/azure.keyvault.go @@ -11,58 +11,10 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azsecrets" "github.com/webdevops/go-common/azuresdk/cloudconfig" "github.com/webdevops/go-common/utils/to" -) - -type ( - AzKeyvaultSecretItem struct { - // The secret management attributes. - Attributes *azsecrets.SecretAttributes `json:"attributes"` - - // The content type of the secret. - ContentType *string `json:"contentType"` - - // The secret id. - ID string `json:"id"` - - // Application specific metadata in the form of key-value pairs. - Tags map[string]*string `json:"tags"` - - // The secret value. - Value *string `json:"value"` - - Managed bool `json:"managed"` - Version string `json:"version" yaml:"version"` - Name string `json:"name" yaml:"name"` - } + "github.com/webdevops/helm-azure-tpl/azuretpl/models" ) -func newAzKeyvaultSecretItem(secret azsecrets.Secret) *AzKeyvaultSecretItem { - return &AzKeyvaultSecretItem{ - Attributes: secret.Attributes, - ContentType: secret.ContentType, - ID: string(*secret.ID), - Tags: secret.Tags, - Value: secret.Value, - Managed: to.Bool(secret.Managed), - Version: secret.ID.Version(), - Name: secret.ID.Name(), - } -} - -func newAzKeyvaultSecretListItem(secret azsecrets.SecretProperties) *AzKeyvaultSecretItem { - return &AzKeyvaultSecretItem{ - Attributes: secret.Attributes, - ContentType: secret.ContentType, - ID: string(*secret.ID), - Tags: secret.Tags, - Value: nil, - Managed: to.Bool(secret.Managed), - Version: secret.ID.Version(), - Name: secret.ID.Name(), - } -} - // buildAzKeyVaulUrl builds Azure KeyVault url in case value is supplied as KeyVault name only func (e *AzureTemplateExecutor) buildAzKeyVaulUrl(vaultUrl string) (string, error) { // do not build keyvault url in lint mode @@ -156,7 +108,7 @@ func (e *AzureTemplateExecutor) azKeyVaultSecret(vaultUrl string, secretName str e.logger.Infof(`using Azure KeyVault secret '%v' -> '%v' (version: %v)`, vaultUrl, secretName, secret.ID.Version()) e.handleCicdMaskSecret(to.String(secret.Secret.Value)) - return transformToInterface(newAzKeyvaultSecretItem(secret.Secret)) + return transformToInterface(models.NewAzSecretItem(secret.Secret)) }) } @@ -219,7 +171,7 @@ func (e *AzureTemplateExecutor) azKeyVaultSecretVersions(vaultUrl string, secret e.handleCicdMaskSecret(to.String(secret.Secret.Value)) - if val, err := transformToInterface(newAzKeyvaultSecretItem(secret.Secret)); err == nil { + if val, err := transformToInterface(models.NewAzSecretItem(secret.Secret)); err == nil { ret = append(ret, val) } else { return nil, err @@ -270,7 +222,7 @@ func (e *AzureTemplateExecutor) azKeyVaultSecretList(vaultUrl string, secretName } for _, secret := range result.Value { - secretData, err := transformToInterface(newAzKeyvaultSecretListItem(*secret)) + secretData, err := transformToInterface(models.NewAzSecretItemFromSecretproperties(*secret)) if err != nil { return nil, fmt.Errorf(`unable to transform KeyVault secret '%v': %w`, secret.ID.Name(), err) } diff --git a/azuretpl/models/appconfig.go b/azuretpl/models/appconfig.go new file mode 100644 index 0000000..3a35417 --- /dev/null +++ b/azuretpl/models/appconfig.go @@ -0,0 +1,64 @@ +package models + +import ( + "time" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/data/azappconfig" + "github.com/webdevops/go-common/utils/to" +) + +type ( + AzAppconfigSetting struct { + // The primary identifier of the configuration setting. + // A Key is used together with a Label to uniquely identify a configuration setting. + Key *string `json:"key"` + + // The configuration setting's value. + Value *string `json:"value"` + + // A value used to group configuration settings. + // A Label is used together with a Key to uniquely identify a configuration setting. + Label *string `json:"label"` + + // The content type of the configuration setting's value. + // Providing a proper content-type can enable transformations of values when they are retrieved by applications. + ContentType *string `json:"contentType"` + + // An ETag indicating the state of a configuration setting within a configuration store. + ETag *azcore.ETag `json:"eTag"` + + // A dictionary of tags used to assign additional properties to a configuration setting. + // These can be used to indicate how a configuration setting may be applied. + Tags map[string]string `json:"tags"` + + // The last time a modifying operation was performed on the given configuration setting. + LastModified *time.Time `json:"lastModified"` + + // A value indicating whether the configuration setting is read only. + // A read only configuration setting may not be modified until it is made writable. + IsReadOnly bool `json:"isReadOnly"` + + // Sync token for the Azure App Configuration client, corresponding to the current state of the client. + SyncToken *string `json:"syncToken"` + } +) + +func NewAzAppconfigSetting(setting azappconfig.Setting) *AzAppconfigSetting { + return &AzAppconfigSetting{ + Key: setting.Key, + Value: setting.Value, + Label: setting.Label, + ContentType: setting.ContentType, + ETag: setting.ETag, + Tags: setting.Tags, + LastModified: setting.LastModified, + IsReadOnly: to.Bool(setting.IsReadOnly), + } +} + +func NewAzAppconfigSettingFromReponse(setting azappconfig.GetSettingResponse) *AzAppconfigSetting { + ret := NewAzAppconfigSetting(setting.Setting) + ret.SyncToken = setting.SyncToken + return ret +} diff --git a/azuretpl/models/keyvault.go b/azuretpl/models/keyvault.go new file mode 100644 index 0000000..2a105f9 --- /dev/null +++ b/azuretpl/models/keyvault.go @@ -0,0 +1,56 @@ +package models + +import ( + "github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azsecrets" + "github.com/webdevops/go-common/utils/to" +) + +type ( + AzSecret struct { + // The secret management attributes. + Attributes *azsecrets.SecretAttributes `json:"attributes"` + + // The content type of the secret. + ContentType *string `json:"contentType"` + + // The secret id. + ID string `json:"id"` + + // Application specific metadata in the form of key-value pairs. + Tags map[string]*string `json:"tags"` + + // The secret value. + Value *string `json:"value"` + + Managed bool `json:"managed"` + + Version string `json:"version" yaml:"version"` + Name string `json:"name" yaml:"name"` + } +) + +func NewAzSecretItem(secret azsecrets.Secret) *AzSecret { + return &AzSecret{ + Attributes: secret.Attributes, + ContentType: secret.ContentType, + ID: string(*secret.ID), + Tags: secret.Tags, + Value: secret.Value, + Managed: to.Bool(secret.Managed), + Version: secret.ID.Version(), + Name: secret.ID.Name(), + } +} + +func NewAzSecretItemFromSecretproperties(secret azsecrets.SecretProperties) *AzSecret { + return &AzSecret{ + Attributes: secret.Attributes, + ContentType: secret.ContentType, + ID: string(*secret.ID), + Tags: secret.Tags, + Value: nil, + Managed: to.Bool(secret.Managed), + Version: secret.ID.Version(), + Name: secret.ID.Name(), + } +}