Fix routing for deleting images with a slash in the name

This commit is contained in:
Pablo Carranza Velez 2016-05-17 19:18:39 +00:00
parent 7b9eaeea3a
commit 951bd2888f
2 changed files with 5 additions and 4 deletions

View File

@ -171,7 +171,7 @@ module.exports = (application) ->
res.json(device.getState())
unparsedRouter.post '/v1/images/create', dockerUtils.createImage
unparsedRouter.delete '/v1/images/:name', dockerUtils.deleteImage
unparsedRouter.delete '/v1/images/*', dockerUtils.deleteImage
unparsedRouter.get '/v1/images', dockerUtils.listImages
parsedRouter.post '/v1/containers/create', dockerUtils.createContainer
parsedRouter.post '/v1/containers/:id/start', dockerUtils.startContainer

View File

@ -262,13 +262,14 @@ do ->
res.status(500).send(err?.message or err or 'Unknown error')
exports.deleteImage = (req, res) ->
imageName = req.params[0]
Promise.using lockImages(), ->
knex('image').select().where('repoTag', req.params.name)
knex('image').select().where('repoTag', imageName)
.then (images) ->
throw new Error('Only images created via the Supervisor can be deleted.') if images.length == 0
knex('image').where('repoTag', req.params.name).delete()
knex('image').where('repoTag', imageName).delete()
.then ->
docker.getImage(req.params.name).removeAsync(sanitizeQuery(req.query))
docker.getImage(imageName).removeAsync(sanitizeQuery(req.query))
.then (data) ->
res.json(data)
.catch (err) ->