rancher/opni-monitoring

View on GitHub

Showing 95 of 150 total issues

Method Agent.streamRulesToGateway has 63 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (a *Agent) streamRulesToGateway(ctx context.Context) error {
    lg := a.logger
    updateC, err := a.streamRuleGroupUpdates(ctx)
    if err != nil {
        a.logger.With(
Severity: Minor
Found in pkg/agent/rules.go - About 1 hr to fix

    Method ServerConfig.handleBootstrapAuth has a Cognitive Complexity of 27 (exceeds 20 allowed). Consider refactoring.
    Open

    func (h ServerConfig) handleBootstrapAuth(c *fiber.Ctx) error {
        lg := c.Context().Logger()
        authHeader := strings.TrimSpace(c.Get("Authorization"))
        if strings.TrimSpace(authHeader) == "" {
            return c.SendStatus(fiber.StatusUnauthorized)
    Severity: Minor
    Found in pkg/bootstrap/server.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 PrometheusRuleFinder.findRulesInNamespace has a Cognitive Complexity of 27 (exceeds 20 allowed). Consider refactoring.
    Open

    func (f *PrometheusRuleFinder) findRulesInNamespace(
        ctx context.Context,
        namespace string,
    ) ([]rulefmt.RuleGroup, error) {
        lg := f.logger
    Severity: Minor
    Found in pkg/rules/prometheusrule.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

    Function BuildAgentCmd has a Cognitive Complexity of 27 (exceeds 20 allowed). Consider refactoring.
    Open

    func BuildAgentCmd() *cobra.Command {
        lg := logger.New()
        var configLocation string
    
        agentCmd := &cobra.Command{
    Severity: Minor
    Found in pkg/opnim/commands/agent.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 ServerConfig.handleBootstrapAuth has 15 return statements (exceeds 4 allowed).
    Open

    func (h ServerConfig) handleBootstrapAuth(c *fiber.Ctx) error {
        lg := c.Context().Logger()
        authHeader := strings.TrimSpace(c.Get("Authorization"))
        if strings.TrimSpace(authHeader) == "" {
            return c.SendStatus(fiber.StatusUnauthorized)
    Severity: Major
    Found in pkg/bootstrap/server.go - About 1 hr to fix

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

      func To(addr string, opts ...ForwarderOption) func(*fiber.Ctx) error {
          defaultLogger := logger.New(
              logger.WithSampling(&zap.SamplingConfig{
                  Initial:    1,
                  Thereafter: 0,
      Severity: Minor
      Found in pkg/util/fwd/forwarder.go - About 1 hr to fix

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

          Method PrometheusRuleFinder.findRulesInNamespace has 58 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (f *PrometheusRuleFinder) findRulesInNamespace(
              ctx context.Context,
              namespace string,
          ) ([]rulefmt.RuleGroup, error) {
              lg := f.logger
          Severity: Minor
          Found in pkg/rules/prometheusrule.go - About 1 hr to fix

            Function ControllerGen has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring.
            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: Minor
            Found in magefile.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 rbacProvider.SubjectAccess has 56 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func (p *rbacProvider) SubjectAccess(
                ctx context.Context,
                req *core.SubjectAccessRequest,
            ) (*core.ReferenceList, error) {
                // Look up all role bindings which exist for this user, then look up the roles
            Severity: Minor
            Found in pkg/storage/rbac_provider.go - About 1 hr to fix

              Function LoadServingCertBundle has 56 lines of code (exceeds 50 allowed). Consider refactoring.
              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: Minor
              Found in pkg/util/certs.go - About 1 hr to fix

                Function newHandler has 54 lines of code (exceeds 50 allowed). Consider refactoring.
                Open

                func newHandler(
                    stub grpcdynamic.Stub,
                    svcDesc *desc.ServiceDescriptor,
                    mux *runtime.ServeMux,
                    rule *HTTPRuleDescriptor,
                Severity: Minor
                Found in pkg/management/extensions.go - About 1 hr to fix

                  Function DecodeAuthHeader has 54 lines of code (exceeds 50 allowed). Consider refactoring.
                  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: Minor
                  Found in pkg/b2mac/header.go - About 1 hr to fix

                    Function BuildAccessMatrixCmd has 54 lines of code (exceeds 50 allowed). Consider refactoring.
                    Open

                    func BuildAccessMatrixCmd() *cobra.Command {
                        cmd := &cobra.Command{
                            Use:   "access-matrix",
                            Short: "Print an access matrix showing all users and their allowed clusters",
                            Run: func(cmd *cobra.Command, args []string) {
                    Severity: Minor
                    Found in pkg/opnim/commands/rbac.go - About 1 hr to fix

                      Method Server.handleUserInfoRequest has 53 lines of code (exceeds 50 allowed). Consider refactoring.
                      Open

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

                        Function RenderAccessMatrix has 53 lines of code (exceeds 50 allowed). Consider refactoring.
                        Open

                        func RenderAccessMatrix(am AccessMatrix) string {
                            w := table.NewWriter()
                            w.SetStyle(table.StyleColoredDark)
                            w.Style().Format = table.FormatOptions{
                                Footer: text.FormatUpper,
                        Severity: Minor
                        Found in pkg/opnim/util/render.go - About 1 hr to fix

                          Method Plugin.Install has 53 lines of code (exceeds 50 allowed). Consider refactoring.
                          Open

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

                            Function BuildAccessMatrixCmd has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring.
                            Open

                            func BuildAccessMatrixCmd() *cobra.Command {
                                cmd := &cobra.Command{
                                    Use:   "access-matrix",
                                    Short: "Print an access matrix showing all users and their allowed clusters",
                                    Run: func(cmd *cobra.Command, args []string) {
                            Severity: Minor
                            Found in pkg/opnim/commands/rbac.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 ClientConfig.Bootstrap has 11 return statements (exceeds 4 allowed).
                            Open

                            func (c *ClientConfig) Bootstrap(
                                ctx context.Context,
                                ident ident.Provider,
                            ) (keyring.Keyring, error) {
                                if c.Token == nil {
                            Severity: Major
                            Found in pkg/bootstrap/client.go - About 1 hr to fix

                              Method OpenidMiddleware.Handle has 52 lines of code (exceeds 50 allowed). Consider refactoring.
                              Open

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