pythonbridge

package
v0.0.0-...-bf5d939 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
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

type BridgeFactory struct {
	PolicyName    string
	PolicyVersion string
}

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

DestroyPolicy destroys a Python policy instance via the unary RPC.

func (*StreamManager) Execute

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

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 NewTranslator

func NewTranslator() *Translator

NewTranslator creates a new Translator.

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL