Created
March 9, 2017 15:20
-
-
Save evanshortiss/61a4135f6400e8aa13b988b6ad03677e to your computer and use it in GitHub Desktop.
Rename the Cloud App of RHMAP Services so they show the correct name across all UI components
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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 [email protected]", or by uncommenting the defaults below and | |
// inserting your own | |
const USER = env('FHC_USER'/*, [email protected] */).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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment