Skip to content
Snippets Groups Projects

Draft: Iss #10 - Add support for private GL token when fetching specs

Closed Draft: Iss #10 - Add support for private GL token when fetching specs
Closed Martin Lowe requested to merge malowe/main/retry-fix into main
1 file
+ 5
3
Compare changes
  • Side-by-side
  • Inline
+ 5
3
@@ -31,14 +31,16 @@ const artificialSpecData = { items: [] };
@@ -31,14 +31,16 @@ const artificialSpecData = { items: [] };
* @param {*} externalLocation the URL for the raw openapi spec file.
* @param {*} externalLocation the URL for the raw openapi spec file.
* @param {*} localPath the location where the downloaded spec should be saved
* @param {*} localPath the location where the downloaded spec should be saved
*/
*/
async function pullExternalSpec(externalLocation, localPath) {
async function pullExternalSpec(externalLocation, localPath, isPrivate = false) {
let retries = 0;
let retries = 0;
// retry 3 times before giving up
// retry 3 times before giving up
while (retries < 3) {
while (retries < 3) {
try {
try {
fs.writeFileSync(
fs.writeFileSync(
localPath,
localPath,
await fetch(externalLocation).then(response => {
await fetch(externalLocation, {headers: {
 
"PRIVATE-TOKEN": isPrivate ? process.env.GITLAB_TOKEN : ''
 
}}).then(response => {
if (!response.ok) {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
throw new Error(`HTTP error! Status: ${response.status}`);
}
}
@@ -122,7 +124,7 @@ async function run() {
@@ -122,7 +124,7 @@ async function run() {
console.log(`Retrieving openapi spec for ${specDisplayName}...`);
console.log(`Retrieving openapi spec for ${specDisplayName}...`);
// prepare the spec, fetching remote specs or copying the spec for processing
// prepare the spec, fetching remote specs or copying the spec for processing
if (isExternalSpec(specLocation)) {
if (isExternalSpec(specLocation)) {
await pullExternalSpec(specLocation, outputSpecLocation);
await pullExternalSpec(specLocation, outputSpecLocation, currentSpecDefinition['private'] === true);
} else {
} else {
fs.copyFileSync(potentialLocalSpecLocation, outputSpecLocation);
fs.copyFileSync(potentialLocalSpecLocation, outputSpecLocation);
console.log(`Copied local spec for ${specDisplayName} to output dir`);
console.log(`Copied local spec for ${specDisplayName} to output dir`);
Loading