nats

package
v0.4.23 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAccessControlChecker

func NewAccessControlChecker(ctx context.Context, config Config) (port.AccessControlChecker, error)

NewAccessControlChecker creates a new NATS access control checker

Types

type AccessCheckNATSRequest

type AccessCheckNATSRequest struct {
	// Subject is the NATS subject for the request
	Subject string `json:"subject"`
	// Message is the serialized request data
	Message []byte `json:"message"`
	// Timeout is the request timeout duration
	Timeout time.Duration `json:"timeout"`
}

AccessCheckNATSRequest represents a NATS request for access checking

type AccessCheckNATSResponse

type AccessCheckNATSResponse map[string]string

AccessCheckNATSResponse represents a NATS response for access checking

type Config

type Config struct {
	// URL is the NATS server URL
	URL string `json:"url"`
	// Timeout is the request timeout duration
	Timeout time.Duration `json:"timeout"`
	// MaxReconnect is the maximum number of reconnection attempts
	MaxReconnect int `json:"max_reconnect"`
	// ReconnectWait is the time to wait between reconnection attempts
	ReconnectWait time.Duration `json:"reconnect_wait"`
}

Config represents NATS configuration

type NATSAccessControlChecker

type NATSAccessControlChecker struct {
	// contains filtered or unexported fields
}

NATSAccessControlChecker implements the AccessControlChecker interface for NATS

func (*NATSAccessControlChecker) CheckAccess

func (n *NATSAccessControlChecker) CheckAccess(ctx context.Context, subj string, data []byte, timeout time.Duration) (model.AccessCheckResult, error)

CheckAccess implements the AccessControlChecker interface

func (*NATSAccessControlChecker) Close

func (n *NATSAccessControlChecker) Close() error

Close gracefully closes the NATS connection

func (*NATSAccessControlChecker) IsReady

func (*NATSAccessControlChecker) ReadTuples added in v0.4.17

func (n *NATSAccessControlChecker) ReadTuples(ctx context.Context, user string, objectType string, timeout time.Duration) ([]string, error)

ReadTuples retrieves the object refs that a user has direct FGA relationships to

type NATSClient

type NATSClient struct {
	// contains filtered or unexported fields
}

NATSClient wraps the NATS connection and provides access control operations

func NewClient

func NewClient(ctx context.Context, config Config) (*NATSClient, error)

NewClient creates a new NATS client with the given configuration

func (*NATSClient) CheckAccess

CheckAccess sends an access control request via NATS and waits for the response

func (*NATSClient) Close

func (c *NATSClient) Close() error

Close gracefully closes the NATS connection

func (*NATSClient) IsReady

func (c *NATSClient) IsReady(ctx context.Context) error

IsReady checks if the NATS client is ready

func (*NATSClient) ReadTuples added in v0.4.17

ReadTuples sends a read_tuples request via NATS and returns the parsed response

type NATSClientInterface

type NATSClientInterface interface {
	CheckAccess(ctx context.Context, request *AccessCheckNATSRequest) (AccessCheckNATSResponse, error)
	ReadTuples(ctx context.Context, request *ReadTuplesNATSRequest) (*ReadTuplesNATSResponse, error)
	Close() error
	IsReady(ctx context.Context) error
}

NATSClientInterface defines the interface for NATS operations This allows for easy mocking and testing

type ReadTuplesNATSRequest added in v0.4.17

type ReadTuplesNATSRequest struct {
	User       string        `json:"user"`
	ObjectType string        `json:"object_type"`
	Timeout    time.Duration `json:"-"`
}

ReadTuplesNATSRequest represents a NATS request for reading FGA tuples

type ReadTuplesNATSResponse added in v0.4.17

type ReadTuplesNATSResponse struct {
	Results []string `json:"results"`
	Error   string   `json:"error,omitempty"`
}

ReadTuplesNATSResponse represents a NATS response for reading FGA tuples

Jump to

Keyboard shortcuts

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