Documentation ¶
Index ¶
- Constants
- Variables
- func ApplyMigrationsForTenantFixture(t *testing.T, ctx context.Context, dbConnectionPool db.DBConnectionPool, ...)
- func AssertRegisteredAssetsFixture(t *testing.T, ctx context.Context, dbConnectionPool db.DBConnectionPool, ...)
- func AssertRegisteredUserFixture(t *testing.T, ctx context.Context, dbConnectionPool db.DBConnectionPool, ...)
- func AssertRegisteredWalletsFixture(t *testing.T, ctx context.Context, dbConnectionPool db.DBConnectionPool, ...)
- func CheckSchemaExistsFixture(t *testing.T, ctx context.Context, dbConnectionPool db.DBConnectionPool, ...) bool
- func DeleteAllTenantsFixture(t *testing.T, ctx context.Context, adminDBConnectionPool db.DBConnectionPool)
- func LoadDefaultTenantInContext(t *testing.T, dbConnectionPool db.DBConnectionPool) context.Context
- func PrepareDBForTenant(t *testing.T, dbt *dbtest.DB, tenantName string) string
- func SaveTenantInContext(ctx context.Context, t *Tenant) context.Context
- func TenantSchemaMatchTablesFixture(t *testing.T, ctx context.Context, dbConnectionPool db.DBConnectionPool, ...)
- type FilterKey
- type Manager
- func (m *Manager) AddTenant(ctx context.Context, name string) (*Tenant, error)
- func (m *Manager) CreateTenantSchema(ctx context.Context, tenantName string) error
- func (m *Manager) DeactivateTenantDistributionAccount(ctx context.Context, tenantID string) error
- func (m *Manager) DeleteTenantByName(ctx context.Context, name string) error
- func (m *Manager) DropTenantSchema(ctx context.Context, tenantName string) error
- func (m *Manager) GetAllTenants(ctx context.Context, queryParams *QueryParams) ([]Tenant, error)
- func (m *Manager) GetDSNForTenant(ctx context.Context, tenantName string) (string, error)
- func (m *Manager) GetDSNForTenantByID(ctx context.Context, id string) (string, error)
- func (m *Manager) GetDefault(ctx context.Context) (*Tenant, error)
- func (m *Manager) GetTenant(ctx context.Context, queryParams *QueryParams) (*Tenant, error)
- func (m *Manager) GetTenantByID(ctx context.Context, id string) (*Tenant, error)
- func (m *Manager) GetTenantByIDOrName(ctx context.Context, arg string) (*Tenant, error)
- func (m *Manager) GetTenantByName(ctx context.Context, name string) (*Tenant, error)
- func (m *Manager) SetDefault(ctx context.Context, sqlExec db.SQLExecuter, id string) (*Tenant, error)
- func (m *Manager) SoftDeleteTenantByID(ctx context.Context, tenantID string) (*Tenant, error)
- func (m *Manager) UpdateTenantConfig(ctx context.Context, tu *TenantUpdate) (*Tenant, error)
- type ManagerInterface
- type MultiTenantDataSourceRouter
- func (m *MultiTenantDataSourceRouter) AnyDataSource() (db.DBConnectionPool, error)
- func (m *MultiTenantDataSourceRouter) GetAllDataSources() ([]db.DBConnectionPool, error)
- func (m *MultiTenantDataSourceRouter) GetDataSource(ctx context.Context) (db.DBConnectionPool, error)
- func (m *MultiTenantDataSourceRouter) GetDataSourceForTenant(ctx context.Context, currentTenant Tenant) (db.DBConnectionPool, error)
- type Option
- type QueryParams
- type Tenant
- type TenantManagerMock
- func (m *TenantManagerMock) AddTenant(ctx context.Context, name string) (*Tenant, error)
- func (m *TenantManagerMock) CreateTenantSchema(ctx context.Context, name string) error
- func (m *TenantManagerMock) DeactivateTenantDistributionAccount(ctx context.Context, id string) error
- func (m *TenantManagerMock) DeleteTenantByName(ctx context.Context, name string) error
- func (m *TenantManagerMock) DropTenantSchema(ctx context.Context, name string) error
- func (m *TenantManagerMock) GetAllTenants(ctx context.Context, queryParams *QueryParams) ([]Tenant, error)
- func (m *TenantManagerMock) GetDSNForTenant(ctx context.Context, tenantName string) (string, error)
- func (m *TenantManagerMock) GetDSNForTenantByID(ctx context.Context, id string) (string, error)
- func (m *TenantManagerMock) GetDefault(ctx context.Context) (*Tenant, error)
- func (m *TenantManagerMock) GetTenant(ctx context.Context, queryParams *QueryParams) (*Tenant, error)
- func (m *TenantManagerMock) GetTenantByID(ctx context.Context, id string) (*Tenant, error)
- func (m *TenantManagerMock) GetTenantByIDOrName(ctx context.Context, arg string) (*Tenant, error)
- func (m *TenantManagerMock) GetTenantByName(ctx context.Context, name string) (*Tenant, error)
- func (m *TenantManagerMock) SetDefault(ctx context.Context, sqlExec db.SQLExecuter, id string) (*Tenant, error)
- func (m *TenantManagerMock) SoftDeleteTenantByID(ctx context.Context, id string) (*Tenant, error)
- func (m *TenantManagerMock) UpdateTenantConfig(ctx context.Context, tu *TenantUpdate) (*Tenant, error)
- type TenantStatus
- type TenantUpdate
Constants ¶
const ( // MinTenantDistributionAccountAmount is the minimum amount of the native asset that the host distribution account is allowed to // send to the tenant distribution account at a time. It is also used as the default amount to bootstrap a tenant distribution account, // when non is specified. MinTenantDistributionAccountAmount = 5 // MaxTenantDistributionAccountAmount is the maximum amount of the native asset that the host distribution account is allowed to // send to the tenant distribution account at a time. MaxTenantDistributionAccountAmount = 50 )
Variables ¶
var ( ErrTenantDoesNotExist = errors.New("tenant does not exist") ErrDuplicatedTenantName = errors.New("duplicated tenant name") ErrEmptyTenantName = errors.New("tenant name cannot be empty") ErrEmptyUpdateTenant = errors.New("provide at least one field to be updated") ErrTenantNotFoundInContext = errors.New("tenant not found in context") ErrTooManyDefaultTenants = errors.New("too many default tenants. Expected at most one default tenant") )
var ErrNoDataSourcesAvailable = errors.New("no data sources are available")
Functions ¶
func DeleteAllTenantsFixture ¶
func PrepareDBForTenant ¶
func SaveTenantInContext ¶
SaveTenantInContext stores the tenant information in the context.
func TenantSchemaMatchTablesFixture ¶
func TenantSchemaMatchTablesFixture(t *testing.T, ctx context.Context, dbConnectionPool db.DBConnectionPool, schemaName string, tableNames []string)
TenantSchemaMatchTablesFixture asserts if the new tenant database schema has the tables passed by parameter.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func NewManager ¶
func (*Manager) CreateTenantSchema ¶
func (*Manager) DeactivateTenantDistributionAccount ¶
DeactivateTenantDistributionAccount sets a distribution account of status ACTIVE to PENDING_USER_ACTIVATION for the given tenant id, and is only used in the case where the distribution account is of type CircleDBVault.
func (*Manager) DeleteTenantByName ¶
func (*Manager) DropTenantSchema ¶
func (*Manager) GetAllTenants ¶
GetAllTenants returns all tenants in the database.
func (*Manager) GetDSNForTenant ¶
func (*Manager) GetDSNForTenantByID ¶
func (*Manager) GetDefault ¶
GetDefault returns the tenant where is_default is true. Returns an error if more than one tenant is set as default.
func (*Manager) GetTenant ¶
GetTenant is a generic method that fetches a tenant based on queryParams.
func (*Manager) GetTenantByID ¶
func (*Manager) GetTenantByIDOrName ¶
GetTenantByIDOrName returns the tenant with a given id or name.
func (*Manager) GetTenantByName ¶
func (*Manager) SetDefault ¶
func (m *Manager) SetDefault(ctx context.Context, sqlExec db.SQLExecuter, id string) (*Tenant, error)
SetDefault sets the is_default = true for the given tenant id.
func (*Manager) SoftDeleteTenantByID ¶
func (*Manager) UpdateTenantConfig ¶
type ManagerInterface ¶
type ManagerInterface interface { GetDSNForTenant(ctx context.Context, tenantName string) (string, error) GetDSNForTenantByID(ctx context.Context, id string) (string, error) GetAllTenants(ctx context.Context, queryParams *QueryParams) ([]Tenant, error) GetTenant(ctx context.Context, queryParams *QueryParams) (*Tenant, error) GetTenantByID(ctx context.Context, id string) (*Tenant, error) GetTenantByName(ctx context.Context, name string) (*Tenant, error) GetTenantByIDOrName(ctx context.Context, arg string) (*Tenant, error) GetDefault(ctx context.Context) (*Tenant, error) SetDefault(ctx context.Context, sqlExec db.SQLExecuter, id string) (*Tenant, error) AddTenant(ctx context.Context, name string) (*Tenant, error) DeleteTenantByName(ctx context.Context, name string) error CreateTenantSchema(ctx context.Context, tenantName string) error DropTenantSchema(ctx context.Context, tenantName string) error UpdateTenantConfig(ctx context.Context, tu *TenantUpdate) (*Tenant, error) SoftDeleteTenantByID(ctx context.Context, tenantID string) (*Tenant, error) DeactivateTenantDistributionAccount(ctx context.Context, tenantID string) error }
type MultiTenantDataSourceRouter ¶
type MultiTenantDataSourceRouter struct {
// contains filtered or unexported fields
}
func NewMultiTenantDataSourceRouter ¶
func NewMultiTenantDataSourceRouter(tenantManager ManagerInterface) *MultiTenantDataSourceRouter
func (*MultiTenantDataSourceRouter) AnyDataSource ¶
func (m *MultiTenantDataSourceRouter) AnyDataSource() (db.DBConnectionPool, error)
AnyDataSource returns any database connection pool.
func (*MultiTenantDataSourceRouter) GetAllDataSources ¶
func (m *MultiTenantDataSourceRouter) GetAllDataSources() ([]db.DBConnectionPool, error)
GetAllDataSources returns all the database connection pools.
func (*MultiTenantDataSourceRouter) GetDataSource ¶
func (m *MultiTenantDataSourceRouter) GetDataSource(ctx context.Context) (db.DBConnectionPool, error)
func (*MultiTenantDataSourceRouter) GetDataSourceForTenant ¶
func (m *MultiTenantDataSourceRouter) GetDataSourceForTenant( ctx context.Context, currentTenant Tenant, ) (db.DBConnectionPool, error)
GetDataSourceForTenant returns the database connection pool for the given tenant if it exists, otherwise create a new one.
type Option ¶
type Option func(m *Manager)
func WithDatabase ¶
func WithDatabase(dbConnectionPool db.DBConnectionPool) Option
type QueryParams ¶
type Tenant ¶
type Tenant struct { ID string `json:"id" db:"id"` Name string `json:"name" db:"name"` BaseURL *string `json:"base_url" db:"base_url"` SDPUIBaseURL *string `json:"sdp_ui_base_url" db:"sdp_ui_base_url"` Status TenantStatus `json:"status" db:"status"` IsDefault bool `json:"is_default" db:"is_default"` CreatedAt time.Time `json:"created_at" db:"created_at"` UpdatedAt time.Time `json:"updated_at" db:"updated_at"` DeletedAt *time.Time `json:"deleted_at" db:"deleted_at"` // Distribution Account fields: DistributionAccountAddress *string `json:"distribution_account_address" db:"distribution_account_address"` DistributionAccountType schema.AccountType `json:"distribution_account_type" db:"distribution_account_type"` DistributionAccountStatus schema.AccountStatus `json:"distribution_account_status" db:"distribution_account_status"` }
func CreateTenantFixture ¶
type TenantManagerMock ¶
func NewTenantManagerMock ¶
func NewTenantManagerMock(t testInterface) *TenantManagerMock
func (*TenantManagerMock) CreateTenantSchema ¶
func (m *TenantManagerMock) CreateTenantSchema(ctx context.Context, name string) error
func (*TenantManagerMock) DeactivateTenantDistributionAccount ¶
func (m *TenantManagerMock) DeactivateTenantDistributionAccount(ctx context.Context, id string) error
func (*TenantManagerMock) DeleteTenantByName ¶
func (m *TenantManagerMock) DeleteTenantByName(ctx context.Context, name string) error
func (*TenantManagerMock) DropTenantSchema ¶
func (m *TenantManagerMock) DropTenantSchema(ctx context.Context, name string) error
func (*TenantManagerMock) GetAllTenants ¶
func (m *TenantManagerMock) GetAllTenants(ctx context.Context, queryParams *QueryParams) ([]Tenant, error)
func (*TenantManagerMock) GetDSNForTenant ¶
func (*TenantManagerMock) GetDSNForTenantByID ¶
func (*TenantManagerMock) GetDefault ¶
func (m *TenantManagerMock) GetDefault(ctx context.Context) (*Tenant, error)
func (*TenantManagerMock) GetTenant ¶
func (m *TenantManagerMock) GetTenant(ctx context.Context, queryParams *QueryParams) (*Tenant, error)
func (*TenantManagerMock) GetTenantByID ¶
func (*TenantManagerMock) GetTenantByIDOrName ¶
func (*TenantManagerMock) GetTenantByName ¶
func (*TenantManagerMock) SetDefault ¶
func (m *TenantManagerMock) SetDefault(ctx context.Context, sqlExec db.SQLExecuter, id string) (*Tenant, error)
func (*TenantManagerMock) SoftDeleteTenantByID ¶
func (*TenantManagerMock) UpdateTenantConfig ¶
func (m *TenantManagerMock) UpdateTenantConfig(ctx context.Context, tu *TenantUpdate) (*Tenant, error)
type TenantStatus ¶
type TenantStatus string
const ( CreatedTenantStatus TenantStatus = "TENANT_CREATED" ProvisionedTenantStatus TenantStatus = "TENANT_PROVISIONED" ActivatedTenantStatus TenantStatus = "TENANT_ACTIVATED" DeactivatedTenantStatus TenantStatus = "TENANT_DEACTIVATED" )
func (TenantStatus) IsValid ¶
func (s TenantStatus) IsValid() bool
type TenantUpdate ¶
type TenantUpdate struct { ID string BaseURL *string SDPUIBaseURL *string Status *TenantStatus DistributionAccountAddress string DistributionAccountType schema.AccountType DistributionAccountStatus schema.AccountStatus }
func (*TenantUpdate) Validate ¶
func (tu *TenantUpdate) Validate() error