-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdelete.ts
More file actions
87 lines (71 loc) · 2.39 KB
/
delete.ts
File metadata and controls
87 lines (71 loc) · 2.39 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
82
83
84
85
86
87
/*
* 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 {EcdnCommand, formatApiError} from '../../../utils/ecdn/index.js';
import {t, withDocs} from '../../../i18n/index.js';
/**
* Response type for the delete command.
*/
interface DeleteOutput {
deleted: boolean;
certificateId: string;
}
/**
* Command to delete an mTLS certificate.
*/
export default class EcdnMtlsDelete extends EcdnCommand<typeof EcdnMtlsDelete> {
static description = withDocs(
t('commands.ecdn.mtls.delete.description', 'Delete an mTLS certificate'),
'/cli/ecdn.html#b2c-ecdn-mtls-delete',
);
static enableJsonFlag = true;
static examples = [
'<%= config.bin %> <%= command.id %> --tenant-id zzxy_prd --certificate-id 465a48f6-3d98-4c15-9312-211984ee8629',
];
static flags = {
...EcdnCommand.baseFlags,
'certificate-id': Flags.string({
description: t('flags.certificateId.description', 'mTLS certificate ID to delete'),
required: true,
}),
};
async run(): Promise<DeleteOutput> {
// Prevent deletion in safe mode
this.assertDestructiveOperationAllowed('delete mTLS certificate');
this.requireOAuthCredentials();
const mtlsCertificateId = this.flags['certificate-id'];
if (!this.jsonEnabled()) {
this.log(t('commands.ecdn.mtls.delete.deleting', 'Deleting mTLS certificate {{id}}...', {id: mtlsCertificateId}));
}
const client = this.getCdnZonesRwClient();
const organizationId = this.getOrganizationId();
const {error} = await client.DELETE(
'/organizations/{organizationId}/mtls/code-upload-certificates/{mtlsCertificateId}',
{
params: {
path: {organizationId, mtlsCertificateId},
},
},
);
if (error) {
this.error(
t('commands.ecdn.mtls.delete.error', 'Failed to delete mTLS certificate: {{message}}', {
message: formatApiError(error),
}),
);
}
const output: DeleteOutput = {deleted: true, certificateId: mtlsCertificateId};
if (this.jsonEnabled()) {
return output;
}
ux.stdout(
t('commands.ecdn.mtls.delete.success', 'mTLS certificate {{id}} deleted successfully.', {
id: mtlsCertificateId,
}),
);
return output;
}
}