Documentation ¶
Overview ¶
Package clients contains the domain concept definitions needed to support SuperMQ clients service functionality.
This package defines the core domain concepts and types necessary to handle clients in the context of a SuperMQ clients service. It abstracts the underlying complexities of user management and provides a structured approach to working with clients.
Copyright (c) Abstract Machines SPDX-License-Identifier: Apache-2.0
Index ¶
- Constants
- Variables
- func AvailableActions() []roles.Action
- func BuiltInRoles() map[roles.BuiltInRoleName][]roles.Action
- func NewExternalOperationPerm() svcutil.ExternalOperationPerm
- func NewExternalOperationPermissionMap() map[svcutil.ExternalOperation]svcutil.Permission
- func NewOperationPerm() svcutil.OperationPerm
- func NewOperationPermissionMap() map[svcutil.Operation]svcutil.Permission
- func NewRolesOperationPermissionMap() map[svcutil.Operation]svcutil.Permission
- type Cache
- type Client
- type ClientRepository
- type ClientsPage
- type Connection
- type Credentials
- type MembersPage
- type Metadata
- type Page
- type Repository
- type Role
- type Service
- type Status
Constants ¶
const ( ClientUpdate roles.Action = "update" ClientRead roles.Action = "read" ClientDelete roles.Action = "delete" ClientSetParentGroup roles.Action = "set_parent_group" ClientConnectToChannel roles.Action = "connect_to_channel" ClientManageRole roles.Action = "manage_role" ClientAddRoleUsers roles.Action = "add_role_users" ClientRemoveRoleUsers roles.Action = "remove_role_users" ClientViewRoleUsers roles.Action = "view_role_users" )
const ( OpViewClient svcutil.Operation = iota OpUpdateClient OpUpdateClientTags OpUpdateClientSecret OpEnableClient OpDisableClient OpDeleteClient OpSetParentGroup OpRemoveParentGroup OpConnectToChannel OpDisconnectFromChannel )
const ( DomainOpCreateClient svcutil.ExternalOperation = iota DomainOpListClients GroupOpSetChildClient GroupsOpRemoveChildClient ChannelsOpConnectChannel ChannelsOpDisconnectChannel )
External Operations.
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.
const (
ClientBuiltInRoleAdmin = "admin"
)
Variables ¶
var ( // 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 ¶
func AvailableActions ¶
func BuiltInRoles ¶
func BuiltInRoles() map[roles.BuiltInRoleName][]roles.Action
func NewExternalOperationPerm ¶
func NewExternalOperationPerm() svcutil.ExternalOperationPerm
func NewExternalOperationPermissionMap ¶
func NewExternalOperationPermissionMap() map[svcutil.ExternalOperation]svcutil.Permission
func NewOperationPerm ¶
func NewOperationPerm() svcutil.OperationPerm
func NewOperationPermissionMap ¶
func NewOperationPermissionMap() map[svcutil.Operation]svcutil.Permission
func NewRolesOperationPermissionMap ¶
func NewRolesOperationPermissionMap() map[svcutil.Operation]svcutil.Permission
Types ¶
type Cache ¶
type Cache interface { // Save stores pair client secret, client id. Save(ctx context.Context, clientSecret, clientID string) error // ID returns client ID for given client secret. ID(ctx context.Context, clientSecret string) (string, error) // Removes client from cache. Remove(ctx context.Context, clientID string) error }
Cache contains client caching interface.
type Client ¶
type Client struct { ID string `json:"id"` Name string `json:"name,omitempty"` Tags []string `json:"tags,omitempty"` Domain string `json:"domain_id,omitempty"` ParentGroup string `json:"parent_group_id,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 Permissions []string `json:"permissions,omitempty"` Identity string `json:"identity,omitempty"` }
func (Client) MarshalJSON ¶
type ClientRepository ¶
type ClientsPage ¶
ClientsPage contains page related metadata as well as list.
type Connection ¶
type Connection struct { ClientID string ChannelID string DomainID string Type connections.ConnType }
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 ¶
type Page ¶
type Page struct { Total uint64 `json:"total"` Offset uint64 `json:"offset"` Limit uint64 `json:"limit"` Name string `json:"name,omitempty"` 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"` Identity string `json:"identity,omitempty"` ListPerms bool `json:"-"` }
type Repository ¶
type Repository interface { // RetrieveByID retrieves client by its unique ID. RetrieveByID(ctx context.Context, id string) (Client, error) // RetrieveAll retrieves all clients. RetrieveAll(ctx context.Context, pm Page) (ClientsPage, error) // SearchClients retrieves clients based on search criteria. SearchClients(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) // 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, clientIDs ...string) error // Save persists the client account. A non-nil error is returned to indicate // operation failure. Save(ctx context.Context, client ...Client) ([]Client, error) // RetrieveBySecret retrieves a client based on the secret (key). RetrieveBySecret(ctx context.Context, key string) (Client, error) RetrieveByIds(ctx context.Context, ids []string) (ClientsPage, error) AddConnections(ctx context.Context, conns []Connection) error RemoveConnections(ctx context.Context, conns []Connection) error ClientConnectionsCount(ctx context.Context, id string) (uint64, error) DoesClientHaveConnections(ctx context.Context, id string) (bool, error) RemoveChannelConnections(ctx context.Context, channelID string) error RemoveClientConnections(ctx context.Context, clientID string) error // SetParentGroup set parent group id to a given channel id SetParentGroup(ctx context.Context, cli Client) error // RemoveParentGroup remove parent group id fr given chanel id RemoveParentGroup(ctx context.Context, cli Client) error RetrieveParentGroupClients(ctx context.Context, parentGroupID string) ([]Client, error) UnsetParentGroupFromClient(ctx context.Context, parentGroupID string) error roles.Repository }
Repository is the interface that wraps the basic methods for a client repository.
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 Service ¶
type Service interface { // CreateClients creates new client. In case of the failed registration, a // non-nil error value is returned. CreateClients(ctx context.Context, session authn.Session, client ...Client) ([]Client, error) // View retrieves client info for a given client ID and an authorized token. View(ctx context.Context, session authn.Session, id string) (Client, error) // ListClients retrieves clients list for a valid auth token. ListClients(ctx context.Context, session authn.Session, reqUserID string, pm Page) (ClientsPage, error) // Update updates the client's name and metadata. Update(ctx context.Context, session authn.Session, client Client) (Client, error) // UpdateTags updates the client's tags. UpdateTags(ctx context.Context, session authn.Session, client Client) (Client, error) // UpdateSecret updates the client's secret UpdateSecret(ctx context.Context, session authn.Session, id, key string) (Client, error) // Enable logically enableds the client identified with the provided ID Enable(ctx context.Context, session authn.Session, id string) (Client, error) // Disable logically disables the client identified with the provided ID Disable(ctx context.Context, session authn.Session, id string) (Client, error) // Delete deletes client with given ID. Delete(ctx context.Context, session authn.Session, id string) error SetParentGroup(ctx context.Context, session authn.Session, parentGroupID string, id string) error RemoveParentGroup(ctx context.Context, session authn.Session, id string) error roles.RoleManager }
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(repo Repository, policy policies.Service, cache Cache, channels grpcChannelsV1.ChannelsServiceClient, groups grpcGroupsV1.GroupsServiceClient, idProvider smq.IDProvider, sIDProvider smq.IDProvider) (Service, error)
NewService returns a new Clients service implementation.
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.
func (*Status) UnmarshalJSON ¶
Custom Unmarshaler for Client.
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. |
grpc
Package grpc contains implementation of Auth service gRPC API.
|
Package grpc contains implementation of Auth service gRPC API. |
Package cache contains the domain concept definitions needed to support SuperMQ clients cache service functionality.
|
Package cache contains the domain concept definitions needed to support SuperMQ clients cache service functionality. |
Package events provides the domain concept definitions needed to support clients events functionality.
|
Package events provides the domain concept definitions needed to support clients events functionality. |
Package middleware provides middleware for SuperMQ Clients service.
|
Package middleware provides middleware for SuperMQ Clients service. |
Package mocks contains mocks for testing purposes.
|
Package mocks contains mocks for testing purposes. |
Package postgres contains the database implementation of clients repository layer.
|
Package postgres contains the database implementation of clients repository layer. |
Private package is a service wrapper around the underlying Repository.
|
Private package is a service wrapper around the underlying Repository. |
Package standalone contains implementation for auth service in single-user scenario.
|
Package standalone contains implementation for auth service in single-user scenario. |
Package tracing provides tracing instrumentation for SuperMQ clients service.
|
Package tracing provides tracing instrumentation for SuperMQ clients service. |