forked from harness/harness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.go
72 lines (61 loc) · 1.62 KB
/
settings.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package database
import (
. "github.com/drone/drone/pkg/model"
"github.com/russross/meddler"
)
// Name of the Settings table in the database
const settingsTable = "settings"
// SQL Queries to retrieve the system settings
const settingsStmt = `
SELECT id, github_key, github_secret, bitbucket_key, bitbucket_secret,
smtp_server, smtp_port, smtp_address, smtp_username, smtp_password, hostname, scheme
FROM settings WHERE id = 1
`
//var (
// // mutex for locking the local settings cache
// settingsLock sync.Mutex
//
// // cached settings
// settingsCache = &Settings{}
//)
// Returns the system Settings.
func GetSettings() (*Settings, error) {
//settingsLock.Lock()
//defer settingsLock.Unlock()
// return a copy of the settings
//if settingsCache.ID == 0 {
/// settingsCopy := &Settings{}
// *settingsCopy = *settingsCache
// return settingsCopy, nil
//}
settings := Settings{}
err := meddler.QueryRow(db, &settings, settingsStmt)
//if err == sql.ErrNoRows {
// // we ignore the NoRows error in case this
// // is the first time the system is being used
// err = nil
//}
return &settings, err
}
// Returns the system Settings. This is expected
// always pass, and will panic on failure.
func SettingsMust() *Settings {
settings, err := GetSettings()
if err != nil {
panic(err)
}
return settings
}
// Saves the system Settings.
func SaveSettings(settings *Settings) error {
//settingsLock.Lock()
//defer settingsLock.Unlock()
// persist changes to settings
err := meddler.Save(db, settingsTable, settings)
if err != nil {
return err
}
// store updated settings in cache
//*settingsCache = *settings
return nil
}