atkafka

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: MIT Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultClientID = "go-bus-producer"
	ModeAsync       = "async"
	ModeSync        = "sync"
)
View Source
const (
	DefaultPLCHost = "https://plc.directory"
)

Variables

View Source
var ErrAuditLogNotFound = errors.New("audit log not found for DID")

Functions

This section is empty.

Types

type ApiClient added in v0.1.1

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

func NewApiClient added in v0.1.1

func NewApiClient(args *ApiClientArgs) (*ApiClient, error)

func (*ApiClient) BustProfileCache added in v0.1.1

func (pc *ApiClient) BustProfileCache(did string) bool

func (*ApiClient) GetProfile added in v0.1.1

type ApiClientArgs added in v0.1.1

type ApiClientArgs struct {
	ApiHost string
}

type AtKafkaAccount

type AtKafkaAccount struct {
	Active bool    `json:"active"`
	Seq    int64   `json:"seq"`
	Status *string `json:"status,omitempty"`
}

type AtKafkaEvent

type AtKafkaEvent struct {
	Did       string         `json:"did"`
	Timestamp string         `json:"timestamp"`
	Metadata  *EventMetadata `json:"eventMetadata"`

	Operation *AtKafkaOp       `json:"operation,omitempty"`
	Account   *AtKafkaAccount  `json:"account,omitempty"`
	Identity  *AtKafkaIdentity `json:"identity,omitempty"`
	Info      *AtKafkaInfo     `json:"info,omitempty"`
}

type AtKafkaIdentity

type AtKafkaIdentity struct {
	Seq    int64  `json:"seq"`
	Handle string `json:"handle"`
}

type AtKafkaInfo

type AtKafkaInfo struct {
	Name    string  `json:"name"`
	Message *string `json:"message,omitempty"`
}

type AtKafkaOp

type AtKafkaOp struct {
	Action     string         `json:"action"`
	Collection string         `json:"collection"`
	Rkey       string         `json:"rkey"`
	Uri        string         `json:"uri"`
	Cid        string         `json:"cid"`
	Path       string         `json:"path"`
	Record     map[string]any `json:"record"`
}

type DidAuditEntry

type DidAuditEntry struct {
	Did       string      `json:"did"`
	Operation DidLogEntry `json:"operation"`
	Cid       string      `json:"cid"`
	Nullified bool        `json:"nullified"`
	CreatedAt string      `json:"createdAt"`
}

type DidAuditLog

type DidAuditLog []DidAuditEntry

type DidLogEntry

type DidLogEntry struct {
	Sig                 string                      `json:"sig"`
	Prev                *string                     `json:"prev"`
	Type                string                      `json:"type"`
	Services            map[string]OperationService `json:"services"`
	AlsoKnownAs         []string                    `json:"alsoKnownAs"`
	RotationKeys        []string                    `json:"rotationKeys"`
	VerificationMethods map[string]string           `json:"verificationMethods"`
}

type EventMetadata

type EventMetadata struct {
	DidDocument  identity.DIDDocument                `json:"didDocument,omitempty"`
	PdsHost      string                              `json:"pdsHost,omitempty"`
	Handle       string                              `json:"handle,omitempty"`
	DidCreatedAt string                              `json:"didCreatedAt,omitempty"`
	AccountAge   int64                               `json:"accountAge"`
	Profile      *bsky.ActorDefs_ProfileViewDetailed `json:"profile"`
}

type IdentityResolver added in v0.2.1

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

func NewIdentityResolver added in v0.2.1

func NewIdentityResolver(args *IdentityResolverArgs) *IdentityResolver

func (*IdentityResolver) GetDIDAuditLog added in v0.2.1

func (c *IdentityResolver) GetDIDAuditLog(ctx context.Context, did syntax.DID) (*DidAuditEntry, error)

func (*IdentityResolver) GetIdentity added in v0.2.1

func (c *IdentityResolver) GetIdentity(ctx context.Context, did syntax.DID) (*identity.Identity, error)

type IdentityResolverArgs added in v0.2.1

type IdentityResolverArgs struct {
	PlcHost string
}

type OperationService

type OperationService struct {
	Type     string `json:"type"`
	Endpoint string `json:"endpoint"`
}

type OspreyAtKafkaEvent

type OspreyAtKafkaEvent struct {
	Data     OspreyEventData `json:"data"`
	SendTime string          `json:"send_time"`
}

type OspreyEventData

type OspreyEventData struct {
	ActionName string            `json:"action_name"`
	ActionId   int64             `json:"action_id"`
	Data       AtKafkaEvent      `json:"data"`
	Timestamp  string            `json:"timestamp"`
	SecretData map[string]string `json:"secret_data"`
	Encoding   string            `json:"encoding"`
}

Intentionally using snake case since that is what Osprey expects

type OzoneClient added in v0.2.0

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

func NewOzoneClient added in v0.2.0

func NewOzoneClient(args *OzoneClientArgs) (*OzoneClient, error)

func (*OzoneClient) GetEvents added in v0.2.0

func (oc *OzoneClient) GetEvents(ctx context.Context, before string) (*string, []*ozone.ModerationDefs_ModEventView, error)

type OzoneClientArgs added in v0.2.0

type OzoneClientArgs struct {
	OzonePdsHost    string
	OzoneIdentifier string
	OzonePassword   string
	OzoneLabelerDid string
	Logger          *slog.Logger
}

type OzoneServer added in v0.2.0

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

func NewOzoneServer added in v0.2.0

func NewOzoneServer(args *OzoneServerArgs) (*OzoneServer, error)

func (*OzoneServer) GetCursor added in v0.2.0

func (s *OzoneServer) GetCursor() string

func (*OzoneServer) LoadCursor added in v0.2.0

func (s *OzoneServer) LoadCursor() error

func (*OzoneServer) Run added in v0.2.0

func (s *OzoneServer) Run(ctx context.Context) error

func (*OzoneServer) UpdateCursor added in v0.2.0

func (s *OzoneServer) UpdateCursor(cursor string) error

type OzoneServerArgs added in v0.2.0

type OzoneServerArgs struct {
	BootstrapServers []string
	OutputTopic      string
	Logger           *slog.Logger
	OzoneClientArgs  *OzoneClientArgs
}

type Producer

type Producer struct {

	// Close the producer and flush any async writes.
	// We can safely call this concurrently and multiple times, as it uses a sync.Once to ensure the client is only flushed and closed once.
	Close func()
	// contains filtered or unexported fields
}

Producer is an example producer to a given topic using given Protobuf message type.

A Producer takes a Kafka client and a topic, and sends one of two types of data:

  • A Protobuf message of the given type.
  • Invalid data that could not be parsed as any Protobuf message.

func NewProducer

func NewProducer(
	ctx context.Context,
	logger *slog.Logger,
	bootstrapServers []string,
	topic string,
	options ...ProducerOption,
) (*Producer, error)

New returns a new Producer.

Always use this constructor to construct Producers.

func (*Producer) ProduceAsync

func (p *Producer) ProduceAsync(ctx context.Context, key string, message []byte, cb func(r *kgo.Record, err error)) error

ProduceAsync asynchronously sends the given message to the Producer's topic with the given partition key. This should return immediately, and the message will be sent in the background. Errors returned from this method are only related to serialization issues.

func (*Producer) ProduceSync

func (p *Producer) ProduceSync(ctx context.Context, key string, message []byte) error

ProduceSync serializes the given Protobuf messages, and synchronously sends it to the Producer's topic with the given partition key. This will block until the message is sent or an error occurs.

type ProducerOption

type ProducerOption func(*Producer)

ProducerOption is an option when constructing a new Producer.

All parameters except options are required. ProducerOptions allow for optional parameters.

func WithClient

func WithClient(client *kgo.Client) ProducerOption

WithClient allows initializing the producer with the specified Kafka client. This overrides the provided topic configuration and partitions.

func WithCredentials

func WithCredentials(username, password string) ProducerOption

WithCredentials sets the SASL username and password for the producer.

func WithEnsureTopic

func WithEnsureTopic(ensure bool) ProducerOption

WithEnsureTopic allows setting whether to ensure the topic exists before producing messages. If true, the producer will attempt to create the topic if it does not exist.

func WithHostOverride

func WithHostOverride(host string) ProducerOption

WithHostOverride returns a new Producer Option that overrides the default broker host This allows us to connect to the Kafka broker using a different hostname than what the broker advertises.

func WithInfiniteRetention

func WithInfiniteRetention() ProducerOption

WithInfiniteRetention allows setting the topic to have infinite retention time. By default Topics have a retention time of 7 days and infinite retention bytes.

func WithMaxMessageBytes

func WithMaxMessageBytes(bytes int) ProducerOption

WithMaxMessageBytes allows setting the maximum message size for the topic. Default is 1MB (1048576 bytes).

func WithReplicationFactor

func WithReplicationFactor(replicationFactor int) ProducerOption

WithReplicationFactor allows setting the replication factor for the topic.

func WithRetentionBytes

func WithRetentionBytes(bytes int) ProducerOption

WithRetentionBytes allows setting the retention bytes for the topic.

func WithRetentionTime

func WithRetentionTime(duration time.Duration) ProducerOption

WithRetentionTime allows setting the retention time for the topic (to millisecond precision).

func WithTopicConfig

func WithTopicConfig(config ...string) ProducerOption

WithTopicConfig allows setting topic configuration options for the producer.

func WithTopicPartitions

func WithTopicPartitions(partitions int) ProducerOption

WithTopicPartitions allows setting the number of partitions for the topic.

type Server

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

func NewServer

func NewServer(args *ServerArgs) (*Server, error)

func (*Server) FetchEventMetadata

func (s *Server) FetchEventMetadata(ctx context.Context, did syntax.DID) (*EventMetadata, *identity.Identity, error)

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

func (*Server) RunTapMode added in v0.2.0

func (s *Server) RunTapMode(ctx context.Context) error

type ServerArgs

type ServerArgs struct {
	// network params
	RelayHost   string
	TapHost     string
	TapWorkers  int
	DisableAcks bool
	PlcHost     string
	ApiHost     string

	// list of services that are events will be emitted for
	WatchedServices []string
	// list of services that events are ignored for
	IgnoredServices []string

	// list of collections that events are emitted for
	WatchedCollections []string
	// list of collections that events are ignored for
	IgnoredCollections []string

	// kafka params
	BootstrapServers []string
	OutputTopic      string

	// osprey-specific params
	OspreyCompat bool

	// other
	Logger *slog.Logger
}

type TapAck added in v0.2.0

type TapAck struct {
	Type string `json:"type"`
	Id   uint   `json:"id"`
}

type TapEvent added in v0.2.0

type TapEvent struct {
	Id       uint              `json:"id"`
	Type     string            `json:"type"`
	Record   *TapEventRecord   `json:"record,omitempty"`
	Identity *TapEventIdentity `json:"identity,omitempty"`
}

type TapEventIdentity added in v0.2.0

type TapEventIdentity struct {
	Did      string `json:"did"`
	Handle   string `json:"handle"`
	IsActive bool   `json:"isActive"`
	Status   string `json:"status"`
}

type TapEventRecord added in v0.2.0

type TapEventRecord struct {
	Live       bool            `json:"live"`
	Rev        string          `json:"rev"`
	Did        string          `json:"did"`
	Collection string          `json:"collection"`
	Rkey       string          `json:"rkey"`
	Action     string          `json:"action"`
	Cid        string          `json:"cid"`
	Record     *map[string]any `json:"record,omitempty"`
}

Jump to

Keyboard shortcuts

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