Skip to content

Commit

Permalink
Merge pull request #124 from fjogeleit/response-mask
Browse files Browse the repository at this point in the history
mask response as secret if configured
  • Loading branch information
fjogeleit authored Dec 18, 2023
2 parents 25a5a55 + 2d6a2f1 commit d81c81a
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 10 deletions.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
72 changes: 67 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26561,6 +26561,10 @@ class GithubActions {
core.setOutput(name, output)
}

setSecret(value) {
core.setSecret(value)
}

setFailed(message) {
core.setFailed(message)
}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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 = {}

Expand Down Expand Up @@ -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))
}
Expand All @@ -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))
}
})
Expand Down
4 changes: 4 additions & 0 deletions src/githubActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class GithubActions {
core.setOutput(name, output)
}

setSecret(value) {
core.setSecret(value)
}

setFailed(message) {
core.setFailed(message)
}
Expand Down
21 changes: 21 additions & 0 deletions src/handler/mask.js
Original file line number Diff line number Diff line change
@@ -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 changes: 16 additions & 0 deletions src/handler/output.js
Original file line number Diff line number Diff line change
@@ -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 }
3 changes: 0 additions & 3 deletions src/httpClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
14 changes: 12 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down Expand Up @@ -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))
}
Expand All @@ -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))
}
})

0 comments on commit d81c81a

Please sign in to comment.