github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/pkg/resource/resource.go (about)

     1  package resource
     2  
     3  // Type represents a resource type in compass.
     4  type Type string
     5  
     6  const (
     7  	// Destination type represents destination resource.
     8  	Destination Type = "destination"
     9  	// Application type represents application resource.
    10  	Application Type = "application"
    11  	// ApplicationTemplate type represents application template resource.
    12  	ApplicationTemplate Type = "applicationTemplate"
    13  	// ApplicationTemplateVersion type represents application template version resource.
    14  	ApplicationTemplateVersion Type = "applicationTemplateVersion"
    15  	// Runtime type represents runtime resource.
    16  	Runtime Type = "runtime"
    17  	// RuntimeContext type represents runtime context resource.
    18  	RuntimeContext Type = "runtimeContext"
    19  	// LabelDefinition type represents label definition resource.
    20  	LabelDefinition Type = "labelDefinition"
    21  	// Label type represents generic label resource. This resource type does not assume the referenced resource type of the label.
    22  	Label Type = "label"
    23  	// RuntimeLabel type represents runtime label resource.
    24  	RuntimeLabel Type = "runtimeLabel"
    25  	// RuntimeContextLabel type represents runtime context label resource.
    26  	RuntimeContextLabel Type = "runtimeContextLabel"
    27  	// ApplicationLabel type represents application label resource.
    28  	ApplicationLabel Type = "applicationLabel"
    29  	// TenantLabel type represents tenant label resource.
    30  	TenantLabel Type = "tenantLabel"
    31  	// Bundle type represents bundle resource.
    32  	Bundle Type = "bundle"
    33  	// BundleReference type represents bundle reference resource.
    34  	BundleReference Type = "bundleReference"
    35  	// Package type represents package resource.
    36  	Package Type = "package"
    37  	// Product type represents product resource.
    38  	Product Type = "product"
    39  	// Vendor type represents vendor resource.
    40  	Vendor Type = "vendor"
    41  	// Tombstone type represents tombstone resource.
    42  	Tombstone Type = "tombstone"
    43  	// IntegrationSystem type represents integration system resource.
    44  	IntegrationSystem Type = "integrationSystem"
    45  	// SystemAuth type represents system auth resource.
    46  	SystemAuth Type = "systemAuth"
    47  	// FetchRequest type represents generic fetch request resource. This resource does not assume the referenced resource type of the FR.
    48  	FetchRequest Type = "fetchRequest"
    49  	// DocFetchRequest type represents document fetch request resource.
    50  	DocFetchRequest Type = "docFetchRequest"
    51  	// APISpecFetchRequest type represents API specification fetch request resource.
    52  	APISpecFetchRequest Type = "apiSpecFetchRequest"
    53  	// EventSpecFetchRequest type represents Event specification fetch request resource.
    54  	EventSpecFetchRequest Type = "eventSpecFetchRequest"
    55  	// Specification type represents generic specification resource. This resource does not assume the referenced resource type of the Spec.
    56  	Specification Type = "specification"
    57  	// APISpecification type represents API specification resource.
    58  	APISpecification Type = "apiSpecification"
    59  	// EventSpecification type represents Event specification resource.
    60  	EventSpecification Type = "eventSpecification"
    61  	// Document type represents document resource.
    62  	Document Type = "document"
    63  	// BundleInstanceAuth type represents bundle instance auth resource.
    64  	BundleInstanceAuth Type = "bundleInstanceAuth"
    65  	// API type represents api resource.
    66  	API Type = "api"
    67  	// EventDefinition type represents event resource.
    68  	EventDefinition Type = "eventDefinition"
    69  	// AutomaticScenarioAssigment type represents ASA resource.
    70  	AutomaticScenarioAssigment Type = "automaticScenarioAssigment"
    71  	// CertSubjectMapping type represents certificate subject mapping resource
    72  	CertSubjectMapping Type = "certSubjectMapping"
    73  	// Formations type represents formations resource.
    74  	Formations Type = "formations"
    75  	// FormationTemplate type represents formation template resource.
    76  	FormationTemplate Type = "formationTemplate"
    77  	// FormationAssignment type represents formation assignment resource.
    78  	FormationAssignment Type = "formationAssignment"
    79  	// FormationConstraint type represents formation constraint resource.
    80  	FormationConstraint Type = "formationConstraint"
    81  	// FormationTemplateConstraintReference type represents formationTemplate-constraint reference resource.
    82  	FormationTemplateConstraintReference Type = "formationTemplateConstraintReference"
    83  	// Webhook type represents generic webhook resource. This resource does not assume the referenced resource type of the Webhook.
    84  	Webhook Type = "webhook"
    85  	// AppWebhook type represents application webhook resource.
    86  	AppWebhook Type = "appWebhook"
    87  	// RuntimeWebhook type represents runtime webhook resource.
    88  	RuntimeWebhook Type = "runtimeWebhook"
    89  	// Operation type represents operation resource.
    90  	Operation Type = "operation"
    91  	// FormationTemplateWebhook type represents formation template webhook resource.
    92  	FormationTemplateWebhook Type = "formationTemplateWebhook"
    93  	// Tenant type represents tenant resource.
    94  	Tenant Type = "tenant"
    95  	// TenantAccess type represents tenant access resource.
    96  	TenantAccess Type = "tenantAccess"
    97  	// TenantBusinessType type represents tenant business type resource.
    98  	TenantBusinessType Type = "tenantBusinessType"
    99  	// Schema type represents schema resource.
   100  	Schema Type = "schemaMigration"
   101  	// SystemsSync type represents systems synchronization timestamps resource
   102  	SystemsSync Type = "systemsSync"
   103  )
   104  
   105  var ignoredTenantAccessTable = map[Type]string{
   106  	ApplicationTemplateVersion: "application_template_versions",
   107  }
   108  
   109  var tenantAccessTable = map[Type]string{
   110  	// Tables
   111  
   112  	Application:    "tenant_applications",
   113  	Runtime:        "tenant_runtimes",
   114  	RuntimeContext: "tenant_runtime_contexts",
   115  
   116  	// Views
   117  
   118  	Label:                    "labels_tenants",
   119  	ApplicationLabel:         "application_labels_tenants",
   120  	RuntimeLabel:             "runtime_labels_tenants",
   121  	RuntimeContextLabel:      "runtime_contexts_labels_tenants",
   122  	Bundle:                   "bundles_tenants",
   123  	Package:                  "packages_tenants",
   124  	Product:                  "products_tenants",
   125  	Vendor:                   "vendors_tenants",
   126  	Tombstone:                "tombstones_tenants",
   127  	DocFetchRequest:          "document_fetch_requests_tenants",
   128  	APISpecFetchRequest:      "api_specifications_fetch_requests_tenants",
   129  	EventSpecFetchRequest:    "event_specifications_fetch_requests_tenants",
   130  	APISpecification:         "api_specifications_tenants",
   131  	EventSpecification:       "event_specifications_tenants",
   132  	Document:                 "documents_tenants",
   133  	BundleInstanceAuth:       "bundle_instance_auths_tenants",
   134  	API:                      "api_definitions_tenants",
   135  	EventDefinition:          "event_api_definitions_tenants",
   136  	Webhook:                  "webhooks_tenants",
   137  	AppWebhook:               "application_webhooks_tenants",
   138  	RuntimeWebhook:           "runtime_webhooks_tenants",
   139  	FormationTemplateWebhook: "formation_templates_webhooks_tenants",
   140  }
   141  
   142  var tablesWithEmbeddedTenant = map[Type]string{
   143  	// Tables
   144  	FormationTemplate:          "formation_templates",
   145  	AutomaticScenarioAssigment: "automatic_scenario_assignments",
   146  	LabelDefinition:            "label_definitions",
   147  	Label:                      "labels",
   148  	SystemAuth:                 "system_auths",
   149  }
   150  
   151  // IgnoredTenantAccessTable returns the table / view with tenant accesses of the given type.
   152  func (t Type) IgnoredTenantAccessTable() (string, bool) {
   153  	tbl, ok := ignoredTenantAccessTable[t]
   154  	return tbl, ok
   155  }
   156  
   157  // IsTenantIgnorable returns true if the entity has a Global access and does not need tenant isolation
   158  func (t Type) IsTenantIgnorable() bool {
   159  	_, exists := ignoredTenantAccessTable[t]
   160  	return exists
   161  }
   162  
   163  // TenantAccessTable returns the table / view with tenant accesses of the given type.
   164  func (t Type) TenantAccessTable() (string, bool) {
   165  	tbl, ok := tenantAccessTable[t]
   166  	return tbl, ok
   167  }
   168  
   169  // EmbeddedTenantTable returns the table of the given type that is with embedded tenant.
   170  func (t Type) EmbeddedTenantTable() (string, bool) {
   171  	tbl, ok := tablesWithEmbeddedTenant[t]
   172  	return tbl, ok
   173  }
   174  
   175  // TopLevelEntities is a map of entities that has a many-to-many relationship with the tenants along with their table names.
   176  var TopLevelEntities = map[Type]string{
   177  	Application:                "public.applications",
   178  	ApplicationTemplateVersion: "public.application_template_versions",
   179  	Runtime:                    "public.runtimes",
   180  	RuntimeContext:             "public.runtime_contexts",
   181  }
   182  
   183  // IsTopLevel returns true only if the entity has a many-to-many relationship with the tenants.
   184  func (t Type) IsTopLevel() bool {
   185  	_, exists := TopLevelEntities[t]
   186  	return exists
   187  }
   188  
   189  // SQLOperation represents an SQL operation
   190  type SQLOperation string
   191  
   192  const (
   193  	// Create represents Create SQL operation
   194  	Create SQLOperation = "Create"
   195  	// Update represents Update SQL operation
   196  	Update SQLOperation = "Update"
   197  	// Upsert represents Upsert SQL operation
   198  	Upsert SQLOperation = "Upsert"
   199  	// Delete represents Delete SQL operation
   200  	Delete SQLOperation = "Delete"
   201  	// Exists represents Exists SQL operation
   202  	Exists SQLOperation = "Exists"
   203  	// Get represents Get SQL operation
   204  	Get SQLOperation = "Get"
   205  	// List represents List SQL operation
   206  	List SQLOperation = "List"
   207  )