This repository was archived by the owner on Oct 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
BREAKING CHANGE: private repository moved to public github. #2
Merged
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
9454574
BREAKING CHANGE: private repository moved to public github.
adamcbrown 59c38de
Updated to have GetCredentials and allows for v2 mappings
adamcbrown e44e961
fix: added tests and renamed files to Go Convention
f957b18
Added Deep Search functionality to parse.go
adamcbrown 1f7ac07
fix: added tests for v2/mappings (untested)
613aba9
Merge branch 'master' of https://github.com/adamcbrown/ibm-cloud-env-…
076ad93
added stuff
26d83ca
Properly returns dictionaries in v2
adamcbrown 4315d67
fix: mappingsv2_test.go
551ce0b
fix: updated Readme with user provided part
8609060
fix: README.md
b85b233
fix: Updated GetCredentials to take a json string instead of a gjson …
adamcbrown 6af8834
Merge branch 'master' of https://github.com/adamcbrown/ibm-cloud-env-…
adamcbrown c1f58f0
fix: renaming functions/files
f753dfc
Merge branch 'master' of https://github.com/adamcbrown/ibm-cloud-env-…
06232d0
fix: Update README Supported Search Pattern Types
sydney-ng 2007280
fix: removed comments on cloud_env.go
sydney-ng 09f211f
fix: removed comments mappingsv1_test.go
sydney-ng 4f4e465
fix: remove comments mappings_test.go
sydney-ng dae7f9d
chore: remove comments mappingsv2_test.go
sydney-ng 05d71cb
fix: updated gopkg to include all libraries
adamcbrown f91e14e
chore: Update README.md
sydney-ng 1ceb370
chore: fixed indentations to only use spaces
adamcbrown fc3c3d8
chore: .go files are correctly formatted
adamcbrown 1cc7a04
chore: fix rephrases
sydney-ng 13324a1
chore: Replaced the term module with package
adamcbrown d143ea1
Updated README.md with new user-provided pattern
adamcbrown bf3df10
Added copyright to credentials.go
adamcbrown 7c251b9
chore: fixed copyright alignment
sydney-ng df4ad28
fix: fixed alignment of filtered credentials
d5a926d
fix: added travis & fixed linting errors
c11bd0a
fix: removed travis comments
80b6b75
fix: add user provided for default unknown prefix
sydney-ng 72185c9
Merge branch 'master' of https://github.com/adamcbrown/ibm-cloud-env-…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
BREAKING CHANGE: private repository moved to public github.
Co-authored-by: sydney-ng <sydney.ng@yahoo.com>
- Loading branch information
commit 9454574fdfb48c8d3767aaae68a450762666e643
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[commit] | ||
template = .gittemplate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
vendor/ | ||
.DS_Store | ||
|
||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Type(<scope>): <subject> | ||
# <body> | ||
# <footer> | ||
|
||
# Type should be one of the following: | ||
# * BREAKING CHANGES (breaking change) [major release -- 1.x.x] | ||
# * feat (new feature) [minor release -- x.1.x] | ||
# * fix (bug fix) [patch release -- 0.0.x] | ||
# * docs (changes to documentation) | ||
# * style (formatting, missing semi colons, etc; no code change) | ||
# * refactor (refactoring production code) | ||
# * test (adding missing tests, refactoring tests; no production code change) | ||
# * chore (updating grunt tasks etc; no production code change) | ||
# Scope is just the scope of the change. Something like (admin) or (teacher). | ||
# Subject should use clear words and say what you did. | ||
# The body should go into detail about changes made. | ||
# The footer should contain any Github (or other tool) issue references or actions. | ||
|
||
# For a full example of how to write a good commit message, check out | ||
# https://conventionalcommits.org/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Gopkg.toml example | ||
# | ||
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md | ||
# for detailed Gopkg.toml documentation. | ||
# | ||
# required = ["github.com/user/thing/cmd/thing"] | ||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project" | ||
# version = "1.0.0" | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project2" | ||
# branch = "dev" | ||
# source = "github.com/myfork/project2" | ||
# | ||
# [[override]] | ||
# name = "github.com/x/y" | ||
# version = "2.4.0" | ||
# | ||
# [prune] | ||
# non-go = false | ||
# go-tests = true | ||
# unused-packages = true | ||
|
||
|
||
[[constraint]] | ||
name = "github.com/tidwall/gjson" | ||
version = "1.1.2" | ||
|
||
[prune] | ||
go-tests = true | ||
unused-packages = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,78 @@ | ||
# ibm-cloud-env-golang | ||
IBM Cloud Environment for Go | ||
# IBM Cloud Environment | ||
|
||
The `ibm-cloud-env-golang` module allows to abstract environment variables from various Cloud compute providers, such as, but not limited to, CloudFoundry and Kubernetes, so the application could be environment-agnostic. | ||
|
||
The module allows to define an array of search patterns that will be executed one by one until required value is found. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rephrase: The module allows for an array of search patterns that will be executed one by one until required value is found. |
||
|
||
### Installation | ||
|
||
```bash | ||
go get github.com/ibm-developer/ibm-cloud-env-golang | ||
``` | ||
|
||
### Usage | ||
|
||
Create a JSON file containing your mappings and initialize the module | ||
|
||
```golang | ||
import "github.com/ibm-developer/ibm-cloud-env-golang" | ||
|
||
//in main function | ||
IBMCloudEnv.init("/path/to/the/mappings/file/relative/to/prject/root") | ||
``` | ||
|
||
#### Supported search patterns types | ||
ibm-cloud-config supports searching for values using three search pattern types - cloudfoundry, env, file. | ||
- Using `cloudfoundry` allows to search for values in VCAP_SERVICES and VCAP_APPLICATIONS environment variables | ||
- Using `env` allows to search for values in environment variables | ||
- Using `file` allows to search for values in text/json files | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add user-provided pattern here too |
||
#### Example search patterns | ||
- cloudfoundry:service-instance-name - searches through parsed VCAP_SERVICES environment variable and returns the `credentials` object of the matching service instance name | ||
- cloudfoundry:$.JSONPath - searches through parsed VCAP_SERVICES and VCAP_APPLICATION environment variables and returns the value that corresponds to JSONPath | ||
- env:env-var-name - returns environment variable named "env-var-name" | ||
- env:env-var-name:$.JSONPath - attempts to parse the environment variable "env-var-name" and return a value that corresponds to JSONPath | ||
- file:/server/config.text - returns content of /server/config.text file | ||
- file:/server/config.json:$.JSONPath - reads the content of /server/config.json file, tries to parse it, returns the value that corresponds to JSONPath | ||
|
||
#### mappings.json file example | ||
```javascript | ||
{ | ||
"service1-credentials": { | ||
"searchPatterns": [ | ||
"cloudfoundry:my-service1-instance-name", | ||
"env:my-service1-credentials", | ||
"file:/localdev/my-service1-credentials.json" | ||
] | ||
}, | ||
"service2-username": { | ||
"searchPatterns":[ | ||
"cloudfoundry:$.service2[@.name=='my-service2-instance-name'].credentials.username", | ||
"env:my-service2-credentials:$.username", | ||
"file:/localdev/my-service1-credentials.json:$.username" | ||
] | ||
} | ||
} | ||
``` | ||
|
||
### Using the values in application | ||
|
||
In your application retrieve the values using below commands | ||
|
||
```golang | ||
service1credentials := IBMCloudEnv.getDictionary("service1-credentials") // this will be a dictionary | ||
service2username := IBMCloudEnv.getString("service2-username") // this will be a string | ||
``` | ||
|
||
Following the above approach your application can be implemented in an runtime-environment agnostic way, abstracting differences in environment variable management introduced by different cloud compute providers. | ||
|
||
|
||
## Publishing Changes | ||
|
||
In order to publish changes, you will need to fork the repository or ask to join the `ibm-developer` org and branch off the `master` branch. | ||
|
||
Make sure to follow the [conventional commit specification](https://conventionalcommits.org/) before contributing. To help you with commit a commit template is provide. Run `config.sh` to initialize the commit template to your `.git/config` | ||
|
||
Once you are finished with your changes, run `go test` to make sure all tests pass. | ||
|
||
Do a pull request against `master`, make sure the build passes. A team member will review and merge your pull request. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env bash | ||
|
||
CMD=$(cat .git/config | grep "commit") | ||
if [ -z $CMD ]; then | ||
echo "$(cat .git/config)\n$(cat .gitconfig)" > ./.git/config | ||
else | ||
echo "commit file template already saved" | ||
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
/* | ||
* © Copyright IBM Corp. 2018 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package IBMCloudEnv | ||
import ( | ||
"testing" | ||
"os" | ||
"github.com/tidwall/gjson" | ||
) | ||
|
||
const jsonObject = | ||
`{ | ||
"service1": [ | ||
{ | ||
"name": "service1-name1", | ||
"credentials": { | ||
"username": "service1-username1" | ||
} | ||
}, | ||
{ | ||
"name": "service1-name2", | ||
"credentials": { | ||
"username": "service1-username2" | ||
} | ||
} | ||
], | ||
"user-provided": [ | ||
{ | ||
"name": "service2-name1", | ||
"credentials":{ | ||
"username": "service2-username1" | ||
} | ||
} | ||
] | ||
}` | ||
|
||
const vcap_application = `{"application_name": "test-application"}` | ||
const var_string = `test-12345` | ||
const credentials = `{"credentials": { | ||
"username": "env-var-json-username" | ||
}}` | ||
|
||
func setEnvVariable() { | ||
os.Setenv("VCAP_APPLICATION", vcap_application) | ||
os.Setenv("VCAP_SERVICES", jsonObject) | ||
os.Setenv("ENV_VAR_STRING", var_string) | ||
os.Setenv("ENV_VAR_JSON", credentials) | ||
|
||
Initialize("/invalid-file-name") | ||
Initialize("mappings.json") | ||
} | ||
|
||
|
||
func TestPlainTextFile(t *testing.T) { | ||
setEnvVariable() | ||
testString, _ := GetString("file_var1") | ||
if testString != "plain-text-string" { | ||
t.Errorf("testSTring is: " + testString) | ||
t.Errorf("can't read " + testString + " from GetString()") | ||
} | ||
result := GetDictionary("file_var1").Get("value") | ||
if result.String() != "plain-text-string" { | ||
t.Errorf("can't read " + result.String() + " text from GetDictionary()") | ||
} | ||
} | ||
|
||
func TestJsonFileAndPath(t *testing.T){ | ||
setEnvVariable() | ||
testString, _ := GetString("file_var2") | ||
if testString != gjson.Parse("{\"level2\":12345}").String() { | ||
t.Errorf("Got: \t%s\n Wanted: \t%s\n", testString, "{\"level2\":12345}") | ||
} | ||
|
||
testString = GetDictionary("file_var2").Get("level2").String() | ||
if testString != "12345" { | ||
t.Errorf("Got: \t%s\n Wanted: \t%s\n", testString, "12345") | ||
} | ||
} | ||
|
||
func TestReadVcapsWithJsonPath(t *testing.T){ | ||
setEnvVariable() | ||
testString, _ := GetString("cf_var2") | ||
|
||
if testString != "service1-username1" { | ||
t.Errorf("can't read " + testString + " from GetString()") | ||
} | ||
|
||
result := GetDictionary("cf_var2").Get("value") | ||
if result.String() != "service1-username1" { | ||
t.Errorf("can't read " + result.String() + " text from GetDictionary()") | ||
} | ||
|
||
testString2, _ := GetString("cf_var3") | ||
if testString2 != "test-application" { | ||
t.Errorf("can't read " + testString2 + " from GetString()") | ||
} | ||
result2 := GetDictionary("cf_var3").Get("value") | ||
if result2.String() != "test-application" { | ||
t.Errorf("can't read " + result2.String() + " text from GetDictionary()") | ||
} | ||
|
||
//removed this test because there wasn't a cf_var4 in mappings.json | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make sure to delete this block before merging |
||
/*testString3, _ := GetString("cf_var4") | ||
if testString3 != "service1-username1" { | ||
t.Errorf("can't read " + testString3 + " from GetString()") | ||
} | ||
result3 := GetDictionary("cf_var4").Get("value") | ||
if result3.String() != "service1-username1" { | ||
t.Errorf("can't read " + result3.String() + " text from GetDictionary()") | ||
}*/ | ||
} | ||
|
||
func TestSimpleStringFromEnvVar(t *testing.T){ | ||
setEnvVariable() | ||
testString, _ := GetString("env_var1") | ||
if testString != "test-12345" { | ||
t.Errorf("can't read " + testString + " from GetString()") | ||
} | ||
result := GetDictionary("env_var1").Get("value") | ||
if result.String() != "test-12345" { | ||
t.Errorf("can't read " + result.String() + " text from GetDictionary()") | ||
} | ||
} | ||
|
||
func TestJsonFromEnvVar(t *testing.T){ | ||
setEnvVariable() | ||
testString, _ := GetString("env_var2") | ||
if testString != credentials { | ||
t.Errorf("Got: \t%s\n Wanted: \t%s\n", testString, credentials) | ||
} | ||
|
||
testString = GetDictionary("env_var2").Get("credentials").Get("username").String() | ||
if testString != "env-var-json-username" { | ||
t.Errorf("Got: \t%s\n Wanted: \t%s\n", testString, "env-var-json-username") | ||
} | ||
} | ||
|
||
func TestJsonPathFromEnvVar(t *testing.T){ | ||
setEnvVariable() | ||
testString, _ := GetString("env_var3") | ||
if testString != "env-var-json-username" { | ||
t.Errorf("Got: \t%s\n Wanted: \t%s\n", testString, "env-var-json-username") | ||
} | ||
|
||
testString = GetDictionary("env_var3").Get("value").String() | ||
if testString != "env-var-json-username" { | ||
t.Errorf("Got: \t%s\n Wanted: \t%s\n", testString, "env-var-json-username") | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rephrase: The
ibm-cloud-env-golang
module allows for the abstraction of environment variables from various Cloud compute providers, such as, but not limited to, CloudFoundry and Kubernetes, so the application can be environment-agnostic.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're not sure how to rephrase this. This paragraph was taken from the IBM-Cloud-Env repositiory