Skip to content

Commit 23aec8d

Browse files
authored
Merge pull request #8723 from achouhan09/account-res-fix
NC | CLI | Updated the CLI response to have more info when account/bucket has been deleted
2 parents ad6b361 + 8645ca2 commit 23aec8d

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

src/cmd/manage_nsfs.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ async function delete_bucket(data, force) {
259259
}
260260
await native_fs_utils.folder_delete(bucket_temp_dir_path, fs_context_fs_backend, true);
261261
await config_fs.delete_bucket_config_file(data.name);
262-
return { code: ManageCLIResponse.BucketDeleted, detail: '', event_arg: { bucket: data.name } };
262+
return { code: ManageCLIResponse.BucketDeleted, detail: { name: data.name }, event_arg: { bucket: data.name } };
263263
} catch (err) {
264264
if (err.code === 'ENOENT') throw_cli_error(ManageCLIError.NoSuchBucket, data.name);
265265
throw err;
@@ -528,7 +528,7 @@ async function update_account(data) {
528528
*/
529529
async function delete_account(data) {
530530
await config_fs.delete_account_config_file(data);
531-
return { code: ManageCLIResponse.AccountDeleted, detail: '', event_arg: { account: data.name } };
531+
return { code: ManageCLIResponse.AccountDeleted, detail: { name: data.name }, event_arg: { account: data.name } };
532532
}
533533

534534
/**
@@ -791,12 +791,12 @@ async function connection_management(action, user_input) {
791791
break;
792792
case ACTIONS.DELETE:
793793
await config_fs.delete_connection_config_file(user_input.name);
794-
response = { code: ManageCLIResponse.ConnectionDeleted };
794+
response = { code: ManageCLIResponse.ConnectionDeleted, detail: {name: user_input.name} };
795795
break;
796796
case ACTIONS.UPDATE:
797797
await notifications_util.update_connect_file(user_input.name, user_input.key,
798798
user_input.value, user_input.remove_key, config_fs);
799-
response = { code: ManageCLIResponse.ConnectionUpdated };
799+
response = { code: ManageCLIResponse.ConnectionUpdated, detail: {name: user_input.name} };
800800
break;
801801
case ACTIONS.STATUS:
802802
data = await new notifications_util.Notificator({

src/manage_nsfs/manage_nsfs_cli_responses.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ const NoobaaEvent = require('../manage_nsfs/manage_nsfs_events_utils').NoobaaEve
77
/**
88
* @typedef {{
99
* code?: string,
10+
* message?: string,
1011
* http_code: number,
1112
* list?: object,
12-
* status?: object,
13+
* status?: object
1314
* }} ManageCLIResponseSpec
1415
*/
1516

@@ -18,17 +19,19 @@ class ManageCLIResponse {
1819
/**
1920
* @param {ManageCLIResponseSpec} response_spec
2021
*/
21-
constructor({ code, status, list }) {
22+
constructor({ code, status, list, message }) {
2223
this.code = code;
2324
this.http_code = 200;
2425
this.status = status;
2526
this.list = list;
27+
this.message = message;
2628
}
2729

2830
to_string(detail) {
2931
const json = {
3032
response: {
3133
code: this.code,
34+
message: detail?.name ? `${this.message}: ${detail.name}` : this.message,
3235
}
3336
};
3437
if (this.list || this.status) json.response.reply = typeof detail === 'string' ? JSON.parse(detail) : detail;
@@ -44,11 +47,13 @@ class ManageCLIResponse {
4447

4548
ManageCLIResponse.HealthStatus = Object.freeze({
4649
code: 'HealthStatus',
50+
message: 'Health status retrieved successfully',
4751
status: {}
4852
});
4953

5054
ManageCLIResponse.MetricsStatus = Object.freeze({
5155
code: 'MetricsStatus',
56+
message: 'Metrics status retrieved successfully',
5257
status: {}
5358
});
5459

@@ -57,6 +62,7 @@ ManageCLIResponse.MetricsStatus = Object.freeze({
5762
///////////////////////////////
5863
ManageCLIResponse.WhiteListIPUpdated = Object.freeze({
5964
code: 'WhiteListIPUpdated',
65+
message: 'WhiteListIP has been updated successfully',
6066
status: {}
6167
});
6268

@@ -66,25 +72,30 @@ ManageCLIResponse.WhiteListIPUpdated = Object.freeze({
6672

6773
ManageCLIResponse.AccountCreated = Object.freeze({
6874
code: 'AccountCreated',
75+
message: 'Account has been created successfully',
6976
status: {}
7077
});
7178

7279
ManageCLIResponse.AccountDeleted = Object.freeze({
7380
code: 'AccountDeleted',
81+
message: 'Account has been deleted successfully'
7482
});
7583

7684
ManageCLIResponse.AccountUpdated = Object.freeze({
7785
code: 'AccountUpdated',
86+
message: 'Account has been updated successfully',
7887
status: {}
7988
});
8089

8190
ManageCLIResponse.AccountStatus = Object.freeze({
8291
code: 'AccountStatus',
92+
message: 'Account status retrieved successfully',
8393
status: {}
8494
});
8595

8696
ManageCLIResponse.AccountList = Object.freeze({
8797
code: 'AccountList',
98+
message: 'Account list retrieved successfully',
8899
list: {}
89100
});
90101

@@ -94,25 +105,30 @@ ManageCLIResponse.AccountList = Object.freeze({
94105

95106
ManageCLIResponse.BucketCreated = Object.freeze({
96107
code: 'BucketCreated',
108+
message: 'Bucket has been created successfully',
97109
status: {}
98110
});
99111

100112
ManageCLIResponse.BucketDeleted = Object.freeze({
101113
code: 'BucketDeleted',
114+
message: 'Bucket has been deleted successfully'
102115
});
103116

104117
ManageCLIResponse.BucketUpdated = Object.freeze({
105118
code: 'BucketUpdated',
119+
message: 'Bucket has been updated successfully',
106120
status: {}
107121
});
108122

109123
ManageCLIResponse.BucketStatus = Object.freeze({
110124
code: 'BucketStatus',
125+
message: 'Bucket status retrieved successfully',
111126
status: {}
112127
});
113128

114129
ManageCLIResponse.BucketList = Object.freeze({
115130
code: 'BucketList',
131+
message: 'Bucket list retrieved successfully',
116132
list: {}
117133
});
118134

@@ -122,6 +138,7 @@ ManageCLIResponse.BucketList = Object.freeze({
122138

123139
ManageCLIResponse.LoggingExported = Object.freeze({
124140
code: 'LoggingExported',
141+
message: 'Logging data exported successfully',
125142
status: {}
126143
});
127144

@@ -131,16 +148,19 @@ ManageCLIResponse.LoggingExported = Object.freeze({
131148

132149
ManageCLIResponse.UpgradeSuccessful = Object.freeze({
133150
code: 'UpgradeSuccessful',
151+
message: 'Config directory upgrade completed successfully',
134152
status: {}
135153
});
136154

137155
ManageCLIResponse.UpgradeStatus = Object.freeze({
138156
code: 'UpgradeStatus',
157+
message: 'Config directory upgrade status retrieved successfully',
139158
status: {}
140159
});
141160

142161
ManageCLIResponse.UpgradeHistory = Object.freeze({
143162
code: 'UpgradeHistory',
163+
message: 'Config directory upgrade history retrieved successfully',
144164
status: {}
145165
});
146166

@@ -150,25 +170,30 @@ ManageCLIResponse.UpgradeHistory = Object.freeze({
150170

151171
ManageCLIResponse.ConnectionCreated = Object.freeze({
152172
code: 'ConnectionCreated',
173+
message: 'Notification connection has been created successfully',
153174
status: {}
154175
});
155176

156177
ManageCLIResponse.ConnectionDeleted = Object.freeze({
157178
code: 'ConnectionDeleted',
179+
message: 'Notification connection has been deleted successfully'
158180
});
159181

160182
ManageCLIResponse.ConnectionUpdated = Object.freeze({
161183
code: 'ConnectionUpdated',
184+
message: 'Notification connection has been updated successfully',
162185
status: {}
163186
});
164187

165188
ManageCLIResponse.ConnectionStatus = Object.freeze({
166189
code: 'ConnectionStatus',
190+
message: 'Notification connection status retrieved successfully',
167191
status: {}
168192
});
169193

170194
ManageCLIResponse.ConnectionList = Object.freeze({
171195
code: 'ConnectionList',
196+
message: 'Notification connection list retrieved successfully',
172197
list: {}
173198
});
174199

src/test/unit_tests/jest_tests/test_nc_account_cli.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,6 +1518,8 @@ describe('manage nsfs cli account flow', () => {
15181518
const res = await exec_manage_cli(type, action, account_options);
15191519
const res_json = JSON.parse(res.trim());
15201520
expect(res_json.response.code).toBe(ManageCLIResponse.AccountDeleted.code);
1521+
const message = `Account has been deleted successfully: ${name}`;
1522+
expect(res_json.response.message).toBe(message);
15211523
const account_by_name_exists = await config_fs.is_account_exists_by_name(name);
15221524
expect(account_by_name_exists).toBe(false);
15231525
const account_by_access_key_exists = await config_fs.is_account_exists_by_access_key(defaults.access_key);

src/test/unit_tests/jest_tests/test_nc_nsfs_bucket_cli.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,8 @@ describe('manage nsfs cli bucket flow', () => {
731731
const delete_bucket_options = { config_root, name: bucket_defaults.name, force: true};
732732
const resp = await exec_manage_cli(TYPES.BUCKET, ACTIONS.DELETE, delete_bucket_options);
733733
expect(JSON.parse(resp.trim()).response.code).toBe(ManageCLIResponse.BucketDeleted.code);
734+
const message = `Bucket has been deleted successfully: ${bucket_defaults.name}`;
735+
expect(JSON.parse(resp.trim()).response.message).toBe(message);
734736
const is_bucket_exists = await config_fs.is_bucket_exists(bucket_defaults.name);
735737
expect(is_bucket_exists).toBe(false);
736738
});

0 commit comments

Comments
 (0)