-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #362 from cyberark/parse-secrets-groups
Parse Secrets Groups
- Loading branch information
Showing
8 changed files
with
352 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package pushtofile | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
|
||
"github.com/cyberark/conjur-authn-k8s-client/pkg/log" | ||
"github.com/cyberark/secrets-provider-for-k8s/pkg/log/messages" | ||
) | ||
|
||
const ( | ||
conjurSecretsPrefix = "conjur.org/conjur-secrets." | ||
conjurSecretsPolicyPathPrefix = "conjur.org/conjur-secrets-policy-path." | ||
secretFilePathPrefix = "conjur.org/secret-file-path." | ||
secretFileFormatPrefix = "conjur.org/secret-file-format." | ||
secretFileTemplatePrefix = "conjur.org/secret-file-template." | ||
|
||
defaultFilePerms os.FileMode = 0777 | ||
) | ||
|
||
// SecretGroup comprises secrets mapping information for a given secrets | ||
// group. | ||
type SecretGroup struct { | ||
Label string | ||
FilePath string | ||
FileTemplate string | ||
ConjurSecretPathPrefix string | ||
SecretSpecs []SecretSpec | ||
FileFormat string | ||
FilePerms os.FileMode | ||
} | ||
|
||
// SecretGroups comprises secrets mapping info for all secret groups | ||
type SecretGroups []SecretGroup | ||
|
||
func NewSecretGroupsFromAnnotations(annotations map[string]string) (SecretGroups, error) { | ||
secretsGroups := []SecretGroup{} | ||
|
||
for annotation := range annotations { | ||
if strings.HasPrefix(annotation, conjurSecretsPrefix) { | ||
groupName := strings.TrimPrefix(annotation, conjurSecretsPrefix) | ||
conjurSecretPathPrefix := annotations[conjurSecretsPolicyPathPrefix+groupName] | ||
filePath := annotations[secretFilePathPrefix+groupName] | ||
fileTemplate := annotations[secretFileTemplatePrefix+groupName] | ||
|
||
fileFormat, err := parseFileFormat(annotations[secretFileFormatPrefix+groupName]) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
secrets, err := NewSecretSpecs([]byte(annotations[conjurSecretsPrefix+groupName])) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
group := SecretGroup{ | ||
Label: groupName, | ||
FilePath: filePath, | ||
FileTemplate: fileTemplate, | ||
ConjurSecretPathPrefix: conjurSecretPathPrefix, | ||
SecretSpecs: secrets, | ||
FileFormat: fileFormat, | ||
FilePerms: defaultFilePerms, | ||
} | ||
|
||
secretsGroups = append(secretsGroups, group) | ||
} | ||
} | ||
|
||
return secretsGroups, nil | ||
} | ||
|
||
func parseFileFormat(fileFormat string) (string, error) { | ||
switch fileFormat { | ||
case "yaml", "json", "dotenv", "bash", "plaintext": | ||
return fileFormat, nil | ||
case "": | ||
return "yaml", nil | ||
default: | ||
return "", log.RecordedError(messages.CSPFK051E, fileFormat) | ||
} | ||
} |
Oops, something went wrong.