@cdot65/prisma-airs-cli 2.8.0 → 2.10.0
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/README.md +132 -0
- package/dist/airs/dlp/data-filtering-profiles.d.ts +10 -0
- package/dist/airs/dlp/data-filtering-profiles.d.ts.map +1 -0
- package/dist/airs/dlp/data-filtering-profiles.js +17 -0
- package/dist/airs/dlp/data-filtering-profiles.js.map +1 -0
- package/dist/airs/dlp/data-patterns.d.ts +13 -0
- package/dist/airs/dlp/data-patterns.d.ts.map +1 -0
- package/dist/airs/dlp/data-patterns.js +26 -0
- package/dist/airs/dlp/data-patterns.js.map +1 -0
- package/dist/airs/dlp/data-profiles.d.ts +12 -0
- package/dist/airs/dlp/data-profiles.d.ts.map +1 -0
- package/dist/airs/dlp/data-profiles.js +23 -0
- package/dist/airs/dlp/data-profiles.js.map +1 -0
- package/dist/airs/dlp/dictionaries.d.ts +13 -0
- package/dist/airs/dlp/dictionaries.d.ts.map +1 -0
- package/dist/airs/dlp/dictionaries.js +34 -0
- package/dist/airs/dlp/dictionaries.js.map +1 -0
- package/dist/airs/dlp/index.d.ts +6 -0
- package/dist/airs/dlp/index.d.ts.map +1 -0
- package/dist/airs/dlp/index.js +6 -0
- package/dist/airs/dlp/index.js.map +1 -0
- package/dist/airs/dlp/types.d.ts +36 -0
- package/dist/airs/dlp/types.d.ts.map +1 -0
- package/dist/airs/dlp/types.js +2 -0
- package/dist/airs/dlp/types.js.map +1 -0
- package/dist/airs/management.d.ts +8 -1
- package/dist/airs/management.d.ts.map +1 -1
- package/dist/airs/management.js +16 -1
- package/dist/airs/management.js.map +1 -1
- package/dist/cli/commands/dlp/build-body.d.ts +28 -0
- package/dist/cli/commands/dlp/build-body.d.ts.map +1 -0
- package/dist/cli/commands/dlp/build-body.js +174 -0
- package/dist/cli/commands/dlp/build-body.js.map +1 -0
- package/dist/cli/commands/dlp/dictionaries.d.ts +3 -0
- package/dist/cli/commands/dlp/dictionaries.d.ts.map +1 -0
- package/dist/cli/commands/dlp/dictionaries.js +167 -0
- package/dist/cli/commands/dlp/dictionaries.js.map +1 -0
- package/dist/cli/commands/dlp/filtering-profiles.d.ts +3 -0
- package/dist/cli/commands/dlp/filtering-profiles.d.ts.map +1 -0
- package/dist/cli/commands/dlp/filtering-profiles.js +82 -0
- package/dist/cli/commands/dlp/filtering-profiles.js.map +1 -0
- package/dist/cli/commands/dlp/index.d.ts +3 -0
- package/dist/cli/commands/dlp/index.d.ts.map +1 -0
- package/dist/cli/commands/dlp/index.js +15 -0
- package/dist/cli/commands/dlp/index.js.map +1 -0
- package/dist/cli/commands/dlp/patch.d.ts +15 -0
- package/dist/cli/commands/dlp/patch.d.ts.map +1 -0
- package/dist/cli/commands/dlp/patch.js +70 -0
- package/dist/cli/commands/dlp/patch.js.map +1 -0
- package/dist/cli/commands/dlp/patterns.d.ts +3 -0
- package/dist/cli/commands/dlp/patterns.d.ts.map +1 -0
- package/dist/cli/commands/dlp/patterns.js +127 -0
- package/dist/cli/commands/dlp/patterns.js.map +1 -0
- package/dist/cli/commands/dlp/profiles.d.ts +3 -0
- package/dist/cli/commands/dlp/profiles.d.ts.map +1 -0
- package/dist/cli/commands/dlp/profiles.js +126 -0
- package/dist/cli/commands/dlp/profiles.js.map +1 -0
- package/dist/cli/commands/runtime.d.ts.map +1 -1
- package/dist/cli/commands/runtime.js +5 -0
- package/dist/cli/commands/runtime.js.map +1 -1
- package/dist/cli/debug-logger.d.ts +1 -0
- package/dist/cli/debug-logger.d.ts.map +1 -1
- package/dist/cli/debug-logger.js +2 -1
- package/dist/cli/debug-logger.js.map +1 -1
- package/dist/cli/renderer/dlp.d.ts +33 -0
- package/dist/cli/renderer/dlp.d.ts.map +1 -0
- package/dist/cli/renderer/dlp.js +348 -0
- package/dist/cli/renderer/dlp.js.map +1 -0
- package/dist/cli/renderer/index.d.ts +1 -0
- package/dist/cli/renderer/index.d.ts.map +1 -1
- package/dist/cli/renderer/index.js +1 -0
- package/dist/cli/renderer/index.js.map +1 -1
- package/dist/config/loader.d.ts.map +1 -1
- package/dist/config/loader.js +1 -0
- package/dist/config/loader.js.map +1 -1
- package/dist/config/schema.d.ts +3 -0
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +1 -0
- package/dist/config/schema.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Body-builders for DLP CLI commands. Each function takes parsed commander opts
|
|
3
|
+
* and returns a plain object suitable for the SDK request. Validation is light —
|
|
4
|
+
* Zod in the SDK does the heavy lifting on the wire.
|
|
5
|
+
*/
|
|
6
|
+
function asCsv(v) {
|
|
7
|
+
if (!v)
|
|
8
|
+
return undefined;
|
|
9
|
+
return v
|
|
10
|
+
.split(',')
|
|
11
|
+
.map((s) => s.trim())
|
|
12
|
+
.filter(Boolean);
|
|
13
|
+
}
|
|
14
|
+
function asNum(v) {
|
|
15
|
+
if (v == null)
|
|
16
|
+
return undefined;
|
|
17
|
+
const n = Number(v);
|
|
18
|
+
return Number.isFinite(n) ? n : undefined;
|
|
19
|
+
}
|
|
20
|
+
function parseTags(values) {
|
|
21
|
+
if (!values || values.length === 0)
|
|
22
|
+
return undefined;
|
|
23
|
+
const out = {};
|
|
24
|
+
for (const v of values) {
|
|
25
|
+
const eq = v.indexOf('=');
|
|
26
|
+
if (eq < 0)
|
|
27
|
+
throw new Error(`--tag must be 'key=value' (got '${v}')`);
|
|
28
|
+
const key = v.slice(0, eq).trim();
|
|
29
|
+
const val = v.slice(eq + 1).trim();
|
|
30
|
+
if (!key)
|
|
31
|
+
throw new Error(`--tag missing key (got '${v}')`);
|
|
32
|
+
if (!out[key])
|
|
33
|
+
out[key] = [];
|
|
34
|
+
for (const part of val
|
|
35
|
+
.split(',')
|
|
36
|
+
.map((s) => s.trim())
|
|
37
|
+
.filter(Boolean)) {
|
|
38
|
+
out[key].push(part);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
function parseRegexes(plain, weighted) {
|
|
44
|
+
const out = [];
|
|
45
|
+
for (const r of plain ?? [])
|
|
46
|
+
out.push({ regex: r, weight: 1 });
|
|
47
|
+
for (const r of weighted ?? []) {
|
|
48
|
+
const pipe = r.lastIndexOf('|');
|
|
49
|
+
if (pipe < 0)
|
|
50
|
+
throw new Error(`--weighted-regex must be 'PATTERN|weight' (got '${r}')`);
|
|
51
|
+
const pattern = r.slice(0, pipe);
|
|
52
|
+
const weight = Number(r.slice(pipe + 1));
|
|
53
|
+
if (!Number.isFinite(weight))
|
|
54
|
+
throw new Error(`--weighted-regex weight invalid in '${r}'`);
|
|
55
|
+
out.push({ regex: pattern, weight });
|
|
56
|
+
}
|
|
57
|
+
return out.length > 0 ? out : undefined;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Build a Data Pattern request body from CLI flags.
|
|
61
|
+
* `requireRequired` enforces name + type (use false for replace where caller already validated).
|
|
62
|
+
*/
|
|
63
|
+
export function buildPatternBody(opts, requireRequired = true) {
|
|
64
|
+
if (requireRequired) {
|
|
65
|
+
if (!opts.name)
|
|
66
|
+
throw new Error('--name is required');
|
|
67
|
+
}
|
|
68
|
+
const technique = opts.technique ?? 'regex';
|
|
69
|
+
const confidence = asCsv(opts.confidenceLevels);
|
|
70
|
+
const regexes = parseRegexes(opts.regex, opts.weightedRegex);
|
|
71
|
+
const tags = parseTags(opts.tag);
|
|
72
|
+
const detectionConfig = { technique };
|
|
73
|
+
if (confidence)
|
|
74
|
+
detectionConfig.supported_confidence_levels = confidence;
|
|
75
|
+
const matchingRules = {};
|
|
76
|
+
if (opts.delimiter != null)
|
|
77
|
+
matchingRules.delimiter = opts.delimiter;
|
|
78
|
+
if (opts.proximityDistance != null)
|
|
79
|
+
matchingRules.proximity_distance = asNum(opts.proximityDistance);
|
|
80
|
+
if (opts.proximityKeyword?.length)
|
|
81
|
+
matchingRules.proximity_keywords = opts.proximityKeyword;
|
|
82
|
+
if (regexes)
|
|
83
|
+
matchingRules.regexes = regexes;
|
|
84
|
+
const body = {
|
|
85
|
+
name: opts.name,
|
|
86
|
+
type: opts.type ?? 'custom',
|
|
87
|
+
detection_config: detectionConfig,
|
|
88
|
+
};
|
|
89
|
+
if (opts.description != null)
|
|
90
|
+
body.description = opts.description;
|
|
91
|
+
if (Object.keys(matchingRules).length > 0)
|
|
92
|
+
body.matching_rules = matchingRules;
|
|
93
|
+
if (tags)
|
|
94
|
+
body.tags = tags;
|
|
95
|
+
return body;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Build a Data Filtering Profile request body from CLI flags.
|
|
99
|
+
* Required: --file-based, --non-file-based (booleans).
|
|
100
|
+
*/
|
|
101
|
+
export function buildFilteringProfileBody(opts) {
|
|
102
|
+
if (opts.fileBased == null || opts.nonFileBased == null) {
|
|
103
|
+
throw new Error('--file-based and --non-file-based are both required');
|
|
104
|
+
}
|
|
105
|
+
const body = {
|
|
106
|
+
file_based: !!opts.fileBased,
|
|
107
|
+
non_file_based: !!opts.nonFileBased,
|
|
108
|
+
};
|
|
109
|
+
if (opts.description != null)
|
|
110
|
+
body.description = opts.description;
|
|
111
|
+
if (opts.direction != null)
|
|
112
|
+
body.direction = opts.direction;
|
|
113
|
+
if (opts.logSeverity != null)
|
|
114
|
+
body.log_severity = opts.logSeverity;
|
|
115
|
+
if (opts.scanType != null)
|
|
116
|
+
body.scan_type = opts.scanType;
|
|
117
|
+
if (opts.dataProfileId != null)
|
|
118
|
+
body.data_profile_id = asNum(opts.dataProfileId);
|
|
119
|
+
if (opts.eucTemplateId != null)
|
|
120
|
+
body.euc_template_id = opts.eucTemplateId;
|
|
121
|
+
if (opts.endUserCoaching != null)
|
|
122
|
+
body.is_end_user_coaching_enabled = !!opts.endUserCoaching;
|
|
123
|
+
if (opts.granular != null)
|
|
124
|
+
body.is_granular_profile = !!opts.granular;
|
|
125
|
+
if (opts.fileType?.length)
|
|
126
|
+
body.file_type = opts.fileType;
|
|
127
|
+
return body;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Build a Data Profile request body. Supports the simple case: a single
|
|
131
|
+
* expression_tree rule that ORs (or ANDs) named pattern IDs. Complex rule
|
|
132
|
+
* trees fall back to --body-file.
|
|
133
|
+
*/
|
|
134
|
+
export function buildProfileBody(opts) {
|
|
135
|
+
if (!opts.name)
|
|
136
|
+
throw new Error('--name is required');
|
|
137
|
+
const profileType = opts.profileType ?? 'advanced';
|
|
138
|
+
const body = {
|
|
139
|
+
name: opts.name,
|
|
140
|
+
profile_type: profileType,
|
|
141
|
+
};
|
|
142
|
+
if (opts.description != null)
|
|
143
|
+
body.description = opts.description;
|
|
144
|
+
if (opts.granular != null)
|
|
145
|
+
body.is_granular_data_profile = !!opts.granular;
|
|
146
|
+
if (opts.patternId?.length) {
|
|
147
|
+
const op = (opts.combinator ?? 'or').toLowerCase();
|
|
148
|
+
if (!['and', 'or', 'not', 'and_not', 'or_not'].includes(op)) {
|
|
149
|
+
throw new Error(`--combinator must be one of and|or|not|and_not|or_not (got '${op}')`);
|
|
150
|
+
}
|
|
151
|
+
body.detection_rules = [
|
|
152
|
+
{
|
|
153
|
+
rule_type: 'expression_tree',
|
|
154
|
+
expression_tree: {
|
|
155
|
+
operator_type: op,
|
|
156
|
+
condition_pattern: opts.patternId.map((id) => ({
|
|
157
|
+
data_pattern_id: id,
|
|
158
|
+
confidence_level: opts.confidence ?? 'high',
|
|
159
|
+
occurrence_operator_type: 'any',
|
|
160
|
+
occurrence_count: 1,
|
|
161
|
+
})),
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
];
|
|
165
|
+
}
|
|
166
|
+
return body;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Collect repeatable options. Use as the commander parser function.
|
|
170
|
+
*/
|
|
171
|
+
export function repeatable(value, prev = []) {
|
|
172
|
+
return [...prev, value];
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=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,CAAC,EAAE,CAAC,EAAE,CAAC;YAC5D,MAAM,IAAI,KAAK,CAAC,+DAA+D,EAAE,IAAI,CAAC,CAAC;QACzF,CAAC;QACD,IAAI,CAAC,eAAe,GAAG;YACrB;gBACE,SAAS,EAAE,iBAAiB;gBAC5B,eAAe,EAAE;oBACf,aAAa,EAAE,EAAE;oBACjB,iBAAiB,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,EAAU,EAAE,EAAE,CAAC,CAAC;wBACrD,eAAe,EAAE,EAAE;wBACnB,gBAAgB,EAAE,IAAI,CAAC,UAAU,IAAI,MAAM;wBAC3C,wBAAwB,EAAE,KAAK;wBAC/B,gBAAgB,EAAE,CAAC;qBACpB,CAAC,CAAC;iBACJ;aACF;SACF,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa,EAAE,OAAiB,EAAE;IAC3D,OAAO,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dictionaries.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/dlp/dictionaries.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAwBzC,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAsJ3C"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { basename } from 'node:path';
|
|
3
|
+
import { SdkDictionariesService } from '../../../airs/dlp/dictionaries.js';
|
|
4
|
+
import { dlpDictionaries, renderError } from '../../renderer/index.js';
|
|
5
|
+
import { buildMergePatch, parseBody } from './patch.js';
|
|
6
|
+
// biome-ignore lint/suspicious/noExplicitAny: opts object from commander
|
|
7
|
+
async function buildMetadata(opts) {
|
|
8
|
+
if (opts.metadataFile) {
|
|
9
|
+
return JSON.parse(await readFile(opts.metadataFile, 'utf-8'));
|
|
10
|
+
}
|
|
11
|
+
if (!opts.name || !opts.category || !opts.region || !opts.file) {
|
|
12
|
+
throw new Error('--name, --category, --region, and --file are required');
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
name: opts.name,
|
|
16
|
+
category: opts.category,
|
|
17
|
+
region_name: opts.region,
|
|
18
|
+
original_file_name: basename(opts.file),
|
|
19
|
+
description: opts.description,
|
|
20
|
+
classification: opts.classification,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export function register(dlp) {
|
|
24
|
+
const group = dlp.command('dictionaries').description('DLP dictionaries (multipart upload)');
|
|
25
|
+
group
|
|
26
|
+
.command('list')
|
|
27
|
+
.description('List dictionaries')
|
|
28
|
+
.option('--page <n>', '', (v) => Number.parseInt(v, 10))
|
|
29
|
+
.option('--size <n>', '', (v) => Number.parseInt(v, 10))
|
|
30
|
+
.option('--sort <field,dir>', '(repeatable)', (v, p = []) => [...p, v])
|
|
31
|
+
.option('--keywords', 'Include keyword list in response')
|
|
32
|
+
.option('--include-keywords', 'Alias for --keywords')
|
|
33
|
+
.option('--output <fmt>', 'Output format', 'pretty')
|
|
34
|
+
.action(async (opts) => {
|
|
35
|
+
try {
|
|
36
|
+
const includeKeywords = opts.keywords || opts.includeKeywords;
|
|
37
|
+
dlpDictionaries.renderList(await new SdkDictionariesService().list({
|
|
38
|
+
page: opts.page,
|
|
39
|
+
size: opts.size,
|
|
40
|
+
sort: opts.sort,
|
|
41
|
+
keywords: includeKeywords ? true : undefined,
|
|
42
|
+
}), opts.output);
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
renderError(err instanceof Error ? err.message : String(err));
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
group
|
|
50
|
+
.command('create')
|
|
51
|
+
.description('Create dictionary via multipart upload')
|
|
52
|
+
.option('--name <s>', '')
|
|
53
|
+
.option('--category <s>', '')
|
|
54
|
+
.option('--region <s>', '')
|
|
55
|
+
.option('--description <s>', '')
|
|
56
|
+
.option('--classification <s>', '')
|
|
57
|
+
.option('--file <path>', 'Keyword file')
|
|
58
|
+
.option('--metadata-file <path>', 'JSON metadata file (overrides --name/--category/...)')
|
|
59
|
+
.option('--include-keywords', 'Include keywords in response')
|
|
60
|
+
.option('--output <fmt>', 'Output format', 'pretty')
|
|
61
|
+
.action(async (opts) => {
|
|
62
|
+
try {
|
|
63
|
+
const metadata = await buildMetadata(opts);
|
|
64
|
+
if (!opts.file)
|
|
65
|
+
throw new Error('--file is required (multipart upload)');
|
|
66
|
+
const file = await readFile(opts.file);
|
|
67
|
+
const r = await new SdkDictionariesService().create({
|
|
68
|
+
metadata,
|
|
69
|
+
file,
|
|
70
|
+
includeKeywords: opts.includeKeywords,
|
|
71
|
+
});
|
|
72
|
+
dlpDictionaries.renderCreated(r, opts.output);
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
renderError(err instanceof Error ? err.message : String(err));
|
|
76
|
+
process.exit(2);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
group
|
|
80
|
+
.command('get <id>')
|
|
81
|
+
.option('--keywords', '')
|
|
82
|
+
.option('--include-keywords', 'Alias for --keywords')
|
|
83
|
+
.option('--output <fmt>', 'Output format', 'pretty')
|
|
84
|
+
.action(async (id, opts) => {
|
|
85
|
+
try {
|
|
86
|
+
const includeKeywords = opts.keywords || opts.includeKeywords;
|
|
87
|
+
dlpDictionaries.renderGet(await new SdkDictionariesService().get(id, { includeKeywords }), opts.output);
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
renderError(err instanceof Error ? err.message : String(err));
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
group
|
|
95
|
+
.command('replace <id>')
|
|
96
|
+
.description('Full-replace via multipart upload. --file required. May return 200 (body) ' +
|
|
97
|
+
'or 204 (re-get; falls back to "(state not echoed)" on transient failure).')
|
|
98
|
+
.option('--name <s>', '')
|
|
99
|
+
.option('--category <s>', '')
|
|
100
|
+
.option('--region <s>', '')
|
|
101
|
+
.option('--description <s>', '')
|
|
102
|
+
.option('--classification <s>', '')
|
|
103
|
+
.option('--file <path>', 'Keyword file (required)')
|
|
104
|
+
.option('--metadata-file <path>', 'JSON metadata file')
|
|
105
|
+
.option('--include-keywords', '')
|
|
106
|
+
.option('--output <fmt>', 'Output format', 'pretty')
|
|
107
|
+
.action(async (id, opts) => {
|
|
108
|
+
try {
|
|
109
|
+
const metadata = await buildMetadata(opts);
|
|
110
|
+
if (!opts.file)
|
|
111
|
+
throw new Error('--file is required (multipart upload)');
|
|
112
|
+
const file = await readFile(opts.file);
|
|
113
|
+
const r = await new SdkDictionariesService().replace(id, {
|
|
114
|
+
metadata,
|
|
115
|
+
file,
|
|
116
|
+
includeKeywords: opts.includeKeywords,
|
|
117
|
+
});
|
|
118
|
+
if ('kind' in r && r.kind === 'fallback') {
|
|
119
|
+
dlpDictionaries.renderReplaced204Fallback(id);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
dlpDictionaries.renderReplaced(r, opts.output);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
renderError(err instanceof Error ? err.message : String(err));
|
|
127
|
+
process.exit(2);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
group
|
|
131
|
+
.command('patch <id>')
|
|
132
|
+
.option('--body-file <path>', '')
|
|
133
|
+
.option('--set <k=v...>', '(repeatable)', (v, p = []) => [...p, v])
|
|
134
|
+
.option('--clear <key...>', '(repeatable)', (v, p = []) => [...p, v])
|
|
135
|
+
.option('--output <fmt>', 'Output format', 'pretty')
|
|
136
|
+
.action(async (id, opts) => {
|
|
137
|
+
try {
|
|
138
|
+
if (opts.bodyFile && (opts.set || opts.clear)) {
|
|
139
|
+
throw new Error('--body-file is mutually exclusive with --set/--clear');
|
|
140
|
+
}
|
|
141
|
+
const body = opts.bodyFile
|
|
142
|
+
? await parseBody({ bodyFile: opts.bodyFile })
|
|
143
|
+
: buildMergePatch({ set: opts.set, clear: opts.clear });
|
|
144
|
+
dlpDictionaries.renderPatched(
|
|
145
|
+
// biome-ignore lint/suspicious/noExplicitAny: buildMergePatch returns Record<string, unknown>, cast for patch()
|
|
146
|
+
await new SdkDictionariesService().patch(id, body), opts.output);
|
|
147
|
+
}
|
|
148
|
+
catch (err) {
|
|
149
|
+
renderError(err instanceof Error ? err.message : String(err));
|
|
150
|
+
process.exit(2);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
group
|
|
154
|
+
.command('delete <id>')
|
|
155
|
+
.description('Delete a dictionary')
|
|
156
|
+
.action(async (id) => {
|
|
157
|
+
try {
|
|
158
|
+
await new SdkDictionariesService().delete(id);
|
|
159
|
+
dlpDictionaries.renderDeleted(id);
|
|
160
|
+
}
|
|
161
|
+
catch (err) {
|
|
162
|
+
renderError(err instanceof Error ? err.message : String(err));
|
|
163
|
+
process.exit(1);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=dictionaries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dictionaries.js","sourceRoot":"","sources":["../../../../src/cli/commands/dlp/dictionaries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAE3E,OAAO,EAAE,eAAe,EAAqB,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC1F,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAExD,yEAAyE;AACzE,KAAK,UAAU,aAAa,CAAC,IAAS;IACpC,IAAI,IAAI,CAAC,YAAY,E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-profiles.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/dlp/filtering-profiles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAuBzC,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAgE3C"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { SdkDataFilteringProfilesService } from '../../../airs/dlp/data-filtering-profiles.js';
|
|
2
|
+
import { dlpFilteringProfiles, renderError } from '../../renderer/index.js';
|
|
3
|
+
import { buildFilteringProfileBody, repeatable } from './build-body.js';
|
|
4
|
+
import { parseBody } from './patch.js';
|
|
5
|
+
function listFlags(cmd) {
|
|
6
|
+
return cmd
|
|
7
|
+
.option('--page <n>', 'Zero-indexed page number', (v) => Number.parseInt(v, 10))
|
|
8
|
+
.option('--size <n>', 'Page size', (v) => Number.parseInt(v, 10))
|
|
9
|
+
.option('--sort <field,dir>', 'Sort criteria (repeatable)', repeatable)
|
|
10
|
+
.option('--output <fmt>', 'Output format', 'pretty');
|
|
11
|
+
}
|
|
12
|
+
async function resolveReplaceBody(opts) {
|
|
13
|
+
if (opts.body || opts.bodyFile) {
|
|
14
|
+
const body = await parseBody({ body: opts.body, bodyFile: opts.bodyFile });
|
|
15
|
+
if (!body)
|
|
16
|
+
throw new Error('--body or --body-file was empty');
|
|
17
|
+
return body;
|
|
18
|
+
}
|
|
19
|
+
return buildFilteringProfileBody(opts);
|
|
20
|
+
}
|
|
21
|
+
export function register(dlp) {
|
|
22
|
+
const group = dlp
|
|
23
|
+
.command('filtering-profiles')
|
|
24
|
+
.description('DLP data filtering profiles. Read + full-replace only. ' +
|
|
25
|
+
'Create, patch, and delete are not exposed by the DLP API.');
|
|
26
|
+
listFlags(group.command('list').description('List filtering profiles')).action(async (opts) => {
|
|
27
|
+
try {
|
|
28
|
+
const svc = new SdkDataFilteringProfilesService();
|
|
29
|
+
const r = await svc.list({ page: opts.page, size: opts.size, sort: opts.sort });
|
|
30
|
+
dlpFilteringProfiles.renderList(r, opts.output);
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
renderError(err instanceof Error ? err.message : String(err));
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
group
|
|
38
|
+
.command('get <id>')
|
|
39
|
+
.description('Get a filtering profile by id')
|
|
40
|
+
.option('--output <fmt>', 'Output format', 'pretty')
|
|
41
|
+
.action(async (id, opts) => {
|
|
42
|
+
try {
|
|
43
|
+
const svc = new SdkDataFilteringProfilesService();
|
|
44
|
+
dlpFilteringProfiles.renderGet(await svc.get(id), opts.output);
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
renderError(err instanceof Error ? err.message : String(err));
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
group
|
|
52
|
+
.command('replace <id>')
|
|
53
|
+
.description('Full-replace a filtering profile (PUT)')
|
|
54
|
+
.option('--file-based', 'Apply to file-based scans (boolean)')
|
|
55
|
+
.option('--non-file-based', 'Apply to non-file-based scans (boolean)')
|
|
56
|
+
.option('--description <s>', 'Description')
|
|
57
|
+
.option('--direction <s>', 'Direction: BOTH|UPLOAD|DOWNLOAD')
|
|
58
|
+
.option('--log-severity <s>', 'Severity: CRITICAL|HIGH|MEDIUM|LOW|INFORMATIONAL')
|
|
59
|
+
.option('--scan-type <s>', 'Scan type: include|exclude')
|
|
60
|
+
.option('--data-profile-id <n>', 'Data profile ID', (v) => Number(v))
|
|
61
|
+
.option('--euc-template-id <s>', 'EUC template ID')
|
|
62
|
+
.option('--end-user-coaching', 'Enable end-user coaching')
|
|
63
|
+
.option('--granular', 'Granular profile')
|
|
64
|
+
.option('--file-type <s>', 'File type (repeatable)', repeatable)
|
|
65
|
+
.option('--body <json|->', 'Raw JSON body (escape hatch; or "-" for stdin)')
|
|
66
|
+
.option('--body-file <path>', 'Raw JSON body file (escape hatch)')
|
|
67
|
+
.option('--output <fmt>', 'Output format', 'pretty')
|
|
68
|
+
.action(async (id, opts) => {
|
|
69
|
+
try {
|
|
70
|
+
const body = await resolveReplaceBody(opts);
|
|
71
|
+
const svc = new SdkDataFilteringProfilesService();
|
|
72
|
+
dlpFilteringProfiles.renderReplaced(
|
|
73
|
+
// biome-ignore lint/suspicious/noExplicitAny: body shape verified by SDK Zod
|
|
74
|
+
await svc.replace(id, body), opts.output);
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
renderError(err instanceof Error ? err.message : String(err));
|
|
78
|
+
process.exit(2);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=filtering-profiles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filtering-profiles.js","sourceRoot":"","sources":["../../../../src/cli/commands/dlp/filtering-profiles.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,+BAA+B,EAAE,MAAM,8CAA8C,CAAC;AAC/F,OAAO,EAAE,oBAAoB,EAAqB,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC/F,OAAO,EAAE,yBAAyB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,SAAS,SAAS,CAAoB,GAAM;IAC1C,OAAO,GAAG;SACP,MAAM,CAAC,YAAY,EAAE,0BAA0B,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;SAC/E,MAAM,CAAC,YAAY,EAAE,WAAW,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;SAChE,MAAM,CAAC,oBAAoB,EAAE,4BAA4B,EAAE,UAAU,CAAC;SACtE,MAAM,CAAC,gBAAgB,EAAE,eAAe,EAAE,QAAQ,CAAC,C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A0B,CAAC;SACzD,MAAM,CAAC,YAAY,EAAE,kBAAkB,CAAC;SACxC,MAAM,CAAC,iBAAiB,EAAE,wBAAwB,EAAE,UAAU,CAAC;SAC/D,MAAM,CAAC,iBAAiB,EAAE,gDAAgD,CAAC;SAC3E,MAAM,CAAC,oBAAoB,EAAE,mCAAmC,CAAC;SACjE,MAAM,CAAC,gBAAgB,EAAE,eAAe,EAAE,QAAQ,CAAC;SACnD,MAAM,CAAC,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE;QACzB,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,kBAAkB,CAAC,IAAI,CAAC,CAAC;YAC5C,MAAM,GAAG,GAAG,IAAI,+BAA+B,EAAE,CAAC;YAClD,oBAAoB,CAAC,cAAc;YACjC,6EAA6E;YAC7E,MAAM,GAAG,CAAC,OAAO,CAAC,EAAE,EAAE,IAAW,CAAC,EAClC,IAAI,CAAC,MAAsB,CAC5B,CAAC;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,WAAW,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;YAC9D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/dlp/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMzC,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAW1D"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { register as registerDictionaries } from './dictionaries.js';
|
|
2
|
+
import { register as registerFilteringProfiles } from './filtering-profiles.js';
|
|
3
|
+
import { register as registerPatterns } from './patterns.js';
|
|
4
|
+
import { register as registerProfiles } from './profiles.js';
|
|
5
|
+
export function registerDlpCommands(runtime) {
|
|
6
|
+
const dlp = runtime
|
|
7
|
+
.command('dlp')
|
|
8
|
+
.description('DLP management (filtering-profiles, patterns, profiles, dictionaries). ' +
|
|
9
|
+
'For the read-only DLP profile list used in Security Profiles, see `runtime dlp-profiles list`.');
|
|
10
|
+
registerFilteringProfiles(dlp);
|
|
11
|
+
registerPatterns(dlp);
|
|
12
|
+
registerProfiles(dlp);
|
|
13
|
+
registerDictionaries(dlp);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/cli/commands/dlp/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,IAAI,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE,QAAQ,IAAI,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,EAAE,QAAQ,IAAI,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,QAAQ,IAAI,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAE7D,MAAM,UAAU,mBAAmB,CAAC,OAAgB;IAClD,MAAM,GAAG,GAAG,OAAO;SAChB,OAAO,CAAC,KAAK,CAAC;SACd,WAAW,CACV,yEAAyE;QACvE,gGAAgG,CACnG,CAAC;IACJ,yBAAyB,CAAC,GAAG,CAAC,CAAC;IAC/B,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACtB,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACtB,oBAAoB,CAAC,GAAG,CAAC,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Readable } from 'node:stream';
|
|
2
|
+
export interface BuildMergePatchOpts {
|
|
3
|
+
set?: string[];
|
|
4
|
+
clear?: string[];
|
|
5
|
+
}
|
|
6
|
+
/** Build a JSON Merge Patch object from --set/--clear CLI flags. Pure. */
|
|
7
|
+
export declare function buildMergePatch(opts: BuildMergePatchOpts): Record<string, unknown>;
|
|
8
|
+
export interface ParseBodyOpts {
|
|
9
|
+
body?: string;
|
|
10
|
+
bodyFile?: string;
|
|
11
|
+
stdin?: Readable;
|
|
12
|
+
}
|
|
13
|
+
/** Read --body or --body-file and JSON.parse. Returns undefined if neither supplied. */
|
|
14
|
+
export declare function parseBody(opts: ParseBodyOpts): Promise<unknown | undefined>;
|
|
15
|
+
//# sourceMappingURL=patch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patch.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/dlp/patch.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,WAAW,mBAAmB;IAClC,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,0EAA0E;AAC1E,wBAAgB,eAAe,CAAC,IAAI,EAAE,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAyBlF;AAkBD,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,QAAQ,CAAC;CAClB;AAED,wFAAwF;AACxF,wBAAsB,SAAS,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAmBjF"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
/** Build a JSON Merge Patch object from --set/--clear CLI flags. Pure. */
|
|
3
|
+
export function buildMergePatch(opts) {
|
|
4
|
+
const out = {};
|
|
5
|
+
for (const entry of opts.set ?? []) {
|
|
6
|
+
const eq = entry.indexOf('=');
|
|
7
|
+
if (eq < 1)
|
|
8
|
+
throw new Error(`--set expected key=value, got: ${entry}`);
|
|
9
|
+
const key = entry.slice(0, eq);
|
|
10
|
+
const raw = entry.slice(eq + 1);
|
|
11
|
+
if (key.includes('.')) {
|
|
12
|
+
throw new Error(`--set ${key}: use --body-file for nested fields`);
|
|
13
|
+
}
|
|
14
|
+
if (raw === 'null') {
|
|
15
|
+
throw new Error(`--set ${key}=null: to clear a field, use --clear ${key}`);
|
|
16
|
+
}
|
|
17
|
+
out[key] = coerceValue(raw);
|
|
18
|
+
}
|
|
19
|
+
for (const key of opts.clear ?? []) {
|
|
20
|
+
if (key.includes('.')) {
|
|
21
|
+
throw new Error(`--clear ${key}: use --body-file for nested fields`);
|
|
22
|
+
}
|
|
23
|
+
out[key] = null;
|
|
24
|
+
}
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
function coerceValue(raw) {
|
|
28
|
+
if (raw === 'true')
|
|
29
|
+
return true;
|
|
30
|
+
if (raw === 'false')
|
|
31
|
+
return false;
|
|
32
|
+
if (raw !== '' && !Number.isNaN(Number(raw)) && /^-?\d+(\.\d+)?$/.test(raw)) {
|
|
33
|
+
return Number(raw);
|
|
34
|
+
}
|
|
35
|
+
if (raw.startsWith('{') || raw.startsWith('[') || raw.startsWith('"')) {
|
|
36
|
+
try {
|
|
37
|
+
return JSON.parse(raw);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return raw;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return raw;
|
|
44
|
+
}
|
|
45
|
+
/** Read --body or --body-file and JSON.parse. Returns undefined if neither supplied. */
|
|
46
|
+
export async function parseBody(opts) {
|
|
47
|
+
let raw;
|
|
48
|
+
if (opts.bodyFile) {
|
|
49
|
+
raw = await readFile(opts.bodyFile, 'utf-8');
|
|
50
|
+
}
|
|
51
|
+
else if (opts.body === '-') {
|
|
52
|
+
const chunks = [];
|
|
53
|
+
for await (const chunk of opts.stdin ?? process.stdin) {
|
|
54
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
55
|
+
}
|
|
56
|
+
raw = Buffer.concat(chunks).toString('utf-8');
|
|
57
|
+
}
|
|
58
|
+
else if (opts.body !== undefined) {
|
|
59
|
+
raw = opts.body;
|
|
60
|
+
}
|
|
61
|
+
if (raw === undefined)
|
|
62
|
+
return undefined;
|
|
63
|
+
try {
|
|
64
|
+
return JSON.parse(raw);
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
throw new Error(`invalid JSON in body: ${e.message}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=patch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patch.js","sourceRoot":"","sources":["../../../../src/cli/commands/dlp/patch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAQ5C,0EAA0E;AAC1E,MAAM,UAAU,eAAe,CAAC,IAAyB;IACvD,MAAM,GAAG,GAA4B,EAAE,CAAC;IAExC,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC;QACnC,MAAM,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC9B,IAAI,EAAE,GAAG,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,kCAAkC,KAAK,EAAE,CAAC,CAAC;QACvE,MAAM,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC/B,MAAM,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;QAChC,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,SAAS,GAAG,qCAAqC,CAAC,CAAC;QACrE,CAAC;QACD,IAAI,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