Skip to content

Commit a6231eb

Browse files
committed
Basic Authentication added
1 parent d80912d commit a6231eb

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ bind9:
44
default_ttl: 3600
55
server:
66
port: "8053"
7+
api_access:
8+
- username: "ehm"
9+
password: "f9ba61a1-a501-4e11-958b-d6b5cbf01c3f"
10+
- username: "anotheruser"
11+
password: "aNother-secure-password"

config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ type Config struct {
1313
Server struct {
1414
Port string `mapstructure:"port"`
1515
} `mapstructure:"server"`
16+
ApiAccess []struct {
17+
Username string `mapstructure:"username"`
18+
Password string `mapstructure:"password"`
19+
} `mapstructure:"api_access"`
1620
}
1721

1822
func LoadConfig(path string) (*Config, error) {

main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ func main() {
1919
// Initialize Gin
2020
r := gin.Default()
2121

22+
// Authentication
23+
accounts := gin.Accounts{}
24+
for _, user := range cfg.ApiAccess {
25+
accounts[user.Username] = user.Password
26+
}
27+
r.Use(gin.BasicAuth(accounts))
28+
2229
// Initialize controller
2330
dnsController := controllers.NewDNSController(cfg)
2431

0 commit comments

Comments
 (0)