Documentation ¶
Overview ¶
Package users contains the domain concept definitions needed to support SuperMQ users service functionality.
This package defines the core domain concepts and types necessary to handle users in the context of a SuperMQ users service. It abstracts the underlying complexities of user management and provides a structured approach to working with users.
Index ¶
Constants ¶
const ( Disabled = "disabled" Enabled = "enabled" Deleted = "deleted" All = "all" Unknown = "unknown" )
String representation of the possible status values.
const (
Admin = "admin"
)
String representation of the possible role values.
Variables ¶
This section is empty.
Functions ¶
func NewDeleteHandler ¶
func NewDeleteHandler(ctx context.Context, users Repository, policyService policies.Service, domainsClient grpcDomainsV1.DomainsServiceClient, defCheckInterval, deleteAfter time.Duration, logger *slog.Logger)
Types ¶
type Credentials ¶
type Emailer ¶
type Emailer interface { // SendPasswordReset sends an email to the user with a link to reset the password. SendPasswordReset(To []string, host, user, token string) error }
Emailer wrapper around the email.
type Hasher ¶
type Hasher interface { // Hash generates the hashed string from plain-text. Hash(string) (string, error) // Compare compares plain-text version to the hashed one. An error should // indicate failed comparison. Compare(string, string) error }
Hasher specifies an API for generating hashes of an arbitrary textual content.
type MembersPage ¶
MembersPage contains page related metadata as well as list of members that belong to this page.
type Page ¶
type Page struct { Total uint64 `json:"total"` Offset uint64 `json:"offset"` Limit uint64 `json:"limit"` Id string `json:"id,omitempty"` Order string `json:"order,omitempty"` Dir string `json:"dir,omitempty"` Metadata Metadata `json:"metadata,omitempty"` Domain string `json:"domain,omitempty"` Tag string `json:"tag,omitempty"` Permission string `json:"permission,omitempty"` Status Status `json:"status,omitempty"` IDs []string `json:"ids,omitempty"` Role Role `json:"-"` ListPerms bool `json:"-"` Username string `json:"username,omitempty"` FirstName string `json:"first_name,omitempty"` LastName string `json:"last_name,omitempty"` Email string `json:"email,omitempty"` }
Page contains page metadata that helps navigation.
type Repository ¶
type Repository interface { // RetrieveByID retrieves user by their unique ID. RetrieveByID(ctx context.Context, id string) (User, error) // RetrieveAll retrieves all users. RetrieveAll(ctx context.Context, pm Page) (UsersPage, error) // RetrieveByEmail retrieves user by its unique credentials. RetrieveByEmail(ctx context.Context, email string) (User, error) // RetrieveByUsername retrieves user by its unique credentials. RetrieveByUsername(ctx context.Context, username string) (User, error) // Update updates the user name and metadata. Update(ctx context.Context, user User) (User, error) // UpdateUsername updates the User's names. UpdateUsername(ctx context.Context, user User) (User, error) // UpdateSecret updates secret for user with given email. UpdateSecret(ctx context.Context, user User) (User, error) // ChangeStatus changes user status to enabled or disabled ChangeStatus(ctx context.Context, user User) (User, error) // Delete deletes user with given id Delete(ctx context.Context, id string) error // Searchusers retrieves users based on search criteria. SearchUsers(ctx context.Context, pm Page) (UsersPage, error) // RetrieveAllByIDs retrieves for given user IDs . RetrieveAllByIDs(ctx context.Context, pm Page) (UsersPage, error) CheckSuperAdmin(ctx context.Context, adminID string) error // Save persists the user account. A non-nil error is returned to indicate // operation failure. Save(ctx context.Context, user User) (User, error) }
type Role ¶
type Role uint8
Role represents User role.
const ( UserRole Role = iota AdminRole // AllRole is used for querying purposes to list users irrespective // of their role - both admin and user. It is never stored in the // database as the actual user role and should always be the largest // value in this enumeration. AllRole )
Possible User role values.
func (Role) MarshalJSON ¶
func (*Role) UnmarshalJSON ¶
type Service ¶
type Service interface { // Register creates new user. In case of the failed registration, a // non-nil error value is returned. Register(ctx context.Context, session authn.Session, user User, selfRegister bool) (User, error) // View retrieves user info for a given user ID and an authorized token. View(ctx context.Context, session authn.Session, id string) (User, error) // ViewProfile retrieves user info for a given token. ViewProfile(ctx context.Context, session authn.Session) (User, error) // ListUsers retrieves users list for a valid auth token. ListUsers(ctx context.Context, session authn.Session, pm Page) (UsersPage, error) // ListMembers retrieves everything that is assigned to a group/client identified by objectID. ListMembers(ctx context.Context, session authn.Session, objectKind, objectID string, pm Page) (MembersPage, error) // SearchUsers searches for users with provided filters for a valid auth token. SearchUsers(ctx context.Context, pm Page) (UsersPage, error) // Update updates the user's name and metadata. Update(ctx context.Context, session authn.Session, user User) (User, error) // UpdateTags updates the user's tags. UpdateTags(ctx context.Context, session authn.Session, user User) (User, error) // UpdateEmail updates the user's email. UpdateEmail(ctx context.Context, session authn.Session, id, email string) (User, error) // UpdateUsername updates the user's username. UpdateUsername(ctx context.Context, session authn.Session, id, username string) (User, error) // UpdateProfilePicture updates the user's profile picture. UpdateProfilePicture(ctx context.Context, session authn.Session, user User) (User, error) // GenerateResetToken email where mail will be sent. // host is used for generating reset link. GenerateResetToken(ctx context.Context, email, host string) error // UpdateSecret updates the user's secret. UpdateSecret(ctx context.Context, session authn.Session, oldSecret, newSecret string) (User, error) // ResetSecret change users secret in reset flow. // token can be authentication token or secret reset token. ResetSecret(ctx context.Context, session authn.Session, secret string) error // SendPasswordReset sends reset password link to email. SendPasswordReset(ctx context.Context, host, email, user, token string) error // UpdateRole updates the user's Role. UpdateRole(ctx context.Context, session authn.Session, user User) (User, error) // Enable logically enables the user identified with the provided ID. Enable(ctx context.Context, session authn.Session, id string) (User, error) // Disable logically disables the user identified with the provided ID. Disable(ctx context.Context, session authn.Session, id string) (User, error) // Delete deletes user with given ID. Delete(ctx context.Context, session authn.Session, id string) error // Identify returns the user id from the given token. Identify(ctx context.Context, session authn.Session) (string, error) // IssueToken issues a new access and refresh token when provided with either a username or email. IssueToken(ctx context.Context, identity, secret string) (*grpcTokenV1.Token, error) // RefreshToken refreshes expired access tokens. // After an access token expires, the refresh token is used to get // a new pair of access and refresh tokens. RefreshToken(ctx context.Context, session authn.Session, refreshToken string) (*grpcTokenV1.Token, error) // OAuthCallback handles the callback from any supported OAuth provider. // It processes the OAuth tokens and either signs in or signs up the user based on the provided state. OAuthCallback(ctx context.Context, user User) (User, error) // OAuthAddUserPolicy adds a policy to the user for an OAuth request. OAuthAddUserPolicy(ctx context.Context, user User) error }
Service specifies an API that must be fullfiled by the domain service implementation, and all of its decorators (e.g. logging & metrics).
func NewService ¶
func NewService(token grpcTokenV1.TokenServiceClient, urepo Repository, policyService policies.Service, emailer Emailer, hasher Hasher, idp supermq.IDProvider) Service
NewService returns a new Users service implementation.
type Status ¶
type Status uint8
Status represents User status.
const ( // EnabledStatus represents enabled User. EnabledStatus Status = iota // DisabledStatus represents disabled User. DisabledStatus // DeletedStatus represents a user that will be deleted. DeletedStatus // AllStatus is used for querying purposes to list users irrespective // of their status - both enabled and disabled. It is never stored in the // database as the actual User status and should always be the largest // value in this enumeration. AllStatus )
Possible User status values.
func (Status) MarshalJSON ¶
Custom Marshaller for Uesr/Groups.
func (*Status) UnmarshalJSON ¶
Custom Unmarshaler for User/Groups.
type User ¶
type User struct { ID string `json:"id"` FirstName string `json:"first_name,omitempty"` LastName string `json:"last_name,omitempty"` Tags []string `json:"tags,omitempty"` Metadata Metadata `json:"metadata,omitempty"` Status Status `json:"status"` // 0 for enabled, 1 for disabled Role Role `json:"role"` // 0 for normal user, 1 for admin ProfilePicture string `json:"profile_picture,omitempty"` // profile picture URL Credentials Credentials `json:"credentials,omitempty"` Permissions []string `json:"permissions,omitempty"` Email string `json:"email,omitempty"` CreatedAt time.Time `json:"created_at,omitempty"` UpdatedAt time.Time `json:"updated_at,omitempty"` UpdatedBy string `json:"updated_by,omitempty"` }
type UserRepository ¶
UserRepository struct implements the Repository interface.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package api contains API-related concerns: endpoint definitions, middlewares and all resource representations.
|
Package api contains API-related concerns: endpoint definitions, middlewares and all resource representations. |
Package emailer contains the domain concept definitions needed to support SuperMQ users email service functionality.
|
Package emailer contains the domain concept definitions needed to support SuperMQ users email service functionality. |
Package events provides the domain concept definitions needed to support SuperMQ users service functionality.
|
Package events provides the domain concept definitions needed to support SuperMQ users service functionality. |
Package hasher contains the domain concept definitions needed to support SuperMQ users password hasher sub-service functionality.
|
Package hasher contains the domain concept definitions needed to support SuperMQ users password hasher sub-service functionality. |
Package middleware provides middleware for SuperMQ Users service.
|
Package middleware provides middleware for SuperMQ Users service. |
Package mocks contains mocks for testing purposes.
|
Package mocks contains mocks for testing purposes. |
Package postgres contains the database implementation of users repository layer.
|
Package postgres contains the database implementation of users repository layer. |
Package tracing provides tracing instrumentation for SuperMQ Users service.
|
Package tracing provides tracing instrumentation for SuperMQ Users service. |