Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Commit

Permalink
CP-30941: allow planex-fetch to apply additional headers from planexrc
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Syms <[email protected]>
  • Loading branch information
MarkSymsCtx committed Mar 25, 2019
1 parent 3b143fc commit 0dc37be
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions planex/cmd/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from planex.link import Link
from planex.cmd.args import common_base_parser, rpm_define_parser
from planex.config import Configuration
from planex.repository import Repository
from planex.util import run
from planex.util import setup_logging
Expand Down Expand Up @@ -132,6 +133,12 @@ def fetch_http(url, filename, retries):
"user-agent": useragent,
})

# See if we have any additional custom headers
custom_headers = Configuration.items('Headers')
if custom_headers:
for header in custom_headers:
headers.update({header[0]: header[1]})

# Once we use requests >= 2.18.0, we should change this into
# with requests.get ... as r:
req = requests_retry_session(retries).get(
Expand Down
11 changes: 11 additions & 0 deletions planex/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ def get(cls, section, option, default=None):
return config.get(section, option)
return default

@classmethod
def items(cls, section):
"""
Return the list of (name, value) pairs for each option in the given
section or an empty list.
"""
config = cls._config()
if config.has_section(section):
return config.items(section)
return []

@classmethod
def _config(cls):
"""Return a ConfigParser object"""
Expand Down

0 comments on commit 0dc37be

Please sign in to comment.