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

Commit

Permalink
Merge branch 'staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
tifayuki committed Aug 5, 2016
2 parents 56c8064 + 06988c3 commit 4325c7c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM python:2.7.11-alpine

RUN apk update && apk add ca-certificates

ADD . /sdk
WORKDIR sdk
RUN python setup.py install
Expand Down
2 changes: 1 addition & 1 deletion dockercloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from dockercloud.api.events import Events
from dockercloud.api.nodeaz import AZ

__version__ = '1.0.7'
__version__ = '1.0.8'

dockercloud_auth = os.environ.get('DOCKERCLOUD_AUTH')
basic_auth = auth.load_from_file("~/.docker/config.json")
Expand Down
26 changes: 23 additions & 3 deletions dockercloud/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import base64
import json
import os
import subprocess

from requests.auth import HTTPBasicAuth

import dockercloud
from .http import send_request

HUB_INDEX = "https://index.docker.io/v1/"

def authenticate(username, password):
verify_credential(username, password)
Expand Down Expand Up @@ -43,11 +45,29 @@ def load_from_file(f="~/.docker/config.json"):
try:
with open(os.path.expanduser(f)) as config_file:
data = json.load(config_file)

return data.get("auths", {}).get("https://index.docker.io/v1/", {}).get("auth", None)
except Exception:
except:
return None

creds_store = data.get("credsStore", None)
if creds_store:
try:
cmd = "docker-credential-" + creds_store
p = subprocess.Popen([cmd, 'get'], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT)
out = p.communicate(input=HUB_INDEX)[0]
except:
raise dockercloud.AuthError('error getting credentials - err: exec: "%s": executable file not found in $PATH, out: ``' % cmd)

try:
credential = json.loads(out)
username = credential.get("Username")
password = credential.get("Secret")
return base64.b64encode("%s:%s" % (username, password))
except:
return None

else:
return data.get("auths", {}).get(HUB_INDEX, {}).get("auth", None)


def get_auth_header():
try:
Expand Down

0 comments on commit 4325c7c

Please sign in to comment.