swirl/misc/option.go

75 lines
1.8 KiB
Go
Raw Normal View History

2021-12-06 12:24:22 +00:00
package misc
import (
"strings"
"time"
"github.com/cuigh/auxo/config"
"github.com/cuigh/auxo/errors"
)
// Options holds custom options of Swirl.
var Options = &struct {
DockerEndpoint string
DockerAPIVersion string
DBType string
DBAddress string
TokenKey string
TokenExpiry time.Duration
2021-12-17 12:13:58 +00:00
Agents []string
2021-12-06 12:24:22 +00:00
}{
DBType: "mongo",
DBAddress: "mongodb://localhost:27017/swirl",
TokenExpiry: 30 * time.Minute,
}
func bindOptions() {
var keys = []string{
"docker_endpoint",
"docker_api_version",
"db_type",
"db_address",
"token_key",
"token_expiry",
2021-12-17 12:13:58 +00:00
"agents",
2021-12-06 12:24:22 +00:00
}
for _, key := range keys {
config.BindEnv("swirl."+key, strings.ToUpper(key))
}
}
func LoadOptions() (err error) {
err = config.UnmarshalOption("swirl", &Options)
if err != nil {
err = errors.Wrap(err, "failed to load options")
}
return
}
// Setting represents the settings of Swirl.
type Setting struct {
System struct {
2021-12-23 10:00:14 +00:00
Version string `json:"version"`
} `json:"system"`
2021-12-06 12:24:22 +00:00
LDAP struct {
2021-12-23 10:00:14 +00:00
Enabled bool `json:"enabled"`
Address string `json:"address"`
Security int32 `json:"security"` // 0, 1, 2
Authentication string `json:"auth"` // simple, bind
BindDN string `json:"bind_dn"`
BindPassword string `json:"bind_pwd"` // Bind DN password
BaseDN string `json:"base_dn"` // Base search path for users
UserDN string `json:"user_dn"` // Template for the DN of the user for simple auth
UserFilter string `json:"user_filter"` // Search filter for user
NameAttr string `json:"name_attr"`
EmailAttr string `json:"email_attr"`
} `json:"ldap"`
2021-12-06 12:24:22 +00:00
Metric struct {
2021-12-23 10:00:14 +00:00
Prometheus string `json:"prometheus"`
} `json:"metric"`
2021-12-06 12:24:22 +00:00
}
func init() {
bindOptions()
}