kubenetworks/kubevpn

View on GitHub
pkg/handler/connect.go

Summary

Maintainability
F
1 wk
Test Coverage

File connect.go has 996 lines of code (exceeds 500 allowed). Consider refactoring.
Open

package handler

import (
    "context"
    "encoding/json"
Severity: Major
Found in pkg/handler/connect.go - About 1 day to fix

    Method ConnectOptions.addExtraRoute has a Cognitive Complexity of 65 (exceeds 20 allowed). Consider refactoring.
    Open

    func (c *ConnectOptions) addExtraRoute(ctx context.Context, nameserver string) error {
        if len(c.ExtraRouteInfo.ExtraDomain) == 0 {
            return nil
        }
    
    
    Severity: Minor
    Found in pkg/handler/connect.go - About 7 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 ConnectOptions.addRouteDynamic has a Cognitive Complexity of 52 (exceeds 20 allowed). Consider refactoring.
    Open

    func (c *ConnectOptions) addRouteDynamic(ctx context.Context) error {
        tunName, e := c.GetTunDeviceName()
        if e != nil {
            return e
        }
    Severity: Minor
    Found in pkg/handler/connect.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

    Method ConnectOptions.addExtraRoute has 120 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (c *ConnectOptions) addExtraRoute(ctx context.Context, nameserver string) error {
        if len(c.ExtraRouteInfo.ExtraDomain) == 0 {
            return nil
        }
    
    
    Severity: Major
    Found in pkg/handler/connect.go - About 3 hrs to fix

      Method ConnectOptions.getCIDR has a Cognitive Complexity of 39 (exceeds 20 allowed). Consider refactoring.
      Open

      func (c *ConnectOptions) getCIDR(ctx context.Context, m *dhcp.Manager) (err error) {
          defer func() {
              if err == nil {
                  u, err2 := url.Parse(c.config.Host)
                  if err2 != nil {
      Severity: Minor
      Found in pkg/handler/connect.go - About 3 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 ConnectOptions.PreCheckResource has a Cognitive Complexity of 37 (exceeds 20 allowed). Consider refactoring.
      Open

      func (c *ConnectOptions) PreCheckResource() error {
          if len(c.Workloads) == 0 {
              return nil
          }
      
      
      Severity: Minor
      Found in pkg/handler/connect.go - About 3 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

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

      type ConnectOptions struct {
          Namespace            string
          Headers              map[string]string
          PortMap              []string
          Workloads            []string
      Severity: Minor
      Found in pkg/handler/connect.go - About 3 hrs to fix

        Method ConnectOptions.portForward has a Cognitive Complexity of 36 (exceeds 20 allowed). Consider refactoring.
        Open

        func (c *ConnectOptions) portForward(ctx context.Context, portPair []string) error {
            firstCtx, firstCancelFunc := context.WithCancel(ctx)
            defer firstCancelFunc()
            var errChan = make(chan error, 1)
            go func() {
        Severity: Minor
        Found in pkg/handler/connect.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 ConnectOptions.addRouteDynamic has 78 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (c *ConnectOptions) addRouteDynamic(ctx context.Context) error {
            tunName, e := c.GetTunDeviceName()
            if e != nil {
                return e
            }
        Severity: Major
        Found in pkg/handler/connect.go - About 2 hrs to fix

          Method ConnectOptions.portForward has 77 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (c *ConnectOptions) portForward(ctx context.Context, portPair []string) error {
              firstCtx, firstCancelFunc := context.WithCancel(ctx)
              defer firstCancelFunc()
              var errChan = make(chan error, 1)
              go func() {
          Severity: Major
          Found in pkg/handler/connect.go - About 2 hrs to fix

            Method ConnectOptions.startLocalTunServe has 73 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func (c *ConnectOptions) startLocalTunServe(ctx context.Context, forwardAddress string, lite bool) (err error) {
                log.Debugf("IPv4: %s, IPv6: %s", c.localTunIPv4.IP.String(), c.localTunIPv6.IP.String())
            
                var cidrList []*net.IPNet
                if !lite {
            Severity: Minor
            Found in pkg/handler/connect.go - About 1 hr to fix

              Method ConnectOptions.DoConnect has 66 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

              func (c *ConnectOptions) DoConnect(ctx context.Context, isLite bool) (err error) {
                  c.ctx, c.cancel = context.WithCancel(ctx)
              
                  log.Info("Starting connect")
                  m := dhcp.NewDHCPManager(c.clientset.CoreV1().ConfigMaps(c.Namespace), c.Namespace)
              Severity: Minor
              Found in pkg/handler/connect.go - About 1 hr to fix

                Method ConnectOptions.setupDNS has 66 lines of code (exceeds 50 allowed). Consider refactoring.
                Open

                func (c *ConnectOptions) setupDNS(ctx context.Context) error {
                    const port = 53
                    const portTCP = 10800
                    pod, err := c.GetRunningPodList(ctx)
                    if err != nil {
                Severity: Minor
                Found in pkg/handler/connect.go - About 1 hr to fix

                  Method ConnectOptions.upgradeDeploy has 64 lines of code (exceeds 50 allowed). Consider refactoring.
                  Open

                  func (c *ConnectOptions) upgradeDeploy(ctx context.Context) error {
                      deploy, err := c.clientset.AppsV1().Deployments(c.Namespace).Get(ctx, config.ConfigMapPodTrafficManager, metav1.GetOptions{})
                      if err != nil {
                          return err
                      }
                  Severity: Minor
                  Found in pkg/handler/connect.go - About 1 hr to fix

                    Method ConnectOptions.getCIDR has 59 lines of code (exceeds 50 allowed). Consider refactoring.
                    Open

                    func (c *ConnectOptions) getCIDR(ctx context.Context, m *dhcp.Manager) (err error) {
                        defer func() {
                            if err == nil {
                                u, err2 := url.Parse(c.config.Host)
                                if err2 != nil {
                    Severity: Minor
                    Found in pkg/handler/connect.go - About 1 hr to fix

                      Method ConnectOptions.DoConnect has 13 return statements (exceeds 4 allowed).
                      Open

                      func (c *ConnectOptions) DoConnect(ctx context.Context, isLite bool) (err error) {
                          c.ctx, c.cancel = context.WithCancel(ctx)
                      
                          log.Info("Starting connect")
                          m := dhcp.NewDHCPManager(c.clientset.CoreV1().ConfigMaps(c.Namespace), c.Namespace)
                      Severity: Major
                      Found in pkg/handler/connect.go - About 1 hr to fix

                        Method ConnectOptions.upgradeDeploy has 13 return statements (exceeds 4 allowed).
                        Open

                        func (c *ConnectOptions) upgradeDeploy(ctx context.Context) error {
                            deploy, err := c.clientset.AppsV1().Deployments(c.Namespace).Get(ctx, config.ConfigMapPodTrafficManager, metav1.GetOptions{})
                            if err != nil {
                                return err
                            }
                        Severity: Major
                        Found in pkg/handler/connect.go - About 1 hr to fix

                          Method ConnectOptions.addExtraRoute has 12 return statements (exceeds 4 allowed).
                          Open

                          func (c *ConnectOptions) addExtraRoute(ctx context.Context, nameserver string) error {
                              if len(c.ExtraRouteInfo.ExtraDomain) == 0 {
                                  return nil
                              }
                          
                          
                          Severity: Major
                          Found in pkg/handler/connect.go - About 1 hr to fix

                            Method ConnectOptions.PreCheckResource has 54 lines of code (exceeds 50 allowed). Consider refactoring.
                            Open

                            func (c *ConnectOptions) PreCheckResource() error {
                                if len(c.Workloads) == 0 {
                                    return nil
                                }
                            
                            
                            Severity: Minor
                            Found in pkg/handler/connect.go - About 1 hr to fix

                              Method ConnectOptions.addRouteDynamic has 10 return statements (exceeds 4 allowed).
                              Open

                              func (c *ConnectOptions) addRouteDynamic(ctx context.Context) error {
                                  tunName, e := c.GetTunDeviceName()
                                  if e != nil {
                                      return e
                                  }
                              Severity: Major
                              Found in pkg/handler/connect.go - About 1 hr to fix

                                Function newer has 8 return statements (exceeds 4 allowed).
                                Open

                                func newer(clientImgStr, serverImgStr string) (bool, error) {
                                    clientImg, err := reference.ParseNormalizedNamed(clientImgStr)
                                    if err != nil {
                                        return false, err
                                    }
                                Severity: Major
                                Found in pkg/handler/connect.go - About 50 mins to fix

                                  Method ConnectOptions.setupDNS has 7 return statements (exceeds 4 allowed).
                                  Open

                                  func (c *ConnectOptions) setupDNS(ctx context.Context) error {
                                      const port = 53
                                      const portTCP = 10800
                                      pod, err := c.GetRunningPodList(ctx)
                                      if err != nil {
                                  Severity: Major
                                  Found in pkg/handler/connect.go - About 45 mins to fix

                                    Method ConnectOptions.portForward has 6 return statements (exceeds 4 allowed).
                                    Open

                                    func (c *ConnectOptions) portForward(ctx context.Context, portPair []string) error {
                                        firstCtx, firstCancelFunc := context.WithCancel(ctx)
                                        defer firstCancelFunc()
                                        var errChan = make(chan error, 1)
                                        go func() {
                                    Severity: Major
                                    Found in pkg/handler/connect.go - About 40 mins to fix

                                      Method ConnectOptions.GetIPFromContext has 6 return statements (exceeds 4 allowed).
                                      Open

                                      func (c *ConnectOptions) GetIPFromContext(ctx context.Context) error {
                                          md, ok := metadata.FromIncomingContext(ctx)
                                          if !ok {
                                              return fmt.Errorf("can not get IOP from context")
                                          }
                                      Severity: Major
                                      Found in pkg/handler/connect.go - About 40 mins to fix

                                        Method ConnectOptions.startLocalTunServe has 6 return statements (exceeds 4 allowed).
                                        Open

                                        func (c *ConnectOptions) startLocalTunServe(ctx context.Context, forwardAddress string, lite bool) (err error) {
                                            log.Debugf("IPv4: %s, IPv6: %s", c.localTunIPv4.IP.String(), c.localTunIPv6.IP.String())
                                        
                                            var cidrList []*net.IPNet
                                            if !lite {
                                        Severity: Major
                                        Found in pkg/handler/connect.go - About 40 mins to fix

                                          Method ConnectOptions.InitClient has 5 return statements (exceeds 4 allowed).
                                          Open

                                          func (c *ConnectOptions) InitClient(f cmdutil.Factory) (err error) {
                                              c.factory = f
                                              if c.config, err = c.factory.ToRESTConfig(); err != nil {
                                                  return
                                              }
                                          Severity: Major
                                          Found in pkg/handler/connect.go - About 35 mins to fix

                                            Method ConnectOptions.PreCheckResource has 5 return statements (exceeds 4 allowed).
                                            Open

                                            func (c *ConnectOptions) PreCheckResource() error {
                                                if len(c.Workloads) == 0 {
                                                    return nil
                                                }
                                            
                                            
                                            Severity: Major
                                            Found in pkg/handler/connect.go - About 35 mins to fix

                                              Method ConnectOptions.getCIDR has 5 return statements (exceeds 4 allowed).
                                              Open

                                              func (c *ConnectOptions) getCIDR(ctx context.Context, m *dhcp.Manager) (err error) {
                                                  defer func() {
                                                      if err == nil {
                                                          u, err2 := url.Parse(c.config.Host)
                                                          if err2 != nil {
                                              Severity: Major
                                              Found in pkg/handler/connect.go - About 35 mins to fix

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

                                                    go func() {
                                                        var listDone bool
                                                        for ctx.Err() == nil {
                                                            err := func() error {
                                                                if !listDone {
                                                Severity: Major
                                                Found in pkg/handler/connect.go and 1 other location - About 2 hrs to fix
                                                pkg/handler/connect.go on lines 461..481

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

                                                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

                                                    go func() {
                                                        var listDone bool
                                                        for ctx.Err() == nil {
                                                            err := func() error {
                                                                if !listDone {
                                                Severity: Major
                                                Found in pkg/handler/connect.go and 1 other location - About 2 hrs to fix
                                                pkg/handler/connect.go on lines 483..503

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

                                                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

                                                                        case *miekgdns.A:
                                                                            if ip := net.ParseIP(a.A.String()); ip != nil && !ip.IsLoopback() {
                                                                                addRouteFunc(domain, a.A.String())
                                                                                c.extraHost = append(c.extraHost, dns.Entry{IP: a.A.String(), Domain: domain})
                                                                                success = true
                                                Severity: Minor
                                                Found in pkg/handler/connect.go and 1 other location - About 55 mins to fix
                                                pkg/handler/connect.go on lines 914..919

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

                                                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

                                                                        case *miekgdns.AAAA:
                                                                            if ip := net.ParseIP(a.AAAA.String()); ip != nil && !ip.IsLoopback() {
                                                                                addRouteFunc(domain, a.AAAA.String())
                                                                                c.extraHost = append(c.extraHost, dns.Entry{IP: a.AAAA.String(), Domain: domain})
                                                                                success = true
                                                Severity: Minor
                                                Found in pkg/handler/connect.go and 1 other location - About 55 mins to fix
                                                pkg/handler/connect.go on lines 908..913

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

                                                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