Skip to content

Commit

Permalink
Merge pull request #4 from oztqa/allow_authorized_requests
Browse files Browse the repository at this point in the history
allow authorized requests
  • Loading branch information
griddic authored Feb 13, 2020
2 parents da62517 + 285a062 commit cc918ab
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions yaml_injection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit cc918ab

Please sign in to comment.