mirror of
https://github.com/edgebox-iot/edgeboxctl.git
synced 2026-09-24 05:41:43 +02:00
Added full support for enable_online and disable_online tasks
This commit is contained in:
@@ -39,6 +39,15 @@ type taskStopEdgeAppArgs struct {
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
type taskEnableOnlineArgs struct {
|
||||
ID string `json:"id"`
|
||||
InternetURL string `json:"internet_url"`
|
||||
}
|
||||
|
||||
type taskDisableOnlineArgs struct {
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
// GetNextTask : Performs a MySQL query over the device's Edgebox API
|
||||
func GetNextTask() Task {
|
||||
|
||||
@@ -137,7 +146,32 @@ func ExecuteTask(task Task) Task {
|
||||
task.Result = sql.NullString{String: taskResult, Valid: true}
|
||||
}
|
||||
|
||||
case "enable_online":
|
||||
|
||||
log.Println("Enabling online access to EdgeApp...")
|
||||
var args taskEnableOnlineArgs
|
||||
err := json.Unmarshal([]byte(task.Args), &args)
|
||||
if err != nil {
|
||||
log.Printf("Error reading arguments of enable_online task: %s", err)
|
||||
} else {
|
||||
taskResult := taskEnableOnline(args)
|
||||
task.Result = sql.NullString{String: taskResult, Valid: true}
|
||||
}
|
||||
|
||||
case "disable_online":
|
||||
|
||||
log.Println("Disabling online access to EdgeApp...")
|
||||
var args taskDisableOnlineArgs
|
||||
err := json.Unmarshal([]byte(task.Args), &args)
|
||||
if err != nil {
|
||||
log.Printf("Error reading arguments of enable_online task: %s", err)
|
||||
} else {
|
||||
taskResult := taskDisableOnline(args)
|
||||
task.Result = sql.NullString{String: taskResult, Valid: true}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if task.Result.Valid {
|
||||
@@ -225,6 +259,34 @@ func taskStopEdgeApp(args taskStopEdgeAppArgs) string {
|
||||
|
||||
}
|
||||
|
||||
func taskEnableOnline(args taskEnableOnlineArgs) string {
|
||||
|
||||
fmt.Println("Executing taskEnableOnline for " + args.ID)
|
||||
|
||||
result := edgeapps.EnableOnline(args.ID, args.InternetURL)
|
||||
|
||||
resultJSON, _ := json.Marshal(result)
|
||||
|
||||
taskGetEdgeApps()
|
||||
|
||||
return string(resultJSON)
|
||||
|
||||
}
|
||||
|
||||
func taskDisableOnline(args taskDisableOnlineArgs) string {
|
||||
|
||||
fmt.Println("Executing taskEnableOnline for " + args.ID)
|
||||
|
||||
result := edgeapps.DisableOnline(args.ID)
|
||||
|
||||
resultJSON, _ := json.Marshal(result)
|
||||
|
||||
taskGetEdgeApps()
|
||||
|
||||
return string(resultJSON)
|
||||
|
||||
}
|
||||
|
||||
func taskGetEdgeApps() string {
|
||||
|
||||
fmt.Println("Executing taskGetEdgeApps")
|
||||
|
||||
Reference in New Issue
Block a user