Skip to content

Commit 9446cbf

Browse files
authored
Merge pull request #1112 from purecloudlabs/DEVTOOLING-1317-CVE-FormData
[DEVTOOLING-1317] Fixing CVE on form-data
2 parents 1ad69fc + 8015ffe commit 9446cbf

File tree

6 files changed

+1974
-2576
lines changed

6 files changed

+1974
-2576
lines changed

modules/builder/builder.ts

Lines changed: 97 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import _ from 'lodash';
22
import childProcess from 'child_process';
33
import $RefParser from "@apidevtools/json-schema-ref-parser";
44
import fs from 'fs-extra';
5-
import githubApi from "github-api-promise";
65
import https from 'https';
76
import path from 'path';
87
import pluralize from 'pluralize';
@@ -18,6 +17,8 @@ import GitModule from '../git/gitModule';
1817
import Zip from '../util/zip';
1918
import { Models } from 'purecloud-platform-client-v2';
2019
import log from '../log/logger';
20+
import axios from "axios";
21+
import { Endpoints } from "@octokit/types";
2122

2223

2324
const swaggerDiff = new SwaggerDiff();
@@ -183,7 +184,7 @@ export class Builder {
183184
const commonRoot = path.resolve('./');
184185
const sdkRepo = path.resolve(path.join('./output', this.config.settings.swaggerCodegen.codegenLanguage));
185186
const sdkTemp = path.resolve(path.join('./temp', this.config.settings.swaggerCodegen.codegenLanguage));
186-
187+
187188
log.debug(`Environment paths - CommonRoot: ${commonRoot}, SdkRepo: ${sdkRepo}, SdkTemp: ${sdkTemp}`);
188189
setEnv('COMMON_ROOT', commonRoot);
189190
setEnv('SDK_REPO', sdkRepo);
@@ -741,9 +742,9 @@ function createRelease(): Promise<string> {
741742
log.log.debug(`repoName: ${repoName}`);
742743
log.log.debug(`repoOwner: ${repoOwner}`);
743744

744-
githubApi.config.repo = repoName;
745-
githubApi.config.owner = repoOwner;
746-
githubApi.config.token = getEnv('GITHUB_TOKEN') as string;
745+
githubConfig.repo = repoName;
746+
githubConfig.owner = repoOwner;
747+
githubConfig.token = getEnv('GITHUB_TOKEN') as string;
747748

748749
const tagName = _this.config.settings.sdkRepo.tagFormat.replace('{version}', _this.version.displayFull);
749750
let createReleaseOptions = {
@@ -757,7 +758,7 @@ function createRelease(): Promise<string> {
757758

758759
console.log(createReleaseOptions);
759760
// Create release
760-
return githubApi.repos.releases.createRelease(createReleaseOptions);
761+
return githubCreateRelease(createReleaseOptions);
761762
})
762763
.then((release) => {
763764
log.info(`Created release #${release}`);
@@ -1240,4 +1241,93 @@ function getFileCount(dir: fs.PathLike) {
12401241
}
12411242

12421243
return files.length;
1243-
}
1244+
}
1245+
1246+
// Alternative to github-api-promise until update
1247+
1248+
let githubConfig: any = {
1249+
owner: "github_username",
1250+
repo: "repo_name",
1251+
token: "your_github_token",
1252+
host: "https://api.github.com",
1253+
debug: false,
1254+
};
1255+
1256+
function githubGetRepoUrl(additionalPath: string) {
1257+
var url = githubConfig.host + "/repos/" + githubConfig.owner + "/" + githubConfig.repo + "/";
1258+
if (additionalPath) url += additionalPath;
1259+
return url;
1260+
}
1261+
1262+
function githubLogRequestSuccess(res: any, message?: string) {
1263+
if (githubConfig.debug != true) {
1264+
return;
1265+
}
1266+
let logMsg: string = "[INFO]" +
1267+
"[" +
1268+
res.statusCode +
1269+
"]" +
1270+
"[" +
1271+
res.req.method +
1272+
" " +
1273+
res.req.path +
1274+
"] " +
1275+
(message ? message : "");
1276+
1277+
console.log(logMsg);
1278+
}
1279+
1280+
function githubLogRequestError(err: any) {
1281+
if (err) {
1282+
let logMsg: string = "[ERROR]" +
1283+
"[" +
1284+
(err.res ? err.res.statusCode : "Unknown Status Code") +
1285+
"]" +
1286+
"[" +
1287+
(err.res && err.res.req ? err.res.req.method : "Unknown Method") +
1288+
" " +
1289+
(err.res && err.res.req ? err.res.req.path : "Unknown Path") +
1290+
"] " +
1291+
(err.message ? err.message : "Unknown Error Message");
1292+
console.log(logMsg);
1293+
} else {
1294+
console.log("[ERROR] Unknown Error");
1295+
}
1296+
}
1297+
1298+
/**
1299+
* Users with push access to the repository can create a release. Returns 422 if anything is wrong with the values in the body.
1300+
* @param {JSON} body A JSON document to send with the request
1301+
* @return {JSON} The release data
1302+
*/
1303+
function githubCreateRelease(
1304+
body: any
1305+
): Promise<
1306+
Endpoints["POST /repos/{owner}/{repo}/releases"]["response"]["data"]
1307+
> {
1308+
return new Promise((resolve, reject) => {
1309+
try {
1310+
axios
1311+
.post(githubGetRepoUrl("releases"), body, {
1312+
headers: {
1313+
Authorization: `token ${githubConfig.token}`,
1314+
"User-Agent": "github-api-promise",
1315+
"Content-Type": "application/json",
1316+
},
1317+
})
1318+
.then(
1319+
function (res: any) {
1320+
githubLogRequestSuccess(res);
1321+
resolve(res.body);
1322+
},
1323+
function (err: any) {
1324+
githubLogRequestError(err);
1325+
reject(err.message);
1326+
}
1327+
);
1328+
} catch (err) {
1329+
console.log(err);
1330+
reject(err.message);
1331+
}
1332+
});
1333+
}

0 commit comments

Comments
 (0)