Skip to content

Commit 2ac7c6b

Browse files
committed
[NRL-1351] Add confirm on clearing perms. Fix sonar warnings
1 parent d2411ab commit 2ac7c6b

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

scripts/manage_permissions.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ def list_apps() -> None:
7373
List all applications in the NRL environment.
7474
"""
7575
keys = _list_s3_keys("")
76-
apps = set([key.split("/")[0] for key in keys])
76+
apps = {key.split("/")[0] for key in keys}
7777

7878
if not apps:
7979
print("No applications found in the bucket.")
80-
return []
80+
return
8181

8282
print(f"There are {len(apps)} apps in {nrl_env} env:")
8383
for app in apps:
@@ -110,7 +110,7 @@ def list_allowed_types() -> None:
110110
print("The following pointer-types are allowed:")
111111

112112
for pointer_type, attributes in TYPE_ATTRIBUTES.items():
113-
print(f"- %-45s (%s)" % (pointer_type, attributes["display"][:45]))
113+
print("- %-45s (%s)" % (pointer_type, attributes["display"][:45]))
114114

115115

116116
def show_perms(app_id: str, org_ods: str) -> None:
@@ -212,6 +212,28 @@ def clear_perms(app_id: str, org_ods: str) -> None:
212212
Clear permissions for an application and organization.
213213
This will remove all permissions for the specified app and org.
214214
"""
215+
if COMPARE_AND_CONFIRM:
216+
current_perms = _get_perms_from_s3(f"{app_id}/{org_ods}.json")
217+
if not current_perms or current_perms == "[]":
218+
print(
219+
f"No need to clear permissions for {app_id}/{org_ods} as it currently has no permissions set."
220+
)
221+
return
222+
223+
print()
224+
print(f"Current permissions for {app_id}/{org_ods}:")
225+
print(current_perms)
226+
227+
print()
228+
confirm = (
229+
input("Are you SURE you want to clear these permissions? (yes/NO): ")
230+
.strip()
231+
.lower()
232+
)
233+
if confirm != "yes":
234+
print("Operation cancelled at user request.")
235+
return
236+
215237
s3 = _get_s3_client()
216238
s3.put_object(
217239
Bucket=nrl_auth_bucket_name,

0 commit comments

Comments
 (0)