github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/pkg/tenant/entity.go (about) 1 package tenant 2 3 import ( 4 "database/sql" 5 ) 6 7 // Entity represents a Compass tenant. 8 type Entity struct { 9 ID string `db:"id"` 10 Name string `db:"external_name"` 11 ExternalTenant string `db:"external_tenant"` 12 Parent sql.NullString `db:"parent"` 13 Type Type `db:"type"` 14 ProviderName string `db:"provider_name"` 15 Initialized *bool `db:"initialized"` // computed value 16 Status Status `db:"status"` 17 } 18 19 // Type missing godoc 20 type Type string 21 22 const ( 23 // Unknown tenant type is used when the tenant type cannot be determined when the tenant's being created. 24 Unknown Type = "unknown" 25 // Customer tenants can be parents of account tenants. 26 Customer Type = "customer" 27 // Account tenant type may have a parent with type Customer. 28 Account Type = "account" 29 // Subaccount tenants must have a parent of type Account. 30 Subaccount Type = "subaccount" 31 // Organization tenants can be parents of Folder or ResourceGroup tenants. 32 Organization Type = "organization" 33 // Folder tenants must have a parent of type Organization. 34 Folder Type = "folder" 35 // ResourceGroup tenants must have a parent of type Folder or Organization. 36 ResourceGroup Type = "resource-group" 37 ) 38 39 // Status is used to determine if a tenant is currently being used or not. 40 type Status string 41 42 const ( 43 // Active status represents tenants, which are currently active and their resources can be operated. 44 Active Status = "Active" 45 // Inactive status represents tenants, whose resources cannot be operated. 46 Inactive Status = "Inactive" 47 ) 48 49 // EntityCollection is a wrapper type for slice of entities. 50 type EntityCollection []Entity 51 52 // Len returns the current number of entities in the collection. 53 func (a EntityCollection) Len() int { 54 return len(a) 55 } 56 57 // WithStatus sets the provided status to the entity. 58 func (e Entity) WithStatus(status Status) Entity { 59 e.Status = status 60 return e 61 } 62 63 // StrToType returns the tenant Type value of the provided string or "Unknown" if there's no type matching the string. 64 func StrToType(value string) Type { 65 switch value { 66 case string(Account): 67 return Account 68 case string(Customer): 69 return Customer 70 case string(Subaccount): 71 return Subaccount 72 case string(Organization): 73 return Organization 74 case string(Folder): 75 return Folder 76 case string(ResourceGroup): 77 return ResourceGroup 78 default: 79 return Unknown 80 } 81 } 82 83 // TypeToStr returns the string value of the provided tenant Type. 84 func TypeToStr(value Type) string { 85 switch value { 86 case Account: 87 return string(Account) 88 case Customer: 89 return string(Customer) 90 case Subaccount: 91 return string(Subaccount) 92 case Organization: 93 return string(Organization) 94 case Folder: 95 return string(Folder) 96 case ResourceGroup: 97 return string(ResourceGroup) 98 default: 99 return string(Unknown) 100 } 101 }