Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | 5x 5x 5x 5x 16x 16x 16x 1x 1x 15x 15x 15x 14x 12x 11x 11x 1x 10x 6x 4x 1x 1x 3x 1x 1x 2x 1x 1x 5x 5x 1x 1x 4x 4x 9x 9x 9x 9x 9x 9x 9x 9x 7x 7x 1x 6x 1x 1x 5x 4x 1x 3x 1x 1x 2x 1x 1x 5x 5x 1x 1x 4x 4x 9x 9x 9x 9x 9x 9x 9x 7x 7x 1x 6x 1x 1x 5x 1x 1x 6x 3x 3x 5x | const chalk = require('chalk');
const CONSTANTS = require('../lib/constant.js');
const { formatEndPointURL, getHttpsAgent, getHeaders, getAppStaticServerUrl } = require('../lib/helper.js');
/*
Interactions with ConstellationAppStatic Service
*/
const AppStaticService = {
/*
libId = libName:libVersions
Fetches all the library versions available for a library
*/
async fetchLibraryNameOrVersions(libId='', tokenParams, appStaticSVCUrl){
try{
const appStaticServerUrl = getAppStaticServerUrl(appStaticSVCUrl);
if(!appStaticServerUrl){
console.log(chalk.red('App static service url not available, exiting fetch operation.'));
return;
}
// Add libId to the url later on
// If libId is not null, then it's fetch the versions of a libname, not the libnames
const URL = formatEndPointURL(appStaticServerUrl, CONSTANTS.FETCH_ENDPOINT_URL, libId);
const headers = getHeaders(tokenParams);
if(!headers) { return; }
const response = await fetch(URL, {
method: 'GET',
headers: headers,
agent: getHttpsAgent()
});
const data = await response.json();
const status = response.status;
if (status === 401) {
throw new Error('Error occurred in authentication. Please regenerate using authenticate');
} else if (status === 200 || status === 201) {
return data;
} else if(status === 400){
console.log(chalk.redBright(`Bad Request: ${data}.`));
process.exit(1);
} else if(status === 403){
console.log(chalk.red(`JWT Token has been expired.. please update token : ${data}`));
process.exit(1);
} else if(status === 404){
return [];
}
else {
//console.log(response);
throw new Error(`${response}`);
}
}
catch(e){
console.log("appstatic.service: fetchLibraryNameOrVersions(): error occured", e);
if (e.code === 'ECONNREFUSED') {
console.log(chalk.red("Error: Connection refused"));
process.exit(1);
} else {
console.log(chalk.red(`Error: Connection error: ${JSON.stringify(e)}`));
process.exit(1);
}
}
},
async fetchLibraryManifestData(libId, libVersion, tokenParams, appStaticSVCUrl, cmptcfg){
try{
const appStaticServerUrl = getAppStaticServerUrl(appStaticSVCUrl);
Iif(!appStaticServerUrl){
console.log(chalk.red('App static service url not available, exiting fetch operation.'));
return;
}
let URL;
if(!cmptcfg){
URL = formatEndPointURL(appStaticServerUrl, CONSTANTS.ENDPOINTURL, 'component', libId+':'+libVersion, 'chunks', CONSTANTS.MANIFEST);
} elseE{
URL = formatEndPointURL(appStaticServerUrl, CONSTANTS.ENDPOINTURL, 'componentsconfig', libId+':'+libVersion);
}
const headers = getHeaders(tokenParams);
Iif(!headers) { return; }
const response = await fetch(URL, {
method: 'GET',
headers: headers,
agent: getHttpsAgent()
});
const status = response.status;
if (status === 401) {
throw new Error('Error occurred in authentication. Please regenerate using authenticate');
} else if(status === 404){
console.log(chalk.red(`Manifest not available for version selected`));
return;
}
const data = await response.json();
if (status === 200 || status === 201) {
return data;
} else if(status === 400){
console.log(chalk.redBright(`Bad Request: ${data}.`));
process.exit(1);
} else if(status === 403){
console.log(chalk.red(`JWT Token has been expired.. please update token : ${data}`));
} else {
throw new Error(`${response}`);
}
}
catch(e){
console.log("appstatic.service: fetchLibraryManifestData(): error occured", e);
if (e.code === 'ECONNREFUSED') {
console.log(chalk.red("Error: Connection refused"));
process.exit(1);
} else {
console.log(chalk.red(`Error: Connection error: ${JSON.stringify(e)}`));
process.exit(1);
}
}
},
/**
* Delete a library entirely, this is done by making calls with all the versions available and deleting them all
*/
async deleteLibraryOrVersions(libVersion, tokenParams, appStaticSVCUrl){
try{
const appStaticServerUrl = getAppStaticServerUrl(appStaticSVCUrl);
Iif(!appStaticServerUrl){
console.log(chalk.red('App static service url not available, exiting delete operation.'));
process.exit(1);
}
const URL = formatEndPointURL(appStaticServerUrl, CONSTANTS.DELETE_ENDPOINT_URL, libVersion);
const headers = getHeaders(tokenParams);
Iif(!headers) { return; }
const response = await fetch(URL, {
method: 'DELETE',
headers: headers,
agent: getHttpsAgent()
});
const status = await response.status;
if (status === 401) {
throw new Error('Error occurred in authentication. Please regenerate using authenticate');
}
else if(status === 400){
console.log(chalk.redBright(`Bad Request.`));
process.exit(1);
}
else if(status === 403){
console.log(chalk.red(`JWT Token has been expired.. please update token :`));
process.exit(1);
}
return status === 200 ? true : false;
}
catch(err){
console.log("appstatic.service: deleteLibraryOrVersions() : error occured", err);
process.exit(1);
}
}
};
module.exports = { AppStaticService } |