Documentation
¶
Index ¶
- Constants
- func Init(cfg config.PythonExecutorConfig)
- func IsAvailable(cfg config.PythonExecutorConfig) bool
- type BridgeFactory
- type PythonHealthAdapter
- type StreamManager
- func (sm *StreamManager) Close() error
- func (sm *StreamManager) Connect(ctx context.Context) error
- func (sm *StreamManager) DestroyPolicy(ctx context.Context, req *proto.DestroyPolicyRequest) (*proto.DestroyPolicyResponse, error)
- func (sm *StreamManager) Execute(ctx context.Context, req *proto.StreamRequest) (*proto.StreamResponse, error)
- func (sm *StreamManager) HealthCheck(ctx context.Context) (*proto.HealthCheckResponse, error)
- func (sm *StreamManager) InitPolicy(ctx context.Context, req *proto.InitPolicyRequest) (*proto.InitPolicyResponse, error)
- func (sm *StreamManager) IsConnected() bool
- type Translator
- func (t *Translator) ToGoNeedsMoreDecision(resp *proto.StreamResponse) (bool, error)
- func (t *Translator) ToGoRequestAction(resp *proto.StreamResponse) (policy.RequestAction, error)
- func (t *Translator) ToGoRequestHeaderAction(resp *proto.StreamResponse) (policy.RequestHeaderAction, error)
- func (t *Translator) ToGoResponseAction(resp *proto.StreamResponse) (policy.ResponseAction, error)
- func (t *Translator) ToGoResponseHeaderAction(resp *proto.StreamResponse) (policy.ResponseHeaderAction, error)
- func (t *Translator) ToGoStreamingRequestAction(resp *proto.StreamResponse) (policy.StreamingRequestAction, error)
- func (t *Translator) ToGoStreamingResponseAction(resp *proto.StreamResponse) (policy.StreamingResponseAction, error)
- func (t *Translator) ToProtoBody(body *policy.Body) *proto.Body
- func (t *Translator) ToProtoHeaders(headers *policy.Headers) *proto.Headers
- func (t *Translator) ToProtoSharedContext(shared *policy.SharedContext) (*proto.SharedContext, error)
- func (t *Translator) ToProtoStreamBody(body *policy.StreamBody) *proto.StreamBody
Constants ¶
const DefaultSocketPath = "/var/run/api-platform/python-executor.sock"
Variables ¶
This section is empty.
Functions ¶
func Init ¶
func Init(cfg config.PythonExecutorConfig)
Init configures the Python executor bridge from the loaded configuration. Must be called once from main before GetStreamManager is used.
func IsAvailable ¶
func IsAvailable(cfg config.PythonExecutorConfig) bool
IsAvailable reports whether a Python executor is configured. Returns true if TCP mode is set (always considered available) or the configured UDS socket exists on disk.
Types ¶
type BridgeFactory ¶
BridgeFactory creates Python bridge instances and validates the executor contract. The factory resolves the global StreamManager singleton at GetPolicy call time, which is guaranteed to be configured after pythonbridge.Init(cfg) runs in main().
func (*BridgeFactory) GetPolicy ¶
func (f *BridgeFactory) GetPolicy(metadata policy.PolicyMetadata, params map[string]interface{}) (policy.Policy, error)
GetPolicy creates a Python-backed policy instance.
type PythonHealthAdapter ¶
type PythonHealthAdapter struct {
// contains filtered or unexported fields
}
PythonHealthAdapter implements admin.PythonHealthChecker using the StreamManager.
func NewPythonHealthAdapter ¶
func NewPythonHealthAdapter(sm *StreamManager) *PythonHealthAdapter
NewPythonHealthAdapter creates a PythonHealthAdapter from the given StreamManager.
func (*PythonHealthAdapter) IsPythonHealthy ¶
func (a *PythonHealthAdapter) IsPythonHealthy() (bool, int32, error)
IsPythonHealthy calls the Python executor's HealthCheck RPC.
type StreamManager ¶
type StreamManager struct {
// contains filtered or unexported fields
}
StreamManager manages the persistent bidirectional stream to the Python executor.
func GetStreamManager ¶
func GetStreamManager() *StreamManager
GetStreamManager returns the singleton StreamManager instance.
func NewStreamManager ¶
func NewStreamManager(address string, isTCP bool) *StreamManager
NewStreamManager creates a StreamManager for the given address. If isTCP is true, the address is dialled as TCP (host:port); otherwise it is treated as a Unix domain socket path.
func (*StreamManager) Close ¶
func (sm *StreamManager) Close() error
Close closes the shared stream and connection.
func (*StreamManager) Connect ¶
func (sm *StreamManager) Connect(ctx context.Context) error
Connect establishes the gRPC connection and starts the receive loop.
func (*StreamManager) DestroyPolicy ¶
func (sm *StreamManager) DestroyPolicy(ctx context.Context, req *proto.DestroyPolicyRequest) (*proto.DestroyPolicyResponse, error)
DestroyPolicy destroys a Python policy instance via the unary RPC.
func (*StreamManager) Execute ¶
func (sm *StreamManager) Execute(ctx context.Context, req *proto.StreamRequest) (*proto.StreamResponse, error)
Execute sends a request on the shared stream and waits for its correlated response.
func (*StreamManager) HealthCheck ¶
func (sm *StreamManager) HealthCheck(ctx context.Context) (*proto.HealthCheckResponse, error)
HealthCheck checks Python executor readiness via the unary RPC.
func (*StreamManager) InitPolicy ¶
func (sm *StreamManager) InitPolicy(ctx context.Context, req *proto.InitPolicyRequest) (*proto.InitPolicyResponse, error)
InitPolicy creates a Python policy instance via the unary RPC.
func (*StreamManager) IsConnected ¶
func (sm *StreamManager) IsConnected() bool
IsConnected reports whether the stream is connected and ready.
type Translator ¶
type Translator struct{}
Translator converts between protobuf messages and Go v1alpha2 policy types.
func (*Translator) ToGoNeedsMoreDecision ¶
func (t *Translator) ToGoNeedsMoreDecision(resp *proto.StreamResponse) (bool, error)
ToGoNeedsMoreDecision converts a needs-more response payload into a Go boolean.
func (*Translator) ToGoRequestAction ¶
func (t *Translator) ToGoRequestAction(resp *proto.StreamResponse) (policy.RequestAction, error)
ToGoRequestAction converts a request-body response payload into a Go action.
func (*Translator) ToGoRequestHeaderAction ¶
func (t *Translator) ToGoRequestHeaderAction(resp *proto.StreamResponse) (policy.RequestHeaderAction, error)
ToGoRequestHeaderAction converts a request-header response payload into a Go action.
func (*Translator) ToGoResponseAction ¶
func (t *Translator) ToGoResponseAction(resp *proto.StreamResponse) (policy.ResponseAction, error)
ToGoResponseAction converts a response-body response payload into a Go action.
func (*Translator) ToGoResponseHeaderAction ¶
func (t *Translator) ToGoResponseHeaderAction(resp *proto.StreamResponse) (policy.ResponseHeaderAction, error)
ToGoResponseHeaderAction converts a response-header response payload into a Go action.
func (*Translator) ToGoStreamingRequestAction ¶
func (t *Translator) ToGoStreamingRequestAction(resp *proto.StreamResponse) (policy.StreamingRequestAction, error)
ToGoStreamingRequestAction converts a streaming-request response payload into a Go action.
func (*Translator) ToGoStreamingResponseAction ¶
func (t *Translator) ToGoStreamingResponseAction(resp *proto.StreamResponse) (policy.StreamingResponseAction, error)
ToGoStreamingResponseAction converts a streaming-response response payload into a Go action.
func (*Translator) ToProtoBody ¶
func (t *Translator) ToProtoBody(body *policy.Body) *proto.Body
ToProtoBody converts buffered body data into the transport form.
func (*Translator) ToProtoHeaders ¶
func (t *Translator) ToProtoHeaders(headers *policy.Headers) *proto.Headers
ToProtoHeaders converts read-only Go headers into the multi-value transport form.
func (*Translator) ToProtoSharedContext ¶
func (t *Translator) ToProtoSharedContext(shared *policy.SharedContext) (*proto.SharedContext, error)
ToProtoSharedContext converts a Go SharedContext into the transport form.
func (*Translator) ToProtoStreamBody ¶
func (t *Translator) ToProtoStreamBody(body *policy.StreamBody) *proto.StreamBody
ToProtoStreamBody converts streaming chunk data into the transport form.