2014-02-20 05:52:58 +02:00
|
|
|
/*
|
2015-09-04 21:12:20 +03:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2015 Joyent, Inc.
|
2014-02-20 05:52:58 +02:00
|
|
|
*
|
|
|
|
* Client library for the SmartDataCenter Cloud API (cloudapi).
|
|
|
|
* http://apidocs.joyent.com/cloudapi/
|
|
|
|
*
|
|
|
|
* Usage example::
|
|
|
|
*
|
|
|
|
* var auth = require('smartdc-auth');
|
|
|
|
* var cloudapi = require('./lib/cloudapi2');
|
|
|
|
* var client = cloudapi.createClient({
|
2015-05-19 00:07:45 +03:00
|
|
|
* url: <URL>, // 'https://us-sw-1.api.joyent.com',
|
2015-11-04 01:40:59 +02:00
|
|
|
* account: <ACCOUNT>, // 'acmecorp'
|
|
|
|
* [user: <RBAC-USER>,] // 'bob'
|
2014-02-20 05:52:58 +02:00
|
|
|
* log: <BUNYAN-LOGGER>,
|
|
|
|
* sign: auth.cliSigner({
|
|
|
|
* keyId: <KEY-ID>, // ssh fingerprint
|
2015-11-04 01:40:59 +02:00
|
|
|
* // Unfortunately node-smartdc-auth uses user/subuser, while
|
|
|
|
* // node-triton uses account/user:
|
|
|
|
* user: <ACCOUNT>, // 'acmecorp'
|
|
|
|
* [subuser: <RBAC-USER>,] // 'bob'
|
2014-02-20 05:52:58 +02:00
|
|
|
* log: <BUNYAN-LOGGER>,
|
|
|
|
* }),
|
|
|
|
* ...
|
|
|
|
* });
|
|
|
|
* client.listImages(function (err, images) { ... });
|
|
|
|
* ...
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
var assert = require('assert-plus');
|
2015-08-26 00:25:30 +03:00
|
|
|
var format = require('util').format;
|
2015-08-26 02:46:14 +03:00
|
|
|
var LOMStream = require('lomstream').LOMStream;
|
2014-02-20 05:52:58 +02:00
|
|
|
var os = require('os');
|
|
|
|
var querystring = require('querystring');
|
2015-08-25 23:11:40 +03:00
|
|
|
var vasync = require('vasync');
|
2015-11-14 02:19:35 +02:00
|
|
|
var auth = require('smartdc-auth');
|
2014-02-20 05:52:58 +02:00
|
|
|
|
2015-12-08 21:59:45 +02:00
|
|
|
var bunyannoop = require('./bunyannoop');
|
2014-02-20 05:52:58 +02:00
|
|
|
var errors = require('./errors');
|
2015-09-23 22:32:09 +03:00
|
|
|
var SaferJsonClient = require('./SaferJsonClient');
|
2014-02-20 05:52:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ---- globals
|
|
|
|
|
2015-08-25 23:11:40 +03:00
|
|
|
var VERSION = require('../package.json').version;
|
2014-02-20 05:52:58 +02:00
|
|
|
var OS_ARCH = os.arch();
|
|
|
|
var OS_PLATFORM = os.platform();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ---- client API
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a cloudapi client.
|
|
|
|
*
|
|
|
|
* @param options {Object}
|
|
|
|
* - {String} url (required) Cloud API base url
|
2015-11-04 01:40:59 +02:00
|
|
|
* - {String} account (required) The account login name.
|
2014-02-20 05:52:58 +02:00
|
|
|
* - {Function} sign (required) An http-signature auth signing function
|
2015-11-04 01:40:59 +02:00
|
|
|
* - {String} user (optional) The RBAC user login name.
|
2014-02-20 05:52:58 +02:00
|
|
|
* - {String} version (optional) Used for the accept-version header. This
|
|
|
|
* defaults to '*', meaning that over time you could experience breaking
|
|
|
|
* changes. Specifying a value is strongly recommended. E.g. '~7.1'.
|
|
|
|
* - {Bunyan Logger} log (optional)
|
|
|
|
* - ... and any other standard restify client options, e.g.:
|
|
|
|
* {String} userAgent
|
|
|
|
* {Boolean} rejectUnauthorized
|
|
|
|
* {Boolean} agent Set to `false` to not get KeepAlive. You want
|
|
|
|
* this for CLIs.
|
|
|
|
* TODO doc the backoff/retry available options
|
|
|
|
* @throws {TypeError} on bad input.
|
|
|
|
* @constructor
|
|
|
|
*
|
|
|
|
* TODO: caching options (copy node-manta/node-moray/node-smartdc?)
|
|
|
|
* - {Boolean} noCache (optional) disable client caching (default false).
|
|
|
|
* - {Boolean} cacheSize (optional) number of cache entries (default 1k).
|
|
|
|
* - {Boolean} cacheExpiry (optional) entry age in seconds (default 60).
|
|
|
|
*/
|
2015-09-04 21:04:45 +03:00
|
|
|
function CloudApi(options) {
|
2014-02-20 05:52:58 +02:00
|
|
|
assert.object(options, 'options');
|
|
|
|
assert.string(options.url, 'options.url');
|
2015-11-04 01:40:59 +02:00
|
|
|
assert.string(options.account, 'options.account');
|
2014-02-20 05:52:58 +02:00
|
|
|
assert.func(options.sign, 'options.sign');
|
2015-11-04 01:40:59 +02:00
|
|
|
assert.optionalString(options.user, 'options.user');
|
2014-02-20 05:52:58 +02:00
|
|
|
assert.optionalString(options.version, 'options.version');
|
|
|
|
assert.optionalObject(options.log, 'options.log');
|
|
|
|
|
|
|
|
this.url = options.url;
|
2015-11-04 01:40:59 +02:00
|
|
|
this.account = options.account;
|
|
|
|
this.user = options.user; // optional RBAC subuser
|
2014-02-20 05:52:58 +02:00
|
|
|
this.sign = options.sign;
|
2015-12-08 21:59:45 +02:00
|
|
|
this.log = options.log || new bunyannoop.BunyanNoopLogger();
|
2014-02-20 05:52:58 +02:00
|
|
|
if (!options.version) {
|
|
|
|
options.version = '*';
|
|
|
|
}
|
|
|
|
if (!options.userAgent) {
|
2015-09-03 07:02:40 +03:00
|
|
|
options.userAgent = format('triton/%s (%s-%s; node/%s)',
|
2015-08-25 23:11:40 +03:00
|
|
|
VERSION, OS_ARCH, OS_PLATFORM, process.versions.node);
|
2014-02-20 05:52:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// XXX relevant?
|
|
|
|
//options.retryCallback = function checkFor500(code) {
|
|
|
|
// return (code === 500);
|
|
|
|
//};
|
|
|
|
|
2015-11-04 01:40:59 +02:00
|
|
|
// TODO support token auth
|
2014-02-20 05:52:58 +02:00
|
|
|
//this.token = options.token;
|
|
|
|
|
2015-09-23 22:32:09 +03:00
|
|
|
this.client = new SaferJsonClient(options);
|
2014-02-20 05:52:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-08 21:59:45 +02:00
|
|
|
CloudApi.prototype.close = function close(callback) {
|
|
|
|
this.log.trace({host: this.client.url && this.client.url.host},
|
|
|
|
'close cloudapi http client');
|
|
|
|
this.client.close();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-09-04 21:04:45 +03:00
|
|
|
CloudApi.prototype._getAuthHeaders = function _getAuthHeaders(callback) {
|
2014-02-20 05:52:58 +02:00
|
|
|
assert.func(callback, 'callback');
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
var headers = {};
|
2015-11-14 02:19:35 +02:00
|
|
|
|
|
|
|
var rs = auth.requestSigner({
|
|
|
|
sign: self.sign
|
|
|
|
});
|
|
|
|
headers.date = rs.writeDateHeader();
|
2014-02-20 05:52:58 +02:00
|
|
|
|
2015-11-04 01:40:59 +02:00
|
|
|
// TODO: token auth support
|
2014-02-20 05:52:58 +02:00
|
|
|
//if (this.token !== undefined) {
|
|
|
|
// obj.headers['X-Auth-Token'] = this.token;
|
|
|
|
//}
|
|
|
|
|
2015-11-14 02:19:35 +02:00
|
|
|
rs.sign(function (err, authz) {
|
|
|
|
if (err || !authz) {
|
2014-02-20 05:52:58 +02:00
|
|
|
callback(new errors.SigningError(err));
|
|
|
|
return;
|
|
|
|
}
|
2015-11-14 02:19:35 +02:00
|
|
|
headers.authorization = authz;
|
2014-02-20 05:52:58 +02:00
|
|
|
callback(null, headers);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-08-26 00:25:30 +03:00
|
|
|
/**
|
|
|
|
* Return an appropriate query string *with the leading '?'* from the given
|
|
|
|
* fields. If any of the field values are undefined or null, then they will
|
|
|
|
* be excluded.
|
|
|
|
*/
|
2015-09-04 21:04:45 +03:00
|
|
|
CloudApi.prototype._qs = function _qs(/* fields1, ...*/) {
|
2015-08-26 01:30:25 +03:00
|
|
|
var fields = Array.prototype.slice.call(arguments);
|
2015-08-26 00:25:30 +03:00
|
|
|
|
|
|
|
var query = {};
|
2015-08-26 01:30:25 +03:00
|
|
|
fields.forEach(function (field) {
|
|
|
|
Object.keys(field).forEach(function (key) {
|
|
|
|
var value = field[key];
|
2015-08-26 00:25:30 +03:00
|
|
|
if (value !== undefined && value !== null) {
|
|
|
|
query[key] = value;
|
|
|
|
}
|
|
|
|
});
|
2015-08-26 01:30:25 +03:00
|
|
|
});
|
2015-08-26 00:25:30 +03:00
|
|
|
|
|
|
|
if (Object.keys(query).length === 0) {
|
|
|
|
return '';
|
|
|
|
} else {
|
|
|
|
return '?' + querystring.stringify(query);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2015-11-04 01:40:59 +02:00
|
|
|
* Return an appropriate full URL *path* given a CloudApi subpath.
|
2015-08-26 00:25:30 +03:00
|
|
|
* This handles prepending the API's base path, if any: e.g. if the configured
|
|
|
|
* URL is "https://example.com/base/path".
|
|
|
|
*
|
|
|
|
* Optionally an object of query params can be passed in to include a query
|
|
|
|
* string. This just calls `this._qs(...)`.
|
|
|
|
*/
|
2015-09-04 21:04:45 +03:00
|
|
|
CloudApi.prototype._path = function _path(subpath /* , qparams, ... */) {
|
2015-08-26 00:25:30 +03:00
|
|
|
assert.string(subpath, 'subpath');
|
|
|
|
assert.ok(subpath[0] === '/');
|
|
|
|
|
|
|
|
var path = subpath;
|
2015-08-26 01:30:25 +03:00
|
|
|
var qparams = Array.prototype.slice.call(arguments, 1);
|
|
|
|
path += this._qs.apply(this, qparams);
|
2015-08-26 00:25:30 +03:00
|
|
|
return path;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-08-26 01:30:25 +03:00
|
|
|
/**
|
2015-08-26 01:47:29 +03:00
|
|
|
* Cloud API request wrapper - modeled after http.request
|
2015-08-26 01:30:25 +03:00
|
|
|
*
|
|
|
|
* @param {Object|String} options - object or string for endpoint
|
|
|
|
* - {String} path - URL endpoint to hit
|
|
|
|
* - {String} method - HTTP(s) request method
|
2015-08-26 04:09:32 +03:00
|
|
|
* - {Object} data - data to be passed
|
2015-08-26 01:30:25 +03:00
|
|
|
* @param {Function} callback passed via the restify client
|
|
|
|
*/
|
2015-09-04 21:04:45 +03:00
|
|
|
CloudApi.prototype._request = function _request(options, callback) {
|
2015-08-26 01:30:25 +03:00
|
|
|
var self = this;
|
2015-09-01 22:03:52 +03:00
|
|
|
if (typeof (options) === 'string')
|
2015-08-26 01:30:25 +03:00
|
|
|
options = {path: options};
|
|
|
|
assert.object(options, 'options');
|
|
|
|
assert.func(callback, 'callback');
|
2015-08-26 04:09:32 +03:00
|
|
|
assert.optionalObject(options.data, 'options.data');
|
2015-08-26 01:30:25 +03:00
|
|
|
|
|
|
|
var method = (options.method || 'GET').toLowerCase();
|
2015-11-10 01:09:37 +02:00
|
|
|
assert.ok(['get', 'post', 'put', 'delete', 'head'].indexOf(method) >= 0,
|
2015-08-26 01:30:25 +03:00
|
|
|
'invalid method given');
|
2015-08-26 08:25:26 +03:00
|
|
|
switch (method) {
|
2015-09-01 22:03:52 +03:00
|
|
|
case 'delete':
|
|
|
|
method = 'del';
|
2015-09-01 19:00:45 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2015-08-26 08:25:26 +03:00
|
|
|
}
|
2015-09-01 19:00:45 +03:00
|
|
|
|
2015-08-26 01:30:25 +03:00
|
|
|
self._getAuthHeaders(function (err, headers) {
|
|
|
|
if (err) {
|
|
|
|
callback(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var opts = {
|
|
|
|
path: options.path,
|
|
|
|
headers: headers
|
|
|
|
};
|
2015-08-26 04:09:32 +03:00
|
|
|
if (options.data)
|
|
|
|
self.client[method](opts, options.data, callback);
|
|
|
|
else
|
|
|
|
self.client[method](opts, callback);
|
2015-08-26 01:30:25 +03:00
|
|
|
});
|
|
|
|
};
|
2014-02-20 05:52:58 +02:00
|
|
|
|
2015-08-26 23:40:50 +03:00
|
|
|
/**
|
|
|
|
* A simple wrapper around making a GET request to an endpoint and
|
|
|
|
* passing back the body returned
|
|
|
|
*/
|
2015-11-04 01:40:59 +02:00
|
|
|
CloudApi.prototype._passThrough = function _passThrough(endpoint, opts, cb) {
|
2015-09-24 07:08:26 +03:00
|
|
|
var self = this;
|
2015-08-26 23:40:50 +03:00
|
|
|
if (typeof (opts) === 'function') {
|
|
|
|
cb = opts;
|
|
|
|
opts = null;
|
|
|
|
}
|
|
|
|
opts = opts || {};
|
2015-08-26 01:47:29 +03:00
|
|
|
|
2015-08-26 23:40:50 +03:00
|
|
|
assert.string(endpoint, 'endpoint');
|
|
|
|
assert.object(opts, 'opts');
|
|
|
|
assert.func(cb, 'cb');
|
2015-08-26 01:47:29 +03:00
|
|
|
|
2015-08-26 23:40:50 +03:00
|
|
|
var p = this._path(endpoint, opts);
|
|
|
|
this._request(p, function (err, req, res, body) {
|
2015-09-24 07:08:26 +03:00
|
|
|
/*
|
|
|
|
* Improve this kind of error message:
|
|
|
|
*
|
|
|
|
* Error: DEPTH_ZERO_SELF_SIGNED_CERT
|
|
|
|
* at SecurePair.<anonymous> (tls.js:1381:32)
|
|
|
|
* at SecurePair.emit (events.js:92:17)
|
|
|
|
*
|
|
|
|
* TODO: could generalize this into a wrapErr method.
|
|
|
|
*/
|
|
|
|
if (err && err.message === 'DEPTH_ZERO_SELF_SIGNED_CERT' &&
|
|
|
|
self.client.rejectUnauthorized)
|
|
|
|
{
|
|
|
|
err = new errors.SelfSignedCertError(err, self.url);
|
|
|
|
}
|
|
|
|
|
2015-08-26 23:40:50 +03:00
|
|
|
cb(err, body, res);
|
|
|
|
});
|
|
|
|
};
|
2014-02-20 05:52:58 +02:00
|
|
|
|
2015-11-04 01:40:59 +02:00
|
|
|
|
|
|
|
|
2015-08-26 23:40:50 +03:00
|
|
|
// ---- networks
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get network information
|
|
|
|
*
|
2015-11-06 01:13:14 +02:00
|
|
|
* @param {Function} callback of the form `function (err, networks, res)`
|
2015-08-26 23:40:50 +03:00
|
|
|
*/
|
2015-09-04 21:04:45 +03:00
|
|
|
CloudApi.prototype.listNetworks = function listNetworks(opts, cb) {
|
2015-11-04 01:40:59 +02:00
|
|
|
var endpoint = format('/%s/networks', this.account);
|
2015-08-26 23:40:50 +03:00
|
|
|
this._passThrough(endpoint, opts, cb);
|
|
|
|
};
|
|
|
|
|
2015-08-27 00:09:50 +03:00
|
|
|
/**
|
|
|
|
* <http://apidocs.joyent.com/cloudapi/#GetNetwork>
|
|
|
|
*
|
|
|
|
* @param {String} - UUID
|
|
|
|
* @param {Function} callback of the form `function (err, network, res)`
|
|
|
|
*/
|
2015-09-04 21:04:45 +03:00
|
|
|
CloudApi.prototype.getNetwork = function getNetwork(id, cb) {
|
2015-08-27 00:09:50 +03:00
|
|
|
assert.uuid(id, 'id');
|
|
|
|
assert.func(cb, 'cb');
|
|
|
|
|
2015-11-04 01:40:59 +02:00
|
|
|
var endpoint = this._path(format('/%s/networks/%s', this.account, id));
|
2015-08-27 00:09:50 +03:00
|
|
|
this._request(endpoint, function (err, req, res, body) {
|
|
|
|
cb(err, body, res);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-11-04 01:40:59 +02:00
|
|
|
|
|
|
|
|
2015-08-27 02:56:18 +03:00
|
|
|
// ---- datacenters
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get services information
|
|
|
|
*
|
2015-11-06 01:13:14 +02:00
|
|
|
* @param {Function} callback of the form `function (err, services, res)`
|
2015-08-27 02:56:18 +03:00
|
|
|
*/
|
2015-09-04 21:04:45 +03:00
|
|
|
CloudApi.prototype.listServices = function listServices(opts, cb) {
|
2015-11-04 01:40:59 +02:00
|
|
|
var endpoint = format('/%s/services', this.account);
|
2015-08-27 02:56:18 +03:00
|
|
|
this._passThrough(endpoint, opts, cb);
|
|
|
|
};
|
|
|
|
|
2015-08-27 02:59:28 +03:00
|
|
|
/**
|
|
|
|
* Get datacenters information
|
|
|
|
*
|
2015-11-06 01:13:14 +02:00
|
|
|
* @param {Function} callback of the form `function (err, datacenters, res)`
|
2015-08-27 02:59:28 +03:00
|
|
|
*/
|
2015-09-04 21:04:45 +03:00
|
|
|
CloudApi.prototype.listDatacenters = function listDatacenters(opts, cb) {
|
2015-11-04 01:40:59 +02:00
|
|
|
var endpoint = format('/%s/datacenters', this.account);
|
2015-08-27 02:59:28 +03:00
|
|
|
this._passThrough(endpoint, opts, cb);
|
|
|
|
};
|
|
|
|
|
2015-11-04 01:40:59 +02:00
|
|
|
|
2015-08-26 23:40:50 +03:00
|
|
|
// ---- accounts
|
2015-08-26 06:44:08 +03:00
|
|
|
|
2014-02-20 05:52:58 +02:00
|
|
|
/**
|
2015-08-26 06:44:08 +03:00
|
|
|
* Get account information
|
2014-02-20 05:52:58 +02:00
|
|
|
*
|
2015-11-06 01:13:14 +02:00
|
|
|
* @param {Function} callback of the form `function (err, account, res)`
|
2014-02-20 05:52:58 +02:00
|
|
|
*/
|
2015-09-04 21:04:45 +03:00
|
|
|
CloudApi.prototype.getAccount = function getAccount(opts, cb) {
|
2015-11-04 01:40:59 +02:00
|
|
|
var endpoint = format('/%s', this.account);
|
2015-08-26 23:40:50 +03:00
|
|
|
this._passThrough(endpoint, opts, cb);
|
2014-02-20 05:52:58 +02:00
|
|
|
};
|
|
|
|
|
2015-08-26 07:40:32 +03:00
|
|
|
/**
|
2015-11-06 01:13:14 +02:00
|
|
|
* List account's SSH keys.
|
2015-08-26 07:40:32 +03:00
|
|
|
*
|
2015-11-06 01:13:14 +02:00
|
|
|
* @param {Function} callback of the form `function (err, keys, res)`
|
2015-08-26 07:40:32 +03:00
|
|
|
*/
|
2015-09-04 21:04:45 +03:00
|
|
|
CloudApi.prototype.listKeys = function listKeys(opts, cb) {
|
2015-11-04 01:40:59 +02:00
|
|
|
var endpoint = format('/%s/keys', this.account);
|
2015-08-26 23:40:50 +03:00
|
|
|
this._passThrough(endpoint, opts, cb);
|
2015-08-26 07:40:32 +03:00
|
|
|
};
|
2014-02-20 05:52:58 +02:00
|
|
|
|
2015-11-04 01:40:59 +02:00
|
|
|
|
2015-08-26 00:25:30 +03:00
|
|
|
// ---- images
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <http://apidocs.joyent.com/cloudapi/#ListImages>
|
|
|
|
*
|
2015-11-04 01:40:59 +02:00
|
|
|
* @param {Object} opts (optional)
|
2015-09-21 20:33:42 +03:00
|
|
|
* XXX be more strict about accepted options
|
2015-08-26 00:25:30 +03:00
|
|
|
* XXX document this, see the api doc above :)
|
2015-11-04 01:40:59 +02:00
|
|
|
* @param {Function} cb of the form `function (err, images, res)`
|
2015-08-26 00:25:30 +03:00
|
|
|
*/
|
2015-09-04 21:04:45 +03:00
|
|
|
CloudApi.prototype.listImages = function listImages(opts, cb) {
|
2015-11-04 01:40:59 +02:00
|
|
|
var endpoint = format('/%s/images', this.account);
|
2015-08-26 23:44:11 +03:00
|
|
|
this._passThrough(endpoint, opts, cb);
|
2015-08-26 01:47:29 +03:00
|
|
|
};
|
2015-08-26 00:25:30 +03:00
|
|
|
|
2015-08-26 01:47:29 +03:00
|
|
|
/**
|
2015-11-04 01:40:59 +02:00
|
|
|
* <http://apidocs.joyent.com/cloudapi/#GetImage>
|
2015-08-26 01:47:29 +03:00
|
|
|
*
|
2015-11-04 01:40:59 +02:00
|
|
|
* @param {Object} opts
|
2015-08-26 01:47:29 +03:00
|
|
|
* - id {UUID}
|
2015-11-04 01:40:59 +02:00
|
|
|
* @param {Function} cb of the form `function (err, image, res)`
|
2015-08-26 01:47:29 +03:00
|
|
|
*/
|
2015-11-04 01:40:59 +02:00
|
|
|
CloudApi.prototype.getImage = function getImage(opts, cb) {
|
|
|
|
assert.object(opts, 'opts');
|
|
|
|
assert.uuid(opts.id, 'opts.id');
|
|
|
|
assert.func(cb, 'cb');
|
2015-08-26 01:47:29 +03:00
|
|
|
|
2015-11-04 01:40:59 +02:00
|
|
|
var endpoint = this._path(format('/%s/images/%s', this.account, opts.id));
|
2015-08-26 01:47:29 +03:00
|
|
|
this._request(endpoint, function (err, req, res, body) {
|
2015-11-04 01:40:59 +02:00
|
|
|
cb(err, body, res);
|
2015-08-26 00:25:30 +03:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-08-26 02:12:35 +03:00
|
|
|
// ---- packages
|
|
|
|
|
2015-11-04 01:40:59 +02:00
|
|
|
/**
|
|
|
|
* <http://apidocs.joyent.com/cloudapi/#ListPackages>
|
|
|
|
*
|
|
|
|
* @param {Object} opts (optional)
|
|
|
|
* XXX be more strict about accepted options
|
|
|
|
* XXX document this, see the api doc above :)
|
|
|
|
* @param {Function} callback of the form `function (err, packages, res)`
|
|
|
|
*/
|
2015-09-04 21:04:45 +03:00
|
|
|
CloudApi.prototype.listPackages = function listPackages(opts, cb) {
|
2015-11-04 01:40:59 +02:00
|
|
|
var endpoint = format('/%s/packages', this.account);
|
2015-08-26 23:44:11 +03:00
|
|
|
this._passThrough(endpoint, opts, cb);
|
2015-08-26 02:12:35 +03:00
|
|
|
};
|
|
|
|
|
2015-11-04 01:40:59 +02:00
|
|
|
/**
|
|
|
|
* <http://apidocs.joyent.com/cloudapi/#GetPackage>
|
|
|
|
*
|
|
|
|
* @param {Object} opts
|
|
|
|
* - id {UUID|String} Package ID (a UUID) or name.
|
|
|
|
* @param {Function} cb of the form `function (err, package, res)`
|
|
|
|
*/
|
|
|
|
CloudApi.prototype.getPackage = function getPackage(opts, cb) {
|
|
|
|
assert.object(opts, 'opts');
|
|
|
|
assert.uuid(opts.id, 'opts.id');
|
|
|
|
assert.func(cb, 'cb');
|
2015-08-26 02:12:35 +03:00
|
|
|
|
2015-11-04 01:40:59 +02:00
|
|
|
// XXX use _passThrough?
|
|
|
|
var endpoint = this._path(format('/%s/packages/%s', this.account, opts.id));
|
2015-08-26 02:12:35 +03:00
|
|
|
this._request(endpoint, function (err, req, res, body) {
|
2015-11-04 01:40:59 +02:00
|
|
|
cb(err, body, res);
|
2015-08-26 02:12:35 +03:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-02-20 05:52:58 +02:00
|
|
|
// ---- machines
|
|
|
|
|
2015-07-26 08:45:20 +03:00
|
|
|
/**
|
|
|
|
* Get a machine by id.
|
|
|
|
*
|
|
|
|
* XXX add getCredentials equivalent
|
|
|
|
* XXX cloudapi docs don't doc the credentials=true option
|
|
|
|
*
|
2015-08-26 04:09:32 +03:00
|
|
|
* @param {String} uuid (required) The machine id.
|
2015-11-06 01:13:14 +02:00
|
|
|
* @param {Function} callback of the form `function (err, machine, res)`
|
2015-07-26 08:45:20 +03:00
|
|
|
*/
|
2015-09-04 21:04:45 +03:00
|
|
|
CloudApi.prototype.getMachine = function getMachine(id, cb) {
|
2015-08-27 00:09:50 +03:00
|
|
|
assert.uuid(id, 'id');
|
|
|
|
assert.func(cb, 'cb');
|
2015-07-26 08:45:20 +03:00
|
|
|
|
2015-11-04 01:40:59 +02:00
|
|
|
var endpoint = format('/%s/machines/%s', this.account, id);
|
2015-08-26 03:27:46 +03:00
|
|
|
this._request(endpoint, function (err, req, res, body) {
|
2015-08-27 03:08:52 +03:00
|
|
|
cb(err, body, res);
|
2015-07-26 08:45:20 +03:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-08-26 08:25:26 +03:00
|
|
|
/**
|
|
|
|
* delete a machine by id.
|
|
|
|
*
|
|
|
|
* @param {String} uuid (required) The machine id.
|
2015-11-05 22:30:06 +02:00
|
|
|
* @param {Function} callback of the form `function (err, res)`
|
2015-08-26 08:25:26 +03:00
|
|
|
*/
|
2015-09-04 21:04:45 +03:00
|
|
|
CloudApi.prototype.deleteMachine = function deleteMachine(uuid, callback) {
|
2015-08-26 08:25:26 +03:00
|
|
|
var self = this;
|
|
|
|
assert.string(uuid, 'uuid');
|
|
|
|
assert.func(callback, 'callback');
|
|
|
|
|
|
|
|
var opts = {
|
2015-11-04 01:40:59 +02:00
|
|
|
path: format('/%s/machines/%s', self.account, uuid),
|
2015-08-26 08:25:26 +03:00
|
|
|
method: 'DELETE'
|
|
|
|
};
|
2015-11-05 22:30:06 +02:00
|
|
|
this._request(opts, function (err, req, res) {
|
|
|
|
callback(err, res);
|
2015-08-26 08:25:26 +03:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-08-26 04:09:32 +03:00
|
|
|
/**
|
|
|
|
* start a machine by id.
|
|
|
|
*
|
|
|
|
* @param {String} uuid (required) The machine id.
|
2015-11-06 01:13:14 +02:00
|
|
|
* @param {Function} callback of the form `function (err, machine, res)`
|
2015-08-26 04:09:32 +03:00
|
|
|
*/
|
2015-09-04 21:04:45 +03:00
|
|
|
CloudApi.prototype.startMachine = function startMachine(uuid, callback) {
|
2015-08-26 04:09:32 +03:00
|
|
|
return this._doMachine('start', uuid, callback);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* stop a machine by id.
|
|
|
|
*
|
|
|
|
* @param {String} uuid (required) The machine id.
|
2015-11-06 01:13:14 +02:00
|
|
|
* @param {Function} callback of the form `function (err, machine, res)`
|
2015-08-26 04:09:32 +03:00
|
|
|
*/
|
2015-09-04 21:04:45 +03:00
|
|
|
CloudApi.prototype.stopMachine = function stopMachine(uuid, callback) {
|
2015-08-26 04:09:32 +03:00
|
|
|
return this._doMachine('stop', uuid, callback);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* reboot a machine by id.
|
|
|
|
*
|
|
|
|
* @param {String} uuid (required) The machine id.
|
2015-11-06 01:13:14 +02:00
|
|
|
* @param {Function} callback of the form `function (err, machine, res)`
|
2015-08-26 04:09:32 +03:00
|
|
|
*/
|
2015-09-04 21:04:45 +03:00
|
|
|
CloudApi.prototype.rebootMachine = function rebootMachine(uuid, callback) {
|
2015-08-26 04:09:32 +03:00
|
|
|
return this._doMachine('reboot', uuid, callback);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* internal function for start/stop/reboot
|
|
|
|
*/
|
2015-09-04 21:04:45 +03:00
|
|
|
CloudApi.prototype._doMachine = function _doMachine(action, uuid, callback) {
|
2015-08-26 04:09:32 +03:00
|
|
|
var self = this;
|
2015-08-26 04:46:14 +03:00
|
|
|
assert.string(action, 'action');
|
2015-08-26 04:09:32 +03:00
|
|
|
assert.string(uuid, 'uuid');
|
|
|
|
assert.func(callback, 'callback');
|
|
|
|
|
|
|
|
var opts = {
|
2015-11-04 01:40:59 +02:00
|
|
|
path: format('/%s/machines/%s', self.account, uuid),
|
2015-08-26 04:09:32 +03:00
|
|
|
method: 'POST',
|
|
|
|
data: {
|
|
|
|
action: action
|
|
|
|
}
|
|
|
|
};
|
|
|
|
this._request(opts, function (err, req, res, body) {
|
|
|
|
callback(err, body, res);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-08-26 04:46:14 +03:00
|
|
|
/**
|
2015-08-26 06:53:48 +03:00
|
|
|
* Wait for a machine to go one of a set of specfic states.
|
2015-08-26 04:46:14 +03:00
|
|
|
*
|
|
|
|
* @param {Object} options
|
|
|
|
* - {String} id - machine UUID
|
2015-08-26 06:53:48 +03:00
|
|
|
* - {Array of String} states - desired state
|
2015-08-26 04:46:14 +03:00
|
|
|
* - {Number} interval (optional) - time in ms to poll
|
|
|
|
* @param {Function} callback - called when state is reached or on error
|
|
|
|
*/
|
2015-09-04 21:04:45 +03:00
|
|
|
CloudApi.prototype.waitForMachineStates =
|
2015-09-02 20:47:06 +03:00
|
|
|
function waitForMachineStates(opts, callback) {
|
2015-08-26 04:46:14 +03:00
|
|
|
var self = this;
|
|
|
|
assert.object(opts, 'opts');
|
|
|
|
assert.string(opts.id, 'opts.id');
|
2015-08-26 06:53:48 +03:00
|
|
|
assert.arrayOfString(opts.states, 'opts.states');
|
2015-08-26 04:46:14 +03:00
|
|
|
assert.optionalNumber(opts.interval, 'opts.interval');
|
|
|
|
assert.func(callback, 'callback');
|
|
|
|
var interval = (opts.interval === undefined ? 1000 : opts.interval);
|
|
|
|
|
|
|
|
poll();
|
|
|
|
|
|
|
|
function poll() {
|
2015-08-26 08:25:26 +03:00
|
|
|
self.getMachine(opts.id, function (err, machine, res) {
|
2015-08-26 04:46:14 +03:00
|
|
|
if (err) {
|
2015-08-26 08:25:26 +03:00
|
|
|
callback(err, null, res);
|
2015-08-26 04:46:14 +03:00
|
|
|
return;
|
|
|
|
}
|
2015-08-26 06:53:48 +03:00
|
|
|
if (opts.states.indexOf(machine.state) !== -1) {
|
2015-08-26 08:25:26 +03:00
|
|
|
callback(null, machine, res);
|
2015-08-26 04:46:14 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
setTimeout(poll, interval);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2015-07-26 08:45:20 +03:00
|
|
|
|
2014-02-20 05:52:58 +02:00
|
|
|
/**
|
2015-11-04 01:40:59 +02:00
|
|
|
* List the account's machines.
|
2014-02-20 05:52:58 +02:00
|
|
|
* <http://apidocs.joyent.com/cloudapi/#ListMachines>
|
|
|
|
*
|
2015-08-26 02:46:14 +03:00
|
|
|
* @param {Object} options
|
|
|
|
* See document above
|
|
|
|
* @return {LOMStream} a stream for each machine entry
|
2014-02-20 05:52:58 +02:00
|
|
|
*/
|
2015-09-04 21:04:45 +03:00
|
|
|
CloudApi.prototype.createListMachinesStream =
|
2015-08-26 02:46:14 +03:00
|
|
|
function createListMachinesStream(options) {
|
|
|
|
var self = this;
|
2015-08-26 07:16:41 +03:00
|
|
|
options = options || {};
|
2015-08-26 02:46:14 +03:00
|
|
|
|
2015-11-04 01:40:59 +02:00
|
|
|
// If a `limit` is specified, we don't paginate.
|
2015-08-26 02:46:14 +03:00
|
|
|
var once = options.limit !== undefined;
|
|
|
|
|
|
|
|
return new LOMStream({
|
|
|
|
fetch: fetch,
|
|
|
|
limit: 1000,
|
|
|
|
offset: true
|
|
|
|
});
|
|
|
|
|
|
|
|
function fetch(fetcharg, limitObj, datacb, donecb) {
|
|
|
|
options.limit = limitObj.limit;
|
|
|
|
options.offset = limitObj.offset;
|
2015-11-04 01:40:59 +02:00
|
|
|
var endpoint = self._path(
|
|
|
|
format('/%s/machines', self.account), options);
|
2015-08-26 02:46:14 +03:00
|
|
|
|
|
|
|
self._request(endpoint, function (err, req, res, body) {
|
2015-09-21 20:33:42 +03:00
|
|
|
if (err) {
|
|
|
|
return donecb(err);
|
|
|
|
}
|
2015-08-26 02:46:14 +03:00
|
|
|
var resourcecount = res.headers['x-resource-count'];
|
|
|
|
var done = once || resourcecount < options.limit;
|
2015-09-21 20:33:42 +03:00
|
|
|
donecb(null, {done: done, results: body});
|
2015-08-26 02:46:14 +03:00
|
|
|
});
|
2014-02-20 05:52:58 +02:00
|
|
|
}
|
2015-08-26 02:46:14 +03:00
|
|
|
};
|
2014-02-20 05:52:58 +02:00
|
|
|
|
2015-08-26 02:46:14 +03:00
|
|
|
/**
|
2015-11-04 01:40:59 +02:00
|
|
|
* List the account's machines.
|
2015-08-26 02:46:14 +03:00
|
|
|
* <http://apidocs.joyent.com/cloudapi/#ListMachines>
|
|
|
|
*
|
|
|
|
* @param {Object} options
|
|
|
|
* See document above
|
|
|
|
* @param {Function} callback - called like `function (err, machines)`
|
|
|
|
*/
|
2015-09-04 21:04:45 +03:00
|
|
|
CloudApi.prototype.listMachines = function listMachines(options, callback) {
|
2015-08-26 07:16:41 +03:00
|
|
|
if (typeof (options) === 'function') {
|
|
|
|
callback = options;
|
|
|
|
options = {};
|
|
|
|
}
|
2015-08-26 02:46:14 +03:00
|
|
|
var machines = [];
|
|
|
|
var s = this.createListMachinesStream(options);
|
|
|
|
s.on('error', function (e) {
|
|
|
|
callback(e);
|
|
|
|
});
|
|
|
|
s.on('readable', function () {
|
|
|
|
var machine;
|
|
|
|
while ((machine = s.read()) !== null) {
|
|
|
|
machines.push(machine);
|
2014-02-20 05:52:58 +02:00
|
|
|
}
|
2015-08-26 02:46:14 +03:00
|
|
|
});
|
|
|
|
s.on('end', function () {
|
|
|
|
callback(null, machines);
|
|
|
|
});
|
2014-02-20 05:52:58 +02:00
|
|
|
};
|
|
|
|
|
2015-08-26 06:53:48 +03:00
|
|
|
|
2015-09-04 21:04:45 +03:00
|
|
|
CloudApi.prototype.createMachine = function createMachine(options, callback) {
|
2015-08-26 06:53:48 +03:00
|
|
|
assert.object(options, 'options');
|
|
|
|
assert.optionalString(options.name, 'options.name');
|
|
|
|
assert.uuid(options.image, 'options.image');
|
|
|
|
assert.uuid(options.package, 'options.package');
|
|
|
|
assert.optionalArrayOfUuid(options.networks, 'options.networks');
|
|
|
|
// TODO: assert the other fields
|
|
|
|
assert.func(callback, 'callback');
|
|
|
|
|
|
|
|
// XXX how does options.networks array work here?
|
|
|
|
this._request({
|
|
|
|
method: 'POST',
|
2015-11-04 01:40:59 +02:00
|
|
|
path: format('/%s/machines', this.account),
|
2015-09-03 07:02:09 +03:00
|
|
|
data: options
|
2015-08-26 06:53:48 +03:00
|
|
|
}, function (err, req, res, body) {
|
|
|
|
callback(err, body, res);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-07-26 08:45:20 +03:00
|
|
|
/**
|
|
|
|
* List machine audit (successful actions on the machine).
|
|
|
|
*
|
|
|
|
* XXX IMO this endpoint should be called ListMachineAudit in cloudapi.
|
|
|
|
*
|
2015-09-08 19:41:31 +03:00
|
|
|
* @param {String} id (required) The machine id.
|
2015-11-06 01:13:14 +02:00
|
|
|
* @param {Function} callback of the form `function (err, audit, res)`
|
2015-07-26 08:45:20 +03:00
|
|
|
*/
|
2015-09-08 19:41:31 +03:00
|
|
|
CloudApi.prototype.machineAudit = function machineAudit(id, cb) {
|
|
|
|
assert.uuid(id, 'id');
|
|
|
|
assert.func(cb, 'cb');
|
2015-07-26 08:45:20 +03:00
|
|
|
|
2015-11-04 01:40:59 +02:00
|
|
|
var endpoint = format('/%s/machines/%s/audit', this.account, id);
|
2015-09-08 19:41:31 +03:00
|
|
|
this._request(endpoint, function (err, req, res, body) {
|
|
|
|
cb(err, body, res);
|
2015-07-26 08:45:20 +03:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-11-04 01:40:59 +02:00
|
|
|
// --- rbac
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <http://apidocs.joyent.com/cloudapi/#ListUsers>
|
|
|
|
*
|
|
|
|
* @param opts {Object} Options (optional)
|
|
|
|
* @param cb {Function} Callback of the form `function (err, users, res)`
|
|
|
|
*/
|
|
|
|
CloudApi.prototype.listUsers = function listUsers(opts, cb) {
|
|
|
|
if (cb === undefined) {
|
|
|
|
cb = opts;
|
|
|
|
opts = {};
|
|
|
|
}
|
|
|
|
assert.func(cb, 'cb');
|
|
|
|
assert.object(opts, 'opts');
|
|
|
|
|
|
|
|
var endpoint = format('/%s/users', this.account);
|
|
|
|
this._passThrough(endpoint, opts, cb);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <http://apidocs.joyent.com/cloudapi/#GetUser>
|
|
|
|
*
|
|
|
|
* @param {Object} opts
|
|
|
|
* - id {UUID|String} The user ID or login.
|
|
|
|
* - membership {Boolean} Optional. Whether to includes roles of which
|
|
|
|
* this user is a member. Default false.
|
|
|
|
* @param {Function} callback of the form `function (err, user, res)`
|
|
|
|
*/
|
|
|
|
CloudApi.prototype.getUser = function getUser(opts, cb) {
|
|
|
|
assert.object(opts, 'opts');
|
|
|
|
assert.string(opts.id, 'opts.id');
|
|
|
|
assert.optionalBool(opts.membership, 'opts.membership');
|
|
|
|
assert.func(cb, 'cb');
|
|
|
|
|
|
|
|
var endpoint = format('/%s/users/%s', this.account, opts.id);
|
|
|
|
this._passThrough(endpoint, {membership: opts.membership}, cb);
|
|
|
|
};
|
|
|
|
|
2015-11-04 10:11:19 +02:00
|
|
|
/**
|
|
|
|
* <http://apidocs.joyent.com/cloudapi/#CreateUser>
|
|
|
|
*
|
|
|
|
* @param {Object} opts (object) user object containing:
|
|
|
|
* - {String} login (required) for your user.
|
|
|
|
* - {String} password (required) for the user.
|
|
|
|
* - {String} email (required) for the user.
|
|
|
|
* - {String} companyName (optional) for the user.
|
|
|
|
* - {String} firstName (optional) for the user.
|
|
|
|
* - {String} lastName (optional) for the user.
|
|
|
|
* - {String} address (optional) for the user.
|
|
|
|
* - {String} postalCode (optional) for the user.
|
|
|
|
* - {String} city (optional) for the user.
|
|
|
|
* - {String} state (optional) for the user.
|
|
|
|
* - {String} country (optional) for the user.
|
|
|
|
* - {String} phone (optional) for the user.
|
|
|
|
* @param {Function} cb of the form `function (err, user, res)`
|
|
|
|
*/
|
|
|
|
CloudApi.prototype.createUser = function createUser(opts, cb) {
|
|
|
|
assert.object(opts, 'opts');
|
|
|
|
assert.string(opts.login, 'opts.login');
|
|
|
|
assert.string(opts.password, 'opts.password');
|
|
|
|
assert.string(opts.email, 'opts.email');
|
|
|
|
// XXX strict on inputs
|
|
|
|
assert.func(cb, 'cb');
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
login: opts.login,
|
|
|
|
password: opts.password,
|
|
|
|
email: opts.email,
|
|
|
|
companyName: opts.companyName,
|
|
|
|
firstName: opts.firstName,
|
|
|
|
lastName: opts.lastName,
|
|
|
|
address: opts.address,
|
|
|
|
postalCode: opts.postalCode,
|
|
|
|
city: opts.city,
|
|
|
|
state: opts.state,
|
|
|
|
country: opts.country,
|
|
|
|
phone: opts.phone
|
|
|
|
};
|
|
|
|
|
|
|
|
this._request({
|
|
|
|
method: 'POST',
|
|
|
|
path: format('/%s/users', this.account),
|
|
|
|
data: data
|
|
|
|
}, function (err, req, res, body) {
|
|
|
|
cb(err, body, res);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <http://apidocs.joyent.com/cloudapi/#UpdateUser>
|
|
|
|
*
|
|
|
|
* @param {Object} opts (object) user object containing:
|
2015-11-18 22:54:44 +02:00
|
|
|
* - {String} id (required) for your user. This can be either the user
|
|
|
|
* login, or the user id (UUID)
|
|
|
|
* - {String} login (optional)
|
|
|
|
* - {String} email (optional)
|
|
|
|
* - {String} companyName (optional)
|
|
|
|
* - {String} firstName (optional)
|
|
|
|
* - {String} lastName (optional)
|
|
|
|
* - {String} address (optional)
|
|
|
|
* - {String} postalCode (optional)
|
|
|
|
* - {String} city (optional)
|
|
|
|
* - {String} state (optional)
|
|
|
|
* - {String} country (optional)
|
|
|
|
* - {String} phone (optional)
|
2015-11-04 10:11:19 +02:00
|
|
|
* @param {Function} cb of the form `function (err, user, res)`
|
|
|
|
*/
|
|
|
|
CloudApi.prototype.updateUser = function updateUser(opts, cb) {
|
|
|
|
assert.object(opts, 'opts');
|
|
|
|
assert.string(opts.id, 'opts.id');
|
|
|
|
// XXX strict on inputs
|
|
|
|
assert.func(cb, 'cb');
|
|
|
|
|
|
|
|
var update = {
|
2015-11-18 22:54:44 +02:00
|
|
|
login: opts.login,
|
2015-11-04 10:11:19 +02:00
|
|
|
email: opts.email,
|
|
|
|
companyName: opts.companyName,
|
|
|
|
firstName: opts.firstName,
|
|
|
|
lastName: opts.lastName,
|
|
|
|
address: opts.address,
|
|
|
|
postalCode: opts.postalCode,
|
|
|
|
city: opts.city,
|
|
|
|
state: opts.state,
|
|
|
|
country: opts.country,
|
|
|
|
phone: opts.phone
|
|
|
|
};
|
|
|
|
|
|
|
|
this._request({
|
|
|
|
method: 'POST',
|
|
|
|
path: format('/%s/users/%s', this.account, opts.id),
|
|
|
|
data: update
|
|
|
|
}, function (err, req, res, body) {
|
|
|
|
cb(err, body, res);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <http://apidocs.joyent.com/cloudapi/#DeleteUser>
|
|
|
|
*
|
2015-11-05 22:30:06 +02:00
|
|
|
* @param {Object} opts (object)
|
2015-11-04 10:11:19 +02:00
|
|
|
* - {String} id (required) for your user.
|
2015-11-05 22:30:06 +02:00
|
|
|
* @param {Function} cb of the form `function (err, res)`
|
2015-11-04 10:11:19 +02:00
|
|
|
*/
|
|
|
|
CloudApi.prototype.deleteUser = function deleteUser(opts, cb) {
|
|
|
|
assert.object(opts, 'opts');
|
|
|
|
assert.string(opts.id, 'opts.id');
|
|
|
|
assert.func(cb, 'cb');
|
|
|
|
|
|
|
|
this._request({
|
|
|
|
method: 'DELETE',
|
|
|
|
path: format('/%s/users/%s', this.account, opts.id)
|
2015-11-05 22:30:06 +02:00
|
|
|
}, function (err, req, res) {
|
|
|
|
cb(err, res);
|
2015-11-04 10:11:19 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-11-04 01:40:59 +02:00
|
|
|
|
2015-11-06 01:13:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* List RBAC user's SSH keys.
|
|
|
|
*
|
|
|
|
* @param {Object} opts (object)
|
|
|
|
* - {String} userId (required) The user id or login.
|
|
|
|
* @param {Function} callback of the form `function (err, userKeys, res)`
|
|
|
|
*/
|
|
|
|
CloudApi.prototype.listUserKeys = function listUserKeys(opts, cb) {
|
|
|
|
assert.object(opts, 'opts');
|
|
|
|
assert.string(opts.userId, 'opts.userId');
|
|
|
|
assert.func(cb, 'cb');
|
|
|
|
|
|
|
|
var endpoint = format('/%s/users/%s/keys', this.account, opts.userId);
|
2015-11-18 22:54:44 +02:00
|
|
|
this._passThrough(endpoint, {}, cb);
|
2015-11-06 01:13:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a RBAC user's SSH key.
|
|
|
|
*
|
|
|
|
* @param {Object} opts (object)
|
|
|
|
* - {String} userId (required) The user id or login.
|
|
|
|
* - {String} fingerprint (required*) The SSH key fingerprint. One of
|
|
|
|
* 'fingerprint' or 'name' is required.
|
|
|
|
* - {String} name (required*) The SSH key name. One of 'fingerprint'
|
|
|
|
* or 'name' is required.
|
|
|
|
* @param {Function} callback of the form `function (err, userKey, res)`
|
|
|
|
*/
|
|
|
|
CloudApi.prototype.getUserKey = function getUserKey(opts, cb) {
|
|
|
|
assert.object(opts, 'opts');
|
|
|
|
assert.string(opts.userId, 'opts.userId');
|
|
|
|
assert.optionalString(opts.fingerprint, 'opts.fingerprint');
|
|
|
|
assert.optionalString(opts.name, 'opts.name');
|
|
|
|
assert.ok(opts.fingerprint || opts.name,
|
|
|
|
'one of "fingerprint" or "name" is require');
|
|
|
|
assert.func(cb, 'cb');
|
|
|
|
|
|
|
|
var endpoint = format('/%s/users/%s/keys/%s', this.account, opts.userId,
|
|
|
|
encodeURIComponent(opts.fingerprint || opts.name));
|
|
|
|
this._passThrough(endpoint, {}, cb);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create/upload a new RBAC user SSH public key.
|
|
|
|
*
|
|
|
|
* @param {Object} opts (object)
|
|
|
|
* - {String} userId (required) The user id or login.
|
|
|
|
* - {String} key (required) The SSH public key content.
|
|
|
|
* - {String} name (optional) A name for the key. If not given, the
|
|
|
|
* key fingerprint will be used.
|
|
|
|
* @param {Function} callback of the form `function (err, userKey, res)`
|
|
|
|
*/
|
|
|
|
CloudApi.prototype.createUserKey = function createUserKey(opts, cb) {
|
|
|
|
assert.object(opts, 'opts');
|
|
|
|
assert.string(opts.userId, 'opts.userId');
|
|
|
|
assert.string(opts.key, 'opts.key');
|
|
|
|
assert.optionalString(opts.name, 'opts.name');
|
|
|
|
assert.func(cb, 'cb');
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
name: opts.name,
|
|
|
|
key: opts.key
|
|
|
|
};
|
|
|
|
|
|
|
|
this._request({
|
|
|
|
method: 'POST',
|
|
|
|
path: format('/%s/users/%s/keys', this.account, opts.userId),
|
|
|
|
data: data
|
|
|
|
}, function (err, req, res, body) {
|
|
|
|
cb(err, body, res);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a RBAC user's SSH key.
|
|
|
|
*
|
|
|
|
* @param {Object} opts (object)
|
|
|
|
* - {String} userId (required) The user id or login.
|
|
|
|
* - {String} fingerprint (required*) The SSH key fingerprint. One of
|
|
|
|
* 'fingerprint' or 'name' is required.
|
|
|
|
* - {String} name (required*) The SSH key name. One of 'fingerprint'
|
|
|
|
* or 'name' is required.
|
|
|
|
* @param {Function} callback of the form `function (err, res)`
|
|
|
|
*/
|
|
|
|
CloudApi.prototype.deleteUserKey = function deleteUserKey(opts, cb) {
|
|
|
|
assert.object(opts, 'opts');
|
|
|
|
assert.string(opts.userId, 'opts.userId');
|
|
|
|
assert.optionalString(opts.fingerprint, 'opts.fingerprint');
|
|
|
|
assert.optionalString(opts.name, 'opts.name');
|
|
|
|
assert.ok(opts.fingerprint || opts.name,
|
|
|
|
'one of "fingerprint" or "name" is require');
|
|
|
|
assert.func(cb, 'cb');
|
|
|
|
|
|
|
|
this._request({
|
|
|
|
method: 'DELETE',
|
|
|
|
path: format('/%s/users/%s/keys/%s', this.account, opts.userId,
|
|
|
|
encodeURIComponent(opts.fingerprint || opts.name))
|
|
|
|
}, function (err, req, res) {
|
|
|
|
cb(err, res);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-11-05 01:38:38 +02:00
|
|
|
/**
|
|
|
|
* <http://apidocs.joyent.com/cloudapi/#ListRoles>
|
|
|
|
*
|
|
|
|
* @param opts {Object} Options (optional)
|
|
|
|
* @param cb {Function} Callback of the form `function (err, roles, res)`
|
|
|
|
*/
|
|
|
|
CloudApi.prototype.listRoles = function listRoles(opts, cb) {
|
|
|
|
if (cb === undefined) {
|
|
|
|
cb = opts;
|
|
|
|
opts = {};
|
|
|
|
}
|
|
|
|
assert.func(cb, 'cb');
|
|
|
|
assert.object(opts, 'opts');
|
|
|
|
|
|
|
|
var endpoint = format('/%s/roles', this.account);
|
|
|
|
this._passThrough(endpoint, opts, cb);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <http://apidocs.joyent.com/cloudapi/#GetRole>
|
|
|
|
*
|
|
|
|
* @param {Object} opts
|
|
|
|
* - id {UUID|String} The role ID or name.
|
2015-11-05 22:30:06 +02:00
|
|
|
* @param {Function} callback of the form `function (err, role, res)`
|
2015-11-05 01:38:38 +02:00
|
|
|
*/
|
|
|
|
CloudApi.prototype.getRole = function getRole(opts, cb) {
|
|
|
|
assert.object(opts, 'opts');
|
|
|
|
assert.string(opts.id, 'opts.id');
|
|
|
|
assert.func(cb, 'cb');
|
|
|
|
|
|
|
|
var endpoint = format('/%s/roles/%s', this.account, opts.id);
|
|
|
|
this._passThrough(endpoint, {}, cb);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <http://apidocs.joyent.com/cloudapi/#CreateRole>
|
|
|
|
*
|
|
|
|
* @param {Object} opts (object) role object containing:
|
|
|
|
* - {String} name (required) for the role.
|
|
|
|
* - {Array} members (optional) for the role.
|
|
|
|
* - {Array} default_members (optional) for the role.
|
|
|
|
* - {Array} policies (optional) for the role.
|
|
|
|
* @param {Function} cb of the form `function (err, role, res)`
|
|
|
|
*/
|
|
|
|
CloudApi.prototype.createRole = function createRole(opts, cb) {
|
|
|
|
assert.object(opts, 'opts');
|
|
|
|
assert.string(opts.name, 'opts.name');
|
|
|
|
// XXX strict on inputs
|
|
|
|
assert.func(cb, 'cb');
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
name: opts.name,
|
|
|
|
default_members: opts.default_members,
|
|
|
|
members: opts.members,
|
|
|
|
policies: opts.policies
|
|
|
|
};
|
|
|
|
|
|
|
|
this._request({
|
|
|
|
method: 'POST',
|
|
|
|
path: format('/%s/roles', this.account),
|
|
|
|
data: data
|
|
|
|
}, function (err, req, res, body) {
|
|
|
|
cb(err, body, res);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <http://apidocs.joyent.com/cloudapi/#UpdateRole>
|
|
|
|
*
|
|
|
|
* @param {Object} opts (object) role object containing:
|
|
|
|
* - {UUID|String} id (required) The role ID or name.
|
|
|
|
* - {String} name (optional) for the role.
|
|
|
|
* - {Array} members (optional) for the role.
|
|
|
|
* - {Array} default_members (optional) for the role.
|
|
|
|
* - {Array} policies (optional) for the role.
|
|
|
|
* @param {Function} cb of the form `function (err, role, res)`
|
|
|
|
*/
|
|
|
|
CloudApi.prototype.updateRole = function updateRole(opts, cb) {
|
|
|
|
assert.object(opts, 'opts');
|
|
|
|
assert.string(opts.id, 'opts.id');
|
|
|
|
// XXX strict on inputs
|
|
|
|
assert.func(cb, 'cb');
|
|
|
|
|
|
|
|
var update = {
|
|
|
|
name: opts.name,
|
|
|
|
members: opts.members,
|
|
|
|
default_members: opts.default_members,
|
|
|
|
policies: opts.policies
|
|
|
|
};
|
|
|
|
|
|
|
|
this._request({
|
|
|
|
method: 'POST',
|
|
|
|
path: format('/%s/roles/%s', this.account, opts.id),
|
|
|
|
data: update
|
|
|
|
}, function (err, req, res, body) {
|
|
|
|
cb(err, body, res);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <http://apidocs.joyent.com/cloudapi/#DeleteRole>
|
|
|
|
*
|
2015-11-05 22:30:06 +02:00
|
|
|
* @param {Object} opts (object)
|
2015-11-05 01:38:38 +02:00
|
|
|
* - {String} id (required) of the role to delete.
|
2015-11-05 22:30:06 +02:00
|
|
|
* @param {Function} cb of the form `function (err, res)`
|
2015-11-05 01:38:38 +02:00
|
|
|
*/
|
|
|
|
CloudApi.prototype.deleteRole = function deleteRole(opts, cb) {
|
|
|
|
assert.object(opts, 'opts');
|
|
|
|
assert.string(opts.id, 'opts.id');
|
|
|
|
assert.func(cb, 'cb');
|
|
|
|
|
|
|
|
this._request({
|
|
|
|
method: 'DELETE',
|
|
|
|
path: format('/%s/roles/%s', this.account, opts.id)
|
2015-11-05 22:30:06 +02:00
|
|
|
}, function (err, req, res) {
|
|
|
|
cb(err, res);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <http://apidocs.joyent.com/cloudapi/#ListPolicies>
|
|
|
|
*
|
|
|
|
* @param opts {Object} Options (optional)
|
|
|
|
* @param cb {Function} Callback of the form `function (err, policies, res)`
|
|
|
|
*/
|
|
|
|
CloudApi.prototype.listPolicies = function listPolicies(opts, cb) {
|
|
|
|
if (cb === undefined) {
|
|
|
|
cb = opts;
|
|
|
|
opts = {};
|
|
|
|
}
|
|
|
|
assert.func(cb, 'cb');
|
|
|
|
assert.object(opts, 'opts');
|
|
|
|
|
|
|
|
var endpoint = format('/%s/policies', this.account);
|
|
|
|
this._passThrough(endpoint, opts, cb);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <http://apidocs.joyent.com/cloudapi/#GetPolicy>
|
|
|
|
*
|
|
|
|
* @param {Object} opts
|
|
|
|
* - id {UUID|String} The policy ID or name.
|
|
|
|
* @param {Function} callback of the form `function (err, policy, res)`
|
|
|
|
*/
|
|
|
|
CloudApi.prototype.getPolicy = function getPolicy(opts, cb) {
|
|
|
|
assert.object(opts, 'opts');
|
|
|
|
assert.string(opts.id, 'opts.id');
|
|
|
|
assert.func(cb, 'cb');
|
|
|
|
|
|
|
|
var endpoint = format('/%s/policies/%s', this.account, opts.id);
|
|
|
|
this._passThrough(endpoint, {}, cb);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <http://apidocs.joyent.com/cloudapi/#CreatePolicy>
|
|
|
|
*
|
|
|
|
* @param {Object} opts (object) policy object containing:
|
|
|
|
* - {String} name (required) for the policy.
|
|
|
|
* - {Array} description (optional) for the policy.
|
|
|
|
* - {Array} rules (optional) for the policy.
|
|
|
|
* @param {Function} cb of the form `function (err, policy, res)`
|
|
|
|
*/
|
|
|
|
CloudApi.prototype.createPolicy = function createPolicy(opts, cb) {
|
|
|
|
assert.object(opts, 'opts');
|
|
|
|
assert.string(opts.name, 'opts.name');
|
|
|
|
// XXX strict on inputs
|
|
|
|
assert.func(cb, 'cb');
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
name: opts.name,
|
|
|
|
description: opts.description,
|
|
|
|
rules: opts.rules
|
|
|
|
};
|
|
|
|
|
|
|
|
this._request({
|
|
|
|
method: 'POST',
|
|
|
|
path: format('/%s/policies', this.account),
|
|
|
|
data: data
|
2015-11-05 01:38:38 +02:00
|
|
|
}, function (err, req, res, body) {
|
|
|
|
cb(err, body, res);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-11-05 22:30:06 +02:00
|
|
|
/**
|
|
|
|
* <http://apidocs.joyent.com/cloudapi/#UpdatePolicy>
|
|
|
|
*
|
|
|
|
* @param {Object} opts (object) policy object containing:
|
|
|
|
* - {UUID|String} id (required) The policy ID or name.
|
|
|
|
* - {String} name (optional)
|
|
|
|
* - {String} description (optional)
|
|
|
|
* - {Array} rules (optional)
|
|
|
|
* @param {Function} cb of the form `function (err, policy, res)`
|
|
|
|
*/
|
|
|
|
CloudApi.prototype.updatePolicy = function updatePolicy(opts, cb) {
|
|
|
|
assert.object(opts, 'opts');
|
|
|
|
assert.string(opts.id, 'opts.id');
|
|
|
|
// XXX strict on inputs
|
|
|
|
assert.func(cb, 'cb');
|
|
|
|
|
|
|
|
var update = {
|
|
|
|
name: opts.name,
|
|
|
|
description: opts.description,
|
|
|
|
rules: opts.rules
|
|
|
|
};
|
|
|
|
|
|
|
|
this._request({
|
|
|
|
method: 'POST',
|
|
|
|
path: format('/%s/policies/%s', this.account, opts.id),
|
|
|
|
data: update
|
|
|
|
}, function (err, req, res, body) {
|
|
|
|
cb(err, body, res);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <http://apidocs.joyent.com/cloudapi/#DeletePolicy>
|
|
|
|
*
|
|
|
|
* @param {Object} opts (object) user object containing:
|
|
|
|
* - {String} id (required) of the policy to delete.
|
|
|
|
* @param {Function} cb of the form `function (err, res)`
|
|
|
|
*/
|
|
|
|
CloudApi.prototype.deletePolicy = function deletePolicy(opts, cb) {
|
|
|
|
assert.object(opts, 'opts');
|
|
|
|
assert.string(opts.id, 'opts.id');
|
|
|
|
assert.func(cb, 'cb');
|
|
|
|
|
|
|
|
this._request({
|
|
|
|
method: 'DELETE',
|
|
|
|
path: format('/%s/policies/%s', this.account, opts.id)
|
|
|
|
}, function (err, req, res) {
|
|
|
|
cb(err, res);
|
|
|
|
});
|
|
|
|
};
|
2015-11-05 01:38:38 +02:00
|
|
|
|
2015-11-04 01:40:59 +02:00
|
|
|
|
2015-11-13 02:04:12 +02:00
|
|
|
// ---- RBAC role tag support functions
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <http://apidocs.joyent.com/cloudapi/#role-tags>
|
|
|
|
* Get RBAC role-tags on a resource. Technically there isn't a separate
|
|
|
|
* specific API endpoint for this -- it is the Get$Resource endpoint instead.
|
|
|
|
*
|
|
|
|
* @param {Object} opts:
|
|
|
|
* - {String} resource (required) The resource URL. E.g.
|
|
|
|
* '/:account/machines/:uuid' to tag a particular machine instance.
|
|
|
|
* @param {Function} cb of the form `function (err, roleTags, resource, res)`
|
|
|
|
* @throws {AssertionError, TypeError} on invalid inputs
|
|
|
|
*/
|
|
|
|
CloudApi.prototype.getRoleTags = function getRoleTags(opts, cb) {
|
|
|
|
assert.object(opts, 'opts');
|
|
|
|
assert.string(opts.resource, 'opts.resource');
|
|
|
|
assert.func(cb, 'cb');
|
|
|
|
|
|
|
|
// Validate `resource`.
|
|
|
|
// TODO: share this validation with `setRoleTags`.
|
|
|
|
var resourceRe = new RegExp('^/[^/]{2,}/[^/]+');
|
|
|
|
if (! resourceRe.test(opts.resource)) {
|
|
|
|
throw new TypeError(format('invalid resource "%s": must match ' +
|
|
|
|
'"/:account/:type..."', opts.resource));
|
|
|
|
}
|
|
|
|
|
|
|
|
var validResources = [
|
|
|
|
'machines',
|
|
|
|
'packages',
|
|
|
|
'images',
|
|
|
|
'fwrules',
|
|
|
|
'networks',
|
|
|
|
// TODO: validate/test role tags on these rbac resources
|
|
|
|
'users',
|
|
|
|
'roles',
|
|
|
|
'policies',
|
|
|
|
// TODO: validate, test
|
|
|
|
'keys',
|
|
|
|
'datacenters',
|
|
|
|
'analytics',
|
|
|
|
'instrumentations'
|
|
|
|
];
|
|
|
|
var parts = opts.resource.split('/');
|
|
|
|
if (validResources.indexOf(parts[2]) === -1) {
|
|
|
|
throw new TypeError(format('invalid resource "%s": resource type ' +
|
|
|
|
'must be one of: %s', opts.resource, validResources.join(', ')));
|
|
|
|
}
|
|
|
|
|
|
|
|
function roleTagsFromRes(res) {
|
|
|
|
return (
|
|
|
|
(res.headers['role-tag'] || '')
|
|
|
|
/* JSSTYLED */
|
|
|
|
.split(/\s*,\s*/)
|
|
|
|
.filter(function (r) { return r.trim(); })
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
this._request({
|
|
|
|
/*
|
|
|
|
* We use GET instead of HEAD to also be able to return the
|
|
|
|
* resource JSON. Technically we *could* drop support for that from
|
|
|
|
* this API, but `tritonapi.js` is using it.
|
|
|
|
*/
|
|
|
|
method: 'GET',
|
|
|
|
path: opts.resource
|
|
|
|
}, function (err, req, res, body) {
|
|
|
|
if (err) {
|
|
|
|
cb(err, null, res);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var roleTags = roleTagsFromRes(res);
|
|
|
|
cb(err, roleTags, body, res);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-11-10 01:09:37 +02:00
|
|
|
/**
|
|
|
|
* <http://apidocs.joyent.com/cloudapi/#SetRoleTags>
|
|
|
|
* Set RBAC role-tags on a resource.
|
|
|
|
*
|
|
|
|
* @param {Object} opts (object):
|
|
|
|
* - {String} resource (required) The resource URL. E.g.
|
|
|
|
* '/:account/machines/:uuid' to tag a particular machine instance.
|
|
|
|
* - {Array} roleTags (required) the array of role tags to set. Each
|
|
|
|
* role tag string is the name of a RBAC role. See `ListRoles`.
|
|
|
|
* @param {Function} cb of the form `function (err, body, res)`
|
|
|
|
* Where `body` is of the form `{name: <resource url>,
|
|
|
|
* 'role-tag': <array of added role tags>}`.
|
|
|
|
* @throws {AssertionError, TypeError} on invalid inputs
|
|
|
|
*/
|
|
|
|
CloudApi.prototype.setRoleTags = function setRoleTags(opts, cb) {
|
|
|
|
assert.object(opts, 'opts');
|
|
|
|
assert.string(opts.resource, 'opts.resource');
|
|
|
|
assert.arrayOfString(opts.roleTags, 'opts.roleTags');
|
|
|
|
assert.func(cb, 'cb');
|
|
|
|
|
|
|
|
// Validate `resource`.
|
|
|
|
var resourceRe = new RegExp('^/[^/]{2,}/[^/]+');
|
|
|
|
if (! resourceRe.test(opts.resource)) {
|
|
|
|
throw new TypeError(format('invalid resource "%s": must match ' +
|
|
|
|
'"/:account/:type..."', opts.resource));
|
|
|
|
}
|
|
|
|
|
|
|
|
var validResources = [
|
|
|
|
'machines',
|
|
|
|
'packages',
|
|
|
|
'images',
|
|
|
|
'fwrules',
|
|
|
|
'networks',
|
|
|
|
// TODO: validate/test role tags on these rbac resources
|
|
|
|
'users',
|
|
|
|
'roles',
|
|
|
|
'policies',
|
|
|
|
// TODO: validate, test
|
|
|
|
'keys',
|
|
|
|
'datacenters',
|
|
|
|
'analytics',
|
|
|
|
'instrumentations'
|
|
|
|
];
|
|
|
|
var parts = opts.resource.split('/');
|
|
|
|
if (validResources.indexOf(parts[2]) === -1) {
|
|
|
|
throw new TypeError(format('invalid resource "%s": resource type ' +
|
|
|
|
'must be one of: %s', opts.resource, validResources.join(', ')));
|
|
|
|
}
|
|
|
|
|
|
|
|
this._request({
|
|
|
|
method: 'PUT',
|
|
|
|
path: opts.resource,
|
|
|
|
data: {
|
|
|
|
'role-tag': opts.roleTags
|
|
|
|
}
|
|
|
|
}, function (err, req, res, body) {
|
|
|
|
cb(err, body, res);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-20 05:52:58 +02:00
|
|
|
// --- Exports
|
|
|
|
|
2015-09-30 01:13:34 +03:00
|
|
|
module.exports.createClient = function (options) {
|
|
|
|
return new CloudApi(options);
|
2014-02-20 05:52:58 +02:00
|
|
|
};
|