Skip to content

Commit

Permalink
More clean-up for 2.0.x and start of work on supporting Debian instal…
Browse files Browse the repository at this point in the history
…l targets (#20)

* Minor updates, cleaning up dev branch

* Updated embedded dojoConfig.yml to latest version of DefectDojo

* More clean-up for 2.0.x and start of work on supporting Debian install targets
  • Loading branch information
mtesauro authored Jul 9, 2021
1 parent 7fdf62e commit 9610513
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 33 deletions.
8 changes: 4 additions & 4 deletions bindata.go

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions database.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ func installDBClient(osTar string, dbTar *config.DBTarget, dCmd *osCmds) {
return
}


func startDB(osTar string, dbTar *config.DBTarget, dbCmd *osCmds) {
// Look at the dbTar and call function to install that DB target
switch dbTar.Engine {
Expand All @@ -92,6 +91,8 @@ func startSQLite(osTar string, dbCmd *osCmds) {
case "ubuntu:20.04":
fallthrough
case "ubuntu:20.10":
fallthrough
case "ubuntu:21.04":
dbCmd.id = osTar
dbCmd.cmds = []string{
"echo 'Nothing to start for SQLite'",
Expand All @@ -113,6 +114,8 @@ func startMariaDB(osTar string, dbCmd *osCmds) {
case "ubuntu:20.04":
fallthrough
case "ubuntu:20.10":
fallthrough
case "ubuntu:21.04":
dbCmd.id = osTar
// TODO: Propably time to convert this to systemctl calls
// also consider enabling the service just in case
Expand All @@ -136,6 +139,8 @@ func startMySQL(osTar string, dbCmd *osCmds) {
case "ubuntu:20.04":
fallthrough
case "ubuntu:20.10":
fallthrough
case "ubuntu:21.04":
dbCmd.id = osTar
// TODO: Propably time to convert this to systemctl calls
// also consider enabling the service just in case
Expand All @@ -159,11 +164,13 @@ func startPostgres(osTar string, dbCmd *osCmds) {
case "ubuntu:20.04":
fallthrough
case "ubuntu:20.10":
fallthrough
case "ubuntu:21.04":
dbCmd.id = osTar
// TODO: Propably time to convert this to systemctl calls
// also consider enabling the service just in case
dbCmd.cmds = []string{
"service postgresql start",
"/usr/sbin/service postgresql start",
}
dbCmd.errmsg = []string{
"Unable to start PostgreSQL",
Expand Down
4 changes: 2 additions & 2 deletions embd/dojoConfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
# SecretKey

Install:
Version: "1.15.1" # DD_Version - Release version of DefectDojo from Github Releases
Version: "2.0.3" # DD_Version - Release version of DefectDojo from Github Releases
SourceInstall: false # DD_SourceInstall - Boolean if a source install is desired (vs a release)
# If ^ is true, a souce code install will occur overriding the release version provided
SourceBranch: "dev" # DD_SourceBranch - The branch's HEAD to be checked out if SourceInstall is true
SourceCommit: 22294ab6c69468057bce79386768869b2788de5d # DD_SourceCommit - If there is a value here, the specific commit will be used over the branch ^
SourceCommit: # DD_SourceCommit - If there is a value here, the specific commit will be used over the branch ^
Quiet: false # DD_Quiet - Suppress normal output - only errors will be shown
Trace: true # DD_Trace - Boolean to enable the most verbose logging during install
Redact: true # DD_Redact - Boolean to redact sensitive info from the logs
Expand Down
8 changes: 4 additions & 4 deletions godojo.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
// Global vars
var (
// Installer version
ver = "1.1.3"
ver = "1.1.4"
// Configuration file name
cf = "dojoConfig.yml"
// Global config struct
Expand Down Expand Up @@ -172,10 +172,10 @@ func getDojoRelease(i *config.InstallConfig) error {

// Setup a custom http client for downloading the Dojo release
var ddClient = &http.Client{
// Set time to a max of 20 seconds
Timeout: time.Second * 20,
// Set time to a max of 60 seconds
Timeout: time.Second * 60,
}
traceMsg("http.Client timeout set to 20 seconds for release download")
traceMsg("http.Client timeout set to 60 seconds for release download")

// Download requested release from Dojo's Github repo
traceMsg(fmt.Sprintf("Downloading release from %+v", dwnURL))
Expand Down
19 changes: 18 additions & 1 deletion os.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ func initOSInst(id string, b *osCmds) {
case "ubuntu:20.04":
fallthrough
case "ubuntu:20.10":
fallthrough
case "ubuntu:21.04":
ubuntuInitOSInst(id, b)

}
Expand All @@ -29,6 +31,8 @@ func instSQLite(id string, b *osCmds) {
case "ubuntu:20.04":
fallthrough
case "ubuntu:20.10":
fallthrough
case "ubuntu:21.04":
ubuntuInstSQLite(id, b)
}
return
Expand All @@ -41,6 +45,8 @@ func instMariaDB(id string, b *osCmds) {
case "ubuntu:20.04":
fallthrough
case "ubuntu:20.10":
fallthrough
case "ubuntu:21.04":
ubuntuInstMariaDB(id, b)
}
return
Expand All @@ -54,6 +60,8 @@ func instMySQL(id string, b *osCmds) {
case "ubuntu:20.04":
fallthrough
case "ubuntu:20.10":
fallthrough
case "ubuntu:21.04":
ubuntuInstMySQL(id, b)
}
return
Expand All @@ -66,6 +74,8 @@ func instPostgreSQL(id string, b *osCmds) {
case "ubuntu:20.04":
fallthrough
case "ubuntu:20.10":
fallthrough
case "ubuntu:21.04":
ubuntuInstPostgreSQL(id, b)
}
return
Expand All @@ -78,12 +88,13 @@ func instPostgreSQLClient(id string, b *osCmds) {
case "ubuntu:20.04":
fallthrough
case "ubuntu:20.10":
fallthrough
case "ubuntu:21.04":
ubuntuInstPostgreSQLClient(id, b)
}
return
}


func defaultDBCreds(db *config.DBTarget, os string) map[string]string {
// Setup a map to return
creds := map[string]string{"user": "foo", "pass": "bar"}
Expand All @@ -95,6 +106,8 @@ func defaultDBCreds(db *config.DBTarget, os string) map[string]string {
case "ubuntu:20.04":
fallthrough
case "ubuntu:20.10":
fallthrough
case "ubuntu:21.04":
ubuntuDefaultDBCreds(db, creds)
}

Expand All @@ -108,6 +121,8 @@ func osPrep(id string, inst *config.InstallConfig, cmds *osCmds) {
case "ubuntu:20.04":
fallthrough
case "ubuntu:20.10":
fallthrough
case "ubuntu:21.04":
ubuntuOSPrep(id, inst, cmds)
}
return
Expand Down Expand Up @@ -163,6 +178,8 @@ func setupDjango(id string, inst *config.DojoConfig, cmds *osCmds) {
case "ubuntu:20.04":
fallthrough
case "ubuntu:20.10":
fallthrough
case "ubuntu:21.04":
ubuntuSetupDDjango(id, &inst.Install, cmds)
}
return
Expand Down
26 changes: 17 additions & 9 deletions runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"syscall"
"time"
)

// TODO: Document this and/or move it to a separate package
Expand All @@ -22,7 +23,8 @@ func sendCmd(o io.Writer, cmd string, lerr string, hard bool) {
// Run and gather its output
cmdOut, err := runCmd.CombinedOutput()
if err != nil {
errorMsg(fmt.Sprintf("Failed to run OS command, error was: %+v", err))
errorMsg(fmt.Sprintf("%s - Failed to run OS command %+v, error was: %+v",
timeStamp(), Redactatron(cmd, Redact), err))
if hard {
// Exit on hard aka fatal errors
os.Exit(1)
Expand Down Expand Up @@ -51,7 +53,7 @@ func tryCmd(o io.Writer, cmd string, lerr string, hard bool) error {
runCmd := exec.Command("bash", "-c", cmd)
_, err := o.Write([]byte("[godojo] # " + Redactatron(cmd, Redact) + "\n"))
if err != nil {
traceMsg(fmt.Sprintf("Failed to setup command, error was: %+v", err))
traceMsg(fmt.Sprintf("Failed to setup command %+v, error was: %+v", Redactatron(cmd, Redact), err))
return err
}

Expand All @@ -74,11 +76,11 @@ func tryCmd(o io.Writer, cmd string, lerr string, hard bool) error {
// The program has exited with an exit code != 0
if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {
// Above casts the exiterr to syscll.WaitStatus aka unint32
traceMsg(fmt.Sprintf("%s errored with exit status: %d", cmd, status.ExitStatus()))
traceMsg(fmt.Sprintf("%s - %s errored with exit status: %d", timeStamp(), cmd, status.ExitStatus()))
return err
}
} else {
traceMsg(fmt.Sprintf("%s errored from Wait(): %v", cmd, err))
traceMsg(fmt.Sprintf("%s - %s errored from Wait(): %v", timeStamp(), cmd, err))
return err
}
}
Expand All @@ -96,7 +98,8 @@ func tryCmds(o io.Writer, c osCmds) error {
c.hard[i])

if err != nil {
traceMsg(fmt.Sprintf("Command %s errored with %s. Underlying error is %+v", c.cmds[i], c.errmsg[i], err))
traceMsg(fmt.Sprintf("%s - Command %s errored with %s. Underlying error is %+v",
timeStamp(), c.cmds[i], c.errmsg[i], err))
return errors.New(c.errmsg[i])
}
}
Expand Down Expand Up @@ -128,7 +131,7 @@ func inspectCmd(o io.Writer, cmd string, lerr string, hard bool) (string, error)
// Start the command
err = runCmd.Start()
if err != nil {
traceMsg(fmt.Sprintf("Failed to start command, error was: %+v", err))
traceMsg(fmt.Sprintf("%s - Failed to start command %+v, error was: %+v", timeStamp(), Redactatron(cmd, Redact), err))
return "", err
}

Expand All @@ -141,11 +144,11 @@ func inspectCmd(o io.Writer, cmd string, lerr string, hard bool) (string, error)
// The program has exited with an exit code != 0
if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {
// Above casts the exiterr to syscll.WaitStatus aka unint32
traceMsg(fmt.Sprintf("%s errored with exit status: %d", cmd, status.ExitStatus()))
traceMsg(fmt.Sprintf("%s - %s errored with exit status: %d", timeStamp(), cmd, status.ExitStatus()))
return "", err
}
} else {
traceMsg(fmt.Sprintf("%s errored from Wait(): %v", cmd, err))
traceMsg(fmt.Sprintf("%s - %s errored from Wait(): %v", timeStamp(), cmd, err))
return "", err
}
}
Expand All @@ -167,7 +170,8 @@ func inspectCmds(o io.Writer, c osCmds) ([]string, error) {
c.hard[i])

if err != nil {
traceMsg(fmt.Sprintf("Command %s errored with %s. Underlying error is %+v", c.cmds[i], c.errmsg[i], err))
traceMsg(fmt.Sprintf("%s - Command %s errored with %s. Underlying error is %+v",
timeStamp(), c.cmds[i], c.errmsg[i], err))
return ret, errors.New(c.errmsg[i])
}
ret = append(ret, out)
Expand All @@ -176,4 +180,8 @@ func inspectCmds(o io.Writer, c osCmds) ([]string, error) {
return ret, nil
}

func timeStamp() string {
return time.Now().Format("2006/01/02 15:04:05")
}

// TODO: Write a version of impsectCmds that returns the exit code in addition to combined stderr & stdout to caller
4 changes: 3 additions & 1 deletion targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,9 @@ func parseFile(f string, sep string, flds map[string]string) map[string]string {
// TODO: Make this fail for unsupported OSes
// TODO: Consider making a bootstrap per Linux distro switching to those here
func initBootstrap(id string, b *osCmds) {
switch distOnly(id) {
switch strings.ToLower(distOnly(id)) {
case "debian":
fallthrough
case "ubuntu":
b.id = id
b.cmds = []string{
Expand Down
Loading

0 comments on commit 9610513

Please sign in to comment.