Skip to content
Snippets Groups Projects

Add plugin `Api-Key` for auth

Merged Andrei Biriukov requested to merge feature/add_auth_api_key_plugin into master
2 files
+ 42
0
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 29
0
 
import logging
 
 
import grpc
 
 
from perxis.auth import APIKeyPlugin
 
from perxis.collections import collections_pb2_grpc, collections_pb2
 
 
API_KEY = '0Xp7bYBqYmIUqwZcNRMtRCtDBaheFdAc'
 
SPACE_ID = 'c2qcp9cuaccmpj8lmom0'
 
ENV_ID = 'master'
 
TARGET = 'envoy.perxis.pt.perx.ru:443'
 
 
 
def main():
 
api_key_plugin = APIKeyPlugin(API_KEY)
 
call_credentials = grpc.metadata_call_credentials(api_key_plugin, name='api-key')
 
channel_credentials = grpc.ssl_channel_credentials()
 
composite_credentials = grpc.composite_channel_credentials(
 
channel_credentials, call_credentials
 
)
 
with grpc.secure_channel(TARGET, composite_credentials) as channel:
 
stub = collections_pb2_grpc.CollectionsStub(channel)
 
collections = stub.List(collections_pb2.ListRequest(space_id=SPACE_ID, env_id=ENV_ID))
 
print(collections)
 
 
 
if __name__ == '__main__':
 
logging.basicConfig(level=logging.INFO)
 
main()
Loading