From 804464c30450233f90d9f57e00a80c196b1a3cc0 Mon Sep 17 00:00:00 2001 From: Johannes Zellner Date: Thu, 18 Feb 2016 15:43:46 +0100 Subject: [PATCH] Add apps.getByIpAddress() --- src/apps.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/apps.js b/src/apps.js index 81144a151..7a773fbaa 100644 --- a/src/apps.js +++ b/src/apps.js @@ -9,6 +9,7 @@ exports = module.exports = { get: get, getBySubdomain: getBySubdomain, + getByIpAddress: getByIpAddress, getAll: getAll, purchase: purchase, install: install, @@ -308,6 +309,25 @@ function getBySubdomain(subdomain, callback) { }); } +function getByIpAddress(ip, callback) { + assert.strictEqual(typeof ip, 'string'); + assert.strictEqual(typeof callback, 'function'); + + docker.getContainerIdByIp(ip, function (error, containerId) { + if (error) return callback(new AppsError(AppsError.INTERNAL_ERROR, error)); + + appdb.getByContainerId(containerId, function (error, app) { + if (error && error.reason === DatabaseError.NOT_FOUND) return callback(new AppsError(AppsError.NOT_FOUND, 'No such app')); + if (error) return callback(new AppsError(AppsError.INTERNAL_ERROR, error)); + + app.iconUrl = getIconUrlSync(app); + app.fqdn = config.appFqdn(app.location); + + callback(null, app); + }); + }); +} + function getAll(callback) { assert.strictEqual(typeof callback, 'function');