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

Commit 004da3f

Browse files
adamcbrownJennifer Oliver
authored and
Jennifer Oliver
committed
fix: GetString properly fails when given a mapping variable that does not exist (#3)
* BREAKING CHANGE: private repository moved to public github. Co-authored-by: sydney-ng <[email protected]> * Updated to have GetCredentials and allows for v2 mappings * fix: added tests and renamed files to Go Convention * Added Deep Search functionality to parse.go * fix: added tests for v2/mappings (untested) * added stuff * Properly returns dictionaries in v2 * fix: mappingsv2_test.go * fix: updated Readme with user provided part * fix: README.md * fix: Updated GetCredentials to take a json string instead of a gjson object. Added test for GetCredentials function * fix: renaming functions/files * fix: Update README Supported Search Pattern Types added user-provided description in supported search patterns types * fix: removed comments on cloud_env.go * fix: removed comments mappingsv1_test.go * fix: remove comments mappings_test.go * chore: remove comments mappingsv2_test.go * fix: updated gopkg to include all libraries * chore: Update README.md Fixed wording from Pull Request #3 * chore: fixed indentations to only use spaces * chore: .go files are correctly formatted * chore: fix rephrases * chore: Replaced the term module with package * Updated README.md with new user-provided pattern * Added copyright to credentials.go * chore: fixed copyright alignment * fix: fixed alignment of filtered credentials * fix: added travis & fixed linting errors * fix: removed travis comments * fix: add user provided for default unknown prefix * fix: GetString properly fails when given a mapping variable that does not exist
1 parent f4bcbfc commit 004da3f

File tree

3 files changed

+42
-12
lines changed

3 files changed

+42
-12
lines changed

Diff for: Gopkg.lock

+24-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: cloud_env.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func processJSONPath(jsonString string, jsonPath string) (string, bool) {
248248
err := json.Unmarshal([]byte(jsonString), &json_data)
249249
if err != nil {
250250
return "", false
251-
}
251+
}
252252
res, err := jsonpath.JsonPathLookup(json_data, jsonPath)
253253
_, isMap := res.(map[string]interface{})
254254
_, isArr := res.([]interface{})
@@ -282,12 +282,16 @@ func GetCredentialsForService(serviceTag, serviceLabel, credentials string) map[
282282

283283
func GetString(name string) (string, bool) {
284284
val, ok := loadedMappings[name]
285+
if !ok {
286+
return "", false
287+
}
288+
285289
_, isStr := val.(string)
286-
if ok && !isStr {
290+
if !isStr {
287291
bytes, _ := json.Marshal(val)
288292
return string(bytes), true
289293
}
290-
return val.(string), ok
294+
return val.(string), true
291295
}
292296

293297
func GetDictionary(name string) gjson.Result {

Diff for: mappings_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,14 @@ func TestJsonPathFromEnvVar(t *testing.T) {
149149
t.Errorf("Got: \t%s\n Wanted: \t%s\n", testString, "env-var-json-username")
150150
}
151151
}
152+
153+
func TestBadVars(t *testing.T) {
154+
setEnvVariable()
155+
156+
for i := 1; i <= 4; i++ {
157+
badStr, ok := GetString("bad_var" + string(i))
158+
if badStr != "" || ok {
159+
t.Errorf("Did not correctly fail bad string\n")
160+
}
161+
}
162+
}

0 commit comments

Comments
 (0)