Skip to content

Commit

Permalink
Merge pull request #2 from Piszmog/develop
Browse files Browse the repository at this point in the history
Merge develop
  • Loading branch information
Piszmog committed Sep 2, 2018
2 parents 81adc8e + f24ce61 commit b3f68e2
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 14 deletions.
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
language: go

go:
- "1.10"
- "1.11"

env:
- GO111MODULE=on

notifications:
email:
Expand All @@ -21,13 +24,9 @@ cache:
- $GOPATH/bin

before_install:
- go get -u golang.org/x/vgo
- go get golang.org/x/tools/cmd/cover
- go get github.com/mattn/goveralls

install:
- vgo mod vendor

script:
- go test -v ./... -covermode=count -coverprofile=coverage.out
- $HOME/gopath/bin/goveralls -coverprofile=coverage.out -service=travis-ci
38 changes: 34 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ Spring's Config Server provides way to externalize configurations of application
[Spring Cloud Config Client](https://github.com/spring-cloud/spring-cloud-config/tree/master/spring-cloud-config-client)
can be used to load the base configurations an application requires to function.

This library provides clients the ability to load Configurations and Files from the Config Server
This library provides clients the ability to load Configurations and Files from the Config Server.

### Compatibility
This library is compatible with versions of Spring Config Server greater than or equal to `1.4.x.RELEASE`. Prior versions
of the Config Server do not provide the endpoint necessary to retrieve files for the Config Server's default branch.

## Example Usage
Below is an example usage of the library to retrieve a file from the Config Server and to retrieve the application's configurations
Expand Down Expand Up @@ -71,7 +75,33 @@ and a cloud client for a Config Server running in a cloud environment.
To create a local client, call `client.CreateLocalClient()`. The client is configured with timeouts set and to use a pool of connections.

### Cloud
To create a cloud client, call `client.CreateCloudClient()`. The client is an OAuth2 client. The OAuth2 configurations are determined from the `VCAP_SERVICES` environment variable.
To create a cloud client, call `client.CreateCloudClient()`. The client is an OAuth2 client (client credentials).
The OAuth2 configurations are determined from the `VCAP_SERVICES` environment variable.

#### VCAP_SERVICES
When an application is deployed to Cloud Foundry, services can be bounded to the application. When a service is bounded to an application,
the application will have the necessary connection information provided in the environment variable `VCAP_SERVICES`.

Structure of the `VCAP_SERVICES` value
```json
{
"<service type :: e.g. p-config-server>": [
{
"name": "<the service name>",
"instance_name": "<service name>",
"binding_name": "<bounded name of the service>",
"credentials": {
"uri": "<URI of the service :: used to connect to the service>",
"client_secret": "<OAuth2 client secret>",
"client_id": "<OAuth2 client id>",
"access_token_uri": "<OAuth2 token URI>"
},
...
}
]
}
```


## Configurations
The Config Server allows the ability to retrieve configurations for an application. Only files that follow a strict naming
Expand Down Expand Up @@ -108,7 +138,7 @@ The loaded configurations are in the following JSON format,

To use the library to retrieve configurations, create a `client/ConfigClient` and
invoke the method `GetConfiguration(applicationName string, profiles []string)`. The return will be the struct representation
of the configuration JSON - `model.Configuration`.
of the configuration JSON - `client.Configuration`.

## Resources
Spring's Config Server allows two ways to retrieve files from a backing repository.
Expand All @@ -123,4 +153,4 @@ Spring's Config Server allows two ways to retrieve files from a backing reposito
The functions available to retrieve resource files are, `GetFile(directory string, file string, interfaceType interface{}) error` and
`GetFileFromBranch(branch string, directory string, file string, interfaceType interface{})`.

* The `interfaceTypee` is the object to deserialize the file to
* The `interfaceType` is the object to deserialize the file to
3 changes: 1 addition & 2 deletions client/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ func CreateCloudClientForService(name string) (*ConfigClient, error) {

// GetCloudCredentials retrieves the Config Server's credentials so an OAuth2 client can be created.
func GetCloudCredentials(name string) (*cfservices.ServiceCredentials, error) {
vcapServices := cfservices.LoadFromEnvironment()
serviceCreds, err := cfservices.GetServiceCredentials(name, vcapServices)
serviceCreds, err := cfservices.GetServiceCredentialsFromEnvironment(name)
if err != nil {
return nil, errors.Wrapf(err, "failed to get credentials for the Config Server service %s", name)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/Piszmog/cloudconfigclient

require (
github.com/Piszmog/cfservices v1.2.0
github.com/Piszmog/cfservices v1.3.1
github.com/golang/protobuf v1.1.0 // indirect
github.com/pkg/errors v0.8.0
golang.org/x/net v0.0.0-20180808004115-f9ce57c11b24
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/Piszmog/cfservices v1.2.0 h1:qro2rdtFs7ifYrmxEY/dwTj84p0Qq7FlNE8Ucajkh44=
github.com/Piszmog/cfservices v1.2.0/go.mod h1:uxLe5gKNnODE9Bt1aJd5WjaeTg8/Qr6Dibd1wFgfAwk=
github.com/Piszmog/cfservices v1.3.1 h1:xiX4kjYJUxJYUBDgUJ+OgdqUsLX48yFq8YMZs/gdGyE=
github.com/Piszmog/cfservices v1.3.1/go.mod h1:uxLe5gKNnODE9Bt1aJd5WjaeTg8/Qr6Dibd1wFgfAwk=
github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
golang.org/x/net v0.0.0-20180808004115-f9ce57c11b24 h1:mEsFm194MmS9vCwxFy+zwu0EU7ZkxxMD1iH++vmGdUY=
Expand Down

0 comments on commit b3f68e2

Please sign in to comment.