From 142c96c210a8a5b856b91c79b148ff8e59eaf448 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Wed, 18 Dec 2019 15:50:36 +0100 Subject: [PATCH] Fix stylecheck --- .golangci.yml | 1 - cmd/example-app/main.go | 4 +-- connector/saml/saml.go | 8 ++--- storage/kubernetes/client.go | 58 ++++++++++++++++++------------------ 4 files changed, 35 insertions(+), 36 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 45cfc35f..5bfe3e99 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -16,7 +16,6 @@ linters: - wsl # TODO: fix me - - stylecheck - misspell - unparam - goimports diff --git a/cmd/example-app/main.go b/cmd/example-app/main.go index a21b2e86..c16ddfdf 100644 --- a/cmd/example-app/main.go +++ b/cmd/example-app/main.go @@ -143,7 +143,7 @@ func cmd() *cobra.Command { ctx := oidc.ClientContext(context.Background(), a.client) provider, err := oidc.NewProvider(ctx, issuerURL) if err != nil { - return fmt.Errorf("Failed to query provider %q: %v", issuerURL, err) + return fmt.Errorf("failed to query provider %q: %v", issuerURL, err) } var s struct { @@ -153,7 +153,7 @@ func cmd() *cobra.Command { ScopesSupported []string `json:"scopes_supported"` } if err := provider.Claims(&s); err != nil { - return fmt.Errorf("Failed to parse provider scopes_supported: %v", err) + return fmt.Errorf("failed to parse provider scopes_supported: %v", err) } if len(s.ScopesSupported) == 0 { diff --git a/connector/saml/saml.go b/connector/saml/saml.go index 09414ea3..f4e52a69 100644 --- a/connector/saml/saml.go +++ b/connector/saml/saml.go @@ -325,7 +325,7 @@ func (p *provider) HandlePOST(s connector.Scopes, samlResponse, inResponseTo str // Status is a required element. if resp.Status == nil { - return ident, fmt.Errorf("Response did not contain a Status element") + return ident, fmt.Errorf("response did not contain a Status element") } if err = p.validateStatus(resp.Status); err != nil { @@ -398,7 +398,7 @@ func (p *provider) HandlePOST(s connector.Scopes, samlResponse, inResponseTo str if len(p.allowedGroups) > 0 && (!s.Groups || p.groupsAttr == "") { // allowedGroups set but no groups or groupsAttr. Disallowing. - return ident, fmt.Errorf("User not a member of allowed groups") + return ident, fmt.Errorf("user not a member of allowed groups") } // Grab the groups. @@ -427,7 +427,7 @@ func (p *provider) HandlePOST(s connector.Scopes, samlResponse, inResponseTo str if len(groupMatches) == 0 { // No group membership matches found, disallowing - return ident, fmt.Errorf("User not a member of allowed groups") + return ident, fmt.Errorf("user not a member of allowed groups") } // Otherwise, we're good @@ -468,7 +468,7 @@ func (p *provider) validateStatus(status *status) error { func (p *provider) validateSubject(subject *subject, inResponseTo string) error { // Optional according to the spec, but again, we're going to be strict here. if len(subject.SubjectConfirmations) == 0 { - return fmt.Errorf("Subject contained no SubjectConfirmations") + return fmt.Errorf("subject contained no SubjectConfirmations") } var errs []error diff --git a/storage/kubernetes/client.go b/storage/kubernetes/client.go index f2af0e57..795dcc22 100644 --- a/storage/kubernetes/client.go +++ b/storage/kubernetes/client.go @@ -55,14 +55,14 @@ type client struct { } // idToName maps an arbitrary ID, such as an email or client ID to a Kubernetes object name. -func (c *client) idToName(s string) string { - return idToName(s, c.hash) +func (cli *client) idToName(s string) string { + return idToName(s, cli.hash) } // offlineTokenName maps two arbitrary IDs, to a single Kubernetes object name. // This is used when more than one field is used to uniquely identify the object. -func (c *client) offlineTokenName(userID string, connID string) string { - return offlineTokenName(userID, connID, c.hash) +func (cli *client) offlineTokenName(userID string, connID string) string { + return offlineTokenName(userID, connID, cli.hash) } // Kubernetes names must match the regexp '[a-z0-9]([-a-z0-9]*[a-z0-9])?'. @@ -79,7 +79,7 @@ func offlineTokenName(userID string, connID string, h func() hash.Hash) string { return strings.TrimRight(encoding.EncodeToString(hash.Sum(nil)), "=") } -func (c *client) urlFor(apiVersion, namespace, resource, name string) string { +func (cli *client) urlFor(apiVersion, namespace, resource, name string) string { basePath := "apis/" if apiVersion == "v1" { basePath = "api/" @@ -91,10 +91,10 @@ func (c *client) urlFor(apiVersion, namespace, resource, name string) string { } else { p = path.Join(basePath, apiVersion, resource, name) } - if strings.HasSuffix(c.baseURL, "/") { - return c.baseURL + p + if strings.HasSuffix(cli.baseURL, "/") { + return cli.baseURL + p } - return c.baseURL + "/" + p + return cli.baseURL + "/" + p } // Define an error interface so we can get at the underlying status code if it's @@ -156,13 +156,13 @@ func closeResp(r *http.Response) { r.Body.Close() } -func (c *client) get(resource, name string, v interface{}) error { - return c.getResource(c.apiVersion, c.namespace, resource, name, v) +func (cli *client) get(resource, name string, v interface{}) error { + return cli.getResource(cli.apiVersion, cli.namespace, resource, name, v) } -func (c *client) getResource(apiVersion, namespace, resource, name string, v interface{}) error { - url := c.urlFor(apiVersion, namespace, resource, name) - resp, err := c.client.Get(url) +func (cli *client) getResource(apiVersion, namespace, resource, name string, v interface{}) error { + url := cli.urlFor(apiVersion, namespace, resource, name) + resp, err := cli.client.Get(url) if err != nil { return err } @@ -173,22 +173,22 @@ func (c *client) getResource(apiVersion, namespace, resource, name string, v int return json.NewDecoder(resp.Body).Decode(v) } -func (c *client) list(resource string, v interface{}) error { - return c.get(resource, "", v) +func (cli *client) list(resource string, v interface{}) error { + return cli.get(resource, "", v) } -func (c *client) post(resource string, v interface{}) error { - return c.postResource(c.apiVersion, c.namespace, resource, v) +func (cli *client) post(resource string, v interface{}) error { + return cli.postResource(cli.apiVersion, cli.namespace, resource, v) } -func (c *client) postResource(apiVersion, namespace, resource string, v interface{}) error { +func (cli *client) postResource(apiVersion, namespace, resource string, v interface{}) error { body, err := json.Marshal(v) if err != nil { return fmt.Errorf("marshal object: %v", err) } - url := c.urlFor(apiVersion, namespace, resource, "") - resp, err := c.client.Post(url, "application/json", bytes.NewReader(body)) + url := cli.urlFor(apiVersion, namespace, resource, "") + resp, err := cli.client.Post(url, "application/json", bytes.NewReader(body)) if err != nil { return err } @@ -196,13 +196,13 @@ func (c *client) postResource(apiVersion, namespace, resource string, v interfac return checkHTTPErr(resp, http.StatusCreated) } -func (c *client) delete(resource, name string) error { - url := c.urlFor(c.apiVersion, c.namespace, resource, name) +func (cli *client) delete(resource, name string) error { + url := cli.urlFor(cli.apiVersion, cli.namespace, resource, name) req, err := http.NewRequest("DELETE", url, nil) if err != nil { return fmt.Errorf("create delete request: %v", err) } - resp, err := c.client.Do(req) + resp, err := cli.client.Do(req) if err != nil { return fmt.Errorf("delete request: %v", err) } @@ -210,7 +210,7 @@ func (c *client) delete(resource, name string) error { return checkHTTPErr(resp, http.StatusOK) } -func (c *client) deleteAll(resource string) error { +func (cli *client) deleteAll(resource string) error { var list struct { k8sapi.TypeMeta `json:",inline"` k8sapi.ListMeta `json:"metadata,omitempty"` @@ -219,24 +219,24 @@ func (c *client) deleteAll(resource string) error { k8sapi.ObjectMeta `json:"metadata,omitempty"` } `json:"items"` } - if err := c.list(resource, &list); err != nil { + if err := cli.list(resource, &list); err != nil { return err } for _, item := range list.Items { - if err := c.delete(resource, item.Name); err != nil { + if err := cli.delete(resource, item.Name); err != nil { return err } } return nil } -func (c *client) put(resource, name string, v interface{}) error { +func (cli *client) put(resource, name string, v interface{}) error { body, err := json.Marshal(v) if err != nil { return fmt.Errorf("marshal object: %v", err) } - url := c.urlFor(c.apiVersion, c.namespace, resource, name) + url := cli.urlFor(cli.apiVersion, cli.namespace, resource, name) req, err := http.NewRequest("PUT", url, bytes.NewReader(body)) if err != nil { return fmt.Errorf("create patch request: %v", err) @@ -244,7 +244,7 @@ func (c *client) put(resource, name string, v interface{}) error { req.Header.Set("Content-Length", strconv.Itoa(len(body))) - resp, err := c.client.Do(req) + resp, err := cli.client.Do(req) if err != nil { return fmt.Errorf("patch request: %v", err) }