-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdatabase_linux.go
More file actions
54 lines (42 loc) · 1.32 KB
/
database_linux.go
File metadata and controls
54 lines (42 loc) · 1.32 KB
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
//go:build linux
package utils
import (
"fmt"
"net/url"
"text/template"
"gopkg.in/ini.v1"
)
func CreatePostgresDatabaseURL() (string, error) {
var err error
// Open ini file
cfg, err := ini.Load("/etc/openuem-server/openuem.ini")
if err != nil {
return "", err
}
user, err := cfg.Section("DB").GetKey("PostgresUser")
if err != nil {
return "", fmt.Errorf("could not read PostgresUser from INI")
}
username := url.PathEscape(user.String())
host, err := cfg.Section("DB").GetKey("PostgresHost")
if err != nil {
return "", fmt.Errorf("could not read PostgresHost from INI")
}
hostname := url.PathEscape(host.String())
port, err := cfg.Section("DB").GetKey("PostgresPort")
if err != nil {
return "", fmt.Errorf("could not read PostgresPort from INI")
}
dbPort := url.PathEscape(port.String())
database, err := cfg.Section("DB").GetKey("PostgresDatabase")
if err != nil {
return "", fmt.Errorf("could not read PostgresDatabase from INI")
}
databaseName := url.PathEscape(database.String())
pass, err := cfg.Section("DB").GetKey("PostgresPassword")
if err != nil {
return "", fmt.Errorf("could not read password from Windows Credential Manager")
}
password := template.URLQueryEscaper(pass.String())
return fmt.Sprintf("postgres://%s:%s@%s:%s/%s", username, password, hostname, dbPort, databaseName), nil
}