diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 000000000..8753c115a --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,46 @@ +name: golangci-lint +on: + push: + tags: + - v* + branches: + - master + - main + pull_request: +permissions: + contents: read + # Optional: allow read access to pull request. Use with `only-new-issues` option. + # pull-requests: read +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/setup-go@v3 + with: + go-version: 1.19.2 + - uses: actions/checkout@v3 + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version + version: v1.50 + + # Optional: working directory, useful for monorepos + # working-directory: somedir + + # Optional: golangci-lint command line arguments. + # args: --issues-exit-code=0 + + # Optional: show only new issues if it's a pull request. The default value is `false`. + # only-new-issues: true + + # Optional: if set to true then the all caching functionality will be complete disabled, + # takes precedence over all other caching options. + # skip-cache: true + + # Optional: if set to true then the action don't cache or restore ~/go/pkg. + # skip-pkg-cache: true + + # Optional: if set to true then the action don't cache or restore ~/.cache/go-build. + # skip-build-cache: true \ No newline at end of file diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 000000000..123f1c3a6 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,17 @@ +# See https://golangci-lint.run/usage/configuration/ for reference. +run: + concurrency: 16 + skip-dirs: + - bin + +output: + sort-results: true + +linters: + disable-all: true + enable: +# TODO(Andres): enable the linters specified below. +# - revive +# - gosec +# - govet + - staticcheck diff --git a/magefile.go b/magefile.go index 94f935638..3f63cfea3 100644 --- a/magefile.go +++ b/magefile.go @@ -67,6 +67,20 @@ func CleanRun() error { return sh.Run("docker-compose", "--project-directory", "build", "down", "--rmi", "local") } +// Deps installs the dependencies needed for the build toolchain. +func Deps() error { + return brewInstall("golangci-lint") +} + +func brewInstall(formula string) error { + return sh.Run("brew", "install", formula) +} + +// Lint runs the configured linter. +func Lint() error { + return sh.Run("golangci-lint", "run") +} + // Run the service via docker-compose. func Run() error { if err := isDockerReady(); err != nil { diff --git a/pkg/server/router/credential.go b/pkg/server/router/credential.go index 51705f142..6138d2ac1 100644 --- a/pkg/server/router/credential.go +++ b/pkg/server/router/credential.go @@ -156,8 +156,8 @@ func (vcr VerifyCredentialRequest) IsValid() bool { } type VerifyCredentialResponse struct { - Verified bool `json:"verified" json:"verified"` - Reason string `json:"reason,omitempty" json:"reason,omitempty"` + Verified bool `json:"verified"` + Reason string `json:"reason,omitempty"` } // VerifyCredential godoc diff --git a/pkg/server/router/dwn.go b/pkg/server/router/dwn.go index 665bdb618..1089819de 100644 --- a/pkg/server/router/dwn.go +++ b/pkg/server/router/dwn.go @@ -79,7 +79,7 @@ func (dwnr DWNRouter) PublishManifest(ctx context.Context, w http.ResponseWriter req := request.ToServiceRequest() publishManifestResponse, err := dwnr.service.GetManifest(req) - if err != nil || &publishManifestResponse.Manifest == nil { + if err != nil || publishManifestResponse.Manifest.IsEmpty() { errMsg := "could not retrieve manifest" logrus.WithError(err).Error(errMsg) return framework.NewRequestError(errors.Wrap(err, errMsg), http.StatusInternalServerError) diff --git a/pkg/server/server_manifest_test.go b/pkg/server/server_manifest_test.go index 1a998ddb1..a05e2f2de 100644 --- a/pkg/server/server_manifest_test.go +++ b/pkg/server/server_manifest_test.go @@ -709,6 +709,7 @@ func TestManifestAPI(t *testing.T) { applicationRequestValue := newRequestValue(tt, router.SubmitApplicationRequest{ApplicationJWT: *signed}) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/manifests/applications", applicationRequestValue) err = manifestRouter.SubmitApplication(newRequestContext(), w, req) + assert.NoError(tt, err) var appResp router.SubmitApplicationResponse err = json.NewDecoder(w.Body).Decode(&appResp) @@ -731,6 +732,7 @@ func TestManifestAPI(t *testing.T) { // get all responses req = httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/manifests/responses", nil) err = manifestRouter.GetResponses(newRequestContext(), w, req) + assert.NoError(tt, err) var getResponsesResp router.GetResponsesResponse err = json.NewDecoder(w.Body).Decode(&getResponsesResp) @@ -742,6 +744,7 @@ func TestManifestAPI(t *testing.T) { // get all applications req = httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/manifests/applications", applicationRequestValue) err = manifestRouter.GetApplications(newRequestContext(), w, req) + assert.NoError(tt, err) var getApplicationsResp router.GetApplicationsResponse err = json.NewDecoder(w.Body).Decode(&getApplicationsResp) @@ -854,6 +857,7 @@ func TestManifestAPI(t *testing.T) { applicationRequestValue := newRequestValue(tt, router.SubmitApplicationRequest{ApplicationJWT: *signed}) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/manifests/applications", applicationRequestValue) err = manifestRouter.SubmitApplication(newRequestContext(), w, req) + assert.NoError(tt, err) var appResp router.SubmitApplicationResponse err = json.NewDecoder(w.Body).Decode(&appResp) @@ -862,6 +866,7 @@ func TestManifestAPI(t *testing.T) { // get all applications req = httptest.NewRequest(http.MethodGet, "https://ssi-service.com/v1/manifests/applications", applicationRequestValue) err = manifestRouter.GetApplications(newRequestContext(), w, req) + assert.NoError(tt, err) var getApplicationsResp router.GetApplicationsResponse err = json.NewDecoder(w.Body).Decode(&getApplicationsResp) diff --git a/pkg/server/server_schema_test.go b/pkg/server/server_schema_test.go index 9e4d60116..c0ca2b101 100644 --- a/pkg/server/server_schema_test.go +++ b/pkg/server/server_schema_test.go @@ -99,6 +99,7 @@ func TestSchemaAPI(t *testing.T) { schemaRequestValue = newRequestValue(tt, schemaRequest) req = httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/schemas", schemaRequestValue) err = schemaService.CreateSchema(newRequestContext(), w, req) + assert.NoError(tt, err) var resp router.CreateSchemaResponse err = json.NewDecoder(w.Body).Decode(&resp) @@ -300,4 +301,4 @@ func getTestSchema() schema.JSONSchema { "required": []interface{}{"foo"}, "additionalProperties": false, } -} \ No newline at end of file +} diff --git a/pkg/service/credential/service.go b/pkg/service/credential/service.go index 91195337c..af2dde643 100644 --- a/pkg/service/credential/service.go +++ b/pkg/service/credential/service.go @@ -232,8 +232,8 @@ func (vcr VerifyCredentialRequest) IsValid() error { } type VerifyCredentialResponse struct { - Verified bool `json:"verified" json:"verified"` - Reason string `json:"reason,omitempty" json:"reason,omitempty"` + Verified bool `json:"verified"` + Reason string `json:"reason,omitempty"` } // VerifyCredential does three levels of verification on a credential: diff --git a/pkg/service/keystore/service_test.go b/pkg/service/keystore/service_test.go index fb1a9713e..a9f2221da 100644 --- a/pkg/service/keystore/service_test.go +++ b/pkg/service/keystore/service_test.go @@ -85,6 +85,7 @@ func TestEncryptDecryptAllKeyTypes(t *testing.T) { // reconstruct the key from its serialized form privKeyReconstructed, err := crypto.BytesToPrivKey(decryptedKey, test.kt) + assert.NoError(t, err) assert.EqualValues(t, privKey, privKeyReconstructed) }) } @@ -114,6 +115,7 @@ func TestStoreAndGetKey(t *testing.T) { // store the key _, privKey, err := crypto.GenerateEd25519Key() + assert.NoError(t, err) err = keyStore.StoreKey(StoreKeyRequest{ ID: "test-id", Type: crypto.Ed25519, diff --git a/pkg/service/manifest/model.go b/pkg/service/manifest/model.go index eca534f62..f8dd797dc 100644 --- a/pkg/service/manifest/model.go +++ b/pkg/service/manifest/model.go @@ -28,8 +28,8 @@ type VerifyManifestRequest struct { } type VerifyManifestResponse struct { - Verified bool `json:"verified" json:"verified"` - Reason string `json:"reason,omitempty" json:"reason,omitempty"` + Verified bool `json:"verified"` + Reason string `json:"reason,omitempty"` } type GetManifestRequest struct { diff --git a/pkg/service/schema/model.go b/pkg/service/schema/model.go index adfb0a147..fc8ffd857 100644 --- a/pkg/service/schema/model.go +++ b/pkg/service/schema/model.go @@ -33,8 +33,8 @@ type VerifySchemaRequest struct { } type VerifySchemaResponse struct { - Verified bool `json:"verified" json:"verified"` - Reason string `json:"reason,omitempty" json:"reason,omitempty"` + Verified bool `json:"verified"` + Reason string `json:"reason,omitempty"` } type GetSchemasResponse struct { diff --git a/test/steelthread.go b/test/steelthread.go index 4cad05320..ff324e5d8 100644 --- a/test/steelthread.go +++ b/test/steelthread.go @@ -63,6 +63,9 @@ func RunTest() error { } aliceDIDPrivateKey, err := getJSONElement(output, "$.privateKeyBase58") + if err != nil { + return errors.Wrap(err, "getting json") + } // Create a schema to be used in CM fmt.Println("\n\nCreate a schema to be used in CM:")