49 lines
886 B
Go
49 lines
886 B
Go
|
package config
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
|
||
|
"github.com/davecgh/go-spew/spew"
|
||
|
"github.com/pkg/errors"
|
||
|
)
|
||
|
|
||
|
type APIConfig struct {
|
||
|
Authentication AuthenticationConfig `yaml:"auth" envPrefix:"AUTH_"`
|
||
|
}
|
||
|
|
||
|
type Accounts []AccountConfig
|
||
|
|
||
|
type AuthenticationConfig struct {
|
||
|
Accounts Accounts `yaml:"accounts" env:"ACCOUNTS"`
|
||
|
}
|
||
|
|
||
|
func parseAccounts(value string) (any, error) {
|
||
|
var accounts Accounts
|
||
|
|
||
|
spew.Dump(value)
|
||
|
|
||
|
if err := json.Unmarshal([]byte(value), &accounts); err != nil {
|
||
|
return nil, errors.WithStack(err)
|
||
|
}
|
||
|
|
||
|
return accounts, nil
|
||
|
}
|
||
|
|
||
|
type AccountConfig struct {
|
||
|
Username string `yaml:"username" json:"username"`
|
||
|
Password string `yaml:"password" json:"password"`
|
||
|
}
|
||
|
|
||
|
func NewDefaultAPIConfig() APIConfig {
|
||
|
return APIConfig{
|
||
|
Authentication: AuthenticationConfig{
|
||
|
Accounts: []AccountConfig{
|
||
|
{
|
||
|
Username: "admin",
|
||
|
Password: "webauthn",
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
}
|