add support for credential-helpers
This commit is contained in:
parent
f5c85f96f1
commit
bc67aa43cb
1 changed files with 23 additions and 3 deletions
|
|
@ -3,12 +3,14 @@ from __future__ import absolute_import
|
||||||
import base64
|
import base64
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
from requests.auth import HTTPBasicAuth
|
from requests.auth import HTTPBasicAuth
|
||||||
|
|
||||||
import dockercloud
|
import dockercloud
|
||||||
from .http import send_request
|
from .http import send_request
|
||||||
|
|
||||||
|
HUB_INDEX = "https://index.docker.io/v1/"
|
||||||
|
|
||||||
def authenticate(username, password):
|
def authenticate(username, password):
|
||||||
verify_credential(username, password)
|
verify_credential(username, password)
|
||||||
|
|
@ -43,11 +45,29 @@ def load_from_file(f="~/.docker/config.json"):
|
||||||
try:
|
try:
|
||||||
with open(os.path.expanduser(f)) as config_file:
|
with open(os.path.expanduser(f)) as config_file:
|
||||||
data = json.load(config_file)
|
data = json.load(config_file)
|
||||||
|
except:
|
||||||
return data.get("auths", {}).get("https://index.docker.io/v1/", {}).get("auth", None)
|
|
||||||
except Exception:
|
|
||||||
return None
|
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():
|
def get_auth_header():
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue