|
44 | 44 | AuthByPlugin,
|
45 | 45 | AuthByUsrPwdMfa,
|
46 | 46 | AuthByWebBrowser,
|
| 47 | + AuthNoAuth, |
47 | 48 | )
|
48 | 49 | from .auth.idtoken import AuthByIdToken
|
49 | 50 | from .backoff_policies import exponential_backoff
|
|
98 | 99 | DEFAULT_AUTHENTICATOR,
|
99 | 100 | EXTERNAL_BROWSER_AUTHENTICATOR,
|
100 | 101 | KEY_PAIR_AUTHENTICATOR,
|
| 102 | + NO_AUTH_AUTHENTICATOR, |
101 | 103 | OAUTH_AUTHENTICATOR,
|
102 | 104 | PROGRAMMATIC_ACCESS_TOKEN,
|
103 | 105 | REQUEST_ID,
|
@@ -1248,9 +1250,15 @@ def __config(self, **kwargs):
|
1248 | 1250 | with open(token_file_path) as f:
|
1249 | 1251 | self._token = f.read()
|
1250 | 1252 |
|
| 1253 | + # Set of authenticators allowing empty user. |
| 1254 | + empty_user_allowed_authenticators = {OAUTH_AUTHENTICATOR, NO_AUTH_AUTHENTICATOR} |
| 1255 | + |
1251 | 1256 | if not (self._master_token and self._session_token):
|
1252 |
| - if not self.user and self._authenticator != OAUTH_AUTHENTICATOR: |
1253 |
| - # OAuth Authentication does not require a username |
| 1257 | + if ( |
| 1258 | + not self.user |
| 1259 | + and self._authenticator not in empty_user_allowed_authenticators |
| 1260 | + ): |
| 1261 | + # OAuth and NoAuth Authentications does not require a username |
1254 | 1262 | Error.errorhandler_wrapper(
|
1255 | 1263 | self,
|
1256 | 1264 | None,
|
@@ -1279,14 +1287,15 @@ def __config(self, **kwargs):
|
1279 | 1287 | {"msg": "Password is empty", "errno": ER_NO_PASSWORD},
|
1280 | 1288 | )
|
1281 | 1289 |
|
1282 |
| - if not self._account: |
| 1290 | + # Only AuthNoAuth allows account to be omitted. |
| 1291 | + if not self._account and not isinstance(self.auth_class, AuthNoAuth): |
1283 | 1292 | Error.errorhandler_wrapper(
|
1284 | 1293 | self,
|
1285 | 1294 | None,
|
1286 | 1295 | ProgrammingError,
|
1287 | 1296 | {"msg": "Account must be specified", "errno": ER_NO_ACCOUNT_NAME},
|
1288 | 1297 | )
|
1289 |
| - if "." in self._account: |
| 1298 | + if self._account and "." in self._account: |
1290 | 1299 | self._account = parse_account(self._account)
|
1291 | 1300 |
|
1292 | 1301 | if not isinstance(self._backoff_policy, Callable) or not isinstance(
|
|
0 commit comments