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

chore: fix variable names and enhance ENV example guide #1313

Merged
merged 4 commits into from
Aug 31, 2023
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
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ ENV DB_DATABASE cb_tumblebug
ENV DB_USER cb_tumblebug
ENV DB_PASSWORD cb_tumblebug

# API Setting
# ALLOW_ORIGINS (ex: https://cloud-barista.org,xxx.xxx.xxx.xxx or * for all)
ENV ALLOW_ORIGINS *
ENV API_USERNAME default
ENV API_PASSWORD default

Expand Down
2 changes: 1 addition & 1 deletion conf/setup.env
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export DB_USER=cb_tumblebug
export DB_PASSWORD=cb_tumblebug

# API Setting
# ALLOW_ORIGINS (ex: https://cloud-barista.org,xxx.xxx.xxx.xxx,*)
# ALLOW_ORIGINS (ex: https://cloud-barista.org,xxx.xxx.xxx.xxx or * for all)
export ALLOW_ORIGINS=*
export API_USERNAME=default
export API_PASSWORD=default
Expand Down
10 changes: 5 additions & 5 deletions src/api/rest/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ func RunServer(port string) {
AllowMethods: []string{http.MethodGet, http.MethodPut, http.MethodPost, http.MethodDelete},
}))

API_USERNAME := os.Getenv("API_USERNAME")
API_PASSWORD := os.Getenv("API_PASSWORD")
apiUser := os.Getenv("API_USERNAME")
apiPass := os.Getenv("API_PASSWORD")

e.Use(middleware.BasicAuth(func(username, password string, c echo.Context) (bool, error) {
// Be careful to use constant time comparison to prevent timing attacks
if subtle.ConstantTimeCompare([]byte(username), []byte(API_USERNAME)) == 1 &&
subtle.ConstantTimeCompare([]byte(password), []byte(API_PASSWORD)) == 1 {
if subtle.ConstantTimeCompare([]byte(username), []byte(apiUser)) == 1 &&
subtle.ConstantTimeCompare([]byte(password), []byte(apiPass)) == 1 {
return true, nil
}
return false, nil
Expand Down Expand Up @@ -356,7 +356,7 @@ func RunServer(port string) {
selfEndpoint := os.Getenv("SELF_ENDPOINT")
apidashboard := " http://" + selfEndpoint + "/tumblebug/swagger/index.html"

fmt.Println(" Access to API dashboard" + " (username: " + API_USERNAME + " / password: " + API_PASSWORD + ")")
fmt.Println(" Access to API dashboard" + " (username: " + apiUser + " / password: " + apiPass + ")")
fmt.Printf(noticeColor, apidashboard)
fmt.Println("\n ")

Expand Down