Authelia users sync
This commit is contained in:
parent
9e1b06a448
commit
6654463aee
5 changed files with 252 additions and 6 deletions
74
helpers/authelia/database.go
Normal file
74
helpers/authelia/database.go
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
package authelia
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"git.readonly.ch/bouzoure/pop-camarades/helpers"
|
||||
"go.yaml.in/yaml/v4"
|
||||
)
|
||||
|
||||
type AutheliaUser struct {
|
||||
Password string `yaml:"password"`
|
||||
DisplayName string `yaml:"displayname"`
|
||||
Email string `yaml:"email"`
|
||||
Groups []string `yaml:"groups"`
|
||||
GivenName string `yaml:"given_name"`
|
||||
MiddleName string `yaml:"middle_name"`
|
||||
FamilyName string `yaml:"family_name"`
|
||||
Nickname string `yaml:"nickname"`
|
||||
Gender string `yaml:"gender"`
|
||||
Birthdate string `yaml:"birthdate"`
|
||||
Website string `yaml:"website"`
|
||||
Profile string `yaml:"profile"`
|
||||
Picture string `yaml:"picture"`
|
||||
ZoneInfo string `yaml:"zoneinfo"`
|
||||
Locale string `yaml:"locale"`
|
||||
PhoneNumber string `yaml:"phone_number"`
|
||||
PhoneExtension string `yaml:"phone_extension"`
|
||||
Disabled bool `yaml:"disabled"`
|
||||
Address any `yaml:"address"`
|
||||
Extra map[string]any `yaml:"extra"`
|
||||
}
|
||||
|
||||
type AutheliaUsers struct {
|
||||
Users map[string]AutheliaUser `yaml:"users"`
|
||||
}
|
||||
|
||||
func ReadDatabase() (AutheliaUsers, error) {
|
||||
var users AutheliaUsers
|
||||
|
||||
// Get config
|
||||
config, err := helpers.GetConfig()
|
||||
if err != nil {
|
||||
return users, err
|
||||
}
|
||||
|
||||
// Read YAML file
|
||||
filePath := config.Authelia.UsersLocation
|
||||
fileContent, err := os.ReadFile(filePath)
|
||||
if err != nil {
|
||||
return users, err
|
||||
}
|
||||
|
||||
// Unmarshal YAML
|
||||
err = yaml.Unmarshal(fileContent, &users)
|
||||
|
||||
return users, err
|
||||
}
|
||||
|
||||
func WriteDatabase(users AutheliaUsers) error {
|
||||
// Get config
|
||||
config, err := helpers.GetConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Marshal YAML
|
||||
yamlData, err := yaml.Marshal(users)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
filePath := config.Authelia.UsersLocation
|
||||
return os.WriteFile(filePath, yamlData, 0644)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue