Skip to content

Commit cf7bf42

Browse files
committed
Merge pull request #23 from zencoder/remove-assumptions
Remove forced assumptions about bucket naming
2 parents ca11bb1 + 4158ed9 commit cf7bf42

File tree

10 files changed

+186
-594
lines changed

10 files changed

+186
-594
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
bin/
22
coverage/
33
vendor/
4+
.idea

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ build:
1313
go build -v -o bin/go-remote-config
1414
fmt:
1515
go fmt ./...
16+
17+
test: export AWS_ACCESS_KEY_ID := 1
18+
test: export AWS_SECRET_ACCESS_KEY := 1
1619
test:
1720
if [ ! -d coverage ]; then mkdir coverage; fi
1821
go test -v ./ -race -cover -coverprofile=$(COVERAGEDIR)/remoteconfig.coverprofile

glide.lock

Lines changed: 2 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

glide.yaml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,8 @@
11
package: github.com/zencoder/go-remote-config
22
import:
3-
- package: github.com/aws/aws-sdk-go
4-
version: v1.0.9
5-
subpackages:
6-
- aws
7-
- internal/endpoints
8-
- internal/protocol/query
9-
- internal/protocol/rest
10-
- internal/protocol/restxml
11-
- internal/protocol/xml/xmlutil
12-
- internal/signer/v4
13-
- service/s3
143
- package: github.com/stretchr/testify
154
version: c478a808a1b37e10c82f71a2172728f8742bad51
165
subpackages:
176
- assert
187
- require
198
- suite
20-
- package: github.com/vaughan0/go-ini
21-
version: a98ad7ee00ec53921f08832bc06ecf7fd600e6a1

remoteconfig.go

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package remoteconfig
33
import (
44
"encoding/json"
55
"fmt"
6+
"io"
67
"net/http"
78
"reflect"
89
"strings"
@@ -20,39 +21,30 @@ type Validater interface {
2021
// Downloads a configuration JSON file from S3.
2122
// Parses it to a particular struct type and runs a validation.
2223
// URL should be of the format s3://bucket/path/file.json
23-
func LoadConfigFromS3(configURL string, configRegion AWSRegion, configEndpoint string, configStruct interface{}) error {
24-
// Build a Signed URL to the config file in S3
25-
signedURL, err := BuildSignedS3URL(configURL, configRegion, DEFAULT_S3_EXPIRY, configEndpoint)
26-
if err != nil {
27-
return err
28-
}
29-
30-
return DownloadJSONValidate(signedURL, configStruct)
31-
}
32-
33-
// Downloads JSON from a URL, decodes it and then validates.
34-
func DownloadJSONValidate(signedURL string, configStruct interface{}) error {
35-
// Download the config file from S3
36-
resp, err := http.Get(signedURL)
24+
func LoadConfigFromURL(configURL string, configStruct interface{}) error {
25+
resp, err := http.Get(configURL)
3726
if err != nil {
3827
return err
3928
}
4029
defer resp.Body.Close()
4130

42-
// Check that we got a valid response code
4331
if resp.StatusCode != http.StatusOK {
44-
return fmt.Errorf("Download of JSON failed, URL = %s, Response Code = %d", signedURL, resp.StatusCode)
32+
return fmt.Errorf("Request to '%s' returned non-200 OK status '%d: %s'", configURL, resp.StatusCode, http.StatusText(resp.StatusCode))
4533
}
4634

35+
return ReadJSONValidate(resp.Body, configStruct)
36+
}
37+
38+
// Downloads JSON from a URL, decodes it and then validates.
39+
func ReadJSONValidate(cfgReader io.Reader, configStruct interface{}) error {
4740
// Do a streaming JSON decode
48-
dec := json.NewDecoder(resp.Body)
49-
if err = dec.Decode(configStruct); err != nil {
41+
dec := json.NewDecoder(cfgReader)
42+
if err := dec.Decode(configStruct); err != nil {
5043
return fmt.Errorf("Failed to decode JSON, with error, %s", err.Error())
5144
}
5245

5346
// Run validation on the config
54-
err = validateConfigWithReflection(configStruct)
55-
if err != nil {
47+
if err := validateConfigWithReflection(configStruct); err != nil {
5648
return err
5749
}
5850

0 commit comments

Comments
 (0)