Skip to content
Snippets Groups Projects
Commit 75bcc108 authored by Martin Lowe's avatar Martin Lowe :flag_ca:
Browse files

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

This change set is 1 half of the changeset, as currently the Jenkinsbuild doesn't allow for tokens to be embedded into the build. We will need tokens to be enabled to finish this feature.
parent 45d91bcf
No related branches found
No related tags found
1 merge request!10Draft: Iss #10 - Add support for private GL token when fetching specs
Pipeline #43730 failed
......@@ -31,14 +31,16 @@ const artificialSpecData = { items: [] };
* @param {*} externalLocation the URL for the raw openapi spec file.
* @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;
// retry 3 times before giving up
while (retries < 3) {
try {
fs.writeFileSync(
localPath,
await fetch(externalLocation).then(response => {
await fetch(externalLocation, {headers: {
"PRIVATE-TOKEN": isPrivate ? process.env.GITLAB_TOKEN : ''
}}).then(response => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
......@@ -122,7 +124,7 @@ async function run() {
console.log(`Retrieving openapi spec for ${specDisplayName}...`);
// prepare the spec, fetching remote specs or copying the spec for processing
if (isExternalSpec(specLocation)) {
await pullExternalSpec(specLocation, outputSpecLocation);
await pullExternalSpec(specLocation, outputSpecLocation, currentSpecDefinition['private'] === true);
} else {
fs.copyFileSync(potentialLocalSpecLocation, outputSpecLocation);
console.log(`Copied local spec for ${specDisplayName} to output dir`);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment