Add apps.getByIpAddress()

This commit is contained in:
Johannes Zellner
2016-02-18 15:43:46 +01:00
parent ecf7f442ba
commit 804464c304

View File

@@ -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');