Skip to content

Commit

Permalink
Merge pull request #21 from 1dustindavis/gorilla_report
Browse files Browse the repository at this point in the history
Added GorillaReport.json that includes all items processed
  • Loading branch information
1dustindavis authored Aug 26, 2018
2 parents 278911e + 51d480a commit d2fb555
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmd/gorilla/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ import (
"github.com/1dustindavis/gorilla/pkg/gorillalog"
"github.com/1dustindavis/gorilla/pkg/manifest"
"github.com/1dustindavis/gorilla/pkg/process"
"github.com/1dustindavis/gorilla/pkg/report"
)

func main() {

// Create a new logger object
gorillalog.NewLog()

// Start creating GorillaReport
report.Start()

// Get our configuration
config.Get()

Expand Down Expand Up @@ -40,5 +44,8 @@ func main() {
gorillalog.Info("Processing managed updates...")
process.Updates(updates, catalog)

// Save GorillaReport to disk
report.End()

gorillalog.Info("Done!")
}
6 changes: 6 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"path/filepath"

"github.com/1dustindavis/gorilla/pkg/report"
"gopkg.in/yaml.v2"
)

Expand Down Expand Up @@ -91,12 +92,17 @@ func Get() {
configuration.Verbose = true
}

// Set global variables
URL = configuration.URL
Manifest = configuration.Manifest
Catalog = configuration.Catalog
CachePath = configuration.CachePath
Verbose = configuration.Verbose
Debug = configuration.Debug

// Add to GorillaReport
report.Items["Manifest"] = Manifest
report.Items["Catalog"] = Catalog

return
}
13 changes: 13 additions & 0 deletions pkg/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/1dustindavis/gorilla/pkg/config"
"github.com/1dustindavis/gorilla/pkg/download"
"github.com/1dustindavis/gorilla/pkg/gorillalog"
"github.com/1dustindavis/gorilla/pkg/report"
"github.com/1dustindavis/gorilla/pkg/status"
)

Expand Down Expand Up @@ -129,6 +130,10 @@ func Install(item catalog.Item) {
return
}

// Add the item to InstalledItems in GorillaReport
report.InstalledItems = append(report.InstalledItems, item)

// Run the command and arguments
runCommand(installCmd, installArgs)

return
Expand Down Expand Up @@ -205,6 +210,10 @@ func Uninstall(item catalog.Item) {
return
}

// Add the item to UninstalledItems in GorillaReport
report.UninstalledItems = append(report.UninstalledItems, item)

// Run the command and arguments
runCommand(uninstallCmd, uninstallArgs)

return
Expand Down Expand Up @@ -293,6 +302,10 @@ func Update(item catalog.Item) {
return
}

// Add the item to UpdatedItems in GorillaReport
report.UpdatedItems = append(report.UpdatedItems, item)

// Run the command and arguments
runCommand(installCmd, installArgs)

return
Expand Down
74 changes: 74 additions & 0 deletions pkg/report/report.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package report

import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"os/user"
"path/filepath"
"time"
)

var (
// Items contains the data we will save to GorillaReport
Items = make(map[string]interface{})

// InstalledItems contains a list of items we attempted to install
InstalledItems []interface{}

// UninstalledItems contains a list of items we attempted to uninstall
UninstalledItems []interface{}

// UpdatedItems contains a list of items we attempted to update
UpdatedItems []interface{}
)

// Start adds the data we already know at the begining of a run
func Start() {

// Store the start time
currentTime := time.Now().UTC()
Items["StartTime"] = fmt.Sprint(currentTime.Format("2006-01-02 15:04:05 -0700"))

// Store the current user
currentUser, userErr := user.Current()
if userErr != nil {
fmt.Println("Unable to determine current user", userErr)
}
Items["CurrentUser"] = fmt.Sprint(currentUser.Username)

// Store the hostname
hostName, hostErr := os.Hostname()
if hostErr != nil {
fmt.Println("Unable to determine current time", hostErr)
}
Items["HostName"] = fmt.Sprint(hostName)
}

// End will compile everything and save to disk
func End() {

// Compile everything
Items["InstalledItems"] = InstalledItems
Items["UninstalledItems"] = UninstalledItems
Items["UpdatedItems"] = UpdatedItems

// Store the end time
currentTime := time.Now().UTC()
Items["EndTime"] = fmt.Sprint(currentTime.Format("2006-01-02 15:04:05 -0700"))

// Convert it all to json
reportJSON, marshalErr := json.Marshal(Items)
if marshalErr != nil {
fmt.Println("Unable to create GorillaReport json", marshalErr)
}

// Write Items to disk as GorillaReport.json
reportPath := filepath.Join(os.Getenv("ProgramData"), "gorilla/GorillaReport.json")
writeErr := ioutil.WriteFile(reportPath, reportJSON, 0644)
if writeErr != nil {
fmt.Println("Unable to write GorillaReport.json to disk:", writeErr)
}

}

0 comments on commit d2fb555

Please sign in to comment.