Auth
pytruenas.auth
ApiKeyAuth(api_key, username=None)
Bases: Credentials
Source code in src/pytruenas/auth.py
268 269 270 271 272 273 | |
MECHANISM = 'API_KEY_PLAIN'
class-attribute
instance-attribute
METHOD = 'login_with_api_key'
class-attribute
instance-attribute
api_key = api_key
instance-attribute
username = username
instance-attribute
AuthenticationError(response_type, response)
Bases: Exception
A modern auth.login_ex login was refused.
response_type is the server's discriminator (AUTH_ERR/DENIED/
EXPIRED/…); response is the full response dict for callers that need
the detail (e.g. a REDIRECT target).
Source code in src/pytruenas/auth.py
111 112 113 114 | |
response = response
instance-attribute
response_type = response_type
instance-attribute
BasicAuth(username, password, otp_token=None)
Bases: Credentials
Source code in src/pytruenas/auth.py
306 307 308 309 310 311 | |
MECHANISM = 'PASSWORD_PLAIN'
class-attribute
instance-attribute
METHOD = 'login'
class-attribute
instance-attribute
otp_token = otp_token
instance-attribute
password = password
instance-attribute
username = username
instance-attribute
Credentials(*args, **kwargs)
Source code in src/pytruenas/auth.py
126 127 | |
MECHANISM = None
class-attribute
instance-attribute
METHOD = None
class-attribute
instance-attribute
from_env(env=None)
staticmethod
Source code in src/pytruenas/auth.py
196 197 198 199 200 201 202 | |
from_host_credentials(username=None, password=None, otp=None, api_key=None, token=None)
staticmethod
Select a credential from an already-parsed credential mapping.
This is the hostctl bridge. hostctl.host.parse_credentials has
already split a URI's password field into the password proper and its
trailing key:value extras -- the OTP arrives here as otp, not
embedded in password. So this method deliberately does no string
parsing: it only picks the matching subclass. Contrast
Credentials(...), which still accepts (and must keep accepting) the
raw single-string form used by TN_CREDS and the creds= argument.
Both projects encode an OTP the same way -- a newline after the
password, then otp:<token> -- so the two paths agree on meaning
while splitting the string exactly once, here or in hostctl, never
twice.
A newline is the separator because a password can never contain one:
at an interactive prompt, Enter submits the value rather than being
typed into it. That makes the split free -- no character is stolen from
the password alphabet and no escaping scheme is needed. The one caveat
is transport-specific: a URI cannot carry a raw newline (urlsplit
strips it), so an OTP in a connection string must be percent-encoded as
%0A. See :mod:pytruenas.host.
Precedence when several are supplied: token, then api_key, then
password. They are mutually exclusive mechanisms rather than a
fallback chain, so passing more than one is a caller error; the order
only makes the outcome deterministic rather than arbitrary. With none of
them, this is local-socket auth (:class:LocalAuth), which is also what
an empty mapping means for a local target.
Source code in src/pytruenas/auth.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | |
login(client)
Legacy login via auth.login/login_with_* (unchanged).
Source code in src/pytruenas/auth.py
132 133 134 135 136 | |
login_ex(client, *, login_options=None, otp_provider=None)
Authenticate via the modern auth.login_ex mechanism.
Handles the discriminated response: SUCCESS returns the response
dict; OTP_REQUIRED calls auth.login_ex_continue with an OTP
token (from this credential's own otp_token if set, else from
otp_provider() if given, else raises); any other response_type
raises :class:AuthenticationError. A credential with no login_ex
mechanism (e.g. :class:LocalAuth) falls back to legacy :meth:login.
login_options overrides the server defaults ({"user_info": True,
"reconnect_token": False}).
Source code in src/pytruenas/auth.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |
LocalAuth(*args, **kwargs)
Bases: Credentials
Source code in src/pytruenas/auth.py
126 127 | |
TokenAuth(token)
Bases: Credentials
Source code in src/pytruenas/auth.py
292 293 | |