File tree 2 files changed +20
-1
lines changed
2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change 1
1
package latest
2
2
3
+ // BasicAuthConfig represents the configuration for basic auth.
4
+ type BasicAuthConfig struct {
5
+ Users map [string ]string `yaml:"users"`
6
+ }
7
+
8
+ type AuthConfig struct {
9
+ BasicAuth * BasicAuthConfig `yaml:"basic,omitempty"`
10
+ }
11
+
3
12
// ServerConfig represents the current server configuration file.
4
13
type ServerConfig struct {
5
14
Repositories []* GithubRepositoryConfig `yaml:"repositories,omitempty"`
15
+ AuthConfig * AuthConfig `yaml:"auth,omitempty"`
6
16
}
7
17
8
18
// GithubRepositoryConfig defines how a repository should be handled
@@ -13,6 +23,6 @@ type GithubRepositoryConfig struct {
13
23
StabilizeDuration int `yaml:"stabilize_duration_seconds"`
14
24
TTL int `yaml:"ttl_seconds"`
15
25
ExpectedRequestCount int `yaml:"expected_request_count"`
16
- // DelayLEaseASsignmentBy is the number of times a lease can be delayed before it is assigned.
26
+ // DelayLeaseASsignmentBy is the number of times a lease can be delayed before it is assigned.
17
27
DelayLeaseAssignmentBy int `yaml:"delay_lease_assignment_by"`
18
28
}
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import (
16
16
"github.com/ankorstore/mq-lease-service/internal/storage"
17
17
"github.com/ankorstore/mq-lease-service/internal/version"
18
18
"github.com/gofiber/fiber/v2"
19
+ fiberbasicauth "github.com/gofiber/fiber/v2/middleware/basicauth"
19
20
fiberrecover "github.com/gofiber/fiber/v2/middleware/recover"
20
21
"github.com/prometheus/client_golang/prometheus"
21
22
"github.com/rs/zerolog"
@@ -141,6 +142,14 @@ func (s *serverImpl) Init() error {
141
142
},
142
143
}))
143
144
145
+ // Configure basic auth if needed
146
+ if cfg .AuthConfig != nil && cfg .AuthConfig .BasicAuth != nil {
147
+ log .Ctx (s .ctx ).Info ().Msg ("Basic auth enabled" )
148
+ s .app .Use (fiberbasicauth .New (fiberbasicauth.Config {
149
+ Users : cfg .AuthConfig .BasicAuth .Users ,
150
+ }))
151
+ }
152
+
144
153
// register k8s probes handlers
145
154
RegisterK8sProbesRoutes (s .app , s .storage )
146
155
// register API routes on the fiber app
You can’t perform that action at this time.
0 commit comments