Documentation
¶
Index ¶
- Constants
- Variables
- type APIKeyIssued
- type APIKeyRevoked
- type Event
- type EventAction
- type EventHandler
- type GroupCreated
- type GroupMembershipCreated
- type GroupMembershipRemoved
- type GroupMembershipUpdated
- type GroupRemoved
- type GroupUpdated
- type OrgCreated
- type OrgInviteAccepted
- type OrgInviteCreated
- type OrgInviteDeclined
- type OrgInviteRevoked
- type OrgMembershipCreated
- type OrgMembershipRemoved
- type OrgMembershipUpdated
- type OrgRemoved
- type OrgUpdated
- type PlatformInviteCreated
- type PlatformInviteRevoked
- type ProfileCreated
- type ProfileRemoved
- type ProfileUpdated
- type Publisher
- type PublisherConfig
- type SessionLoggedOutAll
- type Subscriber
- type SubscriberConfig
- type ThingCreated
- type ThingExternalKeyRemoved
- type ThingExternalKeyUpdated
- type ThingGroupAndProfileUpdated
- type ThingMetadataUpdated
- type ThingRemoved
- type ThingUpdated
- type UserAdminRoleAssigned
- type UserAdminRoleUnassigned
- type UserDisabled
- type UserEnabled
- type UserImpersonated
- type UserLoggedIn
- type UserLoginFailed
- type UserPasswordChanged
- type UserPasswordReset
- type UserRegistered
- type UserUpdated
Constants ¶
const ( // DefStreamMaxLen is the default approx number of messages in the Redis event stream. DefStreamMaxLen = 100000 // DefBufferSize is the default capacity of the publish // buffer channel. DefBufferSize = 10000 // DefDrainInitialInterval is the initial sleep duration between XADD retries when // emitting an event fails. DefDrainInitialInterval = time.Second // DefDrainMaxBackoff is the maximum backoff duration between XADD retries. DefDrainMaxBackoff = 30 * time.Second // DefShutdownDrainTimeout is the maximum duration that Close() can spends trying to drain // the remaining buffered events. DefShutdownDrainTimeout = 5 * time.Second )
const ( // Event operation strings ThingCreate = thingPrefix + "create" ThingUpdate = thingPrefix + "update" ThingUpdateGroupAndProfile = thingPrefix + "update_group_and_profile" ThingUpdateMetadata = thingPrefix + "update_metadata" ThingUpdateExternalKey = thingPrefix + "update_external_key" ThingRemoveExternalKey = thingPrefix + "remove_external_key" ThingRemove = thingPrefix + "remove" ProfileCreate = profilePrefix + "create" ProfileUpdate = profilePrefix + "update" ProfileRemove = profilePrefix + "remove" GroupCreate = groupPrefix + "create" GroupUpdate = groupPrefix + "update" GroupRemove = groupPrefix + "remove" GroupMembershipCreate = groupMembershipPrefix + "create" GroupMembershipUpdate = groupMembershipPrefix + "update" GroupMembershipRemove = groupMembershipPrefix + "remove" OrgCreate = orgPrefix + "create" OrgUpdate = orgPrefix + "update" OrgRemove = orgPrefix + "remove" OrgMembershipCreate = orgMembershipPrefix + "create" OrgMembershipUpdate = orgMembershipPrefix + "update" OrgMembershipRemove = orgMembershipPrefix + "remove" OrgInviteCreate = orgInvitePrefix + "create" OrgInviteRevoke = orgInvitePrefix + "revoke" OrgInviteAccept = orgInvitePrefix + "accept" OrgInviteDecline = orgInvitePrefix + "decline" APIKeyIssue = apiKeyPrefix + "issue" APIKeyRevoke = apiKeyPrefix + "revoke" SessionLogoutAll = sessionPrefix + "logout_all" UserRegister = userPrefix + "register" UserLogin = userPrefix + "login" UserLoginFail = userPrefix + "login_fail" UserUpdate = userPrefix + "update" UserChangePassword = userPrefix + "change_password" UserResetPassword = userPrefix + "reset_password" UserEnable = userPrefix + "enable" UserDisable = userPrefix + "disable" UserAssignAdminRole = userPrefix + "assign_admin_role" UserUnassignAdminRole = userPrefix + "unassign_admin_role" UserImpersonate = userPrefix + "impersonate" PlatformInviteCreate = platformInvitePrefix + "create" PlatformInviteRevoke = platformInvitePrefix + "revoke" // Redis event streams ThingsStream = mainfluxPrefix + "things" AuthStream = mainfluxPrefix + "auth" UsersStream = mainfluxPrefix + "users" )
Variables ¶
var ( // ErrEmptyStream is returned when stream name is empty. ErrEmptyStream = errors.New("stream name cannot be empty") // ErrEmptyName is returned when the subscriber name is empty. ErrEmptyName = errors.New("subscriber name cannot be empty") )
Functions ¶
This section is empty.
Types ¶
type APIKeyIssued ¶ added in v0.46.0
APIKeyIssued signals that a user issued an API key, without the key secret.
func (APIKeyIssued) Encode ¶ added in v0.46.0
func (e APIKeyIssued) Encode() map[string]any
func (APIKeyIssued) Operation ¶ added in v0.46.0
func (e APIKeyIssued) Operation() string
type APIKeyRevoked ¶ added in v0.46.0
type APIKeyRevoked struct {
ID string
}
APIKeyRevoked signals that a user revoked an API key.
func (APIKeyRevoked) Encode ¶ added in v0.46.0
func (e APIKeyRevoked) Encode() map[string]any
func (APIKeyRevoked) Operation ¶ added in v0.46.0
func (e APIKeyRevoked) Operation() string
type Event ¶
type Event struct {
// The specific EventAction that occurred.
Action EventAction
// The identity of the user whose action triggered the event.
JWTUserIdentity domain.Identity
// The ID of the organization to which the event belongs. May be empty.
OrgID string
// The ID of the group to which the event belongs. May be empty.
GroupID string
OccurredAt time.Time
}
Event is the type representing a platform event.
type EventAction ¶ added in v0.41.0
type EventAction interface {
// Encode returns a map representation of the event action.
Encode() map[string]any
// Operation returns the string representation of the event action operation.
Operation() string
}
EventAction represents an action occurring on the platform.
type EventHandler ¶
EventHandler reacts to a single event delivered by a Subscriber.
type GroupCreated ¶ added in v0.46.0
GroupCreated signals the creation of a group.
func (GroupCreated) Encode ¶ added in v0.46.0
func (e GroupCreated) Encode() map[string]any
func (GroupCreated) Operation ¶ added in v0.46.0
func (e GroupCreated) Operation() string
type GroupMembershipCreated ¶ added in v0.46.0
GroupMembershipCreated signals that a member was added to a group.
func (GroupMembershipCreated) Encode ¶ added in v0.46.0
func (e GroupMembershipCreated) Encode() map[string]any
func (GroupMembershipCreated) Operation ¶ added in v0.46.0
func (e GroupMembershipCreated) Operation() string
type GroupMembershipRemoved ¶ added in v0.46.0
GroupMembershipRemoved signals that a member was removed from a group.
func (GroupMembershipRemoved) Encode ¶ added in v0.46.0
func (e GroupMembershipRemoved) Encode() map[string]any
func (GroupMembershipRemoved) Operation ¶ added in v0.46.0
func (e GroupMembershipRemoved) Operation() string
type GroupMembershipUpdated ¶ added in v0.46.0
GroupMembershipUpdated signals that a group member's role was changed.
func (GroupMembershipUpdated) Encode ¶ added in v0.46.0
func (e GroupMembershipUpdated) Encode() map[string]any
func (GroupMembershipUpdated) Operation ¶ added in v0.46.0
func (e GroupMembershipUpdated) Operation() string
type GroupRemoved ¶ added in v0.41.0
GroupRemoved signals that a group has been removed.
func (GroupRemoved) Encode ¶ added in v0.41.0
func (e GroupRemoved) Encode() map[string]any
func (GroupRemoved) Operation ¶ added in v0.41.0
func (e GroupRemoved) Operation() string
type GroupUpdated ¶ added in v0.46.0
GroupUpdated signals a group update.
func (GroupUpdated) Encode ¶ added in v0.46.0
func (e GroupUpdated) Encode() map[string]any
func (GroupUpdated) Operation ¶ added in v0.46.0
func (e GroupUpdated) Operation() string
type OrgCreated ¶ added in v0.41.0
type OrgCreated struct {
ID string
}
OrgCreated signals the creation of an organization.
func (OrgCreated) Encode ¶ added in v0.41.0
func (e OrgCreated) Encode() map[string]any
func (OrgCreated) Operation ¶ added in v0.41.0
func (e OrgCreated) Operation() string
type OrgInviteAccepted ¶ added in v0.46.0
type OrgInviteAccepted struct {
ID string
}
OrgInviteAccepted signals that an organization invite was accepted by its invitee.
func (OrgInviteAccepted) Encode ¶ added in v0.46.0
func (e OrgInviteAccepted) Encode() map[string]any
func (OrgInviteAccepted) Operation ¶ added in v0.46.0
func (e OrgInviteAccepted) Operation() string
type OrgInviteCreated ¶ added in v0.46.0
type OrgInviteCreated struct {
ID string
InviteeID string
InviteeEmail string
InviteeRole string
GroupInvites []domain.GroupInvite
}
OrgInviteCreated signals that a user was invited to an organization.
func (OrgInviteCreated) Encode ¶ added in v0.46.0
func (e OrgInviteCreated) Encode() map[string]any
func (OrgInviteCreated) Operation ¶ added in v0.46.0
func (e OrgInviteCreated) Operation() string
type OrgInviteDeclined ¶ added in v0.46.0
type OrgInviteDeclined struct {
ID string
}
OrgInviteDeclined signals that an organization invite was declined by its invitee.
func (OrgInviteDeclined) Encode ¶ added in v0.46.0
func (e OrgInviteDeclined) Encode() map[string]any
func (OrgInviteDeclined) Operation ¶ added in v0.46.0
func (e OrgInviteDeclined) Operation() string
type OrgInviteRevoked ¶ added in v0.46.0
type OrgInviteRevoked struct {
ID string
}
OrgInviteRevoked signals that an organization invite was revoked by its inviter.
func (OrgInviteRevoked) Encode ¶ added in v0.46.0
func (e OrgInviteRevoked) Encode() map[string]any
func (OrgInviteRevoked) Operation ¶ added in v0.46.0
func (e OrgInviteRevoked) Operation() string
type OrgMembershipCreated ¶ added in v0.46.0
OrgMembershipCreated signals that a member was added to an organization.
func (OrgMembershipCreated) Encode ¶ added in v0.46.0
func (e OrgMembershipCreated) Encode() map[string]any
func (OrgMembershipCreated) Operation ¶ added in v0.46.0
func (e OrgMembershipCreated) Operation() string
type OrgMembershipRemoved ¶ added in v0.46.0
OrgMembershipRemoved signals that a member was removed from an organization.
func (OrgMembershipRemoved) Encode ¶ added in v0.46.0
func (e OrgMembershipRemoved) Encode() map[string]any
func (OrgMembershipRemoved) Operation ¶ added in v0.46.0
func (e OrgMembershipRemoved) Operation() string
type OrgMembershipUpdated ¶ added in v0.46.0
OrgMembershipUpdated signals that an organization member's role was changed.
func (OrgMembershipUpdated) Encode ¶ added in v0.46.0
func (e OrgMembershipUpdated) Encode() map[string]any
func (OrgMembershipUpdated) Operation ¶ added in v0.46.0
func (e OrgMembershipUpdated) Operation() string
type OrgRemoved ¶ added in v0.41.0
type OrgRemoved struct {
ID string
}
OrgRemoved signals that an organization has been removed.
func (OrgRemoved) Encode ¶ added in v0.41.0
func (e OrgRemoved) Encode() map[string]any
func (OrgRemoved) Operation ¶ added in v0.41.0
func (e OrgRemoved) Operation() string
type OrgUpdated ¶ added in v0.46.0
OrgUpdated signals an organization update.
func (OrgUpdated) Encode ¶ added in v0.46.0
func (e OrgUpdated) Encode() map[string]any
func (OrgUpdated) Operation ¶ added in v0.46.0
func (e OrgUpdated) Operation() string
type PlatformInviteCreated ¶ added in v0.46.0
PlatformInviteCreated signals that a person was invited to register on the platform.
func (PlatformInviteCreated) Encode ¶ added in v0.46.0
func (e PlatformInviteCreated) Encode() map[string]any
func (PlatformInviteCreated) Operation ¶ added in v0.46.0
func (e PlatformInviteCreated) Operation() string
type PlatformInviteRevoked ¶ added in v0.46.0
type PlatformInviteRevoked struct {
ID string
}
PlatformInviteRevoked signals that a platform owner or admin revoked a platform invite.
func (PlatformInviteRevoked) Encode ¶ added in v0.46.0
func (e PlatformInviteRevoked) Encode() map[string]any
func (PlatformInviteRevoked) Operation ¶ added in v0.46.0
func (e PlatformInviteRevoked) Operation() string
type ProfileCreated ¶ added in v0.41.0
ProfileCreated signals the creation of a profile.
func (ProfileCreated) Encode ¶ added in v0.41.0
func (e ProfileCreated) Encode() map[string]any
func (ProfileCreated) Operation ¶ added in v0.41.0
func (e ProfileCreated) Operation() string
type ProfileRemoved ¶ added in v0.41.0
type ProfileRemoved struct {
ID string
}
ProfileRemoved signals that a profile has been removed.
func (ProfileRemoved) Encode ¶ added in v0.41.0
func (e ProfileRemoved) Encode() map[string]any
func (ProfileRemoved) Operation ¶ added in v0.41.0
func (e ProfileRemoved) Operation() string
type ProfileUpdated ¶ added in v0.41.0
type ProfileUpdated struct {
ID string
Name string
Config *domain.ProfileConfig
Metadata map[string]any
}
ProfileUpdated signals a profile update.
func (ProfileUpdated) Encode ¶ added in v0.41.0
func (e ProfileUpdated) Encode() map[string]any
func (ProfileUpdated) Operation ¶ added in v0.41.0
func (e ProfileUpdated) Operation() string
type Publisher ¶ added in v0.41.0
type Publisher interface {
// Publish queues the passed event for delivery by sending it to the buffer
// channel. It's asynchronous, meaning that it doesn't block the caller
// and as such returns no errors. If the underlying event buffer is full,
// the oldest queued event is dropped to make space.
Publish(ctx context.Context, e Event)
// Close stops the event drainer goroutine, attempts a final drain,
// and closes the underlying Redis client.
Close() error
}
Publisher delivers Events to the Redis event store asynchronously. It uses an in-memory buffer to queue and retry failed events.
func NewPublisher ¶ added in v0.41.0
func NewPublisher(cfg PublisherConfig, log logger.Logger) (Publisher, error)
NewPublisher returns a Publisher that buffers events in process and drains them to Redis in the background.
type PublisherConfig ¶ added in v0.41.0
type PublisherConfig struct {
URL string
Stream string
// MaxLen is the approximate stream retention (XADD MAXLEN ~).
MaxLen int64
// BufferSize is the capacity of the buffer channel holding events.
BufferSize int
// DrainInitialInterval is the initial XADD retry sleep on failure.
DrainInitialInterval time.Duration
// DrainMaxBackoff caps the exponential retry backoff.
DrainMaxBackoff time.Duration
// ShutdownDrainTimeout bounds the final drain in Close().
ShutdownDrainTimeout time.Duration
}
type SessionLoggedOutAll ¶ added in v0.46.0
type SessionLoggedOutAll struct{}
SessionLoggedOutAll signals that a user ended all of their sessions.
func (SessionLoggedOutAll) Encode ¶ added in v0.46.0
func (e SessionLoggedOutAll) Encode() map[string]any
func (SessionLoggedOutAll) Operation ¶ added in v0.46.0
func (e SessionLoggedOutAll) Operation() string
type Subscriber ¶
type Subscriber interface {
// Subscribe subscribes to the event stream and consumes events.
Subscribe(ctx context.Context, handler EventHandler) error
// Close gracefully closes event subscriber's connection.
Close() error
}
Subscriber specifies event subscription API.
func NewSubscriber ¶ added in v0.34.0
func NewSubscriber(cfg SubscriberConfig, log logger.Logger) (Subscriber, error)
NewSubscriber returns a Subscriber that reads from a Redis stream using XRead and tracks its position via a per-subscriber Redis key.
type SubscriberConfig ¶ added in v0.41.0
type SubscriberConfig struct {
// URL is the Redis connection URL (e.g. redis://host:6379/0).
URL string
// Stream is the name of the Redis stream to read from.
Stream string
// Name identifies this subscriber. Used in the cursor key so
// independent subscribers maintain independent cursors on the same
// stream.
Name string
}
SubscriberConfig holds the parameters for creating a Subscriber.
type ThingCreated ¶ added in v0.41.0
type ThingCreated struct {
ID string
GroupID string
ProfileID string
Name string
Metadata map[string]any
}
ThingCreated signals the creation of a thing.
func (ThingCreated) Encode ¶ added in v0.41.0
func (e ThingCreated) Encode() map[string]any
func (ThingCreated) Operation ¶ added in v0.41.0
func (e ThingCreated) Operation() string
type ThingExternalKeyRemoved ¶ added in v0.46.0
type ThingExternalKeyRemoved struct {
ID string
}
ThingExternalKeyRemoved signals that a thing's external key was removed.
func (ThingExternalKeyRemoved) Encode ¶ added in v0.46.0
func (e ThingExternalKeyRemoved) Encode() map[string]any
func (ThingExternalKeyRemoved) Operation ¶ added in v0.46.0
func (e ThingExternalKeyRemoved) Operation() string
type ThingExternalKeyUpdated ¶ added in v0.46.0
type ThingExternalKeyUpdated struct {
ID string
}
ThingExternalKeyUpdated signals that a thing's external key was set, without the key itself.
func (ThingExternalKeyUpdated) Encode ¶ added in v0.46.0
func (e ThingExternalKeyUpdated) Encode() map[string]any
func (ThingExternalKeyUpdated) Operation ¶ added in v0.46.0
func (e ThingExternalKeyUpdated) Operation() string
type ThingGroupAndProfileUpdated ¶ added in v0.41.0
ThingGroupAndProfileUpdated signals a thing's group/profile reassignment.
func (ThingGroupAndProfileUpdated) Encode ¶ added in v0.41.0
func (e ThingGroupAndProfileUpdated) Encode() map[string]any
func (ThingGroupAndProfileUpdated) Operation ¶ added in v0.41.0
func (e ThingGroupAndProfileUpdated) Operation() string
type ThingMetadataUpdated ¶ added in v0.46.0
ThingMetadataUpdated signals a merge of metadata keys into a thing's metadata.
func (ThingMetadataUpdated) Encode ¶ added in v0.46.0
func (e ThingMetadataUpdated) Encode() map[string]any
func (ThingMetadataUpdated) Operation ¶ added in v0.46.0
func (e ThingMetadataUpdated) Operation() string
type ThingRemoved ¶ added in v0.41.0
type ThingRemoved struct {
ID string
}
ThingRemoved signals that a thing has been removed.
func (ThingRemoved) Encode ¶ added in v0.41.0
func (e ThingRemoved) Encode() map[string]any
func (ThingRemoved) Operation ¶ added in v0.41.0
func (e ThingRemoved) Operation() string
type ThingUpdated ¶ added in v0.41.0
ThingUpdated signals a thing update.
func (ThingUpdated) Encode ¶ added in v0.41.0
func (e ThingUpdated) Encode() map[string]any
func (ThingUpdated) Operation ¶ added in v0.41.0
func (e ThingUpdated) Operation() string
type UserAdminRoleAssigned ¶ added in v0.46.0
type UserAdminRoleAssigned struct {
ID string
}
UserAdminRoleAssigned signals that the platform owner assigned the platform admin role to a user.
func (UserAdminRoleAssigned) Encode ¶ added in v0.46.0
func (e UserAdminRoleAssigned) Encode() map[string]any
func (UserAdminRoleAssigned) Operation ¶ added in v0.46.0
func (e UserAdminRoleAssigned) Operation() string
type UserAdminRoleUnassigned ¶ added in v0.46.0
type UserAdminRoleUnassigned struct {
ID string
}
UserAdminRoleUnassigned signals that the platform owner removed the platform admin role from a user.
func (UserAdminRoleUnassigned) Encode ¶ added in v0.46.0
func (e UserAdminRoleUnassigned) Encode() map[string]any
func (UserAdminRoleUnassigned) Operation ¶ added in v0.46.0
func (e UserAdminRoleUnassigned) Operation() string
type UserDisabled ¶ added in v0.46.0
type UserDisabled struct {
ID string
}
UserDisabled signals that a platform owner or admin disabled a user.
func (UserDisabled) Encode ¶ added in v0.46.0
func (e UserDisabled) Encode() map[string]any
func (UserDisabled) Operation ¶ added in v0.46.0
func (e UserDisabled) Operation() string
type UserEnabled ¶ added in v0.46.0
type UserEnabled struct {
ID string
}
UserEnabled signals that a platform owner or admin enabled a user.
func (UserEnabled) Encode ¶ added in v0.46.0
func (e UserEnabled) Encode() map[string]any
func (UserEnabled) Operation ¶ added in v0.46.0
func (e UserEnabled) Operation() string
type UserImpersonated ¶ added in v0.46.0
UserImpersonated signals that a platform admin started an impersonated session of a user.
func (UserImpersonated) Encode ¶ added in v0.46.0
func (e UserImpersonated) Encode() map[string]any
func (UserImpersonated) Operation ¶ added in v0.46.0
func (e UserImpersonated) Operation() string
type UserLoggedIn ¶ added in v0.46.0
type UserLoggedIn struct{}
UserLoggedIn signals that a user started a new session.
func (UserLoggedIn) Encode ¶ added in v0.46.0
func (e UserLoggedIn) Encode() map[string]any
func (UserLoggedIn) Operation ¶ added in v0.46.0
func (e UserLoggedIn) Operation() string
type UserLoginFailed ¶ added in v0.46.0
type UserLoginFailed struct {
Email string
}
UserLoginFailed signals a login attempt with invalid credentials.
func (UserLoginFailed) Encode ¶ added in v0.46.0
func (e UserLoginFailed) Encode() map[string]any
func (UserLoginFailed) Operation ¶ added in v0.46.0
func (e UserLoginFailed) Operation() string
type UserPasswordChanged ¶ added in v0.46.0
type UserPasswordChanged struct {
ID string
}
UserPasswordChanged signals that a user's password was changed by the user or a platform owner or admin.
func (UserPasswordChanged) Encode ¶ added in v0.46.0
func (e UserPasswordChanged) Encode() map[string]any
func (UserPasswordChanged) Operation ¶ added in v0.46.0
func (e UserPasswordChanged) Operation() string
type UserPasswordReset ¶ added in v0.46.0
type UserPasswordReset struct {
ID string
}
UserPasswordReset signals that a user set a new password through the recovery flow.
func (UserPasswordReset) Encode ¶ added in v0.46.0
func (e UserPasswordReset) Encode() map[string]any
func (UserPasswordReset) Operation ¶ added in v0.46.0
func (e UserPasswordReset) Operation() string
type UserRegistered ¶ added in v0.46.0
UserRegistered signals that a new user account was created.
func (UserRegistered) Encode ¶ added in v0.46.0
func (e UserRegistered) Encode() map[string]any
func (UserRegistered) Operation ¶ added in v0.46.0
func (e UserRegistered) Operation() string
type UserUpdated ¶ added in v0.46.0
UserUpdated signals that a user changed their metadata.
func (UserUpdated) Encode ¶ added in v0.46.0
func (e UserUpdated) Encode() map[string]any
func (UserUpdated) Operation ¶ added in v0.46.0
func (e UserUpdated) Operation() string