Skip to content
This repository was archived by the owner on Jan 20, 2020. It is now read-only.

Merge python3 pull requests, add tests for python3 #35

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Dockerfile.py3
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM python:3.5.3-alpine

RUN apk update && apk add ca-certificates

ADD . /sdk
WORKDIR sdk
RUN python setup.py install

14 changes: 11 additions & 3 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
sut:
build: .
command: python setup.py test
version: '3'
services:
sut:
build: .
command: python setup.py test

sut-py3:
build:
context: .
dockerfile: Dockerfile.py3
command: python setup.py test
6 changes: 4 additions & 2 deletions dockercloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
basic_auth = auth.load_from_file("~/.docker/config.json")

if os.environ.get('DOCKERCLOUD_USER') and os.environ.get('DOCKERCLOUD_PASS'):
basic_auth = base64.b64encode("%s:%s" % (os.environ.get('DOCKERCLOUD_USER'), os.environ.get('DOCKERCLOUD_PASS')))
creds = "%s:%s" % (os.environ.get('DOCKERCLOUD_USER'), os.environ.get('DOCKERCLOUD_PASS'))
basic_auth = base64.b64encode(creds.encode()).decode()
if os.environ.get('DOCKERCLOUD_USER') and os.environ.get('DOCKERCLOUD_APIKEY'):
basic_auth = base64.b64encode("%s:%s" % (os.environ.get('DOCKERCLOUD_USER'), os.environ.get('DOCKERCLOUD_APIKEY')))
creds = "%s:%s" % (os.environ.get('DOCKERCLOUD_USER'), os.environ.get('DOCKERCLOUD_APIKEY'))
basic_auth = base64.b64encode(creds.encode()).decode()

rest_host = os.environ.get("DOCKERCLOUD_REST_HOST") or 'https://cloud.docker.com/'
stream_host = os.environ.get("DOCKERCLOUD_STREAM_HOST") or 'wss://ws.cloud.docker.com/'
Expand Down
9 changes: 6 additions & 3 deletions dockercloud/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

def authenticate(username, password):
verify_credential(username, password)
dockercloud.basic_auth = base64.b64encode("%s:%s" % (username, password))
cred = "%s:%s" % (username, password)
dockercloud.basic_auth = base64.b64encode(cred.encode())


def verify_credential(username, password):
Expand Down Expand Up @@ -73,12 +74,14 @@ def load_from_file(f="~/.docker/config.json"):

def get_auth_header():
try:
dockercloud.basic_auth = base64.b64encode("%s:%s" % (dockercloud.user, dockercloud.password))
cred = "%s:%s" % (dockercloud.user, dockercloud.password)
dockercloud.basic_auth = base64.b64encode(cred.encode()).decode()
except:
pass

try:
dockercloud.basic_auth = base64.b64encode("%s:%s" % (dockercloud.user, dockercloud.apikey))
cred = "%s:%s" % (dockercloud.user, dockercloud.apikey)
dockercloud.basic_auth = base64.b64encode(cred.encode()).decode()
except:
pass

Expand Down
8 changes: 4 additions & 4 deletions dockercloud/api/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


def get_session(time=time):
if (dockercloud.reconnection_interval >= 0):
if dockercloud.reconnection_interval is not None and (dockercloud.reconnection_interval >= 0):
global last_connection_time
if (time.time() - last_connection_time > dockercloud.reconnection_interval):
new_session()
Expand All @@ -40,9 +40,9 @@ def new_session():

def send_request(method, path, inject_header=True, **kwargs):
json = None
url = urljoin(dockercloud.rest_host.rstrip("/"), path.strip("/").encode("ascii", "ignore"))
if not url.endswith("/"):
url = "%s/" % url
url = urljoin(dockercloud.rest_host.encode(), path.strip("/").encode())
if not url.endswith(b"/"):
url = b"%s/" % url
user_agent = 'python-dockercloud/%s' % dockercloud.__version__
if dockercloud.user_agent:
user_agent = "%s %s" % (dockercloud.user_agent, user_agent)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
future==0.15.0
mock==2.0.0
requests==2.7.0
six==1.9.0
websocket-client==0.37.0
4 changes: 2 additions & 2 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import absolute_import
from __future__ import absolute_import, print_function

import os
import tempfile
Expand Down Expand Up @@ -26,7 +26,7 @@ def tearDown(self):
def test_auth_authenticate(self, mock_verify_credential):
dockercloud.auth.authenticate(FAKE_USER, FAKE_PASSWORD)
mock_verify_credential.assert_called_with(FAKE_USER, FAKE_PASSWORD)
self.assertEqual(dockercloud.basic_auth, FAKE_BASIC_AUTH)
self.assertEqual(dockercloud.basic_auth, FAKE_BASIC_AUTH.encode('latin-1'))
self.tearDown()

def test_auth_is_authenticated(self):
Expand Down