-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdelete.ts
More file actions
81 lines (65 loc) · 2.34 KB
/
delete.ts
File metadata and controls
81 lines (65 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* Copyright (c) 2025, Salesforce, Inc.
* SPDX-License-Identifier: Apache-2
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
*/
import {Flags, ux} from '@oclif/core';
import {EcdnZoneCommand, formatApiError} from '../../../utils/ecdn/index.js';
import {t, withDocs} from '../../../i18n/index.js';
/**
* Response type for the delete command.
*/
interface DeleteOutput {
deleted: boolean;
rulesetId: string;
}
/**
* Command to delete an MRT ruleset for a zone.
*/
export default class EcdnMrtRulesDelete extends EcdnZoneCommand<typeof EcdnMrtRulesDelete> {
static description = withDocs(
t('commands.ecdn.mrt-rules.delete.description', 'Delete an MRT ruleset and all rules within it'),
'/cli/ecdn.html#b2c-ecdn-mrt-rules-delete',
);
static enableJsonFlag = true;
static examples = [
'<%= config.bin %> <%= command.id %> --tenant-id zzxy_prd --zone my-zone --ruleset-id 12345678901234asdfasfasdf',
];
static flags = {
...EcdnZoneCommand.baseFlags,
'ruleset-id': Flags.string({
description: t('flags.rulesetId.description', 'MRT ruleset ID to delete'),
required: true,
}),
};
async run(): Promise<DeleteOutput> {
// Prevent deletion in safe mode
this.assertDestructiveOperationAllowed('delete MRT ruleset');
this.requireOAuthCredentials();
const zoneId = await this.resolveZoneId();
const rulesetId = this.flags['ruleset-id'];
if (!this.jsonEnabled()) {
this.log(t('commands.ecdn.mrt-rules.delete.deleting', 'Deleting MRT ruleset {{id}}...', {id: rulesetId}));
}
const client = this.getCdnZonesRwClient();
const organizationId = this.getOrganizationId();
const {error} = await client.DELETE('/organizations/{organizationId}/zones/{zoneId}/mrtrules/{rulesetId}', {
params: {
path: {organizationId, zoneId, rulesetId},
},
});
if (error) {
this.error(
t('commands.ecdn.mrt-rules.delete.error', 'Failed to delete MRT ruleset: {{message}}', {
message: formatApiError(error),
}),
);
}
const output: DeleteOutput = {deleted: true, rulesetId};
if (this.jsonEnabled()) {
return output;
}
ux.stdout(t('commands.ecdn.mrt-rules.delete.success', 'MRT ruleset {{id}} deleted successfully.', {id: rulesetId}));
return output;
}
}