Documentation ¶
Index ¶
- Constants
- Variables
- func WithAuth(ctx context.Context, auth Authorization) context.Context
- func WithAuthFailure(ctx context.Context, err error) context.Context
- type APIKey
- type APIKeyInfo
- type APIKeys
- type Authorization
- type CreateUser
- type DB
- type DBTx
- type Pagination
- type Project
- type ProjectInfo
- type ProjectMember
- type ProjectMemberOrder
- type ProjectMembers
- type Projects
- type RegistrationSecret
- type RegistrationToken
- type RegistrationTokens
- type Service
- func (s *Service) ActivateAccount(ctx context.Context, activationToken string) (err error)
- func (s *Service) AddProjectMembers(ctx context.Context, projectID uuid.UUID, emails []string) (users []*User, err error)
- func (s *Service) Authorize(ctx context.Context) (a Authorization, err error)
- func (s *Service) ChangePassword(ctx context.Context, pass, newPass string) (err error)
- func (s *Service) CreateAPIKey(ctx context.Context, projectID uuid.UUID, name string) (*APIKeyInfo, *APIKey, error)
- func (s *Service) CreateProject(ctx context.Context, projectInfo ProjectInfo) (p *Project, err error)
- func (s *Service) CreateRegToken(ctx context.Context, projLimit int) (*RegistrationToken, error)
- func (s *Service) CreateUser(ctx context.Context, user CreateUser, tokenSecret RegistrationSecret) (u *User, err error)
- func (s *Service) DeleteAPIKeys(ctx context.Context, ids []uuid.UUID) (err error)
- func (s *Service) DeleteAccount(ctx context.Context, password string) (err error)
- func (s *Service) DeleteProject(ctx context.Context, projectID uuid.UUID) (err error)
- func (s *Service) DeleteProjectMembers(ctx context.Context, projectID uuid.UUID, emails []string) (err error)
- func (s *Service) GenerateActivationToken(ctx context.Context, id uuid.UUID, email string) (token string, err error)
- func (s *Service) GetAPIKeyInfo(ctx context.Context, id uuid.UUID) (*APIKeyInfo, error)
- func (s *Service) GetAPIKeysInfoByProjectID(ctx context.Context, projectID uuid.UUID) (info []APIKeyInfo, err error)
- func (s *Service) GetProject(ctx context.Context, projectID uuid.UUID) (p *Project, err error)
- func (s *Service) GetProjectMembers(ctx context.Context, projectID uuid.UUID, pagination Pagination) (pm []ProjectMember, err error)
- func (s *Service) GetUser(ctx context.Context, id uuid.UUID) (u *User, err error)
- func (s *Service) GetUsersProjects(ctx context.Context) (ps []Project, err error)
- func (s *Service) Token(ctx context.Context, email, password string) (token string, err error)
- func (s *Service) UpdateAccount(ctx context.Context, info UserInfo) (err error)
- func (s *Service) UpdateProject(ctx context.Context, projectID uuid.UUID, description string) (p *Project, err error)
- type Signer
- type User
- type UserInfo
- type UserStatus
- type Users
Constants ¶
const ( // DefaultPasswordCost is the hashing complexity DefaultPasswordCost = bcrypt.DefaultCost // TestPasswordCost is the hashing complexity to use for testing TestPasswordCost = bcrypt.MinCost )
Variables ¶
var ErrNoMembership = errs.Class("no membership error")
ErrNoMembership is error type of not belonging to a specific project
ErrUnauthorized is error class for authorization related errors
var ErrValidation = errs.Class("validation error")
ErrValidation validation related error class
Functions ¶
Types ¶
type APIKey ¶
type APIKey [24]byte
APIKey is an api key type
func APIKeyFromBase64 ¶
APIKeyFromBase64 creates new key from base64 string
func APIKeyFromBytes ¶
APIKeyFromBytes creates new key from byte slice
type APIKeyInfo ¶
type APIKeyInfo struct { ID uuid.UUID `json:"id"` // Fk on project ProjectID uuid.UUID `json:"projectId"` Name string `json:"name"` CreatedAt time.Time `json:"createdAt"` }
APIKeyInfo describing api key model in the database
type APIKeys ¶
type APIKeys interface { // GetByProjectID retrieves list of APIKeys for given projectID GetByProjectID(ctx context.Context, projectID uuid.UUID) ([]APIKeyInfo, error) // Get retrieves APIKeyInfo with given ID Get(ctx context.Context, id uuid.UUID) (*APIKeyInfo, error) //GetByKey retrieves APIKeyInfo for given key GetByKey(ctx context.Context, key APIKey) (*APIKeyInfo, error) // Create creates and stores new APIKeyInfo Create(ctx context.Context, key APIKey, info APIKeyInfo) (*APIKeyInfo, error) // Update updates APIKeyInfo in store Update(ctx context.Context, key APIKeyInfo) error // Delete deletes APIKeyInfo from store Delete(ctx context.Context, id uuid.UUID) error }
APIKeys is interface for working with api keys store
type Authorization ¶
type Authorization struct { User User Claims consoleauth.Claims }
Authorization contains auth info of authorized User
type CreateUser ¶
CreateUser struct holds info for User creation.
func (*CreateUser) IsValid ¶
func (user *CreateUser) IsValid() error
IsValid checks CreateUser validity and returns error describing whats wrong.
type DB ¶
type DB interface { // Users is a getter for Users repository Users() Users // Projects is a getter for Projects repository Projects() Projects // ProjectMembers is a getter for ProjectMembers repository ProjectMembers() ProjectMembers // APIKeys is a getter for APIKeys repository APIKeys() APIKeys // BucketUsage is a getter for accounting.BucketUsage repository BucketUsage() accounting.BucketUsage // RegistrationTokens is a getter for RegistrationTokens repository RegistrationTokens() RegistrationTokens // BeginTransaction is a method for opening transaction BeginTx(ctx context.Context) (DBTx, error) }
DB contains access to different satellite databases
type DBTx ¶
type DBTx interface { DB // CommitTransaction is a method for committing and closing transaction Commit() error // RollbackTransaction is a method for rollback and closing transaction Rollback() error }
DBTx extends Database with transaction scope
type Pagination ¶
type Pagination struct { Limit int Offset int64 Search string Order ProjectMemberOrder }
Pagination defines pagination, filtering and sorting rules
type Project ¶
type Project struct { ID uuid.UUID `json:"id"` Name string `json:"name"` Description string `json:"description"` CreatedAt time.Time `json:"createdAt"` }
Project is a database object that describes Project entity
type ProjectInfo ¶
type ProjectInfo struct { Name string `json:"name"` Description string `json:"description"` CreatedAt time.Time `json:"createdAt"` }
ProjectInfo holds data needed to create/update Project
type ProjectMember ¶
type ProjectMember struct { // FK on Users table. MemberID uuid.UUID // FK on Projects table. ProjectID uuid.UUID CreatedAt time.Time }
ProjectMember is a database object that describes ProjectMember entity.
type ProjectMemberOrder ¶
type ProjectMemberOrder int8
ProjectMemberOrder is used for querying project members in specified order
const ( // Name indicates that we should order by full name Name ProjectMemberOrder = 1 // Email indicates that we should order by email Email ProjectMemberOrder = 2 // Created indicates that we should order by created date Created ProjectMemberOrder = 3 )
type ProjectMembers ¶
type ProjectMembers interface { // GetByMemberID is a method for querying project members from the database by memberID. GetByMemberID(ctx context.Context, memberID uuid.UUID) ([]ProjectMember, error) // GetByProjectID is a method for querying project members from the database by projectID, offset and limit. GetByProjectID(ctx context.Context, projectID uuid.UUID, pagination Pagination) ([]ProjectMember, error) // Insert is a method for inserting project member into the database. Insert(ctx context.Context, memberID, projectID uuid.UUID) (*ProjectMember, error) // Delete is a method for deleting project member by memberID and projectID from the database. Delete(ctx context.Context, memberID, projectID uuid.UUID) error }
ProjectMembers exposes methods to manage ProjectMembers table in database.
type Projects ¶
type Projects interface { // GetAll is a method for querying all projects from the database. GetAll(ctx context.Context) ([]Project, error) // GetByUserID is a method for querying all projects from the database by userID. GetByUserID(ctx context.Context, userID uuid.UUID) ([]Project, error) // Get is a method for querying project from the database by id. Get(ctx context.Context, id uuid.UUID) (*Project, error) // Insert is a method for inserting project into the database. Insert(ctx context.Context, project *Project) (*Project, error) // Delete is a method for deleting project by Id from the database. Delete(ctx context.Context, id uuid.UUID) error // Update is a method for updating project entity. Update(ctx context.Context, project *Project) error }
Projects exposes methods to manage Project table in database.
type RegistrationSecret ¶
type RegistrationSecret [32]byte
RegistrationSecret stores secret of registration token
func NewRegistrationSecret ¶
func NewRegistrationSecret() (RegistrationSecret, error)
NewRegistrationSecret creates new registration secret
func RegistrationSecretFromBase64 ¶
func RegistrationSecretFromBase64(s string) (RegistrationSecret, error)
RegistrationSecretFromBase64 creates new registration secret from base64 string
func (RegistrationSecret) String ¶
func (secret RegistrationSecret) String() string
String implements Stringer
type RegistrationToken ¶
type RegistrationToken struct { // Secret is PK of the table and keeps unique value forRegToken Secret RegistrationSecret // OwnerID stores current token owner ID OwnerID *uuid.UUID // ProjectLimit defines how many projects user is able to create ProjectLimit int `json:"projectLimit"` CreatedAt time.Time `json:"createdAt"` }
RegistrationToken describing api key model in the database
type RegistrationTokens ¶
type RegistrationTokens interface { // Create creates new registration token Create(ctx context.Context, projectLimit int) (*RegistrationToken, error) // GetBySecret retrieves RegTokenInfo with given Secret GetBySecret(ctx context.Context, secret RegistrationSecret) (*RegistrationToken, error) // GetByOwnerID retrieves RegTokenInfo by ownerID GetByOwnerID(ctx context.Context, ownerID uuid.UUID) (*RegistrationToken, error) // UpdateOwner updates registration token's owner UpdateOwner(ctx context.Context, secret RegistrationSecret, ownerID uuid.UUID) error }
RegistrationTokens is interface for working with registration tokens TODO: remove after vanguard release
type Service ¶
type Service struct { Signer // contains filtered or unexported fields }
Service is handling accounts related logic
func NewService ¶
NewService returns new instance of Service
func (*Service) ActivateAccount ¶
ActivateAccount - is a method for activating user account after registration
func (*Service) AddProjectMembers ¶
func (s *Service) AddProjectMembers(ctx context.Context, projectID uuid.UUID, emails []string) (users []*User, err error)
AddProjectMembers adds users by email to given project
func (*Service) Authorize ¶
func (s *Service) Authorize(ctx context.Context) (a Authorization, err error)
Authorize validates token from context and returns authorized Authorization
func (*Service) ChangePassword ¶
ChangePassword updates password for a given user
func (*Service) CreateAPIKey ¶
func (s *Service) CreateAPIKey(ctx context.Context, projectID uuid.UUID, name string) (*APIKeyInfo, *APIKey, error)
CreateAPIKey creates new api key
func (*Service) CreateProject ¶
func (s *Service) CreateProject(ctx context.Context, projectInfo ProjectInfo) (p *Project, err error)
CreateProject is a method for creating new project
func (*Service) CreateRegToken ¶
CreateRegToken creates new registration token. Needed for testing TODO: remove after vanguard release
func (*Service) CreateUser ¶
func (s *Service) CreateUser(ctx context.Context, user CreateUser, tokenSecret RegistrationSecret) (u *User, err error)
CreateUser gets password hash value and creates new inactive User
func (*Service) DeleteAPIKeys ¶
DeleteAPIKeys deletes api key by id
func (*Service) DeleteAccount ¶
DeleteAccount deletes User
func (*Service) DeleteProject ¶
DeleteProject is a method for deleting project by id
func (*Service) DeleteProjectMembers ¶
func (s *Service) DeleteProjectMembers(ctx context.Context, projectID uuid.UUID, emails []string) (err error)
DeleteProjectMembers removes users by email from given project
func (*Service) GenerateActivationToken ¶
func (s *Service) GenerateActivationToken(ctx context.Context, id uuid.UUID, email string) (token string, err error)
GenerateActivationToken - is a method for generating activation token
func (*Service) GetAPIKeyInfo ¶
GetAPIKeyInfo retrieves api key by id
func (*Service) GetAPIKeysInfoByProjectID ¶
func (s *Service) GetAPIKeysInfoByProjectID(ctx context.Context, projectID uuid.UUID) (info []APIKeyInfo, err error)
GetAPIKeysInfoByProjectID retrieves all api keys for a given project
func (*Service) GetProject ¶
GetProject is a method for querying project by id
func (*Service) GetProjectMembers ¶
func (s *Service) GetProjectMembers(ctx context.Context, projectID uuid.UUID, pagination Pagination) (pm []ProjectMember, err error)
GetProjectMembers returns ProjectMembers for given Project
func (*Service) GetUsersProjects ¶
GetUsersProjects is a method for querying all projects
func (*Service) UpdateAccount ¶
UpdateAccount updates User
type User ¶
type User struct { ID uuid.UUID `json:"id"` FullName string `json:"fullName"` ShortName string `json:"shortName"` Email string `json:"email"` PasswordHash []byte `json:"passwordHash"` Status UserStatus `json:"status"` CreatedAt time.Time `json:"createdAt"` }
User is a database object that describes User entity.
type UserInfo ¶
type UserInfo struct { FullName string `json:"fullName"` ShortName string `json:"shortName"` Email string `json:"email"` }
UserInfo holds User updatable data.
type UserStatus ¶
type UserStatus int
UserStatus - is used to indicate status of the users account
const ( // Inactive is a user status that he receives after registration Inactive UserStatus = 0 // Active is a user status that he receives after account activation Active UserStatus = 1 // Deleted is a user status that he receives after deleting account Deleted UserStatus = 2 )
type Users ¶
type Users interface { // Get is a method for querying user from the database by id. Get(ctx context.Context, id uuid.UUID) (*User, error) // GetByEmail is a method for querying user by email from the database. GetByEmail(ctx context.Context, email string) (*User, error) // Insert is a method for inserting user into the database. Insert(ctx context.Context, user *User) (*User, error) // Delete is a method for deleting user by Id from the database. Delete(ctx context.Context, id uuid.UUID) error // Update is a method for updating user entity. Update(ctx context.Context, user *User) error }
Users exposes methods to manage User table in database.