-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdelete.ts
More file actions
107 lines (90 loc) · 3.17 KB
/
delete.ts
File metadata and controls
107 lines (90 loc) · 3.17 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* 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} 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 {
success: boolean;
certificateId: string;
}
/**
* Command to delete a certificate for a zone.
* WARNING: Deleting a certificate in use can cause site downtime.
*/
export default class EcdnCertificatesDelete extends EcdnZoneCommand<typeof EcdnCertificatesDelete> {
static description = withDocs(
t(
'commands.ecdn.certificates.delete.description',
'Delete a certificate from a zone (WARNING: can cause downtime if in use)',
),
'/cli/ecdn.html#b2c-ecdn-certificates-delete',
);
static enableJsonFlag = true;
static examples = [
'<%= config.bin %> <%= command.id %> --tenant-id zzxy_prd --zone my-zone --certificate-id abc123',
'<%= config.bin %> <%= command.id %> --tenant-id zzxy_prd --zone my-zone --certificate-id abc123 --force',
];
static flags = {
...EcdnZoneCommand.baseFlags,
'certificate-id': Flags.string({
description: t('flags.certificateId.description', 'Certificate ID to delete'),
required: true,
}),
force: Flags.boolean({
char: 'f',
description: t('flags.force.description', 'Skip confirmation prompt'),
default: false,
}),
};
async run(): Promise<DeleteOutput> {
// Prevent deletion in safe mode
this.assertDestructiveOperationAllowed('delete certificate');
this.requireOAuthCredentials();
const zoneId = await this.resolveZoneId();
const certificateId = this.flags['certificate-id'];
const force = this.flags.force;
if (!force && !this.jsonEnabled()) {
this.warn(
t(
'commands.ecdn.certificates.delete.warning',
'WARNING: Deleting a certificate that is in use can result in downtime!',
),
);
this.log(t('commands.ecdn.certificates.delete.useForce', 'Use --force to confirm deletion.'));
return {success: false, certificateId};
}
if (!this.jsonEnabled()) {
this.log(t('commands.ecdn.certificates.delete.deleting', 'Deleting certificate {{id}}...', {id: certificateId}));
}
const client = this.getCdnZonesRwClient();
const organizationId = this.getOrganizationId();
const {error} = await client.DELETE('/organizations/{organizationId}/zones/{zoneId}/certificates/{certificateId}', {
params: {
path: {organizationId, zoneId, certificateId},
},
});
if (error) {
this.error(
t('commands.ecdn.certificates.delete.error', 'Failed to delete certificate: {{message}}', {
message: formatApiError(error),
}),
);
}
const output: DeleteOutput = {
success: true,
certificateId,
};
if (this.jsonEnabled()) {
return output;
}
this.log('');
this.log(t('commands.ecdn.certificates.delete.success', 'Certificate deleted successfully.'));
return output;
}
}