Skip to content

Commit

Permalink
Get rid of gocheck, and add specific gas tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mcardosos committed Dec 12, 2016
1 parent 3fa71a0 commit 3b3aa5e
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 28 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ install:
- go get -u golang.org/x/net/context
- go get -u github.com/HewlettPackard/gas
- go get -u gopkg.in/godo.v2/cmd/godo
- go get -u github.com/kisielk/errcheck
- export GO15VENDOREXPERIMENT=1
- glide install

script:
- gas -skip=*/arm/*/models.go -skip=*/management/examples/*.go -skip=*vendor* -skip=*/Gododir/* ./...
- gas -exclude=G101 ./arm/... ./management/examples/...
- gas -exclude=G204 ./Gododir/...
- test -z "$(gofmt -s -l $(find ./arm/* -type d -print) | tee /dev/stderr)"
- test -z "$(gofmt -s -l -w management | tee /dev/stderr)"
- test -z "$(gofmt -s -l -w storage | tee /dev/stderr)"
Expand All @@ -31,4 +32,3 @@ script:
- go vet ./management/...
- test -z "$(golint ./Gododir/... | tee /dev/stderr)"
- go vet ./Gododir/...
- set -e; for v in ./arm/... ./datalake-store/... ./Gododir/... ./management/... ./storage/...; do (errcheck -ignoretests "$v" | grep -v 'Close()' | tee /dev/stderr); done
5 changes: 1 addition & 4 deletions storage/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -1475,10 +1475,7 @@ func (b BlobStorageClient) GetBlobSASURIWithSignedIPAndProtocol(container, name
return "", err
}

sig, err := b.client.computeHmac256(stringToSign)
if err != nil {
return "", err
}
sig := b.client.computeHmac256(stringToSign)
sasParams := url.Values{
"sv": {b.client.apiVersion},
"se": {signedExpiry},
Expand Down
16 changes: 5 additions & 11 deletions storage/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,9 @@ func (c Client) GetFileService() FileServiceClient {
return FileServiceClient{c}
}

func (c Client) createAuthorizationHeader(canonicalizedString string) (string, error) {
signature, err := c.computeHmac256(canonicalizedString)
if err != nil {
return "", err
}
return fmt.Sprintf("%s %s:%s", "SharedKey", c.getCanonicalizedAccountName(), signature), nil
func (c Client) createAuthorizationHeader(canonicalizedString string) string {
signature := c.computeHmac256(canonicalizedString)
return fmt.Sprintf("%s %s:%s", "SharedKey", c.getCanonicalizedAccountName(), signature)
}

func (c Client) getAuthorizationHeader(verb, url string, headers map[string]string) (string, error) {
Expand All @@ -249,7 +246,7 @@ func (c Client) getAuthorizationHeader(verb, url string, headers map[string]stri
}

canonicalizedString := c.buildCanonicalizedString(verb, headers, canonicalizedResource)
return c.createAuthorizationHeader(canonicalizedString)
return c.createAuthorizationHeader(canonicalizedString), nil
}

func (c Client) getStandardHeaders() map[string]string {
Expand Down Expand Up @@ -503,10 +500,7 @@ func (c Client) createSharedKeyLite(url string, headers map[string]string) (stri
}
strToSign := headers["x-ms-date"] + "\n" + can

hmac, err := c.computeHmac256(strToSign)
if err != nil {
return "", err
}
hmac := c.computeHmac256(strToSign)
return fmt.Sprintf("SharedKeyLite %s:%s", c.accountName, hmac), nil
}

Expand Down
4 changes: 1 addition & 3 deletions storage/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,5 @@ func (s *StorageClientSuite) Test_createAuthorizationHeader(c *chk.C) {

canonicalizedString := `foobarzoo`
expected := `SharedKey foo:h5U0ATVX6SpbFX1H6GNuxIMeXXCILLoIvhflPtuQZ30=`
ah, err := cli.createAuthorizationHeader(canonicalizedString)
c.Assert(err, chk.IsNil)
c.Assert(ah, chk.Equals, expected)
c.Assert(cli.createAuthorizationHeader(canonicalizedString), chk.Equals, expected)
}
4 changes: 2 additions & 2 deletions storage/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func (f FileServiceClient) listContent(path string, params url.Values, extraHead
}

if err = checkRespCode(resp.statusCode, []int{http.StatusOK}); err != nil {
_ = resp.body.Close()
resp.body.Close()
return nil, err
}

Expand Down Expand Up @@ -420,7 +420,7 @@ func (f FileServiceClient) GetFile(path string, fileRange *FileRange) (*FileStre
}

if err = checkRespCode(resp.statusCode, []int{http.StatusOK, http.StatusPartialContent}); err != nil {
defer resp.body.Close()
resp.body.Close()
return nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion storage/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func (c QueueServiceClient) DeleteMessage(queue, messageID, popReceipt string) e
if err != nil {
return err
}
deferresp.body.Close()
defer resp.body.Close()
return checkRespCode(resp.statusCode, []int{http.StatusNoContent})
}

Expand Down
8 changes: 3 additions & 5 deletions storage/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ import (
"time"
)

func (c Client) computeHmac256(message string) (string, error) {
func (c Client) computeHmac256(message string) string {
h := hmac.New(sha256.New, c.accountKey)
if _, err := h.Write([]byte(message)); err != nil {
return "", fmt.Errorf("Failed computing to hmac256 : %v", err)
}
return base64.StdEncoding.EncodeToString(h.Sum(nil)), nil
h.Write([]byte(message))
return base64.StdEncoding.EncodeToString(h.Sum(nil))
}

func currentTimeRfc1123Formatted() string {
Expand Down

0 comments on commit 3b3aa5e

Please sign in to comment.