docker/swarmkit

View on GitHub
swarmd/cmd/swarm-rafttool/dump.go

Summary

Maintainability
F
1 wk
Test Coverage

Function dumpObject has a Cognitive Complexity of 145 (exceeds 20 allowed). Consider refactoring.
Open

func dumpObject(swarmdir, unlockKey, objType string, selector objSelector) error {
    memStore := store.NewMemoryStore(nil)
    defer memStore.Close()

    walData, snapshot, err := loadData(swarmdir, unlockKey)
Severity: Minor
Found in swarmd/cmd/swarm-rafttool/dump.go - About 2 days 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 dumpWAL has a Cognitive Complexity of 67 (exceeds 20 allowed). Consider refactoring.
Open

func dumpWAL(swarmdir, unlockKey string, start, end uint64, redact bool) error {
    walData, _, err := loadData(swarmdir, unlockKey)
    if err != nil {
        return err
    }
Severity: Minor
Found in swarmd/cmd/swarm-rafttool/dump.go - About 1 day 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 dumpObject has 191 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func dumpObject(swarmdir, unlockKey, objType string, selector objSelector) error {
    memStore := store.NewMemoryStore(nil)
    defer memStore.Close()

    walData, snapshot, err := loadData(swarmdir, unlockKey)
Severity: Major
Found in swarmd/cmd/swarm-rafttool/dump.go - About 6 hrs to fix

    Function dumpSnapshot has a Cognitive Complexity of 51 (exceeds 20 allowed). Consider refactoring.
    Open

    func dumpSnapshot(swarmdir, unlockKey string, redact bool) error {
        _, snapshot, err := loadData(swarmdir, unlockKey)
        if err != nil {
            return err
        }
    Severity: Minor
    Found in swarmd/cmd/swarm-rafttool/dump.go - About 5 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 dumpSnapshot has 70 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func dumpSnapshot(swarmdir, unlockKey string, redact bool) error {
        _, snapshot, err := loadData(swarmdir, unlockKey)
        if err != nil {
            return err
        }
    Severity: Minor
    Found in swarmd/cmd/swarm-rafttool/dump.go - About 1 hr to fix

      Function dumpObject has 19 return statements (exceeds 4 allowed).
      Open

      func dumpObject(swarmdir, unlockKey, objType string, selector objSelector) error {
          memStore := store.NewMemoryStore(nil)
          defer memStore.Close()
      
          walData, snapshot, err := loadData(swarmdir, unlockKey)
      Severity: Major
      Found in swarmd/cmd/swarm-rafttool/dump.go - About 1 hr to fix

        Function dumpWAL has 60 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func dumpWAL(swarmdir, unlockKey string, start, end uint64, redact bool) error {
            walData, _, err := loadData(swarmdir, unlockKey)
            if err != nil {
                return err
            }
        Severity: Minor
        Found in swarmd/cmd/swarm-rafttool/dump.go - About 1 hr to fix

          Avoid deeply nested control flow statements.
          Open

                                      if container := actype.Task.Spec.GetContainer(); container != nil {
                                          container.Env = []string{"ENVVARS REDACTED"}
                                          if container.PullOptions != nil {
                                              container.PullOptions.RegistryAuth = "REDACTED"
                                          }
          Severity: Major
          Found in swarmd/cmd/swarm-rafttool/dump.go - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                        if container := actype.Service.Spec.Task.GetContainer(); container != nil {
                                            container.Env = []string{"ENVVARS REDACTED"}
                                            if container.PullOptions != nil {
                                                container.PullOptions.RegistryAuth = "REDACTED"
                                            }
            Severity: Major
            Found in swarmd/cmd/swarm-rafttool/dump.go - About 45 mins to fix

              Function dumpSnapshot has 6 return statements (exceeds 4 allowed).
              Open

              func dumpSnapshot(swarmdir, unlockKey string, redact bool) error {
                  _, snapshot, err := loadData(swarmdir, unlockKey)
                  if err != nil {
                      return err
                  }
              Severity: Major
              Found in swarmd/cmd/swarm-rafttool/dump.go - About 40 mins to fix

                Function dumpWAL has 5 return statements (exceeds 4 allowed).
                Open

                func dumpWAL(swarmdir, unlockKey string, start, end uint64, redact bool) error {
                    walData, _, err := loadData(swarmdir, unlockKey)
                    if err != nil {
                        return err
                    }
                Severity: Major
                Found in swarmd/cmd/swarm-rafttool/dump.go - About 35 mins to fix

                  Function loadData has 5 return statements (exceeds 4 allowed).
                  Open

                  func loadData(swarmdir, unlockKey string) (*storage.WALData, *raftpb.Snapshot, error) {
                      snapDir := filepath.Join(swarmdir, "raft", "snap-v3-encrypted")
                      walDir := filepath.Join(swarmdir, "raft", "wal-v3-encrypted")
                  
                      var (
                  Severity: Major
                  Found in swarmd/cmd/swarm-rafttool/dump.go - About 35 mins to fix

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

                            case "service":
                                if selector.id != "" {
                                    object := store.GetService(tx, selector.id)
                                    if object != nil {
                                        objects = append(objects, object)
                    Severity: Major
                    Found in swarmd/cmd/swarm-rafttool/dump.go and 8 other locations - About 55 mins to fix
                    swarmd/cmd/swarm-rafttool/dump.go on lines 298..313
                    swarmd/cmd/swarm-rafttool/dump.go on lines 330..345
                    swarmd/cmd/swarm-rafttool/dump.go on lines 346..361
                    swarmd/cmd/swarm-rafttool/dump.go on lines 362..377
                    swarmd/cmd/swarm-rafttool/dump.go on lines 378..393
                    swarmd/cmd/swarm-rafttool/dump.go on lines 394..409
                    swarmd/cmd/swarm-rafttool/dump.go on lines 410..425
                    swarmd/cmd/swarm-rafttool/dump.go on lines 426..441

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

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

                            case "config":
                                if selector.id != "" {
                                    object := store.GetConfig(tx, selector.id)
                                    if object != nil {
                                        objects = append(objects, object)
                    Severity: Major
                    Found in swarmd/cmd/swarm-rafttool/dump.go and 8 other locations - About 55 mins to fix
                    swarmd/cmd/swarm-rafttool/dump.go on lines 298..313
                    swarmd/cmd/swarm-rafttool/dump.go on lines 314..329
                    swarmd/cmd/swarm-rafttool/dump.go on lines 330..345
                    swarmd/cmd/swarm-rafttool/dump.go on lines 346..361
                    swarmd/cmd/swarm-rafttool/dump.go on lines 362..377
                    swarmd/cmd/swarm-rafttool/dump.go on lines 378..393
                    swarmd/cmd/swarm-rafttool/dump.go on lines 410..425
                    swarmd/cmd/swarm-rafttool/dump.go on lines 426..441

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

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

                            case "secret":
                                if selector.id != "" {
                                    object := store.GetSecret(tx, selector.id)
                                    if object != nil {
                                        objects = append(objects, object)
                    Severity: Major
                    Found in swarmd/cmd/swarm-rafttool/dump.go and 8 other locations - About 55 mins to fix
                    swarmd/cmd/swarm-rafttool/dump.go on lines 298..313
                    swarmd/cmd/swarm-rafttool/dump.go on lines 314..329
                    swarmd/cmd/swarm-rafttool/dump.go on lines 330..345
                    swarmd/cmd/swarm-rafttool/dump.go on lines 346..361
                    swarmd/cmd/swarm-rafttool/dump.go on lines 362..377
                    swarmd/cmd/swarm-rafttool/dump.go on lines 394..409
                    swarmd/cmd/swarm-rafttool/dump.go on lines 410..425
                    swarmd/cmd/swarm-rafttool/dump.go on lines 426..441

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

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

                            case "extension":
                                if selector.id != "" {
                                    object := store.GetExtension(tx, selector.id)
                                    if object != nil {
                                        objects = append(objects, object)
                    Severity: Major
                    Found in swarmd/cmd/swarm-rafttool/dump.go and 8 other locations - About 55 mins to fix
                    swarmd/cmd/swarm-rafttool/dump.go on lines 298..313
                    swarmd/cmd/swarm-rafttool/dump.go on lines 314..329
                    swarmd/cmd/swarm-rafttool/dump.go on lines 330..345
                    swarmd/cmd/swarm-rafttool/dump.go on lines 346..361
                    swarmd/cmd/swarm-rafttool/dump.go on lines 362..377
                    swarmd/cmd/swarm-rafttool/dump.go on lines 378..393
                    swarmd/cmd/swarm-rafttool/dump.go on lines 394..409
                    swarmd/cmd/swarm-rafttool/dump.go on lines 410..425

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

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

                            case "cluster":
                                if selector.id != "" {
                                    object := store.GetCluster(tx, selector.id)
                                    if object != nil {
                                        objects = append(objects, object)
                    Severity: Major
                    Found in swarmd/cmd/swarm-rafttool/dump.go and 8 other locations - About 55 mins to fix
                    swarmd/cmd/swarm-rafttool/dump.go on lines 298..313
                    swarmd/cmd/swarm-rafttool/dump.go on lines 314..329
                    swarmd/cmd/swarm-rafttool/dump.go on lines 330..345
                    swarmd/cmd/swarm-rafttool/dump.go on lines 346..361
                    swarmd/cmd/swarm-rafttool/dump.go on lines 378..393
                    swarmd/cmd/swarm-rafttool/dump.go on lines 394..409
                    swarmd/cmd/swarm-rafttool/dump.go on lines 410..425
                    swarmd/cmd/swarm-rafttool/dump.go on lines 426..441

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

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

                            case "node":
                                if selector.id != "" {
                                    object := store.GetNode(tx, selector.id)
                                    if object != nil {
                                        objects = append(objects, object)
                    Severity: Major
                    Found in swarmd/cmd/swarm-rafttool/dump.go and 8 other locations - About 55 mins to fix
                    swarmd/cmd/swarm-rafttool/dump.go on lines 314..329
                    swarmd/cmd/swarm-rafttool/dump.go on lines 330..345
                    swarmd/cmd/swarm-rafttool/dump.go on lines 346..361
                    swarmd/cmd/swarm-rafttool/dump.go on lines 362..377
                    swarmd/cmd/swarm-rafttool/dump.go on lines 378..393
                    swarmd/cmd/swarm-rafttool/dump.go on lines 394..409
                    swarmd/cmd/swarm-rafttool/dump.go on lines 410..425
                    swarmd/cmd/swarm-rafttool/dump.go on lines 426..441

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

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

                            case "task":
                                if selector.id != "" {
                                    object := store.GetTask(tx, selector.id)
                                    if object != nil {
                                        objects = append(objects, object)
                    Severity: Major
                    Found in swarmd/cmd/swarm-rafttool/dump.go and 8 other locations - About 55 mins to fix
                    swarmd/cmd/swarm-rafttool/dump.go on lines 298..313
                    swarmd/cmd/swarm-rafttool/dump.go on lines 314..329
                    swarmd/cmd/swarm-rafttool/dump.go on lines 346..361
                    swarmd/cmd/swarm-rafttool/dump.go on lines 362..377
                    swarmd/cmd/swarm-rafttool/dump.go on lines 378..393
                    swarmd/cmd/swarm-rafttool/dump.go on lines 394..409
                    swarmd/cmd/swarm-rafttool/dump.go on lines 410..425
                    swarmd/cmd/swarm-rafttool/dump.go on lines 426..441

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

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

                            case "resource":
                                if selector.id != "" {
                                    object := store.GetResource(tx, selector.id)
                                    if object != nil {
                                        objects = append(objects, object)
                    Severity: Major
                    Found in swarmd/cmd/swarm-rafttool/dump.go and 8 other locations - About 55 mins to fix
                    swarmd/cmd/swarm-rafttool/dump.go on lines 298..313
                    swarmd/cmd/swarm-rafttool/dump.go on lines 314..329
                    swarmd/cmd/swarm-rafttool/dump.go on lines 330..345
                    swarmd/cmd/swarm-rafttool/dump.go on lines 346..361
                    swarmd/cmd/swarm-rafttool/dump.go on lines 362..377
                    swarmd/cmd/swarm-rafttool/dump.go on lines 378..393
                    swarmd/cmd/swarm-rafttool/dump.go on lines 394..409
                    swarmd/cmd/swarm-rafttool/dump.go on lines 426..441

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

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

                            case "network":
                                if selector.id != "" {
                                    object := store.GetNetwork(tx, selector.id)
                                    if object != nil {
                                        objects = append(objects, object)
                    Severity: Major
                    Found in swarmd/cmd/swarm-rafttool/dump.go and 8 other locations - About 55 mins to fix
                    swarmd/cmd/swarm-rafttool/dump.go on lines 298..313
                    swarmd/cmd/swarm-rafttool/dump.go on lines 314..329
                    swarmd/cmd/swarm-rafttool/dump.go on lines 330..345
                    swarmd/cmd/swarm-rafttool/dump.go on lines 362..377
                    swarmd/cmd/swarm-rafttool/dump.go on lines 378..393
                    swarmd/cmd/swarm-rafttool/dump.go on lines 394..409
                    swarmd/cmd/swarm-rafttool/dump.go on lines 410..425
                    swarmd/cmd/swarm-rafttool/dump.go on lines 426..441

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

                    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

                    There are no issues that match your filters.

                    Category
                    Status