nuts-foundation/nuts-node

View on GitHub

Showing 140 of 165 total issues

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

func (system *System) Start() error {
    var err error
    return system.VisitEnginesE(func(engine Engine) error {
        if m, ok := engine.(Runnable); ok {
            name := engineName(engine)
Severity: Major
Found in core/engine.go and 1 other location - About 1 hr to fix
core/engine.go on lines 140..155

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 156.

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 Module.Migrate has a Cognitive Complexity of 27 (exceeds 20 allowed). Consider refactoring.
Open

func (r *Module) Migrate() error {
    // Find all documents that are managed by this node
    owned, err := r.ListOwned(context.Background())
    if err != nil {
        return err
Severity: Minor
Found in vdr/vdr.go - About 1 hr 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 store.applyFrom has a Cognitive Complexity of 27 (exceeds 20 allowed). Consider refactoring.
Open

func (tl *store) applyFrom(tx stoabs.WriteTx, base *event, applyList []event) error {
    var document *did.Document
    var metadata *documentMetadata
    var err error

Severity: Minor
Found in vdr/didnuts/didstore/writer.go - About 1 hr 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 StatusList2021.Entry has 60 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (cs *StatusList2021) Entry(ctx context.Context, issuer did.DID, purpose StatusPurpose) (*StatusList2021Entry, error) {
    if purpose != StatusPurposeRevocation {
        return nil, errUnsupportedPurpose
    }

Severity: Minor
Found in vcr/revocation/statuslist2021_issuer.go - About 1 hr to fix

    Method PresentationSubmissionBuilder.Build has 59 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (b *PresentationSubmissionBuilder) Build(format string) (PresentationSubmission, SignInstructions, error) {
        presentationSubmission := PresentationSubmission{
            Id:           uuid.New().String(),
            DefinitionId: b.presentationDefinition.Id,
        }
    Severity: Minor
    Found in vcr/pe/presentation_submission.go - About 1 hr to fix

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

      func loadOIDCProviderMetadata(ctx context.Context, identifier string, httpClient core.HTTPRequestDoer) (*ProviderMetadata, error) {
          // TODO: what about caching?
          //       See https://github.com/nuts-foundation/nuts-node/issues/2034
          result := ProviderMetadata{}
          err := httpGet(ctx, httpClient, core.JoinURLPaths(identifier, ProviderMetadataWellKnownPath), &result)
      Severity: Major
      Found in vcr/openid4vci/issuer_client.go and 1 other location - About 1 hr to fix
      vcr/openid4vci/issuer_client.go on lines 121..136

      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 151.

      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 2 locations. Consider refactoring.
      Open

      func loadCredentialIssuerMetadata(ctx context.Context, identifier string, httpClient core.HTTPRequestDoer) (*CredentialIssuerMetadata, error) {
          // TODO: what about caching?
          //       See https://github.com/nuts-foundation/nuts-node/issues/2034
          result := CredentialIssuerMetadata{}
          err := httpGet(ctx, httpClient, core.JoinURLPaths(identifier, CredentialIssuerMetadataWellKnownPath), &result)
      Severity: Major
      Found in vcr/openid4vci/issuer_client.go and 1 other location - About 1 hr to fix
      vcr/openid4vci/issuer_client.go on lines 138..153

      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 151.

      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

      Function CreateSystem has 58 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func CreateSystem(shutdownCallback context.CancelFunc) *core.System {
          system := core.NewSystem()
      
          // Create instances
          pkiInstance := pki.New()
      Severity: Minor
      Found in cmd/root.go - About 1 hr to fix

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

        func (c *OpenID4VPClient) OpenIdCredentialIssuerMetadata(ctx context.Context, oauthIssuerURI string) (*oauth.OpenIDCredentialIssuerMetadata, error) {
            iamClient := c.httpClient
            parsedURL, err := core.ParsePublicURL(oauthIssuerURI, c.strictMode)
            if err != nil {
                return nil, fmt.Errorf("invalid oauth issuer url: %w", err)
        Severity: Major
        Found in auth/client/iam/openid4vp.go and 1 other location - About 1 hr to fix
        auth/client/iam/openid4vp.go on lines 133..145

        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 149.

        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 2 locations. Consider refactoring.
        Open

        func (c *OpenID4VPClient) AuthorizationServerMetadata(ctx context.Context, oauthIssuer string) (*oauth.AuthorizationServerMetadata, error) {
            iamClient := c.httpClient
            parsedURL, err := core.ParsePublicURL(oauthIssuer, c.strictMode)
            if err != nil {
                return nil, fmt.Errorf("invalid oauth issuer url: %w", err)
        Severity: Major
        Found in auth/client/iam/openid4vp.go and 1 other location - About 1 hr to fix
        auth/client/iam/openid4vp.go on lines 299..311

        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 149.

        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 2 locations. Consider refactoring.
        Open

        func (w *Wrapper) ResolveStatusCode(err error) int {
            return core.ResolveStatusCode(err, map[error]int{
                vcrTypes.ErrNotFound:        http.StatusNotFound,
                resolver.ErrServiceNotFound: http.StatusPreconditionFailed,
                vcrTypes.ErrRevoked:         http.StatusConflict,
        Severity: Major
        Found in vcr/api/vcr/v2/api.go and 1 other location - About 1 hr to fix
        vdr/api/v1/api.go on lines 49..59

        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 146.

        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 Formats.Match has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring.
        Open

        func (f Formats) Match(other Formats) Formats {
            aliases := f.FormatAliases
            if aliases == nil {
                aliases = other.FormatAliases
            }
        Severity: Minor
        Found in vcr/credential/formats.go - About 1 hr 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 StatusList2021.Credential has 56 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (cs *StatusList2021) Credential(ctx context.Context, issuerDID did.DID, page int) (*vc.VerifiableCredential, error) {
            statusListCredentialURL, err := toStatusListCredential(issuerDID, page)
            if err != nil {
                return nil, err
            }
        Severity: Minor
        Found in vcr/revocation/statuslist2021_issuer.go - About 1 hr to fix

          Method kvBackedLeiaStore.handleRestore has 56 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (k *kvBackedLeiaStore) handleRestore(config LeiaBackupConfiguration) error {
              backupPresent := k.backupStorePresent(config.BackupShelf)
              collection := k.store.Collection(config.CollectionType, config.CollectionName)
          
              storePresent := storePresent(collection, config)
          Severity: Minor
          Found in storage/leia.go - About 1 hr to fix

            Function matchFilter has 56 lines of code (exceeds 50 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 1 hr to fix

              Method validator.verifyVP has 56 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

              func (v validator) verifyVP(vp vc.VerifiablePresentation, validAt *time.Time) (credentialSubject types.EmployeeIdentityCredentialSubject, proof vc.JSONWebSignature2020Proof, resultErr error) {
                  // #2428: NutsEmployeeCredential should be valid (signature), but does not need to be trusted.
                  vcs, err := v.vcr.Verifier().VerifyVP(vp, true, true, validAt)
                  if err != nil {
                      if errors.As(err, &verifier.VerificationError{}) {
              Severity: Minor
              Found in auth/services/selfsigned/validator.go - About 1 hr to fix

                Method issuer.buildAndSignVC has 55 lines of code (exceeds 50 allowed). Consider refactoring.
                Open

                func (i issuer) buildAndSignVC(ctx context.Context, template vc.VerifiableCredential, options CredentialOptions) (*vc.VerifiableCredential, error) {
                    issuerDID, err := did.ParseDID(template.Issuer.String())
                    if err != nil {
                        return nil, fmt.Errorf("failed to parse issuer: %w", err)
                    }
                Severity: Minor
                Found in vcr/issuer/issuer.go - About 1 hr to fix

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

                  func extractChallenge(presentation vc.VerifiablePresentation) (string, error) {
                      var nonce string
                      switch presentation.Format() {
                      case vc.JWTPresentationProofFormat:
                          nonceRaw, _ := presentation.JWT().Get("nonce")
                  Severity: Major
                  Found in auth/api/iam/openid4vp.go and 1 other location - About 1 hr to fix
                  auth/api/iam/s2s_vptoken.go on lines 198..214

                  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 141.

                  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 2 locations. Consider refactoring.
                  Open

                  func extractNonce(presentation vc.VerifiablePresentation) (string, error) {
                      var nonce string
                      switch presentation.Format() {
                      case vc.JWTPresentationProofFormat:
                          nonceRaw, _ := presentation.JWT().Get("nonce")
                  Severity: Major
                  Found in auth/api/iam/s2s_vptoken.go and 1 other location - About 1 hr to fix
                  auth/api/iam/openid4vp.go on lines 609..625

                  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 141.

                  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 vcr.Configure has 54 lines of code (exceeds 50 allowed). Consider refactoring.
                  Open

                  func (c *vcr) Configure(config core.ServerConfig) error {
                      var err error
                  
                      // store config parameters for use in Start()
                      c.datadir = config.Datadir
                  Severity: Minor
                  Found in vcr/vcr.go - About 1 hr to fix
                    Severity
                    Category
                    Status
                    Source
                    Language