Skip to content

Commit

Permalink
cta api: add container start/stop/restart
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy Razon committed Sep 6, 2023
1 parent 4a82e40 commit 1cbd9c2
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions packages/compose-tunnel-agent/src/api-server/containers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import exec from './exec'
import logs from './logs'
import { inspectFilteredContainer } from './filter'

const containerIdActionSchema = z.object({
containerId: z.string(),
action: z.union([z.literal('stop'), z.literal('start'), z.literal('restart')]),
})

export const containers: FastifyPluginAsync<{
docker: Dockerode
dockerFilter: DockerFilterClient
Expand All @@ -20,10 +25,16 @@ export const containers: FastifyPluginAsync<{
schema: {
params: containerIdSchema,
},
}, async ({ params: { containerId } }, res) => {
const container = await inspectFilteredContainer(dockerFilter, containerId)
void res.send(container)
})
}, async ({ params: { containerId } }) => await inspectFilteredContainer(dockerFilter, containerId))

app.post<{
Params: z.infer<typeof containerIdActionSchema>
}>('/:containerId/:action', {
schema: {
params: containerIdActionSchema,
},
preValidation: async ({ params: { containerId } }) => await inspectFilteredContainer(dockerFilter, containerId),
}, async ({ params: { containerId, action } }) => await docker.getContainer(containerId)[action]())

Check failure

Code scanning / CodeQL

Unvalidated dynamic method call High

Invocation of method with
user-controlled
name may dispatch to unexpected target and cause an exception.

await app.register(fastifyWebsocket)
await app.register(exec, { docker, dockerFilter })
Expand Down

0 comments on commit 1cbd9c2

Please sign in to comment.