Skip to content

Commit 9382a30

Browse files
achouhan09romayalon
authored andcommitted
Updated the CLI response to have more info when account/bucket has been deleted and also for other operations
Signed-off-by: Aayush Chouhan <achouhan@redhat.com> (cherry picked from commit 8645ca2)
1 parent 11145f5 commit 9382a30

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
@@ -266,7 +266,7 @@ async function delete_bucket(data, force) {
266266
}
267267
await native_fs_utils.folder_delete(bucket_temp_dir_path, fs_context_fs_backend, true);
268268
await config_fs.delete_bucket_config_file(data.name);
269-
return { code: ManageCLIResponse.BucketDeleted, detail: '', event_arg: { bucket: data.name } };
269+
return { code: ManageCLIResponse.BucketDeleted, detail: { name: data.name }, event_arg: { bucket: data.name } };
270270
} catch (err) {
271271
if (err.code === 'ENOENT') throw_cli_error(ManageCLIError.NoSuchBucket, data.name);
272272
throw err;
@@ -475,7 +475,7 @@ async function update_account(data) {
475475
*/
476476
async function delete_account(data) {
477477
await config_fs.delete_account_config_file(data);
478-
return { code: ManageCLIResponse.AccountDeleted, detail: '', event_arg: { account: data.name } };
478+
return { code: ManageCLIResponse.AccountDeleted, detail: { name: data.name }, event_arg: { account: data.name } };
479479
}
480480

481481
/**
@@ -768,12 +768,12 @@ async function connection_management(action, user_input) {
768768
break;
769769
case ACTIONS.DELETE:
770770
await config_fs.delete_connection_config_file(user_input.name);
771-
response = { code: ManageCLIResponse.ConnectionDeleted };
771+
response = { code: ManageCLIResponse.ConnectionDeleted, detail: {name: user_input.name} };
772772
break;
773773
case ACTIONS.UPDATE:
774774
await notifications_util.update_connect_file(user_input.name, user_input.key,
775775
user_input.value, user_input.remove_key, config_fs);
776-
response = { code: ManageCLIResponse.ConnectionUpdated };
776+
response = { code: ManageCLIResponse.ConnectionUpdated, detail: {name: user_input.name} };
777777
break;
778778
case ACTIONS.STATUS:
779779
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
@@ -9,9 +9,10 @@ const NoobaaEvent = require('../manage_nsfs/manage_nsfs_events_utils').NoobaaEve
99
/**
1010
* @typedef {{
1111
* code?: string,
12+
* message?: string,
1213
* http_code: number,
1314
* list?: object,
14-
* status?: object,
15+
* status?: object
1516
* }} ManageCLIResponseSpec
1617
*/
1718

@@ -20,17 +21,19 @@ class ManageCLIResponse {
2021
/**
2122
* @param {ManageCLIResponseSpec} response_spec
2223
*/
23-
constructor({ code, status, list }) {
24+
constructor({ code, status, list, message }) {
2425
this.code = code;
2526
this.http_code = 200;
2627
this.status = status;
2728
this.list = list;
29+
this.message = message;
2830
}
2931

3032
to_string(detail) {
3133
const json = {
3234
response: {
3335
code: this.code,
36+
message: detail?.name ? `${this.message}: ${detail.name}` : this.message,
3437
}
3538
};
3639
if (this.list || this.status) json.response.reply = typeof detail === 'string' ? JSON.parse(detail) : detail;
@@ -46,11 +49,13 @@ class ManageCLIResponse {
4649

4750
ManageCLIResponse.HealthStatus = Object.freeze({
4851
code: 'HealthStatus',
52+
message: 'Health status retrieved successfully',
4953
status: {}
5054
});
5155

5256
ManageCLIResponse.MetricsStatus = Object.freeze({
5357
code: 'MetricsStatus',
58+
message: 'Metrics status retrieved successfully',
5459
status: {}
5560
});
5661

@@ -59,6 +64,7 @@ ManageCLIResponse.MetricsStatus = Object.freeze({
5964
///////////////////////////////
6065
ManageCLIResponse.WhiteListIPUpdated = Object.freeze({
6166
code: 'WhiteListIPUpdated',
67+
message: 'WhiteListIP has been updated successfully',
6268
status: {}
6369
});
6470

@@ -68,25 +74,30 @@ ManageCLIResponse.WhiteListIPUpdated = Object.freeze({
6874

6975
ManageCLIResponse.AccountCreated = Object.freeze({
7076
code: 'AccountCreated',
77+
message: 'Account has been created successfully',
7178
status: {}
7279
});
7380

7481
ManageCLIResponse.AccountDeleted = Object.freeze({
7582
code: 'AccountDeleted',
83+
message: 'Account has been deleted successfully'
7684
});
7785

7886
ManageCLIResponse.AccountUpdated = Object.freeze({
7987
code: 'AccountUpdated',
88+
message: 'Account has been updated successfully',
8089
status: {}
8190
});
8291

8392
ManageCLIResponse.AccountStatus = Object.freeze({
8493
code: 'AccountStatus',
94+
message: 'Account status retrieved successfully',
8595
status: {}
8696
});
8797

8898
ManageCLIResponse.AccountList = Object.freeze({
8999
code: 'AccountList',
100+
message: 'Account list retrieved successfully',
90101
list: {}
91102
});
92103

@@ -96,25 +107,30 @@ ManageCLIResponse.AccountList = Object.freeze({
96107

97108
ManageCLIResponse.BucketCreated = Object.freeze({
98109
code: 'BucketCreated',
110+
message: 'Bucket has been created successfully',
99111
status: {}
100112
});
101113

102114
ManageCLIResponse.BucketDeleted = Object.freeze({
103115
code: 'BucketDeleted',
116+
message: 'Bucket has been deleted successfully'
104117
});
105118

106119
ManageCLIResponse.BucketUpdated = Object.freeze({
107120
code: 'BucketUpdated',
121+
message: 'Bucket has been updated successfully',
108122
status: {}
109123
});
110124

111125
ManageCLIResponse.BucketStatus = Object.freeze({
112126
code: 'BucketStatus',
127+
message: 'Bucket status retrieved successfully',
113128
status: {}
114129
});
115130

116131
ManageCLIResponse.BucketList = Object.freeze({
117132
code: 'BucketList',
133+
message: 'Bucket list retrieved successfully',
118134
list: {}
119135
});
120136

@@ -124,6 +140,7 @@ ManageCLIResponse.BucketList = Object.freeze({
124140

125141
ManageCLIResponse.LoggingExported = Object.freeze({
126142
code: 'LoggingExported',
143+
message: 'Logging data exported successfully',
127144
status: {}
128145
});
129146

@@ -133,16 +150,19 @@ ManageCLIResponse.LoggingExported = Object.freeze({
133150

134151
ManageCLIResponse.UpgradeSuccessful = Object.freeze({
135152
code: 'UpgradeSuccessful',
153+
message: 'Config directory upgrade completed successfully',
136154
status: {}
137155
});
138156

139157
ManageCLIResponse.UpgradeStatus = Object.freeze({
140158
code: 'UpgradeStatus',
159+
message: 'Config directory upgrade status retrieved successfully',
141160
status: {}
142161
});
143162

144163
ManageCLIResponse.UpgradeHistory = Object.freeze({
145164
code: 'UpgradeHistory',
165+
message: 'Config directory upgrade history retrieved successfully',
146166
status: {}
147167
});
148168

@@ -152,25 +172,30 @@ ManageCLIResponse.UpgradeHistory = Object.freeze({
152172

153173
ManageCLIResponse.ConnectionCreated = Object.freeze({
154174
code: 'ConnectionCreated',
175+
message: 'Notification connection has been created successfully',
155176
status: {}
156177
});
157178

158179
ManageCLIResponse.ConnectionDeleted = Object.freeze({
159180
code: 'ConnectionDeleted',
181+
message: 'Notification connection has been deleted successfully'
160182
});
161183

162184
ManageCLIResponse.ConnectionUpdated = Object.freeze({
163185
code: 'ConnectionUpdated',
186+
message: 'Notification connection has been updated successfully',
164187
status: {}
165188
});
166189

167190
ManageCLIResponse.ConnectionStatus = Object.freeze({
168191
code: 'ConnectionStatus',
192+
message: 'Notification connection status retrieved successfully',
169193
status: {}
170194
});
171195

172196
ManageCLIResponse.ConnectionList = Object.freeze({
173197
code: 'ConnectionList',
198+
message: 'Notification connection list retrieved successfully',
174199
list: {}
175200
});
176201

src/test/unit_tests/jest_tests/test_nc_nsfs_account_cli.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,6 +1552,8 @@ describe('manage nsfs cli account flow', () => {
15521552
const res = await exec_manage_cli(type, action, account_options);
15531553
const res_json = JSON.parse(res.trim());
15541554
expect(res_json.response.code).toBe(ManageCLIResponse.AccountDeleted.code);
1555+
const message = `Account has been deleted successfully: ${name}`;
1556+
expect(res_json.response.message).toBe(message);
15551557
const account_by_name_exists = await config_fs.is_account_exists_by_name(name);
15561558
expect(account_by_name_exists).toBe(false);
15571559
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
@@ -755,6 +755,8 @@ describe('manage nsfs cli bucket flow', () => {
755755
const delete_bucket_options = { config_root, name: bucket_defaults.name, force: true};
756756
const resp = await exec_manage_cli(TYPES.BUCKET, ACTIONS.DELETE, delete_bucket_options);
757757
expect(JSON.parse(resp.trim()).response.code).toBe(ManageCLIResponse.BucketDeleted.code);
758+
const message = `Bucket has been deleted successfully: ${bucket_defaults.name}`;
759+
expect(JSON.parse(resp.trim()).response.message).toBe(message);
758760
const is_bucket_exists = await config_fs.is_bucket_exists(bucket_defaults.name);
759761
expect(is_bucket_exists).toBe(false);
760762
});

0 commit comments

Comments
 (0)