Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mask response as secret if configured #124

Merged
merged 1 commit into from Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions action.yml
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
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
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
@@ -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
@@ -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
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
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))
}
})