Compare commits

..

No commits in common. "master" and "v1.0.8" have entirely different histories.

3 changed files with 11 additions and 6 deletions

View file

@ -25,7 +25,7 @@ from dockercloud.api.utils import Utils
from dockercloud.api.events import Events
from dockercloud.api.nodeaz import AZ
__version__ = '1.0.9'
__version__ = '1.0.8'
dockercloud_auth = os.environ.get('DOCKERCLOUD_AUTH')
basic_auth = auth.load_from_file("~/.docker/config.json")

View file

@ -267,7 +267,11 @@ class Triggerable(BasicObject):
class StreamingAPI(BasicObject):
def __init__(self, url):
self._ws_init(url)
def _ws_init(self, url):
self.url = url
user_agent = 'python-dockercloud/%s' % dockercloud.__version__
if dockercloud.user_agent:
user_agent = "%s %s" % (dockercloud.user_agent, user_agent)

View file

@ -21,6 +21,8 @@ class Events(StreamingAPI):
else:
url = "/".join([dockercloud.stream_host.rstrip("/"), "api", "audit", self._api_version,
endpoint.lstrip("/")])
self.invaid_auth_headers = set()
self.auth_error = ""
super(self.__class__, self).__init__(url)
def _on_message(self, ws, message):
@ -37,16 +39,15 @@ class Events(StreamingAPI):
def _on_error(self, ws, e):
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)
def run_forever(self, *args, **kwargs):
while True:
if self.auth_error:
self.auth_error = False
raise AuthError("Not Authorized")
if str(dockercloud.auth.get_auth_header()) in self.invaid_auth_headers:
raise AuthError(self.auth_error)
ws = websocket.WebSocketApp(self.url, header=self.header,
on_open=self._on_open,
on_message=self._on_message,