Skip to content
This repository has been archived by the owner on Mar 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #30 from magneticio/bug/LAM-247
Browse files Browse the repository at this point in the history
Fix for json path, now it supports Yaml and large structs LAM-247
  • Loading branch information
bgokden authored May 8, 2019
2 parents cffeba9 + 302f990 commit 76b3dc2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Json path example with wait
if JsonPath != "" {
resultPath, jsonpathError := util.GetJsonPath(result, OutputType, JsonPath)
if jsonpathError != nil {
getError = jsonpathError
time.Sleep(5 * time.Second)
continue
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var Hosts []string
var kubeConfigPath string

// version should be in format d.d.d where d is a decimal number
const Version string = "v0.0.28"
const Version string = "v0.0.29"

var AppName string = InitAppName()

Expand Down
19 changes: 14 additions & 5 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,29 @@ func DownloadFile(filepath string, url string) error {
}

func GetJsonPath(source string, sourceFormat string, jsonPath string) (string, error) {
sourceAsJson, conversionToJsonError := Convert(sourceFormat, "json", source)
if conversionToJsonError != nil {
return "", conversionToJsonError
}
var jsonInterface map[string]interface{}
err := json.Unmarshal([]byte(source), &jsonInterface)
err := json.Unmarshal([]byte(sourceAsJson), &jsonInterface)
if err != nil {
return "", err
}
resultPath, err := jsonpath.Read(jsonInterface, jsonPath)
if err != nil {
return "", err
}
str, ok := resultPath.(string)
if !ok {
return "", errors.New("There is no string representation for " + jsonPath)
strJson, jsonMarshalError := json.Marshal(resultPath)
if jsonMarshalError != nil {
return "", jsonMarshalError
}

sourceAsSourceFormat, conversionFromJsonError := Convert("json", sourceFormat, string(strJson))
if conversionFromJsonError != nil {
return "", conversionFromJsonError
}
return str, nil
return sourceAsSourceFormat, nil
}

func VerifyCertForHost(resourceUrl string, cert string) error {
Expand Down

0 comments on commit 76b3dc2

Please sign in to comment.