2017-05-27 19:35:38 +03:00
|
|
|
'use strict';
|
|
|
|
|
2017-06-02 00:25:45 +03:00
|
|
|
const Yamljs = require('yamljs');
|
2017-07-05 16:33:16 +03:00
|
|
|
const ParamCase = require('param-case');
|
2017-06-02 00:25:45 +03:00
|
|
|
|
2017-07-05 16:33:16 +03:00
|
|
|
const clean = (v) => {
|
|
|
|
return JSON.parse(JSON.stringify(v));
|
|
|
|
};
|
2017-05-27 19:35:38 +03:00
|
|
|
|
2017-06-05 23:54:44 +03:00
|
|
|
exports.fromPortal = function ({ portal, datacenter, deploymentGroups, user }) {
|
2017-05-27 19:35:38 +03:00
|
|
|
return {
|
|
|
|
id: portal.id,
|
2017-06-05 23:54:44 +03:00
|
|
|
user,
|
2017-05-27 19:35:38 +03:00
|
|
|
datacenter,
|
2017-06-08 00:35:45 +03:00
|
|
|
deploymentGroups
|
2017-05-27 19:35:38 +03:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.toPortal = function (clientPortal) {
|
|
|
|
return {
|
2017-06-05 23:54:44 +03:00
|
|
|
user_id: clientPortal.user ? clientPortal.user.id : '',
|
2017-05-27 19:35:38 +03:00
|
|
|
datacenter_id: clientPortal.datacenter ? clientPortal.datacenter.id : '',
|
|
|
|
deployment_group_ids: clientPortal.deploymentGroups ? clientPortal.deploymentGroups.map((deploymentGroup) => {
|
|
|
|
return deploymentGroup.id;
|
|
|
|
}) : []
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-06-02 00:25:45 +03:00
|
|
|
|
2017-06-27 18:15:27 +03:00
|
|
|
exports.fromDeploymentGroup = function (deploymentGroup) {
|
2017-05-27 19:35:38 +03:00
|
|
|
return {
|
|
|
|
id: deploymentGroup.id,
|
|
|
|
name: deploymentGroup.name,
|
|
|
|
slug: deploymentGroup.slug,
|
2017-06-27 18:15:27 +03:00
|
|
|
services: deploymentGroup.services,
|
|
|
|
version: deploymentGroup.version,
|
2017-07-05 16:33:16 +03:00
|
|
|
history: deploymentGroup.history,
|
|
|
|
imported: deploymentGroup.imported,
|
|
|
|
status: deploymentGroup.status
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.toDeploymentGroup = function (clientDeploymentGroup) {
|
|
|
|
return clean({
|
|
|
|
id: clientDeploymentGroup.id,
|
|
|
|
name: clientDeploymentGroup.name,
|
|
|
|
slug: clientDeploymentGroup.slug ?
|
|
|
|
clientDeploymentGroup.slug :
|
|
|
|
clientDeploymentGroup.name ?
|
|
|
|
ParamCase(clientDeploymentGroup.name) :
|
|
|
|
undefined,
|
|
|
|
service_ids: Array.isArray(clientDeploymentGroup.services) ? clientDeploymentGroup.services.map(({ id }) => {
|
|
|
|
return id;
|
|
|
|
}).filter(Boolean) : undefined,
|
|
|
|
version_id: clientDeploymentGroup.version ? clientDeploymentGroup.version.id : undefined,
|
|
|
|
history_version_ids: Array.isArray(clientDeploymentGroup.history) ? clientDeploymentGroup.history.map(({ id }) => {
|
|
|
|
return id;
|
|
|
|
}).filter(Boolean) : undefined,
|
|
|
|
imported: clientDeploymentGroup.imported,
|
|
|
|
status: clientDeploymentGroup.status || 'ACTIVE'
|
|
|
|
});
|
2017-05-31 01:08:06 +03:00
|
|
|
};
|
|
|
|
|
2017-05-27 19:35:38 +03:00
|
|
|
|
2017-05-31 22:27:53 +03:00
|
|
|
exports.fromService = function ({ service, instances, packages }) {
|
|
|
|
return {
|
|
|
|
id: service.id,
|
|
|
|
hash: service.version_hash,
|
2017-06-02 00:25:45 +03:00
|
|
|
deploymentGroupId: service.deployment_group_id,
|
2017-05-31 22:27:53 +03:00
|
|
|
name: service.name,
|
|
|
|
slug: service.slug,
|
2017-06-08 23:50:12 +03:00
|
|
|
instances,
|
2017-05-31 22:27:53 +03:00
|
|
|
connections: service.service_dependency_ids,
|
2017-07-05 16:33:16 +03:00
|
|
|
parent: service.parent_id,
|
|
|
|
config: service.config ? service.config : undefined,
|
2017-07-05 16:33:16 +03:00
|
|
|
status: service.status,
|
|
|
|
hasPlan: service.has_plan
|
2017-05-31 22:27:53 +03:00
|
|
|
};
|
|
|
|
};
|
2017-05-27 19:35:38 +03:00
|
|
|
|
2017-05-31 22:27:53 +03:00
|
|
|
exports.toService = function (clientService) {
|
2017-06-22 20:09:13 +03:00
|
|
|
// wat??
|
2017-07-05 16:33:16 +03:00
|
|
|
return clean({
|
2017-06-22 20:09:13 +03:00
|
|
|
id: clientService.id,
|
2017-07-05 16:33:16 +03:00
|
|
|
version_hash: clientService.hash,
|
2017-06-02 00:25:45 +03:00
|
|
|
deployment_group_id: clientService.deploymentGroupId,
|
2017-05-31 22:27:53 +03:00
|
|
|
name: clientService.name,
|
2017-06-28 13:06:27 +03:00
|
|
|
slug: clientService.slug,
|
2017-07-05 16:33:16 +03:00
|
|
|
instance_ids: clientService.instances ?
|
|
|
|
clientService.instances.map((instance) => {
|
|
|
|
return instance.id;
|
|
|
|
}) :
|
|
|
|
undefined,
|
|
|
|
service_dependency_ids: clientService.connections,
|
|
|
|
parent_id: clientService.parent ? clientService.parent : undefined,
|
2017-07-05 16:33:16 +03:00
|
|
|
config: clientService.config ? clientService.config : undefined,
|
2017-07-05 16:33:16 +03:00
|
|
|
status: clientService.status,
|
|
|
|
has_plan: clientService.hasPlan
|
|
|
|
});
|
2017-05-27 19:35:38 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
exports.toVersion = function (clientVersion) {
|
2017-07-05 16:33:16 +03:00
|
|
|
return clean({
|
2017-05-27 19:35:38 +03:00
|
|
|
id: clientVersion.id,
|
|
|
|
created: clientVersion.created || Date.now(),
|
2017-06-27 18:15:27 +03:00
|
|
|
manifest_id: (clientVersion.manifest || {}).id,
|
2017-07-05 16:33:16 +03:00
|
|
|
service_scales: clientVersion.scale ? clientVersion.scale : undefined,
|
|
|
|
plan: clientVersion.plan ? clientVersion.plan : undefined,
|
|
|
|
error: clientVersion.version
|
|
|
|
});
|
2017-05-27 19:35:38 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.fromVersion = function (version) {
|
|
|
|
return {
|
|
|
|
id: version.id,
|
|
|
|
created: version.created,
|
2017-06-27 18:15:27 +03:00
|
|
|
manifest: version.manifest,
|
2017-07-05 16:33:16 +03:00
|
|
|
scale: version.service_scales,
|
|
|
|
plan: version.plan,
|
|
|
|
error: version.error
|
2017-05-27 19:35:38 +03:00
|
|
|
};
|
|
|
|
};
|
2017-05-31 01:08:06 +03:00
|
|
|
|
|
|
|
|
|
|
|
exports.toManifest = function (clientManifest) {
|
|
|
|
return {
|
|
|
|
id: clientManifest.id,
|
|
|
|
deployment_group_id: clientManifest.deploymentGroupId,
|
|
|
|
created: clientManifest.created || Date.now(),
|
|
|
|
type: clientManifest.type,
|
|
|
|
format: clientManifest.format,
|
2017-07-05 16:33:16 +03:00
|
|
|
environment: clientManifest.environment,
|
2017-05-31 01:08:06 +03:00
|
|
|
raw: clientManifest.raw,
|
2017-06-02 00:25:45 +03:00
|
|
|
json: clientManifest.json || Yamljs.parse(clientManifest.raw)
|
2017-05-31 01:08:06 +03:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.fromManifest = function (manifest) {
|
|
|
|
return {
|
|
|
|
id: manifest.id,
|
|
|
|
deploymentGroupId: manifest.deployment_group_id,
|
|
|
|
created: manifest.created,
|
|
|
|
type: manifest.type,
|
|
|
|
format: manifest.format,
|
2017-07-05 16:33:16 +03:00
|
|
|
environment: manifest.environment,
|
2017-05-31 01:08:06 +03:00
|
|
|
raw: manifest.raw,
|
|
|
|
json: manifest.json
|
|
|
|
};
|
|
|
|
};
|
2017-05-31 22:27:53 +03:00
|
|
|
|
|
|
|
|
|
|
|
exports.fromPackage = function (packages) {
|
|
|
|
return packages;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.toPackage = function (packages) {
|
|
|
|
return packages;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
exports.fromInstance = function (instance) {
|
|
|
|
return {
|
|
|
|
id: instance.id,
|
|
|
|
name: instance.name,
|
|
|
|
machineId: instance.machine_id,
|
2017-07-05 16:33:16 +03:00
|
|
|
status: instance.status,
|
|
|
|
ips: instance.ips,
|
2017-06-30 22:57:42 +03:00
|
|
|
healthy: instance.healthy
|
2017-05-31 22:27:53 +03:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.toInstance = function (clientInstance) {
|
2017-07-05 16:33:16 +03:00
|
|
|
return clean({
|
2017-05-31 22:27:53 +03:00
|
|
|
id: clientInstance.id,
|
|
|
|
name: clientInstance.name,
|
|
|
|
machine_id: clientInstance.machineId,
|
2017-07-05 16:33:16 +03:00
|
|
|
status: clientInstance.status,
|
|
|
|
ips: clientInstance.ips,
|
2017-06-30 22:57:42 +03:00
|
|
|
healthy: clientInstance.healthy
|
2017-07-05 16:33:16 +03:00
|
|
|
});
|
2017-05-31 22:27:53 +03:00
|
|
|
};
|
2017-06-05 23:54:44 +03:00
|
|
|
|
|
|
|
|
|
|
|
exports.fromUser = function (user) {
|
|
|
|
return {
|
|
|
|
id: user.id,
|
|
|
|
firstName: user.first_name,
|
|
|
|
lastName: user.last_name,
|
|
|
|
email: user.email,
|
|
|
|
login: user.login
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.toUser = function (clientUser) {
|
|
|
|
return {
|
|
|
|
id: clientUser.id,
|
|
|
|
first_name: clientUser.firstName,
|
|
|
|
last_name: clientUser.lastName,
|
|
|
|
email: clientUser.email,
|
|
|
|
login: clientUser.login
|
|
|
|
};
|
|
|
|
};
|