| 1377 | self._ini_parser = ini_parser |
| 1378 | |
| 1379 | def load(self): |
| 1380 | try: |
| 1381 | available_creds = self._ini_parser(self._creds_filename) |
| 1382 | except ConfigNotFound: |
| 1383 | return None |
| 1384 | if self._profile_name in available_creds: |
| 1385 | config = available_creds[self._profile_name] |
| 1386 | if self.ACCESS_KEY in config: |
| 1387 | logger.info( |
| 1388 | "Found credentials in shared credentials file: %s", |
| 1389 | self._creds_filename, |
| 1390 | ) |
| 1391 | access_key, secret_key = self._extract_creds_from_mapping( |
| 1392 | config, self.ACCESS_KEY, self.SECRET_KEY |
| 1393 | ) |
| 1394 | token = self._get_session_token(config) |
| 1395 | account_id = self._get_account_id(config) |
| 1396 | register_feature_id('CREDENTIALS_PROFILE') |
| 1397 | return Credentials( |
| 1398 | access_key, |
| 1399 | secret_key, |
| 1400 | token, |
| 1401 | method=self.METHOD, |
| 1402 | account_id=account_id, |
| 1403 | ) |
| 1404 | |
| 1405 | def _get_session_token(self, config): |
| 1406 | for token_envvar in self.TOKENS: |