Skip to content

Commit

Permalink
Merge pull request #68 from drone/lint-fixes
Browse files Browse the repository at this point in the history
fix for various lint warnings
  • Loading branch information
TP Honey authored Oct 14, 2021
2 parents 88e2be2 + c04fe95 commit 6acc5cc
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 30 deletions.
24 changes: 9 additions & 15 deletions drone/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
Expand Down Expand Up @@ -690,15 +684,15 @@ 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)
return out, err
}

// 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)
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/config/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion plugin/converter/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion plugin/internal/aesgcm/aesgcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
11 changes: 5 additions & 6 deletions plugin/internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
},
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions plugin/validator/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
12 changes: 8 additions & 4 deletions plugin/validator/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand All @@ -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)
}

0 comments on commit 6acc5cc

Please sign in to comment.