How to use the yandexcloud._auth_plugin function in yandexcloud

To help you get started, we’ve selected a few yandexcloud examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yandex-cloud / python-sdk / yandexcloud / _channels.py View on Github external
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]