Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def channel(self, endpoint):
if not self._channels:
self._unauthenticated_channel = grpc.secure_channel(
self._endpoint, self._channel_creds)
endpoint_service = ApiEndpointServiceStub(
self._unauthenticated_channel)
resp = endpoint_service.List(ListApiEndpointsRequest())
endpoints = resp.endpoints
plugin = _auth_plugin.Credentials(
self._token_requester, lambda: self._channels["iam"])
call_creds = grpc.metadata_call_credentials(plugin)
creds = grpc.composite_channel_credentials(
self._channel_creds, call_creds)
self._channels = {
ep.id: grpc.secure_channel(ep.address, creds)
for ep in endpoints
}
if endpoint not in self._channels:
raise RuntimeError('Unknown endpoint: {}'.format(endpoint))
return self._channels[endpoint]