Port the MAAS code to oauthlib.
This commit is contained in:
parent
c86cdd766f
commit
bc41baf9b8
@ -22,10 +22,11 @@ from __future__ import print_function
|
||||
|
||||
from email.utils import parsedate
|
||||
import errno
|
||||
import oauth.oauth as oauth
|
||||
import oauthlib
|
||||
import os
|
||||
import time
|
||||
import urllib2
|
||||
|
||||
from six.moves.urllib_request import Request, urlopen
|
||||
|
||||
from cloudinit import log as logging
|
||||
from cloudinit import sources
|
||||
@ -274,25 +275,34 @@ def check_seed_contents(content, seed):
|
||||
|
||||
def oauth_headers(url, consumer_key, token_key, token_secret, consumer_secret,
|
||||
timestamp=None):
|
||||
consumer = oauth.OAuthConsumer(consumer_key, consumer_secret)
|
||||
token = oauth.OAuthToken(token_key, token_secret)
|
||||
client = oauthlib.oauth1.Client(
|
||||
consumer_key,
|
||||
client_secret=consumer_secret,
|
||||
resource_owner_key=token_key,
|
||||
resource_owner_secret=token_secret,
|
||||
signature_method=oauthlib.SIGNATURE_PLAINTEXT)
|
||||
uri, signed_headers, body = client.sign(url)
|
||||
return signed_headers
|
||||
|
||||
if timestamp is None:
|
||||
ts = int(time.time())
|
||||
else:
|
||||
ts = timestamp
|
||||
## consumer = oauth.OAuthConsumer(consumer_key, consumer_secret)
|
||||
## token = oauth.OAuthToken(token_key, token_secret)
|
||||
|
||||
params = {
|
||||
'oauth_version': "1.0",
|
||||
'oauth_nonce': oauth.generate_nonce(),
|
||||
'oauth_timestamp': ts,
|
||||
'oauth_token': token.key,
|
||||
'oauth_consumer_key': consumer.key,
|
||||
}
|
||||
req = oauth.OAuthRequest(http_url=url, parameters=params)
|
||||
req.sign_request(oauth.OAuthSignatureMethod_PLAINTEXT(),
|
||||
consumer, token)
|
||||
return req.to_header()
|
||||
## if timestamp is None:
|
||||
## ts = int(time.time())
|
||||
## else:
|
||||
## ts = timestamp
|
||||
|
||||
## params = {
|
||||
## 'oauth_version': "1.0",
|
||||
## 'oauth_nonce': oauth.generate_nonce(),
|
||||
## 'oauth_timestamp': ts,
|
||||
## 'oauth_token': token.key,
|
||||
## 'oauth_consumer_key': consumer.key,
|
||||
## }
|
||||
## req = oauth.OAuthRequest(http_url=url, parameters=params)
|
||||
## req.sign_request(oauth.OAuthSignatureMethod_PLAINTEXT(),
|
||||
## consumer, token)
|
||||
## return req.to_header()
|
||||
|
||||
|
||||
class MAASSeedDirNone(Exception):
|
||||
@ -359,8 +369,8 @@ if __name__ == "__main__":
|
||||
creds[key] = cfg[key]
|
||||
|
||||
def geturl(url, headers_cb):
|
||||
req = urllib2.Request(url, data=None, headers=headers_cb(url))
|
||||
return (urllib2.urlopen(req).read())
|
||||
req = Request(url, data=None, headers=headers_cb(url))
|
||||
return urlopen(req).read()
|
||||
|
||||
def printurl(url, headers_cb):
|
||||
print("== %s ==\n%s\n" % (url, geturl(url, headers_cb)))
|
||||
|
@ -8,7 +8,7 @@ PrettyTable
|
||||
|
||||
# This one is currently only used by the MAAS datasource. If that
|
||||
# datasource is removed, this is no longer needed
|
||||
oauth
|
||||
oauthlib
|
||||
|
||||
# This one is currently used only by the CloudSigma and SmartOS datasources.
|
||||
# If these datasources are removed, this is no longer needed
|
||||
|
@ -4,11 +4,7 @@ import shutil
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
# XXX DataSourceMAAS must be ported to oauthlib for Python 3
|
||||
import six
|
||||
if not six.PY3:
|
||||
from cloudinit.sources import DataSourceMAAS
|
||||
|
||||
from cloudinit.sources import DataSourceMAAS
|
||||
from cloudinit import url_helper
|
||||
from ..helpers import populate_dir
|
||||
|
||||
@ -18,7 +14,6 @@ except ImportError:
|
||||
import mock
|
||||
|
||||
|
||||
@unittest.skipIf(six.PY3, 'DataSourceMAAS must be ported to oauthlib')
|
||||
class TestMAASDataSource(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user