forked from DefectDojo/godojo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
os.go
122 lines (103 loc) · 2.77 KB
/
os.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package main
import (
"strconv"
"github.com/mtesauro/godojo/config"
)
// Location for all non-OS specific calls where case statements handle dispacting calls to OS specifc calls
func initOSInst(id string, b *osCmds) {
switch id {
case "ubuntu:18.04":
ubuntuInitOSInst(id, b)
}
return
}
func instSQLite(id string, b *osCmds) {
switch id {
case "ubuntu:18.04":
ubuntuInstSQLite(id, b)
}
return
}
func instMariaDB(id string, b *osCmds) {
switch id {
case "ubuntu:18.04":
ubuntuInstMariaDB(id, b)
}
return
}
func instMySQL(id string, b *osCmds) {
switch id {
case "ubuntu:18.04":
ubuntuInstMySQL(id, b)
}
return
}
func instPostgreSQL(id string, b *osCmds) {
switch id {
case "ubuntu:18.04":
ubuntuInstPostgreSQL(id, b)
}
return
}
func defaultDBCreds(db string, os string) map[string]string {
// Setup a map to return
creds := map[string]string{"user": "foo", "pass": "bar"}
// Get the default creds based on OS
switch os {
case "ubuntu:18.04":
ubuntuDefaultDBCreds(db, creds)
}
return creds
}
func osPrep(id string, inst *config.InstallConfig, cmds *osCmds) {
switch id {
case "ubuntu:18.04":
ubuntuOSPrep(id, inst, cmds)
}
return
}
func createSettingsPy(id string, inst *config.DojoConfig, cmds *osCmds) {
// Setup the env.prod file used by settings.py
// Create the database URL for the env file - https://github.com/kennethreitz/dj-database-url
dbURL := ""
switch inst.Install.DB.Engine {
case "SQLite":
// sqlite:///PATH
dbURL = "sqlite:///defectdojo.db"
case "MySQL":
// mysql://USER:PASSWORD@HOST:PORT/NAME
dbURL = "mysql://" + inst.Install.DB.User + ":" + inst.Install.DB.Pass + "@" + inst.Install.DB.Host + ":" +
strconv.Itoa(inst.Install.DB.Port) + "/" + inst.Install.DB.Name
case "PostgreSQL":
// postgres://USER:PASSWORD@HOST:PORT/NAME
dbURL = "postgres://" + inst.Install.DB.User + ":" + inst.Install.DB.Pass + "@" + inst.Install.DB.Host + ":" +
strconv.Itoa(inst.Install.DB.Port) + "/" + inst.Install.DB.Name
}
// Setup env file for production
genAndWriteEnv(inst, dbURL)
// Create a settings.py for Dojo to use
cmds.id = id
cmds.cmds = []string{
"cp " + inst.Install.Root + "/django-DefectDojo/dojo/settings/settings.dist.py " +
inst.Install.Root + "/django-DefectDojo/dojo/settings/settings.py",
"chown " + inst.Install.OS.User + "." + inst.Install.OS.Group + " " + inst.Install.Root +
"/django-DefectDojo/dojo/settings/settings.py",
}
cmds.errmsg = []string{
"Unable to create settings.py file",
"Unable to change ownership of settings.py file",
}
cmds.hard = []bool{
true,
true,
}
return
}
func setupDjango(id string, inst *config.DojoConfig, cmds *osCmds) {
// Generate the commands to do the Django install
switch id {
case "ubuntu:18.04":
ubuntuSetupDDjango(id, &inst.Install, cmds)
}
return
}