From: Tom Clegg Date: Wed, 28 Jun 2017 19:38:36 +0000 (-0400) Subject: 2411: Remove golang<1.4 shim. X-Git-Tag: 1.1.0~168^2~3 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/ec88c9eee4d0e4827e28f015c464adef43773005 2411: Remove golang<1.4 shim. Arvados-DCO-1.1-Signed-off-by: Tom Clegg --- diff --git a/sdk/go/auth/auth.go b/sdk/go/auth/auth.go index 9c2a759f60..730989b3a3 100644 --- a/sdk/go/auth/auth.go +++ b/sdk/go/auth/auth.go @@ -45,7 +45,7 @@ func (a *Credentials) LoadTokensFromHTTPRequest(r *http.Request) { // Load base64-encoded token from "Authorization: Basic ..." // header (typically used by git via credential helper) - if _, password, ok := BasicAuth(r); ok { + if _, password, ok := r.BasicAuth(); ok { a.Tokens = append(a.Tokens, password) } diff --git a/sdk/go/auth/basic_auth_go13.go b/sdk/go/auth/basic_auth_go13.go deleted file mode 100644 index 7108ded21a..0000000000 --- a/sdk/go/auth/basic_auth_go13.go +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) The Arvados Authors. All rights reserved. -// -// SPDX-License-Identifier: Apache-2.0 - -// +build !go1.4 - -package auth - -import ( - "encoding/base64" - "net/http" - "strings" -) - -func BasicAuth(r *http.Request) (username, password string, ok bool) { - tokens := strings.SplitN(r.Header.Get("Authorization"), " ", 2) - if len(tokens) != 2 || tokens[0] != "Basic" { - return "", "", false - } - - decoded, err := base64.StdEncoding.DecodeString(tokens[1]) - if err != nil { - return "", "", false - } - - userAndPass := strings.SplitN(string(decoded), ":", 2) - if len(userAndPass) != 2 { - return "", "", false - } - - return userAndPass[0], userAndPass[1], true -} diff --git a/sdk/go/auth/basic_auth_go14.go b/sdk/go/auth/basic_auth_go14.go deleted file mode 100644 index bfb430b66b..0000000000 --- a/sdk/go/auth/basic_auth_go14.go +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (C) The Arvados Authors. All rights reserved. -// -// SPDX-License-Identifier: Apache-2.0 - -// +build go1.4 - -package auth - -import ( - "net/http" -) - -func BasicAuth(r *http.Request) (username, password string, ok bool) { - return r.BasicAuth() -} diff --git a/sdk/go/auth/basic_auth_test.go b/sdk/go/auth/basic_auth_test.go deleted file mode 100644 index 83b737ef5a..0000000000 --- a/sdk/go/auth/basic_auth_test.go +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (C) The Arvados Authors. All rights reserved. -// -// SPDX-License-Identifier: Apache-2.0 - -package auth - -import ( - "net/http" - "testing" -) - -type basicAuthTestCase struct { - hdr string - user string - pass string - ok bool -} - -func TestBasicAuth(t *testing.T) { - tests := []basicAuthTestCase{ - {"Basic Zm9vOmJhcg==", "foo", "bar", true}, - {"Bogus Zm9vOmJhcg==", "", "", false}, - {"Zm9vOmJhcg==", "", "", false}, - {"Basic", "", "", false}, - {"", "", "", false}, - } - for _, test := range tests { - if u, p, ok := BasicAuth(&http.Request{Header: map[string][]string{ - "Authorization": {test.hdr}, - }}); u != test.user || p != test.pass || ok != test.ok { - t.Error("got:", u, p, ok, "expected:", test.user, test.pass, test.ok, "from:", test.hdr) - } - } -}