Skip to content

Commit

Permalink
make admin accounts optional
Browse files Browse the repository at this point in the history
  • Loading branch information
sethetter committed Feb 23, 2025
1 parent 4134ba3 commit 8ed57a0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ type Config struct {
Email *EmailConfig
Twitter *TwitterConfig
SlackHook string `envconfig:"SLACK_HOOK"`
AdminUser string `envconfig:"ADMIN_USER" required:"true"`
AdminPassword string `envconfig:"ADMIN_PASSWORD" require:"true"`
AdminUser string `envconfig:"ADMIN_USER"`
AdminPassword string `envconfig:"ADMIN_PASSWORD"`
}

type EmailConfig struct {
Expand Down
10 changes: 7 additions & 3 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,13 @@ func NewServer(c *ServerConfig) (http.Server, error) {

// Admin routes
admin := router.Group("/admin")
admin.Use(gin.BasicAuth(gin.Accounts{
c.Config.AdminUser: c.Config.AdminPassword,
}))

accounts := gin.Accounts{}
if c.Config.AdminUser != "" {
accounts[c.Config.AdminUser] = c.Config.AdminPassword
}

admin.Use(gin.BasicAuth(accounts))
{
admin.GET("", ctrl.AdminIndex)
admin.GET("/jobs/:id/edit", ctrl.EditJob)
Expand Down

0 comments on commit 8ed57a0

Please sign in to comment.