Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,31 @@ let logofied = text => {
);
};

/**
* Validated input
* @param {*} value
* @param {*} error
*/
var argumentValidator = {
isString: (value, expected) => {
if (typeof value === "string") {
console.log(chalk.red("Failed validation isNotEmpty: " + expected));
return true;
}
return false;
},
isNotEmpty: (value, expected) => {
if (value !== "" && value !== null && typeof value !== "undefined") {
console.log(chalk.red("Failed validation isNotEmpty: " + expected));
return true;
}
return false;
}
};

/**
* Logs the values with colors according to the type
* @param {*} data
* @param {*} error
*/
let logger = (data, error) => {
if (error) {
Expand Down Expand Up @@ -116,5 +137,6 @@ module.exports = {
checkNcConfig: checkNcConfig,
writeMetaData: writeMetaData,
logger: logger,
logofied: logofied
logofied: logofied,
argumentValidator: argumentValidator
};
27 changes: 26 additions & 1 deletion lib/services.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Core = require("./core");
const Init = require("./init");
const { logger, logofied } = require("./helper");
const { logger, logofied, argumentValidator } = require("./helper");
//import services

const Compute = require("./compute");
Expand Down Expand Up @@ -29,8 +29,12 @@ function Services(program, spinner) {
}
if (program.compute) {
let compute = new Compute(program, ncProviders, options);

switch (program.compute) {
case "create":
argumentValidator.isString(program.image, "Program Image");
argumentValidator.isString(program.instance, "Program Instance");
argumentValidator.isString(program.name, "Program Name");
compute.createInstance(
{
params: {
Expand Down Expand Up @@ -61,6 +65,7 @@ function Services(program, spinner) {
});
break;
case "stop":
argumentValidator.isString(program.id, "Program ID");
compute.stopInstance(
{
InstanceIds: [program.id]
Expand All @@ -74,6 +79,7 @@ function Services(program, spinner) {
);
break;
case "reboot":
argumentValidator.isString(program.id, "Program ID");
compute.rebootInstance(
{
InstanceIds: [program.id]
Expand All @@ -87,6 +93,7 @@ function Services(program, spinner) {
);
break;
case "start":
argumentValidator.isString(program.id, "Program ID");
compute.startInstance(
{
InstanceIds: [program.id]
Expand All @@ -100,6 +107,7 @@ function Services(program, spinner) {
);
break;
case "destroy":
argumentValidator.isString(program.id, "Program ID");
compute.destroyInstance(
{
InstanceIds: [program.id]
Expand All @@ -123,6 +131,7 @@ function Services(program, spinner) {
let storage = new Storage(program, ncProviders, options);
switch (program.storage) {
case "create":
argumentValidator.isString(program.name, "Program Name");
storage.createStorage(
{
Bucket: program.name,
Expand Down Expand Up @@ -150,6 +159,7 @@ function Services(program, spinner) {
});
break;
case "delete":
argumentValidator.isString(program.name, "Program Name");
storage.deleteStorage(
{
Bucket: program.name
Expand Down Expand Up @@ -215,6 +225,7 @@ function Services(program, spinner) {
let iam = new Iam(program, ncProviders, options);
switch (program.iam) {
case "create":
argumentValidator.isString(program.name, "Program Name");
iam.createGroup(
{
GroupName: program.name
Expand All @@ -228,6 +239,7 @@ function Services(program, spinner) {
);
break;
case "delete":
argumentValidator.isString(program.name, "Program Name");
iam.deleteGroup(
{
GroupName: program.name
Expand All @@ -241,6 +253,7 @@ function Services(program, spinner) {
);
break;
case "attach":
argumentValidator.isString(program.name, "Program Name");
iam.attachResoure(
{
GroupName: program.name,
Expand All @@ -255,6 +268,7 @@ function Services(program, spinner) {
);
break;
case "detach":
argumentValidator.isString(program.name, "Program Name");
iam.detachResource(
{
GroupName: program.name,
Expand All @@ -279,6 +293,8 @@ function Services(program, spinner) {
let network = new Network(program, ncProviders, options);
switch (program.network) {
case "create":
argumentValidator.isString(program.port, "Program Port");
argumentValidator.isString(program.name, "Program Name");
network.create(
{
AvailabilityZones: ["eu-central-1b"],
Expand Down Expand Up @@ -309,6 +325,7 @@ function Services(program, spinner) {
});
break;
case "delete":
argumentValidator.isString(program.name, "Program Name");
network.delete(
{
LoadBalancerName: program.name
Expand All @@ -322,6 +339,9 @@ function Services(program, spinner) {
);
break;
case "tag":
argumentValidator.isString(program.name, "Program Name");
argumentValidator.isString(program.key, "Program Key");
argumentValidator.isString(program.value, "Program Value");
network.addTags(
{
LoadBalancerNames: [program.name],
Expand All @@ -341,6 +361,8 @@ function Services(program, spinner) {
);
break;
case "detag":
argumentValidator.isString(program.name, "Program Name");
argumentValidator.isString(program.key, "Program Key");
network.removeTags(
{
LoadBalancerNames: [program.name],
Expand All @@ -359,6 +381,8 @@ function Services(program, spinner) {
);
break;
case "createz":
argumentValidator.isString(program.cr, "Program CR");
argumentValidator.isString(program.name, "Program Name");
network.createZone(
{ CallerReference: program.cr, Name: program.name },
(error, data) => {
Expand All @@ -378,6 +402,7 @@ function Services(program, spinner) {
});
break;
case "deletez":
argumentValidator.isString(program.id, "Program ID");
network.deleteZone(
{ Id: `/hostedzone/${program.id}` },
(error, data) => {
Expand Down
Loading