Skip to content

Commit

Permalink
Merge pull request #17 from mailgun/thrawn/develop
Browse files Browse the repository at this point in the history
PIP-711: Skip auth if disabled
  • Loading branch information
thrawn01 authored Jan 15, 2020
2 parents 8008684 + 0cd445d commit 0463547
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
19 changes: 12 additions & 7 deletions etcd3/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,15 @@ def _dial(self, endpoint):
if not self._tls_creds:
return grpc.insecure_channel(endpoint)

creds = self._tls_creds

if self._auth_rq:
token = self._authenticate(endpoint)
token_plugin = _TokenAuthMetadataPlugin(token)
token_creds = grpc.metadata_call_credentials(token_plugin)
creds = grpc.composite_channel_credentials(self._tls_creds,
token_creds)
else:
creds = self._tls_creds
if token:
token_plugin = _TokenAuthMetadataPlugin(token)
token_creds = grpc.metadata_call_credentials(token_plugin)
creds = grpc.composite_channel_credentials(self._tls_creds,
token_creds)

return grpc.secure_channel(endpoint, creds)

Expand All @@ -218,7 +219,11 @@ def _authenticate(self, endpoint):
auth_stub = AuthStub(grpc_channel)
rs = auth_stub.Authenticate(self._auth_rq, timeout=self._timeout)
return rs.token

except grpc.RpcError as e:
if "authentication is not enabled" in e.details():
_log.error("server authentication disabled; skipping")
return None
raise
finally:
grpc_channel.close()

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
],
install_requires=[
'enum34;python_version<"3.4"',
'grpcio',
'protobuf',
'grpcio==1.20.1',
'protobuf==3.7.1',
'six'
])

0 comments on commit 0463547

Please sign in to comment.