8555: golint
authorTom Clegg <tom@curoverse.com>
Tue, 26 Jul 2016 20:29:57 +0000 (16:29 -0400)
committerTom Clegg <tom@curoverse.com>
Wed, 27 Jul 2016 19:22:07 +0000 (15:22 -0400)
services/keepstore/handlers.go
services/keepstore/pull_worker.go

index f698982415aae5bd7d8a341428acb2d8bdb57317..a6798a9f72bb6355ba8b5f6d9cb7d58f3ffe69e9 100644 (file)
@@ -73,7 +73,7 @@ func BadRequestHandler(w http.ResponseWriter, r *http.Request) {
 func GetBlockHandler(resp http.ResponseWriter, req *http.Request) {
        if enforcePermissions {
                locator := req.URL.Path[1:] // strip leading slash
-               if err := VerifySignature(locator, GetApiToken(req)); err != nil {
+               if err := VerifySignature(locator, GetAPIToken(req)); err != nil {
                        http.Error(resp, err.Error(), err.(*KeepError).HTTPCode)
                        return
                }
@@ -184,7 +184,7 @@ func PutBlockHandler(resp http.ResponseWriter, req *http.Request) {
        // Success; add a size hint, sign the locator if possible, and
        // return it to the client.
        returnHash := fmt.Sprintf("%s+%d", hash, req.ContentLength)
-       apiToken := GetApiToken(req)
+       apiToken := GetAPIToken(req)
        if PermissionSecret != nil && apiToken != "" {
                expiry := time.Now().Add(blobSignatureTTL)
                returnHash = SignLocator(returnHash, apiToken, expiry)
@@ -196,7 +196,7 @@ func PutBlockHandler(resp http.ResponseWriter, req *http.Request) {
 // IndexHandler is a HandleFunc to address /index and /index/{prefix} requests.
 func IndexHandler(resp http.ResponseWriter, req *http.Request) {
        // Reject unauthorized requests.
-       if !IsDataManagerToken(GetApiToken(req)) {
+       if !IsDataManagerToken(GetAPIToken(req)) {
                http.Error(resp, UnauthorizedError.Error(), UnauthorizedError.HTTPCode)
                return
        }
@@ -328,7 +328,7 @@ func DeleteHandler(resp http.ResponseWriter, req *http.Request) {
        hash := mux.Vars(req)["hash"]
 
        // Confirm that this user is an admin and has a token with unlimited scope.
-       var tok = GetApiToken(req)
+       var tok = GetAPIToken(req)
        if tok == "" || !CanDelete(tok) {
                http.Error(resp, PermissionError.Error(), PermissionError.HTTPCode)
                return
@@ -419,7 +419,7 @@ type PullRequest struct {
 // PullHandler processes "PUT /pull" requests for the data manager.
 func PullHandler(resp http.ResponseWriter, req *http.Request) {
        // Reject unauthorized requests.
-       if !IsDataManagerToken(GetApiToken(req)) {
+       if !IsDataManagerToken(GetAPIToken(req)) {
                http.Error(resp, UnauthorizedError.Error(), UnauthorizedError.HTTPCode)
                return
        }
@@ -455,7 +455,7 @@ type TrashRequest struct {
 // TrashHandler processes /trash requests.
 func TrashHandler(resp http.ResponseWriter, req *http.Request) {
        // Reject unauthorized requests.
-       if !IsDataManagerToken(GetApiToken(req)) {
+       if !IsDataManagerToken(GetAPIToken(req)) {
                http.Error(resp, UnauthorizedError.Error(), UnauthorizedError.HTTPCode)
                return
        }
@@ -485,7 +485,7 @@ func TrashHandler(resp http.ResponseWriter, req *http.Request) {
 // UntrashHandler processes "PUT /untrash/{hash:[0-9a-f]{32}}" requests for the data manager.
 func UntrashHandler(resp http.ResponseWriter, req *http.Request) {
        // Reject unauthorized requests.
-       if !IsDataManagerToken(GetApiToken(req)) {
+       if !IsDataManagerToken(GetAPIToken(req)) {
                http.Error(resp, UnauthorizedError.Error(), UnauthorizedError.HTTPCode)
                return
        }
@@ -714,10 +714,10 @@ func IsValidLocator(loc string) bool {
 
 var authRe = regexp.MustCompile(`^OAuth2\s+(.*)`)
 
-// GetApiToken returns the OAuth2 token from the Authorization
+// GetAPIToken returns the OAuth2 token from the Authorization
 // header of a HTTP request, or an empty string if no matching
 // token is found.
-func GetApiToken(req *http.Request) string {
+func GetAPIToken(req *http.Request) string {
        if auth, ok := req.Header["Authorization"]; ok {
                if match := authRe.FindStringSubmatch(auth[0]); match != nil {
                        return match[1]
index 2626d4bf68e1594f394ad4539f0f32a90fe00339..d53d1060e743e07d9d2bfba6b90c67376a1006ab 100644 (file)
@@ -2,7 +2,6 @@ package main
 
 import (
        "crypto/rand"
-       "errors"
        "fmt"
        "git.curoverse.com/arvados.git/sdk/go/keepclient"
        "io"
@@ -57,7 +56,7 @@ func PullItemAndProcess(pullRequest PullRequest, token string, keepClient *keepc
                return
        }
        if reader == nil {
-               return errors.New(fmt.Sprintf("No reader found for : %s", signedLocator))
+               return fmt.Errorf("No reader found for : %s", signedLocator)
        }
        defer reader.Close()
 
@@ -67,7 +66,7 @@ func PullItemAndProcess(pullRequest PullRequest, token string, keepClient *keepc
        }
 
        if (readContent == nil) || (int64(len(readContent)) != contentLen) {
-               return errors.New(fmt.Sprintf("Content not found for: %s", signedLocator))
+               return fmt.Errorf("Content not found for: %s", signedLocator)
        }
 
        err = PutContent(readContent, pullRequest.Locator)