diff --git a/yaml_injection.py b/yaml_injection.py index 2a17c10..72df4b0 100644 --- a/yaml_injection.py +++ b/yaml_injection.py @@ -7,10 +7,17 @@ class InjectionLoader(yaml.SafeLoader): - def __init__(self, stream): + def __init__(self, stream, auth=None): super().__init__(stream) self.data = None self.main_node = None + self.auth = auth + + @classmethod + def authorized_loader(cls, auth): + def create_authorized_loader(stream): + return cls(stream, auth) + return create_authorized_loader def get_single_data(self): # Ensure that the stream contains a single document and construct it. @@ -42,7 +49,7 @@ def _inject(self, mapping, value_node, source=None): if not isinstance(urls, list): urls = [urls] for url in urls: - r = requests.get(url) + r = requests.get(url, auth=self.auth) r.raise_for_status() data = yaml.load(r.text, self.__class__) mapping.update(data)