Documentation
¶
Index ¶
- Constants
- Variables
- type Authn
- type Authz
- type AuthzReq
- type Backup
- type Identity
- type Key
- type KeyRepository
- type Keys
- type Org
- type OrgMembership
- type OrgMemberships
- type OrgMembershipsBackup
- type OrgMembershipsPage
- type OrgMembershipsRepository
- type OrgMetadata
- type OrgRepository
- type Orgs
- type OrgsPage
- type Roles
- type RolesRepository
- type Service
- type Tokenizer
- type User
Constants ¶
const ( // LoginKey is temporary User key received on successful login. LoginKey uint32 = iota // RecoveryKey represents a key for resseting password. RecoveryKey // APIKey enables the one to act on behalf of the user. APIKey )
const ( // RoleRootAdmin is the super admin role. RoleRootAdmin = "root" // RoleAdmin is the admin role. RoleAdmin = "admin" )
const ( Admin = "admin" Owner = "owner" Editor = "editor" Viewer = "viewer" RootSub = "root" OrgSub = "org" )
Variables ¶
var ( // ErrInvalidKeyIssuedAt indicates that the Key is being used before it's issued. ErrInvalidKeyIssuedAt = errors.New("invalid issue time") // ErrKeyExpired indicates that the Key is expired. ErrKeyExpired = errors.New("use of expired key") // ErrAPIKeyExpired indicates that the Key is expired // and that the key type is API key. ErrAPIKeyExpired = errors.New("use of expired API key") )
var ( // ErrCreateOrgMembership indicates failure to create org membership. ErrCreateOrgMembership = errors.New("failed to create org membership") // ErrRemoveOrgMembership indicates failure to remove org membership. ErrRemoveOrgMembership = errors.New("failed to remove org membership") // ErrOrgMembershipExists indicates that membership already exists. ErrOrgMembershipExists = errors.New("org membership already exists") // ErrMissingUserMembership indicates that required user membership was not found. ErrMissingUserMembership = errors.New("user membership not found") )
var ( // ErrRetrieveMembershipsByOrg indicates that retrieving memberships by org failed. ErrRetrieveMembershipsByOrg = errors.New("failed to retrieve memberships by org") // ErrRetrieveOrgsByMembership indicates that retrieving orgs by membership failed. ErrRetrieveOrgsByMembership = errors.New("failed to retrieve orgs by membership") )
var ( // ErrOrgNotEmpty indicates org is not empty, can't be deleted. ErrOrgNotEmpty = errors.New("org is not empty") )
Functions ¶
This section is empty.
Types ¶
type Authn ¶
type Authn interface {
// Identify validates token token. If token is valid, content
// is returned. If token is invalid, or invocation failed for some
// other reason, non-nil error value is returned in response.
Identify(ctx context.Context, token string) (Identity, error)
}
Authn specifies an API that must be fullfiled by the domain service implementation, and all of its decorators (e.g. logging & metrics). Token is a string value of the actual Key and is used to authenticate an Auth service request.
type Authz ¶
Authz represents a authorization service. It exposes functionalities through `auth` to perform authorization.
type Backup ¶
type Backup struct {
Orgs []Org
OrgMemberships []OrgMembership
}
type Key ¶
type Key struct {
ID string
Type uint32
IssuerID string
Subject string
IssuedAt time.Time
ExpiresAt time.Time
}
Key represents API key.
type KeyRepository ¶
type KeyRepository interface {
// Save persists the Key. A non-nil error is returned to indicate
// operation failure
Save(context.Context, Key) (string, error)
// Retrieve retrieves Key by its unique identifier.
Retrieve(context.Context, string, string) (Key, error)
// Remove removes Key with provided ID.
Remove(context.Context, string, string) error
}
KeyRepository specifies Key persistence API.
type Keys ¶ added in v0.24.0
type Keys interface {
// Issue issues a new Key, returning its token value alongside.
Issue(ctx context.Context, token string, key Key) (Key, string, error)
// Revoke removes the Key with the provided id that is
// issued by the user identified by the provided key.
Revoke(ctx context.Context, token, id string) error
// RetrieveKey retrieves data for the Key identified by the provided
// ID, that is issued by the user identified by the provided key.
RetrieveKey(ctx context.Context, token, id string) (Key, error)
}
Keys specifies an API that must be fullfiled by the domain service implementation, and all of its decorators (e.g. logging & metrics).
type Org ¶
type Org struct {
ID string
OwnerID string
Name string
Description string
Metadata OrgMetadata
CreatedAt time.Time
UpdatedAt time.Time
}
Org represents the org information.
type OrgMembership ¶ added in v0.29.0
type OrgMemberships ¶ added in v0.29.0
type OrgMemberships interface {
// CreateOrgMemberships adds memberships with member emails into the org identified by orgID.
CreateOrgMemberships(ctx context.Context, token, orgID string, oms ...OrgMembership) error
// RemoveOrgMemberships removes memberships with member ids from org identified by orgID.
RemoveOrgMemberships(ctx context.Context, token string, orgID string, memberIDs ...string) error
// UpdateOrgMemberships updates membership roles in an org.
UpdateOrgMemberships(ctx context.Context, token, orgID string, oms ...OrgMembership) error
// ListOrgMemberships retrieves memberships created for an org identified by orgID.
ListOrgMemberships(ctx context.Context, token, orgID string, pm apiutil.PageMetadata) (OrgMembershipsPage, error)
// ViewOrgMembership retrieves membership identified by memberID and orgID.
ViewOrgMembership(ctx context.Context, token, orgID, memberID string) (OrgMembership, error)
// BackupOrgMemberships retrieves all org memberships for given org ID.
BackupOrgMemberships(ctx context.Context, token string, orgID string) (OrgMembershipsBackup, error)
// RestoreOrgMemberships adds all org memberships for given org ID from a backup.
RestoreOrgMemberships(ctx context.Context, token string, orgID string, backup OrgMembershipsBackup) error
}
OrgMemberships specify an API that must be fulfilled by the domain service implementation, and all of its decorators (e.g. logging & metrics).
type OrgMembershipsBackup ¶ added in v0.29.0
type OrgMembershipsBackup struct {
OrgMemberships []OrgMembership
}
type OrgMembershipsPage ¶ added in v0.29.0
type OrgMembershipsPage struct {
apiutil.PageMetadata
OrgMemberships []OrgMembership
}
OrgMembershipsPage contains page related metadata as well as list of memberships that belong to this page.
type OrgMembershipsRepository ¶ added in v0.29.0
type OrgMembershipsRepository interface {
// Save saves memberships.
Save(ctx context.Context, oms ...OrgMembership) error
// Update updates memberships.
Update(ctx context.Context, oms ...OrgMembership) error
// Remove removes memberships.
Remove(ctx context.Context, orgID string, memberIDs ...string) error
// RetrieveRole retrieves role of membership specified by memberID and orgID.
RetrieveRole(ctx context.Context, memberID, orgID string) (string, error)
// RetrieveByOrg retrieves org memberships identified by orgID.
RetrieveByOrg(ctx context.Context, orgID string, pm apiutil.PageMetadata) (OrgMembershipsPage, error)
// BackupAll retrieves all memberships.
BackupAll(ctx context.Context) ([]OrgMembership, error)
// BackupByOrg retrieves all memberships by org ID.
BackupByOrg(ctx context.Context, orgID string) ([]OrgMembership, error)
}
type OrgRepository ¶
type OrgRepository interface {
// Save orgs
Save(ctx context.Context, orgs ...Org) error
// Update an org
Update(ctx context.Context, org Org) error
// Remove orgs
Remove(ctx context.Context, ownerID string, orgIDs ...string) error
// RetrieveByID retrieves org by its id
RetrieveByID(ctx context.Context, id string) (Org, error)
// BackupAll retrieves all orgs.
BackupAll(ctx context.Context) ([]Org, error)
// RetrieveAll retrieves all orgs with pagination.
RetrieveAll(ctx context.Context, pm apiutil.PageMetadata) (OrgsPage, error)
// RetrieveByMember list of orgs that member belongs to
RetrieveByMember(ctx context.Context, memberID string, pm apiutil.PageMetadata) (OrgsPage, error)
}
OrgRepository specifies an org persistence API.
type Orgs ¶
type Orgs interface {
// CreateOrg creates new org.
CreateOrg(ctx context.Context, token string, org Org) (Org, error)
// UpdateOrg updates the org identified by the provided ID.
UpdateOrg(ctx context.Context, token string, org Org) (Org, error)
// ViewOrg retrieves data about the org identified by ID.
ViewOrg(ctx context.Context, token, id string) (Org, error)
// ListOrgs retrieves orgs.
ListOrgs(ctx context.Context, token string, pm apiutil.PageMetadata) (OrgsPage, error)
// RemoveOrgs removes the orgs identified with the provided IDs.
RemoveOrgs(ctx context.Context, token string, ids ...string) error
// GetOwnerIDByOrgID returns an owner ID for a given org ID.
GetOwnerIDByOrgID(ctx context.Context, orgID string) (string, error)
// Backup retrieves all orgs and org memberships. Only accessible by admin.
Backup(ctx context.Context, token string) (Backup, error)
// Restore adds orgs and org memberships from a backup. Only accessible by admin.
Restore(ctx context.Context, token string, backup Backup) error
}
Orgs specifies an API that must be fullfiled by the domain service implementation, and all of its decorators (e.g. logging & metrics).
type OrgsPage ¶
type OrgsPage struct {
apiutil.PageMetadata
Orgs []Org
}
OrgsPage contains page related metadata as well as list of orgs that belong to this page.
type RolesRepository ¶
type RolesRepository interface {
// SaveRole saves the user role.
SaveRole(ctx context.Context, id, role string) error
// RetrieveRole retrieves the user role.
RetrieveRole(ctx context.Context, id string) (string, error)
// UpdateRole updates the user role.
UpdateRole(ctx context.Context, id, role string) error
// RemoveRole removes the user role.
RemoveRole(ctx context.Context, id string) error
}
type Service ¶
Service specifies an API that must be fulfilled by the domain service implementation, and all of its decorators (e.g. logging & metrics). Token is a string value of the actual Key and is used to authenticate an Auth service request.
func New ¶
func New(orgs OrgRepository, tc protomfx.ThingsServiceClient, uc protomfx.UsersServiceClient, keys KeyRepository, roles RolesRepository, memberships OrgMembershipsRepository, idp uuid.IDProvider, tokenizer Tokenizer, duration time.Duration) Service
New instantiates the auth service implementation.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package api contains implementation of Auth service HTTP API.
|
Package api contains implementation of Auth service HTTP API. |
|
grpc
Package grpc contains implementation of Auth service gRPC API.
|
Package grpc contains implementation of Auth service gRPC API. |
|
Package postgres contains Key repository implementations using PostgreSQL as the underlying database.
|
Package postgres contains Key repository implementations using PostgreSQL as the underlying database. |
|
Package tracing contains middlewares that will add spans to existing traces.
|
Package tracing contains middlewares that will add spans to existing traces. |