dotcloud/docker

View on GitHub

Showing 1,904 of 1,904 total issues

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

func GetHostPartIP(ip net.IP, mask net.IPMask) (net.IP, error) {
    // Find the effective starting of address and mask
    is, ms, err := compareIPMask(ip, mask)
    if err != nil {
        return nil, fmt.Errorf("cannot compute host portion ip address because %s", err)
Severity: Major
Found in libnetwork/types/types.go and 1 other location - About 1 hr to fix
libnetwork/types/types.go on lines 308..322

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

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

package client // import "github.com/docker/docker/client"

import (
    "context"
    "encoding/json"
Severity: Major
Found in client/version.go and 2 other locations - About 1 hr to fix
client/swarm_get_unlock_key.go on lines 1..21
client/swarm_inspect.go on lines 1..21

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

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

package client // import "github.com/docker/docker/client"

import (
    "context"
    "encoding/json"
Severity: Major
Found in client/swarm_get_unlock_key.go and 2 other locations - About 1 hr to fix
client/swarm_inspect.go on lines 1..21
client/version.go on lines 1..21

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

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 LayerUploadManager.makeUploadFunc has 57 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (lum *LayerUploadManager) makeUploadFunc(descriptor UploadDescriptor) doFunc {
    return func(progressChan chan<- progress.Progress, start <-chan struct{}, inactive chan<- struct{}) transfer {
        u := &uploadTransfer{
            transfer: newTransfer(),
        }
Severity: Minor
Found in distribution/xfer/upload.go - About 1 hr to fix

    Method Sandbox.clearNetworkResources has 57 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (sb *Sandbox) clearNetworkResources(origEp *Endpoint) error {
        ep := sb.GetEndpoint(origEp.id)
        if ep == nil {
            return fmt.Errorf("could not find the sandbox endpoint data for endpoint %s",
                origEp.id)
    Severity: Minor
    Found in libnetwork/sandbox.go - About 1 hr to fix

      Method Resolver.setupIPTable has 57 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (r *Resolver) setupIPTable() error {
          if r.err != nil {
              return r.err
          }
          laddr := r.conn.LocalAddr().String()
      Severity: Minor
      Found in libnetwork/resolver_unix.go - About 1 hr to fix

        Function updateNodeKey has 57 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func updateNodeKey(lIP, aIP, rIP net.IP, idxs []*spi, curKeys []*key, newIdx, priIdx, delIdx int) []*spi {
            log.G(context.TODO()).Debugf("Updating keys for node: %s (%d,%d,%d)", rIP, newIdx, priIdx, delIdx)
        
            spis := idxs
            log.G(context.TODO()).Debugf("Current: %v", spis)
        Severity: Minor
        Found in libnetwork/drivers/overlay/encryption.go - About 1 hr to fix

          Method ImageService.getPushDescriptor has 57 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (i *ImageService) getPushDescriptor(ctx context.Context, img containerdimages.Image, platform *ocispec.Platform) (ocispec.Descriptor, error) {
              pm := i.matchRequestedOrDefault(platforms.OnlyStrict, platform)
          
              anyMissing := false
          
          
          Severity: Minor
          Found in daemon/containerd/image_push.go - About 1 hr to fix

            Function GetTimestamp has 57 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func GetTimestamp(value string, reference time.Time) (string, error) {
                if d, err := time.ParseDuration(value); value != "0" && err == nil {
                    return strconv.FormatInt(reference.Add(-d).Unix(), 10), nil
                }
            
            
            Severity: Minor
            Found in api/types/time/timestamp.go - About 1 hr to fix

              Method Cluster.resolveSystemAddr has 57 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

              func (c *Cluster) resolveSystemAddr() (net.IP, error) {
                  // Use the system's only device IP address, or fail if there are
                  // multiple addresses to choose from.
                  interfaces, err := nlwrap.LinkList()
                  if err != nil {
              Severity: Minor
              Found in daemon/cluster/listen_addr_linux.go - About 1 hr to fix

                Method Cluster.AttachNetwork has 57 lines of code (exceeds 50 allowed). Consider refactoring.
                Open

                func (c *Cluster) AttachNetwork(target string, containerID string, addresses []string) (*network.NetworkingConfig, error) {
                    aKey := attacherKey(target, containerID)
                    c.mu.Lock()
                    state := c.currentNodeState()
                    if state.swarmNode == nil || state.swarmNode.Agent() == nil {
                Severity: Minor
                Found in daemon/cluster/networks.go - About 1 hr to fix

                  Method Cluster.Join has 57 lines of code (exceeds 50 allowed). Consider refactoring.
                  Open

                  func (c *Cluster) Join(req types.JoinRequest) error {
                      c.controlMutex.Lock()
                      defer c.controlMutex.Unlock()
                      c.mu.Lock()
                      if c.nr != nil {
                  Severity: Minor
                  Found in daemon/cluster/swarm.go - About 1 hr to fix

                    Method Daemon.ContainerStats has 57 lines of code (exceeds 50 allowed). Consider refactoring.
                    Open

                    func (daemon *Daemon) ContainerStats(ctx context.Context, prefixOrName string, config *backend.ContainerStatsConfig) error {
                        ctr, err := daemon.GetContainer(prefixOrName)
                        if err != nil {
                            return err
                        }
                    Severity: Minor
                    Found in daemon/stats.go - About 1 hr to fix

                      Function ffjsonWriteJSONBytesAsString has 57 lines of code (exceeds 50 allowed). Consider refactoring.
                      Open

                      func ffjsonWriteJSONBytesAsString(buf *bytes.Buffer, s []byte) {
                          const hex = "0123456789abcdef"
                      
                          buf.WriteByte('"')
                          start := 0
                      Severity: Minor
                      Found in daemon/logger/jsonfilelog/jsonlog/jsonlogbytes.go - About 1 hr to fix

                        Function StartProxy has 13 return statements (exceeds 4 allowed).
                        Open

                        func StartProxy(pb types.PortBinding,
                            proxyPath string,
                            listenSock *os.File,
                        ) (stop func() error, retErr error) {
                            if proxyPath == "" {
                        Severity: Major
                        Found in libnetwork/portmapper/proxy_linux.go - About 1 hr to fix

                          Method driver.CreateEndpoint has 13 return statements (exceeds 4 allowed).
                          Open

                          func (d *driver) CreateEndpoint(ctx context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]interface{}) error {
                              ctx, span := otel.Tracer("").Start(ctx, fmt.Sprintf("libnetwork.drivers.windows_%s.CreateEndpoint", d.name), trace.WithAttributes(
                                  attribute.String("nid", nid),
                                  attribute.String("eid", eid)))
                              defer span.End()
                          Severity: Major
                          Found in libnetwork/drivers/windows/windows.go - About 1 hr to fix

                            Method Root.validateOpts has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring.
                            Open

                            func (r *Root) validateOpts(opts map[string]string) error {
                                if len(opts) == 0 {
                                    return nil
                                }
                                for opt := range opts {
                            Severity: Minor
                            Found in volume/local/local_unix.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 containerRouter.postContainerExecStart has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring.
                            Open

                            func (s *containerRouter) postContainerExecStart(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
                                if err := httputils.ParseForm(r); err != nil {
                                    return err
                                }
                            
                            
                            Severity: Minor
                            Found in api/server/router/container/exec.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 task.Exec has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring.
                            Open

                            func (t *task) Exec(ctx context.Context, processID string, spec *specs.Process, withStdin bool, attachStdio libcontainerdtypes.StdioCallback) (_ libcontainerdtypes.Process, retErr error) {
                                hcsContainer, err := t.getHCSContainer()
                                if err != nil {
                                    return nil, err
                                }
                            Severity: Minor
                            Found in libcontainerd/local/local_windows.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 Daemon.ContainerLogs has 13 return statements (exceeds 4 allowed).
                            Open

                            func (daemon *Daemon) ContainerLogs(ctx context.Context, containerName string, config *containertypes.LogsOptions) (messages <-chan *backend.LogMessage, isTTY bool, retErr error) {
                                ctx, span := tracing.StartSpan(ctx, "daemon.ContainerLogs")
                                defer func() {
                                    span.SetStatus(retErr)
                                    span.End()
                            Severity: Major
                            Found in daemon/logs.go - About 1 hr to fix
                              Severity
                              Category
                              Status
                              Source
                              Language