add ability to call self-signed or invalid certificate clients

This commit is contained in:
Joel Male
2021-02-26 13:58:33 +10:00
parent 528d756289
commit 9380ee26ff
3852 changed files with 253796 additions and 137756 deletions
+9 -3
View File
@@ -1,14 +1,15 @@
const fetch = require('node-fetch');
var https = require('https');
class Http {
make(url: string, headers: string|null, body: string|null): Promise<any> {
make(url: string, headers: string | null, body: string | null, ignoreCertificate: boolean | null): Promise<any> {
return new Promise((resolve, reject) => {
fetch(url, this.getOptions('post', headers, body))
fetch(url, this.getOptions('post', headers, body, ignoreCertificate))
.then((res: Response) => resolve(res));
});
}
getOptions(method: string, headers: string|null, body: string|null) {
getOptions(method: string, headers: string | null, body: string | null, ignoreCertificate: boolean | null) {
const options: any = {
headers: headers ? JSON.parse(headers) : {},
method
@@ -19,6 +20,11 @@ class Http {
options.body = body;
}
if (ignoreCertificate) {
// ignore the certificate by not rejecting authorized servers
options.agent = new https.Agent({ rejectUnauthorized: false });
}
// set these headers
options.headers['content-type'] = 'application/json';
+2 -1
View File
@@ -5,6 +5,7 @@ async function run() {
const url = core.getInput('url') ? core.getInput('url') : (process.env.WEBHOOK_URL ? process.env.WEBHOOK_URL : '');
const headers = core.getInput('headers') ? core.getInput('headers') : (process.env.headers ? process.env.headers : null);
const body = core.getInput('body') ? core.getInput('body') : (process.env.data ? process.env.data : null);
const insecure = core.getInput('insecure') ? core.getInput('insecure') == 'true' : (process.env.insecure ? process.env.insecure == 'true' : false);
if (!url) {
// validate a url
@@ -20,7 +21,7 @@ async function run() {
core.debug((new Date()).toTimeString()); // debug is only output if you set the secret `ACTIONS_RUNNER_DEBUG` to true
// make the request
http.make(url, headers, body)
http.make(url, headers, body, insecure)
.then((res) => {
// if the status code is not 2xx
if (res.status >= 400) {