Added task SetupCloudOptions
parent
3b3010c8f0
commit
bff0f6f817
|
@ -8,6 +8,8 @@ import (
|
|||
"github.com/edgebox-iot/edgeboxctl/internal/utils"
|
||||
|
||||
"github.com/shirou/gopsutil/host"
|
||||
"github.com/joho/godotenv"
|
||||
|
||||
)
|
||||
|
||||
func GetUptimeInSeconds() string {
|
||||
|
@ -54,3 +56,29 @@ func GetIP() string {
|
|||
func GetHostname() string {
|
||||
return utils.Exec("/", "hostname", []string{})
|
||||
}
|
||||
|
||||
func SetupCloudOptions() {
|
||||
|
||||
var cloudEnv map[string]string
|
||||
cloudEnv, err := godotenv.Read(utils.GetPath("cloudEnvFileLocation"))
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("Error loading .env file for cloud version setup")
|
||||
}
|
||||
|
||||
if cloudEnv["NAME"] != "" {
|
||||
utils.WriteOption("NAME", cloudEnv["NAME"])
|
||||
}
|
||||
|
||||
if cloudEnv["EMAIL"] != "" {
|
||||
utils.WriteOption("EMAIL", cloudEnv["EMAIL"])
|
||||
}
|
||||
|
||||
if cloudEnv["EDGEBOXIO_API_TOKEN"] != "" {
|
||||
utils.WriteOption("EDGEBOXIO_API_TOKEN", cloudEnv["EDGEBOXIO_API_TOKEN"])
|
||||
}
|
||||
|
||||
// In the end of this operation takes place, remove the env file as to not overwrite any options once they are set.
|
||||
utils.Exec("/", "rm", []string{utils.GetPath("cloudEnvFileLocation")})
|
||||
|
||||
}
|
||||
|
|
|
@ -281,11 +281,17 @@ func ExecuteSchedules(tick int) {
|
|||
hostname := taskGetHostname()
|
||||
log.Println("Hostname is " + hostname)
|
||||
|
||||
if diagnostics.Version == "cloud" && !edgeapps.IsPublicDashboard() {
|
||||
taskEnablePublicDashboard(taskEnablePublicDashboardArgs{
|
||||
InternetURL: hostname + ".myedge.app",
|
||||
})
|
||||
// if diagnostics.Version == "cloud" && !edgeapps.IsPublicDashboard() {
|
||||
// taskEnablePublicDashboard(taskEnablePublicDashboardArgs{
|
||||
// InternetURL: hostname + ".myedge.app",
|
||||
// })
|
||||
// }
|
||||
|
||||
if diagnostics.Version == "cloud" {
|
||||
log.Println("Setting up cloud version options (name, email, api token)")
|
||||
taskSetupCloudOptions()
|
||||
}
|
||||
|
||||
|
||||
// Executing on startup (first tick). Schedules run before tasks in the SystemIterator
|
||||
uptime := taskGetSystemUptime()
|
||||
|
@ -467,3 +473,8 @@ func taskGetHostname() string {
|
|||
utils.WriteOption("HOSTNAME", hostname)
|
||||
return hostname
|
||||
}
|
||||
|
||||
func taskSetupCloudOptions() {
|
||||
fmt.Println("Executing taskSetupCloudOptions")
|
||||
system.SetupCloudOptions()
|
||||
}
|
||||
|
|
|
@ -113,6 +113,14 @@ func GetPath(pathKey string) string {
|
|||
}
|
||||
|
||||
switch pathKey {
|
||||
case "cloudEnvFileLocation":
|
||||
|
||||
if env["CLOUD_ENV_FILE_LOCATION"] != "" {
|
||||
targetPath = env["CLOUD_ENV_FILE_LOCATION"]
|
||||
} else {
|
||||
targetPath = "/home/system/components/edgeboxctl/cloud.env"
|
||||
}
|
||||
|
||||
case "apiEnvFileLocation":
|
||||
|
||||
if env["API_ENV_FILE_LOCATION"] != "" {
|
||||
|
|
Loading…
Reference in New Issue