mirror of
https://github.com/edgebox-iot/edgeboxctl.git
synced 2026-09-24 05:41:43 +02:00
Fixed small typo, replaced DB connection details in Makefile by .env loading
This commit is contained in:
@@ -31,8 +31,12 @@ type EdgeAppService struct {
|
||||
}
|
||||
|
||||
const configFilename = "/edgebox-compose.yml"
|
||||
const edgeAppsPath = "/home/system/components/apps/"
|
||||
const wsPath = "/home/system/components/ws/"
|
||||
|
||||
// const edgeAppsPath = "/home/system/components/apps/"
|
||||
const edgeAppsPath = "/home/jpt/Repositories/edgebox/apps/"
|
||||
|
||||
// const wsPath = "/home/system/components/ws/"
|
||||
const wsPath = "/home/jpt/Repositories/edgebox/ws"
|
||||
|
||||
// GetEdgeApps : Returns a list of EdgeApp struct filled with information
|
||||
func GetEdgeApps() []EdgeApp {
|
||||
@@ -53,7 +57,8 @@ func GetEdgeApps() []EdgeApp {
|
||||
_, err := os.Stat(edgeAppsPath + f.Name() + configFilename)
|
||||
if !os.IsNotExist(err) {
|
||||
// File exists. Start digging!
|
||||
edgeApp := EdgeApp{ID: f.Name(), Status: GetEdgeAppStatus(f.Name()), Services: GetEdgeAppServices(f.Name()), NetworkURL: f.Name() + ".edgebox.local"}
|
||||
edgeAppName := "Nextcloud"
|
||||
edgeApp := EdgeApp{ID: f.Name(), Name: edgeAppName, Status: GetEdgeAppStatus(f.Name()), Services: GetEdgeAppServices(f.Name()), NetworkURL: f.Name() + ".edgebox.local"}
|
||||
edgeApps = append(edgeApps, edgeApp)
|
||||
}
|
||||
|
||||
|
||||
+23
-15
@@ -13,18 +13,6 @@ import (
|
||||
_ "github.com/go-sql-driver/mysql" // Mysql Driver
|
||||
)
|
||||
|
||||
// Dbhost : Database host (can be tweaked in makefile)
|
||||
var Dbhost string
|
||||
|
||||
// Dbname : Database name (can be tweaked in makefile)
|
||||
var Dbname string
|
||||
|
||||
// Dbuser : Database user (can be tweaked in makefile)
|
||||
var Dbuser string
|
||||
|
||||
// Dbpass : Database password (can be tweaked in)
|
||||
var Dbpass string
|
||||
|
||||
// Task : Struct for Task type
|
||||
type Task struct {
|
||||
ID int `json:"id"`
|
||||
@@ -47,7 +35,7 @@ type taskSetupTunnelArgs struct {
|
||||
func GetNextTask() Task {
|
||||
|
||||
// Will try to connect to API database, which should be running locally under WS.
|
||||
db, err := sql.Open("mysql", Dbuser+":"+Dbpass+"@tcp("+Dbhost+")/"+Dbname)
|
||||
db, err := sql.Open("mysql", utils.GetMySQLDbConnectionDetails())
|
||||
|
||||
// if there is an error opening the connection, handle it
|
||||
if err != nil {
|
||||
@@ -86,7 +74,7 @@ func GetNextTask() Task {
|
||||
// ExecuteTask : Performs execution of the given task, updating the task status as it goes, and publishing the task result
|
||||
func ExecuteTask(task Task) Task {
|
||||
|
||||
db, err := sql.Open("mysql", Dbuser+":"+Dbpass+"@tcp("+Dbhost+")/"+Dbname)
|
||||
db, err := sql.Open("mysql", utils.GetMySQLDbConnectionDetails())
|
||||
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
@@ -193,7 +181,27 @@ func taskGetEdgeApps() string {
|
||||
|
||||
fmt.Println("Executing taskGetEdgeApps")
|
||||
|
||||
log.Println(edgeapps.GetEdgeApps())
|
||||
edgeApps := edgeapps.GetEdgeApps()
|
||||
edgeAppsJSON, _ := json.Marshal(edgeApps)
|
||||
log.Println(string(edgeAppsJSON))
|
||||
|
||||
// db, err := sql.Open("mysql", utils.GetMySQLDbConnectionDetails())
|
||||
|
||||
// if err != nil {
|
||||
// panic(err.Error())
|
||||
// }
|
||||
|
||||
// defer db.Close()
|
||||
|
||||
// statusUpdate, err := db.Query("UPDATE options SET value = '" + + "' WHERE name = 'EDGEAPPS_LIST'")
|
||||
|
||||
// if err != nil {
|
||||
// panic(err.Error())
|
||||
// }
|
||||
|
||||
// for statusUpdate.Next() {
|
||||
|
||||
// }
|
||||
|
||||
// Saving information in the "options" table.
|
||||
return "OK"
|
||||
|
||||
@@ -5,6 +5,8 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os/exec"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
// Exec : Runs a terminal Command, catches and logs errors, returns the result.
|
||||
@@ -35,3 +37,25 @@ func DeleteEmptySlices(s []string) []string {
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// GetMySQLDbConnectionDetails : Returns the necessary string as connection info for SQL.db()
|
||||
func GetMySQLDbConnectionDetails() string {
|
||||
|
||||
// const apiEnvFileLocation = "/home/system/components/api/edgebox.env"
|
||||
const apiEnvFileLocation = "/home/jpt/Repositories/edgebox/api/edgebox.env"
|
||||
|
||||
var apiEnv map[string]string
|
||||
apiEnv, err := godotenv.Read(apiEnvFileLocation)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal("Error loading .env file")
|
||||
}
|
||||
|
||||
Dbhost := "127.0.0.1:" + apiEnv["HOST_MACHINE_MYSQL_PORT"]
|
||||
Dbname := apiEnv["MYSQL_DATABASE"]
|
||||
Dbuser := apiEnv["MYSQL_USER"]
|
||||
Dbpass := apiEnv["MYSQL_PASSWORD"]
|
||||
|
||||
return Dbuser + ":" + Dbpass + "@tcp(" + Dbhost + ")/" + Dbname
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user