mask response as secret if configured

Signed-off-by: Frank Jogeleit <frank.jogeleit@lovoo.com>
This commit is contained in:
Frank Jogeleit 2023-12-17 15:41:37 +01:00
parent 25a5a55111
commit 2d6a2f17dc
7 changed files with 124 additions and 10 deletions

View file

@ -59,6 +59,10 @@ inputs:
responseFile:
description: 'Persist the response data to the specified file path'
required: false
maskResponse:
description: 'Allows to mark your response as secret and hide the output in the action logs'
required: false
default: 'false'
retry:
description: 'optional amount of retries if the request fails'
required: false

72
dist/index.js vendored
View file

@ -26561,6 +26561,10 @@ class GithubActions {
core.setOutput(name, output)
}
setSecret(value) {
core.setSecret(value)
}
setFailed(message) {
core.setFailed(message)
}
@ -26591,6 +26595,57 @@ class LogActions {
module.exports = { GithubActions, LogActions }
/***/ }),
/***/ 8566:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
"use strict";
const axios = __nccwpck_require__(8757);
const { GithubActions } = __nccwpck_require__(8169);
/**
* @param {GithubActions} actions
*
* @returns {(response: axios.AxiosResponse) => void}
*/
const createMaskHandler = (actions) => (response) => {
let data = response.data
if (typeof data == 'object') {
data = JSON.stringify(data)
}
actions.setSecret(data)
}
module.exports = { createMaskHandler }
/***/ }),
/***/ 2190:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
"use strict";
const axios = __nccwpck_require__(8757);
const { GithubActions } = __nccwpck_require__(8169);
/**
* @param {GithubActions} actions
*
* @returns {(response: axios.AxiosResponse) => void}
*/
const createOutputHandler = (actions) => (response) => {
actions.setOutput('response', response.data)
actions.setOutput('headers', response.headers)
}
module.exports = { createOutputHandler }
/***/ }),
/***/ 6733:
@ -26840,9 +26895,6 @@ const request = async({ method, instanceConfig, data, files, file, actions, opti
return null
}
actions.setOutput('response', JSON.stringify(response.data))
actions.setOutput('headers', response.headers)
return response
} catch (error) {
if ((typeof error === 'object') && (error.isAxiosError === true)) {
@ -33180,7 +33232,10 @@ const axios = __nccwpck_require__(8757);
const https = __nccwpck_require__(5687);
const { request, METHOD_POST } = __nccwpck_require__(9082);
const { GithubActions } = __nccwpck_require__(8169);
const { createPersistHandler } = __nccwpck_require__(6733);
const { createOutputHandler } = __nccwpck_require__(2190);
const { createMaskHandler } = __nccwpck_require__(8566);
let customHeaders = {}
@ -33248,9 +33303,16 @@ if (typeof ignoreStatusCodes === 'string' && ignoreStatusCodes.length > 0) {
ignoredCodes = ignoreStatusCodes.split(',').map(statusCode => parseInt(statusCode.trim()))
}
const handler = [];
const actions = new GithubActions();
const handler = [];
if (core.getBooleanInput('maskResponse')) {
handler.push(createMaskHandler(actions))
}
handler.push(createOutputHandler(actions))
if (!!responseFile) {
handler.push(createPersistHandler(responseFile, actions))
}
@ -33264,7 +33326,7 @@ const options = {
}
request({ data, method, instanceConfig, files, file, actions, options }).then(response => {
if (typeof response == 'object') {
if (response && typeof response == 'object') {
handler.forEach(h => h(response))
}
})

View file

@ -19,6 +19,10 @@ class GithubActions {
core.setOutput(name, output)
}
setSecret(value) {
core.setSecret(value)
}
setFailed(message) {
core.setFailed(message)
}

21
src/handler/mask.js Normal file
View file

@ -0,0 +1,21 @@
'use strict'
const axios = require('axios');
const { GithubActions } = require('../githubActions');
/**
* @param {GithubActions} actions
*
* @returns {(response: axios.AxiosResponse) => void}
*/
const createMaskHandler = (actions) => (response) => {
let data = response.data
if (typeof data == 'object') {
data = JSON.stringify(data)
}
actions.setSecret(data)
}
module.exports = { createMaskHandler }

16
src/handler/output.js Normal file
View file

@ -0,0 +1,16 @@
'use strict'
const axios = require('axios');
const { GithubActions } = require('../githubActions');
/**
* @param {GithubActions} actions
*
* @returns {(response: axios.AxiosResponse) => void}
*/
const createOutputHandler = (actions) => (response) => {
actions.setOutput('response', response.data)
actions.setOutput('headers', response.headers)
}
module.exports = { createOutputHandler }

View file

@ -119,9 +119,6 @@ const request = async({ method, instanceConfig, data, files, file, actions, opti
return null
}
actions.setOutput('response', JSON.stringify(response.data))
actions.setOutput('headers', response.headers)
return response
} catch (error) {
if ((typeof error === 'object') && (error.isAxiosError === true)) {

View file

@ -5,7 +5,10 @@ const axios = require('axios');
const https = require('https');
const { request, METHOD_POST } = require('./httpClient');
const { GithubActions } = require('./githubActions');
const { createPersistHandler } = require('./handler/persist');
const { createOutputHandler } = require('./handler/output');
const { createMaskHandler } = require('./handler/mask');
let customHeaders = {}
@ -73,9 +76,16 @@ if (typeof ignoreStatusCodes === 'string' && ignoreStatusCodes.length > 0) {
ignoredCodes = ignoreStatusCodes.split(',').map(statusCode => parseInt(statusCode.trim()))
}
const handler = [];
const actions = new GithubActions();
const handler = [];
if (core.getBooleanInput('maskResponse')) {
handler.push(createMaskHandler(actions))
}
handler.push(createOutputHandler(actions))
if (!!responseFile) {
handler.push(createPersistHandler(responseFile, actions))
}
@ -89,7 +99,7 @@ const options = {
}
request({ data, method, instanceConfig, files, file, actions, options }).then(response => {
if (typeof response == 'object') {
if (response && typeof response == 'object') {
handler.forEach(h => h(response))
}
})