Skip to content

Commit 0bb0370

Browse files
committed
feat: native support for basicauth
Signed-off-by: Matthias Riegler <[email protected]>
1 parent 75f16d4 commit 0bb0370

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

internal/config/server/latest/server_schema.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
package latest
22

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+
312
// ServerConfig represents the current server configuration file.
413
type ServerConfig struct {
514
Repositories []*GithubRepositoryConfig `yaml:"repositories,omitempty"`
15+
AuthConfig *AuthConfig `yaml:"auth,omitempty"`
616
}
717

818
// GithubRepositoryConfig defines how a repository should be handled
@@ -13,6 +23,6 @@ type GithubRepositoryConfig struct {
1323
StabilizeDuration int `yaml:"stabilize_duration_seconds"`
1424
TTL int `yaml:"ttl_seconds"`
1525
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.
1727
DelayLeaseAssignmentBy int `yaml:"delay_lease_assignment_by"`
1828
}

internal/server/server.go

+9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/ankorstore/mq-lease-service/internal/storage"
1717
"github.com/ankorstore/mq-lease-service/internal/version"
1818
"github.com/gofiber/fiber/v2"
19+
fiberbasicauth "github.com/gofiber/fiber/v2/middleware/basicauth"
1920
fiberrecover "github.com/gofiber/fiber/v2/middleware/recover"
2021
"github.com/prometheus/client_golang/prometheus"
2122
"github.com/rs/zerolog"
@@ -141,6 +142,14 @@ func (s *serverImpl) Init() error {
141142
},
142143
}))
143144

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+
144153
// register k8s probes handlers
145154
RegisterK8sProbesRoutes(s.app, s.storage)
146155
// register API routes on the fiber app

0 commit comments

Comments
 (0)