Skip to content

Commit

Permalink
Polish CP code
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasinsaurralde authored and buger committed Apr 4, 2017
1 parent 3045b11 commit 4636c7a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
26 changes: 14 additions & 12 deletions coprocess_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Bundle struct {
Manifest apidef.BundleManifest
}

// Verify performs a signature verification on the bundle file.
func (b *Bundle) Verify() error {
log.WithFields(logrus.Fields{
"prefix": "main",
Expand Down Expand Up @@ -93,6 +94,7 @@ func (b *Bundle) Verify() error {
return nil
}

// AddToSpec attaches the custom middleware settings to an API definition.
func (b *Bundle) AddToSpec() {
b.Spec.APIDefinition.CustomMiddleware = b.Manifest.CustomMiddleware

Expand All @@ -106,14 +108,14 @@ type BundleGetter interface {
Get() ([]byte, error)
}

// HttpBundleGetter is a simple HTTP BundleGetter.
type HttpBundleGetter struct {
Url string
// HTTPBundleGetter is a simple HTTP BundleGetter.
type HTTPBundleGetter struct {
URL string
}

// Get performs an HTTP GET request.
func (g *HttpBundleGetter) Get() ([]byte, error) {
resp, err := http.Get(g.Url)
func (g *HTTPBundleGetter) Get() ([]byte, error) {
resp, err := http.Get(g.URL)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -143,7 +145,7 @@ func (s *ZipBundleSaver) Save(bundle *Bundle, bundlePath string, spec *APISpec)
destPath := filepath.Join(bundlePath, f.Name)

if f.FileHeader.Mode().IsDir() {
if err := os.Mkdir(destPath, 0755); err != nil {
if err := os.Mkdir(destPath, 0700); err != nil {
return err
}
continue
Expand Down Expand Up @@ -178,18 +180,18 @@ func fetchBundle(spec *APISpec) (bundle Bundle, err error) {
return bundle, err
}

bundleUrl := config.BundleBaseURL + spec.CustomMiddlewareBundle
bundleURL := config.BundleBaseURL + spec.CustomMiddlewareBundle

var getter BundleGetter

u, err := url.Parse(bundleUrl)
u, err := url.Parse(bundleURL)
switch u.Scheme {
case "http":
getter = &HttpBundleGetter{
Url: bundleUrl,
getter = &HTTPBundleGetter{
URL: bundleURL,
}
default:
err = errors.New("unknown URL scheme")
err = errors.New("Unknown URL scheme")
}
if err != nil {
return Bundle{}, err
Expand Down Expand Up @@ -310,7 +312,7 @@ func loadBundle(spec *APISpec) {
return
}

if err := os.Mkdir(destPath, 0755); err != nil {
if err := os.Mkdir(destPath, 0700); err != nil {
bundleError(spec, err, "Couldn't create bundle directory")
return
}
Expand Down
2 changes: 1 addition & 1 deletion coprocess_bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ func TestBundleGetter(t *testing.T) {
}

func TestHttpBundleGetter(t *testing.T) {
getter := &HttpBundleGetter{}
getter := &HTTPBundleGetter{}
getter.Get()
}

Expand Down
2 changes: 1 addition & 1 deletion coprocess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func TestCoProcessObjectPostProcess(t *testing.T) {
chain.ServeHTTP(recorder, req)

resp := testHttpResponse{}
if err := json.Unmarshal(recorder.Body.Bytes(), &resp); err != nil {
if err = json.Unmarshal(recorder.Body.Bytes(), &resp); err != nil {
t.Fatal(err)
}
if resp.Headers["Test"] != "value" {
Expand Down

0 comments on commit 4636c7a

Please sign in to comment.