Skip to content

Commit

Permalink
Make basic auth configurable
Browse files Browse the repository at this point in the history
Signed-off-by: Christos Papageorgiou <[email protected]>
  • Loading branch information
root-expert authored and dhollinger committed Nov 23, 2021
1 parent 40d745b commit 36aa114
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,22 @@ func NewRouter() *gin.Engine {
router := gin.New()
router.Use(gin.Logger())
router.Use(gin.Recovery())
user := users.Users{
User: config.GetConfig().Server.User,
Password: config.GetConfig().Server.Password,

var apiHandlerFuncs []gin.HandlerFunc
if config.GetConfig().Server.Protected {
user := users.Users{
User: config.GetConfig().Server.User,
Password: config.GetConfig().Server.Password,
}

apiHandlerFuncs = append(apiHandlerFuncs, gin.BasicAuth(gin.Accounts{user.User: user.Password}))
}

health := new(wapi.HealthController)

router.GET("/health", health.Status)

api := router.Group("api", gin.BasicAuth(gin.Accounts{user.User: user.Password}))
api := router.Group("api", apiHandlerFuncs...)
{
v1 := api.Group("v1")
{
Expand Down

0 comments on commit 36aa114

Please sign in to comment.