multitenancy

package
v0.0.0-...-8122643 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OpAdd             string = "add"
	OpDelete          string = "delete"
	OpActivate        string = "activate"
	OpDeactivate      string = "deactivate"
	OpSetPath         string = "set_path"
	OpSetShadowPath   string = "set_shadow_path"
	OpSetRole         string = "set_role"
	OpSetCustomer     string = "set_customer"
	OpChangePoolOrDb  string = "change_pool_or_db"
	OpAddIpAddress    string = "add_ip_address"
	OpDeleteIpAddress string = "delete_ip_address"
	OpSetDbRole       string = "set_db_role"
	OpSetPathBlocked  string = "set_path_blocked"
)
View Source
const (
	ErrorCodeTenancyConflictRole           = "tenancy_conflict_role"
	ErrorCodeTenancyConflictPath           = "tenancy_conflict_path"
	ErrorCodeTenancyNotFound               = "tenancy_not_found"
	ErrorCodeTenancyDbInitializationFailed = "tenancy_db_initialization_failed"
	ErrorCodeForeignDatabase               = "foreign_tenancy_database"
	ErrorCodeNoDbserviceInPool             = "no_db_service_in_pool"
)
View Source
const PubsubTopicName = "tenancy"
View Source
const (
	TENANCY_DATABASE_ROLE string = "tenancy_db"
)

Variables

View Source
var ErrorDescriptions = map[string]string{
	ErrorCodeTenancyNotFound:               "Tenancy not found.",
	ErrorCodeTenancyConflictRole:           "Tenancy with such role already exists for that customer.",
	ErrorCodeTenancyConflictPath:           "Tenancy with such path already exists in that pool.",
	ErrorCodeTenancyDbInitializationFailed: "Failed to initialize tenancy database.",
	ErrorCodeForeignDatabase:               "Database does not belong to this tenancy.",
	ErrorCodeNoDbserviceInPool:             "Pool does not contain service for tenancy database.",
}

Functions

func CheckTenancyDatabase

func CheckTenancyDatabase(ctx op_context.Context, database db.DB, tenancyId string) error

func CloseTenancyDb

func CloseTenancyDb(tenancy Tenancy)

func ContextTenancy

func ContextTenancy(ctx TenancyContext) string

func ContextTenancyDisplay

func ContextTenancyDisplay(ctx TenancyContext) string

func ContextTenancyPath

func ContextTenancyPath(ctx TenancyContext) string

func ContextTenancyShadowPath

func ContextTenancyShadowPath(ctx TenancyContext) string

func DbInternalModels

func DbInternalModels() []interface{}

func DbModels

func DbModels() []interface{}

func IsMultiTenancy

func IsMultiTenancy(m Multitenancy) bool

func ParseTenancyDisplay

func ParseTenancyDisplay(display string) (string, string, *validator.ValidationError)

func QueryDbModels

func QueryDbModels() []interface{}

func TenancyDisplay

func TenancyDisplay(t Tenancy) string

func TenancySelector

func TenancySelector(customer string, role string) string

func UpgradeTenancyDatabase

func UpgradeTenancyDatabase(ctx op_context.Context, tenancy Tenancy, dbModels *TenancyDbModels) error

func UpgradeTenancyDatabases

func UpgradeTenancyDatabases(ctx op_context.Context, multitenancy Multitenancy, dbModels *TenancyDbModels) error

Types

type BlockPathCmd

type BlockPathCmd struct {
	Block bool                 `json:"block" long:"block" description:"Block or unblock tenancy path"`
	Mode  TenancyBlockPathMode `json:"mode" long:"mode" description:"Mode: default | shadow | both"`
}

type IpAddressCmd

type IpAddressCmd struct {
	Ip  string `json:"ip" validate:"required,ip" vmessage:"Invalid IP address" long:"ip" description:"IP address" required:"true"`
	Tag string `` /* 129-byte string literal not displayed */
}

type Multitenancy

type Multitenancy interface {

	// Check if multiple tenancies are enabled
	IsMultiTenancy() bool

	// Get all tenancies
	Tenancies() []Tenancy

	// Find tenancy by ID.
	Tenancy(id string) (Tenancy, error)

	// Find tenancy by path.
	TenancyByPath(path string) (Tenancy, error)

	// Find tenancy by shadow path.
	TenancyByShadowPath(path string) (Tenancy, error)

	// Load tenancy.
	LoadTenancy(ctx op_context.Context, id string) (Tenancy, error)

	// Unload tenancy.
	UnloadTenancy(id string)

	// Create tenancy
	CreateTenancy(ctx op_context.Context, data *TenancyData) (*TenancyItem, error)

	// Get tenancy controller.
	TenancyController() TenancyController

	// Check if ip address is in the list of tenancy addresses.
	HasIpAddressByPath(path string, ipAddress string, tag string) bool

	// Close tenancies, e.g. close tenancy databases.
	Close()
}

type OpLogTenancy

type OpLogTenancy struct {
	oplog.OplogBase
	Customer        string `gorm:"index" json:"customer"`
	TenancyId       string `gorm:"index" json:"tenancy_id"`
	Role            string `gorm:"index" json:"role"`
	Path            string `gorm:"index" json:"path"`
	ShadowPath      string `gorm:"index" json:"shadow_path"`
	DbName          string `gorm:"index" json:"db_name"`
	Pool            string `gorm:"index" json:"pool"`
	IpAddress       string `gorm:"index" json:"ip_address"`
	IpAddressTag    string `gorm:"index" json:"ip_address_tag"`
	DbRole          string `gorm:"index" json:"db_role"`
	BlockPath       bool   `gorm:"index" json:"block_path"`
	BlockShadowPath bool   `gorm:"index" json:"block_shadow_path"`
}

type PubsubNotification

type PubsubNotification struct {
	Tenancy   string `json:"tenancy"`
	Operation string `json:"operation"`
}

func NewPubsubNotification

func NewPubsubNotification() *PubsubNotification

type PubsubTopic

type PubsubTopic struct {
	*pubsub_subscriber.TopicBase[*PubsubNotification]
}

type Tenancy

type Tenancy interface {
	common.Object
	common.WithActive
	common.WithDescription

	Path() string
	ShadowPath() string
	CustomerId() string
	CustomerDisplay() string
	Role() string
	DbName() string
	DbRole() string
	PoolId() string

	Db() db.DB
	Pool() pool.Pool
	Cache() cache.Cache

	IsBlockedPath() bool
	IsBlockedShadowPath() bool
}

type TenancyBlockPathMode

type TenancyBlockPathMode string
const (
	TenancyBlockPathModeDefault TenancyBlockPathMode = "default"
	TenancyBlockPathModeShadow  TenancyBlockPathMode = "shadow"
	TenancyBlockPathModeBoth    TenancyBlockPathMode = "both"
)

type TenancyContext

type TenancyContext interface {
	app_with_pools.Context
	WithTenancy
}

type TenancyContextBase

type TenancyContextBase struct {
	app_with_pools.ContextBase
	Tenancy Tenancy
}

func NewContext

func NewContext(fromCtx ...op_context.Context) *TenancyContextBase

func NewInitContext

func NewInitContext(app app_context.Context, log logger.Logger, db db.DB) *TenancyContextBase

func (*TenancyContextBase) Db

func (u *TenancyContextBase) Db() db.DB

func (*TenancyContextBase) GetTenancy

func (u *TenancyContextBase) GetTenancy() Tenancy

func (*TenancyContextBase) Pool

func (u *TenancyContextBase) Pool() pool.Pool

func (*TenancyContextBase) SetTenancy

func (u *TenancyContextBase) SetTenancy(tenancy Tenancy)

type TenancyController

type TenancyController interface {
	generic_error.ErrorsExtender
	Add(ctx op_context.Context, tenancy *TenancyData) (*TenancyItem, error)
	Find(ctx op_context.Context, id string, idIsDisplay ...bool) (*TenancyItem, error)
	List(ctx op_context.Context, filter *db.Filter) ([]*TenancyItem, int64, error)

	Exists(ctx op_context.Context, fields db.Fields) (bool, error)
	Delete(ctx op_context.Context, id string, withDb bool, idIsDisplay ...bool) error

	SetPath(ctx op_context.Context, id string, path string, idIsDisplay ...bool) error
	SetShadowPath(ctx op_context.Context, id string, path string, idIsDisplay ...bool) error
	SetCustomer(ctx op_context.Context, id string, customerId string, idIsDisplay ...bool) error
	SetRole(ctx op_context.Context, id string, role string, idIsDisplay ...bool) error
	ChangePoolOrDb(ctx op_context.Context, id string, poolId string, dbName string, idIsDisplay ...bool) error
	Activate(ctx op_context.Context, id string, idIsDisplay ...bool) error
	Deactivate(ctx op_context.Context, id string, idIsDisplay ...bool) error
	SetDbRole(ctx op_context.Context, id string, dbRole string, idIsDisplay ...bool) error

	SetPathBlocked(ctx op_context.Context, id string, blocked bool, mode TenancyBlockPathMode, idIsDisplay ...bool) error

	ListIpAddresses(ctx op_context.Context, filter *db.Filter) ([]*TenancyIpAddressItem, int64, error)
	DeleteIpAddress(ctx op_context.Context, id string, ipAddress string, tag string, idIsDisplay ...bool) error
	AddIpAddress(ctx op_context.Context, id string, ipAddress string, tag string, idIsDisplay ...bool) error
}

type TenancyDb

type TenancyDb struct {
	common.ObjectBase
	common.WithActiveBase
	TenancyData
}

func (TenancyDb) TableName

func (TenancyDb) TableName() string

type TenancyDbModels

type TenancyDbModels struct {
	DbModels            []interface{}
	PartitionedDbModels []interface{}
}

type TenancyIpAddress

type TenancyIpAddress struct {
	common.ObjectBase
	TenancyId string `gorm:"index" json:"tenancy_id"`
	Ip        string `gorm:"index" json:"ip"`
	Tag       string `gorm:"index" json:"tag"`
}

type TenancyIpAddressItem

type TenancyIpAddressItem struct {
	TenancyIpAddress `source:"tenancy_ip_addresses"`
	PoolName         string `json:"pool_name" source:"pools.name" gorm:"index" display:"Pool"`
	CustomerLogin    string `json:"customer_login" source:"customers.login" gorm:"index" display:"Customer"`
	TenancyRole      string `json:"tenancy_role" source:"tenancies.role" gorm:"index" display:"Tenancy role"`
}

func ListTenancyIpAddresses

func ListTenancyIpAddresses(ctrl TenancyController, ctx op_context.Context, id string, filter *db.Filter, idIsDisplay ...bool) ([]*TenancyIpAddressItem, int64, error)

type TenancyItem

type TenancyItem struct {
	TenancyDb     `source:"tenancies"`
	CustomerLogin string `json:"customer_login" source:"customers.login" gorm:"index" display:"Customer"`
	PoolName      string `json:"pool_name" source:"pools.name" gorm:"index" display:"Pool"`
}

func FindTenancy

func FindTenancy(ctrl TenancyController, ctx op_context.Context, id string, idIsDisplay ...bool) (*TenancyItem, error)

func TenancyId

func TenancyId(ctrl TenancyController, ctx op_context.Context, id string, idIsDisplay ...bool) (string, *TenancyItem, error)

func (*TenancyItem) CustomerDisplay

func (t *TenancyItem) CustomerDisplay() string

func (TenancyItem) TableName

func (TenancyItem) TableName() string

type TenancyMeta

type TenancyMeta struct {
	common.ObjectBase
}

type WithBlockPath

type WithBlockPath struct {
	BLOCK_PATH        bool `json:"block_path" gorm:"index;column:block_path" display:"Block tenancy path"`
	BLOCK_SHADOW_PATH bool `json:"block_shadow_path" gorm:"index;column:block_shadow_path" display:"Block shadow tenancy path"`
}

func (*WithBlockPath) IsBlockedPath

func (t *WithBlockPath) IsBlockedPath() bool

func (*WithBlockPath) IsBlockedShadowPath

func (t *WithBlockPath) IsBlockedShadowPath() bool

type WithCustomerId

type WithCustomerId struct {
	CUSTOMER_ID string `` /* 243-byte string literal not displayed */
}

func (*WithCustomerId) CustomerId

func (t *WithCustomerId) CustomerId() string

type WithDbRole

type WithDbRole struct {
	DB_ROLE string `` /* 216-byte string literal not displayed */
}

func (*WithDbRole) DbRole

func (t *WithDbRole) DbRole() string

func (*WithDbRole) SetDbRole

func (t *WithDbRole) SetDbRole(role string)

type WithPath

type WithPath struct {
	PATH        string `` /* 163-byte string literal not displayed */
	SHADOW_PATH string `` /* 185-byte string literal not displayed */
}

func (*WithPath) Path

func (t *WithPath) Path() string

func (*WithPath) SetPath

func (t *WithPath) SetPath(path string)

func (*WithPath) SetShadowPath

func (t *WithPath) SetShadowPath(path string)

func (*WithPath) ShadowPath

func (t *WithPath) ShadowPath() string

type WithPoolAndDb

type WithPoolAndDb struct {
	POOL_ID string `` /* 185-byte string literal not displayed */
	DBNAME  string `` /* 242-byte string literal not displayed */
}

func (*WithPoolAndDb) DbName

func (t *WithPoolAndDb) DbName() string

func (*WithPoolAndDb) PoolId

func (t *WithPoolAndDb) PoolId() string

type WithRole

type WithRole struct {
	ROLE string `` /* 252-byte string literal not displayed */
}

func (*WithRole) Role

func (t *WithRole) Role() string

type WithTenancy

type WithTenancy interface {
	GetTenancy() Tenancy
}

Jump to

Keyboard shortcuts

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