converted utils to tsc

This commit is contained in:
Kasra Bigdeli
2019-01-03 00:08:03 -08:00
parent 2fc636c83b
commit 5ee897c3e7
19 changed files with 296 additions and 288 deletions
+3
View File
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=IModels.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"IModels.js","sourceRoot":"","sources":["../../src/models/IModels.ts"],"names":[],"mappings":""}
+6 -7
View File
@@ -1,17 +1,16 @@
const MachineHelper = require("../helpers/MachineHelper");
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const MachineHelper = require('../helpers/MachineHelper');
function cleanUpUrl(url) {
if (!url || !url.length)
return null;
let cleanedUrl = url;
const hasSlashAtTheEnd = url.substr(url.length - 1, 1) === "/";
const hasSlashAtTheEnd = url.substr(url.length - 1, 1) === '/';
if (hasSlashAtTheEnd) {
// Remove the slash at the end
cleanedUrl = url.substr(0, url.length - 1);
}
return cleanedUrl
.replace("http://", "")
.replace("https://", "")
.trim();
return cleanedUrl.replace('http://', '').replace('https://', '').trim();
}
function findDefaultCaptainName() {
let currentSuffix = MachineHelper.machines.length + 1;
@@ -24,7 +23,7 @@ function getCaptainFullName(suffix) {
const formatSuffix = suffix < 10 ? `0${suffix}` : suffix;
return `captain-${formatSuffix}`;
}
const isSuffixValid = suffixNumber => MachineHelper.machines.map(machine => {
const isSuffixValid = (suffixNumber) => MachineHelper.machines.map((machine) => {
machine.name !== getCaptainFullName(suffixNumber);
});
module.exports = {
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"loginHelpers.js","sourceRoot":"","sources":["../../src/utils/loginHelpers.js"],"names":[],"mappings":"AAAA,MAAM,aAAa,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAA;AAEzD,SAAS,UAAU,CAAC,GAAG;IACrB,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IAEpC,IAAI,UAAU,GAAG,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AsB;IACtB,aAAa;IACb,kBAAkB;CAClB,CAAC"}
+6 -4
View File
@@ -1,7 +1,9 @@
const DeployApi = require("../api/DeployApi");
const MachineHelper = require("../helpers/MachineHelper");
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const DeployApi = require('../api/DeployApi');
const MachineHelper = require('../helpers/MachineHelper');
function initMachineFromLocalStorage() {
const possibleApp = MachineHelper.apps.find(app => app.cwd === process.cwd());
const possibleApp = MachineHelper.apps.find((app) => app.cwd === process.cwd());
if (possibleApp) {
DeployApi.setMachineToDeploy(possibleApp.machineToDeploy);
DeployApi.setAppName(possibleApp.appName);
@@ -14,7 +16,7 @@ function saveMachineToLocalStorage() {
const currentDirectory = process.cwd();
let appExists = false;
// Update app
const updatedApps = apps.map(app => {
const updatedApps = apps.map((app) => {
if (app.cwd === currentDirectory) {
appExists = true;
return {
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"machineUtils.js","sourceRoot":"","sources":["../../src/utils/machineUtils.js"],"names":[],"mappings":"AAAA,MAAM,SAAS,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAA;AAC7C,MAAM,aAAa,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAA;AAEzD,SAAS,2BAA2B;IAClC,MAAM,WAAW,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,KAAK,OAAO,CAAC,GAAG,EAAE,CAAC,CAAA;IAE7E,IAAI,WAAW,EAAE;QACf,SAAS,CAAC,kBAAkB,CAAC,WAAW,CAAC,eAAe,CAAC,CAAA;QAEzD,SAAS,CAAC,UAAU,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;QAEzC,SAAS,CAAC,eAAe,CAAC,WAAW,CAAC,YAAY,CAAC,CAAA;KACpD;AACH,CAAC;AAED,6CAA6C;AAC7C,SAAS,yBAAyB;IAChC,MAAM,IAAI,GAAG,aAAa,CAAC,IAAI,CAAA;IAC/B,MAAM,g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AC,OAAO,GAAG;IAChB,2BAA2B;IAC3B,yBAAyB;CACzB,CAAC"}
+2 -1
View File
@@ -1,4 +1,5 @@
const chalk = require("chalk");
"use strict";
const chalk = require('chalk');
function printMessage(message) {
console.log(message);
}
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"messageHandler.js","sourceRoot":"","sources":["../../src/utils/messageHandler.js"],"names":[],"mappings":"AAAA,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;AAE9B,SAAS,YAAY,CAAC,OAAO;IAC3B,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;AACtB,CAAC;AAED,SAAS,mBAAmB,CAAC,OAAO;IAClC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IAEpB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC;AAED,SAAS,iBAAiB,CAAC,OAAO,EAAE,IAAI,GAAG,KAAK;IAC9C,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;IAEtC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACzB,CAAC;AAED,SAAS,mBAAmB,CAAC,OAAO,EAAE,IAAI,GAAG,KAAK;IAChD,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;IAExC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACzB,CAAC;AAED,SAAS,UAAU,CAAC,KAAK,EAAE,IAAI,GAAG,KAAK;IACrC,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IAEvC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACzB,CAAC;AAED,SAAS,YAAY,CAAC,KAAK;IACzB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,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAExC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACzB,CAAC;AAED,SAAS,YAAY,CAAC,KAAU;IAC/B,IAAI,KAAK,CAAC,MAAM,EAAE;QACjB,UAAU,CAAC,YAAY,KAAK,CAAC,MAAM,YAAY,KAAK,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,CAAC;KAC1E;SAAM;QACN,UAAU,CAAC,YAAY,KAAK,EAAE,EAAE,IAAI,CAAC,CAAC;KACtC;AACF,CAAC;AAED,iBAAS;IACR,YAAY;IACZ,mBAAmB;IACnB,UAAU;IACV,iBAAiB;IACjB,mBAAmB;IACnB,YAAY;CACZ,CAAC"}
+13 -13
View File
@@ -6,23 +6,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
const fs = require("fs-extra");
const DeployApi = require("../api/DeployApi");
const { printError } = require("./messageHandler");
const { requestLogin } = require("../commands/login");
const { initMachineFromLocalStorage } = require("../utils/machineUtils");
const fs = require('fs-extra');
const DeployApi = require('../api/DeployApi');
const { printError } = require('./messageHandler');
const { requestLogin } = require('../commands/login');
const { initMachineFromLocalStorage } = require('../utils/machineUtils');
function validateIsGitRepository() {
const gitFolderExists = fs.pathExistsSync("./.git");
const gitFolderExists = fs.pathExistsSync('./.git');
if (!gitFolderExists) {
printError("\n**** ERROR: You are not in a git root directory. This command will only deploys the current directory ****\n", true);
printError('\n**** ERROR: You are not in a git root directory. This command will only deploys the current directory ****\n', true);
}
}
function validateDefinitionFile() {
const captainDefinitionExists = fs.pathExistsSync("./captain-definition");
const captainDefinitionExists = fs.pathExistsSync('./captain-definition');
if (!captainDefinitionExists) {
printError("\n**** ERROR: captain-definition file cannot be found. Please see docs! ****\n", true);
printError('\n**** ERROR: captain-definition file cannot be found. Please see docs! ****\n', true);
}
const contents = fs.readFileSync("./captain-definition", "utf8");
const contents = fs.readFileSync('./captain-definition', 'utf8');
let contentsJson = null;
try {
contentsJson = JSON.parse(contents);
@@ -32,13 +32,13 @@ function validateDefinitionFile() {
}
if (contentsJson) {
if (!contentsJson.schemaVersion) {
printError("**** ERROR: captain-definition needs schemaVersion. Please see docs! ****", true);
printError('**** ERROR: captain-definition needs schemaVersion. Please see docs! ****', true);
}
if (!contentsJson.templateId && !contentsJson.dockerfileLines) {
printError("**** ERROR: captain-definition needs templateId or dockerfileLines. Please see docs! ****", true);
printError('**** ERROR: captain-definition needs templateId or dockerfileLines. Please see docs! ****', true);
}
if (contentsJson.templateId && contentsJson.dockerfileLines) {
printError("**** ERROR: captain-definition needs templateId or dockerfileLines, NOT BOTH! Please see docs! ****", true);
printError('**** ERROR: captain-definition needs templateId or dockerfileLines, NOT BOTH! Please see docs! ****', true);
}
}
}
@@ -1 +1 @@
{"version":3,"file":"validationsHandler.js","sourceRoot":"","sources":["../../src/utils/validationsHandler.js"],"names":[],"mappings":";;;;;;;;AAAA,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;AAC9B,MAAM,SAAS,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAA;AAC7C,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAA;AAClD,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAA;AACrD,MAAM,EAAE,2BAA2B,EAAE,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAA;AAExE,SAAS,uBAAuB;IAC9B,MAAM,eAAe,GAAG,EAAE,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAA;IAEnD,IAAI,CAAC,eAAe,EAAE;QACpB,UAAU,CACR,gHAAgH,EAChH,IAAI,CACL,CAAA;KACF;AACH,CAAC;AAED,SAAS,sBAAsB;IAC7B,MAAM,uBAAuB,GAAG,EAAE,CAAC,cAAc,CAAC,sBAAsB,CAAC,CAAA;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AAG;IAChB,sBAAsB;IACtB,uBAAuB;IACvB,sBAAsB;IACtB,WAAW;IACX,gBAAgB;CAChB,CAAC"}
+10
View File
@@ -0,0 +1,10 @@
export interface IApp {
cwd: string;
appName: string;
branchToPush: string;
machineToDeploy: string;
}
export interface IMachine {
name: string;
}
-46
View File
@@ -1,46 +0,0 @@
const MachineHelper = require("../helpers/MachineHelper")
function cleanUpUrl(url) {
if (!url || !url.length) return null
let cleanedUrl = url
const hasSlashAtTheEnd = url.substr(url.length - 1, 1) === "/"
if (hasSlashAtTheEnd) {
// Remove the slash at the end
cleanedUrl = url.substr(0, url.length - 1)
}
return cleanedUrl
.replace("http://", "")
.replace("https://", "")
.trim()
}
function findDefaultCaptainName() {
let currentSuffix = MachineHelper.machines.length + 1
while (!isSuffixValid(currentSuffix)) {
currentSuffix++
}
return getCaptainFullName(currentSuffix)
}
function getCaptainFullName(suffix) {
const formatSuffix = suffix < 10 ? `0${suffix}` : suffix
return `captain-${formatSuffix}`
}
const isSuffixValid = suffixNumber =>
MachineHelper.machines.map(machine => {
machine.name !== getCaptainFullName(suffixNumber)
})
module.exports = {
cleanUpUrl,
findDefaultCaptainName,
isSuffixValid,
getCaptainFullName
}
+45
View File
@@ -0,0 +1,45 @@
import { IMachine } from '../models/IModels';
const MachineHelper = require('../helpers/MachineHelper');
function cleanUpUrl(url: string) {
if (!url || !url.length) return null;
let cleanedUrl = url;
const hasSlashAtTheEnd = url.substr(url.length - 1, 1) === '/';
if (hasSlashAtTheEnd) {
// Remove the slash at the end
cleanedUrl = url.substr(0, url.length - 1);
}
return cleanedUrl.replace('http://', '').replace('https://', '').trim();
}
function findDefaultCaptainName() {
let currentSuffix = MachineHelper.machines.length + 1;
while (!isSuffixValid(currentSuffix)) {
currentSuffix++;
}
return getCaptainFullName(currentSuffix);
}
function getCaptainFullName(suffix: number) {
const formatSuffix = suffix < 10 ? `0${suffix}` : suffix;
return `captain-${formatSuffix}`;
}
const isSuffixValid = (suffixNumber: number) =>
MachineHelper.machines.map((machine: IMachine) => {
machine.name !== getCaptainFullName(suffixNumber);
});
module.exports = {
cleanUpUrl,
findDefaultCaptainName,
isSuffixValid,
getCaptainFullName
};
-56
View File
@@ -1,56 +0,0 @@
const DeployApi = require("../api/DeployApi")
const MachineHelper = require("../helpers/MachineHelper")
function initMachineFromLocalStorage() {
const possibleApp = MachineHelper.apps.find(app => app.cwd === process.cwd())
if (possibleApp) {
DeployApi.setMachineToDeploy(possibleApp.machineToDeploy)
DeployApi.setAppName(possibleApp.appName)
DeployApi.setBranchToPush(possibleApp.branchToPush)
}
}
// Saves the app directory into local storage
function saveMachineToLocalStorage() {
const apps = MachineHelper.apps
const currentDirectory = process.cwd()
let appExists = false
// Update app
const updatedApps = apps.map(app => {
if (app.cwd === currentDirectory) {
appExists = true
return {
cwd: app.cwd,
appName: DeployApi.appName,
branchToPush: DeployApi.branchToPush,
machineToDeploy: DeployApi.machineToDeploy
}
}
return app
})
MachineHelper.setApps(updatedApps)
if (!appExists) {
const newApp = {
cwd: process.cwd(),
appName: DeployApi.appName,
branchToPush: DeployApi.branchToPush,
machineToDeploy: DeployApi.machineToDeploy
}
updatedApps.push(newApp)
MachineHelper.setApps(apps)
}
}
module.exports = {
initMachineFromLocalStorage,
saveMachineToLocalStorage
}
+58
View File
@@ -0,0 +1,58 @@
import { IApp } from '../models/IModels';
const DeployApi = require('../api/DeployApi');
const MachineHelper = require('../helpers/MachineHelper');
function initMachineFromLocalStorage() {
const possibleApp = MachineHelper.apps.find((app: IApp) => app.cwd === process.cwd());
if (possibleApp) {
DeployApi.setMachineToDeploy(possibleApp.machineToDeploy);
DeployApi.setAppName(possibleApp.appName);
DeployApi.setBranchToPush(possibleApp.branchToPush);
}
}
// Saves the app directory into local storage
function saveMachineToLocalStorage() {
const apps = MachineHelper.apps;
const currentDirectory = process.cwd();
let appExists = false;
// Update app
const updatedApps = apps.map((app: IApp) => {
if (app.cwd === currentDirectory) {
appExists = true;
return {
cwd: app.cwd,
appName: DeployApi.appName,
branchToPush: DeployApi.branchToPush,
machineToDeploy: DeployApi.machineToDeploy
};
}
return app;
});
MachineHelper.setApps(updatedApps);
if (!appExists) {
const newApp = {
cwd: process.cwd(),
appName: DeployApi.appName,
branchToPush: DeployApi.branchToPush,
machineToDeploy: DeployApi.machineToDeploy
};
updatedApps.push(newApp);
MachineHelper.setApps(apps);
}
}
module.exports = {
initMachineFromLocalStorage,
saveMachineToLocalStorage
};
-46
View File
@@ -1,46 +0,0 @@
const chalk = require("chalk")
function printMessage(message) {
console.log(message)
}
function printMessageAndExit(message) {
console.log(message)
process.exit(0)
}
function printGreenMessage(message, exit = false) {
console.log(`${chalk.green(message)}`)
exit && process.exit(0)
}
function printMagentaMessage(message, exit = false) {
console.log(`${chalk.magenta(message)}`)
exit && process.exit(0)
}
function printError(error, exit = false) {
console.log(`${chalk.bold.red(error)}`)
exit && process.exit(0)
}
function errorHandler(error) {
if (error.status) {
printError(`\nError: ${error.status}\nError: ${error.description}`, true)
} else {
printError(`\nError: ${error}`, true)
}
}
module.exports = {
printMessage,
printMessageAndExit,
printError,
printGreenMessage,
printMagentaMessage,
errorHandler
}
+46
View File
@@ -0,0 +1,46 @@
const chalk = require('chalk');
function printMessage(message: string) {
console.log(message);
}
function printMessageAndExit(message: string) {
console.log(message);
process.exit(0);
}
function printGreenMessage(message: string, exit = false) {
console.log(`${chalk.green(message)}`);
exit && process.exit(0);
}
function printMagentaMessage(message: string, exit = false) {
console.log(`${chalk.magenta(message)}`);
exit && process.exit(0);
}
function printError(error: string, exit = false) {
console.log(`${chalk.bold.red(error)}`);
exit && process.exit(0);
}
function errorHandler(error: any) {
if (error.status) {
printError(`\nError: ${error.status}\nError: ${error.description}`, true);
} else {
printError(`\nError: ${error}`, true);
}
}
export = {
printMessage,
printMessageAndExit,
printError,
printGreenMessage,
printMagentaMessage,
errorHandler
};
-111
View File
@@ -1,111 +0,0 @@
const fs = require("fs-extra")
const DeployApi = require("../api/DeployApi")
const { printError } = require("./messageHandler")
const { requestLogin } = require("../commands/login")
const { initMachineFromLocalStorage } = require("../utils/machineUtils")
function validateIsGitRepository() {
const gitFolderExists = fs.pathExistsSync("./.git")
if (!gitFolderExists) {
printError(
"\n**** ERROR: You are not in a git root directory. This command will only deploys the current directory ****\n",
true
)
}
}
function validateDefinitionFile() {
const captainDefinitionExists = fs.pathExistsSync("./captain-definition")
if (!captainDefinitionExists) {
printError(
"\n**** ERROR: captain-definition file cannot be found. Please see docs! ****\n",
true
)
}
const contents = fs.readFileSync("./captain-definition", "utf8")
let contentsJson = null
try {
contentsJson = JSON.parse(contents)
} catch (e) {
printError(
`**** ERROR: captain-definition file is not a valid JSON! ****\n Error:${e}`,
true
)
}
if (contentsJson) {
if (!contentsJson.schemaVersion) {
printError(
"**** ERROR: captain-definition needs schemaVersion. Please see docs! ****",
true
)
}
if (!contentsJson.templateId && !contentsJson.dockerfileLines) {
printError(
"**** ERROR: captain-definition needs templateId or dockerfileLines. Please see docs! ****",
true
)
}
if (contentsJson.templateId && contentsJson.dockerfileLines) {
printError(
"**** ERROR: captain-definition needs templateId or dockerfileLines, NOT BOTH! Please see docs! ****",
true
)
}
}
}
// Only show that question if there is no option given as argument
function optionIsNotGiven(allOptions, option) {
// console.log(allOptions)
if (allOptions[option]) {
return false
}
return true
}
function isIpAddress(ipaddress) {
if (
/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(
ipaddress
)
) {
return true
}
return false
}
async function validateAuthentication() {
// 1. Check if valid auth
const isAuthenticated = await DeployApi.isAuthTokenValid()
// 2. Request login
// 3. Login
// 4. Update token
if (!isAuthenticated) {
const loggedInStatus = await requestLogin()
// Refresh token in DeployApi
initMachineFromLocalStorage()
return loggedInStatus
} else {
return Boolean(isAuthenticated)
}
}
module.exports = {
validateAuthentication,
validateIsGitRepository,
validateDefinitionFile,
isIpAddress,
optionIsNotGiven
}
+102
View File
@@ -0,0 +1,102 @@
const fs = require('fs-extra');
const DeployApi = require('../api/DeployApi');
const { printError } = require('./messageHandler');
const { requestLogin } = require('../commands/login');
const { initMachineFromLocalStorage } = require('../utils/machineUtils');
function validateIsGitRepository() {
const gitFolderExists = fs.pathExistsSync('./.git');
if (!gitFolderExists) {
printError(
'\n**** ERROR: You are not in a git root directory. This command will only deploys the current directory ****\n',
true
);
}
}
function validateDefinitionFile() {
const captainDefinitionExists = fs.pathExistsSync('./captain-definition');
if (!captainDefinitionExists) {
printError('\n**** ERROR: captain-definition file cannot be found. Please see docs! ****\n', true);
}
const contents = fs.readFileSync('./captain-definition', 'utf8');
let contentsJson = null;
try {
contentsJson = JSON.parse(contents);
} catch (e) {
printError(`**** ERROR: captain-definition file is not a valid JSON! ****\n Error:${e}`, true);
}
if (contentsJson) {
if (!contentsJson.schemaVersion) {
printError('**** ERROR: captain-definition needs schemaVersion. Please see docs! ****', true);
}
if (!contentsJson.templateId && !contentsJson.dockerfileLines) {
printError(
'**** ERROR: captain-definition needs templateId or dockerfileLines. Please see docs! ****',
true
);
}
if (contentsJson.templateId && contentsJson.dockerfileLines) {
printError(
'**** ERROR: captain-definition needs templateId or dockerfileLines, NOT BOTH! Please see docs! ****',
true
);
}
}
}
// Only show that question if there is no option given as argument
function optionIsNotGiven(allOptions: { [id: string]: any }, option: string) {
// console.log(allOptions)
if (allOptions[option]) {
return false;
}
return true;
}
function isIpAddress(ipaddress: string) {
if (
/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(
ipaddress
)
) {
return true;
}
return false;
}
async function validateAuthentication() {
// 1. Check if valid auth
const isAuthenticated = await DeployApi.isAuthTokenValid();
// 2. Request login
// 3. Login
// 4. Update token
if (!isAuthenticated) {
const loggedInStatus = await requestLogin();
// Refresh token in DeployApi
initMachineFromLocalStorage();
return loggedInStatus;
} else {
return Boolean(isAuthenticated);
}
}
module.exports = {
validateAuthentication,
validateIsGitRepository,
validateDefinitionFile,
isIpAddress,
optionIsNotGiven
};