rancher/opni-monitoring

View on GitHub

Showing 150 of 150 total issues

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

func (e *EtcdStore) DeleteRole(ctx context.Context, ref *core.Reference) error {
    ctx, ca := context.WithTimeout(ctx, e.CommandTimeout)
    defer ca()
    resp, err := e.Client.Delete(ctx, path.Join(e.Prefix, roleKey, ref.Id))
    if err != nil {
Severity: Major
Found in pkg/storage/etcd/rbac_store.go and 1 other location - About 1 hr to fix
pkg/storage/etcd/rbac_store.go on lines 72..83

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

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

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

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

            func BuildTokensListCmd() *cobra.Command {
                return &cobra.Command{
                    Use:   "list",
                    Short: "List bootstrap tokens",
                    Run: func(cmd *cobra.Command, args []string) {
            Severity: Major
            Found in pkg/opnim/commands/tokens.go and 2 other locations - About 1 hr to fix
            pkg/opnim/commands/rbac.go on lines 118..130
            pkg/opnim/commands/rbac.go on lines 194..206

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

            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

            func BuildRoleBindingsListCmd() *cobra.Command {
                return &cobra.Command{
                    Use:   "list",
                    Short: "List role bindings",
                    Run: func(cmd *cobra.Command, args []string) {
            Severity: Major
            Found in pkg/opnim/commands/rbac.go and 2 other locations - About 1 hr to fix
            pkg/opnim/commands/rbac.go on lines 118..130
            pkg/opnim/commands/tokens.go on lines 79..91

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

            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

            func BuildRolesListCmd() *cobra.Command {
                return &cobra.Command{
                    Use:   "list",
                    Short: "List roles",
                    Run: func(cmd *cobra.Command, args []string) {
            Severity: Major
            Found in pkg/opnim/commands/rbac.go and 2 other locations - About 1 hr to fix
            pkg/opnim/commands/rbac.go on lines 194..206
            pkg/opnim/commands/tokens.go on lines 79..91

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

            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

            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

                            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
                              Severity
                              Category
                              Status
                              Source
                              Language