Implemented scaffolding for BrowserDev tasks and implemented taskGetBrowserDevPassword

This commit is contained in:
Paulo Truta
2024-12-03 09:20:44 +01:00
parent b11034dd17
commit 7e42e72bb2
5 changed files with 90 additions and 0 deletions
+32
View File
@@ -7,6 +7,7 @@ import (
"log"
"os"
"io"
"errors"
"os/exec"
"bufio"
"path/filepath"
@@ -17,6 +18,7 @@ import (
"github.com/joho/godotenv"
"github.com/shirou/gopsutil/host"
"github.com/go-yaml/yaml"
)
type cloudflaredTunnelJson struct {
@@ -516,3 +518,33 @@ func ApplyUpdates() {
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")
}