Skip to content

Commit

Permalink
Bug fixes for 2 bugs impacting 1.15.x installs on 'iron' (#23)
Browse files Browse the repository at this point in the history
* Minor updates, cleaning up dev branch

* Updated embedded dojoConfig.yml to latest version

* More clean-up for 2.0.x and start of work on supporting Debian install targets

* Update for new embedded version

* Workaround Python 3.8 bug that kinda broke 1.15.1 (and maybe other releases)

* Bump version for 2 bugfixes
  • Loading branch information
mtesauro authored Jul 24, 2021
1 parent b5e127d commit 54ef9ef
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 88 deletions.
25 changes: 24 additions & 1 deletion bindata.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion 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.5"
ver = "1.1.6"
// Configuration file name
cf = "dojoConfig.yml"
// Global config struct
Expand Down
21 changes: 21 additions & 0 deletions runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,27 @@ import (
"time"
)

// OS commands to perform an action e.g. install DB from OS packages
type osCmds struct {
id string // Holds distro + release e.g. ubuntu:18.04
cmds []string // Holds the os commands
errmsg []string // Holds the error messages if the matching command fails
hard []bool // Flag to know if an error on the matching command is fatal
}

func newCmds(d string) *osCmds {
var o osCmds
o.id = d
return &o
}

func addCmd(o *osCmds, cmd string, lerr string, hard bool) {
// Append command to existing list
o.cmds = append(o.cmds, cmd)
o.errmsg = append(o.cmds, lerr)
o.hard = append(o.hard, hard)
}

// TODO: Document this and/or move it to a separate package
func sendCmd(o io.Writer, cmd string, lerr string, hard bool) {
// Setup command
Expand Down
8 changes: 0 additions & 8 deletions targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ type targetOS struct {
release string
}

// OS commands to perform an action e.g. install DB from OS packages
type osCmds struct {
id string // Holds distro + release e.g. ubuntu:18.04
cmds []string // Holds the os commands
errmsg []string // Holds the error messages if the matching command fails
hard []bool // Flag to know if an error on the matching command is fatal
}

func determineOS(tOS *targetOS) {
// Determine OS first
tOS.os = runtime.GOOS
Expand Down
206 changes: 128 additions & 78 deletions ubuntu.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/fs"
"io/ioutil"
"os"
"strconv"
"strings"

"github.com/mtesauro/godojo/config"
Expand Down Expand Up @@ -309,7 +310,14 @@ func ubuntuSetupDDjango(id string, inst *config.InstallConfig, b *osCmds) {
traceMsg(fmt.Sprintf("Injecting file %s at %s", "setup-superuser.expect", inst.Root+"/django-DefectDojo"))
_ = injectFile("setup-superuser.expect", inst.Root+"/django-DefectDojo", 0755)

err := patchOMatic(inst)
if err != nil {
traceMsg(fmt.Sprintf("patchOMatic failed with non-blocking error: %+v", err))
traceMsg("A failure of patchOMatic may lead to a corrupt install - be warned")
}

// Django installs - migrations, create Django superuser
// TODO: Remove this switch to simplify
switch id {
case "ubuntu:18.04":
fallthrough
Expand All @@ -318,91 +326,82 @@ func ubuntuSetupDDjango(id string, inst *config.InstallConfig, b *osCmds) {
case "ubuntu:20.10":
fallthrough
case "ubuntu:21.04":
b.id = id
b.cmds = []string{
//"cd " + inst.Root + "/django-DefectDojo && source ../bin/activate && python3 manage.py makemigrations --merge --noinput",
"cd " + inst.Root + "/django-DefectDojo && source ../bin/activate && python3 manage.py makemigrations dojo",
"cd " + inst.Root + "/django-DefectDojo && source ../bin/activate && python3 manage.py migrate",
"cd " + inst.Root + "/django-DefectDojo && source ../bin/activate && python3 manage.py createsuperuser --noinput --username=\"" +
inst.Admin.User + "\" --email=\"" + inst.Admin.Email + "\"",
"cd " + inst.Root + "/django-DefectDojo && source ../bin/activate && " +
inst.Root + "/django-DefectDojo/setup-superuser.expect " + inst.Admin.User + " " + inst.Admin.Pass,
"cd " + inst.Root + "/django-DefectDojo && source ../bin/activate && python3 manage.py loaddata role",
"cd " + inst.Root + "/django-DefectDojo && source ../bin/activate && python3 manage.py loaddata product_type",
"cd " + inst.Root + "/django-DefectDojo && source ../bin/activate && python3 manage.py loaddata test_type",
"cd " + inst.Root + "/django-DefectDojo && source ../bin/activate && python3 manage.py loaddata development_environment",
"cd " + inst.Root + "/django-DefectDojo && source ../bin/activate && python3 manage.py loaddata system_settings",
"cd " + inst.Root + "/django-DefectDojo && source ../bin/activate && python3 manage.py loaddata benchmark_type",
"cd " + inst.Root + "/django-DefectDojo && source ../bin/activate && python3 manage.py loaddata benchmark_category",
"cd " + inst.Root + "/django-DefectDojo && source ../bin/activate && python3 manage.py loaddata benchmark_requirement",
"cd " + inst.Root + "/django-DefectDojo && source ../bin/activate && python3 manage.py loaddata language_type",
"cd " + inst.Root + "/django-DefectDojo && source ../bin/activate && python3 manage.py loaddata objects_review",
"cd " + inst.Root + "/django-DefectDojo && source ../bin/activate && python3 manage.py loaddata regulation",
//"cd " + inst.Root + "/django-DefectDojo && source ../bin/activate && python3 manage.py import_surveys",
//"cd " + inst.Root + "/django-DefectDojo && source ../bin/activate && python3 manage.py loaddata initial_surveys",
"cd " + inst.Root + "/django-DefectDojo && source ../bin/activate && python3 manage.py buildwatson",
"cd " + inst.Root + "/django-DefectDojo && source ../bin/activate && python3 manage.py installwatson",
"cd " + inst.Root + "/django-DefectDojo/components && yarn",
"cd " + inst.Root + "/django-DefectDojo/ && source ../bin/activate && python3 manage.py collectstatic --noinput",
"chown -R " + inst.OS.User + "." + inst.OS.Group + " " + inst.Root,
}
b.errmsg = []string{
//"Initial makemgrations failed",
"Failed during makemgration dojo",
"Failed during database migrate",
"Failed while creating DefectDojo superuser",
"Failed while setting the password for the DefectDojo superuser",
"Failed while the loading data for role",
"Failed while the loading data for product_type",
"Failed while the loading data for test_type",
"Failed while the loading data for development_environment",
"Failed while the loading data for system_settings",
"Failed while the loading data for benchmark_type",
"Failed while the loading data for benchmark_category",
"Failed while the loading data for benchmark_requirement",
"Failed while the loading data for language_type",
"Failed while the loading data for objects_review",
"Failed while the loading data for regulation",
//"Failed while the running import_surveys",
//"Failed while the loading data for initial_surveys",
"Failed while the running buildwatson",
"Failed while the running installwatson",
"Failed while the running yarn",
"Failed while the running collectstatic",
"Unable to change ownership of the DefectDojo directory",
}
b.hard = []bool{
//true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
//true,
//true,
true,
true,
true,
true,
true,
// Add commands to setup DefectDojo - migrations, super user,
// removed - "cd " + inst.Root + "/django-DefectDojo && source ../bin/activate && python3 manage.py makemigrations --merge --noinput", "Initial makemgrations failed",
addCmd(b, "cd "+inst.Root+"/django-DefectDojo && source ../bin/activate && python3 manage.py makemigrations dojo",
"Failed during makemgration dojo", true)

addCmd(b, "cd "+inst.Root+"/django-DefectDojo && source ../bin/activate && python3 manage.py migrate",
"Failed during database migrate", true)

addCmd(b, "cd "+inst.Root+"/django-DefectDojo && source ../bin/activate && python3 manage.py createsuperuser --noinput --username=\""+
inst.Admin.User+"\" --email=\""+inst.Admin.Email+"\"",
"Failed while creating DefectDojo superuser", true)

addCmd(b, "cd "+inst.Root+"/django-DefectDojo && source ../bin/activate && "+
inst.Root+"/django-DefectDojo/setup-superuser.expect "+inst.Admin.User+" "+inst.Admin.Pass,
"Failed while setting the password for the DefectDojo superuser", true)

// Roles showed up in 2.x.x
if onlyAfter(inst.Version, 2, 0, 0) {
addCmd(b, "cd "+inst.Root+"/django-DefectDojo && source ../bin/activate && python3 manage.py loaddata role",
"Failed while the loading data for role", true)
}

addCmd(b, "cd "+inst.Root+"/django-DefectDojo && source ../bin/activate && python3 manage.py loaddata product_type",
"Failed while the loading data for product_type", true)

addCmd(b, "cd "+inst.Root+"/django-DefectDojo && source ../bin/activate && python3 manage.py loaddata test_type",
"Failed while the loading data for test_type", true)

addCmd(b, "cd "+inst.Root+"/django-DefectDojo && source ../bin/activate && python3 manage.py loaddata development_environment",
"Failed while the loading data for development_environment", true)

addCmd(b, "cd "+inst.Root+"/django-DefectDojo && source ../bin/activate && python3 manage.py loaddata system_settings",
"Failed while the loading data for system_settings", true)

addCmd(b, "cd "+inst.Root+"/django-DefectDojo && source ../bin/activate && python3 manage.py loaddata benchmark_type",
"Failed while the loading data for benchmark_type", true)

addCmd(b, "cd "+inst.Root+"/django-DefectDojo && source ../bin/activate && python3 manage.py loaddata benchmark_category",
"Failed while the loading data for benchmark_category", true)

addCmd(b, "cd "+inst.Root+"/django-DefectDojo && source ../bin/activate && python3 manage.py loaddata benchmark_requirement",
"Failed while the loading data for benchmark_requirement", true)

addCmd(b, "cd "+inst.Root+"/django-DefectDojo && source ../bin/activate && python3 manage.py loaddata language_type",
"Failed while the loading data for language_type", true)

addCmd(b, "cd "+inst.Root+"/django-DefectDojo && source ../bin/activate && python3 manage.py loaddata objects_review",
"Failed while the loading data for objects_review", true)

addCmd(b, "cd "+inst.Root+"/django-DefectDojo && source ../bin/activate && python3 manage.py loaddata regulation",
"Failed while the loading data for regulation", true)

// removed - "cd " + inst.Root + "/django-DefectDojo && source ../bin/activate && python3 manage.py import_surveys", "Failed while the running import_surveys",
// removed - "cd " + inst.Root + "/django-DefectDojo && source ../bin/activate && python3 manage.py loaddata initial_surveys", "Failed while the loading data for initial_surveys",

addCmd(b, "cd "+inst.Root+"/django-DefectDojo && source ../bin/activate && python3 manage.py buildwatson",
"Failed while the running buildwatson", true)

addCmd(b, "cd "+inst.Root+"/django-DefectDojo && source ../bin/activate && python3 manage.py installwatson",
"Failed while the running installwatson", true)

addCmd(b, "cd "+inst.Root+"/django-DefectDojo/components && yarn",
"Failed while the running yarn", true)

addCmd(b, "cd "+inst.Root+"/django-DefectDojo/ && source ../bin/activate && python3 manage.py collectstatic --noinput",
"Failed while the running collectstatic", true)

addCmd(b, "chown -R "+inst.OS.User+"."+inst.OS.Group+" "+inst.Root,
"Unable to change ownership of the DefectDojo directory", true)
}

return
}

func injectFile(n string, p string, mask fs.FileMode) error {
loc := emdir + "setup-superuser.expect"
loc := emdir + n
d, err := Asset(loc)
if err != nil {
return err
Expand All @@ -418,3 +417,54 @@ func injectFile(n string, p string, mask fs.FileMode) error {

return nil
}

func patchOMatic(inst *config.InstallConfig) error {
// If a source or commit install, do no patching
if inst.SourceInstall {
return nil
}

// Check the install version for any needed patches
switch inst.Version {
case "1.15.1":
// Replace dojo/tools/factory to work around bug in Python 3.8 - https://bugs.python.org/issue44061
w := bufio.NewWriter(os.Stdout)
_ = injectFile("factory_2.0.3", inst.Root+"/django-DefectDojo/dojo/tools", 755)
_ = tryCmd(w,
"mv -f "+inst.Root+"/django-DefectDojo/dojo/tools/factory.py "+inst.Root+"/django-DefectDojo/dojo/tools/factory_py.buggy",
"Error renaming factory.py to factory_py.buggy", false)
_ = tryCmd(w,
"mv -f "+inst.Root+"/django-DefectDojo/dojo/tools/factory_2.0.3 "+inst.Root+"/django-DefectDojo/dojo/tools/factory.py",
"Error replacing factory.py with updated one from version 2.0.3", false)
}

return nil
}

//onlyAfter(inst.Version, "2")
func onlyAfter(v string, major int, minor int, patch int) bool {
// Split up version
vBits := strings.Split(v, ".")
if len(vBits) != 3 {
traceMsg(fmt.Sprintf("Bad version string: %s sent to onlyAfter()", v))
return false
}

// Convert version bits
vMaj, _ := strconv.Atoi(vBits[0])
vMin, _ := strconv.Atoi(vBits[1])
vPat, _ := strconv.Atoi(vBits[2])

//
if vMaj < major {
return false
}
if vMin < minor {
return false
}
if vPat < patch {
return false
}

return true
}

0 comments on commit 54ef9ef

Please sign in to comment.