Fix stylecheck

This commit is contained in:
Mark Sagi-Kazar 2019-12-18 15:50:36 +01:00
parent 8c3dc0ca66
commit 142c96c210
No known key found for this signature in database
GPG key ID: 34CC109EB5ED1C2A
4 changed files with 35 additions and 36 deletions

View file

@ -16,7 +16,6 @@ linters:
- wsl - wsl
# TODO: fix me # TODO: fix me
- stylecheck
- misspell - misspell
- unparam - unparam
- goimports - goimports

View file

@ -143,7 +143,7 @@ func cmd() *cobra.Command {
ctx := oidc.ClientContext(context.Background(), a.client) ctx := oidc.ClientContext(context.Background(), a.client)
provider, err := oidc.NewProvider(ctx, issuerURL) provider, err := oidc.NewProvider(ctx, issuerURL)
if err != nil { 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 { var s struct {
@ -153,7 +153,7 @@ func cmd() *cobra.Command {
ScopesSupported []string `json:"scopes_supported"` ScopesSupported []string `json:"scopes_supported"`
} }
if err := provider.Claims(&s); err != nil { 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 { if len(s.ScopesSupported) == 0 {

View file

@ -325,7 +325,7 @@ func (p *provider) HandlePOST(s connector.Scopes, samlResponse, inResponseTo str
// Status is a required element. // Status is a required element.
if resp.Status == nil { 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 { 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 == "") { if len(p.allowedGroups) > 0 && (!s.Groups || p.groupsAttr == "") {
// allowedGroups set but no groups or groupsAttr. Disallowing. // 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. // Grab the groups.
@ -427,7 +427,7 @@ func (p *provider) HandlePOST(s connector.Scopes, samlResponse, inResponseTo str
if len(groupMatches) == 0 { if len(groupMatches) == 0 {
// No group membership matches found, disallowing // 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 // Otherwise, we're good
@ -468,7 +468,7 @@ func (p *provider) validateStatus(status *status) error {
func (p *provider) validateSubject(subject *subject, inResponseTo string) error { func (p *provider) validateSubject(subject *subject, inResponseTo string) error {
// Optional according to the spec, but again, we're going to be strict here. // Optional according to the spec, but again, we're going to be strict here.
if len(subject.SubjectConfirmations) == 0 { if len(subject.SubjectConfirmations) == 0 {
return fmt.Errorf("Subject contained no SubjectConfirmations") return fmt.Errorf("subject contained no SubjectConfirmations")
} }
var errs []error var errs []error

View file

@ -55,14 +55,14 @@ type client struct {
} }
// idToName maps an arbitrary ID, such as an email or client ID to a Kubernetes object name. // idToName maps an arbitrary ID, such as an email or client ID to a Kubernetes object name.
func (c *client) idToName(s string) string { func (cli *client) idToName(s string) string {
return idToName(s, c.hash) return idToName(s, cli.hash)
} }
// offlineTokenName maps two arbitrary IDs, to a single Kubernetes object name. // 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. // This is used when more than one field is used to uniquely identify the object.
func (c *client) offlineTokenName(userID string, connID string) string { func (cli *client) offlineTokenName(userID string, connID string) string {
return offlineTokenName(userID, connID, c.hash) return offlineTokenName(userID, connID, cli.hash)
} }
// Kubernetes names must match the regexp '[a-z0-9]([-a-z0-9]*[a-z0-9])?'. // 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)), "=") 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/" basePath := "apis/"
if apiVersion == "v1" { if apiVersion == "v1" {
basePath = "api/" basePath = "api/"
@ -91,10 +91,10 @@ func (c *client) urlFor(apiVersion, namespace, resource, name string) string {
} else { } else {
p = path.Join(basePath, apiVersion, resource, name) p = path.Join(basePath, apiVersion, resource, name)
} }
if strings.HasSuffix(c.baseURL, "/") { if strings.HasSuffix(cli.baseURL, "/") {
return c.baseURL + p 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 // 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() r.Body.Close()
} }
func (c *client) get(resource, name string, v interface{}) error { func (cli *client) get(resource, name string, v interface{}) error {
return c.getResource(c.apiVersion, c.namespace, resource, name, v) return cli.getResource(cli.apiVersion, cli.namespace, resource, name, v)
} }
func (c *client) getResource(apiVersion, namespace, resource, name string, v interface{}) error { func (cli *client) getResource(apiVersion, namespace, resource, name string, v interface{}) error {
url := c.urlFor(apiVersion, namespace, resource, name) url := cli.urlFor(apiVersion, namespace, resource, name)
resp, err := c.client.Get(url) resp, err := cli.client.Get(url)
if err != nil { if err != nil {
return err return err
} }
@ -173,22 +173,22 @@ func (c *client) getResource(apiVersion, namespace, resource, name string, v int
return json.NewDecoder(resp.Body).Decode(v) return json.NewDecoder(resp.Body).Decode(v)
} }
func (c *client) list(resource string, v interface{}) error { func (cli *client) list(resource string, v interface{}) error {
return c.get(resource, "", v) return cli.get(resource, "", v)
} }
func (c *client) post(resource string, v interface{}) error { func (cli *client) post(resource string, v interface{}) error {
return c.postResource(c.apiVersion, c.namespace, resource, v) 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) body, err := json.Marshal(v)
if err != nil { if err != nil {
return fmt.Errorf("marshal object: %v", err) return fmt.Errorf("marshal object: %v", err)
} }
url := c.urlFor(apiVersion, namespace, resource, "") url := cli.urlFor(apiVersion, namespace, resource, "")
resp, err := c.client.Post(url, "application/json", bytes.NewReader(body)) resp, err := cli.client.Post(url, "application/json", bytes.NewReader(body))
if err != nil { if err != nil {
return err return err
} }
@ -196,13 +196,13 @@ func (c *client) postResource(apiVersion, namespace, resource string, v interfac
return checkHTTPErr(resp, http.StatusCreated) return checkHTTPErr(resp, http.StatusCreated)
} }
func (c *client) delete(resource, name string) error { func (cli *client) delete(resource, name string) error {
url := c.urlFor(c.apiVersion, c.namespace, resource, name) url := cli.urlFor(cli.apiVersion, cli.namespace, resource, name)
req, err := http.NewRequest("DELETE", url, nil) req, err := http.NewRequest("DELETE", url, nil)
if err != nil { if err != nil {
return fmt.Errorf("create delete request: %v", err) return fmt.Errorf("create delete request: %v", err)
} }
resp, err := c.client.Do(req) resp, err := cli.client.Do(req)
if err != nil { if err != nil {
return fmt.Errorf("delete request: %v", err) return fmt.Errorf("delete request: %v", err)
} }
@ -210,7 +210,7 @@ func (c *client) delete(resource, name string) error {
return checkHTTPErr(resp, http.StatusOK) return checkHTTPErr(resp, http.StatusOK)
} }
func (c *client) deleteAll(resource string) error { func (cli *client) deleteAll(resource string) error {
var list struct { var list struct {
k8sapi.TypeMeta `json:",inline"` k8sapi.TypeMeta `json:",inline"`
k8sapi.ListMeta `json:"metadata,omitempty"` k8sapi.ListMeta `json:"metadata,omitempty"`
@ -219,24 +219,24 @@ func (c *client) deleteAll(resource string) error {
k8sapi.ObjectMeta `json:"metadata,omitempty"` k8sapi.ObjectMeta `json:"metadata,omitempty"`
} `json:"items"` } `json:"items"`
} }
if err := c.list(resource, &list); err != nil { if err := cli.list(resource, &list); err != nil {
return err return err
} }
for _, item := range list.Items { 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 err
} }
} }
return nil 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) body, err := json.Marshal(v)
if err != nil { if err != nil {
return fmt.Errorf("marshal object: %v", err) 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)) req, err := http.NewRequest("PUT", url, bytes.NewReader(body))
if err != nil { if err != nil {
return fmt.Errorf("create patch request: %v", err) 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))) req.Header.Set("Content-Length", strconv.Itoa(len(body)))
resp, err := c.client.Do(req) resp, err := cli.client.Do(req)
if err != nil { if err != nil {
return fmt.Errorf("patch request: %v", err) return fmt.Errorf("patch request: %v", err)
} }