da9ca0c650
Satellites set their configuration values to default values using cfgstruct, however, it turns out our tests don't test these values at all! Instead, they have a completely separate definition system that is easy to forget about. As is to be expected, these values have drifted, and it appears in a few cases test planet is testing unreasonable values that we won't see in production, or perhaps worse, features enabled in production were missed and weren't enabled in testplanet. This change makes it so all values are configured the same, systematic way, so it's easy to see when test values are different than dev values or release values, and it's less hard to forget to enable features in testplanet. In terms of reviewing, this change should be actually fairly easy to review, considering private/testplanet/satellite.go keeps the current config system and the new one and confirms that they result in identical configurations, so you can be certain that nothing was missed and the config is all correct. You can also check the config lock to see what actual config values changed. Change-Id: I6715d0794887f577e21742afcf56fd2b9d12170e
120 lines
4.2 KiB
Go
120 lines
4.2 KiB
Go
// Copyright (C) 2019 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package console
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"time"
|
|
|
|
"storj.io/common/memory"
|
|
"storj.io/common/uuid"
|
|
)
|
|
|
|
// Projects exposes methods to manage Project table in database.
|
|
//
|
|
// architecture: Database
|
|
type Projects interface {
|
|
// GetAll is a method for querying all projects from the database.
|
|
GetAll(ctx context.Context) ([]Project, error)
|
|
// GetCreatedBefore retrieves all projects created before provided date.
|
|
GetCreatedBefore(ctx context.Context, before time.Time) ([]Project, error)
|
|
// GetByUserID returns a list of projects where user is a project member.
|
|
GetByUserID(ctx context.Context, userID uuid.UUID) ([]Project, error)
|
|
// GetOwn returns a list of projects where user is an owner.
|
|
GetOwn(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
|
|
// List returns paginated projects, created before provided timestamp.
|
|
List(ctx context.Context, offset int64, limit int, before time.Time) (ProjectsPage, error)
|
|
// ListByOwnerID is a method for querying all projects from the database by ownerID. It also includes the number of members for each project.
|
|
ListByOwnerID(ctx context.Context, userID uuid.UUID, cursor ProjectsCursor) (ProjectsPage, error)
|
|
|
|
// UpdateRateLimit is a method for updating projects rate limit.
|
|
UpdateRateLimit(ctx context.Context, id uuid.UUID, newLimit int) error
|
|
|
|
// GetMaxBuckets is a method to get the maximum number of buckets allowed for the project
|
|
GetMaxBuckets(ctx context.Context, id uuid.UUID) (*int, error)
|
|
// UpdateBucketLimit is a method for updating projects bucket limit.
|
|
UpdateBucketLimit(ctx context.Context, id uuid.UUID, newLimit int) error
|
|
}
|
|
|
|
// UsageLimitsConfig is a configuration struct for default per-project usage limits.
|
|
type UsageLimitsConfig struct {
|
|
DefaultStorageLimit memory.Size `help:"the default storage usage limit" default:"50.00GB" testDefault:"25.00 GB"`
|
|
DefaultBandwidthLimit memory.Size `help:"the default bandwidth usage limit" default:"50.00GB" testDefault:"25.00 GB"`
|
|
}
|
|
|
|
// Project is a database object that describes Project entity.
|
|
type Project struct {
|
|
ID uuid.UUID `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
Description string `json:"description"`
|
|
PartnerID uuid.UUID `json:"partnerId"`
|
|
OwnerID uuid.UUID `json:"ownerId"`
|
|
RateLimit *int `json:"rateLimit"`
|
|
MaxBuckets *int `json:"maxBuckets"`
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
MemberCount int `json:"memberCount"`
|
|
StorageLimit *memory.Size `json:"storageLimit"`
|
|
BandwidthLimit *memory.Size `json:"bandwidthLimit"`
|
|
}
|
|
|
|
// ProjectInfo holds data needed to create/update Project.
|
|
type ProjectInfo struct {
|
|
Name string `json:"name"`
|
|
Description string `json:"description"`
|
|
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
}
|
|
|
|
// ProjectsCursor holds info for project
|
|
// cursor pagination.
|
|
type ProjectsCursor struct {
|
|
Limit int
|
|
Page int
|
|
}
|
|
|
|
// ProjectsPage returns paginated projects,
|
|
// providing next offset if there are more projects
|
|
// to retrieve.
|
|
type ProjectsPage struct {
|
|
Projects []Project
|
|
Next bool
|
|
NextOffset int64
|
|
|
|
Limit int
|
|
Offset int64
|
|
|
|
PageCount int
|
|
CurrentPage int
|
|
TotalCount int64
|
|
}
|
|
|
|
// ValidateNameAndDescription validates project name and description strings.
|
|
// Project name must have more than 0 and less than 21 symbols.
|
|
// Project description can't have more than hundred symbols.
|
|
func ValidateNameAndDescription(name string, description string) error {
|
|
if len(name) == 0 {
|
|
return errors.New("project name can't be empty")
|
|
}
|
|
|
|
if len(name) > 20 {
|
|
return errors.New("project name can't have more than 20 symbols")
|
|
}
|
|
|
|
if len(description) > 100 {
|
|
return errors.New("project description can't have more than 100 symbols")
|
|
}
|
|
|
|
return nil
|
|
}
|