MCPcopy Index your code
hub / github.com/couchbase/couchbase-python-client / PasswordAuthenticator

Class PasswordAuthenticator

couchbase/auth.py:30–100  ·  view source on GitHub ↗

Password authentication mechanism. Args: username (str): Username to use for authentication. password (str): Password to use for authentication. cert_path (str, optional): Path of the certificate trust store. Defaults to None.

Source from the content-addressed store, hash-verified

28
29
30class PasswordAuthenticator(Authenticator):
31 """
32 Password authentication mechanism.
33
34 Args:
35 username (str): Username to use for authentication.
36 password (str): Password to use for authentication.
37 cert_path (str, optional): Path of the certificate trust store. Defaults to None.
38 """
39
40 def __init__(self,
41 username, # type: str
42 password, # type: str
43 cert_path=None, # type: Optional[str]
44 **kwargs # type: Dict[str, Any]
45 ):
46 """PasswordAuthenticator instance."""
47 if not isinstance(username, str):
48 msg = 'The username must be a str.'
49 raise InvalidArgumentException(msg)
50
51 if not isinstance(password, str):
52 msg = 'The password must be a str.'
53 raise InvalidArgumentException(msg)
54
55 if cert_path is not None and not isinstance(cert_path, str):
56 msg = 'The cert_path must be a str representing the path to the certificate trust store.'
57 raise InvalidArgumentException(msg)
58
59 allowed_sasl_mechanisms = kwargs.pop('allowed_sasl_mechanisms', None)
60 if allowed_sasl_mechanisms is not None:
61 msg = None
62 if isinstance(allowed_sasl_mechanisms, str):
63 allowed_sasl_mechanisms = allowed_sasl_mechanisms.split(',')
64 if isinstance(allowed_sasl_mechanisms, list):
65 if not all(map(lambda x: isinstance(x, str), allowed_sasl_mechanisms)):
66 msg = 'The allowed_sasl_mechanisms must be a list of str SASL mechanisms.'
67 else:
68 msg = ('The allowed_sasl_mechanisms must be a list of str SASL mechanisms '
69 ' or a comma separated str of SASL mechanisms.')
70 if msg:
71 raise InvalidArgumentException(msg)
72
73 self._username = username
74 self._password = password
75 self._cert_path = cert_path
76 self._allowed_sasl_mechanisms = allowed_sasl_mechanisms
77
78 super().__init__(**self.as_dict())
79
80 def valid_keys(self):
81 return ['username', 'password', 'cert_path', 'sasl_mech_force', 'allowed_sasl_mechanisms']
82
83 def as_dict(self):
84 d = {
85 'username': self._username,
86 'password': self._password,
87 'allowed_sasl_mechanisms': self._allowed_sasl_mechanisms

Calls

no outgoing calls