Documentation
¶
Overview ¶
Package clients contains the domain concept definitions needed to support Magistrala clients functionality.
Index ¶
Constants ¶
const ( Admin = "admin" User = "user" )
String representation of the possible role values.
const ( Disabled = "disabled" Enabled = "enabled" Deleted = "deleted" All = "all" Unknown = "unknown" )
String representation of the possible status values.
Variables ¶
var ( // ErrInvalidStatus indicates invalid status. ErrInvalidStatus = errors.New("invalid client status") // ErrEnableClient indicates error in enabling client. ErrEnableClient = errors.New("failed to enable client") // ErrDisableClient indicates error in disabling client. ErrDisableClient = errors.New("failed to disable client") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { ID string `json:"id"` Name string `json:"name,omitempty"` Tags []string `json:"tags,omitempty"` Domain string `json:"domain,omitempty"` Credentials Credentials `json:"credentials,omitempty"` Metadata Metadata `json:"metadata,omitempty"` CreatedAt time.Time `json:"created_at,omitempty"` UpdatedAt time.Time `json:"updated_at,omitempty"` UpdatedBy string `json:"updated_by,omitempty"` Status Status `json:"status,omitempty"` // 1 for enabled, 0 for disabled Role Role `json:"role,omitempty"` // 1 for admin, 0 for normal user Permissions []string `json:"permissions,omitempty"` }
Client represents generic Client.
func (Client) MarshalJSON ¶
type ClientsPage ¶
ClientsPage contains page related metadata as well as list of Clients that belong to the page.
type Credentials ¶
type Credentials struct { Identity string `json:"identity,omitempty"` // username or generated login ID Secret string `json:"secret,omitempty"` // password or token }
Credentials represent client credentials: its "identity" which can be a username, email, generated name; and "secret" which can be a password or access token.
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"` Name string `json:"name,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"` Identity string `json:"identity,omitempty"` Role Role `json:"-"` ListPerms bool `json:"-"` }
Page contains page metadata that helps navigation.
type Repository ¶
type Repository interface { // RetrieveByID retrieves client by its unique ID. RetrieveByID(ctx context.Context, id string) (Client, error) // RetrieveByIdentity retrieves client by its unique credentials RetrieveByIdentity(ctx context.Context, identity string) (Client, error) // RetrieveAll retrieves all clients. RetrieveAll(ctx context.Context, pm Page) (ClientsPage, error) // RetrieveAllBasicInfo list all clients only with basic information. RetrieveAllBasicInfo(ctx context.Context, pm Page) (ClientsPage, error) // RetrieveAllByIDs retrieves for given client IDs . RetrieveAllByIDs(ctx context.Context, pm Page) (ClientsPage, error) // Update updates the client name and metadata. Update(ctx context.Context, client Client) (Client, error) // UpdateTags updates the client tags. UpdateTags(ctx context.Context, client Client) (Client, error) // UpdateIdentity updates identity for client with given id. UpdateIdentity(ctx context.Context, client Client) (Client, error) // UpdateSecret updates secret for client with given identity. UpdateSecret(ctx context.Context, client Client) (Client, error) // UpdateRole updates role for client with given id. UpdateRole(ctx context.Context, client Client) (Client, error) // ChangeStatus changes client status to enabled or disabled ChangeStatus(ctx context.Context, client Client) (Client, error) // Delete deletes client with given id Delete(ctx context.Context, id string) error }
Repository specifies an account persistence API.
type Role ¶
type Role uint8
Role represents Client role.
const ( UserRole Role = iota AdminRole // AllRole is used for querying purposes to list clients irrespective // of their role - both admin and user. It is never stored in the // database as the actual Client role and should always be the largest // value in this enumeration. AllRole )
Possible Client role values.
func (Role) MarshalJSON ¶
func (*Role) UnmarshalJSON ¶
type Status ¶
type Status uint8
Status represents Client status.
const ( // EnabledStatus represents enabled Client. EnabledStatus Status = iota // DisabledStatus represents disabled Client. DisabledStatus // DeletedStatus represents a client that will be deleted. DeletedStatus // AllStatus is used for querying purposes to list clients irrespective // of their status - both enabled and disabled. It is never stored in the // database as the actual Client status and should always be the largest // value in this enumeration. AllStatus )
Possible Client status values.
func (Status) MarshalJSON ¶
Custom Marshaller for Client/Groups.
func (*Status) UnmarshalJSON ¶
Custom Unmarshaler for Client/Groups.