mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-14 11:03:53 +00:00
30 lines
729 B
Python
30 lines
729 B
Python
import os
|
|
|
|
import grpc
|
|
|
|
|
|
def read_binary(f):
|
|
with open(f, 'rb') as fp:
|
|
return fp.read()
|
|
|
|
|
|
def get_grpc_cert_file_from_env():
|
|
cert_file = os.environ.get('BBGO_GRPC_CERT_FILE')
|
|
return cert_file
|
|
|
|
|
|
def get_grpc_key_file_from_env():
|
|
key_file = os.environ.get('BBGO_GRPC_KEY_FILE')
|
|
return key_file
|
|
|
|
|
|
def get_credentials_from_env():
|
|
key_file = get_grpc_key_file_from_env()
|
|
private_key = read_binary(key_file)
|
|
cert_file = get_grpc_cert_file_from_env()
|
|
certificate_chain = read_binary(cert_file)
|
|
|
|
private_key_certificate_chain_pairs = [(private_key, certificate_chain)]
|
|
server_credentials = grpc.ssl_server_credentials(private_key_certificate_chain_pairs)
|
|
return server_credentials
|