From de29b1460fd90e5e72ea6d5f9d63044a649c77f5 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Thu, 14 Nov 2019 12:23:39 -0500 Subject: [PATCH] Run gofmt on all files --- integration/cli_test.go | 54 +++++++++++++++--------------- main.go | 43 ++++++++++++------------ sgauth/appengine.go | 2 +- sgauth/compute.go | 6 ++-- sgauth/credentials/file.go | 28 ++++++++-------- sgauth/credentials/jwt.go | 15 +++++---- sgauth/credentials/jwt_token.go | 8 ++--- sgauth/default.go | 18 +++++----- sgauth/example/library/example.go | 14 ++++---- sgauth/example/library/main.go | 9 ++--- sgauth/example/library/utils.go | 21 ++++++------ sgauth/internal/config.go | 12 +++---- sgauth/internal/token.go | 3 +- sgauth/internal/token_retriever.go | 3 +- util/curl.go | 2 +- util/sso.go | 2 +- util/tasks.go | 16 ++++----- 17 files changed, 125 insertions(+), 131 deletions(-) diff --git a/integration/cli_test.go b/integration/cli_test.go index e3dcdc0..1d5dc00 100644 --- a/integration/cli_test.go +++ b/integration/cli_test.go @@ -15,19 +15,19 @@ package main import ( + "encoding/base64" + "encoding/json" "flag" "fmt" "io/ioutil" + "net/http" "os" "os/exec" "path/filepath" - "runtime" - "testing" "reflect" - "net/http" - "encoding/base64" - "encoding/json" + "runtime" "strings" + "testing" ) // Use this flag to update golden files with test outputs from current run. @@ -109,7 +109,7 @@ func runTestScenariosWithInput(t *testing.T, tests []testCase, input *os.File) { } // Used for processing test output before comparing to golden files. -type processOutput func (string) string +type processOutput func(string) string // Runs test cases where stdin input is needed and output needs to be processed before comparing to golden files. func runTestScenariosWithInputAndProcessedOutput(t *testing.T, tests []testCase, input *os.File, processOutput processOutput) { @@ -146,7 +146,7 @@ func runTestScenariosWithInputAndProcessedOutput(t *testing.T, tests []testCase, // Test base-case scenarios func TestCLI(t *testing.T) { - tests := []testCase { + tests := []testCase{ { "no command", []string{}, @@ -159,7 +159,7 @@ func TestCLI(t *testing.T) { "no-scope.golden", false, }, - { + { "fetch; jwt; no audience", []string{"fetch", "--type", "jwt"}, "no-audience.golden", @@ -185,7 +185,7 @@ func TestCLI(t *testing.T) { }, { "curl; no scope", - []string{"curl","--url","https://test.com"}, + []string{"curl", "--url", "https://test.com"}, "no-scope.golden", false, }, @@ -197,13 +197,13 @@ func TestCLI(t *testing.T) { }, { "info; invalid token", - []string{"info","--token","invalid-token"}, + []string{"info", "--token", "invalid-token"}, "info-invalid-token.golden", false, }, { "test; invalid token", - []string{"test","--token","invalid-token"}, + []string{"test", "--token", "invalid-token"}, "test-invalid-token.golden", false, }, @@ -219,7 +219,7 @@ func TestCLI(t *testing.T) { // Test OAuth 3LO flow with fake client secrets. Fake verification code is injected to stdin to advance the flow. func Test3LOFlow(t *testing.T) { - tests := []testCase { + tests := []testCase{ { "fetch; 3lo", []string{"fetch", "--scope", "pubsub", "--credentials", "integration/fixtures/fake-client-secrets.json", "--cache", ""}, @@ -257,12 +257,12 @@ func Test3LOFlow(t *testing.T) { false, }, } - runTestScenariosWithInput(t, tests, newFixture(t,"fake-verification-code.fixture").asFile()) + runTestScenariosWithInput(t, tests, newFixture(t, "fake-verification-code.fixture").asFile()) } // Test OAuth 2LO Flow with fake service account. func Test2LOFlow(t *testing.T) { - tests := []testCase { + tests := []testCase{ { "fetch; 2lo", []string{"fetch", "--scope", "pubsub", "--credentials", "integration/fixtures/fake-service-account.json", "--cache", ""}, @@ -293,7 +293,7 @@ func Test2LOFlow(t *testing.T) { // Test JWT Flow. func TestJWTFlow(t *testing.T) { - tests := []testCase { + tests := []testCase{ { "fetch; jwt", []string{"fetch", "--type", "jwt", "--audience", "https://pubsub.googleapis.com/", "--credentials", "integration/fixtures/fake-service-account.json"}, @@ -312,8 +312,8 @@ func TestJWTFlow(t *testing.T) { //JWT is signed with a timestamp that differs in every execution, so we will strip out "exp" and "iat" fields encodedPayload := strings.Split(jwt, ".")[1] decodedPayload, _ := base64.RawStdEncoding.DecodeString(encodedPayload) - var jsonData map[string]interface{} - json.Unmarshal(decodedPayload, &jsonData) + var jsonData map[string]interface{} + json.Unmarshal(decodedPayload, &jsonData) // nolint:errcheck delete(jsonData, "exp") delete(jsonData, "iat") jsonString, _ := json.Marshal(jsonData) @@ -324,7 +324,7 @@ func TestJWTFlow(t *testing.T) { // Test SSO Flow. Uses "echo" as a fake ssocli to return the calling parameters instead of an actual token. func TestSSOFlow(t *testing.T) { - tests := []testCase { + tests := []testCase{ { "fetch; sso", []string{"fetch", "--type", "sso", "--email", "example@example.com", "--scope", "pubsub", "--ssocli", "echo"}, @@ -351,7 +351,7 @@ func readFile(path string) string { func MockTokenApi(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - response := readFile ("integration/fixtures/mock-token-response.json") + response := readFile("integration/fixtures/mock-token-response.json") fmt.Fprint(w, response) } @@ -385,14 +385,14 @@ func TestMain(m *testing.M) { } // Start mock server - go func() { - mux := http.NewServeMux() - server := http.Server{Addr: ":8080", Handler: mux} - mux.HandleFunc("/token", MockTokenApi) - mux.HandleFunc("/curl", MockCurlApi) - if err := server.ListenAndServe(); err != nil { - fmt.Printf("could not listen on port 8080 %v", err) - } + go func() { + mux := http.NewServeMux() + server := http.Server{Addr: ":8080", Handler: mux} + mux.HandleFunc("/token", MockTokenApi) + mux.HandleFunc("/curl", MockCurlApi) + if err := server.ListenAndServe(); err != nil { + fmt.Printf("could not listen on port 8080 %v", err) + } }() status := m.Run() diff --git a/main.go b/main.go index 35b2e10..7e68c4a 100644 --- a/main.go +++ b/main.go @@ -18,8 +18,9 @@ import ( "fmt" "io/ioutil" "os" - "strings" "regexp" + "strings" + "github.com/google/oauth2l/sgauth" "github.com/google/oauth2l/util" "github.com/jessevdk/go-flags" @@ -43,12 +44,12 @@ var ( // Top level command-line flags (first argument after program name). type commandOptions struct { - Fetch fetchOptions `command:"fetch" description:"Fetch an access token."` + Fetch fetchOptions `command:"fetch" description:"Fetch an access token."` Header headerOptions `command:"header" description:"Fetch an access token and return it in header format."` - Curl curlOptions `command:"curl" description:"Fetch an access token and use it to make a curl request."` - Info infoOptions `command:"info" description:"Display info about an OAuth access token."` - Test infoOptions `command:"test" description:"Tests an OAuth access token. Returns 0 for valid token."` - Reset resetOptions `command:"reset" description:"Resets the cache."` + Curl curlOptions `command:"curl" description:"Fetch an access token and use it to make a curl request."` + Info infoOptions `command:"info" description:"Display info about an OAuth access token."` + Test infoOptions `command:"test" description:"Tests an OAuth access token. Returns 0 for valid token."` + Reset resetOptions `command:"reset" description:"Resets the cache."` } // Common options for "fetch", "header", and "curl" commands. @@ -62,9 +63,9 @@ type commonFetchOptions struct { // GUAC parameters Credentials string `long:"credentials" description:"Credentials file containing OAuth Client Id or Service Account Key. Optional if environment variable GOOGLE_APPLICATION_CREDENTIALS is set."` - Scope string `long:"scope" description:"List of OAuth scopes requested. Required for oauth and sso authentication type. Comma delimited."` - Audience string `long:"audience" description:"Audience used for JWT self-signed token. Required for jwt authentication type."` - Email string `long:"email" description:"Email associated with SSO. Required for sso authentication type."` + Scope string `long:"scope" description:"List of OAuth scopes requested. Required for oauth and sso authentication type. Comma delimited."` + Audience string `long:"audience" description:"Audience used for JWT self-signed token. Required for jwt authentication type."` + Email string `long:"email" description:"Email associated with SSO. Required for sso authentication type."` // Client parameters SsoCli string `long:"ssocli" description:"Path to SSO CLI. Optional."` @@ -73,9 +74,9 @@ type commonFetchOptions struct { Cache *string `long:"cache" description:"Path to the credential cache file. Disables caching if set to empty. Defaults to ~/.oauth2l."` // Deprecated flags kept for backwards compatibility. Hidden from help page. - Json string `long:"json" description:"Deprecated. Same as --credentials." hidden:"true"` - Jwt bool `long:"jwt" description:"Deprecated. Same as --type jwt." hidden:"true"` - Sso bool `long:"sso" description:"Deprecated. Same as --type sso." hidden:"true"` + Json string `long:"json" description:"Deprecated. Same as --credentials." hidden:"true"` + Jwt bool `long:"jwt" description:"Deprecated. Same as --type jwt." hidden:"true"` + Sso bool `long:"sso" description:"Deprecated. Same as --type sso." hidden:"true"` OldFormat string `long:"credentials_format" choice:"bare" choice:"header" choice:"json" choice:"json_compact" choice:"pretty" description:"Deprecated. Same as --output_format" hidden:"true"` } @@ -94,7 +95,7 @@ type headerOptions struct { type curlOptions struct { commonFetchOptions CurlCli string `long:"curlcli" description:"Path to Curl CLI. Optional."` - Url string `long:"url" description:"URL endpoint for the curl request." required:"true"` + Url string `long:"url" description:"URL endpoint for the curl request." required:"true"` } // Options for "info" and "test" commands. @@ -150,7 +151,7 @@ func setCacheLocation(cache *string) { } // Extracts the common fetch options based on chosen command. -func getCommonFetchOptions (cmdOpts commandOptions, cmd string) commonFetchOptions { +func getCommonFetchOptions(cmdOpts commandOptions, cmd string) commonFetchOptions { var commonOpts commonFetchOptions switch cmd { case "fetch": @@ -164,7 +165,7 @@ func getCommonFetchOptions (cmdOpts commandOptions, cmd string) commonFetchOptio } // Get the authentication type, with backward compatibility. -func getAuthTypeWithFallback (commonOpts commonFetchOptions) string { +func getAuthTypeWithFallback(commonOpts commonFetchOptions) string { authType := commonOpts.AuthType if commonOpts.Jwt { authType = "jwt" @@ -175,7 +176,7 @@ func getAuthTypeWithFallback (commonOpts commonFetchOptions) string { } // Get the credentials file, with backward compatibility. -func getCredentialsWithFallback (commonOpts commonFetchOptions) string { +func getCredentialsWithFallback(commonOpts commonFetchOptions) string { credentials := commonOpts.Credentials if commonOpts.Json != "" { credentials = commonOpts.Json @@ -184,7 +185,7 @@ func getCredentialsWithFallback (commonOpts commonFetchOptions) string { } // Get the fetch output format, with backward compatibility. -func getOutputFormatWithFallback (fetchOpts fetchOptions) string { +func getOutputFormatWithFallback(fetchOpts fetchOptions) string { format := fetchOpts.Format if fetchOpts.OldFormat != "" { format = fetchOpts.OldFormat @@ -193,7 +194,7 @@ func getOutputFormatWithFallback (fetchOpts fetchOptions) string { } // Converts scope argument to string slice, with backward compatibility. -func getScopesWithFallback (scope string, remainingArgs ...string) []string { +func getScopesWithFallback(scope string, remainingArgs ...string) []string { var scopes []string // Fallback to reading scope from remaining args if scope == "" { @@ -217,7 +218,7 @@ func getTaskArgs(cmd, curlcli, url, format string, remainingArgs ...string) []st } // Extracts the info options based on chosen command. -func getInfoOptions (cmdOpts commandOptions, cmd string) infoOptions { +func getInfoOptions(cmdOpts commandOptions, cmd string) infoOptions { var infoOpts infoOptions switch cmd { case "info": @@ -245,7 +246,7 @@ func main() { fetchTasks := map[string]func(*sgauth.Settings, ...string){ "fetch": util.Fetch, "header": util.Header, - "curl": util.Curl, + "curl": util.Curl, } // Tasks that verify the existing token. @@ -267,7 +268,7 @@ func main() { curlcli := opts.Curl.CurlCli url := opts.Curl.Url - if authType == "jwt"{ + if authType == "jwt" { // JWT flow json, err := readJSON(credentials) if err != nil { diff --git a/sgauth/appengine.go b/sgauth/appengine.go index 52a36dd..07f208b 100644 --- a/sgauth/appengine.go +++ b/sgauth/appengine.go @@ -20,8 +20,8 @@ import ( "sync" "time" - "golang.org/x/net/context" "github.com/google/oauth2l/sgauth/internal" + "golang.org/x/net/context" ) // appengineFlex is set at init time by appengineflex_hook.go. If true, we are on App Engine Flex. diff --git a/sgauth/compute.go b/sgauth/compute.go index 6f2a768..fbba0a0 100644 --- a/sgauth/compute.go +++ b/sgauth/compute.go @@ -16,12 +16,12 @@ package sgauth import ( "cloud.google.com/go/compute/metadata" - "errors" "encoding/json" - "strings" + "errors" "fmt" - "time" "github.com/google/oauth2l/sgauth/internal" + "strings" + "time" ) // ComputeTokenSource returns a token source that fetches access tokens diff --git a/sgauth/credentials/file.go b/sgauth/credentials/file.go index fa72bbf..cbec8ca 100644 --- a/sgauth/credentials/file.go +++ b/sgauth/credentials/file.go @@ -17,8 +17,8 @@ package credentials import ( "errors" "fmt" - "golang.org/x/net/context" "github.com/google/oauth2l/sgauth/internal" + "golang.org/x/net/context" ) // DefaultTokenURL is Google's OAuth 2.0 token URL to use with the service @@ -33,16 +33,16 @@ const DefaultAuthURL = "https://accounts.google.com/o/oauth2/auth" const ( ServiceAccountKey = "service_account" UserCredentialsKey = "authorized_user" - OAuthClientKey = "oauth_client" + OAuthClientKey = "oauth_client" ) // Contains data for OAuthClient key. type OAuthClient struct { - ProjectID string `json:"project_id"` - ClientSecret string `json:"client_secret"` - ClientID string `json:"client_id"` - TokenURL string `json:"token_uri"` - AuthURL string `json:"auth_uri"` + ProjectID string `json:"project_id"` + ClientSecret string `json:"client_secret"` + ClientID string `json:"client_id"` + TokenURL string `json:"token_uri"` + AuthURL string `json:"auth_uri"` RedirectURL []string `json:"redirect_uris"` } @@ -85,7 +85,7 @@ func (f *File) CredentialsType() string { // Construct the corresponding token source based on the type of the file. func (f *File) TokenSource(ctx context.Context, scopes []string, - handler func(string)(string, error), state string) (internal.TokenSource, error) { + handler func(string) (string, error), state string) (internal.TokenSource, error) { switch f.CredentialsType() { case ServiceAccountKey: cfg := JWTConfigFromFile(f, scopes) @@ -104,8 +104,8 @@ func (f *File) TokenSource(ctx context.Context, scopes []string, ClientID: f.ClientID, ClientSecret: f.ClientSecret, Scopes: scopes, - Endpoint: internal.Endpoint{ - AuthURL: authURL, + Endpoint: internal.Endpoint{ + AuthURL: authURL, TokenURL: tokenURL, }, } @@ -113,7 +113,7 @@ func (f *File) TokenSource(ctx context.Context, scopes []string, return cfg.TokenSource(ctx, tok), nil case OAuthClientKey: var oauth OAuthClient - if (f.Web.ProjectID != "") { + if f.Web.ProjectID != "" { oauth = f.Web } else { oauth = f.Installed @@ -132,12 +132,12 @@ func (f *File) TokenSource(ctx context.Context, scopes []string, ClientID: oauth.ClientID, ClientSecret: oauth.ClientSecret, Scopes: scopes, - Endpoint: internal.Endpoint{ - AuthURL: oauth.AuthURL, + Endpoint: internal.Endpoint{ + AuthURL: oauth.AuthURL, TokenURL: oauth.TokenURL, }, FlowHandler: handler, - State: state, + State: state, RedirectURL: oauth.RedirectURL[0], } return cfg.TokenSource(ctx, nil), nil diff --git a/sgauth/credentials/jwt.go b/sgauth/credentials/jwt.go index 794a1ee..488e402 100644 --- a/sgauth/credentials/jwt.go +++ b/sgauth/credentials/jwt.go @@ -15,7 +15,12 @@ package credentials import ( + "context" + "crypto/rsa" + "crypto/x509" "encoding/json" + "encoding/pem" + "errors" "fmt" "io" "io/ioutil" @@ -23,13 +28,9 @@ import ( "net/url" "strings" "time" - "golang.org/x/oauth2/jws" - "crypto/rsa" - "encoding/pem" - "crypto/x509" - "errors" - "context" + "github.com/google/oauth2l/sgauth/internal" + "golang.org/x/oauth2/jws" ) var ( @@ -159,7 +160,7 @@ func (js jwtSource) Token() (*internal.Token, error) { TokenType: tokenRes.TokenType, } raw := make(map[string]interface{}) - json.Unmarshal(body, &raw) // no error checks for optional fields + json.Unmarshal(body, &raw) // nolint:errcheck token = token.WithExtra(raw) if secs := tokenRes.ExpiresIn; secs > 0 { diff --git a/sgauth/credentials/jwt_token.go b/sgauth/credentials/jwt_token.go index 32b4c7e..ac56090 100644 --- a/sgauth/credentials/jwt_token.go +++ b/sgauth/credentials/jwt_token.go @@ -19,12 +19,12 @@ import ( "fmt" "time" - "golang.org/x/oauth2/jws" + "crypto/x509" "encoding/json" - "github.com/google/oauth2l/sgauth/internal" "encoding/pem" - "crypto/x509" "errors" + "github.com/google/oauth2l/sgauth/internal" + "golang.org/x/oauth2/jws" ) // JWTConfigFromJSON uses a Google Developers service account JSON key file to read @@ -102,7 +102,6 @@ func (ts *jwtAccessTokenSource) Token() (*internal.Token, error) { return &internal.Token{AccessToken: msg, TokenType: "Bearer", Expiry: exp}, nil } - // ParseKey converts the binary contents of a private key file // to an *rsa.PrivateKey. It detects whether the private key is in a // PEM container or not. If so, it extracts the the private key @@ -126,4 +125,3 @@ func parseKey(key []byte) (*rsa.PrivateKey, error) { } return parsed, nil } - diff --git a/sgauth/default.go b/sgauth/default.go index 60fa6ca..0116012 100644 --- a/sgauth/default.go +++ b/sgauth/default.go @@ -15,25 +15,25 @@ package sgauth import ( + "cloud.google.com/go/compute/metadata" "context" - "os" + "encoding/json" "fmt" + "github.com/google/oauth2l/sgauth/credentials" + "github.com/google/oauth2l/sgauth/internal" "io/ioutil" - "encoding/json" - "strings" - "cloud.google.com/go/compute/metadata" - "runtime" - "path/filepath" + "os" "os/user" - "github.com/google/oauth2l/sgauth/internal" - "github.com/google/oauth2l/sgauth/credentials" + "path/filepath" + "runtime" + "strings" ) // DefaultTokenSource returns the token source for // "Application Default Credentials". // It is a shortcut for FindDefaultCredentials(ctx, scope).TokenSource. func DefaultTokenSource(ctx context.Context, scope string) (internal.TokenSource, error) { - creds, err := applicationDefaultCredentials(ctx, &Settings{Scope: scope,}) + creds, err := applicationDefaultCredentials(ctx, &Settings{Scope: scope}) if err != nil { return nil, err } diff --git a/sgauth/example/library/example.go b/sgauth/example/library/example.go index a064f81..264a72d 100644 --- a/sgauth/example/library/example.go +++ b/sgauth/example/library/example.go @@ -15,15 +15,15 @@ package main import ( - "github.com/wora/protorpc/client" "fmt" - "google.golang.org/genproto/googleapis/example/library/v1" - "github.com/google/oauth2l/sgauth" "github.com/golang/protobuf/proto" + "github.com/google/oauth2l/sgauth" + "github.com/wora/protorpc/client" "golang.org/x/net/context" + "google.golang.org/genproto/googleapis/example/library/v1" ) -func createSettings(args map[string]string) (*sgauth.Settings) { +func createSettings(args map[string]string) *sgauth.Settings { if args[kApiKey] != "" { return &sgauth.Settings{ APIKey: args[kApiKey], @@ -48,9 +48,9 @@ func newHTTPClient(ctx context.Context, args map[string]string) ( return nil, err } return &client.Client{ - HTTP: http, - BaseURL: baseUrl, - UserAgent: "protorpc/0.1", + HTTP: http, + BaseURL: baseUrl, + UserAgent: "protorpc/0.1", }, nil } diff --git a/sgauth/example/library/main.go b/sgauth/example/library/main.go index b0ef67b..a4e0f9a 100644 --- a/sgauth/example/library/main.go +++ b/sgauth/example/library/main.go @@ -14,15 +14,12 @@ // limitations under the License. package main -import "fmt" -import "context" - import ( + "context" + "fmt" "os" ) -var defaultScopes = "https://www.googleapis.com/auth/xapi.zoo" - func main() { args, err := parseArguments() if err != nil { @@ -52,4 +49,4 @@ func main() { } else { printUsage() } -} \ No newline at end of file +} diff --git a/sgauth/example/library/utils.go b/sgauth/example/library/utils.go index 81e5f3e..e9e2d61 100644 --- a/sgauth/example/library/utils.go +++ b/sgauth/example/library/utils.go @@ -15,17 +15,17 @@ package main import ( - "os" - "fmt" "errors" + "fmt" + "os" ) var ( - kScope = "scope" - kAud = "aud" - kHost = "host" + kScope = "scope" + kAud = "aud" + kHost = "host" kApiName = "api_name" - kApiKey = "api_key" + kApiKey = "api_key" ) func contains(arr []string, str string) bool { @@ -40,18 +40,17 @@ func contains(arr []string, str string) bool { func getFlagValue(flag string) string { for i := 0; i < len(os.Args); i++ { if os.Args[i] == flag { - if len(os.Args) < i + 2 { + if len(os.Args) < i+2 { printUsage() return "" } - return os.Args[i + 1] + return os.Args[i+1] } } printUsage() return "" } - func printUsage() { fmt.Println("Usage: cmd [grpc|protorpc] --[aud|scope] [--host] [--api_name]") } @@ -84,12 +83,12 @@ func parseArguments() (map[string]string, error) { if contains(os.Args, "--api_name") { args[kApiName] = getFlagValue("--api_name") - } else if (os.Args[1] == "protorpc") { + } else if os.Args[1] == "protorpc" { return nil, errors.New("Invalid argument: --api_name is required for ProtoRPC mode") } if args[kApiKey] == "" && args[kScope] == "" && args[kAud] == "" { - if (args[kApiName] != "") { + if args[kApiName] != "" { args[kAud] = fmt.Sprintf("https://%s/%s", args[kHost], args[kApiName]) } else { return nil, errors.New("Invalid argument: scope and aud cannot be both empty.") diff --git a/sgauth/internal/config.go b/sgauth/internal/config.go index 1843f58..b3600a8 100644 --- a/sgauth/internal/config.go +++ b/sgauth/internal/config.go @@ -15,11 +15,11 @@ package internal import ( - "net/url" - "golang.org/x/net/context" - "sync" "bytes" + "golang.org/x/net/context" + "net/url" "strings" + "sync" ) type Config struct { @@ -43,7 +43,7 @@ type Config struct { Scopes []string FlowHandler func(string) (string, error) - State string + State string } // A TokenSource is anything that can return a token. @@ -102,8 +102,8 @@ var ( k3LO = "3LO" ) -func (c *Config) getOAuthType() (string) { - if (c.RedirectURL != "") { +func (c *Config) getOAuthType() string { + if c.RedirectURL != "" { return k3LO } else { return k2LO diff --git a/sgauth/internal/token.go b/sgauth/internal/token.go index 01fde8e..ebc6f4d 100644 --- a/sgauth/internal/token.go +++ b/sgauth/internal/token.go @@ -21,8 +21,8 @@ import ( "strings" "time" - "golang.org/x/net/context" "errors" + "golang.org/x/net/context" ) // Token represents the credentials used to authorize @@ -58,7 +58,6 @@ type Token struct { Raw interface{} } - // expiryDelta determines how earlier a token should be considered // expired than its actual expiration time. It is used to avoid late // expirations due to client-server time mismatches. diff --git a/sgauth/internal/token_retriever.go b/sgauth/internal/token_retriever.go index 21c312e..0e3f894 100644 --- a/sgauth/internal/token_retriever.go +++ b/sgauth/internal/token_retriever.go @@ -31,7 +31,6 @@ import ( "golang.org/x/net/context/ctxhttp" ) - // tokenJSON is the struct representing the HTTP response from OAuth2 // providers returning a token in JSON form. type tokenJSON struct { @@ -219,7 +218,7 @@ func retrieveToken(ctx context.Context, clientID, clientSecret, tokenURL string, Expiry: tj.expiry(), Raw: make(map[string]interface{}), } - json.Unmarshal(body, &token.Raw) // no error checks for optional fields + json.Unmarshal(body, &token.Raw) // nolint:errcheck } // Don't overwrite `RefreshToken` with an empty value // if this was a token refreshing request. diff --git a/util/curl.go b/util/curl.go index c87aca0..6e35530 100644 --- a/util/curl.go +++ b/util/curl.go @@ -15,9 +15,9 @@ package util import ( - "os/exec" "bytes" "fmt" + "os/exec" ) const ( diff --git a/util/sso.go b/util/sso.go index fab0d60..bd22b44 100644 --- a/util/sso.go +++ b/util/sso.go @@ -15,9 +15,9 @@ package util import ( - "os/exec" "bytes" "fmt" + "os/exec" "strings" ) diff --git a/util/tasks.go b/util/tasks.go index 93b3bb5..17d3b33 100644 --- a/util/tasks.go +++ b/util/tasks.go @@ -15,14 +15,14 @@ package util import ( - "fmt" - "net/http" - "io/ioutil" - "errors" - "github.com/google/oauth2l/sgauth" "context" "encoding/json" + "errors" + "fmt" + "github.com/google/oauth2l/sgauth" + "io/ioutil" "log" + "net/http" ) const ( @@ -48,7 +48,7 @@ func Fetch(settings *sgauth.Settings, args ...string) { // Fetches and prints the token in header format with the given settings // using Google Authenticator. -func Header(settings *sgauth.Settings, args ... string) { +func Header(settings *sgauth.Settings, args ...string) { Fetch(settings, formatHeader) } @@ -111,7 +111,7 @@ func getTokenInfo(token string) (string, error) { return string(data), err } -func fetchToken(settings *sgauth.Settings) (*sgauth.Token) { +func fetchToken(settings *sgauth.Settings) *sgauth.Token { token, _ := LookupCache(settings) if token != nil { return token @@ -129,7 +129,7 @@ func fetchToken(settings *sgauth.Settings) (*sgauth.Token) { return token } -func getCredentialType(settings *sgauth.Settings) (string) { +func getCredentialType(settings *sgauth.Settings) string { cred, err := sgauth.FindJSONCredentials(context.Background(), settings) if err != nil { return ""