@gokiteam/goki-dev 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +478 -0
- package/bin/goki-dev.js +452 -0
- package/bin/mcp-server.js +16 -0
- package/bin/secrets-cli.js +302 -0
- package/cli/ComposeOverrideGenerator.js +226 -0
- package/cli/ComposeParser.js +73 -0
- package/cli/ConfigGenerator.js +304 -0
- package/cli/ConfigManager.js +46 -0
- package/cli/DatabaseManager.js +94 -0
- package/cli/DevToolsChecker.js +21 -0
- package/cli/DevToolsDir.js +66 -0
- package/cli/DevToolsManager.js +451 -0
- package/cli/DockerManager.js +138 -0
- package/cli/FunctionManager.js +95 -0
- package/cli/HttpProxyRewriter.js +91 -0
- package/cli/Logger.js +10 -0
- package/cli/McpConfigManager.js +123 -0
- package/cli/NgrokManager.js +431 -0
- package/cli/ProjectCLI.js +2322 -0
- package/cli/PubSubManager.js +129 -0
- package/cli/SnapshotManager.js +88 -0
- package/cli/UiFormatter.js +292 -0
- package/cli/WebhookUrlRewriter.js +32 -0
- package/cli/secrets/BiometricAuth.js +125 -0
- package/cli/secrets/SecretInjector.js +47 -0
- package/cli/secrets/SecretsConfig.js +141 -0
- package/cli/secrets/SecretsDoctor.js +384 -0
- package/cli/secrets/SecretsManager.js +255 -0
- package/client/dist/client.d.ts +332 -0
- package/client/dist/client.js +507 -0
- package/client/dist/helpers.d.ts +62 -0
- package/client/dist/helpers.js +122 -0
- package/client/dist/index.d.ts +59 -0
- package/client/dist/index.js +78 -0
- package/client/dist/package.json +1 -0
- package/client/dist/types.d.ts +280 -0
- package/client/dist/types.js +7 -0
- package/config.development +46 -0
- package/config.test +18 -0
- package/guidelines/CodingStyleGuideline.md +148 -0
- package/guidelines/CommentingGuideline.md +10 -0
- package/guidelines/HttpApiImplementationGuideline.md +137 -0
- package/guidelines/NamingGuideline.md +182 -0
- package/package.json +138 -0
- package/patterns/api/[collectionName]/Controllers.md +62 -0
- package/patterns/api/[collectionName]/Logic.md +154 -0
- package/patterns/api/[collectionName]/Permissions.md +81 -0
- package/patterns/api/[collectionName]/Router.md +83 -0
- package/patterns/api/[collectionName]/Schemas.md +197 -0
- package/patterns/configs/Patterns.md +7 -0
- package/patterns/enums/Patterns.md +24 -0
- package/patterns/errorHandling/Patterns.md +185 -0
- package/patterns/testing/Patterns.md +232 -0
- package/src/Server.js +238 -0
- package/src/api/dashboard/Controllers.js +9 -0
- package/src/api/dashboard/Logic.js +76 -0
- package/src/api/dashboard/Router.js +11 -0
- package/src/api/dashboard/Schemas.js +47 -0
- package/src/api/data/Controllers.js +26 -0
- package/src/api/data/Logic.js +188 -0
- package/src/api/data/Router.js +16 -0
- package/src/api/docker/Controllers.js +33 -0
- package/src/api/docker/Logic.js +268 -0
- package/src/api/docker/Router.js +15 -0
- package/src/api/docker/Schemas.js +80 -0
- package/src/api/docs/Controllers.js +15 -0
- package/src/api/docs/Logic.js +85 -0
- package/src/api/docs/Router.js +12 -0
- package/src/api/export/Controllers.js +30 -0
- package/src/api/export/Logic.js +143 -0
- package/src/api/export/Router.js +18 -0
- package/src/api/export/Schemas.js +104 -0
- package/src/api/firestore/Controllers.js +152 -0
- package/src/api/firestore/Logic.js +474 -0
- package/src/api/firestore/Router.js +23 -0
- package/src/api/functions/Controllers.js +261 -0
- package/src/api/functions/Logic.js +710 -0
- package/src/api/functions/Router.js +50 -0
- package/src/api/functions/Schemas.js +193 -0
- package/src/api/gateway/Controllers.js +72 -0
- package/src/api/gateway/Logic.js +74 -0
- package/src/api/gateway/Router.js +10 -0
- package/src/api/gateway/Schemas.js +19 -0
- package/src/api/health/Controllers.js +14 -0
- package/src/api/health/Logic.js +24 -0
- package/src/api/health/Router.js +12 -0
- package/src/api/httpTraffic/Controllers.js +29 -0
- package/src/api/httpTraffic/Logic.js +33 -0
- package/src/api/httpTraffic/Router.js +9 -0
- package/src/api/httpTraffic/Schemas.js +23 -0
- package/src/api/logging/Controllers.js +80 -0
- package/src/api/logging/Logic.js +461 -0
- package/src/api/logging/Router.js +24 -0
- package/src/api/logging/Schemas.js +43 -0
- package/src/api/mqtt/Controllers.js +17 -0
- package/src/api/mqtt/Logic.js +66 -0
- package/src/api/mqtt/Router.js +12 -0
- package/src/api/postgres/Controllers.js +97 -0
- package/src/api/postgres/Logic.js +221 -0
- package/src/api/postgres/Router.js +21 -0
- package/src/api/pubsub/Controllers.js +236 -0
- package/src/api/pubsub/Logic.js +732 -0
- package/src/api/pubsub/Router.js +41 -0
- package/src/api/pubsub/Schemas.js +355 -0
- package/src/api/redis/Controllers.js +63 -0
- package/src/api/redis/Logic.js +239 -0
- package/src/api/redis/Router.js +21 -0
- package/src/api/scheduler/Controllers.js +27 -0
- package/src/api/scheduler/Logic.js +49 -0
- package/src/api/scheduler/Router.js +16 -0
- package/src/api/services/Controllers.js +26 -0
- package/src/api/services/Logic.js +205 -0
- package/src/api/services/Router.js +14 -0
- package/src/api/services/Schemas.js +66 -0
- package/src/api/snapshots/Controllers.js +37 -0
- package/src/api/snapshots/Logic.js +797 -0
- package/src/api/snapshots/Router.js +15 -0
- package/src/api/snapshots/Schemas.js +23 -0
- package/src/api/webhooks/Controllers.js +49 -0
- package/src/api/webhooks/Logic.js +137 -0
- package/src/api/webhooks/Router.js +12 -0
- package/src/api/webhooks/Schemas.js +31 -0
- package/src/configs/Application.js +147 -0
- package/src/configs/Default.js +13 -0
- package/src/consumers/BlackboxLogsConsumer.js +235 -0
- package/src/consumers/DockerLogsConsumer.js +687 -0
- package/src/db/Tables.js +66 -0
- package/src/db/schemas/firestore.js +18 -0
- package/src/db/schemas/functions.js +65 -0
- package/src/db/schemas/httpTraffic.js +43 -0
- package/src/db/schemas/logging.js +74 -0
- package/src/db/schemas/migrations.js +64 -0
- package/src/db/schemas/mqtt.js +56 -0
- package/src/db/schemas/pubsub.js +90 -0
- package/src/db/schemas/pubsubRegistry.js +22 -0
- package/src/db/schemas/webhooks.js +28 -0
- package/src/emulation/awsiot/Controllers.js +91 -0
- package/src/emulation/awsiot/Logic.js +70 -0
- package/src/emulation/awsiot/Router.js +19 -0
- package/src/emulation/awsiot/Server.js +100 -0
- package/src/emulation/firestore/Server.js +136 -0
- package/src/emulation/logging/Controllers.js +212 -0
- package/src/emulation/logging/Logic.js +416 -0
- package/src/emulation/logging/Router.js +36 -0
- package/src/emulation/logging/Schemas.js +82 -0
- package/src/emulation/logging/Server.js +108 -0
- package/src/emulation/pubsub/Controllers.js +279 -0
- package/src/emulation/pubsub/DefaultTopics.js +162 -0
- package/src/emulation/pubsub/Logic.js +427 -0
- package/src/emulation/pubsub/README.md +309 -0
- package/src/emulation/pubsub/Router.js +33 -0
- package/src/emulation/pubsub/Server.js +104 -0
- package/src/emulation/pubsub/ShadowPoller.js +276 -0
- package/src/emulation/pubsub/ShadowSubscriptionManager.js +199 -0
- package/src/enums/ContainerNames.js +106 -0
- package/src/enums/ErrorReason.js +28 -0
- package/src/enums/FunctionStatuses.js +15 -0
- package/src/enums/FunctionTriggerTypes.js +15 -0
- package/src/enums/GatewayState.js +7 -0
- package/src/enums/ServiceNames.js +68 -0
- package/src/jobs/DatabaseMaintenance.js +184 -0
- package/src/jobs/MessageHistoryCleanup.js +152 -0
- package/src/mcp/ApiClient.js +25 -0
- package/src/mcp/Server.js +52 -0
- package/src/mcp/prompts/debugging.js +104 -0
- package/src/mcp/resources/platform.js +118 -0
- package/src/mcp/tools/data.js +84 -0
- package/src/mcp/tools/docker.js +166 -0
- package/src/mcp/tools/firestore.js +162 -0
- package/src/mcp/tools/functions.js +380 -0
- package/src/mcp/tools/httpTraffic.js +69 -0
- package/src/mcp/tools/logging.js +174 -0
- package/src/mcp/tools/mqtt.js +37 -0
- package/src/mcp/tools/postgres.js +130 -0
- package/src/mcp/tools/pubsub.js +316 -0
- package/src/mcp/tools/redis.js +146 -0
- package/src/mcp/tools/services.js +169 -0
- package/src/mcp/tools/snapshots.js +88 -0
- package/src/mcp/tools/webhooks.js +115 -0
- package/src/middleware/DevProxy.js +67 -0
- package/src/middleware/ErrorCatcher.js +35 -0
- package/src/middleware/HttpProxy.js +215 -0
- package/src/middleware/Reply.js +24 -0
- package/src/middleware/TraceId.js +9 -0
- package/src/middleware/WebhookProxy.js +234 -0
- package/src/protocols/mqtt/Broker.js +92 -0
- package/src/protocols/mqtt/Handlers.js +175 -0
- package/src/protocols/mqtt/PubSubBridge.js +162 -0
- package/src/protocols/mqtt/Server.js +116 -0
- package/src/runtime/FunctionRunner.js +179 -0
- package/src/services/AppGatewayService.js +582 -0
- package/src/singletons/FirestoreBroadcaster.js +367 -0
- package/src/singletons/FunctionTriggerDispatcher.js +456 -0
- package/src/singletons/FunctionsService.js +418 -0
- package/src/singletons/HttpProxy.js +224 -0
- package/src/singletons/LogBroadcaster.js +159 -0
- package/src/singletons/Logger.js +49 -0
- package/src/singletons/MemoryJsonStore.js +175 -0
- package/src/singletons/MessageBroadcaster.js +190 -0
- package/src/singletons/PostgresBroadcaster.js +367 -0
- package/src/singletons/PostgresClient.js +180 -0
- package/src/singletons/RedisClient.js +184 -0
- package/src/singletons/SqliteStore.js +480 -0
- package/src/singletons/TickService.js +151 -0
- package/src/singletons/WebhookProxy.js +223 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Logic } from './Logic.js'
|
|
2
|
+
|
|
3
|
+
export const Controllers = {
|
|
4
|
+
async startTick (ctx) {
|
|
5
|
+
const { traceId } = ctx.state
|
|
6
|
+
const result = await Logic.startTick({ traceId })
|
|
7
|
+
ctx.reply(result)
|
|
8
|
+
},
|
|
9
|
+
|
|
10
|
+
async stopTick (ctx) {
|
|
11
|
+
const { traceId } = ctx.state
|
|
12
|
+
const result = await Logic.stopTick({ traceId })
|
|
13
|
+
ctx.reply(result)
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
async getTickStatus (ctx) {
|
|
17
|
+
const { traceId } = ctx.state
|
|
18
|
+
const result = Logic.getTickStatus({ traceId })
|
|
19
|
+
ctx.reply(result)
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
async triggerTick (ctx) {
|
|
23
|
+
const { traceId } = ctx.state
|
|
24
|
+
const result = await Logic.triggerTick({ traceId })
|
|
25
|
+
ctx.reply(result)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { TickService } from '../../singletons/TickService.js'
|
|
2
|
+
|
|
3
|
+
export const Logic = {
|
|
4
|
+
async startTick (params) {
|
|
5
|
+
const { traceId } = params
|
|
6
|
+
const result = await TickService.start()
|
|
7
|
+
return {
|
|
8
|
+
...result,
|
|
9
|
+
...TickService.getStatus(),
|
|
10
|
+
traceId
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
stopTick (params) {
|
|
15
|
+
const { traceId } = params
|
|
16
|
+
const result = TickService.stop()
|
|
17
|
+
return {
|
|
18
|
+
...result,
|
|
19
|
+
...TickService.getStatus(),
|
|
20
|
+
traceId
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
getTickStatus (params) {
|
|
25
|
+
const { traceId } = params
|
|
26
|
+
return {
|
|
27
|
+
...TickService.getStatus(),
|
|
28
|
+
traceId
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
async triggerTick (params) {
|
|
33
|
+
const { traceId } = params
|
|
34
|
+
try {
|
|
35
|
+
await TickService.publishTick()
|
|
36
|
+
return {
|
|
37
|
+
tickTime: new Date().toISOString(),
|
|
38
|
+
published: true,
|
|
39
|
+
traceId
|
|
40
|
+
}
|
|
41
|
+
} catch (error) {
|
|
42
|
+
return {
|
|
43
|
+
status: 'error',
|
|
44
|
+
message: error.message,
|
|
45
|
+
traceId
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import KoaRouter from 'koa-router'
|
|
2
|
+
import { Controllers } from './Controllers.js'
|
|
3
|
+
|
|
4
|
+
const Router = new KoaRouter()
|
|
5
|
+
const v1 = new KoaRouter({ prefix: '/v1/scheduler' })
|
|
6
|
+
|
|
7
|
+
v1.post('/tick/start', Controllers.startTick)
|
|
8
|
+
v1.post('/tick/stop', Controllers.stopTick)
|
|
9
|
+
v1.post('/tick/status', Controllers.getTickStatus)
|
|
10
|
+
|
|
11
|
+
// Testing Helpers
|
|
12
|
+
v1.post('/tick/trigger', Controllers.triggerTick)
|
|
13
|
+
|
|
14
|
+
Router.use(v1.routes())
|
|
15
|
+
|
|
16
|
+
export { Router }
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Logic } from './Logic.js'
|
|
2
|
+
|
|
3
|
+
export const Controllers = {
|
|
4
|
+
async list (ctx) {
|
|
5
|
+
const { traceId } = ctx.state
|
|
6
|
+
const result = await Logic.list({ traceId })
|
|
7
|
+
ctx.reply(result)
|
|
8
|
+
},
|
|
9
|
+
async status (ctx) {
|
|
10
|
+
const { traceId } = ctx.state
|
|
11
|
+
const result = await Logic.status({ traceId })
|
|
12
|
+
ctx.reply(result)
|
|
13
|
+
},
|
|
14
|
+
async restart (ctx) {
|
|
15
|
+
const { traceId } = ctx.state
|
|
16
|
+
const { serviceName } = ctx.request.body
|
|
17
|
+
const result = await Logic.restart({ serviceName, traceId })
|
|
18
|
+
ctx.reply(result)
|
|
19
|
+
},
|
|
20
|
+
async healthCheck (ctx) {
|
|
21
|
+
const { traceId } = ctx.state
|
|
22
|
+
const { healthEndpoint } = ctx.request.body
|
|
23
|
+
const result = await Logic.healthCheck({ healthEndpoint, traceId })
|
|
24
|
+
ctx.reply(result)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { Application } from '../../configs/Application.js'
|
|
2
|
+
import { MqttServer } from '../../protocols/mqtt/Server.js'
|
|
3
|
+
import { FirestoreEmulator } from '../../emulation/firestore/Server.js'
|
|
4
|
+
import { AppGatewayService } from '../../services/AppGatewayService.js'
|
|
5
|
+
import { ServiceNames, ServiceDisplayNames, ServiceDescriptions, isValidServiceName } from '../../enums/ServiceNames.js'
|
|
6
|
+
|
|
7
|
+
export const Logic = {
|
|
8
|
+
async list (params) {
|
|
9
|
+
const { traceId } = params
|
|
10
|
+
const { ports } = Application
|
|
11
|
+
const startTime = Application.runId
|
|
12
|
+
const currentTime = Date.now()
|
|
13
|
+
const uptime = currentTime - startTime
|
|
14
|
+
|
|
15
|
+
const services = [
|
|
16
|
+
{
|
|
17
|
+
name: ServiceNames.PUBSUB,
|
|
18
|
+
displayName: ServiceDisplayNames[ServiceNames.PUBSUB],
|
|
19
|
+
port: ports.pubsub,
|
|
20
|
+
status: 'running',
|
|
21
|
+
uptime,
|
|
22
|
+
description: ServiceDescriptions[ServiceNames.PUBSUB],
|
|
23
|
+
capabilities: {
|
|
24
|
+
canStart: false,
|
|
25
|
+
canStop: false,
|
|
26
|
+
canRestart: false
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: ServiceNames.MQTT,
|
|
31
|
+
displayName: ServiceDisplayNames[ServiceNames.MQTT],
|
|
32
|
+
port: ports.mqtt,
|
|
33
|
+
status: 'running',
|
|
34
|
+
uptime,
|
|
35
|
+
description: ServiceDescriptions[ServiceNames.MQTT],
|
|
36
|
+
capabilities: {
|
|
37
|
+
canStart: true,
|
|
38
|
+
canStop: true,
|
|
39
|
+
canRestart: true
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: ServiceNames.FIRESTORE,
|
|
44
|
+
displayName: ServiceDisplayNames[ServiceNames.FIRESTORE],
|
|
45
|
+
port: ports.firestore,
|
|
46
|
+
status: 'running',
|
|
47
|
+
uptime,
|
|
48
|
+
description: ServiceDescriptions[ServiceNames.FIRESTORE],
|
|
49
|
+
capabilities: {
|
|
50
|
+
canStart: true,
|
|
51
|
+
canStop: true,
|
|
52
|
+
canRestart: true
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: ServiceNames.WEBUI,
|
|
57
|
+
displayName: ServiceDisplayNames[ServiceNames.WEBUI],
|
|
58
|
+
port: ports.webUi,
|
|
59
|
+
status: 'running',
|
|
60
|
+
uptime,
|
|
61
|
+
description: ServiceDescriptions[ServiceNames.WEBUI],
|
|
62
|
+
capabilities: {
|
|
63
|
+
canStart: false,
|
|
64
|
+
canStop: false,
|
|
65
|
+
canRestart: false
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: ServiceNames.APP_GATEWAY,
|
|
70
|
+
displayName: ServiceDisplayNames[ServiceNames.APP_GATEWAY],
|
|
71
|
+
port: null,
|
|
72
|
+
status: AppGatewayService.isRunning ? 'running' : 'stopped',
|
|
73
|
+
uptime: AppGatewayService.startedAt ? currentTime - AppGatewayService.startedAt : null,
|
|
74
|
+
description: ServiceDescriptions[ServiceNames.APP_GATEWAY],
|
|
75
|
+
capabilities: {
|
|
76
|
+
canStart: true,
|
|
77
|
+
canStop: true,
|
|
78
|
+
canRestart: true
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
data: services,
|
|
85
|
+
traceId
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
async status (params) {
|
|
89
|
+
const { traceId } = params
|
|
90
|
+
const { ports } = Application
|
|
91
|
+
const uptimeMs = process.uptime() * 1000
|
|
92
|
+
|
|
93
|
+
const services = [
|
|
94
|
+
{
|
|
95
|
+
name: ServiceNames.PUBSUB,
|
|
96
|
+
displayName: ServiceDisplayNames[ServiceNames.PUBSUB],
|
|
97
|
+
status: 'running',
|
|
98
|
+
uptime: uptimeMs,
|
|
99
|
+
port: ports.pubsub
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: ServiceNames.MQTT,
|
|
103
|
+
displayName: ServiceDisplayNames[ServiceNames.MQTT],
|
|
104
|
+
status: MqttServer.isRunning ? 'running' : 'stopped',
|
|
105
|
+
uptime: MqttServer.isRunning ? uptimeMs : null,
|
|
106
|
+
port: ports.mqtt
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: ServiceNames.FIRESTORE,
|
|
110
|
+
displayName: ServiceDisplayNames[ServiceNames.FIRESTORE],
|
|
111
|
+
status: FirestoreEmulator.isRunning ? 'running' : 'stopped',
|
|
112
|
+
uptime: FirestoreEmulator.isRunning ? uptimeMs : null,
|
|
113
|
+
port: ports.firestore
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
name: ServiceNames.WEBUI,
|
|
117
|
+
displayName: ServiceDisplayNames[ServiceNames.WEBUI],
|
|
118
|
+
status: 'running',
|
|
119
|
+
uptime: uptimeMs,
|
|
120
|
+
port: ports.webUi
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
name: ServiceNames.APP_GATEWAY,
|
|
124
|
+
displayName: ServiceDisplayNames[ServiceNames.APP_GATEWAY],
|
|
125
|
+
status: AppGatewayService.isRunning ? 'running' : 'stopped',
|
|
126
|
+
uptime: AppGatewayService.startedAt ? Date.now() - AppGatewayService.startedAt : null,
|
|
127
|
+
port: null
|
|
128
|
+
}
|
|
129
|
+
]
|
|
130
|
+
|
|
131
|
+
return {
|
|
132
|
+
data: services,
|
|
133
|
+
traceId
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
async restart (params) {
|
|
137
|
+
const { serviceName, traceId } = params
|
|
138
|
+
|
|
139
|
+
// Validate service name using enum
|
|
140
|
+
if (!isValidServiceName(serviceName)) {
|
|
141
|
+
return {
|
|
142
|
+
message: `Unknown service: ${serviceName}. Valid services: ${Object.values(ServiceNames).join(', ')}`,
|
|
143
|
+
traceId
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
let message = ''
|
|
148
|
+
switch (serviceName) {
|
|
149
|
+
case ServiceNames.MQTT:
|
|
150
|
+
MqttServer.stop()
|
|
151
|
+
await MqttServer.start()
|
|
152
|
+
message = `${ServiceDisplayNames[ServiceNames.MQTT]} restarted successfully`
|
|
153
|
+
break
|
|
154
|
+
case ServiceNames.FIRESTORE:
|
|
155
|
+
await FirestoreEmulator.stop()
|
|
156
|
+
await FirestoreEmulator.start()
|
|
157
|
+
message = `${ServiceDisplayNames[ServiceNames.FIRESTORE]} restarted successfully`
|
|
158
|
+
break
|
|
159
|
+
case ServiceNames.PUBSUB:
|
|
160
|
+
message = `${ServiceDisplayNames[ServiceNames.PUBSUB]} restart not supported (requires full server restart)`
|
|
161
|
+
break
|
|
162
|
+
case ServiceNames.WEBUI:
|
|
163
|
+
message = `${ServiceDisplayNames[ServiceNames.WEBUI]} restart not supported (requires full server restart)`
|
|
164
|
+
break
|
|
165
|
+
case ServiceNames.APP_GATEWAY:
|
|
166
|
+
await AppGatewayService.stop()
|
|
167
|
+
await AppGatewayService.start()
|
|
168
|
+
message = `${ServiceDisplayNames[ServiceNames.APP_GATEWAY]} restarted successfully`
|
|
169
|
+
break
|
|
170
|
+
default:
|
|
171
|
+
message = `Service ${serviceName} restart not implemented`
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
message,
|
|
175
|
+
traceId
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
async healthCheck (params) {
|
|
179
|
+
const { healthEndpoint, traceId } = params
|
|
180
|
+
const startTime = Date.now()
|
|
181
|
+
try {
|
|
182
|
+
const response = await fetch(healthEndpoint, {
|
|
183
|
+
method: 'GET',
|
|
184
|
+
signal: AbortSignal.timeout(5000)
|
|
185
|
+
})
|
|
186
|
+
const responseTime = Date.now() - startTime
|
|
187
|
+
return {
|
|
188
|
+
healthy: response.ok,
|
|
189
|
+
statusCode: response.status,
|
|
190
|
+
responseTime,
|
|
191
|
+
error: null,
|
|
192
|
+
traceId
|
|
193
|
+
}
|
|
194
|
+
} catch (error) {
|
|
195
|
+
const responseTime = Date.now() - startTime
|
|
196
|
+
return {
|
|
197
|
+
healthy: false,
|
|
198
|
+
statusCode: null,
|
|
199
|
+
responseTime,
|
|
200
|
+
error: error.message,
|
|
201
|
+
traceId
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import KoaRouter from 'koa-router'
|
|
2
|
+
import { Controllers } from './Controllers.js'
|
|
3
|
+
|
|
4
|
+
const Router = new KoaRouter()
|
|
5
|
+
const v1 = new KoaRouter({ prefix: '/v1/services' })
|
|
6
|
+
|
|
7
|
+
v1.post('/list', Controllers.list)
|
|
8
|
+
v1.post('/status', Controllers.status)
|
|
9
|
+
v1.post('/restart', Controllers.restart)
|
|
10
|
+
v1.post('/health/check', Controllers.healthCheck)
|
|
11
|
+
|
|
12
|
+
Router.use(v1.routes())
|
|
13
|
+
|
|
14
|
+
export { Router }
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Joi } from '@gokiteam/koa'
|
|
2
|
+
|
|
3
|
+
export const Schemas = {
|
|
4
|
+
list: {
|
|
5
|
+
request: {
|
|
6
|
+
body: {}
|
|
7
|
+
},
|
|
8
|
+
responses: {
|
|
9
|
+
success: {
|
|
10
|
+
services: Joi.array().items(
|
|
11
|
+
Joi.object({
|
|
12
|
+
name: Joi.string().required(),
|
|
13
|
+
displayName: Joi.string().required(),
|
|
14
|
+
port: Joi.number().integer().required(),
|
|
15
|
+
description: Joi.string().required()
|
|
16
|
+
})
|
|
17
|
+
).required()
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
status: {
|
|
22
|
+
request: {
|
|
23
|
+
body: {}
|
|
24
|
+
},
|
|
25
|
+
responses: {
|
|
26
|
+
success: {
|
|
27
|
+
services: Joi.array().items(
|
|
28
|
+
Joi.object({
|
|
29
|
+
name: Joi.string().required(),
|
|
30
|
+
displayName: Joi.string().required(),
|
|
31
|
+
status: Joi.string().valid('running', 'stopped', 'error').required(),
|
|
32
|
+
uptime: Joi.number().integer().min(0).allow(null).required(),
|
|
33
|
+
port: Joi.number().integer().required()
|
|
34
|
+
})
|
|
35
|
+
).required()
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
restart: {
|
|
40
|
+
request: {
|
|
41
|
+
body: {
|
|
42
|
+
serviceName: Joi.string().valid('pubsub', 'mqtt', 'logging').required()
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
responses: {
|
|
46
|
+
success: {
|
|
47
|
+
message: Joi.string().required()
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
healthCheck: {
|
|
52
|
+
request: {
|
|
53
|
+
body: {
|
|
54
|
+
healthEndpoint: Joi.string().uri().required()
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
responses: {
|
|
58
|
+
success: {
|
|
59
|
+
healthy: Joi.boolean().required(),
|
|
60
|
+
statusCode: Joi.number().integer().allow(null),
|
|
61
|
+
responseTime: Joi.number().integer().allow(null),
|
|
62
|
+
error: Joi.string().allow(null)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Logic } from './Logic.js'
|
|
2
|
+
|
|
3
|
+
export const Controllers = {
|
|
4
|
+
async createSnapshot (ctx) {
|
|
5
|
+
const { traceId } = ctx.state
|
|
6
|
+
const { services, metadata } = ctx.request.body
|
|
7
|
+
const result = await Logic.createSnapshot({ services, metadata, traceId })
|
|
8
|
+
ctx.reply(result)
|
|
9
|
+
},
|
|
10
|
+
|
|
11
|
+
async restoreSnapshot (ctx) {
|
|
12
|
+
const { traceId } = ctx.state
|
|
13
|
+
const { snapshotId, restartServices } = ctx.request.body
|
|
14
|
+
const result = await Logic.restoreSnapshot({ snapshotId, restartServices, traceId })
|
|
15
|
+
ctx.reply(result)
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
async listSnapshots (ctx) {
|
|
19
|
+
const { traceId } = ctx.state
|
|
20
|
+
const result = await Logic.listSnapshots({ traceId })
|
|
21
|
+
ctx.reply(result)
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
async getSnapshotDetails (ctx) {
|
|
25
|
+
const { traceId } = ctx.state
|
|
26
|
+
const { snapshotId } = ctx.request.body
|
|
27
|
+
const result = await Logic.getSnapshotDetails({ snapshotId, traceId })
|
|
28
|
+
ctx.reply(result)
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
async deleteSnapshot (ctx) {
|
|
32
|
+
const { traceId } = ctx.state
|
|
33
|
+
const { snapshotId } = ctx.request.body
|
|
34
|
+
const result = await Logic.deleteSnapshot({ snapshotId, traceId })
|
|
35
|
+
ctx.reply(result)
|
|
36
|
+
}
|
|
37
|
+
}
|