forked from PaloAltoNetworks/prismacloud-api-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pcs_user_update.py
83 lines (70 loc) · 2.17 KB
/
pcs_user_update.py
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
""" Update a User """
from __future__ import print_function
from pc_lib import pc_api, pc_utility
# --Configuration-- #
parser = pc_utility.get_arg_parser()
parser.add_argument(
'user_email',
type=str,
help='Email address of the User to update.')
parser.add_argument(
'-fn',
'--firstname',
type=str,
help='(Optional) - New First Name for the specified User.')
parser.add_argument(
'-ln',
'--lastname',
type=str,
help='(Optional) - New Last Name for the specified User.')
parser.add_argument(
'-rn',
'--role_name',
type=str,
help='(Optional) - New Role to assign for the specified User.')
parser.add_argument(
'--access_keys_allowed',
choices=['true', 'false', None],
type=str,
help='(Optional) - Whether Access Keys are allowed for the specified User.')
args = parser.parse_args()
# --Initialize-- #
pc_utility.prompt_for_verification_to_continue(args)
settings = pc_utility.get_settings(args)
pc_api.configure(settings)
# --Main-- #
print('API - Getting the User ...', end='')
user = pc_api.user_read(args.user_email.lower())
print(' done.')
print()
update_needed = False
if args.role_name is not None:
print('API - Getting the Roles list ...', end='')
user_role_list = pc_api.user_role_list_read()
print(' done.')
print()
user_role_id = None
for user_role in user_role_list:
if user_role['name'].lower() == args.role_name.lower():
user_role_id = user_role['id']
update_needed = True
break
if user_role_id is None:
pc_utility.error_and_exit(400, 'Role not found. Please verify the Role name.')
user['roleId'] = user_role_id
if args.firstname is not None:
update_needed = True
user['firstName'] = args.firstname
if args.lastname is not None:
update_needed = True
user['lastName'] = args.lastname
if args.access_keys_allowed is not None:
update_needed = True
user['accessKeysAllowed'] = args.access_keys_allowed
if update_needed:
print('API - Updating the User ...', end='')
pc_api.user_update(user)
print(' done.')
print()
else:
print('No update required: current User attributes match new attributes.')