Skip to content
Snippets Groups Projects
Commit 31118a18 authored by Daniel's avatar Daniel
Browse files

ENH: connection now has "input" password_method to read the password

parent 43146c98
Branches
Tags
No related merge requests found
# -*- coding: utf-8 -*-
#
# ** header v3.0
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# ** end header
#
"""input.
A CredentialsProvider which reads the password from the input line.
"""
from __future__ import absolute_import, unicode_literals, print_function
from .interface import CredentialsProvider, CredentialsAuthenticator
import getpass
def get_authentication_provider():
"""get_authentication_provider.
Return an authenticator which uses the input for username/password credentials.
Returns
-------
CredentialsAuthenticator
with an InputCredentialsProvider as back-end.
"""
return CredentialsAuthenticator(InputCredentialsProvider())
class InputCredentialsProvider(CredentialsProvider):
"""InputCredentialsProvider.
A class for obtaining the password directly from the user.
Methods
-------
configure
Attributes
----------
password
username
"""
def __init__(self):
super(InputCredentialsProvider, self).__init__()
self._password = None
self._username = None
def configure(self, **config):
"""configure.
Parameters
----------
**config
Keyword arguments containing at least keywords "username" and "password".
Returns
-------
None
"""
if config.get("username"):
self._username = config["username"]
else:
self._username = input("Please enter the user name: ")
self._password = getpass.getpass("Please enter the password: ")
@property
def password(self):
return self._password
@property
def username(self):
return self._username
...@@ -22,7 +22,10 @@ ...@@ -22,7 +22,10 @@
# ** end header # ** end header
# #
"""This module provides the interfaces for authenticating requests to the """This module provides the interfaces for authenticating requests to the
caosdb server.""" caosdb server.
Implementing modules muts provide a `get_authentication_provider()` method.
"""
from abc import ABCMeta, abstractmethod, abstractproperty from abc import ABCMeta, abstractmethod, abstractproperty
import logging import logging
from caosdb.connection.utils import urlencode from caosdb.connection.utils import urlencode
......
...@@ -145,8 +145,10 @@ def _make_conf(*conf): ...@@ -145,8 +145,10 @@ def _make_conf(*conf):
return result return result
_DEFAULT_CONF = {"password_method": "plain", "implementation": _DEFAULT_CONF = {
_DefaultCaosDBServerConnection} "password_method": "plain",
"implementation": _DefaultCaosDBServerConnection,
}
def _get_authenticator(**config): def _get_authenticator(**config):
...@@ -182,6 +184,12 @@ def configure_connection(**kwargs): ...@@ -182,6 +184,12 @@ def configure_connection(**kwargs):
1) The plain text password 1) The plain text password
2) A function which returns the password. 2) A function which returns the password.
timeout A connection timeout in seconds. timeout A connection timeout in seconds.
password_method The method to use for obtaining the password. Can be for
example:
- "plain" Need username and password arguments.
- "pass" Uses the `pass` password manager.
- "keyring" Uses the `keyring` library.
- "input" Asks for the password.
implementation A class which implements CaosDBServerConnection. (Default: implementation A class which implements CaosDBServerConnection. (Default:
_DefaultCaosDBServerConnection) _DefaultCaosDBServerConnection)
ssl_insecure Whether SSL certificate warnings should be ignored. Only use ssl_insecure Whether SSL certificate warnings should be ignored. Only use
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment