Skip to content

Commit

Permalink
Enable github private repos.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgoppert committed Jun 16, 2017
1 parent 9ea33a7 commit 9b32ab6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Binary file added bloom/commands/.release.py.swp
Binary file not shown.
8 changes: 8 additions & 0 deletions bloom/github.py
Expand Up @@ -41,10 +41,14 @@
import datetime
import json
import socket
import os

from urlparse import urlunsplit
from urllib import urlencode

GITHUB_USER = os.getenv('GITHUB_USER', None)
GITHUB_PASSWORD = os.getenv('GITHUB_PASSWORD', None)

try:
# Python2
from urllib2 import HTTPError
Expand Down Expand Up @@ -88,6 +92,10 @@ def do_github_post_req(path, data=None, auth=None, site='api.github.com'):
else:
request = Request(url, data=json.dumps(data), headers=headers) # POST

if GITHUB_USER and GITHUB_PASSWORD:
authheader = 'Basic %s' % base64.b64encode('%s:%s' % (GITHUB_USER, GITHUB_PASSWORD))
request.add_header('Authorization', authheader)

try:
response = urlopen(request, timeout=120)
except HTTPError as e:
Expand Down
15 changes: 12 additions & 3 deletions bloom/util.py
Expand Up @@ -38,22 +38,26 @@

import argparse
import os
import base64
import shutil
import socket
import sys
import tempfile
import time

GITHUB_USER = os.getenv('GITHUB_USER', None)
GITHUB_PASSWORD = os.getenv('GITHUB_PASSWORD', None)

try:
# Python2
from urllib2 import HTTPError
from urllib2 import URLError
from urllib2 import urlopen
from urllib2 import urlopen, Request
except ImportError:
# Python3
from urllib.error import HTTPError
from urllib.error import URLError
from urllib.request import urlopen
from urllib.request import urlopen, Request

from email.utils import formatdate

Expand Down Expand Up @@ -195,8 +199,13 @@ def load_url_to_file_handle(url, retry=2, retry_period=1, timeout=10):
:param timeout: timeout for opening the URL in seconds
:type timeout: float
"""
req = Request(url)
if GITHUB_USER and GITHUB_PASSWORD:
authheader = 'Basic %s' % base64.b64encode('%s:%s' % (GITHUB_USER, GITHUB_PASSWORD))
req.add_header('Authorization', authheader)

try:
fh = urlopen(url, timeout=timeout)
fh = urlopen(req, timeout=timeout)
except HTTPError as e:
if e.code == 503 and retry:
time.sleep(retry_period)
Expand Down

0 comments on commit 9b32ab6

Please sign in to comment.