Skip to content

Commit d81c81a

Browse files
authored
Merge pull request #124 from fjogeleit/response-mask
mask response as secret if configured
2 parents 25a5a55 + 2d6a2f1 commit d81c81a

File tree

7 files changed

+124
-10
lines changed

7 files changed

+124
-10
lines changed

action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ inputs:
5959
responseFile:
6060
description: 'Persist the response data to the specified file path'
6161
required: false
62+
maskResponse:
63+
description: 'Allows to mark your response as secret and hide the output in the action logs'
64+
required: false
65+
default: 'false'
6266
retry:
6367
description: 'optional amount of retries if the request fails'
6468
required: false

dist/index.js

+67-5
Original file line numberDiff line numberDiff line change
@@ -26561,6 +26561,10 @@ class GithubActions {
2656126561
core.setOutput(name, output)
2656226562
}
2656326563

26564+
setSecret(value) {
26565+
core.setSecret(value)
26566+
}
26567+
2656426568
setFailed(message) {
2656526569
core.setFailed(message)
2656626570
}
@@ -26591,6 +26595,57 @@ class LogActions {
2659126595
module.exports = { GithubActions, LogActions }
2659226596

2659326597

26598+
/***/ }),
26599+
26600+
/***/ 8566:
26601+
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
26602+
26603+
"use strict";
26604+
26605+
26606+
const axios = __nccwpck_require__(8757);
26607+
const { GithubActions } = __nccwpck_require__(8169);
26608+
26609+
/**
26610+
* @param {GithubActions} actions
26611+
*
26612+
* @returns {(response: axios.AxiosResponse) => void}
26613+
*/
26614+
const createMaskHandler = (actions) => (response) => {
26615+
let data = response.data
26616+
26617+
if (typeof data == 'object') {
26618+
data = JSON.stringify(data)
26619+
}
26620+
26621+
actions.setSecret(data)
26622+
}
26623+
26624+
module.exports = { createMaskHandler }
26625+
26626+
/***/ }),
26627+
26628+
/***/ 2190:
26629+
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
26630+
26631+
"use strict";
26632+
26633+
26634+
const axios = __nccwpck_require__(8757);
26635+
const { GithubActions } = __nccwpck_require__(8169);
26636+
26637+
/**
26638+
* @param {GithubActions} actions
26639+
*
26640+
* @returns {(response: axios.AxiosResponse) => void}
26641+
*/
26642+
const createOutputHandler = (actions) => (response) => {
26643+
actions.setOutput('response', response.data)
26644+
actions.setOutput('headers', response.headers)
26645+
}
26646+
26647+
module.exports = { createOutputHandler }
26648+
2659426649
/***/ }),
2659526650

2659626651
/***/ 6733:
@@ -26840,9 +26895,6 @@ const request = async({ method, instanceConfig, data, files, file, actions, opti
2684026895
return null
2684126896
}
2684226897

26843-
actions.setOutput('response', JSON.stringify(response.data))
26844-
actions.setOutput('headers', response.headers)
26845-
2684626898
return response
2684726899
} catch (error) {
2684826900
if ((typeof error === 'object') && (error.isAxiosError === true)) {
@@ -33180,7 +33232,10 @@ const axios = __nccwpck_require__(8757);
3318033232
const https = __nccwpck_require__(5687);
3318133233
const { request, METHOD_POST } = __nccwpck_require__(9082);
3318233234
const { GithubActions } = __nccwpck_require__(8169);
33235+
3318333236
const { createPersistHandler } = __nccwpck_require__(6733);
33237+
const { createOutputHandler } = __nccwpck_require__(2190);
33238+
const { createMaskHandler } = __nccwpck_require__(8566);
3318433239

3318533240
let customHeaders = {}
3318633241

@@ -33248,9 +33303,16 @@ if (typeof ignoreStatusCodes === 'string' && ignoreStatusCodes.length > 0) {
3324833303
ignoredCodes = ignoreStatusCodes.split(',').map(statusCode => parseInt(statusCode.trim()))
3324933304
}
3325033305

33251-
const handler = [];
3325233306
const actions = new GithubActions();
3325333307

33308+
const handler = [];
33309+
33310+
if (core.getBooleanInput('maskResponse')) {
33311+
handler.push(createMaskHandler(actions))
33312+
}
33313+
33314+
handler.push(createOutputHandler(actions))
33315+
3325433316
if (!!responseFile) {
3325533317
handler.push(createPersistHandler(responseFile, actions))
3325633318
}
@@ -33264,7 +33326,7 @@ const options = {
3326433326
}
3326533327

3326633328
request({ data, method, instanceConfig, files, file, actions, options }).then(response => {
33267-
if (typeof response == 'object') {
33329+
if (response && typeof response == 'object') {
3326833330
handler.forEach(h => h(response))
3326933331
}
3327033332
})

src/githubActions.js

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ class GithubActions {
1919
core.setOutput(name, output)
2020
}
2121

22+
setSecret(value) {
23+
core.setSecret(value)
24+
}
25+
2226
setFailed(message) {
2327
core.setFailed(message)
2428
}

src/handler/mask.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict'
2+
3+
const axios = require('axios');
4+
const { GithubActions } = require('../githubActions');
5+
6+
/**
7+
* @param {GithubActions} actions
8+
*
9+
* @returns {(response: axios.AxiosResponse) => void}
10+
*/
11+
const createMaskHandler = (actions) => (response) => {
12+
let data = response.data
13+
14+
if (typeof data == 'object') {
15+
data = JSON.stringify(data)
16+
}
17+
18+
actions.setSecret(data)
19+
}
20+
21+
module.exports = { createMaskHandler }

src/handler/output.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict'
2+
3+
const axios = require('axios');
4+
const { GithubActions } = require('../githubActions');
5+
6+
/**
7+
* @param {GithubActions} actions
8+
*
9+
* @returns {(response: axios.AxiosResponse) => void}
10+
*/
11+
const createOutputHandler = (actions) => (response) => {
12+
actions.setOutput('response', response.data)
13+
actions.setOutput('headers', response.headers)
14+
}
15+
16+
module.exports = { createOutputHandler }

src/httpClient.js

-3
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,6 @@ const request = async({ method, instanceConfig, data, files, file, actions, opti
119119
return null
120120
}
121121

122-
actions.setOutput('response', JSON.stringify(response.data))
123-
actions.setOutput('headers', response.headers)
124-
125122
return response
126123
} catch (error) {
127124
if ((typeof error === 'object') && (error.isAxiosError === true)) {

src/index.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ const axios = require('axios');
55
const https = require('https');
66
const { request, METHOD_POST } = require('./httpClient');
77
const { GithubActions } = require('./githubActions');
8+
89
const { createPersistHandler } = require('./handler/persist');
10+
const { createOutputHandler } = require('./handler/output');
11+
const { createMaskHandler } = require('./handler/mask');
912

1013
let customHeaders = {}
1114

@@ -73,9 +76,16 @@ if (typeof ignoreStatusCodes === 'string' && ignoreStatusCodes.length > 0) {
7376
ignoredCodes = ignoreStatusCodes.split(',').map(statusCode => parseInt(statusCode.trim()))
7477
}
7578

76-
const handler = [];
7779
const actions = new GithubActions();
7880

81+
const handler = [];
82+
83+
if (core.getBooleanInput('maskResponse')) {
84+
handler.push(createMaskHandler(actions))
85+
}
86+
87+
handler.push(createOutputHandler(actions))
88+
7989
if (!!responseFile) {
8090
handler.push(createPersistHandler(responseFile, actions))
8191
}
@@ -89,7 +99,7 @@ const options = {
8999
}
90100

91101
request({ data, method, instanceConfig, files, file, actions, options }).then(response => {
92-
if (typeof response == 'object') {
102+
if (response && typeof response == 'object') {
93103
handler.forEach(h => h(response))
94104
}
95105
})

0 commit comments

Comments
 (0)