Newer
Older
cortex-hub / poc-grpc-agent / agent_node / utils / network.py
import grpc
from protos import agent_pb2_grpc
from agent_node.config import SERVER_HOST, SERVER_PORT, CERT_CA, CERT_CLIENT_CRT, CERT_CLIENT_KEY

def get_secure_stub():
    """Initializes a gRPC secure channel and returns the orchestrator stub."""
    with open(CERT_CLIENT_KEY, 'rb') as f: pkey = f.read()
    with open(CERT_CLIENT_CRT, 'rb') as f: cert = f.read()
    with open(CERT_CA, 'rb') as f: ca = f.read()
    
    creds = grpc.ssl_channel_credentials(ca, pkey, cert)
    channel = grpc.secure_channel(f'{SERVER_HOST}:{SERVER_PORT}', creds)
    return agent_pb2_grpc.AgentOrchestratorStub(channel)