Uh oh!
There was an error while loading. Please reload this page.
forked from open-uem/utils
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase_linux.go
More file actions
Latest commit
54 lines (42 loc) · 1.32 KB
/
Copy pathdatabase_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"
)
funcCreatePostgresDatabaseURL() (string, error) {
varerrerror
// Open ini file
cfg, err:=ini.Load("/etc/openuem-server/openuem.ini")
iferr!=nil {
return"", err
}
user, err:=cfg.Section("DB").GetKey("PostgresUser")
iferr!=nil {
return"", fmt.Errorf("could not read PostgresUser from INI")
}
username:=url.PathEscape(user.String())
host, err:=cfg.Section("DB").GetKey("PostgresHost")
iferr!=nil {
return"", fmt.Errorf("could not read PostgresHost from INI")
}
hostname:=url.PathEscape(host.String())
port, err:=cfg.Section("DB").GetKey("PostgresPort")
iferr!=nil {
return"", fmt.Errorf("could not read PostgresPort from INI")
}
dbPort:=url.PathEscape(port.String())
database, err:=cfg.Section("DB").GetKey("PostgresDatabase")
iferr!=nil {
return"", fmt.Errorf("could not read PostgresDatabase from INI")
}
databaseName:=url.PathEscape(database.String())
pass, err:=cfg.Section("DB").GetKey("PostgresPassword")
iferr!=nil {
return"", fmt.Errorf("could not read password from Windows Credential Manager")
}
password:=template.URLQueryEscaper(pass.String())
returnfmt.Sprintf("postgres://%s:%s@%s:%s/%s", username, password, hostname, dbPort, databaseName), nil
}