From 7188f89ad0d78e13e878ddcae259d2da8e5a9d6c Mon Sep 17 00:00:00 2001 From: Steve Munene Date: Tue, 24 Sep 2024 12:09:34 +0300 Subject: [PATCH] NOISSUE - Fix failing CI (#21) * Fix failing CI Signed-off-by: nyagamunene * Update check generated files Signed-off-by: nyagamunene * Update linter and protoc issues Signed-off-by: nyagamunene * Update protoc version Signed-off-by: nyagamunene --------- Signed-off-by: nyagamunene --- .github/workflows/check-generated-files.yml | 160 ++++++++++---------- .github/workflows/ci.yml | 3 - api/http/responses.go | 14 +- certs_test.go | 4 +- cli/certs_test.go | 1 - cli/config.go | 10 +- go.mod | 11 +- go.sum | 8 + health.go | 6 +- internal/server/http/doc.go | 3 +- internal/server/http/http.go | 4 +- service.go | 23 ++- 12 files changed, 121 insertions(+), 126 deletions(-) diff --git a/.github/workflows/check-generated-files.yml b/.github/workflows/check-generated-files.yml index 10c7d3a..67c1fa0 100644 --- a/.github/workflows/check-generated-files.yml +++ b/.github/workflows/check-generated-files.yml @@ -33,83 +33,83 @@ jobs: uses: dorny/paths-filter@v3 id: changes with: - base: main - filters: | - proto: - - ".github/workflows/check-generated-files.yml" - - mocks: - - ".github/workflows/check-generated-files.yml" - - "sdk/mocks/sdk.go" - - "mocks/repository.go" - - "mocks/service.go" - - - name: Set up protoc - if: steps.changes.outputs.proto == 'true' - run: | - PROTOC_VERSION=27.2 - PROTOC_GEN_VERSION=v1.34.2 - PROTOC_GRPC_VERSION=v1.4.0 - - # Download and install protoc - PROTOC_ZIP=protoc-$PROTOC_VERSION-linux-x86_64.zip - curl -0L -o $PROTOC_ZIP https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOC_VERSION/$PROTOC_ZIP - unzip -o $PROTOC_ZIP -d protoc3 - sudo mv protoc3/bin/* /usr/local/bin/ - sudo mv protoc3/include/* /usr/local/include/ - rm -rf $PROTOC_ZIP protoc3 - - # Install protoc-gen-go and protoc-gen-go-grpc - go install google.golang.org/protobuf/cmd/protoc-gen-go@$PROTOC_GEN_VERSION - go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@$PROTOC_GRPC_VERSION - - # Add protoc to the PATH - export PATH=$PATH:/usr/local/bin/protoc - - - name: Check Protobuf is up to Date - if: steps.changes.outputs.proto == 'true' - run: | - for p in $(find . -name "*.pb.go"); do - mv $p $p.tmp - done - - make proto - - for p in $(find . -name "*.pb.go"); do - if ! cmp -s $p $p.tmp; then - echo "Error: Proto file and generated Go file $p are out of sync!" - echo "Please run 'make proto' with protoc version $PROTOC_VERSION, protoc-gen-go version $PROTOC_GEN_VERSION and protoc-gen-go-grpc version $PROTOC_GRPC_VERSION and commit the changes." - exit 1 - fi - done - - - name: Check Mocks are up to Date - if: steps.changes.outputs.mocks == 'true' - run: | - MOCKERY_VERSION=v2.43.2 - STRINGER_VERSION=v0.19.0 - - go install github.com/vektra/mockery/v2@$MOCKERY_VERSION - go install golang.org/x/tools/cmd/stringer@$STRINGER_VERSION - - mv ./sdk/mocks/sdk.go ./sdk/mocks/sdk.go.tmp - mv ./mocks/repository.go ./mocks/repository.go.tmp - mv ./mocks/service.go ./mocks/service.go.tmp - - make mocks - - check_mock_changes() { - local file_path=$1 - local tmp_file_path=$1.tmp - local entity_name=$2 - - if ! cmp -s "$file_path" "$tmp_file_path"; then - echo "Error: Generated mocks for $entity_name are out of sync!" - echo "Please run 'make mocks' with mockery version $MOCKERY_VERSION and commit the changes." - exit 1 - fi - } - - check_mock_changes ./sdk/mocks/sdk.go "SDK ./sdk/mocks/sdk.go" - check_mock_changes ./mocks/repository.go "Certs Repository ./mocks/repository.go" - check_mock_changes ./mocks/service.go "Certs Service ./mocks/service.go" + base: main + filters: | + proto: + - ".github/workflows/check-generated-files.yml" + + mocks: + - ".github/workflows/check-generated-files.yml" + - "sdk/mocks/sdk.go" + - "mocks/repository.go" + - "mocks/service.go" + + - name: Set up protoc + if: steps.changes.outputs.proto == 'true' + run: | + PROTOC_VERSION=27.1 + PROTOC_GEN_VERSION=v1.34.2 + PROTOC_GRPC_VERSION=v1.4.0 + + # Download and install protoc + PROTOC_ZIP=protoc-$PROTOC_VERSION-linux-x86_64.zip + curl -0L -o $PROTOC_ZIP https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOC_VERSION/$PROTOC_ZIP + unzip -o $PROTOC_ZIP -d protoc3 + sudo mv protoc3/bin/* /usr/local/bin/ + sudo mv protoc3/include/* /usr/local/include/ + rm -rf $PROTOC_ZIP protoc3 + + # Install protoc-gen-go and protoc-gen-go-grpc + go install google.golang.org/protobuf/cmd/protoc-gen-go@$PROTOC_GEN_VERSION + go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@$PROTOC_GRPC_VERSION + + # Add protoc to the PATH + export PATH=$PATH:/usr/local/bin/protoc + + - name: Check Protobuf is up to Date + if: steps.changes.outputs.proto == 'true' + run: | + for p in $(find . -name "*.pb.go"); do + mv $p $p.tmp + done + + make proto + + for p in $(find . -name "*.pb.go"); do + if ! cmp -s $p $p.tmp; then + echo "Error: Proto file and generated Go file $p are out of sync!" + echo "Please run 'make proto' with protoc version $PROTOC_VERSION, protoc-gen-go version $PROTOC_GEN_VERSION and protoc-gen-go-grpc version $PROTOC_GRPC_VERSION and commit the changes." + exit 1 + fi + done + + - name: Check Mocks are up to Date + if: steps.changes.outputs.mocks == 'true' + run: | + MOCKERY_VERSION=v2.43.2 + STRINGER_VERSION=v0.19.0 + + go install github.com/vektra/mockery/v2@$MOCKERY_VERSION + go install golang.org/x/tools/cmd/stringer@$STRINGER_VERSION + + mv ./sdk/mocks/sdk.go ./sdk/mocks/sdk.go.tmp + mv ./mocks/repository.go ./mocks/repository.go.tmp + mv ./mocks/service.go ./mocks/service.go.tmp + + make mocks + + check_mock_changes() { + local file_path=$1 + local tmp_file_path=$1.tmp + local entity_name=$2 + + if ! cmp -s "$file_path" "$tmp_file_path"; then + echo "Error: Generated mocks for $entity_name are out of sync!" + echo "Please run 'make mocks' with mockery version $MOCKERY_VERSION and commit the changes." + exit 1 + fi + } + + check_mock_changes ./sdk/mocks/sdk.go "SDK ./sdk/mocks/sdk.go" + check_mock_changes ./mocks/repository.go "Certs Repository ./mocks/repository.go" + check_mock_changes ./mocks/service.go "Certs Service ./mocks/service.go" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e1f74b7..87350e3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,9 +46,6 @@ jobs: with: node-version: lts/* - - name: Install dependencies - run: npm install - - name: Run Prettier id: prettier-run uses: rutajdash/prettier-cli-action@v1.0.1 diff --git a/api/http/responses.go b/api/http/responses.go index 79bd352..4ef1e90 100644 --- a/api/http/responses.go +++ b/api/http/responses.go @@ -19,12 +19,6 @@ var ( _ Response = (*ocspRes)(nil) ) -type pageRes struct { - Limit uint64 `json:"limit"` - Offset uint64 `json:"offset"` - Total uint64 `json:"total"` -} - type renewCertRes struct { renewed bool } @@ -135,6 +129,10 @@ func (res listCertsRes) Headers() map[string]string { return map[string]string{} } +func (res listCertsRes) Empty() bool { + return false +} + type viewCertRes struct { SerialNumber string `json:"serial_number"` Certificate string `json:"certificate"` @@ -156,10 +154,6 @@ func (res viewCertRes) Empty() bool { return false } -func (res listCertsRes) Empty() bool { - return false -} - type ocspRes struct { template ocsp.Response signer crypto.Signer diff --git a/certs_test.go b/certs_test.go index 1334b39..57cd98a 100644 --- a/certs_test.go +++ b/certs_test.go @@ -25,9 +25,7 @@ import ( const serialNumber = "serial number" -var ( - invalidToken = "123" -) +var invalidToken = "123" func TestIssueCert(t *testing.T) { cRepo := new(mocks.MockRepository) diff --git a/cli/certs_test.go b/cli/certs_test.go index ca66f6c..76637bb 100644 --- a/cli/certs_test.go +++ b/cli/certs_test.go @@ -369,7 +369,6 @@ func TestGetTokenCmd(t *testing.T) { t.Fatalf("Failed to unmarshal JSON: %v", err) } assert.Equal(t, tc.token, token, fmt.Sprintf("%v unexpected response, expected: %v, got: %v", tc.desc, tc.token, token)) - } sdkCall.Unset() }) diff --git a/cli/config.go b/cli/config.go index 219bd0c..1ae1046 100644 --- a/cli/config.go +++ b/cli/config.go @@ -45,13 +45,9 @@ type config struct { const filePermission = 0o644 var ( - errReadFail = errors.New("failed to read config file") - errNoKey = errors.New("no such key") - errUnsupportedKeyValue = errors.New("unsupported data type for key") - errWritingConfig = errors.New("error in writing the updated config to file") - errInvalidURL = errors.New("invalid url") - errURLParseFail = errors.New("failed to parse url") - defaultConfigPath = "./config.toml" + errReadFail = errors.New("failed to read config file") + errWritingConfig = errors.New("error in writing the updated config to file") + defaultConfigPath = "./config.toml" ) func read(file string) (config, error) { diff --git a/go.mod b/go.mod index 71d67bb..d193323 100644 --- a/go.mod +++ b/go.mod @@ -4,15 +4,19 @@ go 1.23.0 require ( github.com/caarlos0/env/v10 v10.0.0 + github.com/fatih/color v1.17.0 github.com/go-chi/chi v1.5.5 github.com/go-kit/kit v0.13.0 github.com/gofrs/uuid v4.4.0+incompatible github.com/golang-jwt/jwt v3.2.2+incompatible + github.com/hokaccha/go-prettyjson v0.0.0-20211117102719-0474bc63780f github.com/jackc/pgx/v5 v5.6.0 github.com/jmoiron/sqlx v1.4.0 github.com/ory/dockertest/v3 v3.11.0 + github.com/pelletier/go-toml v1.9.5 github.com/prometheus/client_golang v1.19.1 github.com/rubenv/sql-migrate v1.7.0 + github.com/spf13/cobra v1.8.1 github.com/stretchr/testify v1.9.0 go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.53.0 go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 @@ -25,6 +29,7 @@ require ( golang.org/x/sync v0.8.0 google.golang.org/grpc v1.65.0 google.golang.org/protobuf v1.34.2 + moul.io/http2curl v1.0.0 ) require ( @@ -41,7 +46,6 @@ require ( github.com/docker/docker v27.1.1+incompatible // indirect github.com/docker/go-connections v0.5.0 // indirect github.com/docker/go-units v0.5.0 // indirect - github.com/fatih/color v1.17.0 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/go-gorp/gorp/v3 v3.1.0 // indirect github.com/go-kit/log v0.2.1 // indirect @@ -52,7 +56,6 @@ require ( github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect github.com/google/uuid v1.6.0 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.21.0 // indirect - github.com/hokaccha/go-prettyjson v0.0.0-20211117102719-0474bc63780f // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 // indirect @@ -65,14 +68,13 @@ require ( github.com/opencontainers/go-digest v1.0.0 // indirect github.com/opencontainers/image-spec v1.1.0 // indirect github.com/opencontainers/runc v1.1.13 // indirect - github.com/pelletier/go-toml v1.9.5 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_model v0.6.1 // indirect github.com/prometheus/common v0.52.2 // indirect github.com/prometheus/procfs v0.13.0 // indirect github.com/sirupsen/logrus v1.9.3 // indirect - github.com/spf13/cobra v1.8.1 // indirect + github.com/smartystreets/goconvey v1.8.1 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/stretchr/objx v0.5.2 // indirect github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect @@ -87,5 +89,4 @@ require ( google.golang.org/genproto/googleapis/rpc v0.0.0-20240730163845-b1a4ccb954bf // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - moul.io/http2curl v1.0.0 // indirect ) diff --git a/go.sum b/go.sum index 3783cf9..3772272 100644 --- a/go.sum +++ b/go.sum @@ -68,6 +68,8 @@ github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaU github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g= +github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k= github.com/grpc-ecosystem/grpc-gateway/v2 v2.21.0 h1:CWyXh/jylQWp2dtiV33mY4iSSp6yf4lmn+c7/tN+ObI= github.com/grpc-ecosystem/grpc-gateway/v2 v2.21.0/go.mod h1:nCLIt0w3Ept2NwF8ThLmrppXsfT07oC8k0XNDxd8sVU= github.com/hokaccha/go-prettyjson v0.0.0-20211117102719-0474bc63780f h1:7LYC+Yfkj3CTRcShK0KOL/w6iTiKyqqBA9a41Wnggw8= @@ -84,6 +86,8 @@ github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o= github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY= +github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= @@ -137,6 +141,10 @@ github.com/rubenv/sql-migrate v1.7.0/go.mod h1:S4wtDEG1CKn+0ShpTtzWhFpHHI5PvCUti github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/smarty/assertions v1.15.0 h1:cR//PqUBUiQRakZWqBiFFQ9wb8emQGDb0HeGdqGByCY= +github.com/smarty/assertions v1.15.0/go.mod h1:yABtdzeQs6l1brC900WlRNwj6ZR55d7B+E8C6HtKdec= +github.com/smartystreets/goconvey v1.8.1 h1:qGjIddxOk4grTu9JPOU31tVfq3cNdBlNa5sSznIX1xY= +github.com/smartystreets/goconvey v1.8.1/go.mod h1:+/u4qLyY6x1jReYOp7GOM2FSt8aP9CzCZL03bI28W60= github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= diff --git a/health.go b/health.go index d6df198..bd1dabf 100644 --- a/health.go +++ b/health.go @@ -17,14 +17,14 @@ const ( var ( // Version represents the last service git tag in git history. - // It's meant to be set using go build ldflags: + // It's meant to be set using go build ldflags. Version = "0.0.0" // Commit represents the service git commit hash. - // It's meant to be set using go build ldflags: + // It's meant to be set using go build ldflags. Commit = "ffffffff" // BuildTime represetns the service build time. - // It's meant to be set using go build ldflags: + // It's meant to be set using go build ldflags. BuildTime = "1970-01-01_00:00:00" ) diff --git a/internal/server/http/doc.go b/internal/server/http/doc.go index 4ffad13..ccc9a7a 100644 --- a/internal/server/http/doc.go +++ b/internal/server/http/doc.go @@ -1,3 +1,4 @@ -// Copyright (c) Ultraviolet +// Copyright (c) Abstract Machines +// SPDX-License-Identifier: Apache-2.0 package http diff --git a/internal/server/http/http.go b/internal/server/http/http.go index 5b47d2e..de88cd9 100644 --- a/internal/server/http/http.go +++ b/internal/server/http/http.go @@ -1,4 +1,6 @@ -// Copyright (c) Ultraviolet +// Copyright (c) Abstract Machines +// SPDX-License-Identifier: Apache-2.0 + package http import ( diff --git a/service.go b/service.go index 9bad704..1441451 100644 --- a/service.go +++ b/service.go @@ -34,18 +34,17 @@ const ( ) var ( - serialNumberLimit = new(big.Int).Lsh(big.NewInt(1), 128) - errFailedReadingPrivateKey = errors.New("failed to read private key") - ErrNotFound = errors.New("entity not found") - ErrConflict = errors.New("entity already exists") - ErrCreateEntity = errors.New("failed to create entity") - ErrViewEntity = errors.New("view entity failed") - ErrGetToken = errors.New("failed to get token") - ErrUpdateEntity = errors.New("update entity failed") - ErrMalformedEntity = errors.New("malformed entity specification") - ErrRootCANotFound = errors.New("root CA not found") - ErrCertExpired = errors.New("certificate expired before renewal") - ErrCertRevoked = errors.New("certificate has been revoked and cannot be renewed") + serialNumberLimit = new(big.Int).Lsh(big.NewInt(1), 128) + ErrNotFound = errors.New("entity not found") + ErrConflict = errors.New("entity already exists") + ErrCreateEntity = errors.New("failed to create entity") + ErrViewEntity = errors.New("view entity failed") + ErrGetToken = errors.New("failed to get token") + ErrUpdateEntity = errors.New("update entity failed") + ErrMalformedEntity = errors.New("malformed entity specification") + ErrRootCANotFound = errors.New("root CA not found") + ErrCertExpired = errors.New("certificate expired before renewal") + ErrCertRevoked = errors.New("certificate has been revoked and cannot be renewed") ) type service struct {