Implemented scaffolding for BrowserDev tasks and implemented taskGetBrowserDevPassword
parent
b11034dd17
commit
7e42e72bb2
1
go.mod
1
go.mod
|
@ -8,6 +8,7 @@ require (
|
||||||
github.com/dustin/go-humanize v1.0.0 // indirect
|
github.com/dustin/go-humanize v1.0.0 // indirect
|
||||||
github.com/go-ole/go-ole v1.2.5 // indirect
|
github.com/go-ole/go-ole v1.2.5 // indirect
|
||||||
github.com/go-sql-driver/mysql v1.5.0
|
github.com/go-sql-driver/mysql v1.5.0
|
||||||
|
github.com/go-yaml/yaml v2.1.0+incompatible // indirect
|
||||||
github.com/joho/godotenv v1.3.0
|
github.com/joho/godotenv v1.3.0
|
||||||
github.com/mattn/go-sqlite3 v1.14.7 // indirect
|
github.com/mattn/go-sqlite3 v1.14.7 // indirect
|
||||||
github.com/shirou/gopsutil v3.21.4+incompatible // indirect
|
github.com/shirou/gopsutil v3.21.4+incompatible // indirect
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -11,6 +11,8 @@ github.com/go-ole/go-ole v1.2.5 h1:t4MGB5xEDZvXI+0rMjjsfBsD7yAgp/s9ZDkL1JndXwY=
|
||||||
github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
||||||
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
|
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
|
||||||
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||||
|
github.com/go-yaml/yaml v2.1.0+incompatible h1:RYi2hDdss1u4YE7GwixGzWwVo47T8UQwnTLB6vQiq+o=
|
||||||
|
github.com/go-yaml/yaml v2.1.0+incompatible/go.mod h1:w2MrLa16VYP0jy6N7M5kHaCkaLENm+P+Tv+MfurjSw0=
|
||||||
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
||||||
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
|
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
|
||||||
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
|
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"io"
|
"io"
|
||||||
|
"errors"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"bufio"
|
"bufio"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -17,6 +18,7 @@ import (
|
||||||
|
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
"github.com/shirou/gopsutil/host"
|
"github.com/shirou/gopsutil/host"
|
||||||
|
"github.com/go-yaml/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
type cloudflaredTunnelJson struct {
|
type cloudflaredTunnelJson struct {
|
||||||
|
@ -516,3 +518,33 @@ func ApplyUpdates() {
|
||||||
utils.WriteOption("UPDATING_SYSTEM", "false")
|
utils.WriteOption("UPDATING_SYSTEM", "false")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FetchBrowserDevPasswordFromFile() (string, error) {
|
||||||
|
fmt.Println("Executing FetchBrowserDevPasswordFromFile")
|
||||||
|
|
||||||
|
// Read the "password" entry on the yaml file
|
||||||
|
// Read the yaml file in system.GetPath(BrowserDevPasswordFileLocation)
|
||||||
|
yamlFile, err := ioutil.ReadFile(utils.GetPath(utils.BrowserDevPasswordFileLocation))
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse the yaml file and get the "password" entry
|
||||||
|
var yamlFileMap yaml.MapSlice
|
||||||
|
err = yaml.Unmarshal(yamlFile, &yamlFileMap)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, item := range yamlFileMap {
|
||||||
|
key, value := item.Key, item.Value
|
||||||
|
if key == "password" {
|
||||||
|
if pwString, ok := value.(string); ok {
|
||||||
|
return pwString, nil
|
||||||
|
} else {
|
||||||
|
return "", errors.New("password value is not a string")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "", errors.New("password key not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -291,6 +291,11 @@ func ExecuteTask(task Task) Task {
|
||||||
taskResult := taskStopShell()
|
taskResult := taskStopShell()
|
||||||
task.Result = sql.NullString{String: taskResult, Valid: true}
|
task.Result = sql.NullString{String: taskResult, Valid: true}
|
||||||
|
|
||||||
|
case "activate_browser_dev":
|
||||||
|
log.Println("Activating Browser Dev Environment")
|
||||||
|
taskResult := taskActivateBrowserDev()
|
||||||
|
task.Result = sql.NullString{String: taskResult, Valid: true}
|
||||||
|
|
||||||
case "install_edgeapp":
|
case "install_edgeapp":
|
||||||
|
|
||||||
log.Println("Installing EdgeApp...")
|
log.Println("Installing EdgeApp...")
|
||||||
|
@ -495,6 +500,8 @@ func ExecuteSchedules(tick int) {
|
||||||
|
|
||||||
if tick == 1 {
|
if tick == 1 {
|
||||||
|
|
||||||
|
resultPassword := taskGetBrowserDevPassword()
|
||||||
|
|
||||||
ip := taskGetSystemIP()
|
ip := taskGetSystemIP()
|
||||||
log.Println("System IP is: " + ip)
|
log.Println("System IP is: " + ip)
|
||||||
|
|
||||||
|
@ -1099,6 +1106,46 @@ func taskStopShell() string {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func taskActivateBrowserDev() string {
|
||||||
|
fmt.Println("Executing taskActivateBrowserDev")
|
||||||
|
wsPath := utils.GetPath(utils.WsPath)
|
||||||
|
|
||||||
|
// start the code-server process
|
||||||
|
// utils.Exec(wsPath, "killall", []string{"sshx"})
|
||||||
|
utils.Exec(wsPath, "killall", []string{"code-server"})
|
||||||
|
|
||||||
|
utils.WriteOption("BROWSERDEV_STATUS", "running")
|
||||||
|
|
||||||
|
return "{\"status\": \"ok\"}"
|
||||||
|
}
|
||||||
|
|
||||||
|
func taskDeactivateBrowserDev() string {
|
||||||
|
fmt.Println("Executing taskDeactivateBrowserDev")
|
||||||
|
utils.WriteOption("BROWSERDEV_STATUS", "not_running")
|
||||||
|
return "{\"status\": \"ok\"}"
|
||||||
|
}
|
||||||
|
|
||||||
|
func taskGetBrowserDevPassword() string {
|
||||||
|
fmt.Println("Executing taskGetBrowserDevPassword")
|
||||||
|
password := utils.ReadOption("BROWSERDEV_PASSWORD")
|
||||||
|
if password == "" {
|
||||||
|
password, err := system.FetchBrowserDevPasswordFromFile()
|
||||||
|
if err == nil {
|
||||||
|
utils.WriteOption("BROWSERDEV_PASSWORD", password)
|
||||||
|
} else {
|
||||||
|
fmt.Println("Error fetching browser dev password from file: " + err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return password
|
||||||
|
}
|
||||||
|
|
||||||
|
// func taskSetBrowserDevPassword(args taskSetBrowserDevPasswordArgs) string {
|
||||||
|
// fmt.Println("Executing taskSetBrowserDevPassword")
|
||||||
|
// system.SetBrowserDevPassword(args.Password)
|
||||||
|
// utils.WriteOption("BROWSERDEV_PASSWORD", args.Password)
|
||||||
|
// return "{\"status\": \"ok\"}"
|
||||||
|
// }
|
||||||
|
|
||||||
func taskInstallEdgeApp(args taskInstallEdgeAppArgs) string {
|
func taskInstallEdgeApp(args taskInstallEdgeAppArgs) string {
|
||||||
fmt.Println("Executing taskInstallEdgeApp for " + args.ID)
|
fmt.Println("Executing taskInstallEdgeApp for " + args.ID)
|
||||||
|
|
||||||
|
|
|
@ -112,6 +112,7 @@ const EdgeAppsPath string = "edgeAppsPath"
|
||||||
const EdgeAppsBackupPath string = "edgeAppsBackupPath"
|
const EdgeAppsBackupPath string = "edgeAppsBackupPath"
|
||||||
const WsPath string = "wsPath"
|
const WsPath string = "wsPath"
|
||||||
const LoggerPath string = "loggerPath"
|
const LoggerPath string = "loggerPath"
|
||||||
|
const BrowserDevPasswordFileLocation string = "browserDevPasswordFileLocation"
|
||||||
|
|
||||||
|
|
||||||
// GetPath : Returns either the hardcoded path, or a overwritten value via .env file at project root. Register paths here for seamless working code between dev and prod environments ;)
|
// GetPath : Returns either the hardcoded path, or a overwritten value via .env file at project root. Register paths here for seamless working code between dev and prod environments ;)
|
||||||
|
@ -189,6 +190,13 @@ func GetPath(pathKey string) string {
|
||||||
targetPath = "/home/system/components/backups/pw.txt"
|
targetPath = "/home/system/components/backups/pw.txt"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case BrowserDevPasswordFileLocation:
|
||||||
|
if env["BROWSERDEV_PASSWORD_FILE_LOCATION"] != "" {
|
||||||
|
targetPath = env["BROWSERDEV_PASSWORD_FILE_LOCATION"]
|
||||||
|
} else {
|
||||||
|
targetPath = "/root/.config/code-server/config.yaml"
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
log.Printf("path_key %s nonexistant in GetPath().\n", pathKey)
|
log.Printf("path_key %s nonexistant in GetPath().\n", pathKey)
|
||||||
|
|
Loading…
Reference in New Issue