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(
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)
- Read upRead up
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
- Read upRead up
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{
- Read upRead up
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)
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,
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",
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
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)
- Read upRead up
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
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)
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,
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"))
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) {
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,
)
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,
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{}
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) {
- Read upRead up
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 {
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()