Skip to content

Commit

Permalink
Add authentication using AuthKey (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertjndw authored Jan 30, 2024
1 parent d003429 commit 6879a17
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions HadesAPI/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var AsynqClient *asynq.Client
type HadesAPIConfig struct {
APIPort uint `env:"API_PORT,notEmpty" envDefault:"8080"`
RedisConfig utils.RedisConfig
AuthKey string `env:"AUTH_KEY"`
}

func main() {
Expand All @@ -37,6 +38,14 @@ func main() {
gin.SetMode(gin.ReleaseMode)

r := gin.Default()
if cfg.AuthKey == "" {
log.Warn("No auth key set")
} else {
log.Info("Auth key set")
r.Use(gin.BasicAuth(gin.Accounts{
"hades": cfg.AuthKey,
}))
}
r.GET("/ping", ping)
r.POST("/build", AddBuildToQueue)

Expand Down

0 comments on commit 6879a17

Please sign in to comment.