Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

fix: GetString properly fails when given a mapping variable that does not exist #3

Merged
merged 36 commits into from
Aug 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
9454574
BREAKING CHANGE: private repository moved to public github.
adamcbrown Jul 18, 2018
59c38de
Updated to have GetCredentials and allows for v2 mappings
adamcbrown Jul 20, 2018
e44e961
fix: added tests and renamed files to Go Convention
Jul 20, 2018
f957b18
Added Deep Search functionality to parse.go
adamcbrown Jul 20, 2018
1f7ac07
fix: added tests for v2/mappings (untested)
Jul 20, 2018
613aba9
Merge branch 'master' of https://github.com/adamcbrown/ibm-cloud-env-…
Jul 20, 2018
076ad93
added stuff
Jul 20, 2018
26d83ca
Properly returns dictionaries in v2
adamcbrown Jul 20, 2018
4315d67
fix: mappingsv2_test.go
Jul 20, 2018
551ce0b
fix: updated Readme with user provided part
Jul 23, 2018
8609060
fix: README.md
Jul 23, 2018
b85b233
fix: Updated GetCredentials to take a json string instead of a gjson …
adamcbrown Jul 23, 2018
6af8834
Merge branch 'master' of https://github.com/adamcbrown/ibm-cloud-env-…
adamcbrown Jul 23, 2018
c1f58f0
fix: renaming functions/files
Jul 23, 2018
f753dfc
Merge branch 'master' of https://github.com/adamcbrown/ibm-cloud-env-…
Jul 23, 2018
06232d0
fix: Update README Supported Search Pattern Types
sydney-ng Jul 24, 2018
2007280
fix: removed comments on cloud_env.go
sydney-ng Jul 24, 2018
09f211f
fix: removed comments mappingsv1_test.go
sydney-ng Jul 24, 2018
4f4e465
fix: remove comments mappings_test.go
sydney-ng Jul 24, 2018
dae7f9d
chore: remove comments mappingsv2_test.go
sydney-ng Jul 24, 2018
05d71cb
fix: updated gopkg to include all libraries
adamcbrown Jul 24, 2018
f91e14e
chore: Update README.md
sydney-ng Jul 24, 2018
1ceb370
chore: fixed indentations to only use spaces
adamcbrown Jul 24, 2018
fc3c3d8
chore: .go files are correctly formatted
adamcbrown Jul 25, 2018
1cc7a04
chore: fix rephrases
sydney-ng Jul 25, 2018
13324a1
chore: Replaced the term module with package
adamcbrown Jul 25, 2018
d143ea1
Updated README.md with new user-provided pattern
adamcbrown Jul 27, 2018
bf3df10
Added copyright to credentials.go
adamcbrown Jul 27, 2018
7c251b9
chore: fixed copyright alignment
sydney-ng Jul 27, 2018
df4ad28
fix: fixed alignment of filtered credentials
Jul 27, 2018
d5a926d
fix: added travis & fixed linting errors
Jul 27, 2018
c11bd0a
fix: removed travis comments
Jul 27, 2018
80b6b75
fix: add user provided for default unknown prefix
sydney-ng Jul 27, 2018
72185c9
Merge branch 'master' of https://github.com/adamcbrown/ibm-cloud-env-…
Jul 27, 2018
304730f
Merge remote-tracking branch 'upstream/master'
adamcbrown Aug 6, 2018
d1565db
fix: GetString properly fails when given a mapping variable that does…
adamcbrown Aug 6, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions cloud_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func processJSONPath(jsonString string, jsonPath string) (string, bool) {
err := json.Unmarshal([]byte(jsonString), &json_data)
if err != nil {
return "", false
}
}
res, err := jsonpath.JsonPathLookup(json_data, jsonPath)
_, isMap := res.(map[string]interface{})
_, isArr := res.([]interface{})
Expand Down Expand Up @@ -282,12 +282,16 @@ func GetCredentialsForService(serviceTag, serviceLabel, credentials string) map[

func GetString(name string) (string, bool) {
val, ok := loadedMappings[name]
if !ok {
return "", false
}

_, isStr := val.(string)
if ok && !isStr {
if !isStr {
bytes, _ := json.Marshal(val)
return string(bytes), true
}
return val.(string), ok
return val.(string), true
}

func GetDictionary(name string) gjson.Result {
Expand Down
11 changes: 11 additions & 0 deletions mappings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,14 @@ func TestJsonPathFromEnvVar(t *testing.T) {
t.Errorf("Got: \t%s\n Wanted: \t%s\n", testString, "env-var-json-username")
}
}

func TestBadVars(t *testing.T) {
setEnvVariable()

for i := 1; i <= 4; i++ {
badStr, ok := GetString("bad_var" + string(i))
if badStr != "" || ok {
t.Errorf("Did not correctly fail bad string\n")
}
}
}