mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-20 14:13:08 +00:00
Add some protections to avoid deleting supervisor or app containers
This commit is contained in:
parent
55870b16b1
commit
7b9eaeea3a
@ -311,14 +311,28 @@ do ->
|
||||
res.status(500).send(err?.message or err or 'Unknown error')
|
||||
|
||||
exports.stopContainer = (req, res) ->
|
||||
docker.getContainer(req.params.id).stopAsync(sanitizeQuery(req.query))
|
||||
container = docker.getContainer(req.params.id)
|
||||
knex('app').select()
|
||||
.then (apps) ->
|
||||
throw new Error('Cannot stop an app container') if _.any(apps, containerId: req.params.id)
|
||||
container.inspectAsync()
|
||||
.then (cont) ->
|
||||
throw new Error('Cannot stop supervisor container') if cont.Name == '/resin_supervisor' or _.any(cont.Names, (n) -> n == '/resin_supervisor')
|
||||
container.stopAsync(sanitizeQuery(req.query))
|
||||
.then (data) ->
|
||||
res.json(data)
|
||||
.catch (err) ->
|
||||
res.status(500).send(err?.message or err or 'Unknown error')
|
||||
|
||||
exports.deleteContainer = (req, res) ->
|
||||
docker.getContainer(req.params.id).removeAsync(sanitizeQuery(req.query))
|
||||
container = docker.getContainer(req.params.id)
|
||||
knex('app').select()
|
||||
.then (apps) ->
|
||||
throw new Error('Cannot remove an app container') if _.any(apps, containerId: req.params.id)
|
||||
container.inspectAsync()
|
||||
.then (cont) ->
|
||||
throw new Error('Cannot remove supervisor container') if cont.Name == '/resin_supervisor' or _.any(cont.Names, (n) -> n == '/resin_supervisor')
|
||||
container.removeAsync(sanitizeQuery(req.query))
|
||||
.then (data) ->
|
||||
res.json(data)
|
||||
.catch (err) ->
|
||||
|
Loading…
Reference in New Issue
Block a user