-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcli
More file actions
executable file
·190 lines (157 loc) · 5.08 KB
/
cli
File metadata and controls
executable file
·190 lines (157 loc) · 5.08 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/env python3
import argparse
import pprint
import json
from uaa_bot.bot import UAABot
from uaa_bot.client import UAAClient
from uaa_bot.notifier import Notifier
def main():
pp = pprint.PrettyPrinter(indent=2)
parser = argparse.ArgumentParser(
description="The uaa-bot cli.",
)
subparsers = parser.add_subparsers(
dest="command", help="Run <command> help for more information."
)
## Bulk deactivation
parser_bulk_deactivate = subparsers.add_parser(
"bulk-deactivate",
help="Deactivate accounts that have not been logged in many months without sending email notification.",
)
parser_bulk_deactivate.add_argument(
"-d",
"--days-ago",
dest="days_ago",
type=int,
help="End of time range for the n number of days ago.",
required=True,
default=180,
)
parser_bulk_deactivate.add_argument(
"-r",
"--day-range",
dest="day_range",
type=int,
help="The n number of days to create a range before the --days-ago param.",
required=True,
default=365,
)
parser_bulk_deactivate.add_argument(
"-t",
"--title",
dest="title",
type=str,
help="The title of the summary of the bulk deactivation.",
required=False,
default="Bulk deactivation",
)
## Notify email
parser_notify = subparsers.add_parser(
"notify",
help="Notify users with an email to login to their accounts within 1 day or be deactivated.",
)
parser_notify.add_argument(
"-e",
"--email",
dest="email",
type=str,
required=True,
)
parser_notify.add_argument(
"-t",
"--template",
dest="template",
type=str,
required=True,
)
## Notify 10 days to deactivation
parser_notify_10_days = subparsers.add_parser(
"notify-10-days",
help="Notify users with an email to login to their accounts within 10 days or be deactivated.",
)
## Notify 1 day to deactivation
parser_notify_1_day = subparsers.add_parser(
"notify-1-day",
help="Notify users with an email to login to their accounts within 1 day or be deactivated.",
)
## Notify and deactivate
parser_notify_deactivate = subparsers.add_parser(
"notify-deactivate",
help="Notify users with an email that their account has been deactivated after 90 days without logging in.",
)
## Notify and deactivate
parser_list_expired_accounts = subparsers.add_parser(
"list-expired",
help="List users that have to be deactivated",
)
## List Last Logons for Users
parser_list_last_logon = subparsers.add_parser(
"list-last-logon",
help="List last logon info for users",
)
parser_list_last_logon.add_argument(
"-d",
"--days-ago",
dest="days_ago",
type=int,
help="End of time range for the n number of days ago.",
required=True,
default=180,
)
parser_list_last_logon.add_argument(
"-r",
"--day-range",
dest="day_range",
type=int,
help="The n number of days to create a range before the --days-ago param.",
required=True,
default=365,
)
parser_list_last_logon.add_argument(
"-t",
"--title",
dest="title",
type=str,
help="The title of the summary of the List Last Logon.",
required=False,
default="Last Logons for all users",
)
args = parser.parse_args()
bot = UAABot()
client = UAAClient()
if args.command == "bulk-deactivate":
summary = bot.deactivate_users(
days_ago=args.days_ago, days_range=args.day_range, summary_title=args.title
)
pp.pprint(summary)
if args.command == "notify":
email = args.email
template = args.template
notification = Notifier(email)
sent_mail = notification.send_email(template)
print(sent_mail)
if args.command == "notify-10-days":
summary = bot.notify_deactivation_in_10_days()
pp.pprint(summary)
if args.command == "notify-1-day":
summary = bot.notify_deactivation_in_1_day()
pp.pprint(summary)
if args.command == "notify-deactivate":
summary = bot.notify_and_deactivate()
pp.pprint(summary)
if args.command == "list-expired":
client.authenticate()
response = client.list_expiring_users(days_ago=90, days_range=1000)
total_results = response.get("totalResults", 0)
users = response.get("resources", [])
print(f"Total Expired Users: {total_results}")
for user in users:
guid = user.get("id", "No GUID")
email = user.get("userName", "Not Found")
print(f"Email: {email}, GUID: {guid}")
if args.command == "list-last-logon":
summary = bot.get_all_user_last_logon(days_ago=args.days_ago, days_range=args.day_range)
print(json.dumps(summary))
return 0
if __name__ == "__main__":
exit(main())