Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #472 from Financial-Times/christos/update_service_…
Browse files Browse the repository at this point in the history
…finding

Christos/update service finding
  • Loading branch information
constantology authored Jul 11, 2017
2 parents 90393a3 + 8353d1f commit 3388d97
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
11 changes: 11 additions & 0 deletions lib/find-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

module.exports = exports = (services, name) => {
let serviceData = services.find(service => service.name === name);

if (!serviceData) {
serviceData = services.find(service => service.systemCode === name);
}

return serviceData || null;
};
11 changes: 10 additions & 1 deletion tasks/configure.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var packageJson = require(process.cwd() + '/package.json');
var findService = require('../lib/find-service');
var herokuAuthToken = require('../lib/heroku-auth-token');
var configVarsKey = require('../lib/config-vars-key');
var normalizeName = require('../lib/normalize-name');
Expand Down Expand Up @@ -30,7 +31,15 @@ function fetchFromVault (source, target, registry = DEFAULT_REGISTRY_URI) {

const path = fetch(registry)
.then(fetchres.json)
.then(json => json.find(app => app.name === normalizeName(source)).config)
.then(json => {
const serviceData = findService(json, normalizeName(source));

if (!serviceData) {
throw new Error('Could not find a service in the registry, with `name` or `systemCode`, matching ' + source + '. Please check the service registry.');
}

return serviceData.config;
})
.then(url => url.replace('https://vault.in.ft.com/v1/',''));

return Promise.all([path, vault.get()])
Expand Down
8 changes: 7 additions & 1 deletion tasks/scale.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const packageJson = require(process.cwd() + '/package.json');
const findService = require('../lib/find-service');
const herokuAuthToken = require('../lib/heroku-auth-token');
const normalizeName = require('../lib/normalize-name');
const fetchres = require('fetchres');
Expand Down Expand Up @@ -33,7 +34,12 @@ function task (opts) {
.then(() => fetch(registry))
.then(fetchres.json)
.then(data => {
const serviceData = data.find(service => service.name === source);
const serviceData = findService(data, source);

if (!serviceData) {
throw new Error('Could not find a service in the registry, with `name` or `systemCode`, matching ' + source + '. Please check the service registry.');
}

const processInfo = serviceData.processes;

if (!processInfo) {
Expand Down

0 comments on commit 3388d97

Please sign in to comment.