| 610 | |
| 611 | |
| 612 | class ScopedConfigProvider(BaseProvider): |
| 613 | def __init__(self, config_var_name, session): |
| 614 | """Initialize ScopedConfigProvider. |
| 615 | |
| 616 | :type config_var_name: str or tuple |
| 617 | :param config_var_name: The name of the config variable to load from |
| 618 | the configuration file. If the value is a tuple, it must only |
| 619 | consist of two items, where the first item represents the section |
| 620 | and the second item represents the config var name in the section. |
| 621 | |
| 622 | :type session: :class:`botocore.session.Session` |
| 623 | :param session: The botocore session to get the loaded configuration |
| 624 | file variables from. |
| 625 | """ |
| 626 | self._config_var_name = config_var_name |
| 627 | self._session = session |
| 628 | |
| 629 | def provide(self): |
| 630 | """Provide a value from a config file property.""" |
| 631 | scoped_config = self._session.get_scoped_config() |
| 632 | if isinstance(self._config_var_name, tuple): |
| 633 | section_config = scoped_config.get(self._config_var_name[0]) |
| 634 | if not isinstance(section_config, dict): |
| 635 | return None |
| 636 | return section_config.get(self._config_var_name[1]) |
| 637 | return scoped_config.get(self._config_var_name) |
| 638 | |
| 639 | def __repr__(self): |
| 640 | return f'ScopedConfigProvider(config_var_name={self._config_var_name}, session={self._session})' |
| 641 | |
| 642 | |
| 643 | class EnvironmentProvider(BaseProvider): |
no outgoing calls