This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
security.py
81 lines (66 loc) · 2.66 KB
/
security.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
# Copyright (C) 2019
# Author: Cesar Roman
# Contact: thecesrom@gmail.com
"""Security Functions
The following functions give you access to interact with the users and
roles in the Gateway."""
__all__ = [
'getRoles',
'getUsername',
'getUserRoles',
'validateUser'
]
def getRoles():
"""Finds the roles that the currently logged in user has, returns
them as a Python tuple of strings.
Returns:
tuple[str]: A list of the roles (strings) that are assigned to
the current user.
"""
return 'Administrator', 'Developer'
def getUsername():
"""Returns the currently logged-in username.
Returns:
str: The current username.
"""
import getpass
return getpass.getuser()
def getUserRoles(username, password, authProfile='', timeout=60000):
"""Fetches the roles for a user from the Gateway. This may not be
the currently logged in user. Requires the password for that user.
If the authentication profile name is omitted, then the current
project's default authentication profile is used.
Args:
username (str): The username to fetch roles for.
password (str): The password for the user.
authProfile (str): The name of the authentication profile to
run against. Optional. Leaving this out will use the
project's default profile.
timeout (int): Timeout for client-to-gateway communication.
Optional. (default: 60,000ms)
Returns:
tuple[str]: A list of the roles that this user has, if the
user authenticates successfully. Otherwise, returns None.
"""
print(username, password, authProfile, timeout)
return 'Administrator', 'Developer'
def validateUser(username, password, authProfile='', timeout=60000):
"""Tests credentials (username and password) against an
authentication profile. Returns a boolean based upon whether or
not the authentication profile accepts the credentials. If the
authentication profile name is omitted, then the current project's
default authentication profile is used.
Args:
username (str): The username to validate.
password (str): The password for the user.
authProfile (str): The name of the authentication profile to
run against. Optional. Leaving this out will use the
project's default profile.
timeout (int): Timeout for client-to-gateway communication.
Optional. (default: 60,000ms)
Returns:
bool: False(0) if the user failed to authenticate, True(1) if
the username/password was a valid combination.
"""
print(username, password, authProfile, timeout)
return True