Skip to content

Commit

Permalink
add [] for special case (#392)
Browse files Browse the repository at this point in the history
Signed-off-by: Foysal Iqbal <[email protected]>
  • Loading branch information
Foysal Iqbal authored Jun 4, 2020
2 parents 97b2239 + bb2974f commit 0b60838
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
29 changes: 25 additions & 4 deletions pkg/api/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"net/http"
"os"
"path/filepath"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -78,8 +79,9 @@ func ProcessConfigArgs(args []string, base64Encoded bool) ([]*ServiceKeyValue, e
if len(first) != 2 {
return nil, notValidErr
}
second := strings.SplitN(first[0], ".", 2)
if len(second) != 2 {

svcKey := getSvcAndKey(first[0])
if len(svcKey) != 2 {
return nil, notValidErr
}
resultValue := strings.Trim(first[1], "\"")
Expand All @@ -91,14 +93,33 @@ func ProcessConfigArgs(args []string, base64Encoded bool) ([]*ServiceKeyValue, e
}
}
resultSvcKV[i] = &ServiceKeyValue{
SvcName: second[0],
Key: second[1],
SvcName: svcKey[0],
Key: svcKey[1],
Value: resultValue,
}
}
return resultSvcKV, nil
}

// input should be svc[key]
func getSvcAndKey(arg string) []string {
// for key
re := regexp.MustCompile(`\[(.*)\]`)
// for service
re2 := regexp.MustCompile(`(.*)\[`)

keys := re.FindStringSubmatch(arg)

svcs := re2.FindStringSubmatch(arg)
if len(svcs) != 2 || len(keys) != 2 {
return strings.SplitN(arg, ".", 2)
}
if svcs[1] == "" || keys[1] == "" {
return []string{}
}
return []string{svcs[1], keys[1]}
}

func ExecuteTaskWithBlinkingStdoutFeedback(task func() (interface{}, error), feedback string) (result interface{}, err error) {
taskDone := make(chan bool)
go func() {
Expand Down
21 changes: 21 additions & 0 deletions pkg/api/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,24 @@ func contains(arr []string, str string) bool {
}
return false
}

func TestGetSvcAndKey(t *testing.T) {
s1 := "qliksense[tls.cert]"
sa := getSvcAndKey(s1)
if sa[0] != "qliksense" || sa[1] != "tls.cert" {
t.Fail()
t.Logf("expected service: qliksense but got %s", sa[0])
t.Logf("expected key: tls.cert but got %s", sa[1])
}
s1 = "qliksense-idps.tls"
sa = getSvcAndKey(s1)
for _, s := range sa {
t.Logf("|%s|", s)
}
if sa[0] != "qliksense-idps" || sa[1] != "tls" {
t.Fail()
t.Logf("expected service: qliksense-idps but got %s", sa[0])
t.Logf("expected key: tls but got %s", sa[1])
}

}

0 comments on commit 0b60838

Please sign in to comment.