Skip to content

Commit

Permalink
fix: split by regex
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Kotzbauer <[email protected]>
  • Loading branch information
ckotzbauer committed Apr 25, 2022
1 parent 411a947 commit 2917d79
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions internal/job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"encoding/json"
"os"
"strings"
"regexp"
"time"

batchv1 "k8s.io/api/batch/v1"
Expand Down Expand Up @@ -109,12 +109,15 @@ func generateObjectSuffix() string {

func getJobEnvs() map[string]string {
m := make(map[string]string)
re := regexp.MustCompile(`SBOM_JOB_(?P<Key>[A-Za-z0-9-_\.]*)=(?P<Value>[A-Za-z0-9-_\.=]*)`)

for _, v := range os.Environ() {
splitted := strings.Split(v, "=")
if strings.HasPrefix(splitted[0], "SBOM_JOB_") {
key := strings.Replace(splitted[0], "SBOM_JOB_", "", 1)
m[key] = splitted[1]
matches := re.FindStringSubmatch(v)
if len(matches) > 1 {
index := re.SubexpIndex("Key")
key := matches[index]
index = re.SubexpIndex("Value")
m[key] = matches[index]
}
}

Expand Down

0 comments on commit 2917d79

Please sign in to comment.