├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── index.js ├── lib ├── apps.js ├── auth.js ├── builds.js ├── commons.js ├── config.js ├── domains.js ├── keys.js ├── limits.js ├── perms.js ├── ps.js ├── releases.js ├── tags.js └── utils.js ├── npm-shrinkwrap.json ├── package.json └── test ├── apps_test.js ├── auth_test.js ├── config_tag_perms_test.js ├── domain_test.js ├── keys_test.js ├── limits_test.js ├── login_test.js ├── logout_test.js ├── mocha.opts ├── ps_test.js └── releases_test.js /.gitignore: -------------------------------------------------------------------------------- 1 | lib-cov 2 | coverage 3 | reports 4 | node_modules 5 | .DS_Store -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 ©aledbf 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | TESTS = $(shell find test -name "*_test.js") 2 | 3 | test: 4 | @NODE_ENV=test ./node_modules/mocha/bin/mocha $(TESTS) 5 | 6 | coverage: 7 | istanbul instrument --output lib-cov --no-compact --variable global.__coverage__ lib 8 | @COVER=1 ./node_modules/mocha/bin/mocha --reporter mocha-istanbul $(TESTS) 9 | 10 | .PHONY: test coverage 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | deis-api 2 | ======== 3 | 4 | Wrapper for deis.io API 5 | 6 | `npm install deis-api --save` 7 | 8 | ```js 9 | var DeisAPI = require('./index'); 10 | 11 | var client = new DeisAPI({ 12 | controller : 'deis.local3.deisapp.com', 13 | secure : true, // Optional 14 | version : 1, // Optional 15 | username : 'deis', 16 | password : 'qwerty' 17 | }); 18 | ``` 19 | 20 | The properties that aren't marked optional will throw an error if they are missing. 21 | 22 | **This module is compatible with deis workflow (deis V2)** 23 | 24 | *Tests* 25 | 26 | To run the test the suite required a running deis cluster. It will use `deis.local3.deisapp.com` as URL. 27 | 28 | Run `npm test` or `make test` 29 | 30 | 31 | 32 | ## License 33 | 34 | (The MIT License) 35 | 36 | Copyright (c) 2015 Manuel Alejandro de Brito fontes <aledbf@gmail.com> 37 | 38 | Permission is hereby granted, free of charge, to any person obtaining a copy 39 | of this software and associated documentation files (the "Software"), to deal 40 | in the Software without restriction, including without limitation the rights 41 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 42 | copies of the Software, and to permit persons to whom the Software is 43 | furnished to do so, subject to the following conditions: 44 | 45 | The above copyright notice and this permission notice shall be included in all 46 | copies or substantial portions of the Software. 47 | 48 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 49 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 50 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 51 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 52 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 53 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 54 | SOFTWARE. 55 | 56 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var request = require('request-json-light'); 2 | var format = require('util').format; 3 | 4 | module.exports = function Deis(configuration) { 5 | var deis = this; 6 | 7 | deis._authenticated = false; 8 | 9 | // Check for configuration. 10 | if (!configuration) { 11 | throw new ReferenceError('Deis API require a configuration'); 12 | } 13 | 14 | // Check we got required config properties. 15 | if (!configuration.hasOwnProperty('controller')) { 16 | throw ReferenceError('Deis API configuration requires controller property.'); 17 | } 18 | 19 | if (!configuration.hasOwnProperty('username')) { 20 | throw ReferenceError('Deis API configuration requires username property'); 21 | } 22 | 23 | if (!configuration.hasOwnProperty('password')) { 24 | throw ReferenceError('Deis API configuration requires password property'); 25 | } 26 | 27 | deis.protocol = configuration.secure ? 'https' : 'http'; 28 | 29 | deis.controller = configuration.controller; 30 | 31 | deis.version = configuration.version ? 'v' + configuration.version : 'v1'; 32 | 33 | deis.client = request.newClient(format('%s://%s', deis.protocol, deis.controller)); 34 | 35 | Object.defineProperty(deis, 'username', { 36 | get: function() { return configuration.username; }, 37 | configurable: false 38 | }); 39 | 40 | Object.defineProperty(deis, 'password', { 41 | get: function() { return configuration.password; }, 42 | configurable: false 43 | }); 44 | 45 | // public interface 46 | deis.api = { 47 | apps: require('./lib/apps')(deis), 48 | auth: require('./lib/auth')(deis), 49 | builds: require('./lib/builds')(deis), 50 | config: require('./lib/config')(deis), 51 | domains: require('./lib/domains')(deis), 52 | keys: require('./lib/keys')(deis), 53 | limits: require('./lib/limits')(deis), 54 | perms: require('./lib/perms')(deis), 55 | ps: require('./lib/ps')(deis), 56 | releases: require('./lib/releases')(deis), 57 | tags: require('./lib/tags')(deis) 58 | }; 59 | 60 | // mimic the deis cli shortcuts. 61 | deis.api.create = deis.api.apps.create; 62 | deis.api.destroy = deis.api.apps.destroy; 63 | deis.api.info = deis.api.apps.info; 64 | deis.api.login = deis.api.auth.login; 65 | deis.api.logout = deis.api.auth.logout; 66 | deis.api.logs = deis.api.apps.logs; 67 | deis.api.open = deis.api.apps.open; 68 | deis.api.passwd = deis.api.auth.passwd; 69 | deis.api.changeUserPassword = deis.api.auth.changeUserPassword; 70 | deis.api.pull = deis.api.builds.create; 71 | deis.api.register = deis.api.auth.register; 72 | deis.api.registerNewUser = deis.api.auth.registerNewUser; 73 | deis.api.rollback = deis.api.releases.rollback; 74 | deis.api.run = deis.api.apps.run; 75 | deis.api.scale = deis.api.ps.scale; 76 | deis.api.sharing = deis.api.perms.list; 77 | deis.api.whoami = deis.api.auth.whoami; 78 | 79 | deis.api.username = deis.username; 80 | deis.api.password = deis.password; 81 | deis.api.authenticated = deis.authenticated; 82 | 83 | return this.api; 84 | }; 85 | -------------------------------------------------------------------------------- /lib/apps.js: -------------------------------------------------------------------------------- 1 | var format = require('util').format, 2 | isFunction = require('./utils').isFunction; 3 | 4 | module.exports = function apps(deis) { 5 | 6 | var commons = require('./commons')(deis); 7 | 8 | /** 9 | * Create a new application 10 | */ 11 | function create(appName, callback) { 12 | commons.post(format('/%s/apps/', deis.version), { 13 | id: appName 14 | }, callback); 15 | } 16 | 17 | /** 18 | * List accessible applications 19 | */ 20 | function list(pageSize, callback) { 21 | var limit = 100; 22 | if (!isFunction(pageSize)) { 23 | limit = pageSize; 24 | }else { 25 | callback = pageSize; 26 | } 27 | commons.get(format('/%s/apps?limit=%s', deis.version, limit), callback); 28 | } 29 | 30 | /** 31 | * View info about an application 32 | */ 33 | function info(appName, callback) { 34 | commons.get(format('/%s/apps/%s/', deis.version, appName), callback); 35 | } 36 | 37 | /** 38 | * View aggregated application logs 39 | */ 40 | function logs(appName, callback) { 41 | commons.get(format('/%s/apps/%s/logs/', deis.version, appName), callback); 42 | } 43 | 44 | /** 45 | * Run a command in an ephemeral app container 46 | */ 47 | function run(appName, command, callback) { 48 | commons.get(format('/%s/apps/%s/run/', deis.version, appName), callback); 49 | } 50 | 51 | /** 52 | * Destroy an application 53 | */ 54 | function destroy(appName, callback) { 55 | commons.del(format('/%s/apps/%s/', deis.version, appName), callback); 56 | } 57 | 58 | function open(appName, callback) { 59 | return callback(new Error('deis open is useless in an API context.')); 60 | } 61 | 62 | return { 63 | create: create, 64 | list: list, 65 | info: info, 66 | logs: logs, 67 | open: open, 68 | run: run, 69 | destroy: destroy 70 | }; 71 | }; 72 | -------------------------------------------------------------------------------- /lib/auth.js: -------------------------------------------------------------------------------- 1 | var request = require('request-json-light'), 2 | format = require('util').format; 3 | 4 | module.exports = function auth(deis) { 5 | 6 | var commons = require('./commons')(deis); 7 | 8 | /** 9 | * remove the account currently logged 10 | */ 11 | function cancel(callback) { 12 | if (!deis._authenticated) { 13 | return callback(new Error('You need to login first')); 14 | } 15 | 16 | commons.del(format('/%s/auth/cancel/', deis.version), function() { 17 | deis.api.logout(callback); 18 | }); 19 | } 20 | 21 | function login(callback) { 22 | if (deis._authenticated) { 23 | return callback(new Error('Already logged in')); 24 | } 25 | 26 | deis.client.post(format('/%s/auth/login/', deis.version), { 27 | username: deis.username, 28 | password: deis.password 29 | }, function(err, response, body) { 30 | if (err) { 31 | deis._authenticated = false; 32 | return callback(err); 33 | } 34 | 35 | if (!body.token) { 36 | deis._authenticated = false; 37 | return callback(Error('Incorrect Deis login details')); 38 | } 39 | 40 | deis.client = request.newClient(format('%s://%s', deis.protocol, deis.controller), { 41 | headers: { 42 | Authorization: format('token %s', body.token) 43 | } 44 | }); 45 | 46 | deis._authenticated = true; 47 | 48 | callback(null); 49 | }); 50 | } 51 | 52 | function logout(callback) { 53 | deis.client = request.newClient(format('%s://%s', deis.protocol, deis.controller), { 54 | }); 55 | 56 | deis._authenticated = false; 57 | callback(null); 58 | } 59 | 60 | /** 61 | * change password 62 | * @param {String} oldPassword current password 63 | * @param {String} newPassword new password 64 | */ 65 | function passwd(oldPassword, newPassword, callback) { 66 | if (!deis._authenticated) { 67 | return callback(new Error('You need to login first')); 68 | } 69 | 70 | deis.client.post(format('/%s/auth/passwd', deis.version), { 71 | password: oldPassword, 72 | new_password: newPassword 73 | }, function(err, res, body) { 74 | if (err) { 75 | return callback(err); 76 | } 77 | 78 | if (res.statusCode === 200) { 79 | return callback(null); 80 | } 81 | 82 | return callback(new Error('Password change failed: ' + body.detail)); 83 | }); 84 | } 85 | 86 | function changeUserPassword(username, oldPassword, newPassword, callback) { 87 | if (!deis._authenticated) { 88 | return callback(new Error('You need to login first')); 89 | } 90 | 91 | deis.client.post(format('/%s/auth/passwd', deis.version), { 92 | username: username, 93 | password: oldPassword, 94 | new_password: newPassword 95 | }, function(err, res, body) { 96 | if (err) { 97 | return callback(err); 98 | } 99 | 100 | if (res.statusCode === 200) { 101 | return callback(null); 102 | } 103 | 104 | return callback(new Error('Password change failed: ' + body.detail)); 105 | }); 106 | } 107 | 108 | function register(email, callback) { 109 | if (deis._authenticated) { 110 | return callback(new Error('Already logged in. You do not to register')); 111 | } 112 | 113 | commons.post(format('%s://%s/%s/auth/register', deis.protocol, deis.controller, deis.version), { 114 | username: deis.username, 115 | email: email, 116 | password: deis.password 117 | }, callback); 118 | } 119 | 120 | function registerNewUser(username, password, email, callback) { 121 | commons.post(format('%s://%s/%s/auth/register', deis.protocol, deis.controller, deis.version), { 122 | username: username, 123 | email: email, 124 | password: password 125 | }, callback); 126 | } 127 | 128 | function whoami() { 129 | return { message: format('You are %s at %s', deis.username, deis.controller) }; 130 | } 131 | 132 | return { 133 | cancel: cancel, 134 | login: login, 135 | logout: logout, 136 | register: register, 137 | registerNewUser: registerNewUser, 138 | passwd: passwd, 139 | changeUserPassword: changeUserPassword, 140 | whoami: whoami 141 | }; 142 | }; 143 | -------------------------------------------------------------------------------- /lib/builds.js: -------------------------------------------------------------------------------- 1 | var format = require('util').format; 2 | 3 | module.exports = function(deis) { 4 | 5 | var commons = require('./commons')(deis); 6 | 7 | function builds(appName, callback) { 8 | commons.get(format('/%s/apps/%s/builds/', deis.version, appName), callback); 9 | } 10 | 11 | function create(appName, image, callback) { 12 | commons.post(format('/%s/apps/%s/builds/', deis.version, appName), image, callback); 13 | } 14 | 15 | return { 16 | builds: builds, 17 | create: create 18 | }; 19 | }; 20 | -------------------------------------------------------------------------------- /lib/commons.js: -------------------------------------------------------------------------------- 1 | var request = require('request-json-light'), 2 | format = require('util').format, 3 | debug = require('debug')('deis:request'); 4 | 5 | 6 | /** 7 | * Check if the http response returns the expected http code 8 | * and return an error with the detail if the check fails 9 | * @param {Number} expected http 10 | * @param {Response} res 11 | * @param {Object} body 12 | * @param {Function} callback 13 | */ 14 | function checkHttpCode(expected, res, body, callback) { 15 | if (res.statusCode !== expected) { 16 | if (!body) { 17 | return callback(new Error(format('Unexpected deis response (expected %s but %s was returned)', expected, res.statusCode))); 18 | } 19 | 20 | var error = body.hasOwnProperty('detail') ? 21 | body.detail : JSON.stringify(body); 22 | 23 | return callback(new Error(error)); 24 | } 25 | 26 | return callback(null, body); 27 | } 28 | 29 | module.exports = function commons(deis) { 30 | 31 | function get(url, callback) { 32 | debug(format('get url: %s', url)); 33 | deis.client.get(url, function(err, res, body) { 34 | if (err) { 35 | return callback(err); 36 | } 37 | 38 | checkHttpCode(200, res, body, callback); 39 | }); 40 | } 41 | 42 | function post(url, body, returnCode, callback) { 43 | if (typeof callback === 'undefined') { 44 | callback = returnCode; 45 | returnCode = 201; 46 | } 47 | 48 | debug(format('post url: %s, body: %j', url, body)); 49 | deis.client.post(url, body, function(err, res, body) { 50 | if (err) { 51 | return callback(err); 52 | } 53 | 54 | checkHttpCode(returnCode, res, body, callback); 55 | }); 56 | } 57 | 58 | function del(url, callback) { 59 | debug(format('del url: %s', url)); 60 | deis.client.del(url, function(err, res, body) { 61 | if (err) { 62 | return callback(err); 63 | } 64 | 65 | checkHttpCode(204, res, body, callback); 66 | }); 67 | } 68 | 69 | return { 70 | get: get, 71 | post: post, 72 | del: del 73 | }; 74 | }; 75 | -------------------------------------------------------------------------------- /lib/config.js: -------------------------------------------------------------------------------- 1 | var util = require('util'), 2 | isObject = require('./utils').isObject, 3 | format = util.format; 4 | 5 | module.exports = function config(deis) { 6 | 7 | var commons = require('./commons')(deis); 8 | 9 | /** 10 | * List environment variables for an app 11 | */ 12 | function list(appName, callback) { 13 | var uri = format('/%s/apps/%s/config/', deis.version, appName); 14 | commons.get(uri, function onListResponse(err, result) { 15 | callback(err, result ? result.values : null); 16 | }); 17 | } 18 | 19 | /** 20 | * Set environment variables for an application 21 | */ 22 | function set(appName, keyValues, keyLimits, callback) { 23 | var config = {}; 24 | 25 | if (!isObject(keyValues)) { 26 | return callback(new Error('To set a variable pass an object')); 27 | } 28 | 29 | config.values = keyValues; 30 | 31 | if (isObject(keyLimits)) { 32 | if (keyLimits.hasOwnProperty('memory')) { 33 | config.memory = keyLimits.memory; 34 | } 35 | if (keyLimits.hasOwnProperty('cpu')) { 36 | config.cpu = keyLimits.cpu; 37 | } 38 | } else { 39 | callback = keyLimits; 40 | } 41 | 42 | var uri = format('/%s/apps/%s/config/', deis.version, appName); 43 | commons.post(uri, config, function onSetResponse(err, result) { 44 | callback(err, result ? result.values : null); 45 | }); 46 | } 47 | 48 | /** 49 | * Unset environment variables for an app 50 | */ 51 | function unset(appName, variableNames, callback) { 52 | if (!util.isArray(variableNames)) { 53 | return callback(new Error('To unset a variable pass an array of names')); 54 | } 55 | 56 | var keyValues = {}; 57 | variableNames.forEach(function onUnsetResponse(variableName) { 58 | keyValues[variableName] = null; 59 | }); 60 | 61 | set(appName, keyValues, callback); 62 | } 63 | 64 | return{ 65 | list: list, 66 | set: set, 67 | unset: unset 68 | }; 69 | }; 70 | -------------------------------------------------------------------------------- /lib/domains.js: -------------------------------------------------------------------------------- 1 | var format = require('util').format; 2 | 3 | module.exports = function domains(deis) { 4 | 5 | var commons = require('./commons')(deis); 6 | 7 | /** 8 | * Add a domain to an app registered with the Deis controller. 9 | */ 10 | function add(appName, domain, callback) { 11 | commons.post(format('/%s/apps/%s/domains/', deis.version, appName), { 12 | domain: domain.toString() 13 | }, callback); 14 | } 15 | 16 | /** 17 | * Remove a domain registered on an application. 18 | */ 19 | function remove(appName, domain, callback) { 20 | var url = format('/%s/apps/%s/domains/%s', deis.version, appName, domain); 21 | commons.del(url, callback); 22 | } 23 | 24 | /** 25 | * Get all the domains for an application. 26 | */ 27 | function getAll(appName, callback) { 28 | var url = format('/%s/apps/%s/domains/', deis.version, appName); 29 | commons.get(endpoint, callback); 30 | } 31 | 32 | /** 33 | * Get a domain by it's name. 34 | */ 35 | function getDomain(domain, callback) { 36 | getAll(function onGetAll(err, domains) { 37 | if (err) { 38 | return callback(err); 39 | } 40 | 41 | callback(null, domains.results.filter(function onGetDomain(domain_obj) { 42 | return domain_obj.domain == domain; 43 | })[0]); 44 | }); 45 | } 46 | 47 | return { 48 | add: add, 49 | get: getDomain, 50 | getAll: getAll, 51 | remove: remove 52 | }; 53 | }; 54 | -------------------------------------------------------------------------------- /lib/keys.js: -------------------------------------------------------------------------------- 1 | var format = require('util').format, 2 | sshKeyparser = require('ssh2-streams/lib/keyParser'); 3 | 4 | module.exports = function keys(deis) { 5 | 6 | var commons = require('./commons')(deis); 7 | 8 | /** 9 | * list SSH keys for the logged in user 10 | */ 11 | function list(callback) { 12 | commons.get(format('/%s/keys/', deis.version), callback); 13 | } 14 | 15 | /** 16 | * add an SSH key 17 | */ 18 | function add(keyId, sshKey, callback) { 19 | try { 20 | sshKeyparser(sshKey); 21 | }catch (e) { 22 | return callback(e); 23 | } 24 | 25 | commons.post(format('/%s/keys/', deis.version), { 26 | id: keyId || deis.username, 27 | 'public': sshKey 28 | },callback); 29 | } 30 | 31 | /** 32 | * remove an SSH key 33 | */ 34 | function remove(keyId, callback) { 35 | commons.del(format('/%s/keys/%s', deis.version, keyId), callback); 36 | } 37 | 38 | return { 39 | list: list, 40 | add: add, 41 | remove: remove 42 | }; 43 | }; 44 | -------------------------------------------------------------------------------- /lib/limits.js: -------------------------------------------------------------------------------- 1 | var format = require('util').format, 2 | debug = require('debug')('deis:limits'), 3 | isObject = require('./utils').isObject; 4 | 5 | function ArgumentError(arg) { 6 | return new Error(format('Invalid or missing argument supplied: %s', arg)); 7 | } 8 | 9 | module.exports = function limits(deis) { 10 | 11 | var commons = require('./commons')(deis); 12 | 13 | function extractLimits(data) { 14 | debug(data); 15 | var result = {}; 16 | if (data.memory && Object.keys(data.memory).length > 0) { 17 | result.memory = data.memory; 18 | } 19 | 20 | if (data.cpu && Object.keys(data.cpu).length > 0) { 21 | result.cpu = data.cpu; 22 | } 23 | 24 | return result; 25 | } 26 | 27 | /** 28 | * list resource limits for an app 29 | */ 30 | function list(appName, callback) { 31 | if (!appName) { 32 | return callback(ArgumentError('appName')); 33 | } 34 | 35 | var uri = format('/%s/apps/%s/config/', deis.version, appName); 36 | commons.get(uri, function onListResponse(err, result) { 37 | console.log(result); 38 | callback(err, result ? extractLimits(result) : null); 39 | }); 40 | } 41 | 42 | /** 43 | * set resource limits for an app 44 | */ 45 | function set(appName, limits, callback) { 46 | if (!isObject(limits)) { 47 | return callback(new Error('To set a variable pass an object')); 48 | } 49 | 50 | var keyValues = {}; 51 | 52 | if (limits.hasOwnProperty('memory')) { 53 | keyValues.memory = limits.memory; 54 | } 55 | 56 | if (limits.hasOwnProperty('cpu')) { 57 | keyValues.cpu = limits.cpu; 58 | } 59 | 60 | if (Object.keys(keyValues).length === 0) { 61 | return callback(new Error('Only cpu and memory limits are valid')); 62 | } 63 | 64 | commons.post(format('/%s/apps/%s/config/', deis.version, appName), keyValues, 65 | function onSetResponse(err, result) { 66 | callback(err, result ? extractLimits(result) : null); 67 | }); 68 | } 69 | 70 | /** 71 | * unset resource limits for an app 72 | */ 73 | function unset(appName, limitType, procType, callback) { 74 | if (!appName) { 75 | return callback(ArgumentError('appName')); 76 | } 77 | 78 | if (!limitType) { 79 | return callback(ArgumentError('limitType')); 80 | } 81 | 82 | if (!procType) { 83 | return callback(ArgumentError('procType')); 84 | } 85 | 86 | var keyValues = {}; 87 | 88 | if (limitType === 'memory') { 89 | keyValues.memory = {}; 90 | keyValues.memory[procType] = null; 91 | } 92 | 93 | if (limitType === 'cpu') { 94 | keyValues.cpu = {}; 95 | keyValues.cpu[procType] = null; 96 | } 97 | 98 | commons.post(format('/%s/apps/%s/config/', deis.version, appName), keyValues, 99 | function onUnsetResponse(err, result) { 100 | console.log(result); 101 | callback(err, result ? extractLimits(result) : null); 102 | }); 103 | } 104 | 105 | return { 106 | list: list, 107 | set: set, 108 | unset: unset 109 | }; 110 | }; 111 | -------------------------------------------------------------------------------- /lib/perms.js: -------------------------------------------------------------------------------- 1 | var format = require('util').format; 2 | 3 | module.exports = function perms(deis) { 4 | 5 | var commons = require('./commons')(deis); 6 | 7 | /** 8 | * list permissions granted on an app 9 | */ 10 | function list(appName, callback) { 11 | commons.get(format('/%s/apps/%s/perms/', deis.version, appName), callback); 12 | } 13 | 14 | /** 15 | * create a new permission for a user 16 | */ 17 | function create(username, appName, callback) { 18 | commons.post(format('/%s/apps/%s/perms/', deis.version, appName), { 19 | username: username 20 | }, callback); 21 | } 22 | 23 | /** 24 | * delete a permission for a user 25 | */ 26 | function deletef() { 27 | 28 | } 29 | 30 | return { 31 | list: list, 32 | create: create, 33 | 'delete': deletef 34 | }; 35 | }; 36 | -------------------------------------------------------------------------------- /lib/ps.js: -------------------------------------------------------------------------------- 1 | var format = require('util').format, 2 | isObject = require('./utils').isObject; 3 | 4 | module.exports = function ps(deis) { 5 | 6 | var commons = require('./commons')(deis); 7 | 8 | /** 9 | * scale an application 10 | */ 11 | function scale(appName, configuration, callback) { 12 | if (!isObject(configuration)) { 13 | return callback(new Error('To scale pass an object with the type as key')); 14 | } 15 | 16 | var url = format('/%s/apps/%s/scale/', deis.version, appName); 17 | commons.post(url, configuration, 204, callback); 18 | } 19 | 20 | /** 21 | * list application containers and their status 22 | */ 23 | function list(appName, callback) { 24 | commons.get(format('/%s/apps/%s/containers/', deis.version, appName), callback); 25 | } 26 | 27 | /** 28 | * list application containers and their status 29 | */ 30 | function byType(appName, type, callback) { 31 | var url = format('/%s/apps/%s/containers/%s/', deis.version, appName, type); 32 | commons.get(url, callback); 33 | } 34 | 35 | return { 36 | list: list, 37 | byType: byType, 38 | scale: scale 39 | }; 40 | }; 41 | -------------------------------------------------------------------------------- /lib/releases.js: -------------------------------------------------------------------------------- 1 | var format = require('util').format; 2 | 3 | module.exports = function releases(deis) { 4 | 5 | var commons = require('./commons')(deis); 6 | 7 | function _releases(appName, callback) { 8 | commons.get(format('/%s/apps/%s/releases/', deis.version, appName), callback); 9 | } 10 | 11 | function detail(appName, release, callback) { 12 | commons.get(format('/%s/apps/%s/releases/v%s/', deis.version, appName, release), callback); 13 | } 14 | 15 | function rollback(appName, version, callback) { 16 | commons.post(format('/%s/apps/%s/releases/rollback/', deis.version, appName), { 17 | version: version 18 | },callback); 19 | } 20 | 21 | return { 22 | releases: _releases, 23 | detail: detail, 24 | rollback: rollback 25 | }; 26 | }; 27 | -------------------------------------------------------------------------------- /lib/tags.js: -------------------------------------------------------------------------------- 1 | var util = require('util'), 2 | isObject = require('./utils').isObject, 3 | format = util.format; 4 | 5 | module.exports = function tags(deis) { 6 | 7 | var commons = require('./commons')(deis); 8 | 9 | /** 10 | * list tags for an app 11 | */ 12 | function list(appName, callback) { 13 | var url = format('/%s/apps/%s/config/', deis.version, appName); 14 | commons.get(url, function onListResponse(err, result) { 15 | callback(err, result ? result.tags : null); 16 | }); 17 | } 18 | 19 | /** 20 | * set tags for an app 21 | */ 22 | function set(appName, tagValues, callback) { 23 | if (!isObject(tagValues)) { 24 | return callback(new Error('To set a variable pass an object')); 25 | } 26 | 27 | commons.post(format('/%s/apps/%s/config/', deis.version, appName), { 28 | tags: tagValues 29 | },function onSetResponse(err, result) { 30 | callback(err, result ? result.tags : null); 31 | }); 32 | } 33 | 34 | /** 35 | * unset tags for an app 36 | */ 37 | function unset(appName, tagNames, callback) { 38 | if (!util.isArray(tagNames)) { 39 | return callback(new Error('To unset a tag pass an array of names')); 40 | } 41 | 42 | var keyValues = {}; 43 | tagNames.forEach(function eachTag(tagName) { 44 | keyValues[tagName] = null; 45 | }); 46 | 47 | set(appName, keyValues, callback); 48 | } 49 | 50 | return { 51 | list: list, 52 | set: set, 53 | unset: unset 54 | }; 55 | }; 56 | -------------------------------------------------------------------------------- /lib/utils.js: -------------------------------------------------------------------------------- 1 | module.exports.isObject = function isObject(x) { 2 | return typeof x === 'object' && x !== null; 3 | }; 4 | 5 | module.exports.isFunction = function isFunction(x) { 6 | return typeof x === 'function' && x !== null; 7 | }; 8 | -------------------------------------------------------------------------------- /npm-shrinkwrap.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "deis-api", 3 | "version": "0.1.5", 4 | "dependencies": { 5 | "asn1": { 6 | "version": "0.2.3", 7 | "from": "asn1@>=0.2.0 <0.3.0", 8 | "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.3.tgz" 9 | }, 10 | "async": { 11 | "version": "1.5.2", 12 | "from": "async@>=1.5.2 <2.0.0", 13 | "resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz" 14 | }, 15 | "combined-stream": { 16 | "version": "1.0.5", 17 | "from": "combined-stream@>=1.0.5 <2.0.0", 18 | "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.5.tgz" 19 | }, 20 | "debug": { 21 | "version": "2.6.8", 22 | "from": "debug@2.6.8", 23 | "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.8.tgz" 24 | }, 25 | "delayed-stream": { 26 | "version": "1.0.0", 27 | "from": "delayed-stream@>=1.0.0 <1.1.0", 28 | "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz" 29 | }, 30 | "form-data": { 31 | "version": "1.0.0-rc4", 32 | "from": "form-data@1.0.0-rc4", 33 | "resolved": "https://registry.npmjs.org/form-data/-/form-data-1.0.0-rc4.tgz" 34 | }, 35 | "mime": { 36 | "version": "1.3.4", 37 | "from": "mime@1.3.4", 38 | "resolved": "https://registry.npmjs.org/mime/-/mime-1.3.4.tgz" 39 | }, 40 | "mime-db": { 41 | "version": "1.27.0", 42 | "from": "mime-db@>=1.27.0 <1.28.0", 43 | "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.27.0.tgz" 44 | }, 45 | "mime-types": { 46 | "version": "2.1.15", 47 | "from": "mime-types@>=2.1.10 <3.0.0", 48 | "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.15.tgz" 49 | }, 50 | "ms": { 51 | "version": "2.0.0", 52 | "from": "ms@2.0.0", 53 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz" 54 | }, 55 | "request-json-light": { 56 | "version": "0.5.25", 57 | "from": "request-json-light@0.5.25", 58 | "resolved": "https://registry.npmjs.org/request-json-light/-/request-json-light-0.5.25.tgz" 59 | }, 60 | "semver": { 61 | "version": "5.3.0", 62 | "from": "semver@>=5.1.0 <6.0.0", 63 | "resolved": "https://registry.npmjs.org/semver/-/semver-5.3.0.tgz" 64 | }, 65 | "ssh2-streams": { 66 | "version": "0.1.18", 67 | "from": "ssh2-streams@0.1.18", 68 | "resolved": "https://registry.npmjs.org/ssh2-streams/-/ssh2-streams-0.1.18.tgz" 69 | }, 70 | "streamsearch": { 71 | "version": "0.1.2", 72 | "from": "streamsearch@>=0.1.2 <0.2.0", 73 | "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-0.1.2.tgz" 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "deis-api", 3 | "version": "0.1.5", 4 | "description": "Wrapper for deis.io API", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/aledbf/deis-api.git" 8 | }, 9 | "keywords": [ 10 | "deis", 11 | "paas" 12 | ], 13 | "author": "Manuel Alejandro de Brito Fontes ", 14 | "license": "MIT", 15 | "bugs": { 16 | "url": "https://github.com/aledbf/deis-api.git/issues" 17 | }, 18 | "homepage": "https://github.com/aledbf/deis-api.git", 19 | "dependencies": { 20 | "debug": "2.6.8", 21 | "request-json-light": "0.5.25", 22 | "ssh2-streams": "0.1.18" 23 | }, 24 | "devDependencies": { 25 | "expect.js": "0.3.1", 26 | "mocha": "3.4.2" 27 | }, 28 | "main": "index.js", 29 | "scripts": { 30 | "test": "make test" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /test/apps_test.js: -------------------------------------------------------------------------------- 1 | var expect = require('expect.js'), 2 | DeisApi = require('../'); 3 | 4 | var APP_NAME = 'app-config-test'; 5 | 6 | describe('apps suite', function() { 7 | 8 | var deis = new DeisApi({ 9 | controller: 'deis.local3.deisapp.com', 10 | username: 'test', 11 | password: 'opensesame' 12 | }); 13 | 14 | before(function(done) { 15 | deis.login(function(err) { 16 | deis.auth.cancel(function(err) { 17 | deis.register('deis@deis.io', function(err, user) { 18 | deis.login(function(err) { 19 | deis.apps.destroy(APP_NAME, function(err) { 20 | done(); 21 | }); 22 | }); 23 | }); 24 | }); 25 | }); 26 | }); 27 | 28 | it('should list the apps (0)', function(done) { 29 | deis.apps.list(function(err, apps) { 30 | expect(err).to.be(null); 31 | expect(apps.count).to.be.eql(0); 32 | done(); 33 | }); 34 | }); 35 | 36 | it('should create an app ', function(done) { 37 | deis.apps.create('app-config-test', function(err, app) { 38 | expect(err).to.be(null); 39 | expect(app).to.be.a(Object); 40 | done(); 41 | }); 42 | }); 43 | 44 | it('should list the apps (1)', function(done) { 45 | deis.apps.list(function(err, apps) { 46 | expect(err).to.be(null); 47 | expect(apps.count).to.be.eql(1); 48 | done(); 49 | }); 50 | }); 51 | 52 | it('should return the info of an app', function(done) { 53 | deis.apps.list(function(err, apps) { 54 | expect(err).to.be(null); 55 | expect(apps.count).to.be.eql(1); 56 | done(); 57 | }); 58 | }); 59 | 60 | it('should return the logs of an app', function(done) { 61 | deis.apps.list(function(err, apps) { 62 | expect(err).to.be(null); 63 | expect(apps.count).to.be.eql(1); 64 | done(); 65 | }); }); 66 | 67 | it('should run the command echo in one app', function(done) { 68 | deis.apps.list(function(err, apps) { 69 | expect(err).to.be(null); 70 | expect(apps.count).to.be.eql(1); 71 | done(); 72 | }); 73 | }); 74 | 75 | it('should destroy the new app', function(done) { 76 | deis.apps.destroy('app-config-test', function(err) { 77 | expect(err).to.be(null); 78 | done(); 79 | }); 80 | }); 81 | }); 82 | -------------------------------------------------------------------------------- /test/auth_test.js: -------------------------------------------------------------------------------- 1 | var expect = require('expect.js'), 2 | DeisApi = require('../'); 3 | 4 | function removeAccount(deis, callback) { 5 | deis.login(function(err) { 6 | deis.auth.cancel(callback); 7 | }); 8 | } 9 | 10 | function registerAndLogin(deis, callback) { 11 | deis.register('deis@deis.io', function(err, user) { 12 | expect(err).to.be(null); 13 | deis.login(callback); 14 | }); 15 | } 16 | 17 | describe('auth suite', function() { 18 | it('should register just as user', function(done) { 19 | var deis = new DeisApi({ 20 | controller: 'deis.local3.deisapp.com', 21 | username: 'test', 22 | password: 'opensesame' 23 | }); 24 | 25 | removeAccount(deis, function(err) { 26 | expect(err).to.be(null); 27 | deis.register('deis@deis.io', function(err, user) { 28 | expect(err).to.be(null); 29 | expect(user).to.be.a(Object); 30 | expect(user.is_active).to.be.eql(true); 31 | done(); 32 | }); 33 | }); 34 | }); 35 | 36 | it('should login', function(done) { 37 | var deis = new DeisApi({ 38 | controller: 'deis.local3.deisapp.com', 39 | username: 'test', 40 | password: 'opensesame' 41 | }); 42 | 43 | deis.login(function(err) { 44 | expect(err).to.be(null); 45 | done(); 46 | }); 47 | }); 48 | 49 | it('should return whoami info', function(done) { 50 | var deis = new DeisApi({ 51 | controller: 'deis.local3.deisapp.com', 52 | username: 'test', 53 | password: 'opensesame' 54 | }); 55 | 56 | var whoami = deis.whoami(); 57 | expect(whoami).to.be.a('object'); 58 | expect(whoami).to.be.eql({ message: 'You are test at deis.local3.deisapp.com' }); 59 | done(); 60 | }); 61 | 62 | it('should allow the password change', function(done) { 63 | var deis = new DeisApi({ 64 | controller: 'deis.local3.deisapp.com', 65 | username: 'super', 66 | password: 'user' 67 | }); 68 | 69 | deis.login(function(err) { 70 | deis.auth.cancel(function(err) { 71 | deis.register('deis@deis.io', function(err, user) { 72 | expect(err).to.be(null); 73 | deis.login(function(err) { 74 | deis.auth.passwd('user', 'newuser', function(err) { 75 | expect(err).to.be(null); 76 | deis = new DeisApi({ 77 | controller: 'deis.local3.deisapp.com', 78 | username: 'super', 79 | password: 'newuser' 80 | }); 81 | 82 | deis.login(function(err) { 83 | expect(err).to.be(null); 84 | deis.auth.cancel(function(err) { 85 | done(err); 86 | }); 87 | }); 88 | }); 89 | }); 90 | }); 91 | }); 92 | }); 93 | }); 94 | 95 | it('should fail to login with an invalid account', function(done) { 96 | var deis = new DeisApi({ 97 | controller: 'deis.local3.deisapp.com', 98 | username: 'invalid-user', 99 | password: 'password' 100 | }); 101 | 102 | deis.login(function(err) { 103 | expect(err).to.be.a(Error); 104 | done(); 105 | }); 106 | }); 107 | 108 | }); 109 | -------------------------------------------------------------------------------- /test/config_tag_perms_test.js: -------------------------------------------------------------------------------- 1 | var expect = require('expect.js'), 2 | DeisApi = require('../'); 3 | 4 | var APP_NAME = 'app-config-test'; 5 | 6 | describe('app config, tags and perms suite', function() { 7 | 8 | var deis = new DeisApi({ 9 | controller: 'deis.local3.deisapp.com', 10 | username: 'test', 11 | password: 'opensesame' 12 | }); 13 | 14 | before(function(done) { 15 | deis.login(function(err) { 16 | deis.auth.cancel(function(err) { 17 | deis.register('deis@deis.io', function(err, user) { 18 | deis.login(function(err) { 19 | deis.apps.create(APP_NAME, function(err, app) { 20 | expect(err).to.be(null); 21 | expect(app).to.be.a(Object); 22 | done(); 23 | }); 24 | }); 25 | }); 26 | }); 27 | }); 28 | }); 29 | 30 | after(function(done) { 31 | deis.apps.destroy(APP_NAME, function(err) { 32 | expect(err).to.be(null); 33 | done(); 34 | }); 35 | }); 36 | 37 | it('should return no configuration', function(done) { 38 | deis.config.list(APP_NAME, function(err, values) { 39 | expect(err).to.be(null); 40 | expect(values).to.be.an(Object); 41 | expect(Object.keys(values).length).to.be.eql(0); 42 | done(); 43 | }); 44 | }); 45 | 46 | it('should add new variables', function(done) { 47 | var test = { 48 | 'HELLO': 'world', 49 | 'PLATFORM': 'deis' 50 | }; 51 | 52 | deis.config.set(APP_NAME, test, function(err, values) { 53 | expect(err).to.be(null); 54 | expect(values).to.be.an(Object); 55 | expect(Object.keys(values).length).to.be.eql(2); 56 | expect(values).to.be.eql(test); 57 | done(); 58 | }); 59 | }); 60 | 61 | it('should remove new variables', function(done) { 62 | var test = { 63 | 'HELLO': 'world', 64 | 'PLATFORM': 'deis' 65 | }; 66 | 67 | deis.config.unset(APP_NAME, ['HELLO', 'PLATFORM'], function(err, values) { 68 | expect(err).to.be(null); 69 | expect(values).to.be.an(Object); 70 | expect(Object.keys(values).length).to.be.eql(0); 71 | done(); 72 | }); 73 | }); 74 | 75 | it('should return no tags', function(done) { 76 | deis.tags.list(APP_NAME, function(err, values) { 77 | expect(err).to.be(null); 78 | expect(values).to.be.an(Object); 79 | expect(Object.keys(values).length).to.be.eql(0); 80 | done(); 81 | }); 82 | }); 83 | 84 | it('should add new tag', function(done) { 85 | var test = { 86 | 'location': 'test' 87 | }; 88 | 89 | deis.tags.set(APP_NAME, test, function(err, values) { 90 | expect(err).to.be(null); 91 | expect(values).to.be.an(Object); 92 | expect(Object.keys(values).length).to.be.eql(1); 93 | expect(values).to.be.eql(test); 94 | done(); 95 | }); 96 | }); 97 | 98 | it('should remove the tag "location"', function(done) { 99 | deis.tags.unset(APP_NAME, ['location'], function(err, values) { 100 | expect(err).to.be(null); 101 | expect(values).to.be.an(Object); 102 | expect(Object.keys(values).length).to.be.eql(0); 103 | done(); 104 | }); 105 | }); 106 | 107 | 108 | /****/ 109 | it('should return empty perms', function(done) { 110 | var expected = { 111 | 'users': [] 112 | }; 113 | 114 | deis.perms.list(APP_NAME, function(err, values) { 115 | expect(err).to.be(null); 116 | expect(values).to.be.an(Object); 117 | expect(Object.keys(values).length).to.be.eql(1); 118 | expect(values).to.be.eql(expected); 119 | done(); 120 | }); 121 | }); 122 | 123 | it('should add new perm for user "deis"', function(done) { 124 | var expected = { 125 | users: ['test'] 126 | }; 127 | 128 | deis.perms.create('test', APP_NAME, function(err) { 129 | expect(err).to.be(null); 130 | deis.perms.list(APP_NAME, function(err, values) { 131 | expect(err).to.be(null); 132 | expect(values).to.be.an(Object); 133 | expect(Object.keys(values).length).to.be.eql(1); 134 | expect(values).to.be.eql(expected); 135 | done(); 136 | }); 137 | }); 138 | }); 139 | 140 | it('should remove the permission for user "test"', function(done) { 141 | deis.tags.unset(APP_NAME, ['location'], function(err, values) { 142 | expect(err).to.be(null); 143 | expect(values).to.be.an(Object); 144 | expect(Object.keys(values).length).to.be.eql(0); 145 | done(); 146 | }); 147 | }); 148 | }); 149 | -------------------------------------------------------------------------------- /test/domain_test.js: -------------------------------------------------------------------------------- 1 | var expect = require('expect.js'), 2 | DeisApi = require('../'); 3 | 4 | var deis = new DeisApi({ 5 | controller: 'deis.local3.deisapp.com', 6 | username: 'admin', 7 | password: 'deis' 8 | }); 9 | 10 | describe('domains suite', function() { 11 | }); 12 | -------------------------------------------------------------------------------- /test/keys_test.js: -------------------------------------------------------------------------------- 1 | var expect = require('expect.js'), 2 | DeisApi = require('../'); 3 | 4 | var deis = new DeisApi({ 5 | controller: 'deis.local3.deisapp.com', 6 | username: 'test', 7 | password: 'opensesame' 8 | }); 9 | 10 | var TEST_KEY = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAYQD3txsEf0HAKElAFUvIXzsM98gfPlIbG4/GlqbYYBulkHu6z0laOdoT14Zx2M+3q+9RjhTZjHxyMfePdcgNK9z98V6tOz5bIQhtMS8tl1Tnw5qZByGqpqOKf665ev62LaM= testing-ssh2-from-node.js'; 11 | 12 | describe('keys suite', function() { 13 | 14 | before(function(done) { 15 | deis.login(function(err) { 16 | deis.auth.cancel(function(err) { 17 | deis.register('deis@deis.io', function(err, user) { 18 | deis.login(function(err) { 19 | done(); 20 | }); 21 | }); 22 | }); 23 | }); 24 | }); 25 | 26 | it('should list the keys (0)', function(done) { 27 | deis.keys.list(function(err, keys) { 28 | expect(err).to.be(null); 29 | expect(keys.count).to.be.eql(0); 30 | done(); 31 | }); 32 | }); 33 | 34 | it('should add a key with id demo-key', function(done) { 35 | deis.keys.add('demo-key', TEST_KEY, function(err, key) { 36 | expect(err).to.be(null); 37 | expect(key).to.be.a(Object); 38 | done(); 39 | }); 40 | }); 41 | 42 | it('should list the keys (1)', function(done) { 43 | deis.keys.list(function(err, keys) { 44 | expect(err).to.be(null); 45 | expect(keys.count).to.be.eql(1); 46 | expect(keys.results[0].public).to.be.eql(TEST_KEY); 47 | done(); 48 | }); 49 | }); 50 | 51 | it('should remove the keys with id demo-key', function(done) { 52 | deis.keys.remove('demo-key', function(err) { 53 | expect(err).to.be(null); 54 | deis.keys.list(function(err, keys) { 55 | expect(err).to.be(null); 56 | expect(keys.count).to.be.eql(0); 57 | done(); 58 | }); 59 | }); 60 | }); 61 | }); 62 | -------------------------------------------------------------------------------- /test/limits_test.js: -------------------------------------------------------------------------------- 1 | var expect = require('expect.js'), 2 | DeisApi = require('../'); 3 | 4 | var APP_NAME = 'app-config-test'; 5 | 6 | describe('limits suite', function() { 7 | 8 | var deis = new DeisApi({ 9 | controller: 'deis.local3.deisapp.com', 10 | username: 'test', 11 | password: 'opensesame' 12 | }); 13 | 14 | before(function(done) { 15 | deis.login(function(err) { 16 | deis.auth.cancel(function(err) { 17 | deis.register('deis@deis.io', function(err, user) { 18 | deis.login(function(err) { 19 | deis.apps.destroy(APP_NAME, function(err) { 20 | done(); 21 | }); 22 | }); 23 | }); 24 | }); 25 | }); 26 | }); 27 | 28 | it('should return no limits', function(done) { 29 | deis.apps.create(APP_NAME, function(err, app) { 30 | expect(err).to.be(null); 31 | expect(app).to.be.a(Object); 32 | 33 | deis.limits.list(APP_NAME, function(err, limits) { 34 | expect(err).to.be(null); 35 | expect(limits).to.be.a(Object); 36 | expect(Object.keys(limits).length).to.be.eql(0); 37 | expect(limits.memory).to.be(undefined); 38 | expect(limits.cpu).to.be(undefined); 39 | done(); 40 | }); 41 | }); 42 | }); 43 | 44 | it('should set memory limits', function(done) { 45 | var customLimits = { 46 | memory: { 47 | web: '1G' 48 | } 49 | }; 50 | 51 | deis.limits.set(APP_NAME, customLimits, function(err, limits) { 52 | expect(err).to.be(null); 53 | expect(limits).to.be.a(Object); 54 | expect(Object.keys(limits).length).to.be.eql(1); 55 | expect(Object.keys(limits.memory).length).to.be.eql(1); 56 | expect(limits.cpu).to.be(undefined); 57 | expect(limits.memory.web).to.be.eql('1G'); 58 | deis.limits.list(APP_NAME, function(err, values) { 59 | expect(values).to.be.eql(customLimits); 60 | done(); 61 | }); 62 | }); 63 | }); 64 | 65 | it('should remove memory limits', function(done) { 66 | deis.limits.unset(APP_NAME, 'memory', 'web', function(err, limits) { 67 | expect(err).to.be(null); 68 | expect(limits).to.be.a(Object); 69 | expect(Object.keys(limits).length).to.be.eql(0); 70 | expect(limits.cpu).to.be(undefined); 71 | expect(limits.memory).to.be(undefined); 72 | deis.config.list(APP_NAME, function(err, values) { 73 | expect(values.memory).to.be.eql({}); 74 | done(); 75 | }); 76 | done(); 77 | }); 78 | }); 79 | }); 80 | -------------------------------------------------------------------------------- /test/login_test.js: -------------------------------------------------------------------------------- 1 | var expect = require('expect.js'), 2 | DeisApi = require('../'); 3 | 4 | describe('login suite', function() { 5 | before(function(done) { 6 | var deis = new DeisApi({ 7 | controller: 'deis.local3.deisapp.com', 8 | username: 'admin', 9 | password: 'deis' 10 | }); 11 | 12 | deis.login(function(err) { 13 | deis.auth.cancel(function(err) { 14 | done(); 15 | }); 16 | }); 17 | }); 18 | 19 | it('should fail (invalid user)', function(done) { 20 | var deis = new DeisApi({ 21 | controller: 'deis.local3.deisapp.com', 22 | username: 'admin', 23 | password: 'invalid' 24 | }); 25 | 26 | deis.login(function(err) { 27 | expect(err).to.be.a(Error); 28 | done(); 29 | }); 30 | }); 31 | 32 | it('should fail (invalid password)', function(done) { 33 | var deis = new DeisApi({ 34 | controller: 'deis.local3.deisapp.com', 35 | username: 'admin', 36 | password: 'invalid' 37 | }); 38 | 39 | deis.login(function(err) { 40 | expect(err).to.be.a(Error); 41 | done(); 42 | }); 43 | }); 44 | 45 | it('should login', function(done) { 46 | var deis = new DeisApi({ 47 | controller: 'deis.local3.deisapp.com', 48 | username: 'admin', 49 | password: 'deis' 50 | }); 51 | 52 | deis.register('deis@deis.io', function(err, user) { 53 | deis.login(function(err) { 54 | expect(err).to.be(null); 55 | done(); 56 | }); 57 | }); 58 | }); 59 | }); 60 | -------------------------------------------------------------------------------- /test/logout_test.js: -------------------------------------------------------------------------------- 1 | var expect = require('expect.js'), 2 | DeisApi = require('../'); 3 | 4 | var deis = new DeisApi({ 5 | controller: 'deis.local3.deisapp.com', 6 | username: 'admin', 7 | password: 'deis' 8 | }); 9 | 10 | describe('logout suite', function() { 11 | before(function(done) { 12 | deis.login(function(err) { 13 | deis.auth.cancel(function(err) { 14 | deis.register('deis@deis.io', function(err, user) { 15 | deis.login(function(err) { 16 | done(); 17 | }); 18 | }); 19 | }); 20 | }); 21 | }); 22 | 23 | it('should remove token', function(done) { 24 | var deis = new DeisApi({ 25 | controller: 'deis.local3.deisapp.com', 26 | username: 'admin', 27 | password: 'deis' 28 | }); 29 | 30 | deis.logout(function() { 31 | done(); 32 | }); 33 | }); 34 | }); 35 | -------------------------------------------------------------------------------- /test/mocha.opts: -------------------------------------------------------------------------------- 1 | --require expect.js 2 | --ui bdd 3 | --growl 4 | --reporter spec 5 | --timeout 10000 6 | --check-leaks -------------------------------------------------------------------------------- /test/ps_test.js: -------------------------------------------------------------------------------- 1 | var expect = require('expect.js'), 2 | DeisApi = require('../'); 3 | 4 | var deis = new DeisApi({ 5 | controller: 'deis.local3.deisapp.com', 6 | username: 'admin', 7 | password: 'deis' 8 | }); 9 | 10 | describe('ps suite', function() { 11 | }); 12 | -------------------------------------------------------------------------------- /test/releases_test.js: -------------------------------------------------------------------------------- 1 | var expect = require('expect.js'), 2 | DeisApi = require('../'); 3 | 4 | var deis = new DeisApi({ 5 | controller: 'deis.local3.deisapp.com', 6 | username: 'admin', 7 | password: 'deis' 8 | }); 9 | 10 | describe('releases suite', function() { 11 | }); 12 | --------------------------------------------------------------------------------