// Handle getting and formating Azure Key Vault Secret containing mulitple values from Azure Key Vault to Kubernetes
Handle getting and formating Azure Key Vault Secret containing mulitple values from Azure Key Vault to Kubernetes
// Handle getting and formating Azure Key Vault Secret containing mulitple values from Azure Key Vault to Kubernetes
func (h *AzureKeyVaultMultiValueSecretHandler) Handle() (string, error) {
	if h.secretSpec.Spec.Vault.Object.ContentType == "" {
		return "", fmt.Errorf("cannot use '%s' without also specifying content type", akv.AzureKeyVaultObjectTypeMultiKeyValueSecret)
	}
	secret, err := h.vaultService.GetSecret(&h.secretSpec.Spec.Vault)
	if err != nil {
		return "", err
	}
	var dat map[string]string
	switch h.secretSpec.Spec.Vault.Object.ContentType {
	case akv.AzureKeyVaultObjectContentTypeJSON:
		if err := json.Unmarshal([]byte(secret), &dat); err != nil {
			return "", err
		}
	case akv.AzureKeyVaultObjectContentTypeYaml:
		if err := yaml.Unmarshal([]byte(secret), &dat); err != nil {
			return "", err
		}
	default:
		return "", fmt.Errorf("content type '%s' not supported", h.secretSpec.Spec.Vault.Object.ContentType)
	}
	if val, ok := dat[h.query]; ok {
		return val, nil
	}
	return "", fmt.Errorf("key '%s' not found in azure key vault secret '%s' of type '%s'", h.query, h.secretSpec.Spec.Vault.Object.Name, h.secretSpec.Spec.Vault.Object.ContentType)
}
func ( h * AzureKeyVaultMultiValueSecretHandler ) Handle ( ) ( string , error ) { if h . secretSpec . Spec . Vault . Object . ContentType == " " { return " " , fmt . Errorf ( " " , akv . AzureKeyVaultObjectTypeMultiKeyValueSecret ) } secret , err := h . vaultService . GetSecret ( & h . secretSpec . Spec . Vault ) if err != nil { return " " , err } var dat map [ string ] string switch h . secretSpec . Spec . Vault . Object . ContentType { case akv . AzureKeyVaultObjectContentTypeJSON : if err := json . Unmarshal ( [ ] byte ( secret ) , & dat ) ; err != nil { return " " , err } case akv . AzureKeyVaultObjectContentTypeYaml : if err := yaml . Unmarshal ( [ ] byte ( secret ) , & dat ) ; err != nil { return " " , err } default : return " " , fmt . Errorf ( " " , h . secretSpec . Spec . Vault . Object . ContentType ) } if val , ok := dat [ h . query ] ; ok { return val , nil } return " " , fmt . Errorf ( " " , h . query , h . secretSpec . Spec . Vault . Object . Name , h . secretSpec . Spec . Vault . Object . ContentType ) }
Handle getting and formating Azure Key Vault Secret containing mulitple values from Azure Key Vault to Kubernetes
Handle getting and formating Azure Key Vault Secret containing mulitple values from Azure Key Vault to Kubernetes