fix: validate status and some security

This commit is contained in:
Wathanyu Phromma
2022-03-20 14:01:35 +07:00
parent 31d4a5f24b
commit a2c408c63d
387 changed files with 33710 additions and 4612 deletions

View File

@@ -1,29 +1,31 @@
import axios, { AxiosRequestConfig } from 'axios'
import config from './requestconf'
import * as core from '@actions/core'
import * as fs from 'fs'
import { sendRequestWithRetry } from './util'
import { AxiosRequestConfig } from "axios";
import config, { INPUT_CUSTOM_CONFIG_FILE } from "./requestconf";
import * as core from "@actions/core";
import * as fs from "fs";
import { sendRequestWithRetry } from "./util";
try {
if(core.getInput('custom-config')){
const configPath = core.getInput('custom-config');
const basePath = process.env.GITHUB_WORKSPACE;
const path = `${basePath}/${configPath}`;
core.info(`Path is ${path}`);
if(configPath.split('.').pop() !== 'json'){
throw new Error('Config must be json file')
}
if(!fs.existsSync(path)){
throw new Error('Config file not found, meybe you need to use action/checkout before this step or there is typo on file name')
}
let customConfig: AxiosRequestConfig = JSON.parse(fs.readFileSync(path).toString()) as AxiosRequestConfig;
sendRequestWithRetry(customConfig)
}else{
sendRequestWithRetry(config)
if (INPUT_CUSTOM_CONFIG_FILE) {
core.info(`Using custom axios config file`);
const basePath = process.env.GITHUB_WORKSPACE;
const path = `${basePath}/${INPUT_CUSTOM_CONFIG_FILE}`;
core.debug(`Path is ${path}`);
if ((INPUT_CUSTOM_CONFIG_FILE as string).split(".").pop() !== "json") {
throw new Error("Config must be json file");
}
if (!fs.existsSync(path)) {
throw new Error(
"Config file not found, meybe you need to use action/checkout before this step or there is typo on file name"
);
}
const customConfig: AxiosRequestConfig = JSON.parse(
fs.readFileSync(path).toString()
) as AxiosRequestConfig;
sendRequestWithRetry(customConfig);
} else {
core.info(`Using config from action params`);
sendRequestWithRetry(config);
}
} catch (err) {
core.setFailed(err.message);
core.setFailed((err as Error).message);
}