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: add default token #29

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions auth/gitee.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
var (
clientId string
clientSecret string
defaultToken string
)

var (
Expand Down Expand Up @@ -64,6 +65,13 @@ func Init(cfg *config.Config) error {
return errors.New("client secret required")
}
}
defaultToken = cfg.DefaultToken
if defaultToken == "" {
defaultToken = os.Getenv("DEFAULT_TOKEN")
if defaultToken == "" {
return errors.New("default token required")
}
}

return nil
}
Expand Down Expand Up @@ -96,6 +104,8 @@ func CheckRepoOwner(userInRepo UserInRepo) error {
)
if userInRepo.Token != "" {
path += fmt.Sprintf("?access_token=%s", userInRepo.Token)
} else {
path += fmt.Sprintf("?access_token=%s", defaultToken)
}
headers := http.Header{"Content-Type": []string{"application/json;charset=UTF-8"}}
repo := new(Repo)
Expand Down Expand Up @@ -154,6 +164,8 @@ func verifyUser(userInRepo UserInRepo) error {
)
if userInRepo.Token != "" {
path += fmt.Sprintf("?access_token=%s", userInRepo.Token)
} else {
path += fmt.Sprintf("?access_token=%s", defaultToken)
}
headers := http.Header{"Content-Type": []string{"application/json;charset=UTF-8"}}
giteeUser := new(giteeUser)
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Config struct {
ObsAccessKeyId string `json:"OBS_ACCESS_KEY_ID"`
ObsSecretAccessKey string `json:"OBS_SECRET_ACCESS_KEY"`
ValidateConfig ValidateConfig `json:"VALIDATE_REGEXP"`
DefaultToken string `json:"DEFAULT_TOKEN"`
}

type ValidateConfig struct {
Expand Down
Loading