dl.authClient module¶
- dl.authClient.acToString(s)[source]¶
acToString – Force a return value to be type ‘string’ for all Python versions.
- class dl.authClient.authClient[source]¶
Bases:
object
- AUTHCLIENT – Client-side methods to access the Data Lab
Authentication Service.
- get_profile()[source]¶
Get the requested service profile.
- Parameters:
None
- Returns:
profile – The currently requested service profile.
- Return type:
str
Examples
>>> from dl import authClient >>> profile = authClient.client.get_profile()
- get_svc_url()[source]¶
Return the currently-used Authentication Service URL.
- Parameters:
None
- Returns:
service_url – The currently-used Authentication Service URL.
- Return type:
str
Examples
>>> from dl import authClient >>> service_url = authClient.get_svc_url()
- hasAccess(token, resource)[source]¶
See whether the given token has access to the named Resource.
- Parameters:
token (str) – User login token
resource (str) – Resource identifier to check
- Returns:
status – True if user owns or has access, False otherwise
- Return type:
bool
Examples
>>> from dl import authClient >>> status = authClient.hasAccess(token,'vos://test.dat')
- isAlive(svc_url='https://datalab.noirlab.edu/auth')[source]¶
- Check whether the AuthManager service at the given URL is
alive and responding. This is a simple call to the root service URL or ping() method.
- Parameters:
service_url (str) – The Query Service URL to ping.
- Returns:
result – True if service responds properly, False otherwise
- Return type:
bool
Examples
>>> from dl import authClient >>> if authClient.isAlive(): ... print("Auth Manager is alive")
- isTokenLoggedIn(token)[source]¶
See whether the user identified by the token is currently logged in.
- Parameters:
token (str) – User login token
- Returns:
status – True if token is marked as logged-in, False otherwise
- Return type:
bool
Examples
>>> if not authClient.isTokenLoggedIn(token): ... token = authClient.login('monty')
- isUserLoggedIn(user)[source]¶
See whether the user identified by the token is currently logged in.
- Parameters:
user (str) – User login name
- Returns:
status – True if user is currently logged-in, False otherwise
- Return type:
bool
Examples
>>> if not authClient.isUserLoggedIn(token): ... token = authClient.login('monty')
- isValidPassword(user, password)[source]¶
See whether the password is valid for the user.
- Parameters:
user (str) – User login name
password (str) – Password for named user
- Returns:
status – True if password is valid for the user, False otherwise
- Return type:
bool
Examples
>>> if authClient.isValidPassword('monty','python'): ... print("Valid password")
- isValidToken(token)[source]¶
See whether the current token is valid.
- Parameters:
token (str) – User login token
- Returns:
status – True if token is valid, False otherwise
- Return type:
bool
Examples
>>> if authClient.isValidToken(token): ... print("Valid token")
- isValidUser(user)[source]¶
See whether the specified user is valid.
- Parameters:
user (str) – User login name
- Returns:
status – True if ‘user’ is a valid user name, False otherwise
- Return type:
bool
Examples
>>> if authClient.isValidUser('monty'): ... print("Valid user")
- list_profiles(token, profile=None, format='text')[source]¶
List the service profiles which can be accessed by the user.
- Parameters:
token (str) – Valid auth service token.
- Returns:
profiles
- Return type:
JSON string
Examples
>>> from dl import authClient >>> profiles = authClient.client.list_profiles(token, profile, format)
- login(username, password, debug=False, verbose=False)[source]¶
- Authenticate the user with the Authentication Service.
We first check for a valid login token in the user’s $HOME/.datalab/ directory and simply return that rather than make a service call to get a new token. If a token exists but is invalid, we remove it and get a new token. In either case, we save the token for later use.
- Parameters:
username (str) – User login name.
password (str) – User password. If not given, a valid ID token will be searched for in the $HOME/.datalab directory.
debug (bool) – Method debug flag.
verbose (bool) – Initialize session to print verbose output messages.
- Returns:
token – One-time security token for valid user(identified via ‘username’ and ‘password’).
- Return type:
str
Examples
>>> from dl import authClient >>> token = authClient.login('dldemo', 'dldemo') # get security token
- logout(token=None)[source]¶
Log the user out of the Data Lab.
- Parameters:
token (str) – User login token
- Return type:
‘OK’ string on success, or exception message
Examples
>>> from dl import authClient >>> status = authClient.logout(token)
- passwordReset(token, username, password)[source]¶
- Reset a user password reset. We require that the user provide
either a valid ‘root’ token or the token for the account being reset.
- Parameters:
token (str) – User login token
username (str) – User login name
password (str) – User password
- Return type:
‘OK’ string on success, or exception message
Examples
>>> from dl import authClient >>> status = authClient.logout(token)
- set_profile(profile)[source]¶
Set the requested service profile.
- Parameters:
profile (str) – Requested service profile string.
- Return type:
Nothing
Examples
>>> from dl import authClient >>> token = authClient.client.set_profile("dev")
- set_svc_url(svc_url)[source]¶
Set the URL of the Authentication Service to be used.
- Parameters:
svc_url (str) – Authentication service base URL to call.
- Return type:
Nothing
Examples
>>> from dl import authClient >>> authClient.set_svc_url("http://localhost:7001/")
- dl.authClient.getClient()[source]¶
Get a new instance of the authClient client.
- Parameters:
None
- Returns:
client – An authClient object
- Return type:
Examples
>>> from dl import authClient >>> new_client = authClient.getClient()
- dl.authClient.get_profile()[source]¶
Get the requested service profile.
- Parameters:
None
- Returns:
profile – The currently requested service profile.
- Return type:
str
Examples
>>> from dl import authClient >>> profile = authClient.client.get_profile()
- dl.authClient.get_svc_url()[source]¶
Return the currently-used Authentication Service URL.
- Parameters:
None
- Returns:
service_url – The currently-used Authentication Service URL.
- Return type:
str
Examples
>>> from dl import authClient >>> service_url = authClient.get_svc_url()
- dl.authClient.hasAccess(user, resource)[source]¶
See whether the given token has access to the named Resource.
- Parameters:
token (str) – User login token
resource (str) – Resource identifier to check
- Returns:
status – True if user owns or has access, False otherwise
- Return type:
bool
Examples
>>> from dl import authClient >>> status = authClient.hasAccess(token,'vos://test.dat')
- dl.authClient.isAlive(svc_url='https://datalab.noirlab.edu/auth')[source]¶
- Check whether the AuthManager service at the given URL is
alive and responding. This is a simple call to the root service URL or ping() method.
- Parameters:
service_url (str) – The Query Service URL to ping.
- Returns:
result – True if service responds properly, False otherwise
- Return type:
bool
Examples
>>> from dl import authClient >>> if authClient.isAlive(): ... print("Auth Manager is alive")
- dl.authClient.isTokenLoggedIn(token)[source]¶
See whether the user identified by the token is currently logged in.
- Parameters:
token (str) – User login token
- Returns:
status – True if token is marked as logged-in, False otherwise
- Return type:
bool
Examples
>>> if not authClient.isTokenLoggedIn(token): ... token = authClient.login('monty')
- dl.authClient.isUserLoggedIn(user)[source]¶
See whether the user identified by the token is currently logged in.
- Parameters:
user (str) – User login name
- Returns:
status – True if user is currently logged-in, False otherwise
- Return type:
bool
Examples
>>> if not authClient.isUserLoggedIn(token): ... token = authClient.login('monty')
- dl.authClient.isValidPassword(user, password)[source]¶
See whether the password is valid for the user.
- Parameters:
user (str) – User login name
password (str) – Password for named user
- Returns:
status – True if password is valid for the user, False otherwise
- Return type:
bool
Examples
>>> if authClient.isValidPassword('monty','python'): ... print("Valid password")
- dl.authClient.isValidToken(token)[source]¶
See whether the current token is valid.
- Parameters:
token (str) – User login token
- Returns:
status – True if token is valid, False otherwise
- Return type:
bool
Examples
>>> if authClient.isValidToken(token): ... print("Valid token")
- dl.authClient.isValidUser(user)[source]¶
See whether the specified user is valid.
- Parameters:
user (str) – User login name
- Returns:
status – True if ‘user’ is a valid user name, False otherwise
- Return type:
bool
Examples
>>> if authClient.isValidUser('monty'): ... print("Valid user")
- dl.authClient.login(user, password=None, debug=False, verbose=False)[source]¶
- Authenticate the user with the Authentication Service.
We first check for a valid login token in the user’s $HOME/.datalab/ directory and simply return that rather than make a service call to get a new token. If a token exists but is invalid, we remove it and get a new token. In either case, we save the token for later use.
- Parameters:
username (str) – User login name.
password (str) – User password. If not given, a valid ID token will be searched for in the $HOME/.datalab directory.
debug (bool) – Method debug flag.
verbose (bool) – Initialize session to print verbose output messages.
- Returns:
token – One-time security token for valid user(identified via ‘username’ and ‘password’).
- Return type:
str
Examples
>>> from dl import authClient >>> token = authClient.login('dldemo', 'dldemo') # get security token
- dl.authClient.logout(token=None)[source]¶
Log the user out of the Data Lab.
- Parameters:
token (str) – User login token
- Return type:
‘OK’ string on success, or exception message
Examples
>>> from dl import authClient >>> status = authClient.logout(token)
- dl.authClient.passwordReset(token, username, password)[source]¶
- Reset a user password reset. We require that the user provide
either a valid ‘root’ token or the token for the account being reset.
- Parameters:
token (str) – User login token
username (str) – User login name
password (str) – User password
- Return type:
‘OK’ string on success, or exception message
Examples
>>> from dl import authClient >>> status = authClient.logout(token)
- dl.authClient.set_profile(profile)[source]¶
Set the requested service profile.
- Parameters:
profile (str) – Requested service profile string.
- Return type:
Nothing
Examples
>>> from dl import authClient >>> token = authClient.client.set_profile("dev")