Skip to content

Commit

Permalink
Enable support to user:password in HTTPS yum repo url
Browse files Browse the repository at this point in the history
Gingerbase makes a checking in new repository URLs passed in edit
window. However, YUM accepts urls like https://user:password@server,
which makes checking fail.
This patches adds the support in Gingerbase to accept this type of URL,
creating a HTTPS with basic authorization.

Signed-off-by: Rodrigo Trujillo <[email protected]>
  • Loading branch information
Truja authored and danielhb committed Mar 8, 2016
1 parent 10d4ec5 commit 8e91ec6
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#

import base64
import contextlib
import os
import urllib2
from httplib import HTTPConnection, HTTPException
from httplib import HTTPConnection, HTTPException, HTTPSConnection
from urlparse import urlparse

from wok.exception import InvalidParameter
Expand All @@ -38,7 +39,15 @@ def check_url_path(path, redirected=0):
try:
code = ''
parse_result = urlparse(path)
server_name = parse_result.netloc
headers = {}
server_name = parse_result.hostname
if (parse_result.scheme in ['https', 'ftp']) and \
(parse_result.username and parse_result.password):
# Yum accepts http urls with user and password credentials. Handle
# them and avoid access test errors
credential = parse_result.username + ':' + parse_result.password
headers = {'Authorization': 'Basic %s' %
base64.b64encode(credential)}
urlpath = parse_result.path
if not urlpath:
# Just a server, as with a repo.
Expand All @@ -47,9 +56,12 @@ def check_url_path(path, redirected=0):
else:
# socket.gaierror could be raised,
# which is a child class of IOError
conn = HTTPConnection(server_name, timeout=15)
if headers:
conn = HTTPSConnection(server_name, timeout=15)
else:
conn = HTTPConnection(server_name, timeout=15)
# Don't try to get the whole file:
conn.request('HEAD', path)
conn.request('HEAD', urlpath, headers=headers)
response = conn.getresponse()
code = response.status
conn.close()
Expand Down

0 comments on commit 8e91ec6

Please sign in to comment.