// Handle getting and formating Azure Key Vault Secret from Azure Key Vault to Kubernetes
Handle getting and formating Azure Key Vault Secret from Azure Key Vault to Kubernetes
// Handle getting and formating Azure Key Vault Secret from Azure Key Vault to Kubernetes
func (h *AzureKeyVaultSecretHandler) Handle() (string, error) {
	secret, err := h.vaultService.GetSecret(&h.secretSpec.Spec.Vault)
	if err != nil {
		return "", err
	}
	secret, err = h.transformator.Transform(secret)
	if err != nil {
		return "", err
	}
	switch h.query {
	case "":
		return secret, nil
	case corev1.BasicAuthUsernameKey:
		creds := strings.Split(secret, ":")
		if len(creds) != 2 {
			return "", fmt.Errorf("unable to handle azure key vault env secret as basic auth - check that formatting is correct 'username:password'")
		}
		return creds[0], nil
	case corev1.BasicAuthPasswordKey:
		creds := strings.Split(secret, ":")
		if len(creds) != 2 {
			return "", fmt.Errorf("unable to handle azure key vault secret as basic auth - check that formatting is correct 'username:password'")
		}
		return creds[1], nil
	default:
		return "", fmt.Errorf("unable to handle azure key vault secret with query '%s' - query is not valid", h.query)
	}
}
func ( h * AzureKeyVaultSecretHandler ) Handle ( ) ( string , error ) { secret , err := h . vaultService . GetSecret ( & h . secretSpec . Spec . Vault ) if err != nil { return " " , err } secret , err = h . transformator . Transform ( secret ) if err != nil { return " " , err } switch h . query { case " " : return secret , nil case corev1 . BasicAuthUsernameKey : creds := strings . Split ( secret , " " ) if len ( creds ) != 2 { return " " , fmt . Errorf ( " " ) } return creds [ 0 ] , nil case corev1 . BasicAuthPasswordKey : creds := strings . Split ( secret , " " ) if len ( creds ) != 2 { return " " , fmt . Errorf ( " " ) } return creds [ 1 ] , nil default : return " " , fmt . Errorf ( " " , h . query ) } }
Handle getting and formating Azure Key Vault Secret from Azure Key Vault to Kubernetes
Handle getting and formating Azure Key Vault Secret from Azure Key Vault to Kubernetes