mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2024-11-10 08:57:25 +01:00
load config.json in current directory by default (issue #17)
This commit is contained in:
parent
8bdab3298d
commit
65f7e5e6c8
@ -137,7 +137,7 @@ func main() {
|
||||
flag.BoolVar(&flagSyncLDAP, "sync-ldap", false, "Sync the 'user' table with ldap")
|
||||
flag.BoolVar(&flagStopImmediately, "no-server", false, "Do not start a server, stop right after initialization and argument handling")
|
||||
flag.BoolVar(&flagGops, "gops", false, "Listen via github.com/google/gops/agent (for debugging)")
|
||||
flag.StringVar(&flagConfigFile, "config", "", "Overwrite the global config options by those specified in `config.json`")
|
||||
flag.StringVar(&flagConfigFile, "config", "./config.json", "Overwrite the global config options by those specified in `config.json`")
|
||||
flag.StringVar(&flagNewUser, "add-user", "", "Add a new user. Argument format: `<username>:[admin,api,user]:<password>`")
|
||||
flag.StringVar(&flagDelUser, "del-user", "", "Remove user by `username`")
|
||||
flag.StringVar(&flagGenJWT, "jwt", "", "Generate and print a JWT for the user specified by its `username`")
|
||||
@ -155,17 +155,19 @@ func main() {
|
||||
log.Fatalf("parsing './.env' file failed: %s", err.Error())
|
||||
}
|
||||
|
||||
if flagConfigFile != "" {
|
||||
f, err := os.Open(flagConfigFile)
|
||||
if err != nil {
|
||||
// Load JSON config:
|
||||
f, err := os.Open(flagConfigFile)
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) || flagConfigFile != "./config.json" {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer f.Close()
|
||||
} else {
|
||||
dec := json.NewDecoder(f)
|
||||
dec.DisallowUnknownFields()
|
||||
if err := dec.Decode(&programConfig); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
f.Close()
|
||||
}
|
||||
|
||||
// As a special case for `db`, allow using an environment variable instead of the value
|
||||
@ -176,7 +178,6 @@ func main() {
|
||||
programConfig.DB = os.Getenv(envvar)
|
||||
}
|
||||
|
||||
var err error
|
||||
repository.Connect(programConfig.DBDriver, programConfig.DB)
|
||||
db := repository.GetConnection()
|
||||
|
||||
|
@ -142,13 +142,13 @@ func (auth *Authentication) SyncWithLDAP(deleteOldUsers bool) error {
|
||||
|
||||
for username, where := range users {
|
||||
if where == IN_DB && deleteOldUsers {
|
||||
log.Infof("ldap-sync: remove %#v (does not show up in LDAP anymore)", username)
|
||||
log.Debugf("ldap-sync: remove %#v (does not show up in LDAP anymore)", username)
|
||||
if _, err := auth.db.Exec(`DELETE FROM user WHERE user.username = ?`, username); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if where == IN_LDAP {
|
||||
name := newnames[username]
|
||||
log.Infof("ldap-sync: add %#v (name: %#v, roles: [user], ldap: true)", username, name)
|
||||
log.Debugf("ldap-sync: add %#v (name: %#v, roles: [user], ldap: true)", username, name)
|
||||
if _, err := auth.db.Exec(`INSERT INTO user (username, ldap, name, roles) VALUES (?, ?, ?, ?)`,
|
||||
username, 1, name, "[\""+RoleUser+"\"]"); err != nil {
|
||||
return err
|
||||
|
Loading…
Reference in New Issue
Block a user