Skip to content

Commit

Permalink
Add option to skip BasicAuth
Browse files Browse the repository at this point in the history
  • Loading branch information
yunkon-kim committed Nov 15, 2023
1 parent 5086116 commit d02214a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ ENV DB_PASSWORD cb_tumblebug
# API Setting
# ALLOW_ORIGINS (ex: https://cloud-barista.org,xxx.xxx.xxx.xxx or * for all)
ENV ALLOW_ORIGINS *
## Set SKIP_BASIC_AUTH=true to skip basic auth for all routes (i.e., url or path)
ENV SKIP_BASIC_AUTH false
ENV API_USERNAME default
ENV API_PASSWORD default

Expand Down
2 changes: 2 additions & 0 deletions conf/setup.env
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export API_USERNAME=default
export API_PASSWORD=default
## ALLOW_ORIGINS (ex: https://cloud-barista.org,http://localhost:8080 or * for all)
export ALLOW_ORIGINS=*
## Set SKIP_BASIC_AUTH=true to skip basic auth for all routes (i.e., url or path)
export SKIP_BASIC_AUTH=false
## Set SELF_ENDPOINT, to access Swagger API dashboard outside (Ex: export SELF_ENDPOINT=x.x.x.x:1323)
export SELF_ENDPOINT=localhost:1323

Expand Down
6 changes: 4 additions & 2 deletions src/api/rest/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"context"
"log"
"os/signal"
"strings"
"sync"
"syscall"
"time"
Expand Down Expand Up @@ -107,12 +106,15 @@ func RunServer(port string) {
AllowMethods: []string{http.MethodGet, http.MethodPut, http.MethodPost, http.MethodDelete},
}))

// Conditions to prevent abnormal operation due to typos (e.g., ture, falss, etc.)
skipBasicAuthOption := os.Getenv("SKIP_BASIC_AUTH") == "true"

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

e.Use(middleware.BasicAuthWithConfig(middleware.BasicAuthConfig{
Skipper: func(c echo.Context) bool {
if strings.HasPrefix(c.Request().Host, "localhost") ||
if skipBasicAuthOption ||
c.Path() == "/tumblebug/health" ||
c.Path() == "/tumblebug/httpVersion" {
// c.Path() == "/tumblebug/swagger/*" {
Expand Down

0 comments on commit d02214a

Please sign in to comment.