Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- const Promise = require('bluebird');
- const fhc = Promise.promisifyAll(require('fh-fhc'));
- const env = require('env-var');
- const log = require('fh-bunyan').getLogger(__filename);
- const R = require('ramda');
- // fhc login and target vars. you can set these in bash using a command such as
- // "export FHC_USER=user@acme.com", or by uncommenting the defaults below and
- // inserting your own
- const USER = env('FHC_USER'/*, default@acme.com */).required().asString();
- const PASS = env('FHC_PASS'/*, defaultpassw0rd */).required().asString();
- const DOMAIN = env('FHC_DOMAIN'/*, default-acme.feedhenry.com */).required().asString();
- function executeCommand (cmd) {
- log.info('exec fhc command - ', cmd.join(' '));
- return fhc.applyCommandFunctionAsync(cmd);
- }
- function init () {
- log.info('initialising fhc');
- return fhc.loadAsync()
- .then(() => executeCommand(['target', DOMAIN]))
- .then(() => executeCommand(['login', USER, PASS]));
- }
- function getServicesWithDefaultName () {
- log.info('getting services that need to be renamed');
- return executeCommand(['services', 'list'])
- .then(R.filter((s) => s.apps[0].title.toLowerCase() === 'cloud app'));
- }
- function updateServiceAppTitles (services) {
- log.info('renaming %d services:', services.length);
- return Promise.mapSeries(services, function updateTitle (s) {
- return executeCommand([
- 'app', 'update', s.guid, s.apps[0].guid, 'title', s.title
- ])
- .then((ret) => {
- log.info('renamed service app - ', ret);
- });
- });
- }
- Promise.resolve()
- .then(init)
- .then(getServicesWithDefaultName)
- .then(updateServiceAppTitles);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement