pstuifzand/ekster

View on GitHub
cmd/eksterd/http.go

Summary

Maintainability
F
6 days
Test Coverage

Method mainHandler.ServeHTTP has a Cognitive Complexity of 159 (exceeds 20 allowed). Consider refactoring.
Open

func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
    conn := h.pool.Get()
    defer conn.Close()

    err := r.ParseForm()
Severity: Minor
Found in cmd/eksterd/http.go - About 2 days 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 mainHandler.ServeHTTP has 350 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
    conn := h.pool.Get()
    defer conn.Close()

    err := r.ParseForm()
Severity: Major
Found in cmd/eksterd/http.go - About 1 day to fix

File http.go has 639 lines of code (exceeds 500 allowed). Consider refactoring.
Open

package main

import (
    "embed"
    "encoding/json"
Severity: Minor
Found in cmd/eksterd/http.go - About 5 hrs to fix

Method mainHandler.ServeHTTP has 40 return statements (exceeds 4 allowed).
Open

func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
    conn := h.pool.Get()
    defer conn.Close()

    err := r.ParseForm()
Severity: Major
Found in cmd/eksterd/http.go - About 3 hrs to fix

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

func verifyAuthCode(code, redirectURI, authEndpoint, clientID string) (bool, *authResponse, error) {
    reqData := url.Values{}
    reqData.Set("code", code)
    reqData.Set("client_id", clientID)
    reqData.Set("redirect_uri", redirectURI)
Severity: Major
Found in cmd/eksterd/http.go - About 55 mins to fix

Avoid deeply nested control flow statements.
Open

            if err != nil {
                fmt.Fprintf(w, "ERROR: %s\n", err)
            }
Severity: Major
Found in cmd/eksterd/http.go - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

            if err == http.ErrNoCookie {
                http.Redirect(w, r, "/", 302)
                return
            }
Severity: Major
Found in cmd/eksterd/http.go - About 45 mins to fix

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

func getEndpoints(me string) (parsedEndpoints, error) {
    endpoints := parsedEndpoints{}

    meURL, err := url.Parse(me)
    if err != nil {
Severity: Major
Found in cmd/eksterd/http.go - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

            if !isLoggedIn(h.Backend, &sess) {
                w.WriteHeader(401)
                fmt.Fprintf(w, "Unauthorized")
                return
            }
Severity: Major
Found in cmd/eksterd/http.go - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

            } else if err != nil {
                http.Error(w, "could not read cookie", 500)
                return
            }
Severity: Major
Found in cmd/eksterd/http.go - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

                if sess.NextURI != "" {
                    http.Redirect(w, r, sess.NextURI, 302)
                } else {
                    http.Redirect(w, r, "/", 302)
                }
Severity: Major
Found in cmd/eksterd/http.go - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

        } else if r.URL.Path == "/logs" {
            c, err := r.Cookie("session")
            if err == http.ErrNoCookie {
                http.Redirect(w, r, "/", 302)
                return
Severity: Major
Found in cmd/eksterd/http.go - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

                if v.UID == currentChannel {
                    page.CurrentChannel = v
                    if setting, e := h.Backend.Settings[v.UID]; e {
                        page.CurrentSetting = setting
                    } else {
Severity: Major
Found in cmd/eksterd/http.go - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

        } else if r.URL.Path == "/auth/approve" {
            // create a code
            code := util.RandStringBytes(32)
            state := r.FormValue("state")
            channel := r.FormValue("channel")
Severity: Major
Found in cmd/eksterd/http.go - About 45 mins to fix

TODO found
Open

            // responseType := query.Get("response_type") // TODO: check response_type
Severity: Minor
Found in cmd/eksterd/http.go by fixme

TODO found
Open

            // TODO: if not logged in, make sure we get back here
Severity: Minor
Found in cmd/eksterd/http.go by fixme

There are no issues that match your filters.

Category
Status