Merge pull request #19 from docker/not_permanently_cache_invalid_auth_header
CLOUD-3774 not permanently cache invalid auth header
This commit is contained in:
commit
9ffe81583c
2 changed files with 5 additions and 10 deletions
|
|
@ -267,11 +267,7 @@ 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)
|
||||
|
|
|
|||
|
|
@ -21,8 +21,6 @@ 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):
|
||||
|
|
@ -39,15 +37,16 @@ class Events(StreamingAPI):
|
|||
|
||||
def _on_error(self, ws, e):
|
||||
if isinstance(e, websocket._exceptions.WebSocketBadStatusException) and getattr(e, "status_code") == 401:
|
||||
self.auth_error = "Not Authorized"
|
||||
self.invaid_auth_headers.add(str(dockercloud.auth.get_auth_header()))
|
||||
self.auth_error = True
|
||||
|
||||
super(self.__class__, self)._on_error(ws, e)
|
||||
|
||||
def run_forever(self, *args, **kwargs):
|
||||
while True:
|
||||
if str(dockercloud.auth.get_auth_header()) in self.invaid_auth_headers:
|
||||
raise AuthError(self.auth_error)
|
||||
if self.auth_error:
|
||||
self.auth_error = False
|
||||
raise AuthError("Not Authorized")
|
||||
|
||||
ws = websocket.WebSocketApp(self.url, header=self.header,
|
||||
on_open=self._on_open,
|
||||
on_message=self._on_message,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue