@continuoussecuritytooling/keycloak-reporter 0.4.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.bin/wait-for-server.sh +1 -0
- package/.ct.yaml +1 -1
- package/.eslintrc.cjs +3 -3
- package/.github/CONTRIBUTING.md +5 -5
- package/.github/workflows/pipeline.yml +31 -23
- package/.github/workflows/release.yml +23 -3
- package/.prettierrc +6 -0
- package/Dockerfile +4 -2
- package/README.md +6 -7
- package/charts/keycloak-reporter/Chart.yaml +3 -2
- package/charts/keycloak-reporter/README.md +2 -2
- package/charts/keycloak-reporter/templates/_helpers.tpl +21 -0
- package/charts/keycloak-reporter/templates/cronjob.yaml +5 -3
- package/charts/keycloak-reporter/values.yaml +4 -7
- package/cli.ts +61 -30
- package/config.json +9 -0
- package/dist/cli.js +41 -19
- package/dist/cli.js.map +1 -1
- package/dist/lib/output.js +53 -50
- package/dist/lib/output.js.map +1 -1
- package/e2e/spec/webhooks.js +84 -10
- package/k8s.yaml +51 -0
- package/keycloak-reporter-0.5.0.tgz +0 -0
- package/lib/output.ts +63 -57
- package/package.json +5 -3
- package/renovate.json +15 -7
- package/test.values.yaml +8 -0
package/dist/cli.js
CHANGED
|
@@ -3,7 +3,7 @@ import { writeFileSync } from 'node:fs';
|
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import yargs from 'yargs/yargs';
|
|
5
5
|
import { hideBin } from 'yargs/helpers';
|
|
6
|
-
import { listUsers, listClients, convertJSON2CSV, post2Webhook
|
|
6
|
+
import { listUsers, listClients, convertJSON2CSV, post2Webhook } from './index.js';
|
|
7
7
|
import config from './src/config.js';
|
|
8
8
|
class WebhookConfig {
|
|
9
9
|
constructor(type, url, title, message) {
|
|
@@ -17,6 +17,7 @@ class ReportConfig {
|
|
|
17
17
|
}
|
|
18
18
|
async function convert(format, output, reports, config, json) {
|
|
19
19
|
let outputContent;
|
|
20
|
+
console.log(output);
|
|
20
21
|
switch (format) {
|
|
21
22
|
case 'csv':
|
|
22
23
|
outputContent = (await convertJSON2CSV(json)).toString();
|
|
@@ -35,8 +36,17 @@ async function convert(format, output, reports, config, json) {
|
|
|
35
36
|
await post2Webhook(config.type, config.url, config.title, outputContent, config.message);
|
|
36
37
|
}
|
|
37
38
|
catch (e) {
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
switch (e.code || e.message) {
|
|
40
|
+
case 'Request failed with status code 400':
|
|
41
|
+
console.error('Invalid Teams Webhook Payload. Check your params.');
|
|
42
|
+
throw new Error('Invalid Teams Payload');
|
|
43
|
+
case 'slack_webhook_http_error':
|
|
44
|
+
console.error('Invalid Slack Webhook Payload. Check your params.');
|
|
45
|
+
throw new Error('Invalid Slack Payload');
|
|
46
|
+
default:
|
|
47
|
+
console.error(`Error during sending webhook.(${e === null || e === void 0 ? void 0 : e.code})`, e === null || e === void 0 ? void 0 : e.original);
|
|
48
|
+
throw e;
|
|
49
|
+
}
|
|
40
50
|
}
|
|
41
51
|
break;
|
|
42
52
|
// defaulting to standard out
|
|
@@ -50,59 +60,71 @@ yargs(hideBin(process.argv))
|
|
|
50
60
|
() => { }, async (argv) => {
|
|
51
61
|
const users = await listUsers({
|
|
52
62
|
clientId: argv.clientId ? argv.clientId : config.clientId,
|
|
53
|
-
clientSecret: argv.clientSecret
|
|
54
|
-
|
|
63
|
+
clientSecret: argv.clientSecret
|
|
64
|
+
? argv.clientSecret
|
|
65
|
+
: config.clientSecret,
|
|
66
|
+
rootUrl: argv.url ? argv.url : config.url
|
|
55
67
|
});
|
|
56
|
-
await convert(argv.format, argv.output, {
|
|
68
|
+
await convert(config.format ? config.format : argv.format, config.output ? config.output : argv.output, {
|
|
57
69
|
name: 'user_listing',
|
|
58
|
-
directory: argv.reports
|
|
59
|
-
}, new WebhookConfig(
|
|
70
|
+
directory: argv.reports ? argv.reports : config.reports
|
|
71
|
+
}, new WebhookConfig(config.webhookType
|
|
72
|
+
? config.webhookType
|
|
73
|
+
: argv.webhookType, config.webhookUrl ? config.webhookUrl : argv.webhookUrl, 'User Listing', argv.webhookMessage
|
|
74
|
+
? argv.webhookMessage
|
|
75
|
+
: config.webhookMessage), users);
|
|
60
76
|
})
|
|
61
77
|
.command('listClients [url] [clientId] [clientSecret]', 'fetches all clients in the realms.',
|
|
62
78
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
63
79
|
() => { }, async (argv) => {
|
|
64
80
|
const clients = await listClients({
|
|
65
81
|
clientId: argv.clientId ? argv.clientId : config.clientId,
|
|
66
|
-
clientSecret: argv.clientSecret
|
|
67
|
-
|
|
82
|
+
clientSecret: argv.clientSecret
|
|
83
|
+
? argv.clientSecret
|
|
84
|
+
: config.clientSecret,
|
|
85
|
+
rootUrl: argv.url ? argv.url : config.url
|
|
68
86
|
});
|
|
69
|
-
await convert(argv.format, argv.output, {
|
|
87
|
+
await convert(config.format ? config.format : argv.format, config.output ? config.output : argv.output, {
|
|
70
88
|
name: 'client_listing',
|
|
71
|
-
directory: argv.reports
|
|
72
|
-
}, new WebhookConfig(
|
|
89
|
+
directory: argv.reports ? argv.reports : config.reports
|
|
90
|
+
}, new WebhookConfig(config.webhookType
|
|
91
|
+
? config.webhookType
|
|
92
|
+
: argv.webhookType, config.webhookUrl ? config.webhookUrl : argv.webhookUrl, 'Client Listing', argv.webhookMessage
|
|
93
|
+
? argv.webhookMessage
|
|
94
|
+
: config.webhookMessage), clients);
|
|
73
95
|
})
|
|
74
96
|
.option('format', {
|
|
75
97
|
alias: 'f',
|
|
76
98
|
type: 'string',
|
|
77
99
|
default: 'json',
|
|
78
|
-
description: 'output format, e.g. JSON|CSV'
|
|
100
|
+
description: 'output format, e.g. JSON|CSV'
|
|
79
101
|
})
|
|
80
102
|
.option('output', {
|
|
81
103
|
alias: 'o',
|
|
82
104
|
type: 'string',
|
|
83
105
|
default: 'stdout',
|
|
84
|
-
description: 'output channel'
|
|
106
|
+
description: 'output channel'
|
|
85
107
|
})
|
|
86
108
|
.option('webhookType', {
|
|
87
109
|
alias: 'w',
|
|
88
110
|
type: 'string',
|
|
89
111
|
default: 'slack',
|
|
90
|
-
description: 'Webhook Type'
|
|
112
|
+
description: 'Webhook Type'
|
|
91
113
|
})
|
|
92
114
|
.option('webhookMessage', {
|
|
93
115
|
alias: 'm',
|
|
94
116
|
type: 'string',
|
|
95
|
-
description: 'Webhook Message'
|
|
117
|
+
description: 'Webhook Message'
|
|
96
118
|
})
|
|
97
119
|
.option('webhookUrl', {
|
|
98
120
|
alias: 't',
|
|
99
121
|
type: 'string',
|
|
100
|
-
description: 'Webhook URL'
|
|
122
|
+
description: 'Webhook URL'
|
|
101
123
|
})
|
|
102
124
|
.option('reports', {
|
|
103
125
|
alias: 'r',
|
|
104
126
|
type: 'string',
|
|
105
|
-
description: 'Reports directory'
|
|
127
|
+
description: 'Reports directory'
|
|
106
128
|
})
|
|
107
129
|
.parse();
|
|
108
130
|
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,aAAa,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EACL,SAAS,EACT,WAAW,EAEX,eAAe,EACf,YAAY,
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,aAAa,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EACL,SAAS,EACT,WAAW,EAEX,eAAe,EACf,YAAY,EACb,MAAM,YAAY,C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BAAiB;CAC/B,CAAC;KACD,MAAM,CAAC,YAAY,EAAE;IACpB,KAAK,EAAE,GAAG;IACV,IAAI,EAAE,QAAQ;IACd,WAAW,EAAE,aAAa;CAC3B,CAAC;KACD,MAAM,CAAC,SAAS,EAAE;IACjB,KAAK,EAAE,GAAG;IACV,IAAI,EAAE,QAAQ;IACd,WAAW,EAAE,mBAAmB;CACjC,CAAC;KACD,KAAK,EAAE,CAAC"}
|
package/dist/lib/output.js
CHANGED
|
@@ -25,19 +25,19 @@ export async function post2Webhook(type, url, title, reportContent, text) {
|
|
|
25
25
|
facts: [
|
|
26
26
|
{
|
|
27
27
|
title: 'Type',
|
|
28
|
-
value: title
|
|
28
|
+
value: title
|
|
29
29
|
},
|
|
30
30
|
{
|
|
31
31
|
title: 'Date',
|
|
32
|
-
value: `${date.getDate()}-${date.getMonth() + 1}-${date.getFullYear()}
|
|
33
|
-
}
|
|
34
|
-
]
|
|
32
|
+
value: `${date.getDate()}-${date.getMonth() + 1}-${date.getFullYear()}`
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
35
|
},
|
|
36
36
|
{
|
|
37
37
|
type: 'TextBlock',
|
|
38
38
|
text: text != null ? text : '',
|
|
39
|
-
wrap: true
|
|
40
|
-
}
|
|
39
|
+
wrap: true
|
|
40
|
+
}
|
|
41
41
|
],
|
|
42
42
|
actions: [
|
|
43
43
|
{
|
|
@@ -49,59 +49,62 @@ export async function post2Webhook(type, url, title, reportContent, text) {
|
|
|
49
49
|
{
|
|
50
50
|
type: 'TextBlock',
|
|
51
51
|
text: reportContent,
|
|
52
|
-
wrap: true
|
|
53
|
-
}
|
|
52
|
+
wrap: true
|
|
53
|
+
}
|
|
54
54
|
],
|
|
55
|
-
$schema: 'http://adaptivecards.io/schemas/adaptive-card.json'
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
]
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
]
|
|
55
|
+
$schema: 'http://adaptivecards.io/schemas/adaptive-card.json'
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
62
|
});
|
|
63
63
|
// defaulting to Slack
|
|
64
64
|
default:
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
65
|
+
// eslint-disable-next-line no-case-declarations
|
|
66
|
+
const blockEntries = [
|
|
67
|
+
{
|
|
68
|
+
type: 'section',
|
|
69
|
+
fields: [
|
|
70
|
+
{ type: 'mrkdwn', text: `*Type*: ${title}` },
|
|
71
|
+
{
|
|
72
|
+
type: 'mrkdwn',
|
|
73
|
+
text: `*Date*: ${date.getDate()}-${date.getMonth() + 1}-${date.getFullYear()}`
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
type: 'divider'
|
|
79
|
+
}
|
|
80
|
+
];
|
|
81
|
+
if (text != null) {
|
|
82
|
+
blockEntries.push({
|
|
83
|
+
type: 'context',
|
|
84
|
+
elements: [{ type: 'plain_text', text: text }]
|
|
85
|
+
});
|
|
86
|
+
blockEntries.push({
|
|
87
|
+
type: 'divider'
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
blockEntries.push({
|
|
91
|
+
type: 'context',
|
|
92
|
+
elements: [
|
|
77
93
|
{
|
|
78
|
-
type: '
|
|
79
|
-
|
|
80
|
-
{
|
|
81
|
-
type: 'context',
|
|
82
|
-
elements: [{ type: 'plain_text', text: text != null ? text : '' }],
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
type: 'divider',
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
type: 'context',
|
|
89
|
-
elements: [
|
|
90
|
-
{
|
|
91
|
-
type: 'mrkdwn',
|
|
92
|
-
text: `
|
|
94
|
+
type: 'mrkdwn',
|
|
95
|
+
text: `
|
|
93
96
|
\`\`\`
|
|
94
97
|
${reportContent}
|
|
95
98
|
\`\`\`
|
|
96
99
|
`
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
}, {
|
|
103
|
+
type: 'context',
|
|
104
|
+
elements: [{ type: 'plain_text', text: 'Raw report data' }]
|
|
105
|
+
});
|
|
106
|
+
return new SlackWebhook(url).send({
|
|
107
|
+
blocks: blockEntries
|
|
105
108
|
});
|
|
106
109
|
}
|
|
107
110
|
}
|
package/dist/lib/output.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output.js","sourceRoot":"","sources":["../../lib/output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,IAAI,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEnE,OAAO,EAAE,eAAe,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEjE,IAAK,WAGJ;AAHD,WAAK,WAAW;IACd,8BAAe,CAAA;IACf,8BAAe,CAAA;AACjB,CAAC,EAHI,WAAW,KAAX,WAAW,QAGf;AAOD,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,IAAY,EACZ,GAAW,EACX,KAAa,EACb,aAAqB,EACrB,IAAa;IAEb,oCAAoC;IACpC,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;IACxB,QAAQ,IAAI,EAAE;QACZ,KAAK,WAAW,CAAC,KAAK,CAAC,QAAQ,EAAE;YAC/B,OAAO,IAAI,YAAY,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBAChC,IAAI,EAAE,SAAS;gBACf,WAAW,EAAE;oBACX;wBACE,WAAW,EAAE,yCAAyC;wBACtD,OAAO,EAAE;4BACP,OAAO,EAAE,oDAAoD;4BAC7D,IAAI,EAAE,cAAc;4BACpB,OA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E,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;iBAC/C,CAAC,CAAC;gBACH,YAAY,CAAC,IAAI,CAAC;oBAChB,IAAI,EAAE,SAAS;iBAChB,CAAC,CAAC;aACJ;YACD,YAAY,CAAC,IAAI,CACf;gBACE,IAAI,EAAE,SAAS;gBACf,QAAQ,EAAE;oBACR;wBACE,IAAI,EAAE,QAAQ;wBACd,IAAI,EAAE;;EAElB,aAAa;;CAEd;qBACY;iBACF;aACF,EACD;gBACE,IAAI,EAAE,SAAS;gBACf,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,iBAAiB,EAAE,CAAC;aAC5D,CACF,CAAC;YACF,OAAO,IAAI,YAAY,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBAChC,MAAM,EAAE,YAAY;aACrB,CAAC,CAAC;KACN;AACH,CAAC;AAED;GACG"}
|
package/e2e/spec/webhooks.js
CHANGED
|
@@ -4,7 +4,7 @@ import { test } from 'tape';
|
|
|
4
4
|
import { spawn } from 'node:child_process';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
|
|
7
|
-
test('Should post message to Teams',
|
|
7
|
+
test('Should post message to Teams', { timeout: 10000 }, (t) => {
|
|
8
8
|
const cli = spawn(
|
|
9
9
|
path.join(path.dirname('.'), 'node'),
|
|
10
10
|
[
|
|
@@ -15,26 +15,66 @@ test('Should post message to Teams', { timeout: 10000 }, (t) => {
|
|
|
15
15
|
'3UYhI2hryFwoVtcd7ljlaDuD9HXrGV5r',
|
|
16
16
|
'--output=webhook',
|
|
17
17
|
'--webhookType=teams',
|
|
18
|
-
'--webhookUrl=' + process.env.WEBHOOK_TESTING_TEAMS
|
|
18
|
+
'--webhookUrl=' + process.env.WEBHOOK_TESTING_TEAMS
|
|
19
19
|
],
|
|
20
20
|
{
|
|
21
21
|
env: {
|
|
22
|
-
...process.env
|
|
23
|
-
}
|
|
22
|
+
...process.env
|
|
23
|
+
}
|
|
24
24
|
}
|
|
25
25
|
);
|
|
26
26
|
cli.stdout.on('data', (chunk) => {
|
|
27
27
|
console.log(chunk.toString());
|
|
28
28
|
});
|
|
29
29
|
cli.stderr.on('data', (msg) => {
|
|
30
|
-
t.fail(msg)
|
|
30
|
+
t.fail(msg);
|
|
31
31
|
});
|
|
32
32
|
cli.stdout.on('end', () => {
|
|
33
33
|
t.end();
|
|
34
34
|
});
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
test(
|
|
37
|
+
test(
|
|
38
|
+
'Should post message to Teams with additional message',
|
|
39
|
+
{ timeout: 10000 },
|
|
40
|
+
(t) => {
|
|
41
|
+
const cli = spawn(
|
|
42
|
+
path.join(path.dirname('.'), 'node'),
|
|
43
|
+
[
|
|
44
|
+
'dist/cli.js',
|
|
45
|
+
'listUsers',
|
|
46
|
+
'http://localhost:8080',
|
|
47
|
+
'keycloak-reporter',
|
|
48
|
+
'3UYhI2hryFwoVtcd7ljlaDuD9HXrGV5r',
|
|
49
|
+
'--output=webhook',
|
|
50
|
+
'--webhookType=teams',
|
|
51
|
+
'--webhookUrl=' + process.env.WEBHOOK_TESTING_TEAMS,
|
|
52
|
+
'--webhookMessage="' +
|
|
53
|
+
(process.env.WEBHOOK_ADDITIONAL_MESSAGE || 'From Github Actions') +
|
|
54
|
+
'"'
|
|
55
|
+
],
|
|
56
|
+
{
|
|
57
|
+
env: {
|
|
58
|
+
...process.env
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
cli.stdout.on('data', (chunk) => {
|
|
63
|
+
console.log(chunk.toString());
|
|
64
|
+
});
|
|
65
|
+
cli.stderr.on('data', (msg) => {
|
|
66
|
+
t.fail(msg);
|
|
67
|
+
});
|
|
68
|
+
cli.stdout.on('end', () => {
|
|
69
|
+
t.end();
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
test(
|
|
75
|
+
'Should post message to Slack with additional message',
|
|
76
|
+
{ timeout: 10000 },
|
|
77
|
+
(t) => {
|
|
38
78
|
const cli = spawn(
|
|
39
79
|
path.join(path.dirname('.'), 'node'),
|
|
40
80
|
[
|
|
@@ -46,20 +86,54 @@ test('Should post message to Slack', { timeout: 10000 }, (t) => {
|
|
|
46
86
|
'--output=webhook',
|
|
47
87
|
'--webhookType=slack',
|
|
48
88
|
'--webhookUrl=' + process.env.WEBHOOK_TESTING_SLACK,
|
|
89
|
+
'--webhookMessage="' +
|
|
90
|
+
(process.env.WEBHOOK_ADDITIONAL_MESSAGE || 'From Github Actions') +
|
|
91
|
+
'"'
|
|
49
92
|
],
|
|
50
93
|
{
|
|
51
94
|
env: {
|
|
52
|
-
...process.env
|
|
53
|
-
}
|
|
95
|
+
...process.env
|
|
96
|
+
}
|
|
54
97
|
}
|
|
55
98
|
);
|
|
56
99
|
cli.stdout.on('data', (chunk) => {
|
|
57
|
-
console.log(chunk.toString())
|
|
100
|
+
console.log(chunk.toString());
|
|
58
101
|
});
|
|
59
102
|
cli.stderr.on('data', (msg) => {
|
|
60
|
-
t.fail(msg)
|
|
103
|
+
t.fail(msg);
|
|
61
104
|
});
|
|
62
105
|
cli.stdout.on('end', () => {
|
|
63
106
|
t.end();
|
|
64
107
|
});
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
test('Should post message to Slack', { timeout: 10000 }, (t) => {
|
|
112
|
+
const cli = spawn(
|
|
113
|
+
path.join(path.dirname('.'), 'node'),
|
|
114
|
+
[
|
|
115
|
+
'dist/cli.js',
|
|
116
|
+
'listUsers',
|
|
117
|
+
'http://localhost:8080',
|
|
118
|
+
'keycloak-reporter',
|
|
119
|
+
'3UYhI2hryFwoVtcd7ljlaDuD9HXrGV5r',
|
|
120
|
+
'--output=webhook',
|
|
121
|
+
'--webhookType=slack',
|
|
122
|
+
'--webhookUrl=' + process.env.WEBHOOK_TESTING_SLACK
|
|
123
|
+
],
|
|
124
|
+
{
|
|
125
|
+
env: {
|
|
126
|
+
...process.env
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
);
|
|
130
|
+
cli.stdout.on('data', (chunk) => {
|
|
131
|
+
console.log(chunk.toString());
|
|
65
132
|
});
|
|
133
|
+
cli.stderr.on('data', (msg) => {
|
|
134
|
+
t.fail(msg);
|
|
135
|
+
});
|
|
136
|
+
cli.stdout.on('end', () => {
|
|
137
|
+
t.end();
|
|
138
|
+
});
|
|
139
|
+
});
|
package/k8s.yaml
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
apiVersion: batch/v1
|
|
2
|
+
kind: Job
|
|
3
|
+
metadata:
|
|
4
|
+
name: test-job
|
|
5
|
+
namespace: kc-reporter
|
|
6
|
+
spec:
|
|
7
|
+
suspend: false
|
|
8
|
+
template:
|
|
9
|
+
spec:
|
|
10
|
+
containers:
|
|
11
|
+
- command:
|
|
12
|
+
- /bin/sh
|
|
13
|
+
- -c
|
|
14
|
+
- |
|
|
15
|
+
while true; do sleep 30; done;
|
|
16
|
+
env:
|
|
17
|
+
- name: CONFIG_FILE
|
|
18
|
+
value: /app/config.json
|
|
19
|
+
image: continuoussecuritytooling/keycloak-reporting-cli:0.5.1
|
|
20
|
+
imagePullPolicy: IfNotPresent
|
|
21
|
+
name: users
|
|
22
|
+
resources: {}
|
|
23
|
+
terminationMessagePath: /dev/termination-log
|
|
24
|
+
terminationMessagePolicy: File
|
|
25
|
+
volumeMounts:
|
|
26
|
+
- mountPath: /app/config.json
|
|
27
|
+
name: config-file
|
|
28
|
+
readOnly: true
|
|
29
|
+
subPath: config.json
|
|
30
|
+
dnsPolicy: ClusterFirst
|
|
31
|
+
restartPolicy: OnFailure
|
|
32
|
+
schedulerName: default-scheduler
|
|
33
|
+
securityContext: {}
|
|
34
|
+
terminationGracePeriodSeconds: 30
|
|
35
|
+
volumes:
|
|
36
|
+
- name: config-file
|
|
37
|
+
secret:
|
|
38
|
+
defaultMode: 420
|
|
39
|
+
secretName: kc-reporter-test-keycloak-reporter
|
|
40
|
+
status:
|
|
41
|
+
conditions:
|
|
42
|
+
- lastProbeTime: "2023-10-07T07:43:08Z"
|
|
43
|
+
lastTransitionTime: "2023-10-07T07:43:08Z"
|
|
44
|
+
message: Job has reached the specified backoff limit
|
|
45
|
+
reason: BackoffLimitExceeded
|
|
46
|
+
status: "True"
|
|
47
|
+
type: Failed
|
|
48
|
+
failed: 1
|
|
49
|
+
ready: 0
|
|
50
|
+
startTime: "2023-10-07T07:37:15Z"
|
|
51
|
+
uncountedTerminatedPods: {}
|
|
Binary file
|
package/lib/output.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { IncomingWebhook as TeamsWebhook } from 'ms-teams-webhook';
|
|
2
|
-
import { Block, SectionBlock } from '@slack/types';
|
|
2
|
+
import { Block, ContextBlock, SectionBlock } from '@slack/types';
|
|
3
3
|
import { IncomingWebhook as SlackWebhook } from '@slack/webhook';
|
|
4
4
|
|
|
5
5
|
enum WebhookType {
|
|
6
6
|
SLACK = 'slack',
|
|
7
|
-
TEAMS = 'teams'
|
|
7
|
+
TEAMS = 'teams'
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export interface WebhookMessage {
|
|
@@ -17,7 +17,7 @@ export async function post2Webhook(
|
|
|
17
17
|
url: string,
|
|
18
18
|
title: string,
|
|
19
19
|
reportContent: string,
|
|
20
|
-
text?: string
|
|
20
|
+
text?: string
|
|
21
21
|
): Promise<unknown> {
|
|
22
22
|
//const title= 'Keycloak Reporting';
|
|
23
23
|
const date = new Date();
|
|
@@ -38,21 +38,21 @@ export async function post2Webhook(
|
|
|
38
38
|
facts: [
|
|
39
39
|
{
|
|
40
40
|
title: 'Type',
|
|
41
|
-
value: title
|
|
41
|
+
value: title
|
|
42
42
|
},
|
|
43
43
|
{
|
|
44
44
|
title: 'Date',
|
|
45
45
|
value: `${date.getDate()}-${
|
|
46
46
|
date.getMonth() + 1
|
|
47
|
-
}-${date.getFullYear()}
|
|
48
|
-
}
|
|
49
|
-
]
|
|
47
|
+
}-${date.getFullYear()}`
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
50
|
},
|
|
51
51
|
{
|
|
52
52
|
type: 'TextBlock',
|
|
53
|
-
text: text!=null ? text : '',
|
|
54
|
-
wrap: true
|
|
55
|
-
}
|
|
53
|
+
text: text != null ? text : '',
|
|
54
|
+
wrap: true
|
|
55
|
+
}
|
|
56
56
|
],
|
|
57
57
|
actions: [
|
|
58
58
|
{
|
|
@@ -64,62 +64,68 @@ export async function post2Webhook(
|
|
|
64
64
|
{
|
|
65
65
|
type: 'TextBlock',
|
|
66
66
|
text: reportContent,
|
|
67
|
-
wrap: true
|
|
68
|
-
}
|
|
67
|
+
wrap: true
|
|
68
|
+
}
|
|
69
69
|
],
|
|
70
70
|
$schema:
|
|
71
|
-
'http://adaptivecards.io/schemas/adaptive-card.json'
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
]
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
]
|
|
71
|
+
'http://adaptivecards.io/schemas/adaptive-card.json'
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
78
|
});
|
|
79
79
|
// defaulting to Slack
|
|
80
80
|
default:
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
{
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
81
|
+
// eslint-disable-next-line no-case-declarations
|
|
82
|
+
const blockEntries: Array<Block | ContextBlock | SectionBlock> = [
|
|
83
|
+
{
|
|
84
|
+
type: 'section',
|
|
85
|
+
fields: [
|
|
86
|
+
{ type: 'mrkdwn', text: `*Type*: ${title}` },
|
|
87
|
+
{
|
|
88
|
+
type: 'mrkdwn',
|
|
89
|
+
text: `*Date*: ${date.getDate()}-${
|
|
90
|
+
date.getMonth() + 1
|
|
91
|
+
}-${date.getFullYear()}`
|
|
92
|
+
}
|
|
93
|
+
]
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
type: 'divider'
|
|
97
|
+
}
|
|
98
|
+
];
|
|
99
|
+
if (text != null) {
|
|
100
|
+
blockEntries.push({
|
|
101
|
+
type: 'context',
|
|
102
|
+
elements: [{ type: 'plain_text', text: text }]
|
|
103
|
+
});
|
|
104
|
+
blockEntries.push({
|
|
105
|
+
type: 'divider'
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
blockEntries.push(
|
|
109
|
+
{
|
|
110
|
+
type: 'context',
|
|
111
|
+
elements: [
|
|
112
|
+
{
|
|
113
|
+
type: 'mrkdwn',
|
|
114
|
+
text: `
|
|
111
115
|
\`\`\`
|
|
112
116
|
${reportContent}
|
|
113
117
|
\`\`\`
|
|
114
118
|
`
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
119
|
+
}
|
|
120
|
+
]
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
type: 'context',
|
|
124
|
+
elements: [{ type: 'plain_text', text: 'Raw report data' }]
|
|
125
|
+
}
|
|
126
|
+
);
|
|
127
|
+
return new SlackWebhook(url).send({
|
|
128
|
+
blocks: blockEntries
|
|
123
129
|
});
|
|
124
130
|
}
|
|
125
131
|
}
|