-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathapi.go
More file actions
103 lines (85 loc) · 5.16 KB
/
Copy pathapi.go
File metadata and controls
103 lines (85 loc) · 5.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// This file is part of arduino-app-cli.
//
// Copyright 2025 ARDUINO SA (http://www.arduino.cc/)
//
// This software is released under the GNU General Public License version 3,
// which covers the main part of arduino-app-cli.
// The terms of this license can be found at:
// https://www.gnu.org/licenses/gpl-3.0.en.html
//
// You can be released from the requirements of the above licenses by purchasing
// a commercial license. Buying such a license is mandatory if you want to
// modify or otherwise use the software for commercial activities involving the
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc.
package api
import (
"embed"
"net/http"
"github.com/arduino/arduino-app-cli/internal/api/handlers"
"github.com/arduino/arduino-app-cli/internal/orchestrator"
"github.com/arduino/arduino-app-cli/internal/orchestrator/app"
"github.com/arduino/arduino-app-cli/internal/orchestrator/bricks"
"github.com/arduino/arduino-app-cli/internal/orchestrator/bricksindex"
"github.com/arduino/arduino-app-cli/internal/orchestrator/config"
"github.com/arduino/arduino-app-cli/internal/orchestrator/modelsindex"
"github.com/arduino/arduino-app-cli/internal/store"
"github.com/arduino/arduino-app-cli/internal/update"
"github.com/docker/cli/cli/command"
_ "net/http/pprof" //nolint:gosec // pprof import is safe for profiling endpoints
)
//go:embed docs
var docsFS embed.FS
func NewHTTPRouter(
dockerClient command.Cli,
version string,
updater *update.Manager,
provisioner *orchestrator.Provision,
staticStore *store.StaticStore,
modelsIndex *modelsindex.ModelsIndex,
bricksIndex *bricksindex.BricksIndex,
brickService *bricks.Service,
idProvider *app.IDProvider,
cfg config.Configuration,
allowedOrigins []string,
) http.Handler {
mux := http.NewServeMux()
mux.Handle("GET /debug/", http.DefaultServeMux) // pprof endpoints
mux.Handle("GET /v1/version", handlers.HandlerVersion(version))
mux.Handle("GET /v1/config", handlers.HandleConfig(cfg))
mux.Handle("GET /v1/bricks", handlers.HandleBrickList(brickService))
mux.Handle("GET /v1/bricks/{brickID}", handlers.HandleBrickDetails(brickService, idProvider, cfg))
mux.Handle("GET /v1/properties", handlers.HandlePropertyKeys(cfg))
mux.Handle("GET /v1/properties/{key}", handlers.HandlePropertyGet(cfg))
mux.Handle("PUT /v1/properties/{key}", handlers.HandlePropertyUpsert(cfg))
mux.Handle("DELETE /v1/properties/{key}", handlers.HandlePropertyDelete(cfg))
mux.Handle("GET /v1/system/update/check", handlers.HandleCheckUpgradable(cfg, updater))
mux.Handle("GET /v1/system/update/events", handlers.HandleUpdateEvents(updater))
mux.Handle("PUT /v1/system/update/apply", handlers.HandleUpdateApply(cfg, updater))
mux.Handle("GET /v1/system/resources", handlers.HandleSystemResources())
mux.Handle("GET /v1/models", handlers.HandleModelsList(modelsIndex))
mux.Handle("GET /v1/models/{modelID}", handlers.HandlerModelByID(modelsIndex))
mux.Handle("GET /v1/apps", handlers.HandleAppList(dockerClient, idProvider, cfg))
mux.Handle("POST /v1/apps", handlers.HandleAppCreate(idProvider, cfg))
mux.Handle("GET /v1/apps/events", handlers.HandlerAppStatus(dockerClient, idProvider, cfg))
mux.Handle("GET /v1/apps/{appID}", handlers.HandleAppDetails(dockerClient, bricksIndex, idProvider, cfg))
mux.Handle("PATCH /v1/apps/{appID}", handlers.HandleAppDetailsEdits(dockerClient, bricksIndex, idProvider, cfg))
mux.Handle("GET /v1/apps/{appID}/logs", handlers.HandleAppLogs(dockerClient, idProvider, staticStore))
mux.Handle("POST /v1/apps/{appID}/start", handlers.HandleAppStart(dockerClient, provisioner, modelsIndex, bricksIndex, idProvider, cfg, staticStore))
mux.Handle("POST /v1/apps/{appID}/stop", handlers.HandleAppStop(dockerClient, idProvider))
mux.Handle("POST /v1/apps/{appID}/clone", handlers.HandleAppClone(dockerClient, idProvider, cfg))
mux.Handle("DELETE /v1/apps/{appID}", handlers.HandleAppDelete(dockerClient, idProvider))
mux.Handle("GET /v1/apps/{appID}/exposed-ports", handlers.HandleAppPorts(bricksIndex, idProvider))
mux.Handle("PUT /v1/apps/{appID}/sketch/libraries/{libRef}", handlers.HandleSketchAddLibrary(idProvider))
mux.Handle("DELETE /v1/apps/{appID}/sketch/libraries/{libRef}", handlers.HandleSketchRemoveLibrary(idProvider))
mux.Handle("GET /v1/apps/{appID}/sketch/libraries", handlers.HandleSketchListLibraries(idProvider))
mux.Handle("GET /v1/apps/{appID}/bricks", handlers.HandleAppBrickInstancesList(brickService, idProvider))
mux.Handle("GET /v1/apps/{appID}/bricks/{brickID}", handlers.HandleAppBrickInstanceDetails(brickService, idProvider))
mux.Handle("PUT /v1/apps/{appID}/bricks/{brickID}", handlers.HandleBrickCreate(brickService, idProvider))
mux.Handle("PATCH /v1/apps/{appID}/bricks/{brickID}", handlers.HandleBrickUpdates(brickService, idProvider))
mux.Handle("DELETE /v1/apps/{appID}/bricks/{brickID}", handlers.HandleBrickDelete(brickService, idProvider))
mux.Handle("GET /v1/docs/", http.StripPrefix("/v1/docs/", handlers.DocsServer(docsFS)))
mux.Handle("GET /v1/monitor/ws", handlers.HandleMonitorWS(allowedOrigins))
mux.Handle("GET /v1/libraries", handlers.HandleLibraryList(cfg.LibrariesAPIURL, version))
return mux
}