├── .doclets.yml ├── .eslintrc.json ├── .gitignore ├── .jshintrc ├── .npmignore ├── .travis.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── appveyor.yml ├── docs ├── cf_architecture_block.png └── umlDiagram.png ├── index.js ├── lib ├── model │ ├── cloudcontroller │ │ ├── Apps.js │ │ ├── BuildPacks.js │ │ ├── CloudController.js │ │ ├── CloudControllerBase.js │ │ ├── Domains.js │ │ ├── Events.js │ │ ├── Jobs.js │ │ ├── Organizations.js │ │ ├── OrganizationsQuota.js │ │ ├── Routes.js │ │ ├── ServiceBindings.js │ │ ├── ServiceInstances.js │ │ ├── ServicePlans.js │ │ ├── Services.js │ │ ├── Spaces.js │ │ ├── SpacesQuota.js │ │ ├── Stacks.js │ │ ├── UserProvidedServices.js │ │ └── Users.js │ ├── metrics │ │ ├── Logs.js │ │ └── log_message.proto │ └── uaa │ │ └── UsersUAA.js └── utils │ ├── HttpMethods.js │ ├── HttpStatus.js │ └── HttpUtils.js ├── package.json ├── scripts ├── setup-dndmasq.sh └── setup-dnsmasq.sh ├── test ├── lib │ └── model │ │ ├── cloudcontroller │ │ ├── AppsTests.js │ │ ├── BuildPacksTests.js │ │ ├── CloudControllerTests.js │ │ ├── DockerTests.js │ │ ├── DomainsTests.js │ │ ├── EventsTests.js │ │ ├── JobTests.js │ │ ├── OrganizationsQuotaTests.js │ │ ├── OrganizationsTests.js │ │ ├── RoutesTests.js │ │ ├── ServiceBindingsTests.js │ │ ├── ServiceInstancesTests.js │ │ ├── ServicePlansTests.js │ │ ├── ServicesTests.js │ │ ├── SpacesQuotaTests.js │ │ ├── SpacesTests.js │ │ ├── StacksTests.js │ │ ├── UploadJEEAppsTests.js │ │ ├── UploadStaticAppsTests.js │ │ ├── UserProvidedServicesTests.js │ │ └── UserTests.js │ │ ├── metrics │ │ └── LogTests.js │ │ └── uaa │ │ └── UserUAATests.js ├── mocha.opts └── utils │ ├── HttpUtilsTests.js │ ├── ZipGenerator.js │ └── ZipGeneratorTests.js └── test_resources ├── SpringMVC_v3_AppExample.war └── SpringMVC_v4_AppExample.war /.doclets.yml: -------------------------------------------------------------------------------- 1 | dir: lib 2 | packageJson: package.json 3 | articles: 4 | - Overview: README.md 5 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "es6": true, 4 | "node": true, 5 | "mocha": true 6 | }, 7 | "extends": "strongloop", 8 | "rules": { 9 | "dot-notation": [2, {"allowPattern": "^[a-z]+(_[a-z]+)+$"}], 10 | "indent": [ 11 | 1, 12 | "tab" 13 | ], 14 | "linebreak-style": [ 15 | "error", 16 | "unix" 17 | ], 18 | "quotes": [ 19 | 1, 20 | "single" 21 | ], 22 | "max-len": 0, 23 | "semi": [ 24 | 1, 25 | "always" 26 | ], 27 | "comma-dangle": ["error", "never"], 28 | "brace-style": [1, "stroustrup"], 29 | "space-before-function-paren": 1, 30 | "spaced-comment": 1, 31 | "space-in-parens": 1, 32 | "keyword-spacing": 1, 33 | "quote-props": 1, 34 | "no-unused-vars": 1 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # node-waf configuration 20 | .lock-wscript 21 | 22 | # Compiled binary addons (http://nodejs.org/api/addons.html) 23 | build/Release 24 | 25 | # Dependency directory 26 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 27 | node_modules 28 | 29 | #Configuration 30 | config.json 31 | configPivotal.json 32 | 33 | #Testing 34 | staticApp.zip 35 | 36 | # Docs 37 | doc 38 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "esnext":true, 3 | "node": true 4 | } 5 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .git* 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | 3 | env: 4 | global: 5 | - LOCAL_INSTANCE_1_CF_API_URL=https://api.bosh-lite.com 6 | - LOCAL_INSTANCE_1_username=admin 7 | - LOCAL_INSTANCE_1_password=admin 8 | 9 | language: node_js 10 | node_js: 11 | - 5.10.1 12 | 13 | before_install: 14 | - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then sudo bash ./scripts/setup-dnsmasq.sh; fi' 15 | 16 | install: npm i 17 | 18 | script: 19 | - npm run lint 20 | - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then npm run test:local; fi' 21 | 22 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## Version 0.13.0 2016-01-26 2 | 3 | - Add ESLint support 4 | - Refactor code to ES2015 5 | - Initial support to deploy Docker containers on CF 6 | - Refactor log support 7 | - Add method setToken in every Object to avoid sending token in every method 8 | 9 | Environment: LOCAL_INSTANCE_1 10 | 11 | 90 passing (3m) 12 | 37 pending 13 | 14 | Environment: PIVOTAL 15 | 16 | 87 passing (5m) 17 | 33 pending 18 | 19 | 20 | ## Version 0.12.0 2015-12-22 21 | 22 | - Support to refresh OAuth Token. 23 | - Adding PHP & Python buildpacks. 24 | - Package.json refactoring 25 | 26 | Pull Requests: 27 | 28 | @jthomas: 29 | 30 | - Support for Service Instances 31 | - Support for Services 32 | - Support for ServicePlans 33 | - Support for filters in Events 34 | 35 | Environment: LOCAL_INSTANCE_1 36 | 37 | 89 passing (3m) 38 | 33 pending 39 | 40 | Environment: PIVOTAL 41 | 42 | 82 passing (4m) 43 | 29 pending 44 | 45 | Environment: BLUEMIX 46 | 47 | 82 passing (4m) 48 | 29 pending 49 | 50 | 51 | ## Version 0.11.1 2015-11-23 52 | 53 | - Defensive code in HttpUtils.js (Avoid crashing in case of Server down or service not reply expected JSON) 54 | 55 | ## Version 0.11.0 2015-11-20 56 | 57 | - Refactor some methods: 58 | 59 | ``` js 60 | Apps.prototype.create = function (token_type, access_token, appOptions) { 61 | Apps.prototype.add = function (token_type, access_token, appOptions) { 62 | 63 | Apps.prototype.stopApp = function (token_type, access_token, app_guid) { 64 | Apps.prototype.stop = function (token_type, access_token, app_guid) { 65 | 66 | Apps.prototype.startApp = function (token_type, access_token, app_guid) { 67 | Apps.prototype.start = function (token_type, access_token, app_guid) { 68 | 69 | Apps.prototype.deleteApp = function (token_type, access_token, app_guid) { 70 | Apps.prototype.remove = function (token_type, access_token, app_guid) { 71 | 72 | Apps.prototype.uploadApp = function (token_type, access_token, app_guid, filePath, async) { 73 | Apps.prototype.upload = function (token_type, access_token, app_guid, filePath, async) { 74 | 75 | Apps.prototype.environmentVariables = function (token_type, access_token, app_guid) { 76 | Apps.prototype.getEnvironmentVariables = function (token_type, access_token, app_guid) { 77 | 78 | Organizations.prototype.memoryUsage = function (token_type, access_token, org_guid) { 79 | Organizations.prototype.getMemoryUsage = function (token_type, access_token, org_guid) { 80 | 81 | Organizations.prototype.summary = function (token_type, access_token, org_guid) { 82 | Organizations.prototype.getSummary = function (token_type, access_token, org_guid) { 83 | 84 | OrganizationsQuota.prototype.quotaDefinitions = function (token_type, access_token) { 85 | OrganizationsQuota.prototype.getQuotaDefinitions = function (token_type, access_token) { 86 | 87 | OrganizationsQuota.prototype.quotaDefinition = function (token_type, access_token, org_guid) { 88 | OrganizationsQuota.prototype.getQuotaDefinition = function (token_type, access_token, org_guid) { 89 | 90 | Routes.prototype.addRoute = function (token_type, access_token, routeOptions) { 91 | Routes.prototype.add = function (token_type, access_token, routeOptions) { 92 | 93 | Routes.prototype.deleteRoute = function (token_type, access_token, route_guid) { 94 | Routes.prototype.remove = function (token_type, access_token, route_guid) { 95 | 96 | ServiceBindings.prototype.removeServiceBinding = function (token_type, access_token, service_guid){ 97 | ServiceBindings.prototype.remove = function (token_type, access_token, service_guid) { 98 | 99 | Spaces.prototype.summary = function (token_type, access_token, space_guid) { 100 | Spaces.prototype.getSummary = function (token_type, access_token, space_guid) { 101 | 102 | Spaces.prototype.userRoles = function (token_type, access_token, space_guid) { 103 | Spaces.prototype.getUserRoles = function (token_type, access_token, space_guid) { 104 | 105 | SpacesQuota.prototype.quotaDefinitions = function (token_type, access_token) { 106 | SpacesQuota.prototype.getQuotaDefinitions = function (token_type, access_token) { 107 | 108 | UserProvidedServices.prototype.create = function (token_type, access_token, user_provided_service_options) { 109 | UserProvidedServices.prototype.add = function (token_type, access_token, user_provided_service_options) { 110 | 111 | UserProvidedServices.prototype.delete = function (token_type, access_token, service_guid) { 112 | UserProvidedServices.prototype.remove = function (token_type, access_token, service_guid) { 113 | 114 | Users.prototype.getUsers = function (token_type, access_token, user_guid) { 115 | Users.prototype.getUsers = function (token_type, access_token) { 116 | ``` 117 | Environment: LOCAL_INSTANCE_1 118 | 119 | 72 passing (2m) 120 | 26 pending 121 | 122 | Environment: PIVOTAL 123 | 124 | 64 passing (5m) 125 | 21 pending 126 | 127 | Environment: BLUEMIX 128 | 129 | 64 passing (5m) 130 | 21 pending 131 | 132 | ## Version 0.10.0 2015-11-06 133 | 134 | - Adding Online documentation: http://prosociallearneu.github.io/cf-nodejs-client-docs/ 135 | - Add method to restage Apps 136 | - Refactor methods: 137 | UserProvidedServices.prototype.create 138 | Routes.prototype.checkRoute & Routes.prototype.getRoutes 139 | Logs.prototype.getRecent 140 | CloudFoundry.prototype.login 141 | Apps.prototype.associateRoute 142 | Apps.prototype.associateRoute 143 | Apps.prototype.stopApp & Apps.prototype.startApp 144 | Apps.prototype.getAppByName 145 | Apps.prototype.getApps 146 | Routes.prototype.addRoute 147 | Routes.prototype.checkRoute 148 | 149 | Environment: LOCAL_INSTANCE_1 150 | 151 | 71 passing (2m) 152 | 25 pending 153 | 154 | Environment: PIVOTAL 155 | 156 | 63 passing (4m) 157 | 20 pending 158 | 159 | Environment: BLUEMIX 160 | 161 | 63 passing (4m) 162 | 20 pending 163 | 164 | 165 | ## Version 0.9.1 2015-10-29 166 | 167 | - Adding the dependency Bluebird to improve the performance 168 | - Adding support for Quotas (Org/Space) 169 | - It is possible to create users in the system. (Quota/Org/Space/User) 170 | 171 | Environment: LOCAL_INSTANCE_1 172 | 173 | 65 passing (2m) 174 | 23 pending 175 | 176 | Environment: PIVOTAL 177 | 178 | 58 passing (3m) 179 | 19 pending 180 | 181 | Environment: BLUEMIX 182 | 183 | 58 passing (3m) 184 | 19 pending 185 | 186 | ## Version 0.9.0 2015-10-23 187 | 188 | - Adding support for Java Buildpack 189 | - Testing development in 3 environments: Local Instance (Yudai), PSW & Bluemix 190 | - Initial support for Organizations & Spaces 191 | 192 | Environment: LOCAL_INSTANCE_1 193 | 194 | 57 passing (1m) 195 | 16 pending 196 | 197 | Environment: PIVOTAL 198 | 199 | 57 passing (1m) 200 | 16 pending 201 | 202 | Environment: BLUEMIX 203 | 204 | 57 passing (4m) 205 | 16 pending 206 | 207 | ## Version 0.8.3 2015-10-19 208 | 209 | - Adding the capability to add filters in a Service Binding Search. 210 | 211 | 39 passing (1m) 212 | 15 pending 213 | 214 | ## Version 0.8.2 2015-10-19 215 | 216 | - Minor fix in index.js to export UserProvidedServices in the right way. 217 | 218 | 39 passing (2m) 219 | 14 pending 220 | 221 | ## Version 0.8.1 2015-10-01 222 | 223 | - Adding adding method in the whole project: setEndPoint 224 | 225 | 39 passing (2m) 226 | 14 pending 227 | 228 | ## Version 0.8.0 2015-09-28 229 | 230 | - Adding support for User Provided Services 231 | - Adding support for Service Binding 232 | 233 | 39 passing (1m) 234 | 14 pending 235 | 236 | ## Version 0.7.0 2015-09-10 237 | 238 | - Big performance improvement in tests. 239 | - Remove the usage of process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; 240 | - Initial Log support 241 | 242 | 37 passing (2m) 243 | 6 pending 244 | 245 | ## Version 0.6.2 2015-09-04 246 | 247 | - CloudFoundry.setEndpoint (0.6.1) 248 | - App.uploadApp with async flag 249 | - App.uploadApp without the useless parameter appName 250 | 251 | 35 passing (3m) 252 | 4 pending 253 | 254 | ## Version 0.0.6 2015-08-20 255 | 256 | - Better support for: Create App, Upload Bits for App & Start App 257 | 258 | 32 passing (3m) 259 | 3 pending 260 | 261 | ## Version 0.0.5 2015-08-14 262 | 263 | - Pending 264 | 265 | 16 passing (23s) 266 | 3 pending 267 | 268 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribution Guidelines 2 | 3 | 1. [Linting](#linting) 4 | 2. [git](#git) 5 | 6 | ## Linting 7 | 8 | We enforce some style rules for code in this repository using [eslint](http://eslint.org/). You can install a linting addon to a lot of editors and IDEs that will follow our linting rules. 9 | 10 | We use [Strongloop's](https://github.com/strongloop/eslint-config-strongloop) eslint configuration module, which is installed via `npm`. If you are using a linting addon and are seeing weird error messages, they can likely be fixed by running `npm i`. 11 | 12 | If you decide to not install a linter addon, or cannot, you can run `npm run lint` to get a report of any style issues. Any issues not fixed will be caught during CI, and may prevent merging. 13 | 14 | ## git 15 | 16 | This repository will be using a forking model. 17 | 18 | After you've made changes to your fork, committed them, and pushed them, open a pull request against `master`. 19 | 20 | Travis CI will run regression checks on your branch and post the results on the PR. 21 | 22 | When merging into `master`, choose to squash commits when it makes sense. 23 | 24 | ### Useful Links for working with `git` 25 | 26 | - [Tutorial](https://try.github.io/levels/1/challenges/1) 27 | - [The simple stuff - workflow commands](http://rogerdudler.github.io/git-guide/) 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cf-client 2 | 3 | [![Build Status](https://travis-ci.org/IBM-Bluemix/cf-nodejs-client.svg)](https://travis-ci.org/IBM-Bluemix/cf-nodejs-client) 4 | [![Build status](https://ci.appveyor.com/api/projects/status/adxrubgykqys7pp9?svg=true)](https://ci.appveyor.com/project/jsloyer/cf-nodejs-client) 5 | [![Dependency Status](https://david-dm.org/IBM-Bluemix/cf-nodejs-client.svg)](https://david-dm.org/IBM-Bluemix/cf-nodejs-client) 6 | [![devDependency Status](https://david-dm.org/IBM-Bluemix/cf-nodejs-client/dev-status.svg)](https://david-dm.org/IBM-Bluemix/cf-nodejs-client#info=devDependencies) 7 | [![Changelog](https://img.shields.io/badge/see-CHANGELOG-red.svg?style=flat-square)](https://github.com/IBM-Bluemix/cf-nodejs-client/blob/master/CHANGELOG.md) 8 | [![API Doc](https://doclets.io/IBM-Bluemix/cf-nodejs-client/master.svg)](https://doclets.io/IBM-Bluemix/cf-nodejs-client/master) 9 | 10 | # Table of Contents 11 | 12 | - [Overview](#overview) 13 | - [Focus](#focus) 14 | - [Getting Started](#getting-started) 15 | - [JSDoc](https://doclets.io/IBM-Bluemix/cf-nodejs-client/master) 16 | - [Changelog](https://github.com/IBM-Bluemix/cf-nodejs-client/blob/master/CHANGELOG.md) 17 | - [Testing](#testing) 18 | - [Issues](#issues) 19 | - [References](#references) 20 | 21 | # Overview 22 | 23 | This project provides a simple client library to interact with the [Cloud Foundry Architecture](https://docs.pivotal.io/pivotalcf/concepts/architecture/): 24 | 25 | ![ScreenShot](https://raw.githubusercontent.com/IBM-Bluemix/cf-nodejs-client/master/docs/cf_architecture_block.png) 26 | 27 | Using this library, you could interact with the following platforms: [PWS](https://console.run.pivotal.io) 28 | , [Bluemix](https://console.ng.bluemix.net/) or a [Local Cloud Foundry instance](https://github.com/yudai/cf_nise_installer): 29 | 30 | | **[Cloud Controller](http://apidocs.cloudfoundry.org/)** | **[UAA](https://github.com/cloudfoundry/uaa)** | **Logging & Metrics** | 31 | |------------------------ |----------------------- |------------------------ | 32 | | [Apps](https://doclets.io/IBM-Bluemix/cf-nodejs-client/master#dl-Apps) | [Users](https://doclets.io/IBM-Bluemix/cf-nodejs-client/master#dl-UsersUAA) | [Logs](https://doclets.io/IBM-Bluemix/cf-nodejs-client/master#dl-Logs) | 33 | | [Buildpacks](https://doclets.io/IBM-Bluemix/cf-nodejs-client/master#dl-BuildPacks) | | | 34 | | [Domains](https://doclets.io/IBM-Bluemix/cf-nodejs-client/master#dl-Domains) | | | 35 | | [Jobs](https://doclets.io/IBM-Bluemix/cf-nodejs-client/master#dl-Jobs) | | | 36 | | [Organizations](https://doclets.io/IBM-Bluemix/cf-nodejs-client/master#dl-Organizations) | | | 37 | | [Organizations Quotas](https://doclets.io/IBM-Bluemix/cf-nodejs-client/master#dl-OrganizationsQuota) | | | 38 | | [Routes](https://doclets.io/IBM-Bluemix/cf-nodejs-client/master#dl-Routes) | | | 39 | | [Services](https://doclets.io/IBM-Bluemix/cf-nodejs-client/master#dl-Services) | | | 40 | | [Service Bindings](https://doclets.io/IBM-Bluemix/cf-nodejs-client/master#dl-ServiceBindings) | | | 41 | | [Service Instances](https://doclets.io/IBM-Bluemix/cf-nodejs-client/master#dl-ServiceInstances) | | | 42 | | [Service Plans](https://doclets.io/IBM-Bluemix/cf-nodejs-client/master#dl-ServicePlans) | | | 43 | | [Spaces](https://doclets.io/IBM-Bluemix/cf-nodejs-client/master#dl-Spaces) | | | 44 | | [Spaces Quotas](https://doclets.io/IBM-Bluemix/cf-nodejs-client/master#dl-SpacesQuota) | | | 45 | | [Stacks](https://doclets.io/IBM-Bluemix/cf-nodejs-client/master#dl-Stacks) | | | 46 | | [User provided Services](https://doclets.io/IBM-Bluemix/cf-nodejs-client/master#dl-UserProvidedServices) | | | 47 | | [Users](https://doclets.io/IBM-Bluemix/cf-nodejs-client/master#dl-Users) | | | 48 | 49 | # Focus 50 | 51 | The development doesn't cover the whole CloudController API. Main areas of development are: 52 | 53 | **App life cycle:** 54 | 55 | * Create an App 56 | * Upload source code in .zip or .war (Support for Static, Python, PHP, Node.js & JEE) 57 | * Create an User Provided Services 58 | * Associate Apps with an User Provided Services 59 | * Start | Stop an App 60 | * Restage Apps 61 | * Scale Apps 62 | * Simple Logs management 63 | * Remove Apps 64 | * Remove User Provided Services 65 | 66 | **PaaS Management:** 67 | 68 | * Organization quota 69 | * Organization 70 | * Space 71 | * Services, Service Instances, Service Plans, User provided Services & Service Binding 72 | * UAA Users 73 | * Users 74 | 75 | # Getting Started 76 | 77 | If you need to interact with a Cloud Foundry platform try this [online tool](https://tonicdev.com/npm/cf-client) and use this example: 78 | 79 | ``` Javascript 80 | "use-strict"; 81 | 82 | const endpoint = "https://api.ng.bluemix.net"; 83 | const username = "BLUEMIX_USERNAME"; 84 | const password = "BLUEMIX_PASSWORD"; 85 | 86 | const CloudController = new (require("cf-client")).CloudController(endpoint); 87 | const UsersUAA = new (require("cf-client")).UsersUAA; 88 | const Apps = new (require("cf-client")).Apps(endpoint); 89 | 90 | CloudController.getInfo().then( (result) => { 91 | UsersUAA.setEndPoint(result.authorization_endpoint); 92 | return UsersUAA.login(username, password); 93 | }).then( (result) => { 94 | Apps.setToken(result); 95 | return Apps.getApps(); 96 | }).then( (result) => { 97 | console.log(result); 98 | }).catch( (reason) => { 99 | console.error("Error: " + reason); 100 | }); 101 | 102 | ``` 103 | 104 | Explore the library and if you like the features, use it on your App: 105 | 106 | ``` Javascript 107 | 108 | npm install cf-client --save 109 | 110 | ``` 111 | 112 | # Testing 113 | 114 | This project has a test suite to ensure the readability of this project. Take a look the [Tests cases](https://github.com/jabrena/cf-nodejs-client/tree/master/test/) developed with [Mocha](https://mochajs.org/) & [Chai](http://chaijs.com/api/bdd/) to understand some stuff about [Cloud Foundry](https://www.cloudfoundry.org/) and the usage of this client. Besides, the project has invested some amount of time in testing phase to be the code with a nice coverage level. 115 | 116 | The development has been tested with: 117 | 118 | | [Local Instance](https://github.com/yudai/cf_nise_installer) | [PWS](https://console.run.pivotal.io) | [Bluemix](https://console.ng.bluemix.net/) | 119 | | -------------- |:-------------:| -------:| 120 | | 2.25.0 | 2.60.0 | 2.54.0 | 121 | 122 | **Last test:** 2016/01/26 123 | 124 | **Testing against Bluemix:** 125 | 126 | ``` shell 127 | export BLUEMIX_CF_API_URL=https://api.ng.bluemix.net && export BLUEMIX_username=$USERNAME && export BLUEMIX_password=$PASSWORD && npm run test:bluemix 128 | ``` 129 | 130 | **Test suite:** 131 | 132 | ``` shell 133 | npm test 134 | 135 | ``` 136 | 137 | **Code coverage:** 138 | 139 | ``` shell 140 | istanbul cover node_modules/mocha/bin/_mocha -- -R spec 141 | 142 | ``` 143 | 144 | # Issues 145 | 146 | If you have any question or doubt, please [create an issue](https://github.com/IBM-Bluemix/cf-nodejs-client/issues). 147 | 148 | # License 149 | 150 | Licensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0). 151 | 152 | # References 153 | 154 | * API Docs: http://apidocs.cloudfoundry.org/ 155 | * Developer list: https://lists.cloudfoundry.org/archives/list/cf-dev@lists.cloudfoundry.org/ 156 | * PWS Console: https://console.run.pivotal.io 157 | * Bluemix Console: https://console.ng.bluemix.net/ 158 | * PWS Forum: https://support.run.pivotal.io/forums 159 | * Bluemix Forum: https://developer.ibm.com/answers/ 160 | * CF for Beginners: From Zero to Hero http://slides.cf-hero.cloudcredo.io/ 161 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | environment: 2 | nodejs_version: "5.10.1" 3 | LOCAL_INSTANCE_1_CF_API_URL: https://api.bosh-lite.com 4 | LOCAL_INSTANCE_1_username: admin 5 | LOCAL_INSTANCE_1_password: admin 6 | 7 | install: 8 | - ps: Install-Product node $env:nodejs_version 9 | - npm install 10 | 11 | test_script: 12 | # Output useful info for debugging. 13 | - node --version 14 | - npm --version 15 | - npm run lint 16 | 17 | # Don't actually build. 18 | build: off 19 | -------------------------------------------------------------------------------- /docs/cf_architecture_block.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM-Cloud/cf-nodejs-client/aea779218f2a1663cfc597db61316f637a429562/docs/cf_architecture_block.png -------------------------------------------------------------------------------- /docs/umlDiagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM-Cloud/cf-nodejs-client/aea779218f2a1663cfc597db61316f637a429562/docs/umlDiagram.png -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var exports = module.exports = {}; 4 | 5 | /** 6 | * Library Version 7 | * @type {String} 8 | */ 9 | exports.version = '0.13.0'; 10 | 11 | /** 12 | * Support for Apps 13 | * @type {[type]} 14 | */ 15 | var Apps = require('./lib/model/cloudcontroller/Apps'); 16 | exports.Apps = Apps; 17 | 18 | /** 19 | * Support for Buildpacks 20 | * @type {[type]} 21 | */ 22 | var BuildPacks = require('./lib/model/cloudcontroller/BuildPacks'); 23 | exports.BuildPacks = BuildPacks; 24 | 25 | /** 26 | * Support for Cloud Controller 27 | * @type {[type]} 28 | */ 29 | var CloudController = require('./lib/model/cloudcontroller/CloudController'); 30 | exports.CloudController = CloudController; 31 | 32 | 33 | /** 34 | * Support for Domains 35 | * @type {[type]} 36 | */ 37 | var Domains = require('./lib/model/cloudcontroller/Domains'); 38 | exports.Domains = Domains; 39 | 40 | /** 41 | * Support for Events 42 | * @type {[type]} 43 | */ 44 | var Events = require('./lib/model/cloudcontroller/Events'); 45 | exports.Events = Events; 46 | 47 | /** 48 | * Support for Jobs 49 | * @type {[type]} 50 | */ 51 | var Jobs = require('./lib/model/cloudcontroller/Jobs'); 52 | exports.Jobs = Jobs; 53 | 54 | /** 55 | * Support for Logs 56 | * @type {[type]} 57 | */ 58 | var Logs = require('./lib/model/metrics/Logs'); 59 | exports.Logs = Logs; 60 | 61 | /** 62 | * Support for Organizations 63 | * @type {[type]} 64 | */ 65 | var Organizations = require('./lib/model/cloudcontroller/Organizations'); 66 | exports.Organizations = Organizations; 67 | 68 | /** 69 | * Support for Organizations Quota 70 | * @type {[type]} 71 | */ 72 | var OrganizationsQuota = require('./lib/model/cloudcontroller/OrganizationsQuota'); 73 | exports.OrganizationsQuota = OrganizationsQuota; 74 | 75 | /** 76 | * Support for Routes 77 | * @type {[type]} 78 | */ 79 | var Routes = require('./lib/model/cloudcontroller/Routes'); 80 | exports.Routes = Routes; 81 | 82 | /** 83 | * Support for Services 84 | * @type {[type]} 85 | */ 86 | var Services = require('./lib/model/cloudcontroller/Services'); 87 | exports.Services = Services; 88 | 89 | /** 90 | * Support for ServiceBindings 91 | * @type {[type]} 92 | */ 93 | var ServiceBindings = require('./lib/model/cloudcontroller/ServiceBindings'); 94 | exports.ServiceBindings = ServiceBindings; 95 | 96 | /** 97 | * Support for ServiceInstances 98 | * @type {[type]} 99 | */ 100 | var ServiceInstances = require('./lib/model/cloudcontroller/ServiceInstances'); 101 | exports.ServiceInstances = ServiceInstances; 102 | 103 | /** 104 | * Support for ServicePlans 105 | * @type {[type]} 106 | */ 107 | var ServicePlans = require('./lib/model/cloudcontroller/ServicePlans'); 108 | exports.ServicePlans = ServicePlans; 109 | 110 | /** 111 | * Support for Spaces 112 | * @type {[type]} 113 | */ 114 | var Spaces = require('./lib/model/cloudcontroller/Spaces'); 115 | exports.Spaces = Spaces; 116 | 117 | /** 118 | * Support for Spaces Quota 119 | * @type {[type]} 120 | */ 121 | var SpacesQuota = require('./lib/model/cloudcontroller/SpacesQuota'); 122 | exports.SpacesQuota = SpacesQuota; 123 | 124 | /** 125 | * Support for Stacks 126 | * @type {[type]} 127 | */ 128 | var Stacks = require('./lib/model/cloudcontroller/Stacks'); 129 | exports.Stacks = Stacks; 130 | 131 | /** 132 | * Support for User Provided Services 133 | * @type {[type]} 134 | */ 135 | var UserProvidedServices = require('./lib/model/cloudcontroller/UserProvidedServices'); 136 | exports.UserProvidedServices = UserProvidedServices; 137 | 138 | /** 139 | * Support for Users 140 | * @type {[type]} 141 | */ 142 | var Users = require('./lib/model/cloudcontroller/Users'); 143 | exports.Users = Users; 144 | 145 | /** 146 | * Support for Users UAA 147 | * @type {[type]} 148 | */ 149 | var UsersUAA = require('./lib/model/uaa/UsersUAA'); 150 | exports.UsersUAA = UsersUAA; 151 | -------------------------------------------------------------------------------- /lib/model/cloudcontroller/BuildPacks.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * This class handles Cloud Foundry buildpacks. 5 | * {@link https://docs.cloudfoundry.org/buildpacks/} 6 | */ 7 | class BuildPacks { 8 | 9 | /** 10 | * Empty constructor 11 | * @constructor 12 | * @returns {void} 13 | */ 14 | constructor() { 15 | //Buildpacks tested 16 | this.buildpackMap = {}; 17 | this.buildpackMap.static = "https://github.com/cloudfoundry/staticfile-buildpack"; 18 | this.buildpackMap.nodejs = "https://github.com/cloudfoundry/nodejs-buildpack"; 19 | this.buildpackMap.java = "https://github.com/cloudfoundry/java-buildpack"; 20 | this.buildpackMap.php = "https://github.com/cloudfoundry/php-buildpack"; 21 | this.buildpackMap.python = "https://github.com/cloudfoundry/python-buildpack"; 22 | } 23 | 24 | /** 25 | * Returns the address to use a buildpack 26 | * @param {String} key [Buildpack key] 27 | * @return {String} [Address about selected buildpack] 28 | * @throws {Error} This exception is throwed if the key is unknown 29 | */ 30 | get (key) { 31 | 32 | if (this.buildpackMap[key]) { 33 | return this.buildpackMap[key]; 34 | } 35 | throw new Error("This Buildpack is not supported"); 36 | } 37 | 38 | } 39 | 40 | module.exports = BuildPacks; 41 | -------------------------------------------------------------------------------- /lib/model/cloudcontroller/CloudController.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const CloudControllerBase = require("./CloudControllerBase"); 4 | 5 | /** 6 | * This class manages the entry point with the Cloud Foundry Controller. 7 | * {@link https://github.com/cloudfoundry/cloud_controller_ng} 8 | */ 9 | class CloudController extends CloudControllerBase { 10 | 11 | /** 12 | * @param {String} endPoint [CC endpoint] 13 | * @returns {void} 14 | * @constructor 15 | */ 16 | constructor(endPoint) { 17 | super(endPoint); 18 | } 19 | 20 | /** 21 | * Get information from Cloud Controller 22 | * {@link http://apidocs.cloudfoundry.org/214/info/get_info.html} 23 | * 24 | * @return {JSON} [Return all enabled services to use] 25 | */ 26 | getInfo () { 27 | 28 | const url = `${this.API_URL}/v2/info`; 29 | const options = { 30 | method: "GET", 31 | url: url 32 | }; 33 | 34 | return this.REST.request(options, this.HttpStatus.OK, true); 35 | } 36 | 37 | /** 38 | * Get information about all featured flags. 39 | * {@link http://apidocs.cloudfoundry.org/214/feature_flags/get_all_feature_flags.html} 40 | * 41 | * @return {JSON} [Response] 42 | */ 43 | getFeaturedFlags() { 44 | 45 | const url = `${this.API_URL}/v2/config/feature_flags`; 46 | const options = { 47 | method: "GET", 48 | url: url, 49 | headers: { 50 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 51 | } 52 | }; 53 | 54 | return this.REST.request(options, this.HttpStatus.OK, true); 55 | } 56 | 57 | /** 58 | * Get information about a determinated featured flag. 59 | * {@link http://apidocs.cloudfoundry.org/214/feature_flags/get_the_diego_docker_feature_flag.html} 60 | * 61 | * @param {String} flag [flag] 62 | * @return {JSON} [Response] 63 | */ 64 | getFeaturedFlag(flag) { 65 | 66 | const url = `${this.API_URL}/v2/config/feature_flags/${flag}`; 67 | const options = { 68 | method: "GET", 69 | url: url, 70 | headers: { 71 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 72 | } 73 | }; 74 | 75 | return this.REST.request(options, this.HttpStatus.OK, true); 76 | } 77 | 78 | /** 79 | * Enable a feature flag 80 | * {@link http://apidocs.cloudfoundry.org/214/feature_flags/set_a_feature_flag.html } 81 | * 82 | * @param {String} flag [flag to make the request] 83 | * @return {JSON} [Response] 84 | */ 85 | setFeaturedFlag(flag) { 86 | 87 | const url = `${this.API_URL}/v2/config/feature_flags/${flag}`; 88 | const options = { 89 | method: "PUT", 90 | url: url, 91 | headers: { 92 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 93 | } 94 | }; 95 | 96 | return this.REST.request(options, this.HttpStatus.OK, true); 97 | } 98 | 99 | } 100 | 101 | module.exports = CloudController; 102 | -------------------------------------------------------------------------------- /lib/model/cloudcontroller/CloudControllerBase.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const HttpUtils = require("../../utils/HttpUtils"); 4 | const HttpStatus = require("../../utils/HttpStatus"); 5 | 6 | /** 7 | * 8 | */ 9 | class CloudControllerBase { 10 | 11 | /** 12 | * @param {String} endPoint [CC endpoint] 13 | * @constructor 14 | * @returns {void} 15 | */ 16 | constructor(endPoint) { 17 | 18 | this.API_URL = endPoint; 19 | this.REST = new HttpUtils(); 20 | this.HttpStatus = HttpStatus; 21 | } 22 | 23 | /** 24 | * Set endpoint 25 | * @param {String} endPoint [CC endpoint] 26 | * @returns {void} 27 | */ 28 | setEndPoint (endPoint) { 29 | 30 | this.API_URL = endPoint; 31 | } 32 | 33 | /** 34 | * Set token 35 | * @param {JSON} token [Oauth token from UAA] 36 | * @returns {void} 37 | */ 38 | setToken (token) { 39 | 40 | this.UAA_TOKEN = token; 41 | } 42 | 43 | /** 44 | * Set a Custom requestObject 45 | * @param {[type]} requestObj [description] 46 | */ 47 | setCustomRequestObject(requestObj){ 48 | 49 | this.REST.setCustomRequestObject(requestObj); 50 | } 51 | } 52 | 53 | module.exports = CloudControllerBase; 54 | -------------------------------------------------------------------------------- /lib/model/cloudcontroller/Domains.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const CloudControllerBase = require("./CloudControllerBase"); 4 | 5 | /** 6 | * Manage Domains on Cloud Foundry 7 | */ 8 | class Domains extends CloudControllerBase { 9 | 10 | /** 11 | * @param {String} endPoint [CC endpoint] 12 | * @constructor 13 | * @returns {void} 14 | */ 15 | constructor(endPoint) { 16 | super(endPoint); 17 | } 18 | 19 | /** 20 | * Get Domains 21 | * {@link http://apidocs.cloudfoundry.org/214/domains_(deprecated)/list_all_domains_(deprecated).html} 22 | * 23 | * @return {JSON} [return a JSON response] 24 | */ 25 | getDomains () { 26 | 27 | const url = `${this.API_URL}/v2/domains`; 28 | const options = { 29 | method: "GET", 30 | url: url, 31 | headers: { 32 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 33 | } 34 | }; 35 | 36 | return this.REST.request(options, this.HttpStatus.OK, true); 37 | } 38 | 39 | /** 40 | * Get shared domains 41 | * {@link http://apidocs.cloudfoundry.org/214/shared_domains/list_all_shared_domains.html} 42 | * 43 | * @return {JSON} [return a JSON response] 44 | */ 45 | getSharedDomains () { 46 | 47 | const url = `${this.API_URL}/v2/shared_domains`; 48 | const options = { 49 | method: "GET", 50 | url: url, 51 | headers: { 52 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 53 | } 54 | }; 55 | 56 | return this.REST.request(options, this.HttpStatus.OK, true); 57 | } 58 | 59 | } 60 | 61 | module.exports = Domains; 62 | -------------------------------------------------------------------------------- /lib/model/cloudcontroller/Events.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const CloudControllerBase = require("./CloudControllerBase"); 4 | 5 | /** 6 | * Manage Events on Cloud Foundry 7 | */ 8 | class Events extends CloudControllerBase { 9 | 10 | /** 11 | * @param {String} endPoint [CC endpoint] 12 | * @constructor 13 | * @returns {void} 14 | */ 15 | constructor(endPoint) { 16 | super(endPoint); 17 | } 18 | 19 | /** 20 | * Get events from CC 21 | * {@link http://apidocs.cloudfoundry.org/214/events/list_all_events.html} 22 | * 23 | * @param {JSON} filter [Query String Parameters] 24 | * @return {JSON} [return a JSON response] 25 | */ 26 | getEvents (filter) { 27 | 28 | const url = `${this.API_URL}/v2/events`; 29 | let qs = {}; 30 | 31 | if (filter) { 32 | qs = filter; 33 | } 34 | const options = { 35 | method: "GET", 36 | url: url, 37 | headers: { 38 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 39 | }, 40 | qs: qs, 41 | useQuerystring: true 42 | }; 43 | 44 | return this.REST.request(options, this.HttpStatus.OK, true); 45 | } 46 | 47 | } 48 | 49 | module.exports = Events; 50 | -------------------------------------------------------------------------------- /lib/model/cloudcontroller/Jobs.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const CloudControllerBase = require("./CloudControllerBase"); 4 | 5 | /** 6 | * Manage Jobs on Cloud Foundry 7 | */ 8 | class Jobs extends CloudControllerBase { 9 | 10 | /** 11 | * @param {String} endPoint [CC endpoint] 12 | * @constructor 13 | * @returns {void} 14 | */ 15 | constructor(endPoint) { 16 | super(endPoint); 17 | } 18 | 19 | /** 20 | * Get a determinated Job 21 | * {@link http://apidocs.cloudfoundry.org/214/jobs/retrieve_job_that_is_queued.html} 22 | * 23 | * @param {String} guid [job guid] 24 | * @return {JSON} [return a JSON response] 25 | */ 26 | getJob (guid) { 27 | 28 | const url = `${this.API_URL}/v2/jobs/${guid}`; 29 | const options = { 30 | method: "GET", 31 | url: url, 32 | headers: { 33 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 34 | } 35 | }; 36 | 37 | return this.REST.request(options, this.HttpStatus.OK, true); 38 | } 39 | 40 | } 41 | 42 | module.exports = Jobs; 43 | -------------------------------------------------------------------------------- /lib/model/cloudcontroller/Organizations.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const CloudControllerBase = require("./CloudControllerBase"); 4 | 5 | /** 6 | * Manage Organizations in Cloud Foundry 7 | */ 8 | class Organizations extends CloudControllerBase { 9 | 10 | /** 11 | * @param {String} endPoint [CC endpoint] 12 | * @constructor 13 | * @returns {void} 14 | */ 15 | constructor(endPoint) { 16 | super(endPoint); 17 | } 18 | 19 | /** 20 | * Get Organizations 21 | * {@link http://apidocs.cloudfoundry.org/213/organizations/list_all_organizations.html} 22 | * 23 | * @param {String} token_type [Authentication type] 24 | * @param {String} access_token [Authentication token] 25 | * @return {JSON} [return a JSON response] 26 | */ 27 | getOrganizations () { 28 | 29 | const url = `${this.API_URL}/v2/organizations`; 30 | const options = { 31 | method: "GET", 32 | url: url, 33 | headers: { 34 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 35 | } 36 | }; 37 | 38 | return this.REST.request(options, this.HttpStatus.OK, true); 39 | } 40 | 41 | /** 42 | * Get memory usage from an Organization 43 | * {@link http://apidocs.cloudfoundry.org/222/organizations/retrieving_organization_memory_usage.html} 44 | * 45 | * @param {String} guid [org guid] 46 | * @return {JSON} [return a JSON response] 47 | */ 48 | getMemoryUsage (guid) { 49 | 50 | const url = `${this.API_URL}/v2/organizations/${guid}/memory_usage`; 51 | const options = { 52 | method: "GET", 53 | url: url, 54 | headers: { 55 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 56 | } 57 | }; 58 | 59 | return this.REST.request(options, this.HttpStatus.OK, true); 60 | } 61 | 62 | /** 63 | * Get a Organization 64 | * {@link http://apidocs.cloudfoundry.org/214/organizations/retrieve_a_particular_organization.html} 65 | * 66 | * @param {String} guid [Organization guid] 67 | * @return {JSON} [return a JSON response] 68 | */ 69 | getOrganization (guid) { 70 | 71 | const url = `${this.API_URL}/v2/organizations/${guid}`; 72 | const options = { 73 | method: "GET", 74 | url: url, 75 | headers: { 76 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 77 | } 78 | }; 79 | 80 | return this.REST.request(options, this.HttpStatus.OK, true); 81 | } 82 | 83 | /** 84 | * Get summary from an Organization 85 | * {@link http://apidocs.cloudfoundry.org/222/organizations/get_organization_summary.html} 86 | * 87 | * @param {String} guid [org guid] 88 | * @return {JSON} [return a JSON response] 89 | */ 90 | getSummary (guid) { 91 | 92 | const url = `${this.API_URL}/v2/organizations/${guid}/summary`; 93 | const options = { 94 | method: "GET", 95 | url: url, 96 | headers: { 97 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 98 | } 99 | }; 100 | 101 | return this.REST.request(options, this.HttpStatus.OK, true); 102 | } 103 | 104 | /** 105 | * Get private domains from an Organizations 106 | * {@link http://apidocs.cloudfoundry.org/214/organizations/list_all_private_domains_for_the_organization.html} 107 | * 108 | * @param {String} guid [org guid] 109 | * @return {JSON} [return a JSON response] 110 | */ 111 | getPrivateDomains (guid) { 112 | 113 | const url = `${this.API_URL}/v2/organizations/${guid}/private_domains`; 114 | const options = { 115 | method: "GET", 116 | url: url, 117 | headers: { 118 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 119 | } 120 | }; 121 | 122 | return this.REST.request(options, this.HttpStatus.OK, true); 123 | } 124 | 125 | /** 126 | * Add a new organization 127 | * {@link http://apidocs.cloudfoundry.org/222/organizations/creating_an_organization.html} 128 | * 129 | * @param {JSon} orgOptions [org options] 130 | * @return {JSON} [return a JSON response] 131 | */ 132 | add (orgOptions) { 133 | 134 | const url = `${this.API_URL}/v2/organizations`; 135 | const options = { 136 | method: "POST", 137 | url: url, 138 | headers: { 139 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 140 | }, 141 | form: JSON.stringify(orgOptions) 142 | }; 143 | 144 | return this.REST.request(options, this.HttpStatus.CREATED, true); 145 | } 146 | 147 | /** 148 | * Remove an Organization 149 | * {@link http://apidocs.cloudfoundry.org/222/organizations/delete_a_particular_organization.html} 150 | * 151 | * @param {String} guid [org guid] 152 | * @param {JSon} orgOptions [org options] 153 | * @return {String} [output] 154 | */ 155 | remove (guid, orgOptions) { 156 | 157 | const url = `${this.API_URL}/v2/organizations/${guid}`; 158 | let qs = {}; 159 | 160 | if (orgOptions) { 161 | qs = orgOptions; 162 | } 163 | const options = { 164 | method: "DELETE", 165 | url: url, 166 | headers: { 167 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 168 | }, 169 | qs: qs 170 | }; 171 | 172 | return this.REST.request(options, this.HttpStatus.NO_CONTENT, false); 173 | } 174 | 175 | /** 176 | * Get users from an Organization 177 | * {@link http://apidocs.cloudfoundry.org/222/organizations/list_all_users_for_the_organization.html} 178 | * 179 | * @param {String} guid [org guid] 180 | * @param {Json} filter [filter to search] 181 | * @return {Json} [output] 182 | */ 183 | getUsers (guid, filter) { 184 | 185 | const url = `${this.API_URL}/v2/organizations/${guid}/users`; 186 | let qs = {}; 187 | 188 | if (filter) { 189 | qs = filter; 190 | } 191 | const options = { 192 | method: "GET", 193 | url: url, 194 | headers: { 195 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 196 | }, 197 | qs: qs 198 | }; 199 | 200 | return this.REST.request(options, this.HttpStatus.OK, true); 201 | } 202 | 203 | /** 204 | * Associate a user with a organization 205 | * {@link http://apidocs.cloudfoundry.org/222/organizations/associate_user_with_the_organization.html} 206 | * 207 | * @param {String} guid [organization uid] 208 | * @param {String} userGuid [User uid] 209 | * @return {JSON} [return a JSON response] 210 | */ 211 | addUser (guid, userGuid) { 212 | const url = `${this.API_URL}/v2/organizations/${guid}/users/${userGuid}`; 213 | 214 | const options = { 215 | method: "PUT", 216 | url: url, 217 | headers: { 218 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 219 | } 220 | }; 221 | 222 | return this.REST.request(options, this.HttpStatus.CREATED, true); 223 | } 224 | 225 | /** 226 | * Dissociate a user with a organization 227 | * {@link http://apidocs.cloudfoundry.org/222/organizations/remove_user_from_the_organization.html} 228 | * 229 | * @param {String} guid [organization uid] 230 | * @param {String} userGuid [User uid] 231 | * @return {JSON} [return a JSON response] 232 | */ 233 | removeUser (guid, userGuid) { 234 | const url = `${this.API_URL}/v2/organizations/${guid}/users/${userGuid}`; 235 | 236 | const options = { 237 | method: "DELETE", 238 | url: url, 239 | headers: { 240 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 241 | } 242 | }; 243 | 244 | return this.REST.request(options, this.HttpStatus.NO_CONTENT, true); 245 | } 246 | 247 | /** 248 | * Get managers from an Organization 249 | * {@link http://apidocs.cloudfoundry.org/222/organizations/list_all_managers_for_the_organization.html} 250 | * 251 | * @param {String} guid [org guid] 252 | * @param {Json} filter [filter to search] 253 | * @return {Json} [output] 254 | */ 255 | getManagers (guid, filter) { 256 | 257 | const url = `${this.API_URL}/v2/organizations/${guid}/managers`; 258 | let qs = {}; 259 | 260 | if (filter) { 261 | qs = filter; 262 | } 263 | const options = { 264 | method: "GET", 265 | url: url, 266 | headers: { 267 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 268 | }, 269 | qs: qs 270 | }; 271 | 272 | return this.REST.request(options, this.HttpStatus.OK, true); 273 | } 274 | 275 | /** 276 | * Associate a manager with a organization 277 | * {@link http://apidocs.cloudfoundry.org/222/organizations/associate_manager_with_the_organization.html} 278 | * 279 | * @param {String} guid [organization uid] 280 | * @param {String} managerGuid [Manager uid] 281 | * @return {JSON} [return a JSON response] 282 | */ 283 | addManager (guid, managerGuid) { 284 | const url = `${this.API_URL}/v2/organizations/${guid}/managers/${managerGuid}`; 285 | 286 | const options = { 287 | method: "PUT", 288 | url: url, 289 | headers: { 290 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 291 | } 292 | }; 293 | 294 | return this.REST.request(options, this.HttpStatus.CREATED, true); 295 | } 296 | 297 | /** 298 | * Dissociate a manager with a organization 299 | * {@link http://apidocs.cloudfoundry.org/222/organizations/remove_manager_from_the_the_organization.html} 300 | * 301 | * @param {String} guid [organization uid] 302 | * @param {String} managerGuid [Manager uid] 303 | * @return {JSON} [return a JSON response] 304 | */ 305 | removeManager (guid, managerGuid) { 306 | const url = `${this.API_URL}/v2/organizations/${guid}/managers/${managerGuid}`; 307 | 308 | const options = { 309 | method: "DELETE", 310 | url: url, 311 | headers: { 312 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 313 | } 314 | }; 315 | 316 | return this.REST.request(options, this.HttpStatus.NO_CONTENT, true); 317 | } 318 | 319 | } 320 | 321 | module.exports = Organizations; 322 | -------------------------------------------------------------------------------- /lib/model/cloudcontroller/OrganizationsQuota.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const CloudControllerBase = require("./CloudControllerBase"); 4 | 5 | /** 6 | * Manage Quotas for an Organization 7 | */ 8 | class OrganizationsQuota extends CloudControllerBase { 9 | 10 | /** 11 | * @param {String} endPoint [CC endpoint] 12 | * @constructor 13 | * @returns {void} 14 | */ 15 | constructor(endPoint) { 16 | super(endPoint); 17 | } 18 | 19 | /** 20 | * Get Quotas for Organizations 21 | * {@link http://apidocs.cloudfoundry.org/213/organization_quota_definitions/list_all_organization_quota_definitions.html} 22 | * 23 | * @return {JSON} [return a JSON response] 24 | */ 25 | getQuotaDefinitions () { 26 | 27 | const url = `${this.API_URL}/v2/quota_definitions`; 28 | const options = { 29 | method: "GET", 30 | url: url, 31 | headers: { 32 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 33 | } 34 | }; 35 | 36 | return this.REST.request(options, this.HttpStatus.OK, true); 37 | } 38 | 39 | /** 40 | * Get a quota from an Organization 41 | * {@link http://apidocs.cloudfoundry.org/213/organization_quota_definitions/retrieve_a_particular_organization_quota_definition.html} 42 | * 43 | * @param {String} guid [org guid] 44 | * @return {JSON} [return a JSON response] 45 | */ 46 | getQuotaDefinition (guid) { 47 | 48 | const url = `${this.API_URL}/v2/quota_definitions/${guid}`; 49 | const options = { 50 | method: "GET", 51 | url: url, 52 | headers: { 53 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 54 | } 55 | }; 56 | 57 | return this.REST.request(options, this.HttpStatus.OK, true); 58 | } 59 | 60 | /** 61 | * Add a Quota 62 | * {@link http://apidocs.cloudfoundry.org/222/organization_quota_definitions/creating_a_organization_quota_definition.html} 63 | * 64 | * @param {JSON} quotaOptions [org options] 65 | * @return {JSON} [return a JSON response] 66 | */ 67 | add (quotaOptions) { 68 | 69 | const url = `${this.API_URL}/v2/quota_definitions`; 70 | const options = { 71 | method: "POST", 72 | url: url, 73 | headers: { 74 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 75 | }, 76 | form: JSON.stringify(quotaOptions) 77 | }; 78 | 79 | return this.REST.request(options, this.HttpStatus.CREATED, true); 80 | } 81 | 82 | /** 83 | * Remove a Quota for an Organization 84 | * {@link http://apidocs.cloudfoundry.org/222/organization_quota_definitions/delete_a_particular_organization_quota_definition.html} 85 | * 86 | * @param {String} guid [quota guid] 87 | * @param {Boolean} async [description] 88 | * @return {JSON} [return a JSON response] 89 | */ 90 | remove (guid, async) { 91 | 92 | const url = `${this.API_URL}/v2/quota_definitions/${guid}`; 93 | let qs = {}; 94 | 95 | if (async) { 96 | qs = async; 97 | } 98 | const options = { 99 | method: "DELETE", 100 | url: url, 101 | headers: { 102 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 103 | }, 104 | qs: qs 105 | }; 106 | 107 | return this.REST.request(options, this.HttpStatus.NO_CONTENT, false); 108 | } 109 | 110 | } 111 | 112 | module.exports = OrganizationsQuota; 113 | -------------------------------------------------------------------------------- /lib/model/cloudcontroller/Routes.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const CloudControllerBase = require("./CloudControllerBase"); 4 | 5 | /** 6 | * Manages Routes on Cloud Foundry 7 | */ 8 | class Routes extends CloudControllerBase { 9 | 10 | /** 11 | * @param {String} endPoint [CC endpoint] 12 | * @constructor 13 | * @returns {void} 14 | */ 15 | constructor(endPoint) { 16 | super(endPoint); 17 | } 18 | 19 | /** 20 | * Get Routes 21 | * {@link http://apidocs.cloudfoundry.org/214/routes/list_all_routes.html} 22 | * 23 | * @example 24 | * Paging: /v2/routes?order-direction=asc&page=2&results-per-page=50 25 | * 26 | * qs: { 27 | * 'page': page, 28 | * 'results-per-page': 50 29 | * } 30 | * 31 | * @param {JSON} filter [Search options] 32 | * @return {JSON} [return a JSON response] 33 | */ 34 | getRoutes (filter) { 35 | 36 | const url = `${this.API_URL}/v2/routes`; 37 | let qs = {}; 38 | 39 | if (filter) { 40 | qs = filter; 41 | } 42 | const options = { 43 | method: "GET", 44 | url: url, 45 | headers: { 46 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 47 | }, 48 | qs: qs 49 | }; 50 | 51 | return this.REST.request(options, this.HttpStatus.OK, true); 52 | } 53 | 54 | /** 55 | * Get a Route 56 | * {@link http://apidocs.cloudfoundry.org/214/routes/retrieve_a_particular_route.html} 57 | * 58 | * @param {String} guid [route guid] 59 | * @return {JSON} [return a JSON response] 60 | */ 61 | getRoute (guid) { 62 | 63 | const url = `${this.API_URL}/v2/routes/${guid}`; 64 | const options = { 65 | method: "GET", 66 | url: url, 67 | headers: { 68 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 69 | } 70 | }; 71 | 72 | return this.REST.request(options, this.HttpStatus.OK, true); 73 | } 74 | 75 | /** 76 | * Add a Route 77 | * {@link http://apidocs.cloudfoundry.org/213/routes/creating_a_route.html} 78 | * 79 | * @param {JSON} routeOptions [route options] 80 | * @return {JSON} [return a JSON response] 81 | */ 82 | add (routeOptions) { 83 | 84 | const url = `${this.API_URL}/v2/routes`; 85 | const options = { 86 | method: "POST", 87 | url: url, 88 | headers: { 89 | "Content-Type": "application/x-www-form-urlencoded", 90 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 91 | }, 92 | form: JSON.stringify(routeOptions) 93 | }; 94 | 95 | return this.REST.request(options, this.HttpStatus.CREATED, true); 96 | } 97 | 98 | /** 99 | * Remove a Route 100 | * {@link http://apidocs.cloudfoundry.org/214/routes/delete_a_particular_route.html} 101 | * 102 | * @param {String} guid [route guid] 103 | * @return {String} [output] 104 | */ 105 | remove (guid) { 106 | 107 | const url = `${this.API_URL}/v2/routes/${guid}`; 108 | const options = { 109 | method: "DELETE", 110 | url: url, 111 | headers: { 112 | "Content-Type": "application/x-www-form-urlencoded", 113 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 114 | } 115 | }; 116 | 117 | return this.REST.request(options, this.HttpStatus.NO_CONTENT, false); 118 | } 119 | 120 | /** 121 | * Check to see if a hostname exists 122 | * {@link http://apidocs.cloudfoundry.org/214/routes/check_a_route_exists.html} 123 | * 124 | * @param {String} domainGuid [domain guid] 125 | * @param {String} hostname [hostname] 126 | * @return {String} [output] 127 | */ 128 | exists (domainGuid, hostname) { 129 | const url = `${this.API_URL}/v2/routes/reserved/domain/${domainGuid}/host/${hostname}`; 130 | const options = { 131 | method: "GET", 132 | url: url, 133 | headers: { 134 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 135 | } 136 | }; 137 | 138 | return this.REST.request(options, this.HttpStatus.NO_CONTENT, false); 139 | } 140 | 141 | } 142 | 143 | module.exports = Routes; 144 | -------------------------------------------------------------------------------- /lib/model/cloudcontroller/ServiceBindings.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const CloudControllerBase = require("./CloudControllerBase"); 4 | 5 | /** 6 | * Manages Service Binding on Cloud Foundry 7 | */ 8 | class ServiceBindings extends CloudControllerBase { 9 | 10 | /** 11 | * @param {String} endPoint [CC endpoint] 12 | * @constructor 13 | * @returns {void} 14 | */ 15 | constructor(endPoint) { 16 | super(endPoint); 17 | } 18 | 19 | /** 20 | * Get Service Bindings 21 | * {@link http://apidocs.cloudfoundry.org/217/service_bindings/list_all_service_bindings.html} 22 | * 23 | * @param {String} filter [Search option] 24 | * @return {JSON} [return a JSON response] 25 | */ 26 | getServiceBindings (filter) { 27 | 28 | const url = `${this.API_URL}/v2/service_bindings`; 29 | let qs = {}; 30 | 31 | if (filter) { 32 | qs = filter; 33 | } 34 | const options = { 35 | method: "GET", 36 | url: url, 37 | headers: { 38 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 39 | }, 40 | qs: qs 41 | }; 42 | 43 | return this.REST.request(options, this.HttpStatus.OK, true); 44 | } 45 | 46 | /** 47 | * Get a Service Binding 48 | * {@link http://apidocs.cloudfoundry.org/217/service_bindings/retrieve_a_particular_service_binding.html} 49 | * 50 | * @param {String} guid [serviceBinding guid] 51 | * @return {JSON} [return a JSON response] 52 | */ 53 | getServiceBinding (guid) { 54 | 55 | const url = `${this.API_URL}/v2/service_bindings/${guid}`; 56 | const options = { 57 | method: "GET", 58 | url: url, 59 | headers: { 60 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 61 | } 62 | }; 63 | 64 | return this.REST.request(options, this.HttpStatus.OK, true); 65 | } 66 | 67 | /** 68 | * Associate Service with an App 69 | * {@link http://apidocs.cloudfoundry.org/217/service_bindings/create_a_service_binding.html} 70 | * 71 | * @param {String} serviceGuid [service_guid] 72 | * @param {String} appGuid [app_guid] 73 | * @return {JSON} [return a JSON response] 74 | */ 75 | associateServiceWithApp (serviceGuid, appGuid) { 76 | 77 | const url = `${this.API_URL}/v2/service_bindings`; 78 | const options = { 79 | method: "POST", 80 | url: url, 81 | headers: { 82 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 83 | }, 84 | form: JSON.stringify({ 85 | service_instance_guid: serviceGuid, 86 | app_guid: appGuid 87 | }) 88 | }; 89 | 90 | return this.REST.request(options, this.HttpStatus.CREATED, true); 91 | } 92 | 93 | /** 94 | * Remove a Service Binding 95 | * {@link http://apidocs.cloudfoundry.org/217/service_bindings/delete_a_particular_service_binding.html} 96 | * 97 | * @param {String} guid [service_guid] 98 | * @return {JSON} [return a JSON response] 99 | */ 100 | remove (guid) { 101 | 102 | const url = `${this.API_URL}/v2/service_bindings/${guid}`; 103 | const options = { 104 | method: "DELETE", 105 | url: url, 106 | headers: { 107 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 108 | } 109 | }; 110 | 111 | return this.REST.request(options, this.HttpStatus.NO_CONTENT, false); 112 | } 113 | 114 | } 115 | 116 | module.exports = ServiceBindings; 117 | -------------------------------------------------------------------------------- /lib/model/cloudcontroller/ServiceInstances.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const CloudControllerBase = require("./CloudControllerBase"); 4 | 5 | /** 6 | * Manages Service Instances on Cloud Foundry 7 | */ 8 | class ServiceInstances extends CloudControllerBase { 9 | 10 | /** 11 | * @param {String} endPoint [CC endpoint] 12 | * @constructor 13 | * @returns {void} 14 | */ 15 | constructor(endPoint) { 16 | super(endPoint); 17 | } 18 | 19 | /** 20 | * Get Service Instances 21 | * {@link https://apidocs.cloudfoundry.org/226/service_instances/list_all_service_instances.html} 22 | * 23 | * @param {String} filter [query string] 24 | * @return {JSON} [return a JSON response] 25 | */ 26 | getInstances (filter) { 27 | 28 | const url = `${this.API_URL}/v2/service_instances`; 29 | let qs = {}; 30 | 31 | if (filter) { 32 | qs = filter; 33 | } 34 | const options = { 35 | method: "GET", 36 | url: url, 37 | headers: { 38 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 39 | }, 40 | qs: qs 41 | }; 42 | 43 | return this.REST.request(options, this.HttpStatus.OK, true); 44 | } 45 | 46 | /** 47 | * Get a Service Instance 48 | * {@link https://apidocs.cloudfoundry.org/226/service_instances/retrieve_a_particular_service_instance.html} 49 | * 50 | * @param {String} guid [servicePlan guid] 51 | * @return {JSON} [return a JSON response] 52 | */ 53 | getInstance (guid) { 54 | 55 | const url = `${this.API_URL}/v2/service_instances/${guid}`; 56 | const options = { 57 | method: "GET", 58 | url: url, 59 | headers: { 60 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 61 | } 62 | }; 63 | 64 | return this.REST.request(options, this.HttpStatus.OK, true); 65 | } 66 | 67 | /** 68 | * Get a Service Instance Permissions 69 | * {@link https://apidocs.cloudfoundry.org/226/service_instances/retrieving_permissions_on_a_service_instance.html} 70 | * 71 | * @param {String} guid [servicePlan guid] 72 | * @return {JSON} [return a JSON response] 73 | */ 74 | getInstancePermissions (guid) { 75 | 76 | const url = `${this.API_URL}/v2/service_instances/${guid}/permissions`; 77 | const options = { 78 | method: "GET", 79 | url: url, 80 | headers: { 81 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 82 | } 83 | }; 84 | 85 | return this.REST.request(options, this.HttpStatus.OK, true); 86 | } 87 | 88 | /** 89 | * Get a Service Instance Bindings 90 | * {@link https://apidocs.cloudfoundry.org/226/service_instances/list_all_service_bindings_for_the_service_instance.html} 91 | * 92 | * @param {String} guid [servicePlan guid] 93 | * @return {JSON} [return a JSON response] 94 | */ 95 | getInstanceBindings (guid) { 96 | 97 | const url = `${this.API_URL}/v2/service_instances/${guid}/service_bindings`; 98 | const options = { 99 | method: "GET", 100 | url: url, 101 | headers: { 102 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 103 | } 104 | }; 105 | 106 | return this.REST.request(options, this.HttpStatus.OK, true); 107 | } 108 | 109 | /** 110 | * Get a Service Instance Routes 111 | * {@link https://apidocs.cloudfoundry.org/226/service_instances/list_all_routes_for_the_service_instance.html} 112 | * 113 | * @param {String} guid [servicePlan guid] 114 | * @return {JSON} [return a JSON response] 115 | */ 116 | getInstanceRoutes (guid) { 117 | 118 | const url = `${this.API_URL}/v2/service_instances/${guid}/routes`; 119 | const options = { 120 | method: "GET", 121 | url: url, 122 | headers: { 123 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 124 | } 125 | }; 126 | 127 | return this.REST.request(options, this.HttpStatus.OK, true); 128 | } 129 | 130 | /** 131 | * Create a Service Instance 132 | * {@link https://apidocs.cloudfoundry.org/226/service_instances/creating_a_service_instance.html} 133 | * 134 | * @param {JSON} appOptions [options to create the application] 135 | * @return {JSON} [return a JSON response] 136 | */ 137 | create (appOptions) { 138 | 139 | const url = `${this.API_URL}/v2/service_instances`; 140 | const options = { 141 | method: "POST", 142 | url: url, 143 | headers: { 144 | "Content-Type": "application/x-www-form-urlencoded", 145 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 146 | }, 147 | form: JSON.stringify(appOptions) 148 | }; 149 | 150 | return this.REST.request(options, this.HttpStatus.CREATED, true); 151 | } 152 | 153 | /** 154 | * Remove a Service Instance 155 | * {@link https://apidocs.cloudfoundry.org/226/service_instances/delete_a_service_instance.html} 156 | * 157 | * @param {String} guid [Service Instance guid] 158 | * @return {JSON} [return a JSON response] 159 | */ 160 | remove (guid) { 161 | 162 | const url = `${this.API_URL}/v2/service_instances/${guid}`; 163 | const options = { 164 | method: "DELETE", 165 | url: url, 166 | headers: { 167 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 168 | } 169 | }; 170 | 171 | return this.REST.request(options, this.HttpStatus.NO_CONTENT, false); 172 | } 173 | 174 | /** 175 | * Update an Service Instance 176 | * {@link https://apidocs.cloudfoundry.org/226/service_instances/update_a_service_instance.html} 177 | * 178 | * @param {String} serviceInstanceGuid [service instance guid] 179 | * @param {JSON} serviceInstanceOptions [options to update the instance] 180 | * @return {JSON} [information about the instance] 181 | */ 182 | update (serviceInstanceGuid, serviceInstanceOptions) { 183 | 184 | const url = `${this.API_URL}/v2/service_instances/${serviceInstanceGuid}`; 185 | const options = { 186 | method: "PUT", 187 | url: url, 188 | headers: { 189 | "Content-Type": "application/x-www-form-urlencoded", 190 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 191 | }, 192 | form: JSON.stringify(serviceInstanceOptions) 193 | }; 194 | 195 | return this.REST.request(options, this.HttpStatus.CREATED, true); 196 | } 197 | 198 | } 199 | 200 | module.exports = ServiceInstances; 201 | -------------------------------------------------------------------------------- /lib/model/cloudcontroller/ServicePlans.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const CloudControllerBase = require("./CloudControllerBase"); 4 | 5 | /** 6 | * Manages Service Plan on Cloud Foundry 7 | */ 8 | class ServicePlans extends CloudControllerBase { 9 | 10 | /** 11 | * @param {String} endPoint [CC endpoint] 12 | * @constructor 13 | * @returns {void} 14 | */ 15 | constructor(endPoint) { 16 | super(endPoint); 17 | } 18 | 19 | /** 20 | * Get Service Plans 21 | * {@link https://apidocs.cloudfoundry.org/226/service_plans/list_all_service_plans.html} 22 | * 23 | * @param {String} filter [Search options] 24 | * @return {JSON} [return a JSON response] 25 | */ 26 | getServicePlans (filter) { 27 | 28 | const url = `${this.API_URL}/v2/service_plans`; 29 | let qs = {}; 30 | 31 | if (filter) { 32 | qs = filter; 33 | } 34 | const options = { 35 | method: "GET", 36 | url: url, 37 | headers: { 38 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 39 | }, 40 | qs: qs 41 | }; 42 | 43 | return this.REST.request(options, this.HttpStatus.OK, true); 44 | } 45 | 46 | /** 47 | * Get a Service Plan 48 | * {@link https://apidocs.cloudfoundry.org/226/service_plans/retrieve_a_particular_service_plan.html} 49 | * 50 | * @param {String} guid [servicePlan guid] 51 | * @return {JSON} [return a JSON response] 52 | */ 53 | getServicePlan (guid) { 54 | 55 | const url = `${this.API_URL}/v2/service_plans/${guid}`; 56 | const options = { 57 | method: "GET", 58 | url: url, 59 | headers: { 60 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 61 | } 62 | }; 63 | 64 | return this.REST.request(options, this.HttpStatus.OK, true); 65 | } 66 | 67 | /** 68 | * List all Service Instances for a Service Plan 69 | * {@link https://apidocs.cloudfoundry.org/226/service_plans/list_all_service_instances_for_the_service_plan.html} 70 | * 71 | * @param {String} guid [servicePlan guid] 72 | * @return {JSON} [return a JSON response] 73 | */ 74 | getServicePlanInstances (guid) { 75 | 76 | const url = `${this.API_URL}/v2/service_plans/${guid}/service_instances`; 77 | const options = { 78 | method: "GET", 79 | url: url, 80 | headers: { 81 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 82 | } 83 | }; 84 | 85 | return this.REST.request(options, this.HttpStatus.OK, true); 86 | } 87 | 88 | /** 89 | * Remove a Service Plan 90 | * {@link https://apidocs.cloudfoundry.org/226/service_plans/delete_a_particular_service_plans.html} 91 | * 92 | * @param {String} guid [servicePlan_guid] 93 | * @return {JSON} [return a JSON response] 94 | */ 95 | remove (guid) { 96 | 97 | const url = `${this.API_URL}/v2/service_plans/${guid}`; 98 | const options = { 99 | method: "DELETE", 100 | url: url, 101 | headers: { 102 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 103 | } 104 | }; 105 | 106 | return this.REST.request(options, this.HttpStatus.NO_CONTENT, false); 107 | } 108 | 109 | } 110 | 111 | module.exports = ServicePlans; 112 | -------------------------------------------------------------------------------- /lib/model/cloudcontroller/Services.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const CloudControllerBase = require("./CloudControllerBase"); 4 | 5 | /** 6 | * Manages Services on Cloud Foundry 7 | */ 8 | class Services extends CloudControllerBase { 9 | 10 | /** 11 | * @param {String} endPoint [CC endpoint] 12 | * @constructor 13 | * @returns {void} 14 | */ 15 | constructor(endPoint) { 16 | super(endPoint); 17 | } 18 | 19 | /** 20 | * Get Services 21 | * {@link https://apidocs.cloudfoundry.org/226/services/list_all_services.html} 22 | * 23 | * @param {String} filter [query string] 24 | * @return {JSON} [return a JSON response] 25 | */ 26 | getServices (filter) { 27 | 28 | const url = `${this.API_URL}/v2/services`; 29 | let qs = {}; 30 | 31 | if (filter) { 32 | qs = filter; 33 | } 34 | const options = { 35 | method: "GET", 36 | url: url, 37 | headers: { 38 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 39 | }, 40 | qs: qs 41 | }; 42 | 43 | return this.REST.request(options, this.HttpStatus.OK, true); 44 | } 45 | 46 | /** 47 | * Get a Service 48 | * {@link https://apidocs.cloudfoundry.org/226/services/retrieve_a_particular_service.html} 49 | * 50 | * @param {String} guid [servicePlan guid] 51 | * @return {JSON} [return a JSON response] 52 | */ 53 | getService (guid) { 54 | 55 | const url = `${this.API_URL}/v2/services/${guid}`; 56 | const options = { 57 | method: "GET", 58 | url: url, 59 | headers: { 60 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 61 | } 62 | }; 63 | 64 | return this.REST.request(options, this.HttpStatus.OK, true); 65 | } 66 | 67 | /** 68 | * List all Service Plans for a Service 69 | * {@link https://apidocs.cloudfoundry.org/226/services/list_all_service_plans_for_the_service.html} 70 | * 71 | * @param {String} guid [service guid] 72 | * @return {JSON} [return a JSON response] 73 | */ 74 | getServicePlans (guid) { 75 | 76 | const url = `${this.API_URL}/v2/services/${guid}/service_plans`; 77 | const options = { 78 | method: "GET", 79 | url: url, 80 | headers: { 81 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 82 | } 83 | }; 84 | 85 | return this.REST.request(options, this.HttpStatus.OK, true); 86 | } 87 | 88 | /** 89 | * Remove a Service 90 | * {@link https://apidocs.cloudfoundry.org/226/services/delete_a_particular_service.html} 91 | * 92 | * @param {String} guid [service_guid] 93 | * @return {String} [return REST response] 94 | */ 95 | remove (guid) { 96 | 97 | const url = `${this.API_URL}/v2/services/${guid}`; 98 | const options = { 99 | method: "DELETE", 100 | url: url, 101 | headers: { 102 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 103 | } 104 | }; 105 | 106 | return this.REST.request(options, this.HttpStatus.NO_CONTENT, false); 107 | } 108 | 109 | } 110 | 111 | module.exports = Services; 112 | -------------------------------------------------------------------------------- /lib/model/cloudcontroller/SpacesQuota.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const CloudControllerBase = require("./CloudControllerBase"); 4 | 5 | /** 6 | * Manage SpacesQuota 7 | */ 8 | class SpacesQuota extends CloudControllerBase { 9 | 10 | /** 11 | * @param {String} endPoint [CC endpoint] 12 | * @constructor 13 | * @returns {void} 14 | */ 15 | constructor(endPoint) { 16 | super(endPoint); 17 | } 18 | 19 | /** 20 | * Get Quota Definitions 21 | * {@link http://apidocs.cloudfoundry.org/214/space_quota_definitions/list_all_space_quota_definitions.html} 22 | * 23 | * @return {JSON} [return a JSON response] 24 | */ 25 | getQuotaDefinitions () { 26 | 27 | const url = `${this.API_URL}/v2/space_quota_definitions`; 28 | const options = { 29 | method: "GET", 30 | url: url, 31 | headers: { 32 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 33 | } 34 | }; 35 | 36 | return this.REST.request(options, this.HttpStatus.OK, true); 37 | } 38 | 39 | } 40 | 41 | module.exports = SpacesQuota; 42 | -------------------------------------------------------------------------------- /lib/model/cloudcontroller/Stacks.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const CloudControllerBase = require("./CloudControllerBase"); 4 | 5 | /** 6 | * Manage Stacks 7 | */ 8 | class Stacks extends CloudControllerBase { 9 | 10 | /** 11 | * @param {String} endPoint [CC endpoint] 12 | * @constructor 13 | * @returns {void} 14 | */ 15 | constructor(endPoint) { 16 | super(endPoint); 17 | } 18 | 19 | /** 20 | * Get Stacks 21 | * {@link http://apidocs.cloudfoundry.org/214/stacks/list_all_stacks.html} 22 | * 23 | * @return {JSON} [return a JSON response] 24 | */ 25 | getStacks () { 26 | 27 | const url = `${this.API_URL}/v2/stacks`; 28 | const options = { 29 | method: "GET", 30 | url: url, 31 | headers: { 32 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 33 | } 34 | }; 35 | 36 | return this.REST.request(options, this.HttpStatus.OK, true); 37 | } 38 | 39 | } 40 | 41 | module.exports = Stacks; 42 | -------------------------------------------------------------------------------- /lib/model/cloudcontroller/UserProvidedServices.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const CloudControllerBase = require("./CloudControllerBase"); 4 | 5 | /** 6 | * Manage User Provided Services 7 | * {@link https://docs.cloudfoundry.org/devguide/services/user-provided.html} 8 | */ 9 | class UserProvidedServices extends CloudControllerBase { 10 | 11 | /** 12 | * @param {String} endPoint [CC endpoint] 13 | * @constructor 14 | * @returns {void} 15 | */ 16 | constructor(endPoint) { 17 | super(endPoint); 18 | } 19 | 20 | /** 21 | * Get Services 22 | * {@link http://apidocs.cloudfoundry.org/217/user_provided_service_instances/list_all_user_provided_service_instances.html} 23 | * 24 | * @return {JSON} [return a JSON response] 25 | */ 26 | getServices () { 27 | 28 | const url = `${this.API_URL}/v2/user_provided_service_instances`; 29 | const options = { 30 | method: "GET", 31 | url: url, 32 | headers: { 33 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 34 | } 35 | }; 36 | 37 | return this.REST.request(options, this.HttpStatus.OK, true); 38 | } 39 | 40 | /** 41 | * Get a Service 42 | * {@link http://apidocs.cloudfoundry.org/217/user_provided_service_instances/retrieve_a_particular_user_provided_service_instance.html} 43 | * 44 | * @param {String} guid [Service guid] 45 | * @return {JSON} [return a JSON response] 46 | */ 47 | getService (guid) { 48 | 49 | const url = `${this.API_URL}/v2/user_provided_service_instances/${guid}`; 50 | const options = { 51 | method: "GET", 52 | url: url, 53 | headers: { 54 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 55 | } 56 | }; 57 | 58 | return this.REST.request(options, this.HttpStatus.OK, true); 59 | } 60 | 61 | /** 62 | * Create an user Provided Service 63 | * {@link http://apidocs.cloudfoundry.org/217/user_provided_service_instances/creating_a_user_provided_service_instance.html} 64 | * 65 | * @param {JSON} upsOptions [user_provided_service_options] 66 | * @return {JSON} [return a JSON response] 67 | */ 68 | add (upsOptions) { 69 | 70 | const url = `${this.API_URL}/v2/user_provided_service_instances`; 71 | const options = { 72 | method: "POST", 73 | url: url, 74 | headers: { 75 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 76 | }, 77 | form: JSON.stringify(upsOptions) 78 | }; 79 | 80 | return this.REST.request(options, this.HttpStatus.CREATED, true); 81 | } 82 | 83 | /** 84 | * Remove an User provided service 85 | * {@link http://apidocs.cloudfoundry.org/217/user_provided_service_instances/delete_a_particular_user_provided_service_instance.html} 86 | * 87 | * @param {String} guid [service_guid] 88 | * @return {String} [output] 89 | */ 90 | remove (guid) { 91 | 92 | const url = `${this.API_URL}/v2/user_provided_service_instances/${guid}`; 93 | const options = { 94 | method: "DELETE", 95 | url: url, 96 | headers: { 97 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 98 | } 99 | }; 100 | 101 | return this.REST.request(options, this.HttpStatus.NO_CONTENT, false); 102 | } 103 | 104 | /** 105 | * Get service bindings from user provided services 106 | * {@link http://apidocs.cloudfoundry.org/221/user_provided_service_instances/list_all_service_bindings_for_the_user_provided_service_instance.html} 107 | * 108 | * @example 109 | * var filter = { 110 | * q': 'app_guid:' + "65be2a2d-a643-4e01-b33d-8755d5934ae6" 111 | * }; 112 | * 113 | * @param {String} guid [service_guid] 114 | * @param {JSON} filter [search options] 115 | * @return {JSON} [Output] 116 | */ 117 | getServiceBindings (guid, filter) { 118 | 119 | const url = `${this.API_URL}/v2/user_provided_service_instances/${guid}/service_bindings`; 120 | let qs = {}; 121 | 122 | if (filter) { 123 | qs = filter; 124 | } 125 | const options = { 126 | method: "GET", 127 | url: url, 128 | headers: { 129 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 130 | }, 131 | qs: qs 132 | }; 133 | 134 | return this.REST.request(options, this.HttpStatus.OK, true); 135 | } 136 | 137 | } 138 | 139 | module.exports = UserProvidedServices; 140 | -------------------------------------------------------------------------------- /lib/model/cloudcontroller/Users.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const CloudControllerBase = require("./CloudControllerBase"); 4 | 5 | /** 6 | * Manage Users 7 | */ 8 | class Users extends CloudControllerBase { 9 | 10 | /** 11 | * @param {String} endPoint [CC endpoint] 12 | * @constructor 13 | * @returns {void} 14 | */ 15 | constructor(endPoint) { 16 | super(endPoint); 17 | } 18 | 19 | /** 20 | * Add a User 21 | * {@link http://apidocs.cloudfoundry.org/222/users/creating_a_user.html} 22 | * 23 | * @param {JSON} userOptions [user options] 24 | * @return {JSON} [return a JSON response] 25 | */ 26 | add (userOptions) { 27 | 28 | const url = `${this.API_URL}/v2/users`; 29 | const options = { 30 | method: "POST", 31 | url: url, 32 | headers: { 33 | Accept: "application/json", 34 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 35 | }, 36 | form: JSON.stringify(userOptions) 37 | }; 38 | 39 | return this.REST.request(options, this.HttpStatus.CREATED, true); 40 | } 41 | 42 | /** 43 | * Delete an User 44 | * {@link http://apidocs.cloudfoundry.org/222/users/delete_a_particular_user.html} 45 | * 46 | * @param {String} guid [user guid] 47 | * @return {JSON} [return a JSON response] 48 | */ 49 | remove (guid) { 50 | 51 | const url = `${this.API_URL}/v2/users/${guid}`; 52 | const options = { 53 | method: "DELETE", 54 | url: url, 55 | headers: { 56 | Accept: "application/json", 57 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 58 | } 59 | }; 60 | 61 | return this.REST.request(options, this.HttpStatus.NO_CONTENT, false); 62 | } 63 | 64 | /** 65 | * Get Users 66 | * {@link http://apidocs.cloudfoundry.org/222/users/list_all_users.html} 67 | * 68 | * @return {JSON} [return a JSON response] 69 | */ 70 | getUsers () { 71 | 72 | const url = `${this.API_URL}/v2/users`; 73 | const options = { 74 | method: "GET", 75 | url: url, 76 | headers: { 77 | Accept: "application/json", 78 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 79 | } 80 | }; 81 | 82 | return this.REST.request(options, this.HttpStatus.OK, true); 83 | } 84 | 85 | /** 86 | * Associate User with a Space 87 | * {@link http://apidocs.cloudfoundry.org/222/users/associate_space_with_the_user.html} 88 | * 89 | * @param {String} userGuid [user guid] 90 | * @param {String} spaceGuid [space guid] 91 | * @return {JSON} [return a JSON response] 92 | */ 93 | associateSpace (userGuid, spaceGuid) { 94 | 95 | const url = `${this.API_URL}/v2/users/${userGuid}/spaces/${spaceGuid}`; 96 | const options = { 97 | method: "PUT", 98 | url: url, 99 | headers: { 100 | Accept: "application/json", 101 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 102 | } 103 | }; 104 | 105 | return this.REST.request(options, this.HttpStatus.CREATED, true); 106 | } 107 | 108 | /** 109 | * Associate User with an Organization 110 | * {@link http://apidocs.cloudfoundry.org/222/users/associate_organization_with_the_user.html} 111 | * 112 | * @param {String} userGuid [user guid] 113 | * @param {String} orgGuid [space guid] 114 | * @return {JSON} [return a JSON response] 115 | */ 116 | associateOrganization (userGuid, orgGuid) { 117 | 118 | const url = `${this.API_URL}/v2/users/${userGuid}/organizations/${orgGuid}`; 119 | const options = { 120 | method: "PUT", 121 | url: url, 122 | headers: { 123 | Accept: "application/json", 124 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 125 | } 126 | }; 127 | 128 | return this.REST.request(options, this.HttpStatus.CREATED, true); 129 | } 130 | 131 | } 132 | 133 | module.exports = Users; 134 | -------------------------------------------------------------------------------- /lib/model/metrics/Logs.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const HttpUtils = require("../../utils/HttpUtils"); 4 | const HttpStatus = require("../../utils/HttpStatus"); 5 | const ws = require('ws'); 6 | 7 | const path = require("path"); 8 | const builder = require("protobufjs").loadProtoFile(path.join(__dirname, "log_message.proto")); 9 | 10 | //Build the logmessage package from the log_message.proto file 11 | const LOG_MESSAGE = builder.build("logmessage"); 12 | 13 | /** 14 | * Manage Logs in Cloud Foundry 15 | * {@link https://docs.pivotal.io/pivotalcf/devguide/deploy-apps/streaming-logs.html} 16 | * @constructor 17 | */ 18 | class Logs { 19 | 20 | /** 21 | * Constructor 22 | * @constructor 23 | * @returns {void} 24 | */ 25 | constructor() { 26 | this.REST = new HttpUtils(); 27 | this.HttpStatus = HttpStatus; 28 | } 29 | 30 | /** 31 | * Set endpoint 32 | * @param {String} endPoint [Logging endpoint] 33 | * @returns {void} 34 | */ 35 | setEndPoint (endPoint) { 36 | 37 | this.LOG_API_URL = endPoint; 38 | } 39 | 40 | /** 41 | * Set token 42 | * @param {JSON} token [Oauth token from UAA] 43 | * @returns {void} 44 | */ 45 | setToken (token) { 46 | 47 | this.UAA_TOKEN = token; 48 | } 49 | 50 | /** 51 | * Method used to return data from CF log services. 52 | * {@link http://docs.run.pivotal.io/devguide/deploy-apps/streaming-logs.html} 53 | * 54 | * @param {String} appGuid [app guid] 55 | * @return {JSon} [UAA Response] 56 | */ 57 | getRecent (appGuid) { 58 | 59 | var http_url = this.LOG_API_URL.replace('wss://', 'https://'); 60 | var options = { 61 | url: http_url + '/recent?app=' + appGuid, 62 | encoding: null, 63 | headers: { 64 | 'transfer-encoding': '', 65 | 'Authorization': `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}`, 66 | 'Content-Type': 'text' 67 | } 68 | }; 69 | 70 | return this.REST.request(options, this.HttpStatus.OK, false).then((response) => { 71 | //The response is an array of protocol buffer encoded messages 72 | return response.map((message) => { 73 | //For each message, decode it and also convert the binary text to a string 74 | const $message = LOG_MESSAGE.LogMessage.decode(message); 75 | 76 | //message is a buffer, convert to a string for simplicity 77 | $message.message = $message.message.toString("utf8"); 78 | //Came across the division by 1e6 on Bluemix. 79 | $message.timestamp = $message.timestamp.toNumber() / 1e6; 80 | return $message; 81 | }).sort((l, r) => { 82 | return l.timestamp - r.timestamp; 83 | }); 84 | }); 85 | } 86 | 87 | } 88 | 89 | module.exports = Logs; 90 | -------------------------------------------------------------------------------- /lib/model/metrics/log_message.proto: -------------------------------------------------------------------------------- 1 | package logmessage; 2 | 3 | message LogMessage { 4 | enum MessageType { 5 | OUT = 1; 6 | ERR = 2; 7 | } 8 | 9 | required bytes message = 1; 10 | required MessageType message_type = 2; 11 | required sint64 timestamp = 3; 12 | required string app_id = 4; 13 | optional string source_id = 6; 14 | repeated string drain_urls = 7; 15 | optional string source_name = 8; 16 | } 17 | 18 | message LogEnvelope { 19 | required string routing_key = 1; 20 | required bytes signature = 2; 21 | required LogMessage log_message = 3; 22 | } 23 | -------------------------------------------------------------------------------- /lib/model/uaa/UsersUAA.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const HttpUtils = require("../../utils/HttpUtils"); 4 | const HttpStatus = require("../../utils/HttpStatus"); 5 | 6 | /** 7 | * Manage Users on Cloud Foundry UAA 8 | */ 9 | class UsersUAA { 10 | 11 | /** 12 | * Constructor 13 | * @param {String} endPoint [UAA endpoint] 14 | * @constructor 15 | * @returns {void} 16 | */ 17 | constructor(endPoint) { 18 | this.UAA_API_URL = endPoint; 19 | this.REST = new HttpUtils(); 20 | this.HttpStatus = HttpStatus; 21 | } 22 | 23 | /** 24 | * Set endpoint 25 | * @param {String} endPoint [UAA endpoint] 26 | * @returns {void} 27 | */ 28 | setEndPoint (endPoint) { 29 | 30 | this.UAA_API_URL = endPoint; 31 | } 32 | 33 | /** 34 | * Set token 35 | * @param {JSON} token [Oauth token from UAA] 36 | * @returns {void} 37 | */ 38 | setToken (token) { 39 | 40 | this.UAA_TOKEN = token; 41 | } 42 | 43 | /** 44 | * Add an User on UAA 45 | * {@link https://github.com/cloudfoundry/uaa/blob/master/docs/UAA-APIs.rst#create-a-user-post-users} 46 | * {@link http://www.simplecloud.info/specs/draft-scim-api-01.html#create-resource} 47 | * 48 | * @param {JSON} uaaOptions [user options] 49 | * @return {JSON} [return a JSON response] 50 | */ 51 | add (uaaOptions) { 52 | 53 | const url = `${this.UAA_API_URL}/Users`; 54 | const options = { 55 | method: "POST", 56 | url: url, 57 | headers: { 58 | Accept: "application/json", 59 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 60 | }, 61 | json: uaaOptions 62 | }; 63 | 64 | return this.REST.request(options, this.HttpStatus.CREATED, false); 65 | } 66 | 67 | /** 68 | * Update Password [PENDING] 69 | * {@link https://github.com/cloudfoundry/uaa/blob/master/docs/UAA-APIs.rst#create-a-user-post-users} 70 | * {@link http://www.simplecloud.info/specs/draft-scim-api-01.html#create-resource} 71 | * 72 | * @param {JSON} uaaGuid [uaa guid] 73 | * @param {JSON} uaaOptions [user options] 74 | * @return {JSON} [return a JSON response] 75 | */ 76 | updatePassword (uaaGuid, uaaOptions) { 77 | 78 | const url = `${this.UAA_API_URL}/Users/${uaaGuid}/password`; 79 | const options = { 80 | method: "PUT", 81 | url: url, 82 | headers: { 83 | Accept: "application/json", 84 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 85 | }, 86 | json: uaaOptions 87 | }; 88 | 89 | return this.REST.request(options, this.HttpStatus.OK, false); 90 | } 91 | 92 | /** 93 | * Remove an User 94 | * {@link http://www.simplecloud.info/specs/draft-scim-api-01.html#delete-resource} 95 | * 96 | * @param {String} uaaGuid [uaa guid] 97 | * @return {JSON} [return a JSON response] 98 | */ 99 | remove (uaaGuid) { 100 | 101 | const url = `${this.UAA_API_URL}/Users/${uaaGuid}`; 102 | const options = { 103 | method: "DELETE", 104 | url: url, 105 | headers: { 106 | Accept: "application/json", 107 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 108 | } 109 | }; 110 | 111 | return this.REST.request(options, this.HttpStatus.OK, false); 112 | } 113 | 114 | /** 115 | * Get users 116 | * {@link http://www.simplecloud.info/specs/draft-scim-api-01.html#get-resources-ops} 117 | * 118 | * @example 119 | * ?filter=userName eq 'demo4'" 120 | * 121 | * @param {JSON} searchOptions [searchOptions] 122 | * @return {JSON} [return a JSON response] 123 | */ 124 | getUsers (searchOptions) { 125 | 126 | let url = `${this.UAA_API_URL}/Users`; 127 | 128 | if (searchOptions) { 129 | url += searchOptions; 130 | } 131 | const options = { 132 | method: "GET", 133 | url: url, 134 | headers: { 135 | Accept: "application/json", 136 | Authorization: `${this.UAA_TOKEN.token_type} ${this.UAA_TOKEN.access_token}` 137 | } 138 | }; 139 | 140 | return this.REST.request(options, this.HttpStatus.OK, true); 141 | } 142 | 143 | /** 144 | * Method to authenticate with Cloud Foundry UAA 145 | * @param {String} username [username] 146 | * @param {String} password [password] 147 | * @return {JSon} [UAA Response] 148 | */ 149 | login (username, password) { 150 | 151 | const url = `${this.UAA_API_URL}/oauth/token`; 152 | let options = { 153 | method: "POST", 154 | url: url, 155 | headers: { 156 | Authorization: "Basic Y2Y6", 157 | "Content-Type": "application/x-www-form-urlencoded" 158 | } 159 | }; 160 | 161 | if (password !== undefined) { 162 | options.form = { 163 | grant_type: "password", 164 | client_id: "cf", 165 | username: username, 166 | password: password 167 | }; 168 | } 169 | else { 170 | options.form = { 171 | grant_type: "password", 172 | client_id: "cf", 173 | passcode: username 174 | }; 175 | } 176 | 177 | return this.REST.request(options, this.HttpStatus.OK, true); 178 | } 179 | 180 | /** 181 | * Method to refresh a Token 182 | * https://github.com/cloudfoundry/uaa/blob/master/docs/UAA-Tokens.md 183 | * 184 | * @param {String} refreshToken [Oauth refresh token] 185 | * @return {JSON} [Response] 186 | */ 187 | refreshToken () { 188 | 189 | const url = `${this.UAA_API_URL}/oauth/token`; 190 | const options = { 191 | method: "POST", 192 | url: url, 193 | headers: { 194 | Accept: "application/json", 195 | Authorization: "Basic Y2Y6", 196 | "Content-Type": "application/x-www-form-urlencoded" 197 | }, 198 | form: { 199 | grant_type: "refresh_token", 200 | refresh_token: this.UAA_TOKEN.refresh_token 201 | } 202 | }; 203 | 204 | return this.REST.request(options, this.HttpStatus.OK, true); 205 | } 206 | 207 | /** 208 | * Method to decode an access token 209 | * @param {String} accessToken [Access Token to be decoded] 210 | * @return {Object} [decoded access token object] 211 | */ 212 | decodeAccessToken (accessToken) { 213 | var tokenString; 214 | if(typeof accessToken !== 'string') 215 | accessToken = accessToken.access_token 216 | var bearerTypeAndToken = accessToken.split(" ") 217 | if (bearerTypeAndToken.length === 2) { 218 | tokenString = bearerTypeAndToken[1] 219 | } else if( bearerTypeAndToken.length === 1) { 220 | tokenString = bearerTypeAndToken[0] 221 | } else { 222 | throw new Error("Invalid token format") 223 | } 224 | 225 | var tokenParts = tokenString.split(".") 226 | if (tokenParts.length !== 3) { 227 | throw new Error("Invalid token format") 228 | } 229 | 230 | var encodedTokenInfo = tokenParts[1]; 231 | var tokenInfo = {}; 232 | 233 | try { 234 | var buf = new Buffer(encodedTokenInfo, "base64") 235 | tokenInfo = JSON.parse(buf.toString("utf8")) 236 | } catch(e) { 237 | console.log(e); 238 | throw new Error("Invalid token format") 239 | } 240 | 241 | return tokenInfo; 242 | } 243 | 244 | } 245 | 246 | module.exports = UsersUAA; 247 | -------------------------------------------------------------------------------- /lib/utils/HttpMethods.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | //https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/http/HttpMethod.html 4 | 5 | exports.DELETE = "DELETE"; 6 | exports.GET = "GET"; 7 | exports.HEAD = "HEAD"; 8 | exports.OPTIONS = "OPTIONS"; 9 | exports.PATCH = "PATCH"; 10 | exports.POST = "POST"; 11 | exports.PUT = "PUT"; 12 | exports.TRACE = "TRACE"; 13 | -------------------------------------------------------------------------------- /lib/utils/HttpStatus.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | //http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html 4 | //https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/http/HttpStatus.html 5 | 6 | exports.OK = 200; 7 | exports.CREATED = 201; 8 | exports.ACCEPTED = 202; 9 | exports.NO_CONTENT = 204; 10 | -------------------------------------------------------------------------------- /lib/utils/HttpUtils.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const Promise = require("bluebird"); 4 | const request = require("request"); 5 | const rest = require("restler"); 6 | 7 | /** 8 | * HttpUtils is a private class designed manage REST operations with 9 | * Cloud Foundry components (Cloud controller, UAA, Metrics). 10 | * It is used by all classes of project. 11 | */ 12 | class HttpUtils { 13 | 14 | /** 15 | * Empty constructor 16 | * @constructor 17 | * @returns {void} 18 | */ 19 | constructor() { 20 | this.requestObj = request; 21 | } 22 | 23 | /** 24 | * Method designed to set a Custom request object. 25 | * https://github.com/request/request 26 | * 27 | * @param {[type]} requestObj [description] 28 | */ 29 | setCustomRequestObject(requestObj){ 30 | this.requestObj = requestObj; 31 | } 32 | 33 | /** 34 | * Stablish a http communications using REST Verbs: GET/POST/PUT/DELETE 35 | * 36 | * @param {json} options [define options to make the request with the CF component] 37 | * @param {number} httpStatusAssert [set expected http status code (200,201,204, etc...)] 38 | * @param {boolan} jsonOutput [if the REST method retuns a String or a JSON representation] 39 | * @return {string} [JSON/String] 40 | * 41 | * @example 42 | * var url = "https://api.run.pivotal.io/v2/info"; 43 | * var options = { 44 | * method: 'GET', 45 | * url: url 46 | * }; 47 | * HttpUtils.request(options, "200", true); 48 | */ 49 | request (options, httpStatusAssert, jsonOutput) { 50 | let result = null; 51 | 52 | let request = this.requestObj; 53 | 54 | return new Promise(function (resolve, reject) { 55 | 56 | try { 57 | 58 | request(options, function (error, response, body) { 59 | if (error) { 60 | return reject(error); 61 | } 62 | 63 | if (jsonOutput) { 64 | try { 65 | result = JSON.parse(body); 66 | } catch (errorJSON) { 67 | return reject(body); 68 | } 69 | } else { 70 | const boundaryMatch = (response.headers["content-type"] || "").match("boundary=(.*)"); 71 | 72 | if (boundaryMatch) { 73 | //It's multipart data. Join it together into a single array 74 | const boundary = `--${boundaryMatch[1]}`; 75 | const respBuffers = []; 76 | 77 | let idx = body.indexOf(boundary); 78 | let lastIdx = idx; 79 | 80 | /*eslint-disable no-cond-assign*/ 81 | while ((idx = body.indexOf(boundary, lastIdx + boundary.length)) > -1) { 82 | //Trim off the \r\n, and start after the boundary accounting for \r\n\r\n 83 | respBuffers.push(body.slice(lastIdx + boundary.length + "\r\n\r\n".length, idx - "\r\n".length)); 84 | lastIdx = idx; 85 | } 86 | 87 | /*eslint-enable no-cond-assign*/ 88 | 89 | result = respBuffers; 90 | } else { 91 | result = body; 92 | } 93 | } 94 | 95 | if (!error && response.statusCode === httpStatusAssert) { 96 | return resolve(result); 97 | } 98 | 99 | //Defensive code. 100 | if (body.length === 0) { 101 | return reject("EMPTY_BODY"); 102 | } 103 | return reject(body); 104 | }); 105 | 106 | } catch (error) { 107 | return reject(error); 108 | } 109 | 110 | }); 111 | } 112 | 113 | /** 114 | * Method designed to upload zip file to Cloud Controller. 115 | * It is the unique usage of Restler dependency. 116 | * 117 | * @param {string} url [url] 118 | * @param {json} options [options] 119 | * @param {number} httpStatusAssert [set expected http status code (200,201,204, etc...)] 120 | * @param {boolan} jsonOutput [if the REST method retuns a String or a JSON representation] 121 | * @return {string} [JSON/String] 122 | */ 123 | upload(url, options, httpStatusAssert, jsonOutput) { 124 | 125 | return new Promise(function (resolve, reject) { 126 | 127 | try { 128 | 129 | rest.put(url, options).on("complete", function (result, response) { 130 | if (result instanceof Error) { 131 | reject(result); 132 | } 133 | 134 | if (response.statusCode === httpStatusAssert) { 135 | 136 | if (jsonOutput) { 137 | return resolve(JSON.parse(result)); 138 | } 139 | 140 | return resolve(result); 141 | } 142 | }); 143 | 144 | } catch (error) { 145 | return reject(error); 146 | } 147 | 148 | }); 149 | } 150 | 151 | /** 152 | * Method designed to upload a stream of a zip to Cloud Controller. 153 | * 154 | * @param {string} url [url] 155 | * @param {json} options [options] 156 | * @param {stream.ReadableStream} stream [the readable stream for the zip file] 157 | * @param {number} httpStatusAssert [set expected http status code (200,201,204, etc...)] 158 | * @param {boolan} jsonOutput [if the REST method retuns a String or a JSON representation] 159 | * @return {string} [JSON/String] 160 | */ 161 | uploadStream(url, options, stream, httpStatusAssert, jsonOutput) { 162 | 163 | let request = this.requestObj; 164 | 165 | return new Promise(function (resolve, reject) { 166 | 167 | try { 168 | const uploadOptions = { 169 | rejectUnauthorized: false, 170 | formData: { 171 | resources: "[]", 172 | application: stream 173 | } 174 | }; 175 | Object.keys(options).forEach(function (key) { 176 | uploadOptions[key] = options[key]; 177 | }); 178 | 179 | request.put(url, uploadOptions, function (error, response, body) { 180 | if (error) { 181 | return reject(error); 182 | } 183 | 184 | if (response.statusCode === httpStatusAssert) { 185 | 186 | if (jsonOutput) { 187 | try { 188 | resolve(JSON.parse(body)); 189 | } 190 | catch (errorJSON) { 191 | reject(body); 192 | } 193 | } 194 | 195 | resolve(body); 196 | } else { 197 | reject(body); 198 | } 199 | }); 200 | 201 | } catch (error) { 202 | reject(error); 203 | } 204 | 205 | }); 206 | } 207 | } 208 | 209 | module.exports = HttpUtils; 210 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cf-client3", 3 | "version": "0.13.28", 4 | "description": "A Cloud Foundry Client for Node.js", 5 | "author": "Juan Antonio Breña Moral ", 6 | "license": "Apache-2.0", 7 | "main": "index.js", 8 | "scripts": { 9 | "preversion": "npm run lint && npm test", 10 | "lint": "eslint ./lib/model/**/*.js ./lib/utils/*.js", 11 | "lint:fix": "eslint --fix ./lib/model/**/*.js ./lib/utils/*.js", 12 | "test": "npm run lint && npm run test:bluemix", 13 | "test:local": "mocha test --config=LOCAL_INSTANCE_1", 14 | "test:pws": "mocha test --config=PIVOTAL", 15 | "test:bluemix": "mocha test --config=BLUEMIX" 16 | }, 17 | "homepage": "https://github.com/IBM-Bluemix/cf-nodejs-client", 18 | "repository": { 19 | "type": "git", 20 | "url": "git+https://github.com/IBM-Bluemix/cf-nodejs-client.git" 21 | }, 22 | "bugs": { 23 | "url": "https://github.com/IBM-Bluemix/cf-nodejs-client/issues" 24 | }, 25 | "engines": { 26 | "node": ">=4.2.3", 27 | "npm": ">=2.14.7" 28 | }, 29 | "files": [ 30 | "index.js", 31 | "lib" 32 | ], 33 | "dependencies": { 34 | "bluebird": "^3.5.5", 35 | "protobufjs": "^5.0.1", 36 | "request": "^2.88.0", 37 | "restler": "^3.4.0", 38 | "ws": "^7.0.1" 39 | }, 40 | "devDependencies": { 41 | "archiver": "^3.0.0", 42 | "chai": "3.4.1", 43 | "chai-as-promised": "5.1.0", 44 | "eslint": "^2.11.1", 45 | "eslint-config-strongloop": "^2.0.1", 46 | "istanbul": "0.4.5", 47 | "mocha": "^6.1.4", 48 | "nconf": "0.8.2", 49 | "optimist": "0.6.1", 50 | "random-words": "0.0.1" 51 | }, 52 | "keywords": [ 53 | "cloud foundry", 54 | "cloudfoundry", 55 | "cloud-foundry", 56 | "vcap", 57 | "pivotal", 58 | "pivotalcf", 59 | "ibm", 60 | "bluemix", 61 | "cloud", 62 | "api", 63 | "REST", 64 | "cf", 65 | "cf client", 66 | "paas" 67 | ] 68 | } 69 | -------------------------------------------------------------------------------- /scripts/setup-dndmasq.sh: -------------------------------------------------------------------------------- 1 | apt-get update 2 | apt-get install dnsmasq httping 3 | echo "address=/bosh-lite.com/${CF_IP}" | tee -a /etc/dnsmasq.conf > /dev/null 4 | dpkg-reconfigure resolvconf 5 | /etc/init.d/dnsmasq restart 6 | -------------------------------------------------------------------------------- /scripts/setup-dnsmasq.sh: -------------------------------------------------------------------------------- 1 | apt-get update 2 | apt-get install dnsmasq httping 3 | echo "address=/bosh-lite.com/${CF_IP}" | tee -a /etc/dnsmasq.conf > /dev/null 4 | dpkg-reconfigure resolvconf 5 | /etc/init.d/dnsmasq restart 6 | -------------------------------------------------------------------------------- /test/lib/model/cloudcontroller/BuildPacksTests.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true*/ 2 | /*global describe: true, it: true*/ 3 | "use strict"; 4 | 5 | var Promise = require('bluebird'); 6 | var chai = require("chai"), 7 | expect = require("chai").expect; 8 | 9 | var Buildpacks = require("../../../../lib/model/cloudcontroller/BuildPacks"); 10 | Buildpacks = new Buildpacks(); 11 | 12 | describe("Cloud Foundry Buildpacks", function () { 13 | 14 | it("Exist a support for a Node.js project", function () { 15 | expect(Buildpacks.get("nodejs")).to.equal("https://github.com/cloudfoundry/nodejs-buildpack"); 16 | }); 17 | 18 | it("Exist a support for a Static project", function () { 19 | expect(Buildpacks.get("static")).to.equal("https://github.com/cloudfoundry/staticfile-buildpack"); 20 | }); 21 | 22 | it("Exist a support for a Java project", function () { 23 | expect(Buildpacks.get("java")).to.equal("https://github.com/cloudfoundry/java-buildpack"); 24 | }); 25 | 26 | it("Exist a support for a PHP project", function () { 27 | expect(Buildpacks.get("php")).to.equal("https://github.com/cloudfoundry/php-buildpack"); 28 | }); 29 | 30 | it("Exist a support for a Python project", function () { 31 | expect(Buildpacks.get("python")).to.equal("https://github.com/cloudfoundry/python-buildpack"); 32 | }); 33 | 34 | 35 | 36 | it("Unknown Buildpacks handling", function () { 37 | expect(function () { 38 | Buildpacks.get("Unknown"); 39 | }).to.throw('This Buildpack is not supported'); 40 | }); 41 | 42 | }); -------------------------------------------------------------------------------- /test/lib/model/cloudcontroller/CloudControllerTests.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true*/ 2 | /*global describe: true, before: true, it: true*/ 3 | "use strict"; 4 | 5 | var Promise = require('bluebird'); 6 | var chai = require("chai"), 7 | chaiAsPromised = require("chai-as-promised"), 8 | expect = require("chai").expect; 9 | chai.use(chaiAsPromised); 10 | 11 | var argv = require('optimist').demand('config').argv; 12 | var environment = argv.config; 13 | var nconf = require('nconf'); 14 | nconf.argv().env().file({ file: 'config.json' }); 15 | 16 | var cf_api_url = nconf.get(environment + "_" + 'CF_API_URL'), 17 | username = nconf.get(environment + "_" + 'username'), 18 | password = nconf.get(environment + "_" + 'password'); 19 | 20 | var CloudController = require("../../../../lib/model/cloudcontroller/CloudController"); 21 | var CloudFoundryUsersUAA = require("../../../../lib/model/uaa/UsersUAA"); 22 | CloudController = new CloudController(); 23 | CloudFoundryUsersUAA = new CloudFoundryUsersUAA(); 24 | 25 | const request = require("request"); 26 | 27 | describe("Cloud Controller", function () { 28 | 29 | var authorization_endpoint = null; 30 | var token_endpoint = null; 31 | 32 | before(function () { 33 | this.timeout(15000); 34 | 35 | CloudController.setEndPoint(cf_api_url); 36 | 37 | return CloudController.getInfo().then(function (result) { 38 | authorization_endpoint = result.authorization_endpoint; 39 | token_endpoint = result.token_endpoint; 40 | CloudFoundryUsersUAA.setEndPoint(authorization_endpoint); 41 | return CloudFoundryUsersUAA.login(username, password); 42 | }).then(function (result) { 43 | CloudFoundryUsersUAA.setToken(result); 44 | CloudController.setToken(result); 45 | }); 46 | }); 47 | 48 | it("The connection show API Version", function () { 49 | return CloudController.getInfo().then(function (result) { 50 | console.log(result.api_version); 51 | return expect(result.api_version).to.be.a('string'); 52 | }); 53 | }); 54 | 55 | it.skip("The connection with the PaaS is OK", function () { 56 | return expect(CloudController.getInfo()).eventually.property("version", 2); 57 | }); 58 | 59 | it("Get all featured flags", function () { 60 | return CloudController.getFeaturedFlags().then(function (result) { 61 | return expect(true).to.be.a('boolean'); 62 | }); 63 | }); 64 | 65 | if(environment === "PIVOTAL") { 66 | 67 | it("Get info about the featured flag: 'diego_docker'", function () { 68 | var dockerFlag = "diego_docker"; 69 | return CloudController.getFeaturedFlag(dockerFlag).then(function (result) { 70 | console.log(result); 71 | return expect(true).to.be.a('boolean'); 72 | }); 73 | }); 74 | 75 | it("[DEBUGGING] Enable Docker on Diego", function () { 76 | var dockerFlag = "diego_docker"; 77 | return CloudController.setFeaturedFlag(dockerFlag).then(function (result) { 78 | return expect(true).to.be.a('boolean'); 79 | }).catch(function (reason) { 80 | console.log(reason); 81 | return expect(true).to.be.a('boolean'); 82 | }); 83 | }); 84 | 85 | } 86 | 87 | it("Set Custom request object", function () { 88 | 89 | //process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; 90 | const requestWithDefaults = request.defaults({ 91 | rejectUnauthorized: false 92 | }); 93 | 94 | CloudController.setCustomRequestObject(requestWithDefaults); 95 | return CloudController.getFeaturedFlags().then(function (result) { 96 | return expect(true).to.be.a('boolean'); 97 | }); 98 | }); 99 | 100 | it.skip("Set Bad Custom request object", function () { 101 | 102 | const badRequestConfiguration = request.defaults({ 103 | proxy: 'http://localproxy.com' 104 | }); 105 | 106 | CloudController.setCustomRequestObject(badRequestConfiguration); 107 | return CloudController.getFeaturedFlags().then(function (result) { 108 | return expect(true).to.be.a('boolean'); 109 | }); 110 | }); 111 | 112 | }); -------------------------------------------------------------------------------- /test/lib/model/cloudcontroller/DockerTests.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true*/ 2 | /*global Promise:true*/ 3 | /*global describe: true, before:true, it: true*/ 4 | "use strict"; 5 | 6 | var Promise = require('bluebird'); 7 | var chai = require("chai"), 8 | expect = require("chai").expect; 9 | var randomWords = require('random-words'); 10 | 11 | var argv = require('optimist').demand('config').argv; 12 | var environment = argv.config; 13 | var nconf = require('nconf'); 14 | nconf.argv().env().file({ file: 'config.json' }); 15 | 16 | var cf_api_url = nconf.get(environment + "_" + 'CF_API_URL'), 17 | username = nconf.get(environment + "_" + 'username'), 18 | password = nconf.get(environment + "_" + 'password'); 19 | 20 | var CloudController = require("../../../../lib/model/cloudcontroller/CloudController"); 21 | var CloudFoundryUsersUAA = require("../../../../lib/model/uaa/UsersUAA"); 22 | var CloudFoundryApps = require("../../../../lib/model/cloudcontroller/Apps"); 23 | var CloudFoundrySpaces = require("../../../../lib/model/cloudcontroller/Spaces"); 24 | var CloudFoundryDomains = require("../../../../lib/model/cloudcontroller/Domains"); 25 | var CloudFoundryRoutes = require("../../../../lib/model/cloudcontroller/Routes"); 26 | var CloudFoundryJobs = require("../../../../lib/model/cloudcontroller/Jobs"); 27 | var CloudFoundryLogs = require("../../../../lib/model/metrics/Logs"); 28 | var BuildPacks = require("../../../../lib/model/cloudcontroller/BuildPacks"); 29 | CloudController = new CloudController(); 30 | CloudFoundryUsersUAA = new CloudFoundryUsersUAA(); 31 | CloudFoundryApps = new CloudFoundryApps(); 32 | CloudFoundrySpaces = new CloudFoundrySpaces(); 33 | CloudFoundryDomains = new CloudFoundryDomains(); 34 | CloudFoundryRoutes = new CloudFoundryRoutes(); 35 | CloudFoundryJobs = new CloudFoundryJobs(); 36 | CloudFoundryLogs = new CloudFoundryLogs(); 37 | BuildPacks = new BuildPacks(); 38 | var HttpUtils = require('../../../../lib/utils/HttpUtils'); 39 | HttpUtils = new HttpUtils(); 40 | 41 | var fs = require('fs'); 42 | var ZipGenerator = require('../../../utils/ZipGenerator'); 43 | ZipGenerator = new ZipGenerator(); 44 | 45 | describe("Docker tests", function () { 46 | 47 | var authorization_endpoint = null; 48 | var token_endpoint = null; 49 | var logging_endpoint = null; 50 | var token_type = null; 51 | var access_token = null; 52 | var domain_guid = null; 53 | var space_guid = null; 54 | 55 | before(function () { 56 | this.timeout(20000); 57 | 58 | CloudController.setEndPoint(cf_api_url); 59 | CloudFoundryApps.setEndPoint(cf_api_url); 60 | CloudFoundrySpaces.setEndPoint(cf_api_url); 61 | CloudFoundryDomains.setEndPoint(cf_api_url); 62 | CloudFoundryRoutes.setEndPoint(cf_api_url); 63 | CloudFoundryJobs.setEndPoint(cf_api_url); 64 | 65 | return CloudController.getInfo().then(function (result) { 66 | authorization_endpoint = result.authorization_endpoint; 67 | token_endpoint = result.token_endpoint; 68 | logging_endpoint = result.logging_endpoint; 69 | CloudFoundryUsersUAA.setEndPoint(authorization_endpoint); 70 | return CloudFoundryUsersUAA.login(username, password); 71 | }).then(function (result) { 72 | CloudController.setToken(result); 73 | CloudFoundryApps.setToken(result); 74 | CloudFoundrySpaces.setToken(result); 75 | CloudFoundryDomains.setToken(result); 76 | CloudFoundryRoutes.setToken(result); 77 | CloudFoundryJobs.setToken(result); 78 | CloudFoundryLogs.setToken(result); 79 | return CloudFoundryDomains.getDomains(); 80 | }).then(function (result) { 81 | domain_guid = result.resources[0].metadata.guid; 82 | return CloudFoundrySpaces.getSpaces(); 83 | }).then(function (result) { 84 | space_guid = result.resources[0].metadata.guid; 85 | }); 86 | 87 | }); 88 | 89 | function randomInt(low, high) { 90 | return Math.floor(Math.random() * (high - low) + low); 91 | } 92 | 93 | 94 | function createApp(appOptions) { 95 | 96 | var app_guid = null; 97 | var routeName = null; 98 | var route_guid = null; 99 | var route_create_flag = false; 100 | var appName = appOptions.name; 101 | 102 | return new Promise(function (resolve, reject) { 103 | 104 | var filter = { 105 | 'q': 'name:' + appName, 106 | 'inline-relations-depth': 1 107 | }; 108 | 109 | //VALIDATIONS 110 | //1. Duplicated app 111 | return CloudFoundrySpaces.getSpaceApps(space_guid, filter).then(function (result) { 112 | 113 | //If exist the application, REJECT 114 | if (result.total_results === 1) { 115 | return reject("Exist the app: " + appName); 116 | } 117 | 118 | var filter = { 119 | 'q': 'host:' + appName + ';domain_guid:' + domain_guid, 120 | 'inline-relations-depth': 1 121 | }; 122 | return CloudFoundryRoutes.getRoutes(filter); 123 | //2. Duplicated route 124 | }).then(function (result) { 125 | 126 | if (result.total_results === 1) { 127 | return reject("Exist the route:" + appName); 128 | } 129 | 130 | return CloudFoundryApps.add(appOptions).then(function (result) { 131 | return new Promise(function (resolve) { 132 | //console.log(result); 133 | app_guid = result.metadata.guid; 134 | return resolve(); 135 | }); 136 | }); 137 | }).then(function () { 138 | //TODO: How to make the inference? 139 | return CloudFoundryDomains.getSharedDomains(); 140 | }).then(function () { 141 | var routeOptions = { 142 | 'domain_guid' : domain_guid, 143 | 'space_guid' : space_guid, 144 | 'host' : appName 145 | }; 146 | return CloudFoundryRoutes.add(routeOptions).then(function (result) { 147 | return new Promise(function (resolve) { 148 | route_guid = result.metadata.guid; 149 | return resolve(result); 150 | }); 151 | }); 152 | }).then(function () { 153 | return CloudFoundryApps.associateRoute(app_guid, route_guid); 154 | }).then(function (result) { 155 | return resolve(result); 156 | }).catch(function (reason) { 157 | console.error("Error: " + reason); 158 | return reject(reason); 159 | }); 160 | 161 | }); 162 | 163 | } 164 | 165 | if(environment === "PIVOTAL") { 166 | 167 | it("[DEBUGGING] Create an App with a Docker Image & Remove app", function () { 168 | this.timeout(40000); 169 | 170 | var app_guid = null; 171 | var appName = "app2" + randomWords() + randomInt(1, 100); 172 | var route_guid = null; 173 | var dockerImage = "cloudfoundry/helloworld"; 174 | var appOptions = { 175 | "name": appName, 176 | "space_guid": space_guid, 177 | "instances" : 1, 178 | "memory" : 512, 179 | "disk_quota" : 512, 180 | "diego": true, 181 | "docker_image" : dockerImage 182 | }; 183 | var dockerFlag = "diego_docker"; 184 | 185 | return CloudController.setFeaturedFlag(dockerFlag).then(function (result) { 186 | return createApp(appOptions); 187 | }).then(function (result) { 188 | console.log(result); 189 | app_guid = result.metadata.guid; 190 | expect(app_guid).is.a("string"); 191 | return CloudFoundryApps.getAppRoutes(app_guid); 192 | }).then(function (result) { 193 | route_guid = result.resources[0].metadata.guid; 194 | return CloudFoundryApps.remove(app_guid); 195 | }).then(function () { 196 | return CloudFoundryRoutes.remove(route_guid); 197 | }).then(function () { 198 | expect(true).to.equal(true); 199 | }).catch(function (reason) { 200 | console.log(reason); 201 | return expect(true).to.be.a('boolean'); 202 | }); 203 | }); 204 | 205 | } 206 | 207 | }); 208 | 209 | 210 | -------------------------------------------------------------------------------- /test/lib/model/cloudcontroller/DomainsTests.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true*/ 2 | /*global describe: true, before: true, it: true*/ 3 | /*globals Promise:true*/ 4 | "use strict"; 5 | 6 | var Promise = require('bluebird'); 7 | var chai = require("chai"), 8 | expect = require("chai").expect; 9 | 10 | var argv = require('optimist').demand('config').argv; 11 | var environment = argv.config; 12 | var nconf = require('nconf'); 13 | nconf.argv().env().file({ file: 'config.json' }); 14 | 15 | var cf_api_url = nconf.get(environment + "_" + 'CF_API_URL'), 16 | username = nconf.get(environment + "_" + 'username'), 17 | password = nconf.get(environment + "_" + 'password'); 18 | 19 | var CloudController = require("../../../../lib/model/cloudcontroller/CloudController"); 20 | var CloudFoundryUsersUAA = require("../../../../lib/model/uaa/UsersUAA"); 21 | var CloudFoundryDomains = require("../../../../lib/model/cloudcontroller/Domains"); 22 | CloudController = new CloudController(); 23 | CloudFoundryUsersUAA = new CloudFoundryUsersUAA(); 24 | CloudFoundryDomains = new CloudFoundryDomains(); 25 | 26 | describe("Cloud foundry Domains", function () { 27 | 28 | var authorization_endpoint = null; 29 | var token_endpoint = null; 30 | var token_type = null; 31 | var access_token = null; 32 | 33 | before(function () { 34 | this.timeout(15000); 35 | 36 | CloudController.setEndPoint(cf_api_url); 37 | CloudFoundryDomains.setEndPoint(cf_api_url); 38 | 39 | return CloudController.getInfo().then(function (result) { 40 | authorization_endpoint = result.authorization_endpoint; 41 | token_endpoint = result.token_endpoint; 42 | CloudFoundryUsersUAA.setEndPoint(authorization_endpoint); 43 | return CloudFoundryUsersUAA.login(username, password); 44 | }).then(function (result) { 45 | CloudFoundryDomains.setToken(result); 46 | }); 47 | }); 48 | 49 | it("The platform returns Domains defined", function () { 50 | this.timeout(3000); 51 | 52 | var domain = null; 53 | return CloudFoundryDomains.getDomains().then(function (result) { 54 | domain = result.resources[0].entity.name; 55 | expect(domain).is.a("string"); 56 | expect(result.resources.length).to.be.above(0); 57 | expect(result.total_results).is.a("number"); 58 | }); 59 | }); 60 | 61 | it("The platform returns Shared domains defined", function () { 62 | this.timeout(5000); 63 | 64 | var domain = null; 65 | return CloudFoundryDomains.getSharedDomains().then(function (result) { 66 | domain = result.resources[0].entity.name; 67 | expect(domain).is.a("string"); 68 | expect(result.resources.length).to.be.above(0); 69 | expect(result.total_results).is.a("number"); 70 | }); 71 | }); 72 | 73 | }); -------------------------------------------------------------------------------- /test/lib/model/cloudcontroller/EventsTests.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true*/ 2 | /*global describe: true, before: true, it: true*/ 3 | 4 | var chai = require("chai"), 5 | expect = require("chai").expect; 6 | 7 | var argv = require('optimist').demand('config').argv; 8 | var environment = argv.config; 9 | var nconf = require('nconf'); 10 | nconf.argv().env().file({file: 'config.json'}); 11 | 12 | var cf_api_url = nconf.get(environment + "_" + 'CF_API_URL'), 13 | username = nconf.get(environment + "_" + 'username'), 14 | password = nconf.get(environment + "_" + 'password'); 15 | 16 | var CloudController = require("../../../../lib/model/cloudcontroller/CloudController"); 17 | var CloudFoundryUsersUAA = require("../../../../lib/model/uaa/UsersUAA"); 18 | var CloudFoundryEvents = require("../../../../lib/model/cloudcontroller/Events"); 19 | CloudController = new CloudController(); 20 | CloudFoundryUsersUAA = new CloudFoundryUsersUAA(); 21 | CloudFoundryEvents = new CloudFoundryEvents(); 22 | 23 | describe("Cloud foundry Events", function () { 24 | "use strict"; 25 | var authorization_endpoint = null; 26 | var token_endpoint = null; 27 | var token_type = null; 28 | var access_token = null; 29 | 30 | before(function () { 31 | this.timeout(15000); 32 | 33 | CloudController.setEndPoint(cf_api_url); 34 | CloudFoundryEvents.setEndPoint(cf_api_url); 35 | 36 | return CloudController.getInfo().then(function (result) { 37 | authorization_endpoint = result.authorization_endpoint; 38 | token_endpoint = result.token_endpoint; 39 | CloudFoundryUsersUAA.setEndPoint(authorization_endpoint); 40 | return CloudFoundryUsersUAA.login(username, password); 41 | }).then(function (result) { 42 | CloudFoundryEvents.setToken(result); 43 | }); 44 | }); 45 | 46 | //TODO: This component has some performance problems in Pivotal systems. 47 | it.skip("The platform returns the Events", function () { 48 | this.timeout(150000); 49 | 50 | return CloudFoundryEvents.getEvents().then(function (result) { 51 | expect(result.total_results).is.a("number"); 52 | }); 53 | }); 54 | 55 | it("The platform returns the Events With Optional Query String Parameters", function () { 56 | this.timeout(150000); 57 | 58 | var resultsPerPage = 20; 59 | var filter = { 60 | q: ['timestamp>=' + "2015-12-10T00:00:00Z"], 61 | 'results-per-page': resultsPerPage 62 | }; 63 | 64 | return CloudFoundryEvents.getEvents(filter).then(function (result) { 65 | expect(result.total_results).is.a("number"); 66 | //Sometimes, system returns less than 20. 67 | //expect(result.resources.length).to.equal(20); 68 | expect(result.resources.length).to.be.below(resultsPerPage + 1); 69 | }); 70 | }); 71 | 72 | it("Events in 2016", function () { 73 | this.timeout(150000); 74 | 75 | var resultsPerPage = 20; 76 | var filter = { 77 | q: ['timestamp>=' + "2016-01-01T00:00:00Z"], 78 | 'results-per-page': resultsPerPage 79 | }; 80 | 81 | return CloudFoundryEvents.getEvents(filter).then(function (result) { 82 | expect(result.total_results).is.a("number"); 83 | //Sometimes, system returns less than 20. 84 | //expect(result.resources.length).to.equal(20); 85 | expect(result.resources.length).to.be.below(resultsPerPage + 1); 86 | }); 87 | }); 88 | 89 | it("Apps crashed in 2016", function () { 90 | this.timeout(150000); 91 | 92 | var resultsPerPage = 20; 93 | var filter = { 94 | q: ['timestamp>=' + "2016-01-01T00:00:00Z", 'type:' + "app.crash"], 95 | 'results-per-page': resultsPerPage 96 | }; 97 | return CloudFoundryEvents.getEvents(filter).then(function (result) { 98 | expect(result.total_results).is.a("number"); 99 | //Sometimes, system returns less than 20. 100 | //expect(result.resources.length).to.equal(20); 101 | expect(result.resources.length).to.be.below(resultsPerPage + 1); 102 | }); 103 | }); 104 | 105 | it.skip("[TOOL] Events from an App in 2016", function () { 106 | this.timeout(150000); 107 | 108 | var resultsPerPage = 20; 109 | var filter = { 110 | q: ['timestamp>=' + "2016-01-01T00:00:00Z", 'actee:' + "b3daddcd-eb94-43fe-9975-e424364c6afb"], 111 | 'results-per-page': resultsPerPage 112 | }; 113 | 114 | return CloudFoundryEvents.getEvents(filter).then(function (result) { 115 | //console.log(result.resources); 116 | expect(result.total_results).is.a("number"); 117 | //Sometimes, system returns less than 20. 118 | //expect(result.resources.length).to.equal(20); 119 | expect(result.resources.length).to.be.below(resultsPerPage + 1); 120 | }); 121 | }); 122 | }); 123 | -------------------------------------------------------------------------------- /test/lib/model/cloudcontroller/OrganizationsQuotaTests.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true*/ 2 | /*global describe: true, before: true, it: true*/ 3 | "use strict"; 4 | 5 | var Promise = require('bluebird'); 6 | var chai = require("chai"), 7 | expect = require("chai").expect; 8 | var randomWords = require('random-words'); 9 | 10 | var argv = require('optimist').demand('config').argv; 11 | var environment = argv.config; 12 | var nconf = require('nconf'); 13 | nconf.argv().env().file({ file: 'config.json' }); 14 | 15 | var cf_api_url = nconf.get(environment + "_" + 'CF_API_URL'), 16 | username = nconf.get(environment + "_" + 'username'), 17 | password = nconf.get(environment + "_" + 'password'); 18 | 19 | var CloudController = require("../../../../lib/model/cloudcontroller/CloudController"); 20 | var CloudFoundryUsersUAA = require("../../../../lib/model/uaa/UsersUAA"); 21 | var CloudFoundryOrg = require("../../../../lib/model/cloudcontroller/Organizations"); 22 | var CloudFoundryOrgQuota = require("../../../../lib/model/cloudcontroller/OrganizationsQuota"); 23 | CloudController = new CloudController(); 24 | CloudFoundryUsersUAA = new CloudFoundryUsersUAA(); 25 | CloudFoundryOrg = new CloudFoundryOrg(); 26 | CloudFoundryOrgQuota = new CloudFoundryOrgQuota(); 27 | 28 | describe("Cloud foundry Organizations Quota", function () { 29 | 30 | var authorization_endpoint = null; 31 | var token_endpoint = null; 32 | var token_type = null; 33 | var access_token = null; 34 | 35 | before(function () { 36 | this.timeout(15000); 37 | 38 | CloudController.setEndPoint(cf_api_url); 39 | CloudFoundryOrg.setEndPoint(cf_api_url); 40 | CloudFoundryOrgQuota.setEndPoint(cf_api_url); 41 | 42 | return CloudController.getInfo().then(function (result) { 43 | authorization_endpoint = result.authorization_endpoint; 44 | token_endpoint = result.token_endpoint; 45 | CloudFoundryUsersUAA.setEndPoint(authorization_endpoint); 46 | return CloudFoundryUsersUAA.login(username, password); 47 | }).then(function (result) { 48 | CloudFoundryOrg.setToken(result); 49 | CloudFoundryOrgQuota.setToken(result); 50 | }); 51 | }); 52 | 53 | function randomInt(low, high) { 54 | return Math.floor(Math.random() * (high - low) + low); 55 | } 56 | 57 | it("The platform returns Quota Definitions from Organizations", function () { 58 | this.timeout(5000); 59 | 60 | var org_guid = null; 61 | 62 | return CloudFoundryOrgQuota.getQuotaDefinitions().then(function (result) { 63 | //console.log(result.resources); 64 | expect(true).is.a("boolean"); 65 | }); 66 | }); 67 | 68 | it.skip("The platform returns Quota Definitions from the first Organization", function () { 69 | this.timeout(3000); 70 | 71 | var org_guid = null; 72 | 73 | return CloudFoundryOrg.getOrganizations().then(function (result) { 74 | console.log(result); 75 | org_guid = result.resources[0].metadata.guid; 76 | return CloudFoundryOrg.getQuotaDefinition(org_guid); 77 | }).then(function (result) { 78 | console.log(result.resources); 79 | expect(true).is.a("boolean"); 80 | }); 81 | }); 82 | 83 | it.skip("Create a Quota Definitions", function () { 84 | this.timeout(3000); 85 | 86 | var quotaOptions = { 87 | 'name': "demo", 88 | 'non_basic_services_allowed': true, 89 | 'total_services': 100, 90 | 'total_routes': 1000, 91 | 'total_private_domains': 1, 92 | 'memory_limit': 2048, 93 | 'instance_memory_limit': 1024 94 | }; 95 | 96 | return CloudFoundryOrgQuota.add(quotaOptions).then(function (result) { 97 | console.log(result); 98 | expect(true).is.a("boolean"); 99 | }); 100 | }); 101 | 102 | it.skip("Remove a Quota Definitions", function () { 103 | this.timeout(3000); 104 | 105 | var quota_guid = "d87d903f-e7ee-4ae8-8840-413c6afc3616"; 106 | var async = { 107 | 'async': false 108 | }; 109 | 110 | return CloudFoundryOrgQuota.remove(quota_guid, async).then(function (result) { 111 | console.log(result); 112 | expect(true).is.a("boolean"); 113 | }); 114 | }); 115 | 116 | //Testing users doesn't have permissions 117 | if(environment === "LOCAL_INSTANCE_1") { 118 | 119 | it("Add & Remove a Quota Definitions", function () { 120 | this.timeout(3000); 121 | 122 | var quota_guid = null; 123 | var quota_name = "quota" + randomWords() + randomInt(1, 10000); 124 | var quotaOptions = { 125 | 'name': quota_name, 126 | 'non_basic_services_allowed': true, 127 | 'total_services': 100, 128 | 'total_routes': 1000, 129 | 'total_private_domains': 1, 130 | 'memory_limit': 2048, 131 | 'instance_memory_limit': 1024 132 | }; 133 | var async = { 134 | 'async': false 135 | }; 136 | return CloudFoundryOrgQuota.add(quotaOptions).then(function (result) { 137 | quota_guid = result.metadata.guid; 138 | return CloudFoundryOrgQuota.remove(quota_guid, async); 139 | }).then(function (result) { 140 | expect(true).is.a("boolean"); 141 | }); 142 | }); 143 | 144 | } 145 | 146 | }); -------------------------------------------------------------------------------- /test/lib/model/cloudcontroller/ServiceInstancesTests.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true*/ 2 | /*global describe: true, before:true, it: true*/ 3 | 4 | var Promise = require('bluebird'); 5 | var chai = require("chai"), 6 | expect = require("chai").expect; 7 | var randomWords = require('random-words'); 8 | 9 | var argv = require('optimist').demand('config').argv; 10 | var environment = argv.config; 11 | var nconf = require('nconf'); 12 | nconf.argv().env().file({ file: 'config.json' }); 13 | 14 | var cf_api_url = nconf.get(environment + "_" + 'CF_API_URL'), 15 | username = nconf.get(environment + "_" + 'username'), 16 | password = nconf.get(environment + "_" + 'password'); 17 | 18 | var CloudController = require("../../../../lib/model/cloudcontroller/CloudController"); 19 | var CloudFoundryUsersUAA = require("../../../../lib/model/uaa/UsersUAA"); 20 | var CloudFoundryApps = require("../../../../lib/model/cloudcontroller/Apps"); 21 | var CloudFoundrySpaces = require("../../../../lib/model/cloudcontroller/Spaces"); 22 | var CloudFoundryUserProvidedServices = require("../../../../lib/model/cloudcontroller/UserProvidedServices"); 23 | var CloudFoundryServiceInstances = require("../../../../lib/model/cloudcontroller/ServiceInstances"); 24 | var CloudFoundryServicePlans = require("../../../../lib/model/cloudcontroller/ServicePlans"); 25 | var BuildPacks = require("../../../../lib/model/cloudcontroller/BuildPacks"); 26 | CloudController = new CloudController(); 27 | CloudFoundryUsersUAA = new CloudFoundryUsersUAA(); 28 | CloudFoundryApps = new CloudFoundryApps(); 29 | CloudFoundrySpaces = new CloudFoundrySpaces(); 30 | CloudFoundryServiceInstances = new CloudFoundryServiceInstances(); 31 | CloudFoundryServicePlans = new CloudFoundryServicePlans(); 32 | CloudFoundryUserProvidedServices = new CloudFoundryUserProvidedServices(); 33 | BuildPacks = new BuildPacks(); 34 | 35 | describe("Cloud foundry Service Instances", function () { 36 | "use strict"; 37 | var authorization_endpoint = null; 38 | var token_endpoint = null; 39 | var token_type = null; 40 | var access_token = null; 41 | var space_guid = null; 42 | 43 | before(function () { 44 | this.timeout(25000); 45 | 46 | CloudController.setEndPoint(cf_api_url); 47 | CloudFoundryApps.setEndPoint(cf_api_url); 48 | CloudFoundrySpaces.setEndPoint(cf_api_url); 49 | CloudFoundryServiceInstances.setEndPoint(cf_api_url); 50 | CloudFoundryServicePlans.setEndPoint(cf_api_url); 51 | CloudFoundryUserProvidedServices.setEndPoint(cf_api_url); 52 | 53 | return CloudController.getInfo().then(function (result) { 54 | authorization_endpoint = result.authorization_endpoint; 55 | token_endpoint = result.token_endpoint; 56 | CloudFoundryUsersUAA.setEndPoint(authorization_endpoint); 57 | return CloudFoundryUsersUAA.login(username, password); 58 | }).then(function (result) { 59 | token_type = result.token_type; 60 | access_token = result.access_token; 61 | CloudFoundrySpaces.setToken(result); 62 | CloudFoundryServiceInstances.setToken(result); 63 | return CloudFoundrySpaces.getSpaces(); 64 | }).then(function (result) { 65 | space_guid = result.resources[0].metadata.guid; 66 | }); 67 | 68 | }); 69 | 70 | function randomInt(low, high) { 71 | return Math.floor(Math.random() * (high - low) + low); 72 | } 73 | 74 | it("The platform returns a list of Service Instances available", function () { 75 | this.timeout(5000); 76 | 77 | return CloudFoundryServiceInstances.getInstances().then(function (result) { 78 | expect(result.total_results).is.a("number"); 79 | }); 80 | }); 81 | 82 | it("The platform returns the first Service", function () { 83 | this.timeout(50000); 84 | 85 | var messageNoService = "No service"; 86 | var service_instance_guid = null; 87 | return CloudFoundryServiceInstances.getInstances().then(function (result) { 88 | if(result.total_results === 0){ 89 | return Promise.reject(messageNoService); 90 | } 91 | service_instance_guid = result.resources[0].metadata.guid; 92 | return CloudFoundryServiceInstances.getInstance(service_instance_guid); 93 | }).then(function (result) { 94 | expect(result.metadata.guid).is.a("string"); 95 | }).catch(function (reason) { 96 | expect(reason).to.equal(messageNoService); 97 | }); 98 | }); 99 | 100 | it("The platform returns a list of Service Instance in a Space available", function () { 101 | this.timeout(50000); 102 | 103 | var filter = { 104 | q: 'space_guid:' + space_guid 105 | }; 106 | return CloudFoundryServiceInstances.getInstances(filter).then(function (result) { 107 | expect(result.total_results).is.a("number"); 108 | }); 109 | }); 110 | 111 | it("The platform returns Service Instance permissions", function () { 112 | this.timeout(50000); 113 | 114 | var service_instance_guid = null; 115 | return CloudFoundryServiceInstances.getInstances().then(function (result) { 116 | if(result.total_results === 0){ 117 | return Promise.reject("No results") 118 | } 119 | service_instance_guid = result.resources[0].metadata.guid; 120 | return CloudFoundryServiceInstances.getInstancePermissions(service_instance_guid); 121 | }).then(function (result) { 122 | expect(result.manage).is.a("boolean"); 123 | }).catch(function (reason) { 124 | expect(reason).to.equal("No results"); 125 | }); 126 | }); 127 | 128 | it("The platform returns Service Instance Bindings", function () { 129 | this.timeout(50000); 130 | 131 | var service_instance_guid = null; 132 | return CloudFoundryServiceInstances.getInstances().then(function (result) { 133 | if(result.total_results === 0){ 134 | return Promise.reject("No results") 135 | } 136 | service_instance_guid = result.resources[0].metadata.guid; 137 | return CloudFoundryServiceInstances.getInstanceBindings(service_instance_guid); 138 | }).then(function (result) { 139 | expect(result.total_results).is.a("number"); 140 | }).catch(function (reason) { 141 | expect(reason).to.equal("No results"); 142 | }); 143 | }); 144 | 145 | it("The platform returns Service Instance Routes", function () { 146 | this.timeout(50000); 147 | 148 | var service_instance_guid = null; 149 | return CloudFoundryServiceInstances.getInstances().then(function (result) { 150 | if(result.total_results === 0){ 151 | return Promise.reject("No results") 152 | } 153 | service_instance_guid = result.resources[0].metadata.guid; 154 | return CloudFoundryServiceInstances.getInstanceRoutes(service_instance_guid); 155 | }).then(function (result) { 156 | expect(result.total_results).is.a("number"); 157 | }).catch(function (reason) { 158 | expect(reason).to.equal("No results"); 159 | }); 160 | }); 161 | 162 | it.skip("The platform creates a new Service Instance and then removes it.", function () { 163 | this.timeout(50000); 164 | 165 | return CloudFoundryServicePlans.getServicePlans().then(function (result) { 166 | var options = { 167 | name: 'sample-test-service-instance', 168 | service_plan_guid: result.resources[0].metadata.guid, 169 | space_guid: space_guid 170 | } 171 | return CloudFoundryServiceInstances.create(options); 172 | }).then(function (result) { 173 | expect(true).to.equal(true); 174 | return CloudFoundryServiceInstances.remove(result.metadata.guid); 175 | }).then(function (result) { 176 | expect(true).to.equal(true); 177 | }); 178 | }); 179 | }); 180 | -------------------------------------------------------------------------------- /test/lib/model/cloudcontroller/ServicePlansTests.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true*/ 2 | /*global describe: true, before:true, it: true*/ 3 | "use strict"; 4 | 5 | var Promise = require('bluebird'); 6 | var chai = require("chai"), 7 | expect = require("chai").expect; 8 | var randomWords = require('random-words'); 9 | 10 | var argv = require('optimist').demand('config').argv; 11 | var environment = argv.config; 12 | var nconf = require('nconf'); 13 | nconf.argv().env().file({ file: 'config.json' }); 14 | 15 | var cf_api_url = nconf.get(environment + "_" + 'CF_API_URL'), 16 | username = nconf.get(environment + "_" + 'username'), 17 | password = nconf.get(environment + "_" + 'password'); 18 | 19 | var CloudController = require("../../../../lib/model/cloudcontroller/CloudController"); 20 | var CloudFoundryUsersUAA = require("../../../../lib/model/uaa/UsersUAA"); 21 | var CloudFoundryApps = require("../../../../lib/model/cloudcontroller/Apps"); 22 | var CloudFoundrySpaces = require("../../../../lib/model/cloudcontroller/Spaces"); 23 | var CloudFoundryUserProvidedServices = require("../../../../lib/model/cloudcontroller/UserProvidedServices"); 24 | var CloudFoundryServicePlans = require("../../../../lib/model/cloudcontroller/ServicePlans"); 25 | var BuildPacks = require("../../../../lib/model/cloudcontroller/BuildPacks"); 26 | CloudController = new CloudController(); 27 | CloudFoundryUsersUAA = new CloudFoundryUsersUAA(); 28 | CloudFoundryApps = new CloudFoundryApps(); 29 | CloudFoundrySpaces = new CloudFoundrySpaces(); 30 | CloudFoundryServicePlans = new CloudFoundryServicePlans(); 31 | CloudFoundryUserProvidedServices = new CloudFoundryUserProvidedServices(); 32 | BuildPacks = new BuildPacks(); 33 | 34 | describe("Cloud foundry Service Plans", function () { 35 | 36 | var authorization_endpoint = null; 37 | var token_endpoint = null; 38 | var token_type = null; 39 | var access_token = null; 40 | var space_guid = null; 41 | 42 | before(function () { 43 | this.timeout(25000); 44 | 45 | CloudController.setEndPoint(cf_api_url); 46 | CloudFoundryServicePlans.setEndPoint(cf_api_url); 47 | 48 | return CloudController.getInfo().then(function (result) { 49 | authorization_endpoint = result.authorization_endpoint; 50 | token_endpoint = result.token_endpoint; 51 | CloudFoundryUsersUAA.setEndPoint(authorization_endpoint); 52 | return CloudFoundryUsersUAA.login(username, password); 53 | }).then(function (result) { 54 | token_type = result.token_type; 55 | access_token = result.access_token; 56 | CloudFoundryServicePlans.setToken(result); 57 | }); 58 | 59 | }); 60 | 61 | function randomInt(low, high) { 62 | return Math.floor(Math.random() * (high - low) + low); 63 | } 64 | 65 | it.skip("Show a list of Service Plans available", function () { 66 | this.timeout(3000); 67 | 68 | var errorMessage = "No Service Plan"; 69 | return CloudFoundryServicePlans.getServicePlans().then(function (result) { 70 | if(result.total_results === 0){ 71 | return new Promise(function (resolve, reject) { 72 | return reject(errorMessage); 73 | }); 74 | } 75 | for(var i = 0; i < result.resources.length; i++){ 76 | console.log(i + " | " + result.resources[i].entity.name + " | " + result.resources[i].entity.description); 77 | } 78 | expect(result.total_results).is.a("number"); 79 | }).catch(function (reason) { 80 | expect(reason).to.equal(errorMessage); 81 | }); 82 | }); 83 | 84 | it("The platform returns a list of Service Plans available", function () { 85 | this.timeout(3000); 86 | 87 | var errorMessage = "No Service Plan"; 88 | return CloudFoundryServicePlans.getServicePlans().then(function (result) { 89 | if(result.total_results === 0){ 90 | return new Promise(function (resolve, reject) { 91 | return reject(errorMessage); 92 | }); 93 | } 94 | expect(result.total_results).is.a("number"); 95 | }).catch(function (reason) { 96 | expect(reason).to.equal(errorMessage); 97 | }); 98 | }); 99 | 100 | it("The platform returns the first Service Plan", function () { 101 | this.timeout(3000); 102 | 103 | var errorMessage = "No Service Plan"; 104 | var servicePlan_guid = null; 105 | return CloudFoundryServicePlans.getServicePlans().then(function (result) { 106 | if(result.total_results === 0){ 107 | return new Promise(function (resolve, reject) { 108 | return reject(errorMessage); 109 | }); 110 | } 111 | servicePlan_guid = result.resources[0].metadata.guid; 112 | return CloudFoundryServicePlans.getServicePlan(servicePlan_guid); 113 | }).then(function (result) { 114 | expect(result.metadata.guid).is.a("string"); 115 | }).catch(function (reason) { 116 | expect(reason).to.equal(errorMessage); 117 | }); 118 | }); 119 | 120 | it("The platform returns a list of active Service Plans available", function () { 121 | this.timeout(3000); 122 | 123 | var errorMessage = "No Service Plan"; 124 | var filter = { 125 | q: 'active:' + true 126 | }; 127 | return CloudFoundryServicePlans.getServicePlans(filter).then(function (result) { 128 | if(result.total_results === 0){ 129 | return new Promise(function (resolve, reject) { 130 | return reject(errorMessage); 131 | }); 132 | } 133 | expect(result.total_results).is.a("number"); 134 | }).catch(function (reason) { 135 | expect(reason).to.equal(errorMessage); 136 | }); 137 | }); 138 | 139 | it("The platform returns a list of Service Instances for the first Service Plan", function () { 140 | this.timeout(3000); 141 | 142 | var errorMessage = "No Service Plan"; 143 | var servicePlan_guid = null; 144 | return CloudFoundryServicePlans.getServicePlans().then(function (result) { 145 | if(result.total_results === 0){ 146 | return new Promise(function (resolve, reject) { 147 | return reject(errorMessage); 148 | }); 149 | } 150 | servicePlan_guid = result.resources[0].metadata.guid; 151 | return CloudFoundryServicePlans.getServicePlanInstances(servicePlan_guid); 152 | }).then(function (result) { 153 | expect(result.total_results).is.a("number"); 154 | }).catch(function (reason) { 155 | expect(reason).to.equal(errorMessage); 156 | }); 157 | }); 158 | 159 | it.skip("The platform removes a Service Plan", function () { 160 | this.timeout(3000); 161 | 162 | var errorMessage = "No Service Plan"; 163 | var servicePlan_guid = null; 164 | return CloudFoundryServicePlans.getServicePlans().then(function (result) { 165 | if(result.total_results === 0){ 166 | return new Promise(function (resolve, reject) { 167 | return reject(errorMessage); 168 | }); 169 | } 170 | servicePlan_guid = result.resources[1].metadata.guid; 171 | return CloudFoundryServicePlans.remove(servicePlan_guid); 172 | }).then(function (result) { 173 | expect(true).to.equal(true); 174 | }).catch(function (reason) { 175 | expect(reason).to.equal(errorMessage); 176 | }); 177 | }); 178 | }); 179 | -------------------------------------------------------------------------------- /test/lib/model/cloudcontroller/ServicesTests.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true*/ 2 | /*global describe: true, before:true, it: true*/ 3 | 4 | var Promise = require('bluebird'); 5 | var chai = require("chai"), 6 | expect = require("chai").expect; 7 | var randomWords = require('random-words'); 8 | 9 | var argv = require('optimist').demand('config').argv; 10 | var environment = argv.config; 11 | var nconf = require('nconf'); 12 | nconf.argv().env().file({ file: 'config.json' }); 13 | 14 | var cf_api_url = nconf.get(environment + "_" + 'CF_API_URL'), 15 | username = nconf.get(environment + "_" + 'username'), 16 | password = nconf.get(environment + "_" + 'password'); 17 | 18 | var CloudController = require("../../../../lib/model/cloudcontroller/CloudController"); 19 | var CloudFoundryUsersUAA = require("../../../../lib/model/uaa/UsersUAA"); 20 | var CloudFoundryApps = require("../../../../lib/model/cloudcontroller/Apps"); 21 | var CloudFoundrySpaces = require("../../../../lib/model/cloudcontroller/Spaces"); 22 | var CloudFoundryUserProvidedServices = require("../../../../lib/model/cloudcontroller/UserProvidedServices"); 23 | var CloudFoundryServices = require("../../../../lib/model/cloudcontroller/Services"); 24 | var BuildPacks = require("../../../../lib/model/cloudcontroller/BuildPacks"); 25 | CloudController = new CloudController(); 26 | CloudFoundryUsersUAA = new CloudFoundryUsersUAA(); 27 | CloudFoundryApps = new CloudFoundryApps(); 28 | CloudFoundrySpaces = new CloudFoundrySpaces(); 29 | CloudFoundryServices = new CloudFoundryServices(); 30 | CloudFoundryUserProvidedServices = new CloudFoundryUserProvidedServices(); 31 | BuildPacks = new BuildPacks(); 32 | 33 | describe("Cloud foundry Services", function () { 34 | "use strict"; 35 | var authorization_endpoint = null; 36 | var token_endpoint = null; 37 | var token_type = null; 38 | var access_token = null; 39 | var space_guid = null; 40 | 41 | before(function () { 42 | this.timeout(25000); 43 | 44 | CloudController.setEndPoint(cf_api_url); 45 | CloudFoundryServices.setEndPoint(cf_api_url); 46 | 47 | return CloudController.getInfo().then(function (result) { 48 | authorization_endpoint = result.authorization_endpoint; 49 | token_endpoint = result.token_endpoint; 50 | CloudFoundryUsersUAA.setEndPoint(authorization_endpoint); 51 | return CloudFoundryUsersUAA.login(username, password); 52 | }).then(function (result) { 53 | CloudFoundryServices.setToken(result); 54 | }); 55 | 56 | }); 57 | 58 | function randomInt(low, high) { 59 | return Math.floor(Math.random() * (high - low) + low); 60 | } 61 | 62 | it.skip("Show a list of Services available", function () { 63 | this.timeout(5000); 64 | 65 | return CloudFoundryServices.getServices().then(function (result) { 66 | for(var i = 0; i < result.resources.length; i++){ 67 | console.log(i + " | " + result.resources[i].entity.label + " | " + result.resources[i].entity.description); 68 | } 69 | expect(result.total_results).is.a("number"); 70 | }); 71 | }); 72 | 73 | it("The platform returns a list of Services available", function () { 74 | this.timeout(5000); 75 | 76 | return CloudFoundryServices.getServices().then(function (result) { 77 | expect(result.total_results).is.a("number"); 78 | }); 79 | }); 80 | 81 | it("The platform returns the first Service", function () { 82 | this.timeout(5000); 83 | 84 | var service_guid = null; 85 | return CloudFoundryServices.getServices().then(function (result) { 86 | if(result.total_results === 0){ 87 | return new Promise(function (resolve, reject) { 88 | return reject("No Service"); 89 | }); 90 | } 91 | service_guid = result.resources[0].metadata.guid; 92 | return CloudFoundryServices.getService(service_guid); 93 | }).then(function (result) { 94 | expect(result.metadata.guid).is.a("string"); 95 | }).catch(function (reason) { 96 | expect(reason).to.equal("No Service"); 97 | }); 98 | }); 99 | 100 | it("The platform returns a list of active Services available", function () { 101 | this.timeout(5000); 102 | 103 | var filter = { 104 | q: 'active:' + true 105 | }; 106 | return CloudFoundryServices.getServices(filter).then(function (result) { 107 | expect(result.total_results).is.a("number"); 108 | }); 109 | }); 110 | 111 | //cf_nise_installer doesn't provide Services by default. 112 | if(environment !== "LOCAL_INSTANCE_1") { 113 | 114 | it("The platform returns a list of Service Plans for the first Service", function () { 115 | this.timeout(5000); 116 | 117 | var service_guid = null; 118 | return CloudFoundryServices.getServices().then(function (result) { 119 | service_guid = result.resources[0].metadata.guid; 120 | return CloudFoundryServices.getServicePlans(service_guid); 121 | }).then(function (result) { 122 | expect(result.total_results).is.a("number"); 123 | }) 124 | }); 125 | 126 | } 127 | 128 | it.skip("The platform removes a Service", function () { 129 | this.timeout(5000); 130 | 131 | var service_guid = null; 132 | return CloudFoundryServices.getServices().then(function (result) { 133 | service_guid = result.resources[1].metadata.guid; 134 | return CloudFoundryServices.remove(service_guid); 135 | }).then(function (result) { 136 | expect(true).to.equal(true); 137 | }); 138 | }); 139 | }); 140 | -------------------------------------------------------------------------------- /test/lib/model/cloudcontroller/SpacesQuotaTests.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true*/ 2 | /*global describe: true, before:true, it: true*/ 3 | "use strict"; 4 | 5 | var Promise = require('bluebird'); 6 | var chai = require("chai"), 7 | expect = require("chai").expect; 8 | 9 | var argv = require('optimist').demand('config').argv; 10 | var environment = argv.config; 11 | var nconf = require('nconf'); 12 | nconf.argv().env().file({ file: 'config.json' }); 13 | 14 | var cf_api_url = nconf.get(environment + "_" + 'CF_API_URL'), 15 | username = nconf.get(environment + "_" + 'username'), 16 | password = nconf.get(environment + "_" + 'password'); 17 | 18 | var CloudController = require("../../../../lib/model/cloudcontroller/CloudController"); 19 | var CloudFoundryUsersUAA = require("../../../../lib/model/uaa/UsersUAA"); 20 | var CloudFoundrySpacesQuota = require("../../../../lib/model/cloudcontroller/SpacesQuota"); 21 | CloudController = new CloudController(); 22 | CloudFoundryUsersUAA = new CloudFoundryUsersUAA(); 23 | CloudFoundrySpacesQuota = new CloudFoundrySpacesQuota(); 24 | 25 | describe("Cloud foundry Spaces Quotas", function () { 26 | 27 | var authorization_endpoint = null; 28 | var token_endpoint = null; 29 | var token_type = null; 30 | var access_token = null; 31 | 32 | before(function () { 33 | this.timeout(15000); 34 | 35 | CloudController.setEndPoint(cf_api_url); 36 | CloudFoundrySpacesQuota.setEndPoint(cf_api_url); 37 | 38 | return CloudController.getInfo().then(function (result) { 39 | authorization_endpoint = result.authorization_endpoint; 40 | token_endpoint = result.token_endpoint; 41 | CloudFoundryUsersUAA.setEndPoint(authorization_endpoint); 42 | return CloudFoundryUsersUAA.login(username, password); 43 | }).then(function (result) { 44 | CloudFoundrySpacesQuota.setToken(result); 45 | }); 46 | 47 | }); 48 | 49 | it("The platform returns Space Quota Defininitions", function () { 50 | this.timeout(3000); 51 | 52 | return CloudFoundrySpacesQuota.getQuotaDefinitions().then(function (result) { 53 | expect(result.total_results).to.be.a('number'); 54 | }); 55 | }); 56 | 57 | }); -------------------------------------------------------------------------------- /test/lib/model/cloudcontroller/SpacesTests.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true*/ 2 | /*global describe: true, before:true, it: true*/ 3 | "use strict"; 4 | 5 | var Promise = require('bluebird'); 6 | var chai = require("chai"), 7 | expect = require("chai").expect; 8 | 9 | var argv = require('optimist').demand('config').argv; 10 | var environment = argv.config; 11 | var nconf = require('nconf'); 12 | nconf.argv().env().file({ file: 'config.json' }); 13 | 14 | var cf_api_url = nconf.get(environment + "_" + 'CF_API_URL'), 15 | username = nconf.get(environment + "_" + 'username'), 16 | password = nconf.get(environment + "_" + 'password'); 17 | 18 | var CloudController = require("../../../../lib/model/cloudcontroller/CloudController"); 19 | var CloudFoundryUsersUAA = require("../../../../lib/model/uaa/UsersUAA"); 20 | var CloudFoundrySpaces = require("../../../../lib/model/cloudcontroller/Spaces"); 21 | var CloudFoundryApps = require("../../../../lib/model/cloudcontroller/Apps"); 22 | CloudController = new CloudController(); 23 | CloudFoundryUsersUAA = new CloudFoundryUsersUAA(); 24 | CloudFoundrySpaces = new CloudFoundrySpaces(); 25 | CloudFoundryApps = new CloudFoundryApps(); 26 | 27 | describe("Cloud foundry Spaces", function () { 28 | 29 | var authorization_endpoint = null; 30 | var token_endpoint = null; 31 | var token_type = null; 32 | var access_token = null; 33 | 34 | before(function () { 35 | this.timeout(15000); 36 | 37 | CloudController.setEndPoint(cf_api_url); 38 | CloudFoundryApps.setEndPoint(cf_api_url); 39 | CloudFoundrySpaces.setEndPoint(cf_api_url); 40 | 41 | return CloudController.getInfo().then(function (result) { 42 | authorization_endpoint = result.authorization_endpoint; 43 | token_endpoint = result.token_endpoint; 44 | CloudFoundryUsersUAA.setEndPoint(authorization_endpoint); 45 | return CloudFoundryUsersUAA.login(username, password); 46 | }).then(function (result) { 47 | CloudFoundryApps.setToken(result); 48 | CloudFoundrySpaces.setToken(result); 49 | }); 50 | 51 | }); 52 | 53 | it("The platform always has defined a Space to operate.", function () { 54 | this.timeout(3000); 55 | 56 | return CloudFoundrySpaces.getSpaces().then(function (result) { 57 | expect(result.total_results).to.be.above(0); 58 | }); 59 | }); 60 | 61 | it("The platform returns a unique Space.", function () { 62 | this.timeout(4500); 63 | 64 | var space_guid = null; 65 | 66 | return CloudFoundrySpaces.getSpaces().then(function (result) { 67 | space_guid = result.resources[0].metadata.guid; 68 | }).then(function () { 69 | return CloudFoundrySpaces.getSpace(space_guid); 70 | }).then(function (result) { 71 | expect(result.metadata.guid).is.a("string"); 72 | }); 73 | }); 74 | 75 | it("The platform returns Apps deployed in a Space.", function () { 76 | this.timeout(4000); 77 | 78 | var space_guid = null; 79 | 80 | return CloudFoundrySpaces.getSpaces().then(function (result) { 81 | space_guid = result.resources[0].metadata.guid; 82 | }).then(function () { 83 | var filter = { 84 | 'guid' : space_guid 85 | }; 86 | return CloudFoundrySpaces.getSpaceApps(space_guid, filter); 87 | }).then(function (result) { 88 | expect(result.total_results).to.be.a('number'); 89 | }); 90 | }); 91 | 92 | it("The platform returns Summary from a Space.", function () { 93 | this.timeout(4000); 94 | 95 | var space_guid = null; 96 | 97 | return CloudFoundrySpaces.getSpaces().then(function (result) { 98 | space_guid = result.resources[0].metadata.guid; 99 | }).then(function () { 100 | return CloudFoundrySpaces.getSummary(space_guid); 101 | }).then(function (result) { 102 | expect(true).to.be.a('boolean'); 103 | }); 104 | }); 105 | 106 | it("[TOOL] The platform returns Services used in the Space.", function () { 107 | this.timeout(4000); 108 | 109 | var space_guid = null; 110 | 111 | return CloudFoundrySpaces.getSpaces().then(function (result) { 112 | space_guid = result.resources[0].metadata.guid; 113 | }).then(function () { 114 | return CloudFoundrySpaces.getSummary(space_guid); 115 | }).then(function (result) { 116 | 117 | var usedServices = []; 118 | result.services.forEach(function(service) { 119 | if(service.bound_app_count > 0){ 120 | usedServices.push(service); 121 | } 122 | }); 123 | expect(true).to.be.a('boolean'); 124 | }); 125 | }); 126 | 127 | it("[TOOL] The platform returns Services Services without usage in the Space.", function () { 128 | this.timeout(4000); 129 | 130 | var space_guid = null; 131 | 132 | return CloudFoundrySpaces.getSpaces().then(function (result) { 133 | space_guid = result.resources[0].metadata.guid; 134 | }).then(function () { 135 | return CloudFoundrySpaces.getSummary(space_guid); 136 | }).then(function (result) { 137 | 138 | var servicesWithoutUsage = []; 139 | result.services.forEach(function(service) { 140 | if(service.bound_app_count === 0){ 141 | servicesWithoutUsage.push(service); 142 | } 143 | }); 144 | expect(true).to.be.a('boolean'); 145 | }); 146 | }); 147 | 148 | it("The platform returns User roles from a Space.", function () { 149 | this.timeout(4000); 150 | 151 | var space_guid = null; 152 | 153 | return CloudFoundrySpaces.getSpaces().then(function (result) { 154 | space_guid = result.resources[0].metadata.guid; 155 | }).then(function () { 156 | return CloudFoundrySpaces.getUserRoles(space_guid); 157 | }).then(function (result) { 158 | expect(result.total_results).to.be.a('number'); 159 | }); 160 | }); 161 | 162 | }); -------------------------------------------------------------------------------- /test/lib/model/cloudcontroller/StacksTests.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true*/ 2 | 3 | var Promise = require('bluebird'); 4 | var chai = require("chai"), 5 | expect = require("chai").expect; 6 | 7 | var argv = require('optimist').demand('config').argv; 8 | var environment = argv.config; 9 | var nconf = require('nconf'); 10 | nconf.argv().env().file({ file: 'config.json' }); 11 | 12 | var cf_api_url = nconf.get(environment + "_" + 'CF_API_URL'), 13 | username = nconf.get(environment + "_" + 'username'), 14 | password = nconf.get(environment + "_" + 'password'); 15 | 16 | var CloudController = require("../../../../lib/model/cloudcontroller/CloudController"); 17 | var CloudFoundryUsersUAA = require("../../../../lib/model/uaa/UsersUAA"); 18 | var CloudFoundryStacks = require("../../../../lib/model/cloudcontroller/Stacks"); 19 | CloudController = new CloudController(); 20 | CloudFoundryUsersUAA = new CloudFoundryUsersUAA(); 21 | CloudFoundryStacks = new CloudFoundryStacks(); 22 | 23 | describe("Cloud foundry Stacks", function () { 24 | "use strict"; 25 | 26 | var authorization_endpoint = null; 27 | var token_endpoint = null; 28 | var token_type = null; 29 | var access_token = null; 30 | 31 | before(function () { 32 | this.timeout(15000); 33 | 34 | CloudController.setEndPoint(cf_api_url); 35 | CloudFoundryStacks.setEndPoint(cf_api_url); 36 | 37 | return CloudController.getInfo().then(function (result) { 38 | authorization_endpoint = result.authorization_endpoint; 39 | token_endpoint = result.token_endpoint; 40 | CloudFoundryUsersUAA.setEndPoint(authorization_endpoint); 41 | return CloudFoundryUsersUAA.login(username, password); 42 | }).then(function (result) { 43 | CloudFoundryStacks.setToken(result); 44 | }); 45 | 46 | }); 47 | 48 | it("The platform returns Stacks installed", function () { 49 | this.timeout(3000); 50 | 51 | return CloudFoundryStacks.getStacks().then(function (result) { 52 | expect(result.total_results).is.a("number"); 53 | }); 54 | }); 55 | 56 | }); 57 | -------------------------------------------------------------------------------- /test/lib/model/cloudcontroller/UploadJEEAppsTests.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true*/ 2 | /*global Promise:true*/ 3 | /*global describe: true, before:true, it: true*/ 4 | "use strict"; 5 | 6 | var Promise = require('bluebird'); 7 | var chai = require("chai"), 8 | expect = require("chai").expect; 9 | var randomWords = require('random-words'); 10 | 11 | var argv = require('optimist').demand('config').argv; 12 | var environment = argv.config; 13 | var nconf = require('nconf'); 14 | nconf.argv().env().file({ file: 'config.json' }); 15 | 16 | var cf_api_url = nconf.get(environment + "_" + 'CF_API_URL'), 17 | username = nconf.get(environment + "_" + 'username'), 18 | password = nconf.get(environment + "_" + 'password'); 19 | 20 | var CloudController = require("../../../../lib/model/cloudcontroller/CloudController"); 21 | var CloudFoundryUsersUAA = require("../../../../lib/model/uaa/UsersUAA"); 22 | var CloudFoundryApps = require("../../../../lib/model/cloudcontroller/Apps"); 23 | var CloudFoundrySpaces = require("../../../../lib/model/cloudcontroller/Spaces"); 24 | var CloudFoundryDomains = require("../../../../lib/model/cloudcontroller/Domains"); 25 | var CloudFoundryRoutes = require("../../../../lib/model/cloudcontroller/Routes"); 26 | var CloudFoundryJobs = require("../../../../lib/model/cloudcontroller/Jobs"); 27 | var BuildPacks = require("../../../../lib/model/cloudcontroller/BuildPacks"); 28 | CloudController = new CloudController(); 29 | CloudFoundryUsersUAA = new CloudFoundryUsersUAA(); 30 | CloudFoundryApps = new CloudFoundryApps(); 31 | CloudFoundrySpaces = new CloudFoundrySpaces(); 32 | CloudFoundryDomains = new CloudFoundryDomains(); 33 | CloudFoundryRoutes = new CloudFoundryRoutes(); 34 | CloudFoundryJobs = new CloudFoundryJobs(); 35 | BuildPacks = new BuildPacks(); 36 | var HttpUtils = require('../../../../lib/utils/HttpUtils'); 37 | HttpUtils = new HttpUtils(); 38 | 39 | var fs = require('fs'); 40 | var ZipGenerator = require('../../../utils/ZipGenerator'); 41 | ZipGenerator = new ZipGenerator(); 42 | 43 | describe("Cloud Foundry Upload JEE Apps", function () { 44 | 45 | var authorization_endpoint = null; 46 | var token_endpoint = null; 47 | var token_type = null; 48 | var access_token = null; 49 | var domain_guid = null; 50 | var space_guid = null; 51 | 52 | before(function () { 53 | this.timeout(15000); 54 | 55 | CloudController.setEndPoint(cf_api_url); 56 | CloudFoundryApps.setEndPoint(cf_api_url); 57 | CloudFoundrySpaces.setEndPoint(cf_api_url); 58 | CloudFoundryDomains.setEndPoint(cf_api_url); 59 | CloudFoundryRoutes.setEndPoint(cf_api_url); 60 | CloudFoundryJobs.setEndPoint(cf_api_url); 61 | 62 | return CloudController.getInfo().then(function (result) { 63 | authorization_endpoint = result.authorization_endpoint; 64 | token_endpoint = result.token_endpoint; 65 | CloudFoundryUsersUAA.setEndPoint(authorization_endpoint); 66 | return CloudFoundryUsersUAA.login(username, password); 67 | }).then(function (result) { 68 | CloudFoundryApps.setToken(result); 69 | CloudFoundrySpaces.setToken(result); 70 | CloudFoundryDomains.setToken(result); 71 | CloudFoundryRoutes.setToken(result); 72 | CloudFoundryJobs.setToken(result); 73 | return CloudFoundryDomains.getDomains(); 74 | }).then(function (result) { 75 | domain_guid = result.resources[0].metadata.guid; 76 | return CloudFoundrySpaces.getSpaces(); 77 | }).then(function (result) { 78 | space_guid = result.resources[0].metadata.guid; 79 | }); 80 | 81 | }); 82 | 83 | function randomInt(low, high) { 84 | return Math.floor(Math.random() * (high - low) + low); 85 | } 86 | 87 | function createApp(appOptions) { 88 | 89 | var app_guid = null; 90 | var routeName = null; 91 | var route_guid = null; 92 | var route_create_flag = false; 93 | var appName = appOptions.name; 94 | 95 | return new Promise(function (resolve, reject) { 96 | 97 | var filter = { 98 | 'q': 'name:' + appName, 99 | 'inline-relations-depth': 1 100 | }; 101 | 102 | //VALIDATIONS 103 | //1. Duplicated app 104 | return CloudFoundrySpaces.getSpaceApps(space_guid, filter).then(function (result) { 105 | 106 | //If exist the application, REJECT 107 | if (result.total_results === 1) { 108 | return reject("Exist the app: " + appName); 109 | } 110 | 111 | var filter = { 112 | 'q': 'host:' + appName + ';domain_guid:' + domain_guid, 113 | 'inline-relations-depth': 1 114 | }; 115 | return CloudFoundryRoutes.getRoutes(filter); 116 | //2. Duplicated route 117 | }).then(function (result) { 118 | 119 | if (result.total_results === 1) { 120 | return reject("Exist the route:" + appName); 121 | } 122 | 123 | return CloudFoundryApps.add(appOptions).then(function (result) { 124 | return new Promise(function (resolve) { 125 | //console.log(result); 126 | app_guid = result.metadata.guid; 127 | return resolve(); 128 | }); 129 | }); 130 | }).then(function () { 131 | //TODO: How to make the inference? 132 | return CloudFoundryDomains.getSharedDomains(); 133 | }).then(function () { 134 | var routeOptions = { 135 | 'domain_guid' : domain_guid, 136 | 'space_guid' : space_guid, 137 | 'host' : appName 138 | }; 139 | return CloudFoundryRoutes.add(routeOptions).then(function (result) { 140 | return new Promise(function (resolve) { 141 | route_guid = result.metadata.guid; 142 | return resolve(result); 143 | }); 144 | }); 145 | }).then(function () { 146 | return CloudFoundryApps.associateRoute(app_guid, route_guid); 147 | }).then(function (result) { 148 | return resolve(result); 149 | }).catch(function (reason) { 150 | console.error("Error: " + reason); 151 | return reject(reason); 152 | }); 153 | 154 | }); 155 | 156 | } 157 | 158 | it("Create a Spring MVC 4 App, Upload the App & Remove app", function () { 159 | this.timeout(40000); 160 | 161 | var app_guid = null; 162 | var appName = "app2" + randomWords() + randomInt(1, 100); 163 | var zipPath = "./test_resources/SpringMVC_v4_AppExample.war"; 164 | var javaBuildPack = BuildPacks.get("java"); 165 | var route_guid = null; 166 | var appOptions = { 167 | "name": appName, 168 | "space_guid": space_guid, 169 | "instances" : 1, 170 | "memory" : 256, 171 | "disk_quota" : 256, 172 | "buildpack" : javaBuildPack 173 | }; 174 | 175 | return createApp(appOptions).then(function (result) { 176 | app_guid = result.metadata.guid; 177 | expect(app_guid).is.a("string"); 178 | expect(result.entity.buildpack).to.equal(javaBuildPack); 179 | 180 | return CloudFoundryApps.upload(app_guid, zipPath, false); 181 | }).then(function (result) { 182 | return CloudFoundryApps.getAppRoutes(app_guid); 183 | }).then(function (result) { 184 | route_guid = result.resources[0].metadata.guid; 185 | return CloudFoundryApps.remove(app_guid); 186 | }).then(function () { 187 | return CloudFoundryRoutes.remove(route_guid); 188 | }).then(function () { 189 | expect(true).to.equal(true); 190 | }); 191 | }); 192 | 193 | it("Create a Spring MVC 3 App, Upload the App & Remove app", function () { 194 | this.timeout(40000); 195 | 196 | var app_guid = null; 197 | var appName = "app2" + randomWords() + randomInt(1, 100); 198 | var zipPath = "./test_resources/SpringMVC_v3_AppExample.war"; 199 | var javaBuildPack = BuildPacks.get("java"); 200 | var route_guid = null; 201 | var appOptions = { 202 | "name": appName, 203 | "space_guid": space_guid, 204 | "instances" : 1, 205 | "memory" : 256, 206 | "disk_quota" : 256, 207 | "buildpack" : javaBuildPack 208 | }; 209 | 210 | return createApp(appOptions).then(function (result) { 211 | app_guid = result.metadata.guid; 212 | expect(app_guid).is.a("string"); 213 | expect(result.entity.buildpack).to.equal(javaBuildPack); 214 | 215 | return CloudFoundryApps.upload(app_guid, zipPath, false); 216 | }).then(function (result) { 217 | return CloudFoundryApps.getAppRoutes(app_guid); 218 | }).then(function (result) { 219 | route_guid = result.resources[0].metadata.guid; 220 | return CloudFoundryApps.remove(app_guid); 221 | }).then(function () { 222 | return CloudFoundryRoutes.remove(route_guid); 223 | }).then(function () { 224 | expect(true).to.equal(true); 225 | }); 226 | }); 227 | 228 | it.skip("[Tool] Create & deploy a JEE App", function () { 229 | this.timeout(40000); 230 | 231 | var app_guid = null; 232 | var appName = "apptest" + randomWords() + randomInt(1, 100); 233 | var zipPath = "./test_resources/SpringMVC_v4_AppExample.war"; 234 | var javaBuildPack = BuildPacks.get("java"); 235 | var route_guid = null; 236 | var appOptions = { 237 | "name": appName, 238 | "space_guid": space_guid, 239 | "instances" : 1, 240 | "memory" : 512, 241 | "disk_quota" : 512, 242 | "buildpack" : javaBuildPack 243 | }; 244 | 245 | return createApp(appOptions).then(function (result) { 246 | app_guid = result.metadata.guid; 247 | expect(app_guid).is.a("string"); 248 | expect(result.entity.buildpack).to.equal(javaBuildPack); 249 | 250 | return CloudFoundryApps.upload(app_guid, zipPath, false); 251 | }).then(function (result) { 252 | return CloudFoundryApps.getAppRoutes(app_guid); 253 | }).then(function (result) { 254 | route_guid = result.resources[0].metadata.guid; 255 | expect(true).to.equal(true); 256 | }); 257 | }); 258 | 259 | }); 260 | 261 | 262 | -------------------------------------------------------------------------------- /test/lib/model/cloudcontroller/UserProvidedServicesTests.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true*/ 2 | /*global describe: true, before:true, it: true*/ 3 | "use strict"; 4 | 5 | var Promise = require('bluebird'); 6 | var chai = require("chai"), 7 | expect = require("chai").expect; 8 | var randomWords = require('random-words'); 9 | 10 | var argv = require('optimist').demand('config').argv; 11 | var environment = argv.config; 12 | var nconf = require('nconf'); 13 | nconf.argv().env().file({ file: 'config.json' }); 14 | 15 | var cf_api_url = nconf.get(environment + "_" + 'CF_API_URL'), 16 | username = nconf.get(environment + "_" + 'username'), 17 | password = nconf.get(environment + "_" + 'password'); 18 | 19 | var CloudController = require("../../../../lib/model/cloudcontroller/CloudController"); 20 | var CloudFoundryUsersUAA = require("../../../../lib/model/uaa/UsersUAA"); 21 | var CloudFoundrySpaces = require("../../../../lib/model/cloudcontroller/Spaces"); 22 | var CloudFoundryUserProvidedServices = require("../../../../lib/model/cloudcontroller/UserProvidedServices"); 23 | CloudController = new CloudController(cf_api_url); 24 | CloudFoundryUsersUAA = new CloudFoundryUsersUAA(); 25 | CloudFoundrySpaces = new CloudFoundrySpaces(cf_api_url); 26 | CloudFoundryUserProvidedServices = new CloudFoundryUserProvidedServices(cf_api_url); 27 | 28 | describe("Cloud foundry User Provided Services", function () { 29 | 30 | var authorization_endpoint = null; 31 | var token_endpoint = null; 32 | var token_type = null; 33 | var access_token = null; 34 | var space_guid = null; 35 | 36 | before(function () { 37 | this.timeout(15000); 38 | 39 | CloudController.setEndPoint(cf_api_url); 40 | CloudFoundrySpaces.setEndPoint(cf_api_url); 41 | CloudFoundryUserProvidedServices.setEndPoint(cf_api_url); 42 | 43 | return CloudController.getInfo().then(function (result) { 44 | authorization_endpoint = result.authorization_endpoint; 45 | token_endpoint = result.token_endpoint; 46 | CloudFoundryUsersUAA.setEndPoint(authorization_endpoint); 47 | return CloudFoundryUsersUAA.login(username, password); 48 | }).then(function (result) { 49 | CloudFoundrySpaces.setToken(result); 50 | CloudFoundryUserProvidedServices.setToken(result); 51 | return CloudFoundrySpaces.getSpaces(); 52 | }).then(function (result) { 53 | space_guid = result.resources[0].metadata.guid; 54 | }); 55 | 56 | }); 57 | 58 | function randomInt(low, high) { 59 | return Math.floor(Math.random() * (high - low) + low); 60 | } 61 | 62 | it("The platform returns a list of User Provided Services", function () { 63 | this.timeout(10000); 64 | 65 | return CloudFoundryUserProvidedServices.getServices().then(function (result) { 66 | //console.log(result.resources); 67 | expect(result.total_results).is.a("number"); 68 | }); 69 | }); 70 | 71 | it("The platform returns the first User Provided Service", function () { 72 | this.timeout(10000); 73 | 74 | var service_guid = null; 75 | return CloudFoundryUserProvidedServices.getServices().then(function (result) { 76 | if(result.total_results === 0){ 77 | return new Promise(function (resolve, reject) { 78 | return reject("No User Provided Service"); 79 | }); 80 | } 81 | service_guid = result.resources[0].metadata.guid; 82 | return CloudFoundryUserProvidedServices.getService(service_guid); 83 | }).then(function (result) { 84 | expect(result.metadata.guid).is.a("string"); 85 | }).catch(function (reason) { 86 | //console.error("Error: " + reason); 87 | expect(reason).to.equal("No User Provided Service"); 88 | }); 89 | }); 90 | 91 | it.skip("Create an User Provided Service", function () { 92 | this.timeout(10000); 93 | 94 | var serviceName = "s" + randomWords() + randomInt(1, 100); 95 | var service_guid = null; 96 | var credentials = { 97 | dbname : "demo", 98 | host : "8.8.8.8", 99 | port : "3306", 100 | username : "root", 101 | password : "123456" 102 | }; 103 | var user_provided_service_options ={ 104 | "space_guid" : space_guid, 105 | "name" : serviceName, 106 | "credentials" : credentials 107 | }; 108 | 109 | return CloudFoundryUserProvidedServices.add(user_provided_service_options).then(function (result) { 110 | expect(result.metadata.guid).is.a("string"); 111 | }); 112 | }); 113 | 114 | it("Create & Delete an User Provided Service", function () { 115 | this.timeout(10000); 116 | 117 | var serviceName = "s" + randomWords() + randomInt(1, 100); 118 | var service_guid = null; 119 | var credentials = { 120 | dbname : "demo", 121 | host : "8.8.8.8", 122 | port : "3306", 123 | username : "root", 124 | password : "123456" 125 | }; 126 | var user_provided_service_options ={ 127 | "space_guid" : space_guid, 128 | "name" : serviceName, 129 | "credentials" : credentials 130 | }; 131 | return CloudFoundryUserProvidedServices.add(user_provided_service_options).then(function (result) { 132 | service_guid = result.metadata.guid; 133 | expect(service_guid).is.a("string"); 134 | return CloudFoundryUserProvidedServices.remove(service_guid); 135 | }).then(function (result) { 136 | expect(true).to.equal(true); 137 | }); 138 | }); 139 | 140 | it("Create, Search & Delete an User Provided Service", function () { 141 | this.timeout(10000); 142 | 143 | var serviceName = "s" + randomWords() + randomInt(1, 100); 144 | var service_guid = null; 145 | var credentials = { 146 | dbname : "demo", 147 | host : "8.8.8.8", 148 | port : "3306", 149 | username : "root", 150 | password : "123456" 151 | }; 152 | var user_provided_service_options ={ 153 | "space_guid" : space_guid, 154 | "name" : serviceName, 155 | "credentials" : credentials 156 | }; 157 | return CloudFoundryUserProvidedServices.add(user_provided_service_options).then(function (result) { 158 | service_guid = result.metadata.guid; 159 | expect(service_guid).is.a("string"); 160 | return CloudFoundryUserProvidedServices.getServiceBindings(service_guid); 161 | }).then(function (result) { 162 | expect(result.total_results).is.a("number"); 163 | expect(result.total_results).to.equal(0); 164 | return CloudFoundryUserProvidedServices.remove(service_guid); 165 | }).then(function (result) { 166 | expect(true).to.equal(true); 167 | }); 168 | }); 169 | 170 | }); -------------------------------------------------------------------------------- /test/lib/model/cloudcontroller/UserTests.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true*/ 2 | /*global Promise:true, describe: true, before:true, it: true*/ 3 | "use strict"; 4 | 5 | var Promise = require('bluebird'); 6 | var chai = require("chai"), 7 | chaiAsPromised = require("chai-as-promised"), 8 | expect = require("chai").expect; 9 | chai.use(chaiAsPromised); 10 | 11 | var argv = require('optimist').demand('config').argv; 12 | var environment = argv.config; 13 | var nconf = require('nconf'); 14 | nconf.argv().env().file({ file: 'config.json' }); 15 | 16 | var cf_api_url = nconf.get(environment + "_" + 'CF_API_URL'), 17 | username = nconf.get(environment + "_" + 'username'), 18 | password = nconf.get(environment + "_" + 'password'); 19 | 20 | var CloudController = require("../../../../lib/model/cloudcontroller/CloudController"); 21 | var CloudFoundryUsersUAA = require("../../../../lib/model/uaa/UsersUAA"); 22 | var CloudFoundryUsers = require("../../../../lib/model/cloudcontroller/Users"); 23 | CloudController = new CloudController(); 24 | CloudFoundryUsersUAA = new CloudFoundryUsersUAA(); 25 | CloudFoundryUsers = new CloudFoundryUsers(); 26 | 27 | 28 | describe("Cloud Foundry Users", function () { 29 | 30 | var authorization_endpoint = null; 31 | var token_endpoint = null; 32 | var token_type = null; 33 | var access_token = null; 34 | 35 | before(function () { 36 | this.timeout(15000); 37 | 38 | CloudController.setEndPoint(cf_api_url); 39 | CloudFoundryUsers.setEndPoint(cf_api_url); 40 | 41 | return CloudController.getInfo().then(function (result) { 42 | authorization_endpoint = result.authorization_endpoint; 43 | token_endpoint = result.token_endpoint; 44 | CloudFoundryUsersUAA.setEndPoint(authorization_endpoint); 45 | return CloudFoundryUsersUAA.login(username, password); 46 | }).then(function (result) { 47 | CloudFoundryUsersUAA.setToken(result); 48 | CloudFoundryUsers.setToken(result); 49 | }); 50 | 51 | }); 52 | 53 | function randomInt(low, high) { 54 | return Math.floor(Math.random() * (high - low) + low); 55 | } 56 | 57 | //Testing users doesn't have permissions 58 | if(environment === "LOCAL_INSTANCE_1") { 59 | 60 | it("The platform retrieves Users from CC", function () { 61 | this.timeout(5000); 62 | 63 | return CloudFoundryUsers.getUsers().then(function (result) { 64 | expect(result.resources).to.be.a('array'); 65 | }); 66 | }); 67 | 68 | it("The platform creates, search & remove an User from UAA", function () { 69 | this.timeout(5000); 70 | 71 | var uaa_guid = null; 72 | var username = "user" + randomInt(1, 10000); 73 | var uaa_options = { 74 | "schemas":["urn:scim:schemas:core:1.0"], 75 | "userName":username, 76 | "emails":[ 77 | { 78 | "value":"demo@example.com", 79 | "type":"work" 80 | } 81 | ] 82 | }; 83 | var searchOptions = "?filter=userName eq '" + username + "'"; 84 | var user_guid = null; 85 | 86 | return CloudFoundryUsersUAA.add(uaa_options).then(function (result) { 87 | return CloudFoundryUsersUAA.getUsers(searchOptions); 88 | }).then(function (result) { 89 | if(result.resources.length !== 1){ 90 | return new Promise(function (resolve, reject) { 91 | return reject("No Users"); 92 | }); 93 | } 94 | uaa_guid = result.resources[0].id; 95 | //console.log(uaa_guid) 96 | var userOptions = { 97 | "guid": uaa_guid 98 | } 99 | return CloudFoundryUsers.add(userOptions); 100 | }).then(function (result) { 101 | //console.log(result); 102 | user_guid = result.metadata.guid; 103 | return CloudFoundryUsers.remove(user_guid); 104 | }).then(function (result) { 105 | return CloudFoundryUsersUAA.remove(uaa_guid); 106 | }).then(function (result) { 107 | return CloudFoundryUsersUAA.getUsers(searchOptions); 108 | }).then(function (result) { 109 | if(result.resources.length !== 0){ 110 | return new Promise(function (resolve, reject) { 111 | return reject("Rare output"); 112 | }); 113 | } 114 | expect(true).to.be.a('boolean'); 115 | }); 116 | }); 117 | 118 | } 119 | 120 | }); 121 | -------------------------------------------------------------------------------- /test/lib/model/metrics/LogTests.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true*/ 2 | /*global describe: true, before: true, it: true */ 3 | "use strict"; 4 | 5 | var Promise = require('bluebird'); 6 | var chai = require("chai"), 7 | expect = require("chai").expect; 8 | 9 | var argv = require('optimist').demand('config').argv; 10 | var environment = argv.config; 11 | var nconf = require('nconf'); 12 | nconf.argv().env().file({ file: 'config.json' }); 13 | 14 | var cf_api_url = nconf.get(environment + "_" + 'CF_API_URL'), 15 | username = nconf.get(environment + "_" + 'username'), 16 | password = nconf.get(environment + "_" + 'password'); 17 | 18 | var CloudController = require("../../../../lib/model/cloudcontroller/CloudController"); 19 | var CloudFoundryUsersUAA = require("../../../../lib/model/uaa/UsersUAA"); 20 | var CloudFoundryApps = require("../../../../lib/model/cloudcontroller/Apps"); 21 | var CloudFoundryLogs = require("../../../../lib/model/metrics/Logs"); 22 | CloudController = new CloudController(); 23 | CloudFoundryUsersUAA = new CloudFoundryUsersUAA(); 24 | CloudFoundryApps = new CloudFoundryApps(); 25 | CloudFoundryLogs = new CloudFoundryLogs(); 26 | 27 | describe("Cloud foundry Logs", function () { 28 | 29 | var authorization_endpoint = null; 30 | var token_endpoint = null; 31 | var logging_endpoint = null; 32 | var token_type = null; 33 | var access_token = null; 34 | 35 | before(function () { 36 | this.timeout(20000); 37 | 38 | CloudController.setEndPoint(cf_api_url); 39 | CloudFoundryApps.setEndPoint(cf_api_url); 40 | 41 | return CloudController.getInfo().then(function (result) { 42 | authorization_endpoint = result.authorization_endpoint; 43 | token_endpoint = result.token_endpoint; 44 | logging_endpoint = result.logging_endpoint; 45 | CloudFoundryUsersUAA.setEndPoint(authorization_endpoint); 46 | return CloudFoundryUsersUAA.login(username, password); 47 | }).then(function (result) { 48 | CloudFoundryUsersUAA.setToken(result); 49 | CloudFoundryApps.setToken(result); 50 | CloudFoundryLogs.setToken(result); 51 | }); 52 | }); 53 | 54 | it("The platform returns Logs", function () { 55 | this.timeout(6000); 56 | 57 | var app_guid = null; 58 | var ERROR_MESSAGE_NO_APPS = "No App"; 59 | 60 | return CloudFoundryApps.getApps().then(function (result) { 61 | 62 | if (result.total_results === 0) { 63 | return new Promise(function check(resolve, reject) { 64 | reject(ERROR_MESSAGE_NO_APPS); 65 | }); 66 | } 67 | 68 | app_guid = result.resources[0].metadata.guid; 69 | //Process URL 70 | //console.log(logging_endpoint); 71 | logging_endpoint = logging_endpoint.replace("wss", "https"); 72 | logging_endpoint = logging_endpoint.replace(":4443", ""); 73 | logging_endpoint = logging_endpoint.replace(":443", "");//Bluemix support 74 | //console.log(logging_endpoint); 75 | CloudFoundryLogs.setEndPoint(logging_endpoint); 76 | return CloudFoundryLogs.getRecent(app_guid); 77 | }).then(function () { 78 | //console.log(result); 79 | expect(true).is.equal(true); 80 | }).catch(function (reason) { 81 | //console.log(reason); 82 | expect(reason).to.be.ok; 83 | }); 84 | }); 85 | 86 | }); 87 | -------------------------------------------------------------------------------- /test/lib/model/uaa/UserUAATests.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true*/ 2 | 3 | var Promise = require('bluebird'); 4 | var chai = require("chai"), 5 | chaiAsPromised = require("chai-as-promised"), 6 | expect = require("chai").expect; 7 | chai.use(chaiAsPromised); 8 | 9 | var argv = require('optimist').demand('config').argv; 10 | var environment = argv.config; 11 | var nconf = require('nconf'); 12 | nconf.argv().env().file({ file: 'config.json' }); 13 | 14 | var cf_api_url = nconf.get(environment + "_" + 'CF_API_URL'), 15 | username = nconf.get(environment + "_" + 'username'), 16 | password = nconf.get(environment + "_" + 'password'); 17 | 18 | var CloudController = require("../../../../lib/model/cloudcontroller/CloudController"); 19 | var CloudFoundryUsersUAA = require("../../../../lib/model/uaa/UsersUAA"); 20 | var CloudFoundryApps = require("../../../../lib/model/cloudcontroller/Apps"); 21 | CloudController = new CloudController(); 22 | CloudFoundryUsersUAA = new CloudFoundryUsersUAA(); 23 | CloudFoundryApps = new CloudFoundryApps(); 24 | 25 | describe("Cloud Foundry Users UAA", function () { 26 | "use strict"; 27 | var authorization_endpoint = null; 28 | var token_endpoint = null; 29 | var token_type = null; 30 | var access_token = null; 31 | var refresh_token = null; 32 | 33 | before(function () { 34 | this.timeout(15000); 35 | 36 | CloudController.setEndPoint(cf_api_url); 37 | CloudFoundryApps.setEndPoint(cf_api_url); 38 | 39 | return CloudController.getInfo().then(function (result) { 40 | authorization_endpoint = result.authorization_endpoint; 41 | token_endpoint = result.token_endpoint; 42 | CloudFoundryUsersUAA.setEndPoint(authorization_endpoint); 43 | return CloudFoundryUsersUAA.login(username, password); 44 | }).then(function (result) { 45 | CloudFoundryApps.setToken(result); 46 | CloudFoundryUsersUAA.setToken(result); 47 | }); 48 | 49 | }); 50 | 51 | function randomInt(low, high) { 52 | return Math.floor(Math.random() * (high - low) + low); 53 | } 54 | 55 | function sleep(time, callback) { 56 | var stop = new Date().getTime(); 57 | while (new Date().getTime() < stop + time) { 58 | ; 59 | } 60 | callback(); 61 | } 62 | 63 | it("Using an unique Login, it is possible to execute several REST operations", function () { 64 | this.timeout(15000); 65 | 66 | return CloudFoundryApps.getApps().then(function () { 67 | return CloudFoundryApps.getApps(); 68 | }).then(function () { 69 | return CloudFoundryApps.getApps(); 70 | }).then(function () { 71 | return CloudFoundryApps.getApps(); 72 | }).then(function () { 73 | expect(true).to.equal(true); 74 | }); 75 | }); 76 | 77 | it("Use a refresh token to renew Oauth token", function () { 78 | this.timeout(25000); 79 | 80 | var token_type_test = null; 81 | var access_token_test = null; 82 | var refresh_token_test = null; 83 | 84 | return CloudFoundryUsersUAA.login(username, password).then(function (result) { 85 | CloudFoundryUsersUAA.setToken(result); 86 | sleep(5000, function () { 87 | console.log("5 second"); 88 | }); 89 | return CloudFoundryUsersUAA.refreshToken(); 90 | }).then(function (result) { 91 | CloudFoundryUsersUAA.setToken(result); 92 | CloudFoundryApps.setToken(result); 93 | return CloudFoundryApps.getApps(); 94 | }).then(function (result) { 95 | return CloudFoundryUsersUAA.refreshToken(); 96 | }).then(function (result) { 97 | CloudFoundryUsersUAA.setToken(result); 98 | CloudFoundryApps.setToken(result); 99 | return CloudFoundryApps.getApps(); 100 | }).then(function (result) { 101 | expect(result.resources).to.be.a('array'); 102 | }); 103 | }); 104 | 105 | //Testing users doesn't have permissions 106 | if(environment === "LOCAL_INSTANCE_1") { 107 | 108 | it.skip("The platform creates an User", function () { 109 | this.timeout(5000); 110 | 111 | var accountName = "user" + randomInt(1, 1000); 112 | var accountPassword = "123456"; 113 | var uaa_options = { 114 | schemas:["urn:scim:schemas:core:1.0"], 115 | userName:accountName, 116 | emails:[ 117 | { 118 | value:"demo@example.com", 119 | type:"work" 120 | } 121 | ], 122 | password: accountPassword, 123 | } 124 | 125 | return CloudFoundryUsersUAA.add(token_type, access_token, uaa_options).then(function (result) { 126 | //console.log(result) 127 | expect(true).to.be.a('boolean'); 128 | }); 129 | }); 130 | 131 | it("The platform retrieves Users from UAA", function () { 132 | this.timeout(5000); 133 | 134 | return CloudFoundryUsersUAA.getUsers(token_type, access_token).then(function (result) { 135 | expect(result.resources).to.be.a('array'); 136 | }); 137 | }); 138 | 139 | it.skip("The platform retrieves Users from UAA with a filter", function () { 140 | this.timeout(5000); 141 | 142 | var uaa_guid = null; 143 | var searchOptions = "?filter=userName eq 'demo4'"; 144 | 145 | return CloudFoundryUsersUAA.getUsers(token_type, access_token, searchOptions).then(function (result) { 146 | //console.log(result.resources[0].groups) 147 | //console.log(result.resources[0]) 148 | uaa_guid = result.resources[0].id; 149 | console.log(uaa_guid) 150 | expect(result.resources).to.be.a('array'); 151 | }); 152 | }); 153 | 154 | it("The platform creates & remove an User", function () { 155 | this.timeout(5000); 156 | 157 | var accountName = "user" + randomInt(1, 1000); 158 | var accountPassword = "123456"; 159 | var uaa_guid = null; 160 | var uaa_options = { 161 | "schemas":["urn:scim:schemas:core:1.0"], 162 | "userName":accountName, 163 | "emails":[ 164 | { 165 | "value":"demo@example.com", 166 | "type":"work" 167 | } 168 | ], 169 | "password": accountPassword, 170 | }; 171 | var searchOptions = "?filter=userName eq '" + accountName + "'"; 172 | 173 | return CloudFoundryUsersUAA.add(uaa_options).then(function (result) { 174 | return CloudFoundryUsersUAA.getUsers(searchOptions); 175 | }).then(function (result) { 176 | if(result.resources.length !== 1){ 177 | return new Promise(function (resolve, reject) { 178 | return reject("No Users"); 179 | }); 180 | } 181 | uaa_guid = result.resources[0].id; 182 | return CloudFoundryUsersUAA.remove(uaa_guid); 183 | }).then(function (result) { 184 | return CloudFoundryUsersUAA.getUsers(searchOptions); 185 | }).then(function (result) { 186 | if(result.resources.length !== 0){ 187 | return new Promise(function (resolve, reject) { 188 | return reject("Rare output"); 189 | }); 190 | } 191 | expect(true).to.be.a('boolean'); 192 | }); 193 | }); 194 | 195 | it.skip("[DEBUGGING] The platform creates, update Password & remove an User", function () { 196 | this.timeout(5000); 197 | 198 | var accountName = "user" + randomInt(1, 1000); 199 | var accountPassword = "123456"; 200 | var uaa_guid = null; 201 | var user_id = null; 202 | var uaa_options = { 203 | schemas: ["urn:scim:schemas:core:1.0"], 204 | userName: accountName, 205 | name: { 206 | formatted: accountName, 207 | familyName: accountName, 208 | givenName: accountName 209 | }, 210 | emails: [ 211 | { 212 | "value":"user@example.com", 213 | "type":"work" 214 | } 215 | ], 216 | password: accountPassword, 217 | }; 218 | var searchOptions = "?filter=userName eq '" + accountName + "'"; 219 | 220 | return CloudFoundryUsersUAA.add(token_type, access_token, uaa_options).then(function (result) { 221 | console.log(result); 222 | user_id = result.id; 223 | return CloudFoundryUsersUAA.getUsers(token_type, access_token, searchOptions); 224 | }).then(function (result) { 225 | if(result.resources.length !== 1){ 226 | return new Promise(function (resolve, reject) { 227 | return reject("No Users"); 228 | }); 229 | } 230 | uaa_guid = result.resources[0].id; 231 | }).then(function (result) { 232 | return CloudFoundryUsersUAA.login(accountName, accountPassword); 233 | }).then(function (result) { 234 | var newuser_token_type = result.token_type; 235 | var newuser_access_token = result.access_token; 236 | uaa_options = { 237 | schemas: ["urn:scim:schemas:core:1.0"], 238 | password: accountPassword, 239 | oldPassword: accountPassword 240 | }; 241 | return CloudFoundryUsersUAA.updatePassword(newuser_token_type, newuser_access_token, user_id, uaa_options); 242 | }).then(function (result) { 243 | console.log(result); 244 | return CloudFoundryUsersUAA.remove(token_type, access_token, uaa_guid); 245 | }).then(function (result) { 246 | return CloudFoundryUsersUAA.getUsers(token_type, access_token, searchOptions); 247 | }).then(function (result) { 248 | if(result.resources.length !== 0){ 249 | return new Promise(function (resolve, reject) { 250 | return reject("Rare output"); 251 | }); 252 | } 253 | expect(true).to.be.a('boolean'); 254 | }).catch(function (reason) { 255 | console.log(reason); 256 | expect(true).to.equal(true); 257 | }); 258 | }); 259 | 260 | } 261 | 262 | }); 263 | -------------------------------------------------------------------------------- /test/mocha.opts: -------------------------------------------------------------------------------- 1 | --colors 2 | --recursive 3 | --ui bdd -------------------------------------------------------------------------------- /test/utils/HttpUtilsTests.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true*/ 2 | /*global describe: true, it: true*/ 3 | "use strict"; 4 | 5 | var chai = require("chai"), 6 | expect = require("chai").expect; 7 | 8 | const request = require("request"); 9 | var HttpUtils = require('../../lib/utils/HttpUtils'); 10 | HttpUtils = new HttpUtils(); 11 | 12 | describe("HttpUtils", function () { 13 | 14 | it("HTML 200 Test", function () { 15 | this.timeout(15000); 16 | 17 | var url = "https://api.run.pivotal.io/v2/info"; 18 | var options = { 19 | method: 'GET', 20 | url: url 21 | }; 22 | 23 | return HttpUtils.request(options, 200, false).then(function (result) { 24 | expect(result).is.a("string"); 25 | }); 26 | }); 27 | 28 | it("System requires JSON, but the response is a String", function () { 29 | this.timeout(15000); 30 | 31 | var url = "https://api3.run.pivotal.io/v2/info"; 32 | var options = { 33 | method: 'GET', 34 | url: url 35 | }; 36 | 37 | return HttpUtils.request(options, 200, true).then(function (result) { 38 | expect(result).is.a("string"); 39 | }).catch(function (reason) { 40 | console.log(reason); 41 | expect(true).is.a("boolean"); 42 | }); 43 | }); 44 | 45 | it("HTML 404 Test", function () { 46 | this.timeout(15000); 47 | 48 | var url = "https://api.run.pivotal.io/v22/info"; 49 | var options = { 50 | method: 'GET', 51 | url: url 52 | }; 53 | 54 | return HttpUtils.request(options, 404, false).then(function (result) { 55 | expect(result).is.a("string"); 56 | }); 57 | }); 58 | 59 | it("Set request defaults", function () { 60 | this.timeout(15000); 61 | 62 | var url = "https://api.run.pivotal.io/v22/info"; 63 | var options = { 64 | method: 'GET', 65 | url: url 66 | }; 67 | 68 | //process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; 69 | const requestWithDefaults = request.defaults({ 70 | rejectUnauthorized: false 71 | }); 72 | 73 | HttpUtils.setCustomRequestObject(requestWithDefaults); 74 | return HttpUtils.request(options, 404, false).then(function (result) { 75 | expect(result).is.a("string"); 76 | }); 77 | }); 78 | 79 | it.skip("Set a bad defaults request", function () { 80 | this.timeout(15000); 81 | 82 | var url = "https://api.run.pivotal.io/v22/info"; 83 | var options = { 84 | method: 'GET', 85 | url: url 86 | }; 87 | 88 | const badRequestConfiguration = request.defaults({ 89 | proxy: 'http://localproxy.com' 90 | }); 91 | 92 | HttpUtils.setCustomRequestObject(badRequestConfiguration); 93 | return HttpUtils.request(options, 404, false).then(function (result) { 94 | expect(result).is.a("string"); 95 | }); 96 | }); 97 | 98 | }); -------------------------------------------------------------------------------- /test/utils/ZipGenerator.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true*/ 2 | /*globals Promise:true*/ 3 | "use strict"; 4 | 5 | var fs = require('fs'); 6 | var archiver = require('archiver'); 7 | 8 | function ZipGenerator() { 9 | return undefined; 10 | } 11 | 12 | ZipGenerator.prototype.generateDummyFile = function (weight) { 13 | 14 | //console.log("Creating a dummy " + weight + "MB file"); 15 | 16 | var seed = "1234567890123456789\n"; 17 | var content = ""; 18 | var oneK = 52; 19 | var oneMB = 1024; 20 | var iterations = oneK * oneMB * weight; 21 | var i = 0; 22 | for (i = 0; i < iterations; i++) { 23 | content += seed; 24 | } 25 | 26 | return content; 27 | }; 28 | 29 | /** 30 | * https://github.com/archiverjs/node-archiver 31 | * 32 | * @param {[type]} zipName [description] 33 | * @return {[type]} [description] 34 | */ 35 | ZipGenerator.prototype.generate = function (zipName, weight, compressionRate) { 36 | 37 | var HTMLContent = "
This is title

Hello world

"; 38 | 39 | var self = this; 40 | 41 | return new Promise(function (resolve) { 42 | 43 | var output = fs.createWriteStream(zipName); 44 | var archive = archiver('zip', { zlib: { level: compressionRate } }); 45 | archive.append(HTMLContent, { name : 'index.html' }); 46 | 47 | if (weight > 0) { 48 | archive.append(self.generateDummyFile(weight), { name : 'dummy.txt' }); 49 | } 50 | 51 | archive.pipe(output); 52 | archive.finalize(); 53 | 54 | output.on('close', function () { 55 | //console.log(zipName + " : " + ((archive.pointer()/1024)/1024).toFixed(2) + 'MB'); 56 | return resolve(); 57 | }); 58 | 59 | }); 60 | 61 | }; 62 | 63 | ZipGenerator.prototype.remove = function (zipName) { 64 | 65 | return new Promise(function (resolve, reject) { 66 | fs.unlink(zipName, function (error) { 67 | if (error) { 68 | return reject(error); 69 | } 70 | return resolve(); 71 | }); 72 | }); 73 | }; 74 | 75 | 76 | module.exports = ZipGenerator; 77 | -------------------------------------------------------------------------------- /test/utils/ZipGeneratorTests.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true*/ 2 | /*global describe: true, it: true*/ 3 | "use strict"; 4 | 5 | var chai = require("chai"), 6 | expect = require("chai").expect; 7 | var fs = require('fs'); 8 | 9 | var ZipGenerator = require('./ZipGenerator'); 10 | ZipGenerator = new ZipGenerator(); 11 | 12 | describe("Zip Generator", function () { 13 | 14 | it("Generates a zip", function () { 15 | 16 | var zipName = "staticApp.zip"; 17 | 18 | return ZipGenerator.generate(zipName, 1, 0).then(function () { 19 | fs.exists(zipName, function (result) { 20 | expect(result).be.equal(true); 21 | }); 22 | return ZipGenerator.remove(zipName); 23 | }).then(function () { 24 | fs.exists(zipName, function (result) { 25 | expect(result).be.equal(false); 26 | }); 27 | }); 28 | 29 | }); 30 | 31 | it.skip("[TOOL] Generates a large zip", function () { 32 | 33 | var zipName = "staticAppLarge.zip"; 34 | 35 | return ZipGenerator.generate(zipName, 100, 0).then(function () { 36 | fs.exists(zipName, function (result) { 37 | expect(result).be.equal(true); 38 | }); 39 | }); 40 | 41 | }); 42 | }); -------------------------------------------------------------------------------- /test_resources/SpringMVC_v3_AppExample.war: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM-Cloud/cf-nodejs-client/aea779218f2a1663cfc597db61316f637a429562/test_resources/SpringMVC_v3_AppExample.war -------------------------------------------------------------------------------- /test_resources/SpringMVC_v4_AppExample.war: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM-Cloud/cf-nodejs-client/aea779218f2a1663cfc597db61316f637a429562/test_resources/SpringMVC_v4_AppExample.war --------------------------------------------------------------------------------