-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathsettings.ts
More file actions
99 lines (82 loc) · 3.05 KB
/
settings.ts
File metadata and controls
99 lines (82 loc) · 3.05 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
/*
* 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 {Args} from '@oclif/core';
import {OdsCommand} from '@salesforce/b2c-tooling-sdk/cli';
import {getApiErrorMessage, type OdsComponents} from '@salesforce/b2c-tooling-sdk';
import {t, withDocs} from '../../i18n/index.js';
type SandboxSettings = OdsComponents['schemas']['SandboxSettings'];
type SandboxSettingsResponse = OdsComponents['schemas']['SandboxSettingsResponse'];
/**
* Show sandbox settings.
*/
export default class SandboxSettingsCommand extends OdsCommand<typeof SandboxSettingsCommand> {
static aliases = ['ods:settings'];
static args = {
sandboxId: Args.string({
description: 'Sandbox ID (UUID or realm-instance, e.g., zzzz-001)',
required: true,
}),
};
static description = withDocs(
t('commands.sandbox.settings.description', 'Show settings for a specific sandbox'),
'/cli/sandbox.html#b2c-sandbox-settings',
);
static enableJsonFlag = true;
static examples = [
'<%= config.bin %> <%= command.id %> zzzz-001',
'<%= config.bin %> <%= command.id %> zzzz-001 --json',
];
async run(): Promise<SandboxSettings | SandboxSettingsResponse | undefined> {
const {args} = await this.parse(SandboxSettingsCommand);
const sandboxId = await this.resolveSandboxId(args.sandboxId);
const result = await this.odsClient.GET('/sandboxes/{sandboxId}/settings', {
params: {
path: {sandboxId},
},
});
if (result.error) {
this.error(
t('commands.sandbox.settings.error', 'Failed to fetch sandbox settings: {{message}}', {
message: getApiErrorMessage(result.error, result.response),
}),
);
}
const data = (result.data as SandboxSettingsResponse | undefined)?.data;
if (!data) {
this.log(t('commands.sandbox.settings.noData', 'No settings were returned for this sandbox.'));
return undefined;
}
if (this.jsonEnabled()) {
return result.data as SandboxSettingsResponse;
}
this.printSettings(data);
return data;
}
private printSettings(settings: SandboxSettings): void {
const ocapi = settings.ocapi ?? [];
const webdav = settings.webdav ?? [];
this.log('Sandbox Settings');
this.log('────────────────');
this.log(`OCAPI client entries: ${ocapi.length}`);
this.log(`WebDAV client entries: ${webdav.length}`);
if (ocapi.length > 0) {
this.log('');
this.log('OCAPI');
for (const entry of ocapi) {
const resources = entry.resources?.length ?? 0;
this.log(` - ${entry.client_id ?? 'unknown-client'} (${resources} resource rules)`);
}
}
if (webdav.length > 0) {
this.log('');
this.log('WebDAV');
for (const entry of webdav) {
const permissions = entry.permissions?.length ?? 0;
this.log(` - ${entry.client_id ?? 'unknown-client'} (${permissions} permission rules)`);
}
}
}
}