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 Manager service.
- get_profile()[source]¶
Get the requested service profile.
- Parameters:
None
- Returns:
profile – The currently requested service profile.
- Return type:
str
Example
>>> from dl import authClient >>> profile = authClient.get_profile()
- get_svc_url()[source]¶
Return the currently-used Authentication Manager service URL.
- Parameters:
None
- Returns:
service_url – The currently-used Authentication Manager service URL.
- Return type:
str
Example
>>> 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
Example
>>> from dl import authClient >>> status = authClient.hasAccess(token, 'vos://test.dat')
- isAlive(svc_url='https://datalab.noirlab.edu/auth')[source]¶
- Check whether the Authentication Manager 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
Example
>>> from dl import authClient >>> authClient.isAlive()
- 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
Example
>>> from dl import authClient >>> authClient.isTokenLoggedIn(token)
- isUserLoggedIn(user)[source]¶
See whether the user identified by the username is currently logged in.
- Parameters:
user (str) – User login name.
- Returns:
status –
True
if user is currently logged in,False
otherwise.- Return type:
bool
Example
>>> from dl import authClient >>> authClient.isUserLoggedIn('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
Example
>>> from dl import authClient >>> authClient.isValidPassword('monty', 'python')
- 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
Example
>>> from dl import authClient >>> authClient.isValidToken(token)
- isValidUser(user)[source]¶
See whether the specified user is valid.
- Parameters:
user (str) – User login name.
- Returns:
status –
True
ifuser
is a valid user name,False
otherwise.- Return type:
bool
Example
>>> from dl import authClient >>> authClient.isValidUser('monty')
- 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
Example
>>> from dl import authClient >>> profiles = authClient.list_profiles(token, profile, format)
- login(username, password, debug=False, verbose=False)[source]¶
- Authenticate the user with the Authentication Manager 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
andpassword
).- Return type:
str
Example
>>> from dl import authClient >>> token = authClient.login('dldemo', 'dldemo') # get security token
- logout(token=None)[source]¶
Log the user out of Data Lab.
- Parameters:
token (str [Optional]) – User login token.
- Return type:
‘OK’ string on success, or exception message.
Example
>>> from dl import authClient >>> status = authClient.logout()
- passwordReset(token, username, password)[source]¶
- Reset a user password. 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.
Example
>>> from dl import authClient >>> authClient.passwordReset(token, 'monty', 'python')
- set_profile(profile)[source]¶
Set the requested service profile.
- Parameters:
profile (str) – Requested service profile.
- Return type:
Nothing
Example
>>> from dl import authClient >>> authClient.set_profile("dev")
- set_svc_url(svc_url)[source]¶
Set the URL of the Authentication Manager service to be used.
- Parameters:
svc_url (str) – Authentication Manager service base URL to call.
- Return type:
Nothing
Example
>>> 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:
Example
>>> 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
Example
>>> from dl import authClient >>> profile = authClient.get_profile()
- dl.authClient.get_svc_url()[source]¶
Return the currently-used Authentication Manager service URL.
- Parameters:
None
- Returns:
service_url – The currently-used Authentication Manager service URL.
- Return type:
str
Example
>>> 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
Example
>>> 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 Authentication Manager 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
Example
>>> from dl import authClient >>> authClient.isAlive()
- 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
Example
>>> from dl import authClient >>> authClient.isTokenLoggedIn(token)
- dl.authClient.isUserLoggedIn(user)[source]¶
See whether the user identified by the username is currently logged in.
- Parameters:
user (str) – User login name.
- Returns:
status –
True
if user is currently logged in,False
otherwise.- Return type:
bool
Example
>>> from dl import authClient >>> authClient.isUserLoggedIn('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
Example
>>> from dl import authClient >>> authClient.isValidPassword('monty', 'python')
- 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
Example
>>> from dl import authClient >>> authClient.isValidToken(token)
- dl.authClient.isValidUser(user)[source]¶
See whether the specified user is valid.
- Parameters:
user (str) – User login name.
- Returns:
status –
True
ifuser
is a valid user name,False
otherwise.- Return type:
bool
Example
>>> from dl import authClient >>> authClient.isValidUser('monty')
- dl.authClient.login(user, password=None, debug=False, verbose=False)[source]¶
- Authenticate the user with the Authentication Manager 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
andpassword
).- Return type:
str
Example
>>> from dl import authClient >>> token = authClient.login('dldemo', 'dldemo') # get security token
- dl.authClient.logout(token=None)[source]¶
Log the user out of Data Lab.
- Parameters:
token (str [Optional]) – User login token.
- Return type:
‘OK’ string on success, or exception message.
Example
>>> from dl import authClient >>> status = authClient.logout()
- dl.authClient.passwordReset(token, username, password)[source]¶
- Reset a user password. 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.
Example
>>> from dl import authClient >>> authClient.passwordReset(token, 'monty', 'python')
- dl.authClient.set_profile(profile)[source]¶
Set the requested service profile.
- Parameters:
profile (str) – Requested service profile.
- Return type:
Nothing
Example
>>> from dl import authClient >>> authClient.set_profile("dev")