Files
upstream-corteza/server/discovery
upstream-mirror 7e385fc126
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
2026-09-18 01:22:23 +05:00
..

= Corteza Discovery

This package provides API endpoints and business logic to serve indexable resources.

== Access control

When Discovery capabilities are installed to Corteza server three combinations of clients, roles and users are provisioned:

- one auth client, role and user for *public* indexing
- one auth client, role and user for *protected* indexing
- one auth client, role and user for *private* indexing

This setup enables discovery indexing service to connect to the API with restricted privileges and have access only to explicitly allowed resources.

=== Additional limitations and protection of auth client

Each role is configured on each client as forced role and each client as impersonated user.
Auth clients are configured with `client_credentials` grant.

Additionally, auth clients only have `discovery` scope enabled.


=== Use of auth clients on indexer

Indexer supports configuration for multiple indexes with different access credentials.
This allows it to set up different indexing schemas and control how what data is available in an index.










== Index field mapping

=== Static mapping

API only serves dynamic index mappings for different types of records (per module).
Static mappings for resources like users, applications, modules, namespaces are not served from Corteza server API.






== Terminology
Index access restrictions or `iar`::
Can be one of public, private or protected.
Some resource-types can not be accessed publicly.

Index name::
  Logicaly structured name of the resource index:

  <prefix-for-distinction>-<iar>-<resource-like-suffix>

  corteza-private-system-users
  corteza-private-compose-records-1-2 (namespaceID: 1, moduleID: 2)




== REST API Endpoints

/api/discovery/resources/<iar>::
Returns resource types that can be indexable
Used when indexer need to crawl over all resources.

/api/discovery/resources/<iar>/types/<resource-type>::
IDs of indexable resources that can be indexed for a certain access restrictions.
Used when indexer need to crawl over all resources.

/api/discovery/resources/<iar>/<resource-type>/<id>::
Indexable resource with all details that can be indexed for a certain access restrictions.

/api/discovery/feed/<iar>?limit=<limit:uint>&cursor=<cursor:uint64>::
Feed of indexable resources that were changed from the cursor on.
Contains resource type, id and index ID that can be used for cursor


== Store structure

.Resource updates (`discovery_update_feed`)
[cols="1,1,2"]
|===
| Field | Type |

| `id`
| Uint64
| PK, pagination cursor

| `iar`
| Int (bitmask)
| Index access restriction: is public, protected and/or private

| `index_suffix`
| String
| Resource type

| `resource_id`
| Uint64
| Resource identifier

| `removed`
| Boolean
| Was resource removed?

| `created_at`
| Timestamp
| Data retention control
|===

== Data flow

We utilize EventBus to handle updates to indexable resources table when resources are created (`afterCreate`), or updated (`afterUpdate`, `afterDelete`).


[NOTE]
====
Corteza resources that support soft-delete are only removed from public and protected indexes.
Private index keeps deleted resources to allow searching through them.
====


== Lifecycle

=== Server start
. Register garbage collector that removes
. Register garbage collection

=== Server running


=== Server stop