Commit 00e24d33 authored by Lucas Carvalho's avatar Lucas Carvalho

Moved the method parseUrl to a utils file.

This file must provide all the utils function, to avoid duplicating
code.
parent 3b4bc05a
......@@ -21,8 +21,8 @@ import os
import tempfile
import urllib
import urllib2
import urlparse
import M2Crypto
from slapos.libnetworkcacheutils import parseUrl
_MARKER = ([], [''], None, '')
......@@ -36,34 +36,17 @@ class NetworkcacheClient(object):
- SHACACHE
'''
def parseUrl(self, url):
return_dict = {}
parsed_url = urlparse.urlparse(url)
return_dict['header_dict'] = {'Content-Type': 'application/json'}
user = parsed_url.username
passwd = parsed_url.password
if user is not None:
authentication_string = '%s:%s' % (user, passwd)
base64string = base64.encodestring(authentication_string).strip()
return_dict['header_dict']['Authorization'] = 'Basic %s' %\
base64string
return_dict['path'] = parsed_url.path
return_dict['host'] = parsed_url.hostname
return_dict['port'] = parsed_url.port or 80
return return_dict
def __init__(self, shacache, shadir,
signature_private_key_file=None,
signature_certificate_file_list=None):
''' Set the initial values. '''
# ShaCache Properties
for k, v in self.parseUrl(shacache).iteritems():
for k, v in parseUrl(shacache).iteritems():
setattr(self, 'shacache_%s' % k, v)
self.shacache_url = shacache
# ShaDir Properties
for k, v in self.parseUrl(shadir).iteritems():
for k, v in parseUrl(shadir).iteritems():
setattr(self, 'shadir_%s' % k, v)
self.signature_private_key_file = signature_private_key_file
......
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