Skip to content

Commit

Permalink
feat: update VCS response codes
Browse files Browse the repository at this point in the history
Signed-off-by: Misha Sizov <mykhailo.sizov@securekey.com>
  • Loading branch information
mishasizov-SK committed Jan 31, 2025
1 parent 79c5077 commit c806807
Show file tree
Hide file tree
Showing 111 changed files with 4,452 additions and 3,707 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ linters-settings:
# Enable to require nolint directives to mention the specific linter being suppressed.
# Default: false
require-specific: true
# Enable to ensure that nolint directives are all used. Default is true.
allow-unused: false

rowserrcheck:
# database/sql is always checked
Expand Down
443 changes: 222 additions & 221 deletions api/spec/openapi.gen.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions cmd/vc-rest/startcmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ import (
verifycredentialtracing "github.com/trustbloc/vcs/pkg/observability/tracing/wrappers/verifycredential"
verifypresentationtracing "github.com/trustbloc/vcs/pkg/observability/tracing/wrappers/verifypresentation"
profilereader "github.com/trustbloc/vcs/pkg/profile/reader"
"github.com/trustbloc/vcs/pkg/restapi/resterr"
"github.com/trustbloc/vcs/pkg/restapi/handlers"
"github.com/trustbloc/vcs/pkg/restapi/v1/devapi"
issuerv1 "github.com/trustbloc/vcs/pkg/restapi/v1/issuer"
"github.com/trustbloc/vcs/pkg/restapi/v1/logapi"
Expand Down Expand Up @@ -423,7 +423,7 @@ func buildEchoHandler(
) (*echo.Echo, error) {
e := createEcho()

e.HTTPErrorHandler = resterr.HTTPErrorHandler(conf.Tracer)
e.HTTPErrorHandler = handlers.HTTPErrorHandler(conf.Tracer)

metrics, err := NewMetrics(conf.StartupParameters, e, options)
if err != nil {
Expand Down
14 changes: 8 additions & 6 deletions component/credentialstatus/credentialstatus_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package credentialstatus
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand All @@ -37,7 +38,6 @@ import (
"github.com/trustbloc/vcs/pkg/event/spi"
vcskms "github.com/trustbloc/vcs/pkg/kms"
profileapi "github.com/trustbloc/vcs/pkg/profile"
"github.com/trustbloc/vcs/pkg/restapi/resterr"
"github.com/trustbloc/vcs/pkg/service/credentialstatus"
)

Expand All @@ -48,7 +48,10 @@ const (
credentialStatusClientRoleActivator = "activator"
)

var logger = log.New("credentialstatus")
var (
logger = log.New("credentialstatus")
ErrActionForbidden = errors.New("client is not allowed to perform the action")
)

type httpClient interface {
Do(req *http.Request) (*http.Response, error)
Expand Down Expand Up @@ -174,9 +177,8 @@ func (s *Service) UpdateVCStatus(ctx context.Context, params credentialstatus.Up
}

if params.StatusType != profile.VCConfig.Status.Type {
return resterr.NewValidationError(resterr.InvalidValue, "CredentialStatus.Type",
fmt.Errorf(
"vc status list version \"%s\" is not supported by current profile", params.StatusType))
return fmt.Errorf(
"vc status list version \"%s\" is not supported by current profile", params.StatusType)
}

typedID, err := s.vcStatusStore.Get(ctx, profile.ID, profile.Version, params.CredentialID)
Expand All @@ -202,7 +204,7 @@ func (s *Service) checkOAuthClientRole(oAuthClientRoles []string, statusValue bo
}

if !slices.Contains(oAuthClientRoles, requiredRole) {
return resterr.ErrActionForbidden
return ErrActionForbidden
}

return nil
Expand Down
5 changes: 2 additions & 3 deletions component/credentialstatus/credentialstatus_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import (
vcsverifiable "github.com/trustbloc/vcs/pkg/doc/verifiable"
"github.com/trustbloc/vcs/pkg/event/spi"
profileapi "github.com/trustbloc/vcs/pkg/profile"
"github.com/trustbloc/vcs/pkg/restapi/resterr"
"github.com/trustbloc/vcs/pkg/service/credentialstatus"
"github.com/trustbloc/vcs/pkg/service/credentialstatus/cslservice"
"github.com/trustbloc/vcs/pkg/service/credentialstatus/eventhandler"
Expand Down Expand Up @@ -502,7 +501,7 @@ func TestCredentialStatusList_UpdateVCStatus(t *testing.T) {

err = s.UpdateVCStatus(context.Background(), params)
require.Error(t, err)
require.ErrorIs(t, err, resterr.ErrActionForbidden)
require.ErrorIs(t, err, ErrActionForbidden)
})
t.Run("UpdateVCStatus action forbidden error: activator tries to revoke", func(t *testing.T) {
mockProfileSrv := NewMockProfileService(gomock.NewController(t))
Expand All @@ -522,7 +521,7 @@ func TestCredentialStatusList_UpdateVCStatus(t *testing.T) {

err = s.UpdateVCStatus(context.Background(), params)
require.Error(t, err)
require.ErrorIs(t, err, resterr.ErrActionForbidden)
require.ErrorIs(t, err, ErrActionForbidden)
})

t.Run("UpdateVCStatus profileService.GetProfile error", func(t *testing.T) {
Expand Down
55 changes: 0 additions & 55 deletions component/credentialstatus/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ require (
github.com/PaesslerAG/gval v1.2.2 // indirect
github.com/PaesslerAG/jsonpath v0.1.2-0.20240726212847-3a740cf7976f // indirect
github.com/VictoriaMetrics/fastcache v1.12.2 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/aws/aws-sdk-go-v2 v1.32.6 // indirect
github.com/aws/aws-sdk-go-v2/config v1.27.33 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.32 // indirect
Expand All @@ -55,81 +54,45 @@ require (
github.com/consensys/gnark-crypto v0.14.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/evanphx/json-patch v4.11.0+incompatible // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-jose/go-jose/v3 v3.0.3 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gobuffalo/pop/v6 v6.1.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.2.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/tink/go v1.7.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hyperledger/fabric-amcl v0.0.0-20230602173724-9e02669dceb2 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/kawamuray/jsonpath v0.0.0-20210127151053-2ab0d7f0a6ad // indirect
github.com/kilic/bls12-381 v0.1.1-0.20210503002446-7b7597926c69 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/labstack/echo/v4 v4.12.0 // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/goveralls v0.0.12 // indirect
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 // indirect
github.com/minio/sha256-simd v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/montanaflynn/stats v0.7.1 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/multiformats/go-base32 v0.1.0 // indirect
github.com/multiformats/go-base36 v0.2.0 // indirect
github.com/multiformats/go-multihash v0.0.14 // indirect
github.com/multiformats/go-varint v0.0.6 // indirect
github.com/openzipkin/zipkin-go v0.4.3 // indirect
github.com/ory/fosite v0.47.0 // indirect
github.com/ory/go-acc v0.2.9-0.20230103102148-6b1c9a70dbbe // indirect
github.com/ory/go-convenience v0.1.0 // indirect
github.com/ory/x v0.0.655 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/pquerna/cachecontrol v0.2.0 // indirect
github.com/sagikazarmark/locafero v0.6.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/samber/lo v1.47.0 // indirect
github.com/seatgeek/logrus-gelf-formatter v0.0.0-20210414080842-5b05eb8ff761 // indirect
github.com/shopspring/decimal v1.4.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.19.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/teserakt-io/golang-ed25519 v0.0.0-20210104091850-3888c087a4c8 // indirect
github.com/theory/jsonpath v0.3.0 // indirect
github.com/tidwall/gjson v1.17.3 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/tidwall/sjson v1.2.5 // indirect
github.com/trustbloc/bbs-signature-go v1.0.2 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/veraison/go-cose v1.3.0-rc.1 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
Expand All @@ -141,35 +104,17 @@ require (
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
go.mongodb.org/mongo-driver v1.16.1 // indirect
go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo v0.54.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.54.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
go.opentelemetry.io/contrib/propagators/b3 v1.29.0 // indirect
go.opentelemetry.io/contrib/propagators/jaeger v1.29.0 // indirect
go.opentelemetry.io/contrib/samplers/jaegerremote v0.23.0 // indirect
go.opentelemetry.io/otel v1.29.0 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.17.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.29.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.29.0 // indirect
go.opentelemetry.io/otel/exporters/zipkin v1.29.0 // indirect
go.opentelemetry.io/otel/metric v1.29.0 // indirect
go.opentelemetry.io/otel/sdk v1.29.0 // indirect
go.opentelemetry.io/otel/trace v1.29.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.29.0 // indirect
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.20.0 // indirect
golang.org/x/tools v0.25.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/grpc v1.66.1 // indirect
google.golang.org/protobuf v1.35.2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)
Expand Down
Loading

0 comments on commit c806807

Please sign in to comment.