clients

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package clients contains the domain concept definitions needed to support Magistrala clients functionality.

Index

Constants

View Source
const (
	Admin = "admin"
	User  = "user"
)

String representation of the possible role values.

View Source
const (
	Disabled = "disabled"
	Enabled  = "enabled"
	All      = "all"
	Unknown  = "unknown"
)

String representation of the possible status values.

Variables

View Source
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")
)
View Source
var ErrStatusAlreadyAssigned = errors.New("status already assigned")

ErrStatusAlreadyAssigned indicated that the client or group has already been assigned the status.

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

func (client Client) MarshalJSON() ([]byte, error)

func (Client) Validate

func (u Client) Validate() error

Validate returns an error if client representation is invalid.

type ClientsPage

type ClientsPage struct {
	Page
	Clients []Client
}

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

type MembersPage struct {
	Page
	Members []Client
}

MembersPage contains page related metadata as well as list of members that belong to this page.

type Metadata

type Metadata map[string]interface{}

Metadata represents arbitrary JSON.

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)
}

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 ToRole

func ToRole(status string) (Role, error)

ToRole converts string value to a valid Client role.

func (Role) MarshalJSON

func (r Role) MarshalJSON() ([]byte, error)

func (Role) String

func (cs Role) String() string

String converts client role to string literal.

func (*Role) UnmarshalJSON

func (r *Role) UnmarshalJSON(data []byte) error

type Status

type Status uint8

Status represents Client status.

const (
	// EnabledStatus represents enabled Client.
	EnabledStatus Status = iota
	// DisabledStatus represents disabled Client.
	DisabledStatus

	// 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 ToStatus

func ToStatus(status string) (Status, error)

ToStatus converts string value to a valid Client/Group status.

func (Status) MarshalJSON

func (s Status) MarshalJSON() ([]byte, error)

Custom Marshaller for Client/Groups.

func (Status) String

func (s Status) String() string

String converts client/group status to string literal.

func (*Status) UnmarshalJSON

func (s *Status) UnmarshalJSON(data []byte) error

Custom Unmarshaler for Client/Groups.

Directories

Path Synopsis
Package postgres contains the database implementation of clients repository layer.
Package postgres contains the database implementation of clients repository layer.

Jump to

Keyboard shortcuts

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