diff options
author | Chad Smith <chad.smith@canonical.com> | 2017-08-29 10:32:38 -0600 |
---|---|---|
committer | Scott Moser <smoser@brickies.net> | 2017-08-30 15:41:17 -0400 |
commit | b931a6473ee929193c0048640bf34876ce831a15 (patch) | |
tree | 319c9bdb5f5d109c24a338cca168e8f1c92e12ab /cloudinit/url_helper.py | |
parent | 502082f6f21fb7592a798087a4c49f90d886ad14 (diff) | |
download | cloud-init-git-b931a6473ee929193c0048640bf34876ce831a15.tar.gz |
url_helper: dynamically import oauthlib import from inside oauth_headers
oauth_headers is the only function which requires oauthlib, move the
import and ImportError handling inside this function to only attempt
loading at runtime if called. This will allow us to build on platforms
that don't have python-oauthlib installed by default. Add simple unittests
around the missing oauthlib dependencies to make sure the function
performs as intended and raises and NotImplementedError if oauthlib can't
be imported.
Diffstat (limited to 'cloudinit/url_helper.py')
-rw-r--r-- | cloudinit/url_helper.py | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/cloudinit/url_helper.py b/cloudinit/url_helper.py index c83061a9..0e0f5b4c 100644 --- a/cloudinit/url_helper.py +++ b/cloudinit/url_helper.py @@ -17,11 +17,6 @@ import time from email.utils import parsedate from functools import partial -try: - import oauthlib.oauth1 as oauth1 -except ImportError: - oauth1 = None - from requests import exceptions from six.moves.urllib.parse import ( @@ -492,8 +487,9 @@ class OauthUrlHelper(object): def oauth_headers(url, consumer_key, token_key, token_secret, consumer_secret, timestamp=None): - - if oauth1 is None: + try: + import oauthlib.oauth1 as oauth1 + except ImportError: raise NotImplementedError('oauth support is not available') if timestamp: |