Compare commits
No commits in common. "master" and "v1.0.6" have entirely different histories.
6 changed files with 14 additions and 32 deletions
|
|
@ -1,7 +1,5 @@
|
||||||
FROM python:2.7.11-alpine
|
FROM python:2.7.11-alpine
|
||||||
|
|
||||||
RUN apk update && apk add ca-certificates
|
|
||||||
|
|
||||||
ADD . /sdk
|
ADD . /sdk
|
||||||
WORKDIR sdk
|
WORKDIR sdk
|
||||||
RUN python setup.py install
|
RUN python setup.py install
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ from dockercloud.api.utils import Utils
|
||||||
from dockercloud.api.events import Events
|
from dockercloud.api.events import Events
|
||||||
from dockercloud.api.nodeaz import AZ
|
from dockercloud.api.nodeaz import AZ
|
||||||
|
|
||||||
__version__ = '1.0.9'
|
__version__ = '1.0.6'
|
||||||
|
|
||||||
dockercloud_auth = os.environ.get('DOCKERCLOUD_AUTH')
|
dockercloud_auth = os.environ.get('DOCKERCLOUD_AUTH')
|
||||||
basic_auth = auth.load_from_file("~/.docker/config.json")
|
basic_auth = auth.load_from_file("~/.docker/config.json")
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ from .base import Immutable, StreamingLog
|
||||||
class Action(Immutable):
|
class Action(Immutable):
|
||||||
subsystem = 'audit'
|
subsystem = 'audit'
|
||||||
endpoint = "/action"
|
endpoint = "/action"
|
||||||
namespaced = False
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _pk_key(cls):
|
def _pk_key(cls):
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,12 @@ 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)
|
||||||
|
|
@ -45,29 +43,11 @@ 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:
|
||||||
|
|
|
||||||
|
|
@ -267,7 +267,11 @@ class Triggerable(BasicObject):
|
||||||
|
|
||||||
class StreamingAPI(BasicObject):
|
class StreamingAPI(BasicObject):
|
||||||
def __init__(self, url):
|
def __init__(self, url):
|
||||||
|
self._ws_init(url)
|
||||||
|
|
||||||
|
def _ws_init(self, url):
|
||||||
self.url = url
|
self.url = url
|
||||||
|
|
||||||
user_agent = 'python-dockercloud/%s' % dockercloud.__version__
|
user_agent = 'python-dockercloud/%s' % dockercloud.__version__
|
||||||
if dockercloud.user_agent:
|
if dockercloud.user_agent:
|
||||||
user_agent = "%s %s" % (dockercloud.user_agent, user_agent)
|
user_agent = "%s %s" % (dockercloud.user_agent, user_agent)
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ class Events(StreamingAPI):
|
||||||
else:
|
else:
|
||||||
url = "/".join([dockercloud.stream_host.rstrip("/"), "api", "audit", self._api_version,
|
url = "/".join([dockercloud.stream_host.rstrip("/"), "api", "audit", self._api_version,
|
||||||
endpoint.lstrip("/")])
|
endpoint.lstrip("/")])
|
||||||
|
self.invaid_auth_headers = set()
|
||||||
|
self.auth_error = ""
|
||||||
super(self.__class__, self).__init__(url)
|
super(self.__class__, self).__init__(url)
|
||||||
|
|
||||||
def _on_message(self, ws, message):
|
def _on_message(self, ws, message):
|
||||||
|
|
@ -37,16 +39,15 @@ class Events(StreamingAPI):
|
||||||
|
|
||||||
def _on_error(self, ws, e):
|
def _on_error(self, ws, e):
|
||||||
if isinstance(e, websocket._exceptions.WebSocketBadStatusException) and getattr(e, "status_code") == 401:
|
if isinstance(e, websocket._exceptions.WebSocketBadStatusException) and getattr(e, "status_code") == 401:
|
||||||
self.auth_error = True
|
self.auth_error = "Not Authorized"
|
||||||
|
self.invaid_auth_headers.add(str(dockercloud.auth.get_auth_header()))
|
||||||
|
|
||||||
super(self.__class__, self)._on_error(ws, e)
|
super(self.__class__, self)._on_error(ws, e)
|
||||||
|
|
||||||
def run_forever(self, *args, **kwargs):
|
def run_forever(self, *args, **kwargs):
|
||||||
while True:
|
while True:
|
||||||
if self.auth_error:
|
if str(dockercloud.auth.get_auth_header()) in self.invaid_auth_headers:
|
||||||
self.auth_error = False
|
raise AuthError(self.auth_error)
|
||||||
raise AuthError("Not Authorized")
|
|
||||||
|
|
||||||
ws = websocket.WebSocketApp(self.url, header=self.header,
|
ws = websocket.WebSocketApp(self.url, header=self.header,
|
||||||
on_open=self._on_open,
|
on_open=self._on_open,
|
||||||
on_message=self._on_message,
|
on_message=self._on_message,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue