From c04fe958ef964713859c3adc5789c66319b38529 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Ga=C4=87e=C5=A1a?= Date: Tue, 12 Oct 2021 15:31:32 +0200 Subject: [PATCH] fix for various lint warnings --- drone/client.go | 24 +++++++++--------------- plugin/config/handler.go | 2 +- plugin/converter/handler.go | 2 +- plugin/internal/aesgcm/aesgcm.go | 2 +- plugin/internal/client/client.go | 11 +++++------ plugin/validator/client.go | 4 ++-- plugin/validator/handler.go | 12 ++++++++---- 7 files changed, 27 insertions(+), 30 deletions(-) diff --git a/drone/client.go b/drone/client.go index 22df311..c9657fe 100644 --- a/drone/client.go +++ b/drone/client.go @@ -28,13 +28,11 @@ import ( const ( pathSelf = "%s/api/user" - pathFeed = "%s/api/user/feed" pathRepos = "%s/api/user/repos" pathIncomplete = "%s/api/builds/incomplete" pathIncompleteV2 = "%s/api/builds/incomplete/v2" pathReposAll = "%s/api/repos" pathRepo = "%s/api/repos/%s/%s" - pathRepoMove = "%s/api/repos/%s/%s/move?to=%s" pathChown = "%s/api/repos/%s/%s/chown" pathRepair = "%s/api/repos/%s/%s/repair" pathBuilds = "%s/api/repos/%s/%s/builds?%s" @@ -43,14 +41,10 @@ const ( pathDecline = "%s/api/repos/%s/%s/builds/%d/decline/%d" pathPromote = "%s/api/repos/%s/%s/builds/%d/promote?%s" pathRollback = "%s/api/repos/%s/%s/builds/%d/rollback?%s" - pathJob = "%s/api/repos/%s/%s/builds/%d/%d" pathLog = "%s/api/repos/%s/%s/builds/%d/logs/%d/%d" pathRepoSecrets = "%s/api/repos/%s/%s/secrets" pathRepoSecret = "%s/api/repos/%s/%s/secrets/%s" - pathRepoRegistries = "%s/api/repos/%s/%s/registry" - pathRepoRegistry = "%s/api/repos/%s/%s/registry/%s" pathEncryptSecret = "%s/api/repos/%s/%s/encrypt/secret" - pathEncryptRegistry = "%s/api/repos/%s/%s/encrypt/registry" pathSign = "%s/api/repos/%s/%s/sign" pathVerify = "%s/api/repos/%s/%s/verify" pathCrons = "%s/api/repos/%s/%s/cron" @@ -178,7 +172,7 @@ func (c *client) IncompleteV2() ([]*RepoBuildStage, error) { } // Repo returns a repository by name. -func (c *client) Repo(owner string, name string) (*Repo, error) { +func (c *client) Repo(owner, name string) (*Repo, error) { out := new(Repo) uri := fmt.Sprintf(pathRepo, c.addr, owner, name) err := c.get(uri, out) @@ -271,7 +265,7 @@ func (c *client) Build(owner, name string, num int) (*Build, error) { func (c *client) BuildLast(owner, name, branch string) (*Build, error) { out := new(Build) uri := fmt.Sprintf(pathBuild, c.addr, owner, name, "latest") - if len(branch) != 0 { + if branch != "" { uri += "?branch=" + branch } err := c.get(uri, out) @@ -420,7 +414,7 @@ func (c *client) Secret(owner, name, secret string) (*Secret, error) { } // SecretList returns a list of all repository secrets. -func (c *client) SecretList(owner string, name string) ([]*Secret, error) { +func (c *client) SecretList(owner, name string) ([]*Secret, error) { var out []*Secret uri := fmt.Sprintf(pathRepoSecrets, c.addr, owner, name) err := c.get(uri, &out) @@ -504,7 +498,7 @@ func (c *client) Cron(owner, name, cron string) (*Cron, error) { } // CronList returns a list of all repository cronjobs. -func (c *client) CronList(owner string, name string) ([]*Cron, error) { +func (c *client) CronList(owner, name string) ([]*Cron, error) { var out []*Cron uri := fmt.Sprintf(pathCrons, c.addr, owner, name) err := c.get(uri, &out) @@ -519,7 +513,7 @@ func (c *client) CronCreate(owner, name string, in *Cron) (*Cron, error) { return out, err } -// CronDisable disables a cronjob. +// CronUpdate disables a cronjob. func (c *client) CronUpdate(owner, name, cron string, in *CronPatch) (*Cron, error) { out := new(Cron) uri := fmt.Sprintf(pathCron, c.addr, owner, name, cron) @@ -632,7 +626,7 @@ func (c *client) ServerCreate() (*Server, error) { func (c *client) ServerDelete(name string, force bool) error { uri := fmt.Sprintf(pathServer, c.addr, name) if force { - uri = uri + "?force=true" + uri += "?force=true" } return c.delete(uri) } @@ -658,7 +652,7 @@ func (c *client) AutoscaleVersion() (*Version, error) { } // Template returns a template by name. -func (c *client) Template(namespace string, name string) (*Template, error) { +func (c *client) Template(namespace, name string) (*Template, error) { out := new(Template) uri := fmt.Sprintf(pathTemplateName, c.addr, namespace, name) err := c.get(uri, out) @@ -690,7 +684,7 @@ func (c *client) TemplateCreate(namespace string, in *Template) (*Template, erro } // TemplateUpdate updates a template. -func (c *client) TemplateUpdate(namespace string, name string, in *Template) (*Template, error) { +func (c *client) TemplateUpdate(namespace, name string, in *Template) (*Template, error) { out := new(Template) uri := fmt.Sprintf(pathTemplateName, c.addr, namespace, name) err := c.patch(uri, in, out) @@ -698,7 +692,7 @@ func (c *client) TemplateUpdate(namespace string, name string, in *Template) (*T } // TemplateDelete deletes a template. -func (c *client) TemplateDelete(namespace string, name string) error { +func (c *client) TemplateDelete(namespace, name string) error { uri := fmt.Sprintf(pathTemplateName, c.addr, namespace, name) return c.delete(uri) } diff --git a/plugin/config/handler.go b/plugin/config/handler.go index 42721f8..b955229 100644 --- a/plugin/config/handler.go +++ b/plugin/config/handler.go @@ -97,5 +97,5 @@ func (p *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } out, _ := json.Marshal(res) w.Header().Set("Content-Type", "application/json") - w.Write(out) + _, _ = w.Write(out) } diff --git a/plugin/converter/handler.go b/plugin/converter/handler.go index da69bff..d16f1ff 100644 --- a/plugin/converter/handler.go +++ b/plugin/converter/handler.go @@ -98,5 +98,5 @@ func (p *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } out, _ := json.Marshal(res) w.Header().Set("Content-Type", "application/json") - w.Write(out) + _, _ = w.Write(out) } diff --git a/plugin/internal/aesgcm/aesgcm.go b/plugin/internal/aesgcm/aesgcm.go index ff44f7c..94defa1 100644 --- a/plugin/internal/aesgcm/aesgcm.go +++ b/plugin/internal/aesgcm/aesgcm.go @@ -77,6 +77,6 @@ func Key(s string) (*[32]byte, error) { return nil, errInvalidKeyLength } var key [32]byte - copy(key[:], []byte(s)) + copy(key[:], s) return &key, nil } diff --git a/plugin/internal/client/client.go b/plugin/internal/client/client.go index 57ade2d..682983b 100644 --- a/plugin/internal/client/client.go +++ b/plugin/internal/client/client.go @@ -71,7 +71,7 @@ func New(endpoint, secret string, skipverify bool) *Client { Transport: &http.Transport{ Proxy: http.ProxyFromEnvironment, TLSClientConfig: &tls.Config{ - InsecureSkipVerify: true, + InsecureSkipVerify: true, // user needs to explicitly enable this with skipverify=true }, }, } @@ -117,10 +117,9 @@ func (s *Client) Do(ctx context.Context, in, out interface{}) error { res, err := s.client().Do(req) if res != nil && res.Body != nil { defer func() { - // drain the response body so we can reuse - // this connection. - io.Copy(ioutil.Discard, io.LimitReader(res.Body, 4096)) - res.Body.Close() + // drain the response body so we can reuse this connection. + _, _ = io.Copy(ioutil.Discard, io.LimitReader(res.Body, 4096)) + _ = res.Body.Close() }() } if err != nil { @@ -164,7 +163,7 @@ func (s *Client) Do(ctx context.Context, in, out interface{}) error { if err != nil { return err } - body = []byte(plaintext) + body = plaintext } if out == nil { diff --git a/plugin/validator/client.go b/plugin/validator/client.go index e39e661..afa8f11 100644 --- a/plugin/validator/client.go +++ b/plugin/validator/client.go @@ -37,10 +37,10 @@ type pluginClient struct { func (c *pluginClient) Validate(ctx context.Context, in *Request) error { err := c.client.Do(ctx, in, nil) if xerr, ok := err.(*drone.Error); ok { - if xerr.Code == 498 { + if xerr.Code == httpStatusSkip { return ErrSkip } - if xerr.Code == 499 { + if xerr.Code == httpStatusBlock { return ErrBlock } } diff --git a/plugin/validator/handler.go b/plugin/validator/handler.go index 0f6bf18..2a03cc8 100644 --- a/plugin/validator/handler.go +++ b/plugin/validator/handler.go @@ -20,12 +20,16 @@ import ( "net/http" "github.com/drone/drone-go/drone" - "github.com/drone/drone-go/plugin/logger" "github.com/99designs/httpsignatures-go" ) +const ( + httpStatusSkip = 498 + httpStatusBlock = 499 +) + // Handler returns a http.Handler that accepts JSON-encoded // HTTP requests to validate the yaml configuration, invokes // the underlying plugin. A 2xx status code is returned if @@ -91,12 +95,12 @@ func (p *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } if err == ErrSkip { - w.WriteHeader(498) + w.WriteHeader(httpStatusSkip) return } if err == ErrBlock { - w.WriteHeader(499) + w.WriteHeader(httpStatusBlock) return } @@ -111,5 +115,5 @@ func (p *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { out, _ := json.Marshal(err) w.WriteHeader(http.StatusBadRequest) - w.Write(out) + _, _ = w.Write(out) }