-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathdelete.py
More file actions
40 lines (32 loc) · 1.22 KB
/
delete.py
File metadata and controls
40 lines (32 loc) · 1.22 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
import click
import sys
from typing import Optional
from utils.utils import delete_user, collect_input_data
from utils.logger import dfl_logger as Logger
@click.command()
@click.option("--username", "-u", help="Username of the user to delete", type=str)
@click.option("--input", "input_json", help="JSON input with username", type=str)
@click.option(
"-w",
"--what-if",
is_flag=True,
help="Show what would happen without making changes",
)
def delete(username: Optional[str], input_json: Optional[str], what_if: bool):
"""
Delete a Linux user.
This command deletes a specified Linux user from the system.
"""
try:
data = collect_input_data(username=username, input_json=input_json)
username_to_delete = data.get("username")
if not username_to_delete:
Logger.error("Username is required to delete a user.", target="delete")
sys.exit(1)
Logger.info(
f"Processing delete request for user: {username_to_delete}", target="delete"
)
delete_user(username=username_to_delete, what_if=what_if)
except Exception as e:
Logger.error(f"Failed to process delete command: {str(e)}", target="delete")
sys.exit(1)