domain

package
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AlarmOriginRule indicates an alarm was triggered by a rule.
	AlarmOriginRule = "rule"
	// AlarmOriginScript indicates an alarm was triggered by a Lua script.
	AlarmOriginScript = "script"
)
View Source
const (
	RootSub = "root"
	OrgSub  = "org"
)

Subject type constants for authorization.

View Source
const (
	OrgAdmin  = "admin"
	OrgOwner  = "owner"
	OrgEditor = "editor"
	OrgViewer = "viewer"
)

Org role constants.

View Source
const (
	// RoleRootAdmin is the super admin role.
	RoleRootAdmin = "root"
	// RoleAdmin is the admin role.
	RoleAdmin = "admin"
)

Platform role constants.

View Source
const (
	LoginKey uint32 = iota
	RecoveryKey
	APIKey
)

Key type constants.

View Source
const (
	KeyTypeInternal = "internal"
	KeyTypeExternal = "external"
)

Thing key type constants.

View Source
const (
	GroupViewer = "viewer"
	GroupEditor = "editor"
	GroupAdmin  = "admin"
	GroupOwner  = "owner"
)

Group role constants.

View Source
const (
	EnabledStatusKey  = "enabled"
	DisabledStatusKey = "disabled"
	AllStatusKey      = "all"
)

Status key constants for user filtering.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthClient added in v0.40.0

type AuthClient interface {
	// Issue issues a token for the given id, email and key type.
	Issue(ctx context.Context, id, email string, keyType uint32) (string, error)

	// Identify validates the token and returns the identity.
	Identify(ctx context.Context, token string) (Identity, error)

	// Authorize checks if the subject is authorized to perform the action on the object.
	Authorize(ctx context.Context, ar AuthzReq) error

	// GetOwnerIDByOrg returns the owner ID of the organization.
	GetOwnerIDByOrg(ctx context.Context, orgID string) (string, error)

	// AssignRole assigns a role to a user.
	AssignRole(ctx context.Context, id, role string) error

	// RetrieveRole retrieves the role for a user.
	RetrieveRole(ctx context.Context, id string) (string, error)

	// CreateDormantOrgInvite creates a dormant org invite.
	CreateDormantOrgInvite(ctx context.Context, token, orgID, inviteeRole, platformInviteID string, groupInvites []GroupInvite) error

	// ActivateOrgInvite activates an org invite.
	ActivateOrgInvite(ctx context.Context, platformInviteID, userID, redirectPath string) error

	// GetDormantOrgInviteByPlatformInvite retrieves a dormant org invite by platform invite ID.
	GetDormantOrgInviteByPlatformInvite(ctx context.Context, platformInviteID string) (OrgInvite, error)

	// ViewOrg retrieves organization details.
	ViewOrg(ctx context.Context, token, orgID string) (Org, error)
}

type AuthzReq

type AuthzReq struct {
	Token   string
	Object  string
	Subject string
	Action  string
}

AuthzReq represents an argument struct for authorization requests.

type Condition added in v0.40.0

type Condition struct {
	Field      string   `json:"field"`
	Comparator string   `json:"comparator"`
	Threshold  *float64 `json:"threshold"`
}

Condition represents a single evaluatable condition used in rules and recorded on alarms.

type Group

type Group struct {
	ID          string    `json:"id,omitempty"`
	OrgID       string    `json:"org_id,omitempty"`
	Name        string    `json:"name,omitempty"`
	Description string    `json:"description,omitempty"`
	Metadata    Metadata  `json:"metadata,omitempty"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

Group represents group information.

type GroupInvite

type GroupInvite struct {
	GroupID    string `json:"group_id,omitempty"`
	MemberRole string `json:"member_role,omitempty"`
}

GroupInvite represents a group membership invite.

type GroupMembership

type GroupMembership struct {
	GroupID  string `json:"group_id,omitempty"`
	MemberID string `json:"member_id,omitempty"`
	Email    string `json:"email,omitempty"`
	Role     string `json:"role,omitempty"`
}

GroupMembership represents a group membership.

type GroupMembershipsPage

type GroupMembershipsPage struct {
	Total            uint64            `json:"total"`
	GroupMemberships []GroupMembership `json:"group_memberships"`
}

GroupMembershipsPage contains page metadata and list of group memberships.

type GroupPage

type GroupPage struct {
	Total  uint64  `json:"total"`
	Groups []Group `json:"groups"`
}

GroupPage contains page metadata and list of groups.

type Identity

type Identity struct {
	ID    string `json:"id,omitempty"`
	Email string `json:"email,omitempty"`
}

Identity contains ID and Email.

type JSONMessagesPage

type JSONMessagesPage struct {
	JSONPageMetadata
	MessagesPage
}

JSONMessagesPage contains a page of JSON messages.

type JSONPageMetadata

type JSONPageMetadata struct {
	Offset      uint64   `json:"offset"`
	Limit       uint64   `json:"limit"`
	Subtopic    string   `json:"subtopic,omitempty"`
	Publisher   string   `json:"publisher,omitempty"`
	Protocol    string   `json:"protocol,omitempty"`
	From        int64    `json:"from,omitempty"`
	To          int64    `json:"to,omitempty"`
	Filter      string   `json:"filter,omitempty"`
	AggInterval string   `json:"agg_interval,omitempty"`
	AggValue    uint64   `json:"agg_value,omitempty"`
	AggType     string   `json:"agg_type,omitempty"`
	AggFields   []string `json:"agg_fields,omitempty"`
	Dir         string   `json:"dir,omitempty"`
}

JSONPageMetadata represents the parameters used to create database queries.

type Key

type Key struct {
	ID        string    `json:"id,omitempty"`
	Type      uint32    `json:"type,omitempty"`
	IssuerID  string    `json:"issuer_id,omitempty"`
	Subject   string    `json:"subject,omitempty"`
	IssuedAt  time.Time `json:"issued_at,omitempty"`
	ExpiresAt time.Time `json:"expires_at,omitempty"`
}

Key represents API key.

func (Key) Expired

func (k Key) Expired() bool

Expired reports whether the key is expired.

type KeysPage

type KeysPage struct {
	Total uint64
	Keys  []Key
}

KeysPage contains page metadata and list of keys.

type Message

type Message any

Message represents any message format.

type MessagesPage

type MessagesPage struct {
	Total    uint64
	Messages []Message
}

MessagesPage contains a page of messages.

type Metadata

type Metadata map[string]any

Metadata defines custom key-value metadata used across domain entities.

type Org

type Org struct {
	ID          string    `json:"id,omitempty"`
	OwnerID     string    `json:"owner_id,omitempty"`
	Name        string    `json:"name,omitempty"`
	Description string    `json:"description,omitempty"`
	Metadata    Metadata  `json:"metadata,omitempty"`
	CreatedAt   time.Time `json:"created_at,omitempty"`
	UpdatedAt   time.Time `json:"updated_at,omitempty"`
}

Org represents org information.

type OrgAccessReq

type OrgAccessReq struct {
	OrgID string
	Token string
}

OrgAccessReq represents an org access request.

type OrgInvite

type OrgInvite struct {
	ID           string        `json:"id,omitempty"`
	OrgID        string        `json:"org_id,omitempty"`
	OrgName      string        `json:"org_name,omitempty"`
	InviteeRole  string        `json:"invitee_role,omitempty"`
	GroupInvites []GroupInvite `json:"group_invites,omitempty"`
	InviteeID    string        `json:"invitee_id,omitempty"`
	InviteeEmail string        `json:"invitee_email,omitempty"`
	InviterID    string        `json:"inviter_id,omitempty"`
	InviterEmail string        `json:"inviter_email,omitempty"`
	CreatedAt    time.Time     `json:"created_at,omitempty"`
	ExpiresAt    time.Time     `json:"expires_at,omitempty"`
	State        string        `json:"state,omitempty"`
}

OrgInvite represents org invite information.

type OrgInvitesPage

type OrgInvitesPage struct {
	Invites []OrgInvite `json:"invites"`
	Total   uint64      `json:"total"`
}

OrgInvitesPage contains page metadata and list of org invites.

type OrgMembership

type OrgMembership struct {
	MemberID  string    `json:"member_id,omitempty"`
	OrgID     string    `json:"org_id,omitempty"`
	Role      string    `json:"role,omitempty"`
	CreatedAt time.Time `json:"created_at,omitempty"`
	UpdatedAt time.Time `json:"updated_at,omitempty"`
	Email     string    `json:"email,omitempty"`
}

OrgMembership represents org membership information.

type OrgMembershipsPage

type OrgMembershipsPage struct {
	Total          uint64          `json:"total"`
	OrgMemberships []OrgMembership `json:"org_memberships"`
}

OrgMembershipsPage contains page metadata and list of org memberships.

type OrgsPage

type OrgsPage struct {
	Total uint64 `json:"total"`
	Orgs  []Org  `json:"orgs"`
}

OrgsPage contains page metadata and list of orgs.

type PlatformInvite

type PlatformInvite struct {
	ID           string     `json:"id,omitempty"`
	InviteeEmail string     `json:"invitee_email,omitempty"`
	CreatedAt    time.Time  `json:"created_at,omitempty"`
	ExpiresAt    time.Time  `json:"expires_at,omitempty"`
	State        string     `json:"state,omitempty"`
	OrgInvite    *OrgInvite `json:"org_invite"`
}

PlatformInvite represents platform invite information.

type PlatformInvitesPage

type PlatformInvitesPage struct {
	Total   uint64           `json:"total"`
	Invites []PlatformInvite `json:"invites"`
}

PlatformInvitesPage contains page metadata and list of platform invites.

type Profile

type Profile struct {
	ID       string         `json:"id,omitempty"`
	GroupID  string         `json:"group_id,omitempty"`
	Name     string         `json:"name,omitempty"`
	Config   *ProfileConfig `json:"config,omitempty"`
	Metadata Metadata       `json:"metadata,omitempty"`
}

Profile represents a communication group (things that can exchange messages).

type ProfileConfig added in v0.40.0

type ProfileConfig struct {
	ContentType string      `json:"content_type"`
	Transformer Transformer `json:"transformer"`
}

ProfileConfig represents profile configuration.

type ProfilesPage

type ProfilesPage struct {
	Total    uint64    `json:"total"`
	Profiles []Profile `json:"profiles"`
}

ProfilesPage contains page metadata and list of profiles.

type PubConfigInfo

type PubConfigInfo struct {
	PublisherID   string
	ProfileConfig *ProfileConfig
}

PubConfigInfo represents publisher config from GetPubConfigByKey.

type ReadersClient added in v0.40.0

type ReadersClient interface {
	ListJSONMessages(ctx context.Context, key ThingKey, pm JSONPageMetadata) (JSONMessagesPage, error)
	ListSenMLMessages(ctx context.Context, key ThingKey, pm SenMLPageMetadata) (SenMLMessagesPage, error)
}

ReadersClient specifies the API for querying messages from the readers service via gRPC.

type RuleInfo added in v0.40.0

type RuleInfo struct {
	Conditions []Condition `json:"conditions"`
	Operator   string      `json:"operator,omitempty"`
}

RuleInfo captures the evaluation logic of the rule that triggered an alarm.

type SenMLMessagesPage

type SenMLMessagesPage struct {
	SenMLPageMetadata
	MessagesPage
}

SenMLMessagesPage contains a page of SenML messages.

type SenMLPageMetadata

type SenMLPageMetadata struct {
	Offset      uint64   `json:"offset"`
	Limit       uint64   `json:"limit"`
	Subtopic    string   `json:"subtopic,omitempty"`
	Publisher   string   `json:"publisher,omitempty"`
	Protocol    string   `json:"protocol,omitempty"`
	Name        string   `json:"name,omitempty"`
	Value       float64  `json:"v,omitempty"`
	Comparator  string   `json:"comparator,omitempty"`
	BoolValue   bool     `json:"vb,omitempty"`
	StringValue string   `json:"vs,omitempty"`
	DataValue   string   `json:"vd,omitempty"`
	From        int64    `json:"from,omitempty"`
	To          int64    `json:"to,omitempty"`
	AggInterval string   `json:"agg_interval,omitempty"`
	AggValue    uint64   `json:"agg_value,omitempty"`
	AggType     string   `json:"agg_type,omitempty"`
	AggFields   []string `json:"agg_fields,omitempty"`
	Dir         string   `json:"dir,omitempty"`
}

SenMLPageMetadata represents the parameters used to create database queries.

type Thing

type Thing struct {
	ID          string   `json:"id,omitempty"`
	GroupID     string   `json:"group_id,omitempty"`
	ProfileID   string   `json:"profile_id,omitempty"`
	Name        string   `json:"name,omitempty"`
	Type        string   `json:"type,omitempty"`
	Key         string   `json:"key,omitempty"`
	ExternalKey string   `json:"external_key,omitempty"`
	Metadata    Metadata `json:"metadata,omitempty"`
}

Thing represents a Mainflux thing. Each thing is owned by one user, and it is assigned with the unique identifier and (temporary) access key.

type ThingAccessReq

type ThingAccessReq struct {
	ThingKey
	ID string
}

ThingAccessReq represents a thing access request.

type ThingCommandReq

type ThingCommandReq struct {
	PublisherID string
	RecipientID string
}

ThingCommandReq represents a request to authorize an inter-thing command.

type ThingGroupCommandReq

type ThingGroupCommandReq struct {
	PublisherID string
	GroupID     string
}

ThingGroupCommandReq represents a request to authorize a thing group command.

type ThingKey

type ThingKey struct {
	Value string `json:"key"`
	Type  string `json:"type"`
}

ThingKey represents a Thing authentication key and its type.

type ThingsClient added in v0.40.0

type ThingsClient interface {
	GetPubConfigByKey(ctx context.Context, key ThingKey) (PubConfigInfo, error)
	GetConfigByThing(ctx context.Context, thingID string) (*ProfileConfig, error)
	CanUserAccessThing(ctx context.Context, ar UserAccessReq) error
	CanUserAccessProfile(ctx context.Context, ar UserAccessReq) error
	CanUserAccessGroup(ctx context.Context, ar UserAccessReq) error
	CanThingAccessGroup(ctx context.Context, ar ThingAccessReq) error
	CanThingCommand(ctx context.Context, req ThingCommandReq) error
	CanThingGroupCommand(ctx context.Context, req ThingGroupCommandReq) error
	Identify(ctx context.Context, key ThingKey) (string, error)
	GetGroupIDByThing(ctx context.Context, thingID string) (string, error)
	GetGroupIDByProfile(ctx context.Context, profileID string) (string, error)
	GetGroupIDsByOrg(ctx context.Context, ar OrgAccessReq) ([]string, error)
	GetThingIDsByProfile(ctx context.Context, profileID string) ([]string, error)
	CreateGroupMemberships(ctx context.Context, memberships ...GroupMembership) error
	GetGroup(ctx context.Context, groupID string) (Group, error)
	GetKeyByThingID(ctx context.Context, thingID string) (ThingKey, error)
}

type ThingsPage

type ThingsPage struct {
	Total  uint64  `json:"total"`
	Things []Thing `json:"things"`
}

ThingsPage contains page related metadata as well as list of things that belong to this page.

type Transformer

type Transformer struct {
	DataFilters  []string `json:"data_filters"`
	DataField    string   `json:"data_field"`
	TimeField    string   `json:"time_field"`
	TimeFormat   string   `json:"time_format"`
	TimeLocation string   `json:"time_location"`
}

Transformer represents message transformation config.

type User

type User struct {
	ID       string   `json:"id,omitempty"`
	Email    string   `json:"email,omitempty"`
	Password string   `json:"password,omitempty"`
	Metadata Metadata `json:"metadata,omitempty"`
	Status   string   `json:"status,omitempty"`
	Role     string   `json:"role,omitempty"`
}

User represents user account information.

func (User) Validate

func (u User) Validate(passRegex *regexp.Regexp) error

Validate returns an error if user representation is invalid.

type UserAccessReq

type UserAccessReq struct {
	Token  string
	ID     string
	Action string
}

UserAccessReq represents a user access request.

type UsersClient added in v0.40.0

type UsersClient interface {
	// GetUsersByIDs retrieves users by their IDs with optional pagination.
	GetUsersByIDs(ctx context.Context, ids []string, pm UsersPageMetadata) (UsersPage, error)

	// GetUsersByEmails retrieves users by their email addresses.
	GetUsersByEmails(ctx context.Context, emails []string) ([]User, error)
}

type UsersPage

type UsersPage struct {
	Total uint64 `json:"total"`
	Users []User `json:"users"`
}

UsersPage contains page metadata and list of users.

type UsersPageMetadata added in v0.40.0

type UsersPageMetadata struct {
	Total    uint64   `json:"total,omitempty"`
	Offset   uint64   `json:"offset,omitempty"`
	Limit    uint64   `json:"limit,omitempty"`
	Order    string   `json:"order,omitempty"`
	Dir      string   `json:"dir,omitempty"`
	Email    string   `json:"email,omitempty"`
	Status   string   `json:"status,omitempty"`
	State    string   `json:"state,omitempty"`
	Metadata Metadata `json:"metadata,omitempty"`
}

PageMetadata contains page metadata that helps navigation.

Jump to

Keyboard shortcuts

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