Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add read only token support #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions deb-drop.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Config struct {
type Token struct {
Value string
Owner string
ReadOnly bool
Repo []Repo
}

Expand Down Expand Up @@ -102,7 +103,7 @@ func mainHandler(w http.ResponseWriter, r *http.Request, config *Config, lg *log
return
}

err = validateToken(lg, config, r.FormValue("token"), repos)
err = validateToken(lg, config, r.FormValue("token"), repos, r.Method)
if err != nil {
w.WriteHeader(http.StatusForbidden)
lg.Println(err)
Expand Down Expand Up @@ -255,7 +256,7 @@ func mainHandler(w http.ResponseWriter, r *http.Request, config *Config, lg *log
}
}

func validateToken(lg *log.Logger, config *Config, token string, repos []string) error {
func validateToken(lg *log.Logger, config *Config, token string, repos []string, method string) error {
Copy link

@Felixoid Felixoid Jan 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, pass here Request r, and not its attributes like method and token?

// Going over all tokens in configuration to find requested
if token == "" {
lg.Printf("Attempt to access %s without token", repos)
Expand All @@ -280,6 +281,10 @@ func validateToken(lg *log.Logger, config *Config, token string, repos []string)
return fmt.Errorf("%s", "Token is not allowed to use on one or more of the specified repos")
}
}
if configToken.ReadOnly == true && method != "GET" {
lg.Println("Use of read only token for non-read http method " + method)
return fmt.Errorf("%s", "Use of read only token for non-read http method " + method)
}
return nil
}
}
Expand Down