Skip to content

Commit eeddd09

Browse files
authored
Merge pull request #26 from githubocto/secrets-mask
feat: add a "mask" param to hide secrets from http_url
2 parents 6283443 + 471ce76 commit eeddd09

7 files changed

Lines changed: 643 additions & 7 deletions

File tree

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,19 @@ In `http` mode this can be anything. This can be any endpoint: a json, csv, txt,
9999

100100
A path to a local Deno javascript or typescript file for postprocessing the `downloaded_filename` file. Read more in the ["Postprocessing section"](https://github.com/githubocto/flat#postprocessing).
101101

102+
#### `mask` (optional)
103+
104+
If your `http_url` string contains secrets, you can choose to mask it from the commit message. You have two options:
105+
106+
**Option 1**: use a string boolean
107+
108+
`mask: true # removes the source entirely from the commit message, defaults to false`
109+
110+
**Option 2**: use a string array with each secret to mask
111+
112+
`mask: '["${{ secrets.SECRET1 }}", "${{ secrets.SECRET2 }}"]'`
113+
114+
102115
### SQL Mode
103116
104117
#### `sql_connstring`

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ inputs:
88
http_url:
99
description: 'A URL containing data to fetch.'
1010
required: false
11+
mask:
12+
description: 'A string array of secrets to strip from the http_url or a string boolean'
13+
required: false
1114
sql_connstring:
1215
description: 'A connection string for making a SQL query.'
1316
required: false

dist/index.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ const CommonConfigSchema = z.object({
233233
const HTTPConfigSchema = z
234234
.object({
235235
http_url: z.string(),
236+
mask: z.string().optional() // string array of secrets or boolean
236237
})
237238
.merge(CommonConfigSchema);
238239
const SQLConfigSchema = z
@@ -247,12 +248,13 @@ function getConfig() {
247248
const keys = [
248249
'downloaded_filename',
249250
'http_url',
251+
'mask',
250252
'sql_connstring',
251253
'sql_queryfile',
252254
'postprocess',
253255
];
254256
keys.forEach(k => {
255-
const v = core.getInput(k);
257+
const v = core.getInput(k); // getInput always returns a string
256258
if (v) {
257259
raw[k] = v;
258260
}
@@ -449,9 +451,30 @@ async function run() {
449451
core.startGroup('Fetch data');
450452
let filename = '';
451453
let source;
454+
let shouldMask = false; // by default we don't mask the source
455+
let sourceMasked = '';
452456
if (config_1.isHTTPConfig(config)) {
453457
filename = await http_1.default(config);
454458
source = config.http_url;
459+
// if including a mask config then we can strip out secrets from the http_url
460+
sourceMasked = source; // if no secrets to mask then this is just source
461+
if (config.mask) {
462+
if (config.mask === 'true' || config.mask === 'false') { // mask param is a string
463+
shouldMask = JSON.parse(config.mask); // convert to boolean
464+
}
465+
else {
466+
try {
467+
const maskArray = JSON.parse(config.mask);
468+
maskArray.forEach((secretToMask) => {
469+
const regex = new RegExp(secretToMask, "g");
470+
sourceMasked = sourceMasked.replace(regex, "***");
471+
});
472+
}
473+
catch (error) {
474+
core.setFailed('Mask param formatted incorrectly. It should be a string array OR a "true" or "false" string.');
475+
}
476+
}
477+
}
455478
}
456479
else if (config_1.isSQLConfig(config)) {
457480
filename = await sql_1.default(config);
@@ -497,8 +520,8 @@ async function run() {
497520
core.debug(`git adding ${filename}…`);
498521
await exec_1.exec('git', ['add', filename]);
499522
const bytes = await git_1.diff(filename);
500-
// core.setOutput('delta_bytes', bytes)
501-
editedFiles.push({ name: filename, deltaBytes: bytes, source });
523+
const source = shouldMask ? {} : { source: sourceMasked };
524+
editedFiles.push({ name: filename, deltaBytes: bytes, ...source });
502525
}
503526
core.endGroup();
504527
core.startGroup('Committing new data');

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)