Commit 60a9ebab authored by Scott Moser's avatar Scott Moser

MAAS: fixes to data source and OauthUrlHelper

the previous version was broken.  The vital fixes here are:
 * adding parsedate and oauth1 imports to url_helper
 * fix skew_data usage intending to use self.skew_data

 * reorder imports in url_helper
 * fixes to python3 -m cloudinit.sources.DataSourceMaas

LP: #1488507
parent 827b7b90
......@@ -20,14 +20,10 @@
from __future__ import print_function
from email.utils import parsedate
import errno
import oauthlib.oauth1 as oauth1
import os
import time
from six.moves.urllib_request import Request, urlopen
from cloudinit import log as logging
from cloudinit import sources
from cloudinit import url_helper
......@@ -62,7 +58,7 @@ class DataSourceMAAS(sources.DataSource):
if required not in mcfg:
return url_helper.OauthUrlHelper()
return url_helper.OauthHelper(
return url_helper.OauthUrlHelper(
consumer_key=mcfg['consumer_key'], token_key=mcfg['token_key'],
......@@ -98,7 +94,7 @@ class DataSourceMAAS(sources.DataSource):
self.base_url = url
(userdata, metadata) = read_maas_seed_url(
self.base_url, self.oauth_helper.md_headers,
self.base_url, read_file_or_url=self.oauth_helper.readurl,
self.userdata_raw = userdata
self.metadata = metadata
......@@ -312,25 +308,30 @@ if __name__ == "__main__":
def geturl(url):
return oauth_helper.readurl(url).contents
def printurl(url, headers_cb):
print("== %s ==\n%s\n" % (url, geturl(url)))
def printurl(url):
print("== %s ==\n%s\n" % (url, geturl(url).decode()))
def crawl(url):
if url.endswith("/"):
for line in geturl(url).splitlines():
for line in geturl(url).decode().splitlines():
if line.endswith("/"):
crawl("%s%s" % (url, line))
elif line == "meta-data":
# meta-data is a dir, it *should* end in a /
crawl("%s%s" % (url, "meta-data/"))
printurl("%s%s" % (url, line))
if args.subcmd == "check-seed":
readurl = oauth_helper.readurl
if args.url[0] == "/" or args.url.startswith("file://"):
readurl = None
(userdata, metadata) = read_maas_seed_url(
args.url, read_file_or_url=oauth_helper.read_file_or_url,
args.url, version=args.apiver, read_file_or_url=readurl)
print("=== userdata ===")
print("=== metadata ===")
......@@ -20,16 +20,16 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <>.
import time
import json
import os
import requests
import six
import time
import requests
import oauthlib.oauth1 as oauth1
import os
import json
from email.utils import parsedate
from functools import partial
from requests import exceptions
import oauthlib.oauth1 as oauth1
from six.moves.urllib.parse import (
urlparse, urlunparse,
......@@ -434,7 +434,7 @@ class OauthUrlHelper(object):
if abs(old_skew - skew) > self.skew_change_limit:
self.update_skew_file(host, skew)
LOG.warn("Setting oauth clockskew for %s to %d", host, skew)
skew_data[host] = skew
self.skew_data[host] = skew
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment