summaryrefslogtreecommitdiff
path: root/cmd/podman/shared/parse/parse.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-02-15 12:50:48 +0100
committerGitHub <noreply@github.com>2020-02-15 12:50:48 +0100
commit92dbcb8841abae35658e5da1bf6eddee7669ea75 (patch)
treea0544ba444109eb5a8f252c8821828282225d8ad /cmd/podman/shared/parse/parse.go
parent9e9b157aa925d8d427999389aabf915dcad83355 (diff)
parent36a0ed9702bf4e6ef50650404c838a26f13ba879 (diff)
downloadpodman-92dbcb8841abae35658e5da1bf6eddee7669ea75.tar.gz
podman-92dbcb8841abae35658e5da1bf6eddee7669ea75.tar.bz2
podman-92dbcb8841abae35658e5da1bf6eddee7669ea75.zip
Merge pull request #5217 from mheon/rework_label_parsing
Rework label parsing
Diffstat (limited to 'cmd/podman/shared/parse/parse.go')
-rw-r--r--cmd/podman/shared/parse/parse.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/cmd/podman/shared/parse/parse.go b/cmd/podman/shared/parse/parse.go
index 3a75ff7a8..79449029d 100644
--- a/cmd/podman/shared/parse/parse.go
+++ b/cmd/podman/shared/parse/parse.go
@@ -79,6 +79,34 @@ func ValidateDomain(val string) (string, error) {
return "", fmt.Errorf("%s is not a valid domain", val)
}
+// GetAllLabels retrieves all labels given a potential label file and a number
+// of labels provided from the command line.
+func GetAllLabels(labelFile, inputLabels []string) (map[string]string, error) {
+ labels := make(map[string]string)
+ for _, file := range labelFile {
+ // Use of parseEnvFile still seems safe, as it's missing the
+ // extra parsing logic of parseEnv.
+ // There's an argument that we SHOULD be doing that parsing for
+ // all environment variables, even those sourced from files, but
+ // that would require a substantial rework.
+ if err := parseEnvFile(labels, file); err != nil {
+ return nil, err
+ }
+ }
+ for _, label := range inputLabels {
+ split := strings.SplitN(label, "=", 2)
+ if split[0] == "" {
+ return nil, errors.Errorf("invalid label format: %q", label)
+ }
+ value := ""
+ if len(split) > 1 {
+ value = split[1]
+ }
+ labels[split[0]] = value
+ }
+ return labels, nil
+}
+
// reads a file of line terminated key=value pairs, and overrides any keys
// present in the file with additional pairs specified in the override parameter
// for env-file and labels-file flags