rancher/opni-monitoring

View on GitHub

Showing 95 of 150 total issues

Method Server.handleAuthorizeRequest has 52 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (s *Server) handleAuthorizeRequest(w http.ResponseWriter, r *http.Request) {
    lg := s.Logger.With(
        "remote_addr", r.RemoteAddr,
        "request", r.RequestURI,
    )
Severity: Minor
Found in pkg/noauth/openid.go - About 1 hr to fix

    Function BuildBootstrapCmd has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
    Open

    func BuildBootstrapCmd() *cobra.Command {
        lg := logger.New()
    
        var namespace, kubeconfig, gatewayAddress, token string
        var pins []string
    Severity: Minor
    Found in pkg/opnim/commands/bootstrap.go - About 55 mins 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 New has 9 return statements (exceeds 4 allowed).
    Open

    func New(ctx context.Context, conf *v1beta1.AgentConfig, opts ...AgentOption) (*Agent, error) {
        lg := logger.New().Named("agent")
        options := AgentOptions{}
        options.Apply(opts...)
    
    
    Severity: Major
    Found in pkg/agent/agent.go - About 55 mins to fix

      Function extractOptions has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
      Open

      func extractOptions(options ...string) ([]OptionSpec, []string, error) {
          var optionSpecs []OptionSpec
          var remaining []string
          for _, option := range options {
              if option != "" && option[0] == '+' {
      Severity: Minor
      Found in pkg/capabilities/template.go - About 55 mins 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 BuildClustersLabelCmd has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
      Open

      func BuildClustersLabelCmd() *cobra.Command {
          overwrite := false
          cmd := &cobra.Command{
              Use:   "label [--overwrite] <cluster-id> <label>=<value> [<label>=<value>...]",
              Short: "Add labels to a cluster",
      Severity: Minor
      Found in pkg/opnim/commands/clusters.go - About 55 mins 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 DecodeAuthHeader has 9 return statements (exceeds 4 allowed).
      Open

      func DecodeAuthHeader(header string) (id []byte, nonce uuid.UUID, mac []byte, err error) {
          if !strings.HasPrefix(header, "MAC ") {
              return nil, uuid.Nil, nil, errors.New("incorrect authorization type")
          }
          trimmed := strings.TrimSpace(strings.TrimPrefix(header, "MAC"))
      Severity: Major
      Found in pkg/b2mac/header.go - About 55 mins to fix

        Function fetchWellKnownConfig has 9 return statements (exceeds 4 allowed).
        Open

        func fetchWellKnownConfig(dc *DiscoverySpec) (*WellKnownConfiguration, error) {
            client := http.Client{
                // Do not redirect when fetching the openid configuration.
                // The issuer URL must be the exact URL at which the discovery
                // endpoint is located. The only valid status code is 200.
        Severity: Major
        Found in pkg/auth/openid/discovery.go - About 55 mins to fix

          Method Reconciler.Reconcile has 9 return statements (exceeds 4 allowed).
          Open

          func (r *Reconciler) Reconcile() (*reconcile.Result, error) {
              allResources := []resources.Resource{}
              configMap, err := r.configMap()
              if err != nil {
                  return nil, err
          Severity: Major
          Found in pkg/sdk/resources/gateway/gateway.go - About 55 mins to fix

            Method OpenidMiddleware.Handle has 8 return statements (exceeds 4 allowed).
            Open

            func (m *OpenidMiddleware) Handle(c *fiber.Ctx) error {
                m.lock.Lock()
                if m.wellKnownConfig == nil {
                    c.Status(http.StatusServiceUnavailable)
                    m.lock.Unlock()
            Severity: Major
            Found in pkg/auth/openid/openid.go - About 50 mins to fix

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

              func NewGatewayHTTPClient(
                  address string,
                  ip ident.Provider,
                  kr keyring.Keyring,
              ) (GatewayHTTPClient, error) {
              Severity: Major
              Found in pkg/clients/gateway_client.go - About 50 mins to fix

                Method Reconciler.optionalContainerPorts has 8 return statements (exceeds 4 allowed).
                Open

                func (r *Reconciler) optionalContainerPorts() ([]corev1.ContainerPort, error) {
                    lg := r.logger
                    var ports []corev1.ContainerPort
                    if addr := r.gateway.Spec.Management.GRPCListenAddress; strings.HasPrefix(addr, "tcp://") {
                        parts := strings.Split(addr, ":")
                Severity: Major
                Found in pkg/sdk/resources/gateway/ports.go - About 50 mins to fix

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

                  func labelSelectorMatches(selector *core.LabelSelector, labels map[string]string) bool {
                      for key, value := range selector.MatchLabels {
                          if labels[key] != value {
                              return false
                          }
                  Severity: Major
                  Found in pkg/storage/selection.go - About 50 mins to fix

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

                    func ControllerGen() error {
                        cmd := exec.Command(mg.GoCmd(), "run", "sigs.k8s.io/controller-tools/cmd/controller-gen",
                            "crd:maxDescLen=0", "object", "paths=./pkg/sdk/api/...", "output:crd:artifacts:config=pkg/sdk/crd",
                        )
                        buf := new(bytes.Buffer)
                    Severity: Major
                    Found in magefile.go - About 50 mins to fix

                      Method WebUIServer.ListenAndServe has 7 return statements (exceeds 4 allowed).
                      Open

                      func (ws *WebUIServer) ListenAndServe() error {
                          ws.mu.Lock()
                          defer ws.mu.Unlock()
                          lg := ws.logger
                          listener, err := net.Listen("tcp4", ws.config.Spec.Management.WebListenAddress)
                      Severity: Major
                      Found in pkg/webui/webui.go - About 45 mins to fix

                        Function LoadServingCertBundle has 7 return statements (exceeds 4 allowed).
                        Open

                        func LoadServingCertBundle(certsSpec v1beta1.CertsSpec) (*tls.Certificate, *x509.CertPool, error) {
                            var caCertData, servingCertData, servingKeyData []byte
                            switch {
                            case certsSpec.CACert != nil:
                                data, err := os.ReadFile(*certsSpec.CACert)
                        Severity: Major
                        Found in pkg/util/certs.go - About 45 mins to fix

                          Avoid deeply nested control flow statements.
                          Open

                                                      goto RETRY
                          Severity: Major
                          Found in pkg/agent/rules.go - About 45 mins to fix

                            Method ClientConfig.bootstrapJoin has 7 return statements (exceeds 4 allowed).
                            Open

                            func (c *ClientConfig) bootstrapJoin() (*BootstrapJoinResponse, *x509.Certificate, error) {
                                url, err := c.bootstrapJoinURL()
                                if err != nil {
                                    return nil, nil, err
                                }
                            Severity: Major
                            Found in pkg/bootstrap/client.go - About 45 mins to fix

                              Method Plugin.Install has 7 return statements (exceeds 4 allowed).
                              Open

                              func (p *Plugin) Install(cluster *core.Reference) error {
                                  labels := map[string]string{
                                      resources.OpniClusterID: cluster.Id,
                                  }
                                  loggingClusterList := &opniv1beta2.LoggingClusterList{}
                              Severity: Major
                              Found in plugins/logging/pkg/logging/capability.go - About 45 mins to fix

                                Avoid deeply nested control flow statements.
                                Open

                                                            goto RETRY
                                Severity: Major
                                Found in pkg/agent/rules.go - About 45 mins to fix

                                  Method ObjectList.Visit has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
                                  Open

                                  func (l ObjectList) Visit(visitors ...ObjectVisitorFunc) {
                                      // For each object in the list, call each visitor if its argument type
                                      // matches the concrete type of the object.
                                      for _, vf := range visitors {
                                          // get the type of the first arg
                                  Severity: Minor
                                  Found in pkg/config/meta/meta.go - About 45 mins 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

                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language