Compare commits
1 Commits
cli/fix/mu
...
fix/add_no
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d9bea6ea10 |
@@ -49,10 +49,7 @@ func main() {
|
||||
|
||||
mainCtx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
apis, err := apiserver.NewServer(mainCtx, port)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
apis := apiserver.NewServer(mainCtx, port)
|
||||
|
||||
if err := state.CheckCurrentStatus(mainCtx); err != nil {
|
||||
klog.Error(err)
|
||||
|
||||
83
daemon/internel/apiserver/handlers/command_group.go
Normal file
83
daemon/internel/apiserver/handlers/command_group.go
Normal file
@@ -0,0 +1,83 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"github.com/beclab/Olares/daemon/internel/apiserver/server"
|
||||
changehost "github.com/beclab/Olares/daemon/pkg/commands/change_host"
|
||||
collectlogs "github.com/beclab/Olares/daemon/pkg/commands/collect_logs"
|
||||
connectwifi "github.com/beclab/Olares/daemon/pkg/commands/connect_wifi"
|
||||
"github.com/beclab/Olares/daemon/pkg/commands/install"
|
||||
mountsmb "github.com/beclab/Olares/daemon/pkg/commands/mount_smb"
|
||||
"github.com/beclab/Olares/daemon/pkg/commands/reboot"
|
||||
"github.com/beclab/Olares/daemon/pkg/commands/shutdown"
|
||||
umountsmb "github.com/beclab/Olares/daemon/pkg/commands/umount_smb"
|
||||
umountusb "github.com/beclab/Olares/daemon/pkg/commands/umount_usb"
|
||||
"github.com/beclab/Olares/daemon/pkg/commands/uninstall"
|
||||
"github.com/beclab/Olares/daemon/pkg/commands/upgrade"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
func init() {
|
||||
s := server.API
|
||||
cmd := s.App.Group("command")
|
||||
cmd.Post("/install", handlers.RequireSignature(
|
||||
handlers.WaitServerRunning(
|
||||
handlers.RunCommand(handlers.PostTerminusInit, install.New))))
|
||||
|
||||
cmd.Post("/uninstall", handlers.RequireSignature(
|
||||
handlers.WaitServerRunning(
|
||||
handlers.RunCommand(handlers.PostTerminusUninstall, uninstall.New))))
|
||||
|
||||
cmd.Post("/upgrade", handlers.RequireSignature(
|
||||
handlers.WaitServerRunning(
|
||||
handlers.RunCommand(handlers.RequestOlaresUpgrade, upgrade.NewCreateUpgradeTarget))))
|
||||
|
||||
cmd.Delete("/upgrade", handlers.RequireSignature(
|
||||
handlers.RunCommand(handlers.CancelOlaresUpgrade, upgrade.NewRemoveUpgradeTarget)))
|
||||
|
||||
cmd.Post("/reboot", handlers.RequireSignature(
|
||||
handlers.WaitServerRunning(
|
||||
handlers.RunCommand(handlers.PostReboot, reboot.New))))
|
||||
|
||||
cmd.Post("/shutdown", handlers.RequireSignature(
|
||||
handlers.WaitServerRunning(
|
||||
handlers.RunCommand(handlers.PostShutdown, shutdown.New))))
|
||||
|
||||
cmd.Post("/connect-wifi", handlers.RequireSignature(
|
||||
handlers.WaitServerRunning(
|
||||
handlers.RunCommand(handlers.PostConnectWifi, connectwifi.New))))
|
||||
|
||||
cmd.Post("/change-host", handlers.RequireSignature(
|
||||
handlers.WaitServerRunning(
|
||||
handlers.RunCommand(handlers.PostChangeHost, changehost.New))))
|
||||
|
||||
cmd.Post("/umount-usb", handlers.RequireSignature(
|
||||
handlers.WaitServerRunning(
|
||||
handlers.RunCommand(handlers.PostUmountUsb, umountusb.New))))
|
||||
|
||||
cmd.Post("/umount-usb-incluster", handlers.RequireSignature(
|
||||
handlers.WaitServerRunning(
|
||||
handlers.RunCommand(handlers.PostUmountUsbInCluster, umountusb.New))))
|
||||
|
||||
cmd.Post("/collect-logs", handlers.RequireSignature(
|
||||
handlers.WaitServerRunning(
|
||||
handlers.RunCommand(handlers.PostCollectLogs, collectlogs.New))))
|
||||
|
||||
cmd.Post("/mount-samba", handlers.RequireSignature(
|
||||
handlers.WaitServerRunning(
|
||||
handlers.RunCommand(handlers.PostMountSambaDriver, mountsmb.New))))
|
||||
|
||||
cmd.Post("/umount-samba", handlers.RequireSignature(
|
||||
handlers.WaitServerRunning(
|
||||
handlers.RunCommand(handlers.PostUmountSmb, umountsmb.New))))
|
||||
|
||||
cmd.Post("/umount-samba-incluster", handlers.RequireSignature(
|
||||
handlers.WaitServerRunning(
|
||||
handlers.RunCommand(handlers.PostUmountSmbInCluster, umountsmb.New))))
|
||||
|
||||
cmdv2 := cmd.Group("v2")
|
||||
cmdv2.Post("/mount-samba", handlers.RequireSignature(
|
||||
handlers.WaitServerRunning(
|
||||
handlers.RunCommand(handlers.PostMountSambaDriverV2, mountsmb.New))))
|
||||
|
||||
klog.Info("command handlers initialized")
|
||||
}
|
||||
28
daemon/internel/apiserver/handlers/containerd_group.go
Normal file
28
daemon/internel/apiserver/handlers/containerd_group.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"github.com/beclab/Olares/daemon/internel/apiserver/server"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
func init() {
|
||||
s := server.API
|
||||
containerd := s.App.Group("containerd")
|
||||
containerd.Get("/registries", handlers.RequireSignature(handlers.ListRegistries))
|
||||
|
||||
registry := containerd.Group("registry")
|
||||
mirrors := registry.Group("mirrors")
|
||||
|
||||
mirrors.Get("/", handlers.RequireSignature(handlers.GetRegistryMirrors))
|
||||
mirrors.Get("/:registry", handlers.RequireSignature(handlers.GetRegistryMirror))
|
||||
mirrors.Put("/:registry", handlers.RequireSignature(handlers.UpdateRegistryMirror))
|
||||
mirrors.Delete("/:registry", handlers.RequireSignature(handlers.DeleteRegistryMirror))
|
||||
|
||||
image := containerd.Group("images")
|
||||
|
||||
image.Get("/", handlers.RequireSignature(handlers.ListImages))
|
||||
image.Delete("/:image", handlers.RequireSignature(handlers.DeleteImage))
|
||||
image.Post("/prune", handlers.RequireSignature(handlers.PruneImages))
|
||||
|
||||
klog.Info("containerd handlers initialized")
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package apiserver
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
@@ -13,7 +13,7 @@ type ChangeHostReq struct {
|
||||
IP string `json:"ip"`
|
||||
}
|
||||
|
||||
func (h *handlers) PostChangeHost(ctx *fiber.Ctx, cmd commands.Interface) error {
|
||||
func (h *Handlers) PostChangeHost(ctx *fiber.Ctx, cmd commands.Interface) error {
|
||||
var req ChangeHostReq
|
||||
if err := h.ParseBody(ctx, &req); err != nil {
|
||||
klog.Error("parse request error, ", err)
|
||||
@@ -1,4 +1,4 @@
|
||||
package apiserver
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
func (h *handlers) PostCollectLogs(ctx *fiber.Ctx, cmd commands.Interface) error {
|
||||
func (h *Handlers) PostCollectLogs(ctx *fiber.Ctx, cmd commands.Interface) error {
|
||||
_, err := cmd.Execute(ctx.Context(), nil)
|
||||
if err != nil {
|
||||
klog.Error("execute command error, ", err, ", ", cmd.OperationName().Stirng())
|
||||
@@ -1,4 +1,4 @@
|
||||
package apiserver
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
@@ -14,7 +14,7 @@ type ConnectWifiReq struct {
|
||||
SSID string `json:"ssid"`
|
||||
}
|
||||
|
||||
func (h *handlers) PostConnectWifi(ctx *fiber.Ctx, cmd commands.Interface) error {
|
||||
func (h *Handlers) PostConnectWifi(ctx *fiber.Ctx, cmd commands.Interface) error {
|
||||
var req ConnectWifiReq
|
||||
if err := h.ParseBody(ctx, &req); err != nil {
|
||||
klog.Error("parse request error, ", err)
|
||||
@@ -1,4 +1,4 @@
|
||||
package apiserver
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
func (h *handlers) ListRegistries(ctx *fiber.Ctx) error {
|
||||
func (h *Handlers) ListRegistries(ctx *fiber.Ctx) error {
|
||||
images, err := containerd.ListRegistries(ctx)
|
||||
if err != nil {
|
||||
klog.Error("list registries error, ", err)
|
||||
@@ -17,7 +17,7 @@ func (h *handlers) ListRegistries(ctx *fiber.Ctx) error {
|
||||
return h.OkJSON(ctx, "success", images)
|
||||
}
|
||||
|
||||
func (h *handlers) GetRegistryMirrors(ctx *fiber.Ctx) error {
|
||||
func (h *Handlers) GetRegistryMirrors(ctx *fiber.Ctx) error {
|
||||
mirrors, err := containerd.GetRegistryMirrors(ctx)
|
||||
if err != nil {
|
||||
klog.Error("get registry mirrors error, ", err)
|
||||
@@ -27,7 +27,7 @@ func (h *handlers) GetRegistryMirrors(ctx *fiber.Ctx) error {
|
||||
return h.OkJSON(ctx, "success", mirrors)
|
||||
}
|
||||
|
||||
func (h *handlers) GetRegistryMirror(ctx *fiber.Ctx) error {
|
||||
func (h *Handlers) GetRegistryMirror(ctx *fiber.Ctx) error {
|
||||
mirror, err := containerd.GetRegistryMirror(ctx)
|
||||
if err != nil {
|
||||
klog.Error("get registry mirror error, ", err)
|
||||
@@ -37,7 +37,7 @@ func (h *handlers) GetRegistryMirror(ctx *fiber.Ctx) error {
|
||||
return h.OkJSON(ctx, "success", mirror)
|
||||
}
|
||||
|
||||
func (h *handlers) UpdateRegistryMirror(ctx *fiber.Ctx) error {
|
||||
func (h *Handlers) UpdateRegistryMirror(ctx *fiber.Ctx) error {
|
||||
mirror, err := containerd.UpdateRegistryMirror(ctx)
|
||||
if err != nil {
|
||||
klog.Error("update registry mirror error, ", err)
|
||||
@@ -47,7 +47,7 @@ func (h *handlers) UpdateRegistryMirror(ctx *fiber.Ctx) error {
|
||||
return h.OkJSON(ctx, "success", mirror)
|
||||
}
|
||||
|
||||
func (h *handlers) DeleteRegistryMirror(ctx *fiber.Ctx) error {
|
||||
func (h *Handlers) DeleteRegistryMirror(ctx *fiber.Ctx) error {
|
||||
if err := containerd.DeleteRegistryMirror(ctx); err != nil {
|
||||
klog.Error("delete registry mirror error, ", err)
|
||||
return h.ErrJSON(ctx, http.StatusInternalServerError, err.Error())
|
||||
@@ -56,7 +56,7 @@ func (h *handlers) DeleteRegistryMirror(ctx *fiber.Ctx) error {
|
||||
return h.OkJSON(ctx, "success")
|
||||
}
|
||||
|
||||
func (h *handlers) ListImages(ctx *fiber.Ctx) error {
|
||||
func (h *Handlers) ListImages(ctx *fiber.Ctx) error {
|
||||
registry := ctx.Query("registry")
|
||||
images, err := containerd.ListImages(ctx, registry)
|
||||
if err != nil {
|
||||
@@ -66,7 +66,7 @@ func (h *handlers) ListImages(ctx *fiber.Ctx) error {
|
||||
return h.OkJSON(ctx, "success", images)
|
||||
}
|
||||
|
||||
func (h *handlers) DeleteImage(ctx *fiber.Ctx) error {
|
||||
func (h *Handlers) DeleteImage(ctx *fiber.Ctx) error {
|
||||
if err := containerd.DeleteImage(ctx); err != nil {
|
||||
klog.Error("delete image error, ", err)
|
||||
return h.ErrJSON(ctx, http.StatusInternalServerError, err.Error())
|
||||
@@ -74,7 +74,7 @@ func (h *handlers) DeleteImage(ctx *fiber.Ctx) error {
|
||||
return h.OkJSON(ctx, "success")
|
||||
}
|
||||
|
||||
func (h *handlers) PruneImages(ctx *fiber.Ctx) error {
|
||||
func (h *Handlers) PruneImages(ctx *fiber.Ctx) error {
|
||||
res, err := containerd.PruneImages(ctx)
|
||||
if err != nil {
|
||||
klog.Error("prune images error, ", err)
|
||||
@@ -1,4 +1,4 @@
|
||||
package apiserver
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
func (h *handlers) GetHostsfile(ctx *fiber.Ctx) error {
|
||||
func (h *Handlers) GetHostsfile(ctx *fiber.Ctx) error {
|
||||
items, err := nets.GetHostsFile()
|
||||
if err != nil {
|
||||
return h.ErrJSON(ctx, http.StatusServiceUnavailable, err.Error())
|
||||
@@ -22,7 +22,7 @@ type writeHostsfileReq struct {
|
||||
Items []*nets.HostsItem `json:"items"`
|
||||
}
|
||||
|
||||
func (h *handlers) PostHostsfile(ctx *fiber.Ctx) error {
|
||||
func (h *Handlers) PostHostsfile(ctx *fiber.Ctx) error {
|
||||
var req writeHostsfileReq
|
||||
if err := h.ParseBody(ctx, &req); err != nil {
|
||||
klog.Error("parse request error, ", err)
|
||||
@@ -1,4 +1,4 @@
|
||||
package apiserver
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
@@ -21,6 +21,7 @@ type NetIf struct {
|
||||
Strength *int `json:"strength,omitempty"`
|
||||
MTU int `json:"mtu,omitempty"`
|
||||
InternetConnected *bool `json:"internetConnected,omitempty"`
|
||||
Hostname string `json:"hostname,omitempty"` // Hostname of the device
|
||||
|
||||
Ipv4Gateway *string `json:"ipv4Gateway,omitempty"`
|
||||
Ipv6Gateway *string `json:"ipv6Gateway,omitempty"`
|
||||
@@ -34,7 +35,7 @@ type NetIf struct {
|
||||
TxRate *float64 `json:"txRate,omitempty"` // in bytes per second
|
||||
}
|
||||
|
||||
func (h *handlers) GetNetIfs(ctx *fiber.Ctx) error {
|
||||
func (h *Handlers) GetNetIfs(ctx *fiber.Ctx) error {
|
||||
test := ctx.Query("testConnectivity", "false")
|
||||
|
||||
ifaces, err := nets.GetInternalIpv4Addr(test != "true")
|
||||
@@ -65,6 +66,7 @@ func (h *handlers) GetNetIfs(ctx *fiber.Ctx) error {
|
||||
IP: i.IP,
|
||||
IsHostIp: i.IP == hostip,
|
||||
MTU: i.Iface.MTU,
|
||||
Hostname: host,
|
||||
}
|
||||
|
||||
if wifiDevs != nil {
|
||||
@@ -137,8 +139,8 @@ func (h *handlers) GetNetIfs(ctx *fiber.Ctx) error {
|
||||
return h.OkJSON(ctx, "", res)
|
||||
}
|
||||
|
||||
func (h *handlers) findAp(ssid string) *ble.AccessPoint {
|
||||
for _, ap := range h.apList {
|
||||
func (h *Handlers) findAp(ssid string) *ble.AccessPoint {
|
||||
for _, ap := range h.ApList {
|
||||
if ap.SSID == ssid {
|
||||
return &ap
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package apiserver
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
@@ -15,7 +15,7 @@ type MountReq struct {
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
func (h *handlers) PostMountSambaDriver(ctx *fiber.Ctx, cmd commands.Interface) error {
|
||||
func (h *Handlers) PostMountSambaDriver(ctx *fiber.Ctx, cmd commands.Interface) error {
|
||||
var req MountReq
|
||||
if err := h.ParseBody(ctx, &req); err != nil {
|
||||
klog.Error("parse request error, ", err)
|
||||
@@ -1,4 +1,4 @@
|
||||
package apiserver
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
@@ -17,7 +17,7 @@ type ListSmbResponse struct {
|
||||
Mounted bool `json:"mounted"`
|
||||
}
|
||||
|
||||
func (h *handlers) PostMountSambaDriverV2(ctx *fiber.Ctx, cmd commands.Interface) error {
|
||||
func (h *Handlers) PostMountSambaDriverV2(ctx *fiber.Ctx, cmd commands.Interface) error {
|
||||
var req MountReq
|
||||
if err := h.ParseBody(ctx, &req); err != nil {
|
||||
klog.Error("parse request error, ", err)
|
||||
@@ -1,4 +1,4 @@
|
||||
package apiserver
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
func (h *handlers) getMountedHdd(ctx *fiber.Ctx, mutate func(*disk.UsageStat) *disk.UsageStat) error {
|
||||
func (h *Handlers) getMountedHdd(ctx *fiber.Ctx, mutate func(*disk.UsageStat) *disk.UsageStat) error {
|
||||
paths, err := utils.MountedHddPath(ctx.Context())
|
||||
if err != nil {
|
||||
return h.ErrJSON(ctx, http.StatusInternalServerError, err.Error())
|
||||
@@ -35,11 +35,11 @@ func (h *handlers) getMountedHdd(ctx *fiber.Ctx, mutate func(*disk.UsageStat) *d
|
||||
return h.OkJSON(ctx, "success", res)
|
||||
}
|
||||
|
||||
func (h *handlers) GetMountedHdd(ctx *fiber.Ctx) error {
|
||||
func (h *Handlers) GetMountedHdd(ctx *fiber.Ctx) error {
|
||||
return h.getMountedHdd(ctx, nil)
|
||||
}
|
||||
|
||||
func (h *handlers) GetMountedHddInCluster(ctx *fiber.Ctx) error {
|
||||
func (h *Handlers) GetMountedHddInCluster(ctx *fiber.Ctx) error {
|
||||
return h.getMountedHdd(ctx, func(us *disk.UsageStat) *disk.UsageStat {
|
||||
us.Path = nodePathToClusterPath(us.Path)
|
||||
return us
|
||||
@@ -1,4 +1,4 @@
|
||||
package apiserver
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
@@ -20,7 +20,7 @@ type mountedPath struct {
|
||||
ReadOnly bool `json:"read_only"`
|
||||
}
|
||||
|
||||
func (h *handlers) getMountedPath(ctx *fiber.Ctx, mutate func(*disk.UsageStat) *disk.UsageStat) error {
|
||||
func (h *Handlers) getMountedPath(ctx *fiber.Ctx, mutate func(*disk.UsageStat) *disk.UsageStat) error {
|
||||
paths, err := utils.MountedPath(ctx.Context())
|
||||
if err != nil {
|
||||
return h.ErrJSON(ctx, http.StatusInternalServerError, err.Error())
|
||||
@@ -58,11 +58,11 @@ func (h *handlers) getMountedPath(ctx *fiber.Ctx, mutate func(*disk.UsageStat) *
|
||||
return h.OkJSON(ctx, "success", res)
|
||||
}
|
||||
|
||||
func (h *handlers) GetMountedPath(ctx *fiber.Ctx) error {
|
||||
func (h *Handlers) GetMountedPath(ctx *fiber.Ctx) error {
|
||||
return h.getMountedPath(ctx, nil)
|
||||
}
|
||||
|
||||
func (h *handlers) GetMountedPathInCluster(ctx *fiber.Ctx) error {
|
||||
func (h *Handlers) GetMountedPathInCluster(ctx *fiber.Ctx) error {
|
||||
return h.getMountedPath(ctx, func(us *disk.UsageStat) *disk.UsageStat {
|
||||
us.Path = nodePathToClusterPath(us.Path)
|
||||
return us
|
||||
@@ -1,4 +1,4 @@
|
||||
package apiserver
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
@@ -15,7 +15,7 @@ type mountedSmbPathResponse struct {
|
||||
Device string `json:"device"`
|
||||
}
|
||||
|
||||
func (h *handlers) getMountedSmb(ctx *fiber.Ctx, mutate func(*disk.UsageStat) *disk.UsageStat) error {
|
||||
func (h *Handlers) getMountedSmb(ctx *fiber.Ctx, mutate func(*disk.UsageStat) *disk.UsageStat) error {
|
||||
paths, err := utils.MountedSambaPath(ctx.Context())
|
||||
if err != nil {
|
||||
return h.ErrJSON(ctx, http.StatusInternalServerError, err.Error())
|
||||
@@ -41,11 +41,11 @@ func (h *handlers) getMountedSmb(ctx *fiber.Ctx, mutate func(*disk.UsageStat) *d
|
||||
return h.OkJSON(ctx, "success", res)
|
||||
}
|
||||
|
||||
func (h *handlers) GetMountedSmb(ctx *fiber.Ctx) error {
|
||||
func (h *Handlers) GetMountedSmb(ctx *fiber.Ctx) error {
|
||||
return h.getMountedSmb(ctx, nil)
|
||||
}
|
||||
|
||||
func (h *handlers) GetMountedSmbInCluster(ctx *fiber.Ctx) error {
|
||||
func (h *Handlers) GetMountedSmbInCluster(ctx *fiber.Ctx) error {
|
||||
return h.getMountedSmb(ctx, func(us *disk.UsageStat) *disk.UsageStat {
|
||||
us.Path = nodePathToClusterPath(us.Path)
|
||||
return us
|
||||
@@ -1,4 +1,4 @@
|
||||
package apiserver
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
func (h *handlers) getMountedUsb(ctx *fiber.Ctx, mutate func(*disk.UsageStat) *disk.UsageStat) error {
|
||||
func (h *Handlers) getMountedUsb(ctx *fiber.Ctx, mutate func(*disk.UsageStat) *disk.UsageStat) error {
|
||||
paths, err := utils.MountedUsbPath(ctx.Context())
|
||||
if err != nil {
|
||||
return h.ErrJSON(ctx, http.StatusInternalServerError, err.Error())
|
||||
@@ -33,11 +33,11 @@ func (h *handlers) getMountedUsb(ctx *fiber.Ctx, mutate func(*disk.UsageStat) *d
|
||||
return h.OkJSON(ctx, "success", res)
|
||||
}
|
||||
|
||||
func (h *handlers) GetMountedUsb(ctx *fiber.Ctx) error {
|
||||
func (h *Handlers) GetMountedUsb(ctx *fiber.Ctx) error {
|
||||
return h.getMountedUsb(ctx, nil)
|
||||
}
|
||||
|
||||
func (h *handlers) GetMountedUsbInCluster(ctx *fiber.Ctx) error {
|
||||
func (h *Handlers) GetMountedUsbInCluster(ctx *fiber.Ctx) error {
|
||||
return h.getMountedUsb(ctx, func(us *disk.UsageStat) *disk.UsageStat {
|
||||
us.Path = nodePathToClusterPath(us.Path)
|
||||
return us
|
||||
@@ -1,4 +1,4 @@
|
||||
package apiserver
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -35,7 +35,7 @@ func (r *UpgradeReq) Check() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *handlers) RequestOlaresUpgrade(ctx *fiber.Ctx, cmd commands.Interface) error {
|
||||
func (h *Handlers) RequestOlaresUpgrade(ctx *fiber.Ctx, cmd commands.Interface) error {
|
||||
var req UpgradeReq
|
||||
if err := h.ParseBody(ctx, &req); err != nil {
|
||||
klog.Error("parse request error, ", err)
|
||||
@@ -60,7 +60,7 @@ func (h *handlers) RequestOlaresUpgrade(ctx *fiber.Ctx, cmd commands.Interface)
|
||||
return h.OkJSON(ctx, "successfully created upgrade target")
|
||||
}
|
||||
|
||||
func (h *handlers) CancelOlaresUpgrade(ctx *fiber.Ctx, cmd commands.Interface) error {
|
||||
func (h *Handlers) CancelOlaresUpgrade(ctx *fiber.Ctx, cmd commands.Interface) error {
|
||||
if _, err := cmd.Execute(ctx.Context(), nil); err != nil {
|
||||
return h.ErrJSON(ctx, http.StatusBadRequest, err.Error())
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package apiserver
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
func (h *handlers) PostReboot(ctx *fiber.Ctx, cmd commands.Interface) error {
|
||||
func (h *Handlers) PostReboot(ctx *fiber.Ctx, cmd commands.Interface) error {
|
||||
_, err := cmd.Execute(ctx.Context(), nil)
|
||||
if err != nil {
|
||||
klog.Error("execute command error, ", err, ", ", cmd.OperationName().Stirng())
|
||||
@@ -1,4 +1,4 @@
|
||||
package apiserver
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
func (h *handlers) PostShutdown(ctx *fiber.Ctx, cmd commands.Interface) error {
|
||||
func (h *Handlers) PostShutdown(ctx *fiber.Ctx, cmd commands.Interface) error {
|
||||
_, err := cmd.Execute(ctx.Context(), nil)
|
||||
if err != nil {
|
||||
klog.Error("execute command error, ", err, ", ", cmd.OperationName().Stirng())
|
||||
@@ -1,4 +1,4 @@
|
||||
package apiserver
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
@@ -16,7 +16,7 @@ type TerminusInitReq struct {
|
||||
Domain string `json:"domain"`
|
||||
}
|
||||
|
||||
func (h *handlers) PostTerminusInit(ctx *fiber.Ctx, cmd commands.Interface) error {
|
||||
func (h *Handlers) PostTerminusInit(ctx *fiber.Ctx, cmd commands.Interface) error {
|
||||
var req TerminusInitReq
|
||||
if err := h.ParseBody(ctx, &req); err != nil {
|
||||
klog.Error("parse request error, ", err)
|
||||
@@ -1,10 +1,10 @@
|
||||
package apiserver
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"github.com/beclab/Olares/daemon/pkg/cluster/state"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func (h *handlers) GetTerminusState(ctx *fiber.Ctx) error {
|
||||
func (h *Handlers) GetTerminusState(ctx *fiber.Ctx) error {
|
||||
return h.OkJSON(ctx, "success", state.CurrentState)
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package apiserver
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
func (h *handlers) PostTerminusUninstall(ctx *fiber.Ctx, cmd commands.Interface) error {
|
||||
func (h *Handlers) PostTerminusUninstall(ctx *fiber.Ctx, cmd commands.Interface) error {
|
||||
// run in background
|
||||
_, err := cmd.Execute(h.mainCtx, nil)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package apiserver
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
@@ -13,7 +13,7 @@ type UmountSmbReq struct {
|
||||
Path string ``
|
||||
}
|
||||
|
||||
func (h *handlers) umountSmbInNode(ctx *fiber.Ctx, cmd commands.Interface, pathInNode string) error {
|
||||
func (h *Handlers) umountSmbInNode(ctx *fiber.Ctx, cmd commands.Interface, pathInNode string) error {
|
||||
_, err := cmd.Execute(ctx.Context(), &umountsmb.Param{
|
||||
MountPath: pathInNode,
|
||||
})
|
||||
@@ -25,7 +25,7 @@ func (h *handlers) umountSmbInNode(ctx *fiber.Ctx, cmd commands.Interface, pathI
|
||||
return h.OkJSON(ctx, "success to umount")
|
||||
}
|
||||
|
||||
func (h *handlers) PostUmountSmb(ctx *fiber.Ctx, cmd commands.Interface) error {
|
||||
func (h *Handlers) PostUmountSmb(ctx *fiber.Ctx, cmd commands.Interface) error {
|
||||
var req UmountSmbReq
|
||||
if err := h.ParseBody(ctx, &req); err != nil {
|
||||
klog.Error("parse request error, ", err)
|
||||
@@ -38,7 +38,7 @@ func (h *handlers) PostUmountSmb(ctx *fiber.Ctx, cmd commands.Interface) error {
|
||||
return h.umountSmbInNode(ctx, cmd, req.Path)
|
||||
}
|
||||
|
||||
func (h *handlers) PostUmountSmbInCluster(ctx *fiber.Ctx, cmd commands.Interface) error {
|
||||
func (h *Handlers) PostUmountSmbInCluster(ctx *fiber.Ctx, cmd commands.Interface) error {
|
||||
var req UmountSmbReq
|
||||
if err := h.ParseBody(ctx, &req); err != nil {
|
||||
klog.Error("parse request error, ", err)
|
||||
@@ -1,4 +1,4 @@
|
||||
package apiserver
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
@@ -13,7 +13,7 @@ type UmountReq struct {
|
||||
Path string ``
|
||||
}
|
||||
|
||||
func (h *handlers) umountUsbInNode(ctx *fiber.Ctx, cmd commands.Interface, pathInNode string) error {
|
||||
func (h *Handlers) umountUsbInNode(ctx *fiber.Ctx, cmd commands.Interface, pathInNode string) error {
|
||||
_, err := cmd.Execute(ctx.Context(), &umountusb.Param{
|
||||
Path: pathInNode,
|
||||
})
|
||||
@@ -25,7 +25,7 @@ func (h *handlers) umountUsbInNode(ctx *fiber.Ctx, cmd commands.Interface, pathI
|
||||
return h.OkJSON(ctx, "success to umount")
|
||||
}
|
||||
|
||||
func (h *handlers) PostUmountUsb(ctx *fiber.Ctx, cmd commands.Interface) error {
|
||||
func (h *Handlers) PostUmountUsb(ctx *fiber.Ctx, cmd commands.Interface) error {
|
||||
var req UmountReq
|
||||
if err := h.ParseBody(ctx, &req); err != nil {
|
||||
klog.Error("parse request error, ", err)
|
||||
@@ -38,7 +38,7 @@ func (h *handlers) PostUmountUsb(ctx *fiber.Ctx, cmd commands.Interface) error {
|
||||
return h.umountUsbInNode(ctx, cmd, req.Path)
|
||||
}
|
||||
|
||||
func (h *handlers) PostUmountUsbInCluster(ctx *fiber.Ctx, cmd commands.Interface) error {
|
||||
func (h *Handlers) PostUmountUsbInCluster(ctx *fiber.Ctx, cmd commands.Interface) error {
|
||||
var req UmountReq
|
||||
if err := h.ParseBody(ctx, &req); err != nil {
|
||||
klog.Error("parse request error, ", err)
|
||||
@@ -1,4 +1,4 @@
|
||||
package apiserver
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -10,12 +10,19 @@ import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type handlers struct {
|
||||
type Handlers struct {
|
||||
mainCtx context.Context
|
||||
apList []ble.AccessPoint
|
||||
ApList []ble.AccessPoint
|
||||
}
|
||||
|
||||
func (h *handlers) ParseBody(ctx *fiber.Ctx, value any) error {
|
||||
var handlers *Handlers = &Handlers{}
|
||||
|
||||
func NewHandlers(ctx context.Context) *Handlers {
|
||||
handlers.mainCtx = ctx
|
||||
return handlers
|
||||
}
|
||||
|
||||
func (h *Handlers) ParseBody(ctx *fiber.Ctx, value any) error {
|
||||
err := ctx.BodyParser(value)
|
||||
|
||||
if err != nil {
|
||||
@@ -35,7 +42,7 @@ func (h *handlers) ParseBody(ctx *fiber.Ctx, value any) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *handlers) ErrJSON(ctx *fiber.Ctx, code int, message string, data ...interface{}) error {
|
||||
func (h *Handlers) ErrJSON(ctx *fiber.Ctx, code int, message string, data ...interface{}) error {
|
||||
switch len(data) {
|
||||
case 0:
|
||||
return ctx.Status(code).JSON(fiber.Map{
|
||||
@@ -58,10 +65,10 @@ func (h *handlers) ErrJSON(ctx *fiber.Ctx, code int, message string, data ...int
|
||||
|
||||
}
|
||||
|
||||
func (h *handlers) OkJSON(ctx *fiber.Ctx, message string, data ...interface{}) error {
|
||||
func (h *Handlers) OkJSON(ctx *fiber.Ctx, message string, data ...interface{}) error {
|
||||
return h.ErrJSON(ctx, http.StatusOK, message, data...)
|
||||
}
|
||||
|
||||
func (h *handlers) NeedChoiceJSON(ctx *fiber.Ctx, message string, data ...interface{}) error {
|
||||
func (h *Handlers) NeedChoiceJSON(ctx *fiber.Ctx, message string, data ...interface{}) error {
|
||||
return h.ErrJSON(ctx, http.StatusMultipleChoices, message, data...)
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package apiserver
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
@@ -1,4 +1,4 @@
|
||||
package apiserver
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
@@ -13,7 +13,7 @@ const (
|
||||
SIGNATURE_HEADER = "X-Signature"
|
||||
)
|
||||
|
||||
func (h *handlers) WaitServerRunning(next func(ctx *fiber.Ctx) error) func(ctx *fiber.Ctx) error {
|
||||
func (h *Handlers) WaitServerRunning(next func(ctx *fiber.Ctx) error) func(ctx *fiber.Ctx) error {
|
||||
return func(ctx *fiber.Ctx) error {
|
||||
if state.CurrentState.TerminusdState != state.Running {
|
||||
return h.ErrJSON(ctx, http.StatusForbidden, "server is not running, please wait and retry again later")
|
||||
@@ -23,7 +23,7 @@ func (h *handlers) WaitServerRunning(next func(ctx *fiber.Ctx) error) func(ctx *
|
||||
}
|
||||
}
|
||||
|
||||
func (h *handlers) RequireSignature(next func(ctx *fiber.Ctx) error) func(ctx *fiber.Ctx) error {
|
||||
func (h *Handlers) RequireSignature(next func(ctx *fiber.Ctx) error) func(ctx *fiber.Ctx) error {
|
||||
return func(ctx *fiber.Ctx) error {
|
||||
headers := ctx.GetReqHeaders()
|
||||
signature, ok := headers[SIGNATURE_HEADER]
|
||||
@@ -42,7 +42,7 @@ func (h *handlers) RequireSignature(next func(ctx *fiber.Ctx) error) func(ctx *f
|
||||
}
|
||||
}
|
||||
|
||||
func (h *handlers) RunCommand(next func(ctx *fiber.Ctx, cmd commands.Interface) error,
|
||||
func (h *Handlers) RunCommand(next func(ctx *fiber.Ctx, cmd commands.Interface) error,
|
||||
cmdNew func() commands.Interface) func(ctx *fiber.Ctx) error {
|
||||
|
||||
return func(ctx *fiber.Ctx) error {
|
||||
25
daemon/internel/apiserver/handlers/system_group.go
Normal file
25
daemon/internel/apiserver/handlers/system_group.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"github.com/beclab/Olares/daemon/internel/apiserver/server"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
func init() {
|
||||
s := server.API
|
||||
system := s.App.Group("system")
|
||||
system.Get("/status", handlers.RequireSignature(handlers.GetTerminusState))
|
||||
system.Get("/ifs", handlers.RequireSignature(handlers.GetNetIfs))
|
||||
system.Get("/hosts-file", handlers.RequireSignature(handlers.GetHostsfile))
|
||||
system.Post("/hosts-file", handlers.RequireSignature(handlers.PostHostsfile))
|
||||
system.Get("/mounted-usb", handlers.RequireSignature(handlers.GetMountedUsb))
|
||||
system.Get("/mounted-hdd", handlers.RequireSignature(handlers.GetMountedHdd))
|
||||
system.Get("/mounted-smb", handlers.RequireSignature(handlers.GetMountedSmb))
|
||||
system.Get("/mounted-path", handlers.RequireSignature(handlers.GetMountedPath))
|
||||
system.Get("/mounted-usb-incluster", handlers.RequireSignature(handlers.GetMountedUsbInCluster))
|
||||
system.Get("/mounted-hdd-incluster", handlers.RequireSignature(handlers.GetMountedHddInCluster))
|
||||
system.Get("/mounted-smb-incluster", handlers.RequireSignature(handlers.GetMountedSmbInCluster))
|
||||
system.Get("/mounted-path-incluster", handlers.RequireSignature(handlers.GetMountedPathInCluster))
|
||||
|
||||
klog.Info("system handlers initialized")
|
||||
}
|
||||
@@ -2,146 +2,26 @@ package apiserver
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/beclab/Olares/daemon/internel/apiserver/handlers"
|
||||
"github.com/beclab/Olares/daemon/internel/apiserver/server"
|
||||
"github.com/beclab/Olares/daemon/internel/ble"
|
||||
changehost "github.com/beclab/Olares/daemon/pkg/commands/change_host"
|
||||
collectlogs "github.com/beclab/Olares/daemon/pkg/commands/collect_logs"
|
||||
connectwifi "github.com/beclab/Olares/daemon/pkg/commands/connect_wifi"
|
||||
"github.com/beclab/Olares/daemon/pkg/commands/install"
|
||||
mountsmb "github.com/beclab/Olares/daemon/pkg/commands/mount_smb"
|
||||
"github.com/beclab/Olares/daemon/pkg/commands/reboot"
|
||||
"github.com/beclab/Olares/daemon/pkg/commands/shutdown"
|
||||
umountsmb "github.com/beclab/Olares/daemon/pkg/commands/umount_smb"
|
||||
umountusb "github.com/beclab/Olares/daemon/pkg/commands/umount_usb"
|
||||
"github.com/beclab/Olares/daemon/pkg/commands/uninstall"
|
||||
"github.com/beclab/Olares/daemon/pkg/commands/upgrade"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/cors"
|
||||
"github.com/gofiber/fiber/v2/middleware/logger"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
type server struct {
|
||||
handlers *handlers
|
||||
port int
|
||||
app *fiber.App
|
||||
}
|
||||
func NewServer(ctx context.Context, port int) *server.Server {
|
||||
server.API.Port = port
|
||||
h := handlers.NewHandlers(ctx)
|
||||
|
||||
func NewServer(ctx context.Context, port int) (*server, error) {
|
||||
return &server{handlers: &handlers{mainCtx: ctx}, port: port}, nil
|
||||
}
|
||||
|
||||
func (s *server) Start() error {
|
||||
app := fiber.New()
|
||||
s.app = app
|
||||
|
||||
app.Use(cors.New())
|
||||
app.Use(logger.New())
|
||||
|
||||
cmd := app.Group("command")
|
||||
cmd.Post("/install", s.handlers.RequireSignature(
|
||||
s.handlers.WaitServerRunning(
|
||||
s.handlers.RunCommand(s.handlers.PostTerminusInit, install.New))))
|
||||
|
||||
cmd.Post("/uninstall", s.handlers.RequireSignature(
|
||||
s.handlers.WaitServerRunning(
|
||||
s.handlers.RunCommand(s.handlers.PostTerminusUninstall, uninstall.New))))
|
||||
|
||||
cmd.Post("/upgrade", s.handlers.RequireSignature(
|
||||
s.handlers.WaitServerRunning(
|
||||
s.handlers.RunCommand(s.handlers.RequestOlaresUpgrade, upgrade.NewCreateUpgradeTarget))))
|
||||
|
||||
cmd.Delete("/upgrade", s.handlers.RequireSignature(
|
||||
s.handlers.RunCommand(s.handlers.CancelOlaresUpgrade, upgrade.NewRemoveUpgradeTarget)))
|
||||
|
||||
cmd.Post("/reboot", s.handlers.RequireSignature(
|
||||
s.handlers.WaitServerRunning(
|
||||
s.handlers.RunCommand(s.handlers.PostReboot, reboot.New))))
|
||||
|
||||
cmd.Post("/shutdown", s.handlers.RequireSignature(
|
||||
s.handlers.WaitServerRunning(
|
||||
s.handlers.RunCommand(s.handlers.PostShutdown, shutdown.New))))
|
||||
|
||||
cmd.Post("/connect-wifi", s.handlers.RequireSignature(
|
||||
s.handlers.WaitServerRunning(
|
||||
s.handlers.RunCommand(s.handlers.PostConnectWifi, connectwifi.New))))
|
||||
|
||||
cmd.Post("/change-host", s.handlers.RequireSignature(
|
||||
s.handlers.WaitServerRunning(
|
||||
s.handlers.RunCommand(s.handlers.PostChangeHost, changehost.New))))
|
||||
|
||||
cmd.Post("/umount-usb", s.handlers.RequireSignature(
|
||||
s.handlers.WaitServerRunning(
|
||||
s.handlers.RunCommand(s.handlers.PostUmountUsb, umountusb.New))))
|
||||
|
||||
cmd.Post("/umount-usb-incluster", s.handlers.RequireSignature(
|
||||
s.handlers.WaitServerRunning(
|
||||
s.handlers.RunCommand(s.handlers.PostUmountUsbInCluster, umountusb.New))))
|
||||
|
||||
cmd.Post("/collect-logs", s.handlers.RequireSignature(
|
||||
s.handlers.WaitServerRunning(
|
||||
s.handlers.RunCommand(s.handlers.PostCollectLogs, collectlogs.New))))
|
||||
|
||||
cmd.Post("/mount-samba", s.handlers.RequireSignature(
|
||||
s.handlers.WaitServerRunning(
|
||||
s.handlers.RunCommand(s.handlers.PostMountSambaDriver, mountsmb.New))))
|
||||
|
||||
cmd.Post("/umount-samba", s.handlers.RequireSignature(
|
||||
s.handlers.WaitServerRunning(
|
||||
s.handlers.RunCommand(s.handlers.PostUmountSmb, umountsmb.New))))
|
||||
|
||||
cmd.Post("/umount-samba-incluster", s.handlers.RequireSignature(
|
||||
s.handlers.WaitServerRunning(
|
||||
s.handlers.RunCommand(s.handlers.PostUmountSmbInCluster, umountsmb.New))))
|
||||
|
||||
cmdv2 := cmd.Group("v2")
|
||||
cmdv2.Post("/mount-samba", s.handlers.RequireSignature(
|
||||
s.handlers.WaitServerRunning(
|
||||
s.handlers.RunCommand(s.handlers.PostMountSambaDriverV2, mountsmb.New))))
|
||||
|
||||
system := app.Group("system")
|
||||
system.Get("/status", s.handlers.RequireSignature(s.handlers.GetTerminusState))
|
||||
system.Get("/ifs", s.handlers.RequireSignature(s.handlers.GetNetIfs))
|
||||
system.Get("/hosts-file", s.handlers.RequireSignature(s.handlers.GetHostsfile))
|
||||
system.Post("/hosts-file", s.handlers.RequireSignature(s.handlers.PostHostsfile))
|
||||
system.Get("/mounted-usb", s.handlers.RequireSignature(s.handlers.GetMountedUsb))
|
||||
system.Get("/mounted-hdd", s.handlers.RequireSignature(s.handlers.GetMountedHdd))
|
||||
system.Get("/mounted-smb", s.handlers.RequireSignature(s.handlers.GetMountedSmb))
|
||||
system.Get("/mounted-path", s.handlers.RequireSignature(s.handlers.GetMountedPath))
|
||||
system.Get("/mounted-usb-incluster", s.handlers.RequireSignature(s.handlers.GetMountedUsbInCluster))
|
||||
system.Get("/mounted-hdd-incluster", s.handlers.RequireSignature(s.handlers.GetMountedHddInCluster))
|
||||
system.Get("/mounted-smb-incluster", s.handlers.RequireSignature(s.handlers.GetMountedSmbInCluster))
|
||||
system.Get("/mounted-path-incluster", s.handlers.RequireSignature(s.handlers.GetMountedPathInCluster))
|
||||
|
||||
containerd := app.Group("containerd")
|
||||
containerd.Get("/registries", s.handlers.RequireSignature(s.handlers.ListRegistries))
|
||||
|
||||
registry := containerd.Group("registry")
|
||||
mirrors := registry.Group("mirrors")
|
||||
|
||||
mirrors.Get("/", s.handlers.RequireSignature(s.handlers.GetRegistryMirrors))
|
||||
mirrors.Get("/:registry", s.handlers.RequireSignature(s.handlers.GetRegistryMirror))
|
||||
mirrors.Put("/:registry", s.handlers.RequireSignature(s.handlers.UpdateRegistryMirror))
|
||||
mirrors.Delete("/:registry", s.handlers.RequireSignature(s.handlers.DeleteRegistryMirror))
|
||||
|
||||
image := containerd.Group("images")
|
||||
|
||||
image.Get("/", s.handlers.RequireSignature(s.handlers.ListImages))
|
||||
image.Delete("/:image", s.handlers.RequireSignature(s.handlers.DeleteImage))
|
||||
image.Post("/prune", s.handlers.RequireSignature(s.handlers.PruneImages))
|
||||
|
||||
return app.Listen(fmt.Sprintf(":%d", s.port))
|
||||
}
|
||||
|
||||
func (s *server) Shutdown() error {
|
||||
klog.Info("shutdown api server")
|
||||
if s.app == nil {
|
||||
return nil
|
||||
server.API.UpdateAps = func(aplist []ble.AccessPoint) {
|
||||
h.ApList = aplist
|
||||
}
|
||||
return s.app.Shutdown()
|
||||
}
|
||||
|
||||
func (s *server) UpdateAps(aplist []ble.AccessPoint) {
|
||||
s.handlers.apList = aplist
|
||||
s := server.API
|
||||
|
||||
s.App.Use(cors.New())
|
||||
s.App.Use(logger.New())
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
31
daemon/internel/apiserver/server/api.go
Normal file
31
daemon/internel/apiserver/server/api.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/beclab/Olares/daemon/internel/ble"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
Port int
|
||||
App *fiber.App
|
||||
UpdateAps func(aplist []ble.AccessPoint)
|
||||
}
|
||||
|
||||
var API *Server = &Server{
|
||||
App: fiber.New(),
|
||||
}
|
||||
|
||||
func (s *Server) Start() error {
|
||||
return s.App.Listen(fmt.Sprintf(":%d", s.Port))
|
||||
}
|
||||
|
||||
func (s *Server) Shutdown() error {
|
||||
klog.Info("shutdown api server")
|
||||
if s.App == nil {
|
||||
return nil
|
||||
}
|
||||
return s.App.Shutdown()
|
||||
}
|
||||
Reference in New Issue
Block a user