Skip to content

Commit

Permalink
golangci-lint: add noctx, sqlclosecheck; rm redundant revive.toml (#1…
Browse files Browse the repository at this point in the history
…1362)

* golangci-lint: add noctx, sqlclosecheck; rm redundant revive.toml

* sqlclosecheck

* noctx
  • Loading branch information
jmank88 authored Jan 11, 2024
1 parent dbc0f91 commit 3aa5e46
Show file tree
Hide file tree
Showing 63 changed files with 384 additions and 347 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ linters:
- misspell
- rowserrcheck
- errorlint
- sqlclosecheck
- noctx
linters-settings:
exhaustive:
default-signifies-exhaustive: true
Expand Down
2 changes: 2 additions & 0 deletions core/bridges/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func (o *orm) CreateBridgeType(bt *BridgeType) error {
if err != nil {
return err
}
defer stmt.Close()
return stmt.Get(bt, bt)
})
if err == nil {
Expand Down Expand Up @@ -222,6 +223,7 @@ func (o *orm) CreateExternalInitiator(externalInitiator *ExternalInitiator) (err
if err != nil {
return errors.Wrap(err, "failed to prepare named stmt")
}
defer stmt.Close()
return errors.Wrap(stmt.Get(externalInitiator, externalInitiator), "failed to load external_initiator")
})
return errors.Wrap(err, "CreateExternalInitiator failed")
Expand Down
17 changes: 9 additions & 8 deletions core/cmd/admin_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (ps AdminUsersPresenters) RenderTable(rt RendererTable) error {

// ListUsers renders all API users and their roles
func (s *Shell) ListUsers(_ *cli.Context) (err error) {
resp, err := s.HTTP.Get("/v2/users/", nil)
resp, err := s.HTTP.Get(s.ctx(), "/v2/users/", nil)
if err != nil {
return s.errorOut(err)
}
Expand All @@ -195,7 +195,7 @@ func (s *Shell) ListUsers(_ *cli.Context) (err error) {

// CreateUser creates a new user by prompting for email, password, and role
func (s *Shell) CreateUser(c *cli.Context) (err error) {
resp, err := s.HTTP.Get("/v2/users/", nil)
resp, err := s.HTTP.Get(s.ctx(), "/v2/users/", nil)
if err != nil {
return s.errorOut(err)
}
Expand Down Expand Up @@ -234,7 +234,7 @@ func (s *Shell) CreateUser(c *cli.Context) (err error) {
}

buf := bytes.NewBuffer(requestData)
response, err := s.HTTP.Post("/v2/users", buf)
response, err := s.HTTP.Post(s.ctx(), "/v2/users", buf)
if err != nil {
return s.errorOut(err)
}
Expand Down Expand Up @@ -263,7 +263,7 @@ func (s *Shell) ChangeRole(c *cli.Context) (err error) {
}

buf := bytes.NewBuffer(requestData)
response, err := s.HTTP.Patch("/v2/users", buf)
response, err := s.HTTP.Patch(s.ctx(), "/v2/users", buf)
if err != nil {
return s.errorOut(err)
}
Expand All @@ -283,7 +283,7 @@ func (s *Shell) DeleteUser(c *cli.Context) (err error) {
return s.errorOut(errors.New("email flag is empty, must specify an email"))
}

response, err := s.HTTP.Delete(fmt.Sprintf("/v2/users/%s", email))
response, err := s.HTTP.Delete(s.ctx(), fmt.Sprintf("/v2/users/%s", email))
if err != nil {
return s.errorOut(err)
}
Expand All @@ -297,8 +297,8 @@ func (s *Shell) DeleteUser(c *cli.Context) (err error) {
}

// Status will display the health of various services
func (s *Shell) Status(_ *cli.Context) error {
resp, err := s.HTTP.Get("/health?full=1", nil)
func (s *Shell) Status(c *cli.Context) error {
resp, err := s.HTTP.Get(s.ctx(), "/health?full=1", nil)
if err != nil {
return s.errorOut(err)
}
Expand All @@ -313,6 +313,7 @@ func (s *Shell) Status(_ *cli.Context) error {

// Profile will collect pprof metrics and store them in a folder.
func (s *Shell) Profile(c *cli.Context) error {
ctx := s.ctx()
seconds := c.Uint("seconds")
baseDir := c.String("output_dir")

Expand Down Expand Up @@ -342,7 +343,7 @@ func (s *Shell) Profile(c *cli.Context) error {
go func(vt string) {
defer wgPprof.Done()
uri := fmt.Sprintf("/v2/debug/pprof/%s?seconds=%d", vt, seconds)
resp, err := s.HTTP.Get(uri)
resp, err := s.HTTP.Get(ctx, uri)
if err != nil {
errs <- fmt.Errorf("error collecting %s: %w", vt, err)
return
Expand Down
2 changes: 1 addition & 1 deletion core/cmd/blocks_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (s *Shell) ReplayFromBlock(c *cli.Context) (err error) {
}

buf := bytes.NewBufferString("{}")
resp, err := s.HTTP.Post(
resp, err := s.HTTP.Post(s.ctx(),
fmt.Sprintf(
"/v2/replay_from_block/%v?%s",
blockNumber,
Expand Down
6 changes: 3 additions & 3 deletions core/cmd/bridge_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (s *Shell) ShowBridge(c *cli.Context) (err error) {
return s.errorOut(errors.New("must pass the name of the bridge to be shown"))
}
bridgeName := c.Args().First()
resp, err := s.HTTP.Get("/v2/bridge_types/" + bridgeName)
resp, err := s.HTTP.Get(s.ctx(), "/v2/bridge_types/"+bridgeName)
if err != nil {
return s.errorOut(err)
}
Expand All @@ -115,7 +115,7 @@ func (s *Shell) CreateBridge(c *cli.Context) (err error) {
return s.errorOut(err)
}

resp, err := s.HTTP.Post("/v2/bridge_types", buf)
resp, err := s.HTTP.Post(s.ctx(), "/v2/bridge_types", buf)
if err != nil {
return s.errorOut(err)
}
Expand All @@ -134,7 +134,7 @@ func (s *Shell) RemoveBridge(c *cli.Context) (err error) {
return s.errorOut(errors.New("must pass the name of the bridge to be removed"))
}
bridgeName := c.Args().First()
resp, err := s.HTTP.Delete("/v2/bridge_types/" + bridgeName)
resp, err := s.HTTP.Delete(s.ctx(), "/v2/bridge_types/"+bridgeName)
if err != nil {
return s.errorOut(err)
}
Expand Down
2 changes: 1 addition & 1 deletion core/cmd/cosmos_transaction_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (s *Shell) CosmosSendNativeToken(c *cli.Context) (err error) {

buf := bytes.NewBuffer(requestData)

resp, err := s.HTTP.Post("/v2/transfers/cosmos", buf)
resp, err := s.HTTP.Post(s.ctx(), "/v2/transfers/cosmos", buf)
if err != nil {
return s.errorOut(err)
}
Expand Down
8 changes: 4 additions & 4 deletions core/cmd/csa_keys_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (ps CSAKeyPresenters) RenderTable(rt RendererTable) error {

// ListCSAKeys retrieves a list of all CSA keys
func (s *Shell) ListCSAKeys(_ *cli.Context) (err error) {
resp, err := s.HTTP.Get("/v2/keys/csa", nil)
resp, err := s.HTTP.Get(s.ctx(), "/v2/keys/csa", nil)
if err != nil {
return s.errorOut(err)
}
Expand All @@ -123,7 +123,7 @@ func (s *Shell) ListCSAKeys(_ *cli.Context) (err error) {

// CreateCSAKey creates a new CSA key
func (s *Shell) CreateCSAKey(_ *cli.Context) (err error) {
resp, err := s.HTTP.Post("/v2/keys/csa", nil)
resp, err := s.HTTP.Post(s.ctx(), "/v2/keys/csa", nil)
if err != nil {
return s.errorOut(err)
}
Expand Down Expand Up @@ -165,7 +165,7 @@ func (s *Shell) ImportCSAKey(c *cli.Context) (err error) {
query.Set("oldpassword", normalizePassword(string(oldPassword)))

exportUrl.RawQuery = query.Encode()
resp, err := s.HTTP.Post(exportUrl.String(), bytes.NewReader(keyJSON))
resp, err := s.HTTP.Post(s.ctx(), exportUrl.String(), bytes.NewReader(keyJSON))
if err != nil {
return s.errorOut(err)
}
Expand Down Expand Up @@ -208,7 +208,7 @@ func (s *Shell) ExportCSAKey(c *cli.Context) (err error) {
query.Set("newpassword", normalizePassword(string(newPassword)))

exportUrl.RawQuery = query.Encode()
resp, err := s.HTTP.Post(exportUrl.String(), nil)
resp, err := s.HTTP.Post(s.ctx(), exportUrl.String(), nil)
if err != nil {
return s.errorOut(errors.Wrap(err, "Could not make HTTP request"))
}
Expand Down
12 changes: 6 additions & 6 deletions core/cmd/eth_keys_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (ps EthKeyPresenters) RenderTable(rt RendererTable) error {

// ListETHKeys renders the active account address with its ETH & LINK balance
func (s *Shell) ListETHKeys(_ *cli.Context) (err error) {
resp, err := s.HTTP.Get("/v2/keys/evm")
resp, err := s.HTTP.Get(s.ctx(), "/v2/keys/evm")

if err != nil {
return s.errorOut(err)
Expand Down Expand Up @@ -206,7 +206,7 @@ func (s *Shell) CreateETHKey(c *cli.Context) (err error) {
}

createUrl.RawQuery = query.Encode()
resp, err := s.HTTP.Post(createUrl.String(), nil)
resp, err := s.HTTP.Post(s.ctx(), createUrl.String(), nil)
if err != nil {
return s.errorOut(err)
}
Expand All @@ -231,7 +231,7 @@ func (s *Shell) DeleteETHKey(c *cli.Context) (err error) {
return nil
}

resp, err := s.HTTP.Delete("/v2/keys/evm/" + address)
resp, err := s.HTTP.Delete(s.ctx(), "/v2/keys/evm/"+address)
if err != nil {
return s.errorOut(err)
}
Expand Down Expand Up @@ -290,7 +290,7 @@ func (s *Shell) ImportETHKey(c *cli.Context) (err error) {
}

importUrl.RawQuery = query.Encode()
resp, err := s.HTTP.Post(importUrl.String(), bytes.NewReader(keyJSON))
resp, err := s.HTTP.Post(s.ctx(), importUrl.String(), bytes.NewReader(keyJSON))
if err != nil {
return s.errorOut(err)
}
Expand Down Expand Up @@ -332,7 +332,7 @@ func (s *Shell) ExportETHKey(c *cli.Context) (err error) {
query.Set("newpassword", strings.TrimSpace(string(newPassword)))

exportUrl.RawQuery = query.Encode()
resp, err := s.HTTP.Post(exportUrl.String(), nil)
resp, err := s.HTTP.Post(s.ctx(), exportUrl.String(), nil)
if err != nil {
return s.errorOut(errors.Wrap(err, "Could not make HTTP request"))
}
Expand Down Expand Up @@ -385,7 +385,7 @@ func (s *Shell) UpdateChainEVMKey(c *cli.Context) (err error) {
}

chainURL.RawQuery = query.Encode()
resp, err := s.HTTP.Post(chainURL.String(), nil)
resp, err := s.HTTP.Post(s.ctx(), chainURL.String(), nil)
if err != nil {
return s.errorOut(errors.Wrap(err, "Could not make HTTP request"))
}
Expand Down
4 changes: 2 additions & 2 deletions core/cmd/evm_transaction_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (s *Shell) ShowTransaction(c *cli.Context) (err error) {
return s.errorOut(errors.New("must pass the hash of the transaction"))
}
hash := c.Args().First()
resp, err := s.HTTP.Get("/v2/transactions/evm/" + hash)
resp, err := s.HTTP.Get(s.ctx(), "/v2/transactions/evm/"+hash)
if err != nil {
return s.errorOut(err)
}
Expand Down Expand Up @@ -198,7 +198,7 @@ func (s *Shell) SendEther(c *cli.Context) (err error) {

buf := bytes.NewBuffer(requestData)

resp, err := s.HTTP.Post("/v2/transfers/evm", buf)
resp, err := s.HTTP.Post(s.ctx(), "/v2/transfers/evm", buf)
if err != nil {
return s.errorOut(err)
}
Expand Down
4 changes: 2 additions & 2 deletions core/cmd/forwarders_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (s *Shell) DeleteForwarder(c *cli.Context) (err error) {
if !c.Args().Present() {
return s.errorOut(errors.New("must pass the forwarder id to be archived"))
}
resp, err := s.HTTP.Delete("/v2/nodes/evm/forwarders/" + c.Args().First())
resp, err := s.HTTP.Delete(s.ctx(), "/v2/nodes/evm/forwarders/"+c.Args().First())
if err != nil {
return s.errorOut(err)
}
Expand Down Expand Up @@ -143,7 +143,7 @@ func (s *Shell) TrackForwarder(c *cli.Context) (err error) {
return s.errorOut(err)
}

resp, err := s.HTTP.Post("/v2/nodes/evm/forwarders/track", bytes.NewReader(request))
resp, err := s.HTTP.Post(s.ctx(), "/v2/nodes/evm/forwarders/track", bytes.NewReader(request))
if err != nil {
return s.errorOut(err)
}
Expand Down
8 changes: 4 additions & 4 deletions core/cmd/jobs_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (s *Shell) ShowJob(c *cli.Context) (err error) {
return s.errorOut(errors.New("must provide the id of the job"))
}
id := c.Args().First()
resp, err := s.HTTP.Get("/v2/jobs/" + id)
resp, err := s.HTTP.Get(s.ctx(), "/v2/jobs/"+id)
if err != nil {
return s.errorOut(err)
}
Expand Down Expand Up @@ -244,7 +244,7 @@ func (s *Shell) CreateJob(c *cli.Context) (err error) {
return s.errorOut(err)
}

resp, err := s.HTTP.Post("/v2/jobs", bytes.NewReader(request))
resp, err := s.HTTP.Post(s.ctx(), "/v2/jobs", bytes.NewReader(request))
if err != nil {
return s.errorOut(err)
}
Expand Down Expand Up @@ -273,7 +273,7 @@ func (s *Shell) DeleteJob(c *cli.Context) error {
if !c.Args().Present() {
return s.errorOut(errors.New("must pass the job id to be archived"))
}
resp, err := s.HTTP.Delete("/v2/jobs/" + c.Args().First())
resp, err := s.HTTP.Delete(s.ctx(), "/v2/jobs/"+c.Args().First())
if err != nil {
return s.errorOut(err)
}
Expand All @@ -291,7 +291,7 @@ func (s *Shell) TriggerPipelineRun(c *cli.Context) error {
if !c.Args().Present() {
return s.errorOut(errors.New("Must pass the job id to trigger a run"))
}
resp, err := s.HTTP.Post("/v2/jobs/"+c.Args().First()+"/runs", nil)
resp, err := s.HTTP.Post(s.ctx(), "/v2/jobs/"+c.Args().First()+"/runs", nil)
if err != nil {
return s.errorOut(err)
}
Expand Down
10 changes: 5 additions & 5 deletions core/cmd/keys_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func newKeysClient[K keystore.Key, P TableRenderer, P2 ~[]P](typ string, s *Shel

// ListKeys retrieves a list of all keys
func (cli *keysClient[K, P, P2]) ListKeys(_ *cli.Context) (err error) {
resp, err := cli.HTTP.Get(cli.path, nil)
resp, err := cli.HTTP.Get(cli.ctx(), cli.path, nil)
if err != nil {
return cli.errorOut(err)
}
Expand All @@ -121,7 +121,7 @@ func (cli *keysClient[K, P, P2]) ListKeys(_ *cli.Context) (err error) {

// CreateKey creates a new key
func (cli *keysClient[K, P, P2]) CreateKey(_ *cli.Context) (err error) {
resp, err := cli.HTTP.Post(cli.path, nil)
resp, err := cli.HTTP.Post(cli.ctx(), cli.path, nil)
if err != nil {
return cli.errorOut(err)
}
Expand Down Expand Up @@ -152,7 +152,7 @@ func (cli *keysClient[K, P, P2]) DeleteKey(c *cli.Context) (err error) {
queryStr = "?hard=true"
}

resp, err := cli.HTTP.Delete(fmt.Sprintf(cli.path+"/%s%s", id, queryStr))
resp, err := cli.HTTP.Delete(cli.ctx(), fmt.Sprintf(cli.path+"/%s%s", id, queryStr))
if err != nil {
return cli.errorOut(err)
}
Expand Down Expand Up @@ -189,7 +189,7 @@ func (cli *keysClient[K, P, P2]) ImportKey(c *cli.Context) (err error) {
}

normalizedPassword := normalizePassword(string(oldPassword))
resp, err := cli.HTTP.Post(cli.path+"/import?oldpassword="+normalizedPassword, bytes.NewReader(keyJSON))
resp, err := cli.HTTP.Post(cli.ctx(), cli.path+"/import?oldpassword="+normalizedPassword, bytes.NewReader(keyJSON))
if err != nil {
return cli.errorOut(err)
}
Expand Down Expand Up @@ -227,7 +227,7 @@ func (cli *keysClient[K, P, P2]) ExportKey(c *cli.Context) (err error) {
ID := c.Args().Get(0)

normalizedPassword := normalizePassword(string(newPassword))
resp, err := cli.HTTP.Post(cli.path+"/export/"+ID+"?newpassword="+normalizedPassword, nil)
resp, err := cli.HTTP.Post(cli.ctx(), cli.path+"/export/"+ID+"?newpassword="+normalizedPassword, nil)
if err != nil {
return cli.errorOut(errors.Wrap(err, "Could not make HTTP request"))
}
Expand Down
10 changes: 5 additions & 5 deletions core/cmd/ocr2_keys_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (ps OCR2KeyBundlePresenters) RenderTable(rt RendererTable) error {

// ListOCR2KeyBundles lists the available OCR2 Key Bundles
func (s *Shell) ListOCR2KeyBundles(_ *cli.Context) error {
resp, err := s.HTTP.Get("/v2/keys/ocr2", nil)
resp, err := s.HTTP.Get(s.ctx(), "/v2/keys/ocr2", nil)
if err != nil {
return s.errorOut(err)
}
Expand All @@ -149,7 +149,7 @@ func (s *Shell) CreateOCR2KeyBundle(c *cli.Context) error {
)
}
chainType := c.Args().Get(0)
resp, err := s.HTTP.Post(fmt.Sprintf("/v2/keys/ocr2/%s", chainType), nil)
resp, err := s.HTTP.Post(s.ctx(), fmt.Sprintf("/v2/keys/ocr2/%s", chainType), nil)
if err != nil {
return s.errorOut(err)
}
Expand Down Expand Up @@ -182,7 +182,7 @@ func (s *Shell) DeleteOCR2KeyBundle(c *cli.Context) error {
queryStr = "?hard=true"
}

resp, err := s.HTTP.Delete(fmt.Sprintf("/v2/keys/ocr2/%s%s", id, queryStr))
resp, err := s.HTTP.Delete(s.ctx(), fmt.Sprintf("/v2/keys/ocr2/%s%s", id, queryStr))
if err != nil {
return s.errorOut(err)
}
Expand Down Expand Up @@ -218,7 +218,7 @@ func (s *Shell) ImportOCR2Key(c *cli.Context) (err error) {
}

normalizedPassword := normalizePassword(string(oldPassword))
resp, err := s.HTTP.Post("/v2/keys/ocr2/import?oldpassword="+normalizedPassword, bytes.NewReader(keyJSON))
resp, err := s.HTTP.Post(s.ctx(), "/v2/keys/ocr2/import?oldpassword="+normalizedPassword, bytes.NewReader(keyJSON))
if err != nil {
return s.errorOut(err)
}
Expand Down Expand Up @@ -255,7 +255,7 @@ func (s *Shell) ExportOCR2Key(c *cli.Context) (err error) {
ID := c.Args().Get(0)

normalizedPassword := normalizePassword(string(newPassword))
resp, err := s.HTTP.Post("/v2/keys/ocr2/export/"+ID+"?newpassword="+normalizedPassword, nil)
resp, err := s.HTTP.Post(s.ctx(), "/v2/keys/ocr2/export/"+ID+"?newpassword="+normalizedPassword, nil)
if err != nil {
return s.errorOut(errors.Wrap(err, "Could not make HTTP request"))
}
Expand Down
Loading

0 comments on commit 3aa5e46

Please sign in to comment.