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

Commit

Permalink
Enabled golangci-lint with staticcheck only and fixed issues (#149)
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

* Use IsEmpty and move back to embedded structs
  • Loading branch information
andresuribe87 authored Oct 28, 2022
1 parent fc607fb commit 8905a12
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 10 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/server/router/credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/router/dwn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions pkg/server/server_manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion pkg/server/server_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -300,4 +301,4 @@ func getTestSchema() schema.JSONSchema {
"required": []interface{}{"foo"},
"additionalProperties": false,
}
}
}
4 changes: 2 additions & 2 deletions pkg/service/credential/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions pkg/service/keystore/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions pkg/service/manifest/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/service/schema/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions test/steelthread.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:")
Expand Down

0 comments on commit 8905a12

Please sign in to comment.