nuts-foundation/nuts-node

View on GitHub

Showing 138 of 163 total issues

File api.go has 725 lines of code (exceeds 500 allowed). Consider refactoring.
Open

/*
 * Copyright (C) 2023 Nuts community
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
Severity: Minor
Found in auth/api/iam/api.go - About 7 hrs to fix

    Wrapper has 32 methods (exceeds 20 allowed). Consider refactoring.
    Open

    type Wrapper struct {
        auth          auth.AuthenticationServices
        policyBackend policy.PDPBackend
        storageEngine storage.Engine
        jsonldManager jsonld.JSONLD
    Severity: Minor
    Found in auth/api/iam/api.go - About 4 hrs to fix

      Method openidHandler.validateProof has 108 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (i *openidHandler) validateProof(ctx context.Context, flow *Flow, request openid4vci.CredentialRequest) error {
          credential := flow.Credentials[0] // there's always just one (at least for now)
          wallet, _ := credential.SubjectDID()
      
          // augment invalid_proof errors according to §7.3.2 of openid4vci spec
      Severity: Major
      Found in vcr/issuer/openid.go - About 3 hrs to fix

        File openid4vp.go has 543 lines of code (exceeds 500 allowed). Consider refactoring.
        Open

        /*
         * Copyright (C) 2023 Nuts community
         *
         * This program is free software: you can redistribute it and/or modify
         * it under the terms of the GNU General Public License as published by
        Severity: Minor
        Found in auth/api/iam/openid4vp.go - About 3 hrs to fix

          state has 26 methods (exceeds 20 allowed). Consider refactoring.
          Open

          type state struct {
              db                  stoabs.KVStore
              graph               *dag
              payloadStore        PayloadStore
              txVerifiers         []Verifier
          Severity: Minor
          Found in network/dag/state.go - About 3 hrs to fix

            Method dag.Migrate has a Cognitive Complexity of 35 (exceeds 20 allowed). Consider refactoring.
            Open

            func (d *dag) Migrate() error {
                return d.db.Write(context.Background(), func(tx stoabs.WriteTx) error {
                    writer := tx.GetShelfWriter(metadataShelf)
                    // Migrate highest LC value
                    // Todo: remove after V5 release
            Severity: Minor
            Found in network/dag/dag.go - About 2 hrs to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Similar blocks of code found in 3 locations. Consider refactoring.
            Open

            func (w *Wrapper) Routes(router core.EchoRouter) {
                RegisterHandlers(router, NewStrictHandler(w, []StrictMiddlewareFunc{
                    func(f StrictHandlerFunc, operationID string) StrictHandlerFunc {
                        return func(ctx echo.Context, request interface{}) (response interface{}, err error) {
                            ctx.Set(core.OperationIDContextKey, operationID)
            Severity: Major
            Found in didman/api/v1/api.go and 2 other locations - About 2 hrs to fix
            auth/api/auth/v1/api.go on lines 77..91
            vcr/api/vcr/v2/api.go on lines 61..75

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 221.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 3 locations. Consider refactoring.
            Open

            func (w *Wrapper) Routes(router core.EchoRouter) {
                RegisterHandlers(router, NewStrictHandler(w, []StrictMiddlewareFunc{
                    func(f StrictHandlerFunc, operationID string) StrictHandlerFunc {
                        return func(ctx echo.Context, request interface{}) (response interface{}, err error) {
                            ctx.Set(core.OperationIDContextKey, operationID)
            Severity: Major
            Found in auth/api/auth/v1/api.go and 2 other locations - About 2 hrs to fix
            didman/api/v1/api.go on lines 80..94
            vcr/api/vcr/v2/api.go on lines 61..75

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 221.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 3 locations. Consider refactoring.
            Open

            func (w *Wrapper) Routes(router core.EchoRouter) {
                RegisterHandlers(router, NewStrictHandler(w, []StrictMiddlewareFunc{
                    func(f StrictHandlerFunc, operationID string) StrictHandlerFunc {
                        return func(ctx echo.Context, request interface{}) (response interface{}, err error) {
                            ctx.Set(core.OperationIDContextKey, operationID)
            Severity: Major
            Found in vcr/api/vcr/v2/api.go and 2 other locations - About 2 hrs to fix
            auth/api/auth/v1/api.go on lines 77..91
            didman/api/v1/api.go on lines 80..94

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 221.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 3 locations. Consider refactoring.
            Open

            func (w *Wrapper) Routes(router core.EchoRouter) {
                RegisterHandlers(router, NewStrictHandler(w, []StrictMiddlewareFunc{
                    func(f StrictHandlerFunc, operationID string) StrictHandlerFunc {
                        return func(ctx echo.Context, request interface{}) (response interface{}, err error) {
                            ctx.Set(core.OperationIDContextKey, operationID)
            Severity: Major
            Found in crypto/api/v1/api.go and 2 other locations - About 2 hrs to fix
            vdr/api/v1/api.go on lines 100..114
            vdr/api/v2/api.go on lines 57..71

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 217.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 3 locations. Consider refactoring.
            Open

            func (a *Wrapper) Routes(router core.EchoRouter) {
                RegisterHandlers(router, NewStrictHandler(a, []StrictMiddlewareFunc{
                    func(f StrictHandlerFunc, operationID string) StrictHandlerFunc {
                        return func(ctx echo.Context, request interface{}) (response interface{}, err error) {
                            ctx.Set(core.OperationIDContextKey, operationID)
            Severity: Major
            Found in vdr/api/v1/api.go and 2 other locations - About 2 hrs to fix
            crypto/api/v1/api.go on lines 58..72
            vdr/api/v2/api.go on lines 57..71

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 217.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 3 locations. Consider refactoring.
            Open

            func (w *Wrapper) Routes(router core.EchoRouter) {
                RegisterHandlers(router, NewStrictHandler(w, []StrictMiddlewareFunc{
                    func(f StrictHandlerFunc, operationID string) StrictHandlerFunc {
                        return func(ctx echo.Context, request interface{}) (response interface{}, err error) {
                            ctx.Set(core.OperationIDContextKey, operationID)
            Severity: Major
            Found in vdr/api/v2/api.go and 2 other locations - About 2 hrs to fix
            crypto/api/v1/api.go on lines 58..72
            vdr/api/v1/api.go on lines 100..114

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 217.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Method openidHandler.HandleCredentialOffer has 86 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func (h *openidHandler) HandleCredentialOffer(ctx context.Context, offer openid4vci.CredentialOffer) error {
                // TODO: This check is too simplistic, there can be multiple credential offers,
                //       but the issuer should only request the one it's interested in.
                //       See https://github.com/nuts-foundation/nuts-node/issues/2049
                if len(offer.Credentials) != 1 {
            Severity: Major
            Found in vcr/holder/openid.go - About 2 hrs to fix

              Function matchFilter has a Cognitive Complexity of 32 (exceeds 20 allowed). Consider refactoring.
              Open

              func matchFilter(filter Filter, value interface{}) (bool, error) {
                  // first we check if it's an enum, so we can recursively call matchFilter for each value
                  if filter.Enum != nil {
                      for _, enum := range filter.Enum {
                          f := Filter{
              Severity: Minor
              Found in vcr/pe/presentation_definition.go - About 2 hrs to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Method Wrapper.handleAuthorizeResponseSubmission has 81 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

              func (r Wrapper) handleAuthorizeResponseSubmission(ctx context.Context, request HandleAuthorizeResponseRequestObject) (HandleAuthorizeResponseResponseObject, error) {
                  verifier, err := r.toOwnedDIDForOAuth2(ctx, request.Did)
                  if err != nil {
                      return nil, oauthError(oauth.InvalidRequest, "unknown verifier id")
                  }
              Severity: Major
              Found in auth/api/iam/openid4vp.go - About 2 hrs to fix

                Function issueVC has a Cognitive Complexity of 31 (exceeds 20 allowed). Consider refactoring.
                Open

                func issueVC() *cobra.Command {
                    var publish bool
                    var visibilityStr string
                    var expirationDate string
                    result := &cobra.Command{
                Severity: Minor
                Found in vcr/cmd/cmd.go - About 2 hrs to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Function matchFormat has a Cognitive Complexity of 31 (exceeds 20 allowed). Consider refactoring.
                Open

                func matchFormat(format *PresentationDefinitionClaimFormatDesignations, credential vc.VerifiableCredential) bool {
                    if format == nil || len(*format) == 0 {
                        return true
                    }
                
                
                Severity: Minor
                Found in vcr/pe/presentation_definition.go - About 2 hrs to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                File didman.go has 503 lines of code (exceeds 500 allowed). Consider refactoring.
                Open

                /*
                 * Nuts node
                 * Copyright (C) 2021 Nuts community
                 *
                 * This program is free software: you can redistribute it and/or modify
                Severity: Minor
                Found in didman/didman.go - About 2 hrs to fix

                  Method Resolver.Resolve has 75 lines of code (exceeds 50 allowed). Consider refactoring.
                  Open

                  func (r Resolver) Resolve(id did.DID, _ *resolver.ResolveMetadata) (*did.Document, *resolver.DocumentMetadata, error) {
                      if id.Method != MethodName {
                          return nil, nil, fmt.Errorf("unsupported DID method: %s", id.Method)
                      }
                      encodedKey := id.ID
                  Severity: Minor
                  Found in vdr/didkey/resolver.go - About 2 hrs to fix

                    Method Wrapper.handleUserLanding has 73 lines of code (exceeds 50 allowed). Consider refactoring.
                    Open

                    func (r Wrapper) handleUserLanding(echoCtx echo.Context) error {
                        // todo: user authentication is currently not implemented, user consent is not implemented
                        // This means that this handler succeeds if the token is valid
                        // It only checks for an existing RequestAccessTokenRequestObject in the store
                        // It does not (yet) check for user consent or the existence of a user wallet
                    Severity: Minor
                    Found in auth/api/iam/user.go - About 1 hr to fix
                      Severity
                      Category
                      Status
                      Source
                      Language