Skip to content

Commit aa3f536

Browse files
committed
nc - iam - role policy crud PR notes
Signed-off-by: Amit Prinz Setter <alphaprinz@gmail.com>
1 parent 375b566 commit aa3f536

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

src/sdk/accountspace_fs.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,9 @@ class AccountSpaceFS {
811811
const requesting_account = account_sdk.requesting_account;
812812
this._check_if_requesting_account_is_root_account(action, requesting_account, {});
813813
const {owner_account_id, role_data} = await this._check_if_role_exists(params, requesting_account);
814+
if (role_data.iam_user_policies && role_data.iam_user_policies.length > 0) {
815+
this._throw_error_delete_conflict(action, params.role_name, 'role policies', 'role');
816+
}
814817
await this.config_fs.delete_role_config_file(role_data);
815818
iam_roles_cache.invalidate({
816819
role_name: role_data.name,
@@ -893,7 +896,7 @@ class AccountSpaceFS {
893896
dbg.error(`AccountSpaceFS.${action} error`, err);
894897
throw native_fs_utils.translate_error_codes(err, native_fs_utils.entity_enum.ROLE);
895898
}
896-
const policy_index = this._check_iam_policy_exists(action, iam_role_policies, params.policy_name);
899+
const policy_index = this._check_iam_policy_exists(action, iam_role_policies, params.policy_name, 'role');
897900
return {
898901
role_name: params.role_name,
899902
policy_name: params.policy_name,
@@ -1154,9 +1157,9 @@ class AccountSpaceFS {
11541157
}
11551158

11561159
// TODO: move to IamError class with a template
1157-
_throw_error_delete_conflict(action, account_to_delete, resource_name) {
1158-
dbg.error(`AccountSpaceFS.${action} requested account ` +
1159-
`${account_to_delete.name} ${account_to_delete._id} has ${resource_name}`);
1160+
_throw_error_delete_conflict(action, entity_to_delete, resource_name, entity_type = 'account') {
1161+
dbg.error(`AccountSpaceFS.${action} requested ${entity_type} ` +
1162+
`${entity_to_delete.name} ${entity_to_delete._id} has ${resource_name}`);
11601163
const message_with_details = `Cannot delete entity, must delete ${resource_name} first.`;
11611164
const { code, http_code, type } = IamError.DeleteConflict;
11621165
throw new IamError({ code, message: message_with_details, http_code, type });
@@ -1356,11 +1359,11 @@ class AccountSpaceFS {
13561359
}
13571360
}
13581361

1359-
_check_iam_policy_exists(action, iam_policies, policy_name) {
1362+
_check_iam_policy_exists(action, iam_policies, policy_name, container = 'user') {
13601363
const iam_policy_index = _get_iam_policy_index(iam_policies, policy_name);
13611364
if (iam_policy_index === -1) {
13621365
dbg.error(`AccountSpaceFS.${action} policy does not exist`, policy_name);
1363-
const message_with_details = `The user policy with name ${policy_name} cannot be found.`;
1366+
const message_with_details = `The ${container} policy with name ${policy_name} cannot be found.`;
13641367
const { code, http_code, type } = IamError.NoSuchEntity;
13651368
throw new IamError({ code, message: message_with_details, http_code, type });
13661369
}

0 commit comments

Comments
 (0)