Created
April 14, 2015 06:10
-
-
Save adrai/10584a9e06a5be2737a7 to your computer and use it in GitHub Desktop.
cf
This file contains 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
var CloudFoundryApi = require('cloud-foundry'); | |
var _ = require('lodash'); | |
var cf_api = new CloudFoundryApi('https....', { | |
token: '.... refresh token' | |
}); | |
cf_api.organizations.list({}, function (err, page) { | |
if (err) { | |
return console.log(err); | |
} | |
var orgs = []; | |
page.data.resources.forEach(function (res) { | |
orgs.push({ name: res.entity.name, guid: res.metadata.guid }); | |
}); | |
// console.log(orgs); | |
cf_api.spaces.list({}, function (err, page) { | |
if (err) { | |
return console.log(err); | |
} | |
var spaces = []; | |
page.data.resources.forEach(function (res) { | |
spaces.push({ name: res.entity.name, guid: res.metadata.guid, organization_guid: res.entity.organization_guid }); | |
}); | |
// console.log(spaces); | |
spaces.forEach(function (space) { | |
var org = _.find(orgs, function (o) { | |
return o.guid === space.organization_guid; | |
}); | |
if (org) { | |
org.spaces = org.spaces || []; | |
org.spaces.push(space); | |
} | |
}); | |
console.log(JSON.stringify(orgs, null, 2)); | |
var adrai = _.find(orgs, function (o) { | |
return o.name === 'adrai'; | |
}); | |
cf_api.apps.list({ | |
filter: { | |
name: 'space_guid', | |
value: adrai.spaces[0].guid | |
} | |
}, function (err, page) { | |
if (err) { | |
return console.log(err); | |
} | |
var apps = []; | |
page.data.resources.forEach(function (res) { | |
apps.push({ name: res.entity.name, guid: res.metadata.guid }); | |
}); | |
console.log(apps); | |
cf_api.service_bindings.list({ | |
filter: { | |
name: 'app_guid', | |
value: apps[0].guid | |
} | |
}, function (err, page) { | |
if (err) { | |
return console.log(err); | |
} | |
var app_services = []; | |
page.data.resources.forEach(function (res) { | |
app_services.push({ guid: res.entity.service_instance_guid }); | |
}); | |
cf_api.service_instances.get(app_services[0].guid, function (err, page) { | |
if (err) { | |
return console.log(err); | |
} | |
app_services[0].name = page.entity.name; | |
console.log(app_services); | |
}); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment