Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
Enabled more linters (#150)
Browse files Browse the repository at this point in the history
* Enabled golangci-lint with staticcheck only and fixed issues

* Reverted extra file and added todo

* Remove the noise

* Added more linters plus fixes

* Tidying up

* undo extra stuff
  • Loading branch information
andresuribe87 authored Oct 28, 2022
1 parent 8905a12 commit 3603ace
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 19 deletions.
15 changes: 11 additions & 4 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ output:
linters:
disable-all: true
enable:
# TODO(Andres): enable the linters specified below.
# - revive
# - gosec
# - govet
- revive
- gosec
- govet
- staticcheck

linters-settings:
gosec:
config:
G101:
# We intentionally remove the 'cred' regex, to avoid false positives
pattern: "(/i)passwd|pass|password|pwd|secret|token|pw|apiKey|bearer"

11 changes: 6 additions & 5 deletions pkg/dwn/dwn.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ import (
"net/http"
)

type DWNPublishManifestRequest struct {
type PublishManifestRequest struct {
Manifest manifest.CredentialManifest `json:"manifest" validate:"required"`
}

type DWNPublishManifestResponse struct {
type PublishManifestResponse struct {
Status int `json:"status" validate:"required"`
Response string `json:"response" validate:"required"`
}

// PublishManifest publishes a CredentialManifest to a DWN
func PublishManifest(endpoint string, manifest manifest.CredentialManifest) (*DWNPublishManifestResponse, error) {
func PublishManifest(endpoint string, manifest manifest.CredentialManifest) (*PublishManifestResponse, error) {

dwnReq := DWNPublishManifestRequest{Manifest: manifest}
dwnReq := PublishManifestRequest{Manifest: manifest}
postResp, err := Post(endpoint, dwnReq)

if err != nil {
Expand All @@ -33,7 +33,7 @@ func PublishManifest(endpoint string, manifest manifest.CredentialManifest) (*DW
b, _ := io.ReadAll(postResp.Body)
body := string(b)

return &DWNPublishManifestResponse{Status: postResp.StatusCode, Response: body}, nil
return &PublishManifestResponse{Status: postResp.StatusCode, Response: body}, nil

}

Expand All @@ -45,6 +45,7 @@ func Post(endpoint string, data interface{}) (*http.Response, error) {
return nil, err
}

// #nosec: we are assuming the endpoint is safe. We might want to revisit.
resp, err := http.Post(endpoint, "application/json", bytes.NewBuffer(jsonData))

if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions pkg/server/router/credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,18 +228,18 @@ func (cr CredentialRouter) GetCredentials(ctx context.Context, w http.ResponseWr
}

if issuer != nil {
return cr.getCredentialsByIssuer(*issuer, ctx, w, r)
return cr.getCredentialsByIssuer(ctx, *issuer, w, r)
}
if subject != nil {
return cr.getCredentialsBySubject(*subject, ctx, w, r)
return cr.getCredentialsBySubject(ctx, *subject, w, r)
}
if schema != nil {
return cr.getCredentialsBySchema(*schema, ctx, w, r)
return cr.getCredentialsBySchema(ctx, *schema, w, r)
}
return err
}

func (cr CredentialRouter) getCredentialsByIssuer(issuer string, ctx context.Context, w http.ResponseWriter, _ *http.Request) error {
func (cr CredentialRouter) getCredentialsByIssuer(ctx context.Context, issuer string, w http.ResponseWriter, _ *http.Request) error {
gotCredentials, err := cr.service.GetCredentialsByIssuer(credential.GetCredentialByIssuerRequest{Issuer: issuer})
if err != nil {
errMsg := fmt.Sprintf("could not get credentials for issuer: %s", util.SanitizeLog(issuer))
Expand All @@ -251,7 +251,7 @@ func (cr CredentialRouter) getCredentialsByIssuer(issuer string, ctx context.Con
return framework.Respond(ctx, w, resp, http.StatusOK)
}

func (cr CredentialRouter) getCredentialsBySubject(subject string, ctx context.Context, w http.ResponseWriter, _ *http.Request) error {
func (cr CredentialRouter) getCredentialsBySubject(ctx context.Context, subject string, w http.ResponseWriter, _ *http.Request) error {
gotCredentials, err := cr.service.GetCredentialsBySubject(credential.GetCredentialBySubjectRequest{Subject: subject})
if err != nil {
errMsg := fmt.Sprintf("could not get credentials for subject: %s", util.SanitizeLog(subject))
Expand All @@ -263,7 +263,7 @@ func (cr CredentialRouter) getCredentialsBySubject(subject string, ctx context.C
return framework.Respond(ctx, w, resp, http.StatusOK)
}

func (cr CredentialRouter) getCredentialsBySchema(schema string, ctx context.Context, w http.ResponseWriter, _ *http.Request) error {
func (cr CredentialRouter) getCredentialsBySchema(ctx context.Context, schema string, w http.ResponseWriter, _ *http.Request) error {
gotCredentials, err := cr.service.GetCredentialsBySchema(credential.GetCredentialBySchemaRequest{Schema: schema})
if err != nil {
errMsg := fmt.Sprintf("could not get credentials for schema: %s", util.SanitizeLog(schema))
Expand Down
4 changes: 2 additions & 2 deletions pkg/server/router/dwn.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func (req PublishManifestRequest) ToServiceRequest() dwn.PublishManifestRequest
}

type PublishManifestResponse struct {
Manifest manifest.CredentialManifest `json:"manifest" validate:"required"`
DWNResponse dwnpkg.DWNPublishManifestResponse `json:"dwnResponse" validate:"required"`
Manifest manifest.CredentialManifest `json:"manifest" validate:"required"`
DWNResponse dwnpkg.PublishManifestResponse `json:"dwnResponse" validate:"required"`
}

// PublishManifest godoc
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/bolt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func TestBoltDBPrefixAndKeys(t *testing.T) {
assert.Len(t, prefixValues, 2)

var keys []string
for k, _ := range prefixValues {
for k := range prefixValues {
keys = append(keys, k)
}
assert.Contains(t, keys, "bitcoin-testnet")
Expand Down
2 changes: 1 addition & 1 deletion test/steelthread.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func getJSONElement(jsonString string, jsonPath string) (string, error) {
func get(url string) (string, error) {
fmt.Printf("\nPerforming GET request to: %s\n", url)

resp, err := http.Get(url)
resp, err := http.Get(url) // #nosec: testing only.
if err != nil {
return "", errors.Wrap(err, "problem with finding element in json string")
}
Expand Down

0 comments on commit 3603ace

Please sign in to comment.