graphcore-kernel 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- graphcore/__init__.py +5 -0
- graphcore/agent_frontend/__init__.py +8 -0
- graphcore/agent_frontend/api.py +69 -0
- graphcore/agent_frontend/base/__init__.py +11 -0
- graphcore/agent_frontend/base/views.py +167 -0
- graphcore/agent_frontend/client.py +31 -0
- graphcore/agent_frontend/context.py +157 -0
- graphcore/agent_frontend/errors.py +12 -0
- graphcore/agent_frontend/loading.py +54 -0
- graphcore/agent_frontend/registry.py +42 -0
- graphcore/agent_frontend/render.py +207 -0
- graphcore/agent_frontend/server.py +103 -0
- graphcore/agent_frontend/signatures.py +35 -0
- graphcore/agent_frontend/testing.py +45 -0
- graphcore/agent_frontend/tests/__init__.py +0 -0
- graphcore/agent_frontend/tests/fakes.py +114 -0
- graphcore/agent_frontend/tests/test_frontend.py +447 -0
- graphcore/agent_frontend/tests/test_loading.py +83 -0
- graphcore/agent_frontend/tests/test_server.py +109 -0
- graphcore/agent_frontend/tools.py +137 -0
- graphcore/api/__init__.py +4 -0
- graphcore/api/graph_api.py +378 -0
- graphcore/api/predicate_codec.py +81 -0
- graphcore/api/tests/__init__.py +0 -0
- graphcore/api/tests/test_changed_entities.py +109 -0
- graphcore/api/tests/test_graph_api.py +290 -0
- graphcore/api/tests/test_graph_api_access.py +94 -0
- graphcore/api/tests/test_graph_api_grants.py +90 -0
- graphcore/api/tests/test_predicate_codec.py +83 -0
- graphcore/api/tests/test_subtree_query.py +79 -0
- graphcore/apps.py +71 -0
- graphcore/auth/__init__.py +1 -0
- graphcore/auth/authn/README.md +178 -0
- graphcore/auth/authn/__init__.py +3 -0
- graphcore/auth/authn/authenticator.py +120 -0
- graphcore/auth/authn/onboarding.py +105 -0
- graphcore/auth/authn/principals.py +20 -0
- graphcore/auth/authn/resource_metadata.py +43 -0
- graphcore/auth/authn/service_accounts.py +96 -0
- graphcore/auth/authn/testing.py +96 -0
- graphcore/auth/authn/tests/__init__.py +0 -0
- graphcore/auth/authn/tests/test_authenticator.py +145 -0
- graphcore/auth/authn/tests/test_onboarding.py +145 -0
- graphcore/auth/authn/tests/test_service_accounts.py +180 -0
- graphcore/auth/authn/users.py +59 -0
- graphcore/auth/authz/__init__.py +0 -0
- graphcore/auth/authz/access_port.py +120 -0
- graphcore/auth/authz/adapter/__init__.py +0 -0
- graphcore/auth/authz/adapter/default_access_adapter.py +556 -0
- graphcore/auth/authz/adapter/tests/__init__.py +0 -0
- graphcore/auth/authz/adapter/tests/test_default_adapter.py +543 -0
- graphcore/auth/authz/adapter/tests/test_entity_write_hooks.py +207 -0
- graphcore/auth/authz/adapter/tests/test_group_types.py +70 -0
- graphcore/auth/authz/adapter/tests/test_sync_support.py +209 -0
- graphcore/auth/authz/defaults.py +26 -0
- graphcore/auth/authz/kernel_policy.py +191 -0
- graphcore/auth/authz/kernel_writes.py +31 -0
- graphcore/auth/authz/lookups.py +25 -0
- graphcore/auth/authz/policy.py +403 -0
- graphcore/auth/authz/tests/__init__.py +0 -0
- graphcore/auth/authz/tests/test_can_contain.py +150 -0
- graphcore/auth/authz/tests/test_contained_by.py +167 -0
- graphcore/auth/authz/tests/test_creation.py +391 -0
- graphcore/auth/authz/tests/test_delete_permission.py +82 -0
- graphcore/auth/authz/tests/test_granted_to_me.py +160 -0
- graphcore/auth/authz/tests/test_integration.py +637 -0
- graphcore/auth/authz/tests/test_invites.py +184 -0
- graphcore/auth/authz/tests/test_kernel_policy.py +140 -0
- graphcore/auth/authz/tests/test_lockout.py +132 -0
- graphcore/auth/authz/tests/test_policy.py +329 -0
- graphcore/auth/authz/tests/test_primitives.py +73 -0
- graphcore/auth/authz/tests/test_principal_creation.py +62 -0
- graphcore/bootstrap/__init__.py +0 -0
- graphcore/bootstrap/deployment.py +67 -0
- graphcore/bootstrap/signals.py +16 -0
- graphcore/bootstrap/tests/__init__.py +0 -0
- graphcore/bootstrap/tests/test_deployment_seed.py +154 -0
- graphcore/broadcast/__init__.py +4 -0
- graphcore/broadcast/broadcaster.py +201 -0
- graphcore/broadcast/channels.py +56 -0
- graphcore/broadcast/tests/__init__.py +0 -0
- graphcore/broadcast/tests/test_broadcaster.py +444 -0
- graphcore/celery.py +14 -0
- graphcore/docs/AGENT_FRONTEND_TDD.md +389 -0
- graphcore/docs/ARCHITECTURE_PRINCIPLES.md +152 -0
- graphcore/docs/AUTHORIZATION_TECHNICAL_TDD.md +1379 -0
- graphcore/docs/ENTITY_REFERENCE_TDD.md +561 -0
- graphcore/docs/GRAPHAPI_FRONT_DOOR.md +173 -0
- graphcore/docs/RUNTIME.md +90 -0
- graphcore/docs/SCHEDULING_TDD.md +244 -0
- graphcore/docs/STRATEGY_EXECUTION_TDD.md +1043 -0
- graphcore/docs/VIEW_ENTITY_TDD.md +522 -0
- graphcore/docs/VIEW_SYSTEM_TDD.md +307 -0
- graphcore/docs/__init__.py +0 -0
- graphcore/docs/doc_topics.py +97 -0
- graphcore/docs/docs_discovery.py +64 -0
- graphcore/docs/public_api.py +56 -0
- graphcore/domain/__init__.py +0 -0
- graphcore/domain/entity/Entity.py +204 -0
- graphcore/domain/entity/__init__.py +0 -0
- graphcore/domain/entity/deployment/Deployment.py +25 -0
- graphcore/domain/entity/deployment/__init__.py +0 -0
- graphcore/domain/entity/grant/Grant.py +31 -0
- graphcore/domain/entity/grant/__init__.py +0 -0
- graphcore/domain/entity/group/Group.py +48 -0
- graphcore/domain/entity/group/README.md +88 -0
- graphcore/domain/entity/group/__init__.py +0 -0
- graphcore/domain/entity/invite/Invite.py +31 -0
- graphcore/domain/entity/invite/__init__.py +0 -0
- graphcore/domain/entity/request_template/RequestTemplate.py +48 -0
- graphcore/domain/entity/request_template/__init__.py +0 -0
- graphcore/domain/entity/request_template/tests/__init__.py +0 -0
- graphcore/domain/entity/request_template/tests/test_request_template.py +52 -0
- graphcore/domain/entity/service_account/ServiceAccount.py +41 -0
- graphcore/domain/entity/service_account/__init__.py +0 -0
- graphcore/domain/entity/strategy_request/StrategyRequest.py +61 -0
- graphcore/domain/entity/strategy_request/__init__.py +0 -0
- graphcore/domain/entity/strategy_request/tests/__init__.py +0 -0
- graphcore/domain/entity/strategy_request/tests/test_strategy_request_entity.py +35 -0
- graphcore/domain/entity/tests/__init__.py +0 -0
- graphcore/domain/entity/tests/test_entity.py +227 -0
- graphcore/domain/entity/tests/test_grant_group_entities.py +36 -0
- graphcore/domain/entity/tests/test_write_once_fields.py +98 -0
- graphcore/domain/entity/user/User.py +39 -0
- graphcore/domain/entity/user/__init__.py +0 -0
- graphcore/domain/entity/user/tests/__init__.py +0 -0
- graphcore/domain/entity/user/tests/test_user_entity.py +33 -0
- graphcore/domain/entity/view/View.py +37 -0
- graphcore/domain/entity/view/__init__.py +0 -0
- graphcore/domain/entity/view/position.py +78 -0
- graphcore/domain/entity/view/tests/__init__.py +0 -0
- graphcore/domain/entity/view/tests/test_position.py +71 -0
- graphcore/domain/entity/view/tests/test_view_entity.py +134 -0
- graphcore/domain/strategy/BaseStrategy.py +759 -0
- graphcore/domain/strategy/DeploymentStrategies.py +55 -0
- graphcore/domain/strategy/GrantStrategies.py +189 -0
- graphcore/domain/strategy/GroupStrategies.py +193 -0
- graphcore/domain/strategy/InviteStrategies.py +84 -0
- graphcore/domain/strategy/RequestTemplateStrategies.py +126 -0
- graphcore/domain/strategy/ViewStrategies.py +219 -0
- graphcore/domain/strategy/__init__.py +0 -0
- graphcore/domain/strategy/runner.py +84 -0
- graphcore/domain/strategy/session.py +56 -0
- graphcore/domain/strategy/tests/BaseStrategyTest.py +167 -0
- graphcore/domain/strategy/tests/__init__.py +0 -0
- graphcore/domain/strategy/tests/test_BaseStrategies.py +870 -0
- graphcore/domain/strategy/tests/test_grant_strategies.py +245 -0
- graphcore/domain/strategy/tests/test_group_strategies.py +99 -0
- graphcore/domain/strategy/tests/test_runner.py +220 -0
- graphcore/domain/strategy/tests/test_strategy_locks.py +446 -0
- graphcore/domain/strategy/tests/test_utils.py +95 -0
- graphcore/domain/strategy/tests/test_view_strategies.py +436 -0
- graphcore/errors.py +145 -0
- graphcore/execution/README.md +97 -0
- graphcore/execution/StrategyExecutorService.py +333 -0
- graphcore/execution/__init__.py +0 -0
- graphcore/execution/dispatcher.py +19 -0
- graphcore/execution/environments/__init__.py +0 -0
- graphcore/execution/environments/celery.py +59 -0
- graphcore/execution/environments/in_process.py +55 -0
- graphcore/execution/local_session.py +117 -0
- graphcore/execution/redis_run_events.py +74 -0
- graphcore/execution/requests.py +22 -0
- graphcore/execution/run_events.py +85 -0
- graphcore/execution/strategy_context.py +54 -0
- graphcore/execution/tasks.py +34 -0
- graphcore/execution/tests/__init__.py +5 -0
- graphcore/execution/tests/contract.py +171 -0
- graphcore/execution/tests/support.py +310 -0
- graphcore/execution/tests/test_dispatchers.py +76 -0
- graphcore/execution/tests/test_executor.py +368 -0
- graphcore/execution/tests/test_local_session.py +95 -0
- graphcore/execution/tests/test_reconcile_runs.py +134 -0
- graphcore/execution/tests/test_run_events.py +106 -0
- graphcore/execution/tests/test_strategy_context.py +62 -0
- graphcore/gateway/__init__.py +1 -0
- graphcore/gateway/remote.py +35 -0
- graphcore/gateway/tests/__init__.py +0 -0
- graphcore/gateway/tests/test_remote.py +30 -0
- graphcore/graph/EntityService.py +710 -0
- graphcore/graph/__init__.py +0 -0
- graphcore/graph/entity_cache.py +152 -0
- graphcore/graph/tests/__init__.py +4 -0
- graphcore/graph/tests/test_EntityService.py +908 -0
- graphcore/graph/tests/test_EntityService_list.py +170 -0
- graphcore/graph/tests/test_EntityService_model_resolution.py +339 -0
- graphcore/graph/tests/test_EntityService_referrers.py +236 -0
- graphcore/graph/tests/test_EntityService_routing.py +119 -0
- graphcore/graph/tests/test_dependent_on.py +141 -0
- graphcore/graph/tests/test_engine_is_type_agnostic.py +25 -0
- graphcore/graph/tests/test_engine_resolves_read_permission.py +93 -0
- graphcore/graph/tests/test_entity_cache.py +159 -0
- graphcore/graph/tests/test_null_entity_cache.py +12 -0
- graphcore/management/__init__.py +0 -0
- graphcore/management/commands/__init__.py +0 -0
- graphcore/management/commands/dev_reset.py +18 -0
- graphcore/management/commands/graphcore_createadmin.py +65 -0
- graphcore/management/commands/graphcore_policy.py +59 -0
- graphcore/management/commands/graphcore_status.py +98 -0
- graphcore/management/tests/__init__.py +0 -0
- graphcore/management/tests/test_createadmin.py +78 -0
- graphcore/management/tests/test_policy_command.py +46 -0
- graphcore/management/tests/test_status_command.py +85 -0
- graphcore/migrations/0001_initial.py +186 -0
- graphcore/migrations/0002_invite.py +26 -0
- graphcore/migrations/__init__.py +0 -0
- graphcore/models.py +11 -0
- graphcore/persistence/ENTITY_REPOSITORY_TECHNICAL_TDD.md +396 -0
- graphcore/persistence/__init__.py +6 -0
- graphcore/persistence/django/__init__.py +0 -0
- graphcore/persistence/django/backends.py +43 -0
- graphcore/persistence/django/bindings.py +28 -0
- graphcore/persistence/django/cache.py +38 -0
- graphcore/persistence/django/compiler.py +214 -0
- graphcore/persistence/django/identity.py +18 -0
- graphcore/persistence/django/models.py +252 -0
- graphcore/persistence/django/repository.py +525 -0
- graphcore/persistence/django/tests/__init__.py +0 -0
- graphcore/persistence/django/tests/test_backends.py +68 -0
- graphcore/persistence/django/tests/test_compiler.py +269 -0
- graphcore/persistence/django/tests/test_repository.py +472 -0
- graphcore/persistence/django/tests/test_shared_column.py +120 -0
- graphcore/persistence/django/tests/test_threads.py +50 -0
- graphcore/persistence/django/tests/test_update_shape.py +175 -0
- graphcore/persistence/django/threads.py +38 -0
- graphcore/persistence/repository.py +172 -0
- graphcore/persistence/tests/__init__.py +0 -0
- graphcore/persistence/tests/contract.py +688 -0
- graphcore/persistence/tests/evaluate.py +51 -0
- graphcore/persistence/tests/fixtures.py +32 -0
- graphcore/persistence/tests/memory.py +263 -0
- graphcore/persistence/tests/test_memory_repository.py +10 -0
- graphcore/persistence/tests/test_query_types.py +127 -0
- graphcore/public/__init__.py +9 -0
- graphcore/public/api.py +9 -0
- graphcore/public/apps.py +10 -0
- graphcore/public/auth/__init__.py +1 -0
- graphcore/public/auth/grants.py +7 -0
- graphcore/public/auth/onboarding.py +8 -0
- graphcore/public/auth/perms.py +7 -0
- graphcore/public/auth/policy.py +10 -0
- graphcore/public/auth/roles.py +8 -0
- graphcore/public/auth/subjects.py +7 -0
- graphcore/public/entities/__init__.py +32 -0
- graphcore/public/errors.py +19 -0
- graphcore/public/persistence/__init__.py +44 -0
- graphcore/public/persistence/django.py +24 -0
- graphcore/public/scheduling.py +23 -0
- graphcore/public/strategies/__init__.py +85 -0
- graphcore/public/test_settings.py +16 -0
- graphcore/public/testing.py +47 -0
- graphcore/registry/EntityDirectory.py +246 -0
- graphcore/registry/README.md +147 -0
- graphcore/registry/StrategyDirectory.py +308 -0
- graphcore/registry/TYPE_METADATA_PLACEMENT.md +66 -0
- graphcore/registry/__init__.py +0 -0
- graphcore/registry/app_discovery.py +108 -0
- graphcore/registry/decorators.py +77 -0
- graphcore/registry/discovery.py +111 -0
- graphcore/registry/registry.py +79 -0
- graphcore/registry/tests/__init__.py +0 -0
- graphcore/registry/tests/test_agent_frontend_discovery.py +56 -0
- graphcore/registry/tests/test_app_config.py +36 -0
- graphcore/registry/tests/test_discovery.py +147 -0
- graphcore/registry/tests/test_entity_directory_storage.py +73 -0
- graphcore/registry/tests/test_import_package.py +87 -0
- graphcore/registry/tests/test_principal_flag.py +67 -0
- graphcore/registry/tests/test_strategy_directory.py +29 -0
- graphcore/routes/__init__.py +116 -0
- graphcore/routes/tests/__init__.py +0 -0
- graphcore/routes/tests/test_routes.py +90 -0
- graphcore/runtime.py +243 -0
- graphcore/scheduling/__init__.py +0 -0
- graphcore/scheduling/beat_scheduler.py +164 -0
- graphcore/scheduling/beat_tasks.py +63 -0
- graphcore/scheduling/scheduler.py +37 -0
- graphcore/scheduling/tests/__init__.py +0 -0
- graphcore/scheduling/tests/contract.py +136 -0
- graphcore/scheduling/tests/memory.py +42 -0
- graphcore/scheduling/tests/test_beat_scheduler.py +87 -0
- graphcore/scheduling/tests/test_memory_scheduler.py +15 -0
- graphcore/scheduling/tests/test_ticks.py +143 -0
- graphcore/tasks.py +9 -0
- graphcore/test_settings.py +78 -0
- graphcore/testing/__init__.py +0 -0
- graphcore/testing/case.py +112 -0
- graphcore/testing/runner.py +32 -0
- graphcore/testing/settings.py +26 -0
- graphcore/testing/tests/__init__.py +0 -0
- graphcore/testing/tests/agent_view_fixture.py +19 -0
- graphcore/testing/tests/test_case_and_runner.py +219 -0
- graphcore/testing/tests/test_settings_for_apps.py +50 -0
- graphcore/tests/__init__.py +0 -0
- graphcore/tests/ids.py +14 -0
- graphcore/tests/public_api_manifest.py +102 -0
- graphcore/tests/runs.py +7 -0
- graphcore/tests/test_app_discovery.py +90 -0
- graphcore/tests/test_composition_boundaries.py +231 -0
- graphcore/tests/test_docs_discovery.py +108 -0
- graphcore/tests/test_no_print.py +70 -0
- graphcore/tests/test_packaging.py +64 -0
- graphcore/tests/test_public_api_boundaries.py +229 -0
- graphcore/tests/test_public_api_contract.py +62 -0
- graphcore/tests/test_public_api_docs.py +28 -0
- graphcore/tests/test_runtime.py +42 -0
- graphcore/tests/test_shared_type_boundaries.py +128 -0
- graphcore/tests/test_shared_types.py +144 -0
- graphcore/tests/test_test_settings.py +45 -0
- graphcore/transport/__init__.py +0 -0
- graphcore/transport/agent_asgi.py +68 -0
- graphcore/transport/agent_client.py +85 -0
- graphcore/transport/channel_layer.py +68 -0
- graphcore/transport/consumers.py +507 -0
- graphcore/transport/routing.py +6 -0
- graphcore/transport/tests/__init__.py +0 -0
- graphcore/transport/tests/test_agent_client.py +31 -0
- graphcore/transport/tests/test_api_views.py +733 -0
- graphcore/transport/tests/test_channel_layer.py +96 -0
- graphcore/transport/tests/test_consumers.py +963 -0
- graphcore/transport/tests/test_resource_metadata.py +67 -0
- graphcore/transport/urls.py +29 -0
- graphcore/transport/views.py +358 -0
- graphcore/types/__init__.py +4 -0
- graphcore/types/access.py +114 -0
- graphcore/types/api.py +76 -0
- graphcore/types/entities.py +100 -0
- graphcore/types/entity_id.py +85 -0
- graphcore/types/execution.py +41 -0
- graphcore/types/identity.py +20 -0
- graphcore/types/onboarding.py +20 -0
- graphcore/types/query.py +116 -0
- graphcore/types/schedules.py +91 -0
- graphcore/types/strategy.py +73 -0
- graphcore/types/tests/__init__.py +0 -0
- graphcore/types/tests/test_entity_id.py +50 -0
- graphcore/urls.py +5 -0
- graphcore_kernel-0.1.0.dist-info/METADATA +94 -0
- graphcore_kernel-0.1.0.dist-info/RECORD +343 -0
- graphcore_kernel-0.1.0.dist-info/WHEEL +5 -0
- graphcore_kernel-0.1.0.dist-info/entry_points.txt +2 -0
- graphcore_kernel-0.1.0.dist-info/licenses/LICENSE +202 -0
- graphcore_kernel-0.1.0.dist-info/licenses/NOTICE +2 -0
- graphcore_kernel-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""The databases the Django repository is tested on and will run against.
|
|
2
|
+
|
|
3
|
+
Behaviour differences are decided by Django's feature flags
|
|
4
|
+
(`connection.features`) wherever Django has one; `connection.vendor` is
|
|
5
|
+
consulted only where it has no portable answer (e.g. GIN indexes). Adding a
|
|
6
|
+
database here also adds it to `scripts/test`'s matrix.
|
|
7
|
+
"""
|
|
8
|
+
from django.core import checks
|
|
9
|
+
from django.core.exceptions import ImproperlyConfigured
|
|
10
|
+
from django.db import connections
|
|
11
|
+
|
|
12
|
+
SUPPORTED_VENDORS = ('postgresql', 'sqlite')
|
|
13
|
+
REFERENCE_VENDOR = 'postgresql'
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _unsupported_message(vendor: str) -> str:
|
|
17
|
+
return (
|
|
18
|
+
f"GraphCore's Django repository does not support the {vendor!r} database; "
|
|
19
|
+
f"supported: {', '.join(SUPPORTED_VENDORS)}."
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def check_supported(connection) -> None:
|
|
24
|
+
if connection.vendor not in SUPPORTED_VENDORS:
|
|
25
|
+
raise ImproperlyConfigured(_unsupported_message(connection.vendor))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def is_unique_violation(error) -> bool:
|
|
29
|
+
"""Django raises one `IntegrityError` for every constraint kind; only the
|
|
30
|
+
driver's error says which."""
|
|
31
|
+
cause = error.__cause__
|
|
32
|
+
if getattr(cause, 'sqlstate', None) == '23505' or getattr(cause, 'pgcode', None) == '23505':
|
|
33
|
+
return True
|
|
34
|
+
return 'UNIQUE constraint failed' in str(error)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def check_database_vendor(app_configs=None, **kwargs) -> list:
|
|
38
|
+
"""Django system check: an unsupported database is reported by `check`,
|
|
39
|
+
`migrate` and `test` before anything touches it."""
|
|
40
|
+
vendor = connections['default'].vendor
|
|
41
|
+
if vendor in SUPPORTED_VENDORS:
|
|
42
|
+
return []
|
|
43
|
+
return [checks.Error(_unsupported_message(vendor), id='graphcore.E001')]
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""Kernel type storage bindings for the Django repository."""
|
|
2
|
+
from graphcore.domain.entity.Entity import Entity
|
|
3
|
+
from graphcore.domain.entity.deployment.Deployment import Deployment
|
|
4
|
+
from graphcore.domain.entity.grant.Grant import Grant
|
|
5
|
+
from graphcore.domain.entity.group.Group import Group
|
|
6
|
+
from graphcore.domain.entity.invite.Invite import Invite
|
|
7
|
+
from graphcore.domain.entity.request_template.RequestTemplate import RequestTemplate
|
|
8
|
+
from graphcore.domain.entity.service_account.ServiceAccount import ServiceAccount
|
|
9
|
+
from graphcore.domain.entity.strategy_request.StrategyRequest import StrategyRequest
|
|
10
|
+
from graphcore.domain.entity.user.User import User
|
|
11
|
+
from graphcore.domain.entity.view.View import View
|
|
12
|
+
from graphcore.persistence.django.models import (
|
|
13
|
+
DeploymentModel, EntityModel, GrantModel, GroupModel, InviteModel, RequestTemplateModel,
|
|
14
|
+
ServiceAccountModel, StrategyRequestModel, UserModel, ViewModel,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def configure(entities) -> None:
|
|
19
|
+
entities.bind_storage(Entity, EntityModel)
|
|
20
|
+
entities.bind_storage(Grant, GrantModel)
|
|
21
|
+
entities.bind_storage(Group, GroupModel)
|
|
22
|
+
entities.bind_storage(Invite, InviteModel)
|
|
23
|
+
entities.bind_storage(Deployment, DeploymentModel)
|
|
24
|
+
entities.bind_storage(User, UserModel)
|
|
25
|
+
entities.bind_storage(ServiceAccount, ServiceAccountModel)
|
|
26
|
+
entities.bind_storage(View, ViewModel)
|
|
27
|
+
entities.bind_storage(StrategyRequest, StrategyRequestModel)
|
|
28
|
+
entities.bind_storage(RequestTemplate, RequestTemplateModel)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""`EntityCache` over `django.core.cache`."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from django.core.cache import cache as django_cache
|
|
5
|
+
|
|
6
|
+
from graphcore.graph.entity_cache import EntityCache
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class DjangoCache(EntityCache):
|
|
10
|
+
"""The eight generic primitives over Django's configured cache backend."""
|
|
11
|
+
|
|
12
|
+
def __init__(self, entity_ttl: int):
|
|
13
|
+
super().__init__(entity_ttl)
|
|
14
|
+
self.cache = django_cache
|
|
15
|
+
|
|
16
|
+
def get(self, key):
|
|
17
|
+
return self.cache.get(key)
|
|
18
|
+
|
|
19
|
+
def set(self, key, value, timeout=None):
|
|
20
|
+
self.cache.set(key, value, timeout)
|
|
21
|
+
|
|
22
|
+
def delete(self, key):
|
|
23
|
+
self.cache.delete(key)
|
|
24
|
+
|
|
25
|
+
def get_many(self, keys):
|
|
26
|
+
return self.cache.get_many(keys)
|
|
27
|
+
|
|
28
|
+
def set_many(self, key_value_dict, timeout=None):
|
|
29
|
+
self.cache.set_many(key_value_dict, timeout)
|
|
30
|
+
|
|
31
|
+
def delete_many(self, keys):
|
|
32
|
+
self.cache.delete_many(keys)
|
|
33
|
+
|
|
34
|
+
def add(self, key, value, timeout=None):
|
|
35
|
+
self.cache.add(key, value, timeout)
|
|
36
|
+
|
|
37
|
+
def incr(self, key):
|
|
38
|
+
return self.cache.incr(key)
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"""Predicate -> Django `Q` compilation.
|
|
2
|
+
|
|
3
|
+
Filterable fields are derived from the entity directory's bound models, not
|
|
4
|
+
hardcoded here - any column on any bound model (kernel or app) is
|
|
5
|
+
filterable by name, with no persistence code beyond the binding. An exact
|
|
6
|
+
node-type table (no MRO fallback) governs which predicate shapes exist;
|
|
7
|
+
anything outside either raises before a query runs, so a predicate is never
|
|
8
|
+
silently narrowed or dropped.
|
|
9
|
+
"""
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import operator
|
|
13
|
+
from functools import reduce
|
|
14
|
+
|
|
15
|
+
from django.db import connection
|
|
16
|
+
from django.db.models import BooleanField, JSONField, Q
|
|
17
|
+
from django.db.models.expressions import RawSQL
|
|
18
|
+
|
|
19
|
+
from graphcore.errors import InvalidQuery, UnsupportedQuery
|
|
20
|
+
from graphcore.persistence.django.models import EntityModel
|
|
21
|
+
from graphcore.types.query import (
|
|
22
|
+
LITERAL_TYPES, AllOf, AnyOf, ContainsAny, ContainsValue, Equal, InValues, Predicate,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
NOTHING = Q(pk__in=[])
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _literal(value):
|
|
29
|
+
if not isinstance(value, LITERAL_TYPES):
|
|
30
|
+
raise InvalidQuery(f"{type(value).__name__} is not a supported literal type")
|
|
31
|
+
return value
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class QueryCompiler:
|
|
35
|
+
"""Compiles predicates against the models bound in `entity_directory`.
|
|
36
|
+
|
|
37
|
+
`_paths` is built lazily on first `compile()` (bindings settle at
|
|
38
|
+
startup, not at import time) and cached for the compiler's lifetime:
|
|
39
|
+
`{attname: [(prefix, field, model), ...]}`, where `prefix` is `''` for a
|
|
40
|
+
column on the base `EntityModel` and `'<model_name>__'` for an MTI child
|
|
41
|
+
column reached through the reverse join.
|
|
42
|
+
|
|
43
|
+
A field name resolves against every bound model, unless an enclosing
|
|
44
|
+
`AllOf` pins `entity_type_id`: every row it matches is then one of those
|
|
45
|
+
types, so its names resolve against those types' models alone. A name
|
|
46
|
+
several pinned types declare matches any of their columns; unpinned, a
|
|
47
|
+
shared name is refused, so installing an app never widens a query.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
def __init__(self, entity_directory) -> None:
|
|
51
|
+
self.entity_directory = entity_directory
|
|
52
|
+
self._paths = None
|
|
53
|
+
|
|
54
|
+
def _build_paths(self) -> dict:
|
|
55
|
+
paths: dict = {}
|
|
56
|
+
for model in self.entity_directory.storage_classes():
|
|
57
|
+
prefix = '' if model is EntityModel else f'{model._meta.model_name}__'
|
|
58
|
+
for f in model._meta.local_concrete_fields:
|
|
59
|
+
if not f.primary_key or model is EntityModel:
|
|
60
|
+
paths.setdefault(f.attname, []).append((prefix, f, model))
|
|
61
|
+
return paths
|
|
62
|
+
|
|
63
|
+
def _columns(self, field: str, models=None) -> list:
|
|
64
|
+
"""Every `(prefix, field)` the name resolves to - more than one only
|
|
65
|
+
under a type pin, and only when those columns share a type."""
|
|
66
|
+
if self._paths is None:
|
|
67
|
+
self._paths = self._build_paths()
|
|
68
|
+
matches = self._paths.get(field, [])
|
|
69
|
+
if models is not None:
|
|
70
|
+
matches = [m for m in matches if m[2] is EntityModel or m[2] in models]
|
|
71
|
+
if not matches:
|
|
72
|
+
raise UnsupportedQuery(f"'{field}' is not a filterable entity field")
|
|
73
|
+
if len(matches) > 1:
|
|
74
|
+
if models is None:
|
|
75
|
+
raise UnsupportedQuery(
|
|
76
|
+
f"'{field}' is ambiguous across bound models - filter on "
|
|
77
|
+
f"entity_type_id alongside it to scope it"
|
|
78
|
+
)
|
|
79
|
+
if len({f.get_internal_type() for _, f, _ in matches}) > 1:
|
|
80
|
+
raise UnsupportedQuery(
|
|
81
|
+
f"'{field}' has different column types across the filtered types"
|
|
82
|
+
)
|
|
83
|
+
return [(prefix, f) for prefix, f, _ in matches]
|
|
84
|
+
|
|
85
|
+
def _pinned_models(self, predicates):
|
|
86
|
+
"""The models an `entity_type_id` filter among these conjuncts pins
|
|
87
|
+
them to (each bound model plus its MTI parents), or None."""
|
|
88
|
+
for p in predicates:
|
|
89
|
+
if getattr(p, 'field', None) != 'entity_type_id':
|
|
90
|
+
continue
|
|
91
|
+
if isinstance(p, Equal) and p.value is not None:
|
|
92
|
+
type_ids = {p.value}
|
|
93
|
+
elif isinstance(p, InValues):
|
|
94
|
+
type_ids = p.values
|
|
95
|
+
else:
|
|
96
|
+
continue
|
|
97
|
+
models = set()
|
|
98
|
+
for type_id in type_ids:
|
|
99
|
+
entity_cls = self.entity_directory.get_entity_class(type_id)
|
|
100
|
+
if entity_cls is None:
|
|
101
|
+
continue
|
|
102
|
+
model = self.entity_directory.storage(entity_cls)
|
|
103
|
+
models.add(model)
|
|
104
|
+
models.update(model._meta.get_parent_list())
|
|
105
|
+
if models:
|
|
106
|
+
return frozenset(models)
|
|
107
|
+
return None
|
|
108
|
+
|
|
109
|
+
def _collection(self, field: str, models=None):
|
|
110
|
+
"""`(prefix, field)` of a JSON array column - the PostgreSQL path
|
|
111
|
+
would otherwise silently accept a scalar. A child table's column is
|
|
112
|
+
a collection only under a type pin, which guarantees every row
|
|
113
|
+
matched has that child row."""
|
|
114
|
+
columns = self._columns(field, models)
|
|
115
|
+
prefix, f = columns[0]
|
|
116
|
+
if len(columns) > 1 or not (isinstance(f, JSONField) and f.default is list):
|
|
117
|
+
raise UnsupportedQuery(f"'{field}' is not a collection field")
|
|
118
|
+
if f.model is not EntityModel and (models is None or f.model not in models):
|
|
119
|
+
raise UnsupportedQuery(
|
|
120
|
+
f"'{field}' is a column of {f.model.__name__} - filter on entity_type_id alongside it"
|
|
121
|
+
)
|
|
122
|
+
return prefix, f
|
|
123
|
+
|
|
124
|
+
@staticmethod
|
|
125
|
+
def _table(model) -> str:
|
|
126
|
+
return f'"{model._meta.db_table}"'
|
|
127
|
+
|
|
128
|
+
def _json_holds_any(self, field: str, values, models=None) -> Q:
|
|
129
|
+
"""`field` overlaps `values`: Django's JSON `contains` where the
|
|
130
|
+
database supports it (indexed on PostgreSQL), otherwise a
|
|
131
|
+
`json_each` scan (SQLite) - the one place the backends diverge."""
|
|
132
|
+
prefix, f = self._collection(field, models)
|
|
133
|
+
if connection.features.supports_json_field_contains:
|
|
134
|
+
clauses = Q()
|
|
135
|
+
for value in values:
|
|
136
|
+
clauses |= Q(**{f'{prefix}{f.attname}__contains': [value]})
|
|
137
|
+
return clauses
|
|
138
|
+
placeholders = ', '.join(['%s'] * len(values))
|
|
139
|
+
column = f'{self._table(f.model)}."{f.column}"'
|
|
140
|
+
if f.model is EntityModel:
|
|
141
|
+
sql = f'EXISTS (SELECT 1 FROM json_each({column}) WHERE json_each.value IN ({placeholders}))'
|
|
142
|
+
else:
|
|
143
|
+
sql = (
|
|
144
|
+
f'{self._table(EntityModel)}."{EntityModel._meta.pk.column}" IN '
|
|
145
|
+
f'(SELECT {self._table(f.model)}."{f.model._meta.pk.column}" '
|
|
146
|
+
f'FROM {self._table(f.model)}, json_each({column}) '
|
|
147
|
+
f'WHERE json_each.value IN ({placeholders}))'
|
|
148
|
+
)
|
|
149
|
+
return Q(RawSQL(sql, list(values), output_field=BooleanField()))
|
|
150
|
+
|
|
151
|
+
@staticmethod
|
|
152
|
+
def _equal_column(prefix: str, f, value) -> Q:
|
|
153
|
+
if value is None:
|
|
154
|
+
if prefix:
|
|
155
|
+
# Child-table null-check hazard: a `LEFT OUTER JOIN` row that
|
|
156
|
+
# doesn't exist for this entity is also "null" on every
|
|
157
|
+
# child column, so without pinning the join itself,
|
|
158
|
+
# `Equal(child_field, None)` would match every other type
|
|
159
|
+
# too.
|
|
160
|
+
return Q(**{f'{prefix}isnull': False, f'{prefix}{f.attname}__isnull': True})
|
|
161
|
+
return Q(**{f'{f.attname}__isnull': True})
|
|
162
|
+
return Q(**{f'{prefix}{f.attname}': value})
|
|
163
|
+
|
|
164
|
+
def _equal(self, node: Equal, models) -> Q:
|
|
165
|
+
columns = self._columns(node.field, models)
|
|
166
|
+
value = _literal(node.value)
|
|
167
|
+
return reduce(operator.or_, (self._equal_column(p, f, value) for p, f in columns))
|
|
168
|
+
|
|
169
|
+
def _in_values(self, node: InValues, models) -> Q:
|
|
170
|
+
columns = self._columns(node.field, models)
|
|
171
|
+
values = [_literal(value) for value in node.values]
|
|
172
|
+
if not values:
|
|
173
|
+
return NOTHING
|
|
174
|
+
return reduce(operator.or_, (Q(**{f'{p}{f.attname}__in': values}) for p, f in columns))
|
|
175
|
+
|
|
176
|
+
def _contains_value(self, node: ContainsValue, models) -> Q:
|
|
177
|
+
return self._json_holds_any(node.field, [_literal(node.value)], models)
|
|
178
|
+
|
|
179
|
+
def _contains_any(self, node: ContainsAny, models) -> Q:
|
|
180
|
+
self._collection(node.field, models)
|
|
181
|
+
values = [_literal(value) for value in node.values]
|
|
182
|
+
return self._json_holds_any(node.field, values, models) if values else NOTHING
|
|
183
|
+
|
|
184
|
+
def _all_of(self, node: AllOf, models) -> Q:
|
|
185
|
+
models = self._pinned_models(node.predicates) or models
|
|
186
|
+
combined = Q()
|
|
187
|
+
for child in node.predicates:
|
|
188
|
+
combined &= self.compile(child, models)
|
|
189
|
+
return combined
|
|
190
|
+
|
|
191
|
+
def _any_of(self, node: AnyOf, models) -> Q:
|
|
192
|
+
if not node.predicates:
|
|
193
|
+
return NOTHING
|
|
194
|
+
combined = Q(pk__in=[])
|
|
195
|
+
for child in node.predicates:
|
|
196
|
+
combined |= self.compile(child, models)
|
|
197
|
+
return combined
|
|
198
|
+
|
|
199
|
+
_HANDLERS = {
|
|
200
|
+
Equal: _equal,
|
|
201
|
+
InValues: _in_values,
|
|
202
|
+
ContainsValue: _contains_value,
|
|
203
|
+
ContainsAny: _contains_any,
|
|
204
|
+
AllOf: _all_of,
|
|
205
|
+
AnyOf: _any_of,
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
def compile(self, predicate: Predicate, models=None) -> Q:
|
|
209
|
+
"""`models` narrows field-name resolution - set by an enclosing
|
|
210
|
+
`AllOf`'s type pin, never by callers."""
|
|
211
|
+
handler = self._HANDLERS.get(type(predicate))
|
|
212
|
+
if handler is None:
|
|
213
|
+
raise UnsupportedQuery(f"Unsupported predicate node: {type(predicate).__name__}")
|
|
214
|
+
return handler(self, predicate, models)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""The store's backend identity row, owned by this adapter."""
|
|
2
|
+
from django.db.models.signals import post_migrate
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def ensure_backend_identity(sender, using=None, **kwargs):
|
|
6
|
+
"""`TransactionTestCase` flushes every table and re-emits `post_migrate`,
|
|
7
|
+
so the row has to be re-established rather than written once by a data
|
|
8
|
+
migration."""
|
|
9
|
+
from graphcore.persistence.django.models import BackendIdentityModel
|
|
10
|
+
|
|
11
|
+
BackendIdentityModel.objects.using(using).get_or_create(singleton=True)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def connect(app_config) -> None:
|
|
15
|
+
post_migrate.connect(
|
|
16
|
+
ensure_backend_identity, sender=app_config,
|
|
17
|
+
dispatch_uid='graphcore_backend_identity',
|
|
18
|
+
)
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
"""Django storage models for the kernel's entity types.
|
|
2
|
+
|
|
3
|
+
Storage is a private decision below the serialization boundary: entities
|
|
4
|
+
never reference these classes, and nothing outside `persistence/django`
|
|
5
|
+
imports them except `graphcore/models.py` (Django's model discovery) and
|
|
6
|
+
the `public.persistence.django` facade.
|
|
7
|
+
"""
|
|
8
|
+
from django.contrib.postgres.indexes import GinIndex
|
|
9
|
+
from django.db import models
|
|
10
|
+
from django.db.models import JSONField
|
|
11
|
+
|
|
12
|
+
from graphcore.types.entity_id import BACKEND_ID_LENGTH, new_backend_id
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class BackendIdentityModel(models.Model):
|
|
16
|
+
"""This deployment's immutable identity, minted once when the store is
|
|
17
|
+
initialised (`graphcore.apps` ensures it on `post_migrate`). `singleton`
|
|
18
|
+
is unique, so the store itself enforces that exactly one exists. Never
|
|
19
|
+
configuration: no setting, env var, or flag supplies it (see
|
|
20
|
+
docs/ENTITY_REFERENCE_TDD.md, Backend identity)."""
|
|
21
|
+
backend_id = models.CharField(
|
|
22
|
+
primary_key=True, max_length=BACKEND_ID_LENGTH, default=new_backend_id, editable=False,
|
|
23
|
+
)
|
|
24
|
+
singleton = models.BooleanField(default=True, unique=True)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class EntityModel(models.Model):
|
|
28
|
+
"""
|
|
29
|
+
Base model for all entities in the system.
|
|
30
|
+
Stores core entity data and provides common functionality.
|
|
31
|
+
"""
|
|
32
|
+
# `gc://<backend_id>/<local_id>`, minted by the entity. Opaque to storage:
|
|
33
|
+
# nothing here parses or routes it (docs/ENTITY_REFERENCE_TDD.md).
|
|
34
|
+
entity_id = models.CharField(max_length=96, primary_key=True, editable=False)
|
|
35
|
+
attributes = JSONField(default=dict, db_column='attributes')
|
|
36
|
+
# Single-parent containment (see docs/AUTHORIZATION_TECHNICAL_TDD.md,
|
|
37
|
+
# Containment): `parent_id` + `sibling_position` are the only persisted
|
|
38
|
+
# edge. `children_ids` on `Entity` is a derived, ordered projection over
|
|
39
|
+
# `parent_id` - never a stored column.
|
|
40
|
+
parent_id = models.CharField(max_length=255, null=True, blank=True, db_index=True)
|
|
41
|
+
sibling_position = models.FloatField(default=0.0)
|
|
42
|
+
# Every containing scope, root-first, maintained by the repository:
|
|
43
|
+
# `ancestor_ids(e) = ancestor_ids(parent) + [parent_id]`. Authorization
|
|
44
|
+
# is a predicate over this column rather than a join through a derived
|
|
45
|
+
# index (see docs/AUTHORIZATION_TECHNICAL_TDD.md, Inheritance).
|
|
46
|
+
ancestor_ids = JSONField(default=list)
|
|
47
|
+
# The forward reference projection, read with the row. Reverse lookup
|
|
48
|
+
# goes through `EntityReferenceModel`, never containment on this column.
|
|
49
|
+
reference_ids = JSONField(default=list)
|
|
50
|
+
created_at = models.DateTimeField(auto_now_add=True)
|
|
51
|
+
updated_at = models.DateTimeField(auto_now=True)
|
|
52
|
+
entity_type_id = models.CharField(max_length=100, db_index=True) # Stable identifier (e.g., 'graphcore.Document')
|
|
53
|
+
version = models.IntegerField(default=0, null=False) # Optimistic locking version
|
|
54
|
+
|
|
55
|
+
# Creator / ownership - UUID string of the User that created this entity
|
|
56
|
+
owner = models.CharField(max_length=200, null=True, blank=True)
|
|
57
|
+
|
|
58
|
+
class Meta:
|
|
59
|
+
# GIN indexes back the Postgres JSONB containment operators the
|
|
60
|
+
# compiler emits for `ContainsValue`/`ContainsAny`. Only meaningful
|
|
61
|
+
# on PostgreSQL; the accompanying migrations are no-ops elsewhere.
|
|
62
|
+
indexes = [
|
|
63
|
+
GinIndex(fields=['ancestor_ids'], name='entitymodel_ancestors_gin'),
|
|
64
|
+
models.Index(fields=['parent_id', 'sibling_position'], name='entitymodel_parent_pos_idx'),
|
|
65
|
+
]
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class EntityReferenceModel(models.Model):
|
|
69
|
+
"""The reverse index over `EntityModel.reference_ids`: one row per
|
|
70
|
+
(target, source). The key order is what lets `referrers` walk a target's
|
|
71
|
+
sources in `entity_id` order and stop at the page limit. `target_id` is
|
|
72
|
+
not a foreign key - targets may be remote or deleted."""
|
|
73
|
+
pk = models.CompositePrimaryKey('target_id', 'source')
|
|
74
|
+
target_id = models.CharField(max_length=96)
|
|
75
|
+
source = models.ForeignKey(
|
|
76
|
+
EntityModel, on_delete=models.CASCADE, db_column='source_id', related_name='references',
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class GrantModel(EntityModel):
|
|
81
|
+
"""A persisted grant: `(subject_id, role_name)`, contained by the
|
|
82
|
+
resource it grants on (the inherited, indexed `parent_id` - a grant
|
|
83
|
+
has exactly one resource, so no denormalized column is needed).
|
|
84
|
+
|
|
85
|
+
`subject_id` and `role_name` are real columns, not attributes-bag JSON -
|
|
86
|
+
the two-tier convention that puts grant state beyond the generic
|
|
87
|
+
attribute strategies. See docs/AUTHORIZATION_TECHNICAL_TDD.md (Grant
|
|
88
|
+
storage).
|
|
89
|
+
"""
|
|
90
|
+
subject_id = models.CharField(max_length=255)
|
|
91
|
+
role_name = models.CharField(max_length=100)
|
|
92
|
+
|
|
93
|
+
class Meta:
|
|
94
|
+
indexes = [
|
|
95
|
+
models.Index(fields=['subject_id'], name='grantmodel_subject_id_idx'),
|
|
96
|
+
]
|
|
97
|
+
|
|
98
|
+
def __str__(self):
|
|
99
|
+
return f"GrantModel(entity_id={self.entity_id}, subject_id={self.subject_id}, role_name={self.role_name})"
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class InviteModel(EntityModel):
|
|
103
|
+
"""A pending invite, contained by the resource it invites to. Holds the
|
|
104
|
+
hash of the link secret, never the secret."""
|
|
105
|
+
role_name = models.CharField(max_length=100)
|
|
106
|
+
token_hash = models.CharField(max_length=64)
|
|
107
|
+
expires_at = models.FloatField(null=True, blank=True)
|
|
108
|
+
max_uses = models.IntegerField(default=1)
|
|
109
|
+
redeemed_by = JSONField(default=list)
|
|
110
|
+
|
|
111
|
+
def __str__(self):
|
|
112
|
+
return f"InviteModel(entity_id={self.entity_id}, role_name={self.role_name})"
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
class GroupModel(EntityModel):
|
|
116
|
+
"""A pure subject: a name and a roster, nothing else."""
|
|
117
|
+
name = models.CharField(max_length=255, null=True, blank=True)
|
|
118
|
+
key = models.CharField(max_length=150, null=True, blank=True)
|
|
119
|
+
member_ids = JSONField(default=list)
|
|
120
|
+
|
|
121
|
+
class Meta:
|
|
122
|
+
indexes = [
|
|
123
|
+
GinIndex(fields=['member_ids'], name='group_member_ids_gin'),
|
|
124
|
+
]
|
|
125
|
+
constraints = [
|
|
126
|
+
models.UniqueConstraint(
|
|
127
|
+
fields=['key'], name='uniq_group_key', condition=models.Q(key__isnull=False),
|
|
128
|
+
),
|
|
129
|
+
]
|
|
130
|
+
|
|
131
|
+
def __str__(self):
|
|
132
|
+
return f"GroupModel(entity_id={self.entity_id}, name={self.name})"
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
class ViewModel(EntityModel):
|
|
136
|
+
"""Stored view state. `position_key` holds at most one view per sibling
|
|
137
|
+
scope, client, slot, and `renders`; a page is read by `address` and `client`."""
|
|
138
|
+
component = models.CharField(max_length=255, null=True, blank=True)
|
|
139
|
+
renders = models.CharField(max_length=255, null=True, blank=True, db_index=True)
|
|
140
|
+
client = models.CharField(max_length=255, null=True, blank=True)
|
|
141
|
+
slot = models.CharField(max_length=255, null=True, blank=True)
|
|
142
|
+
address = models.CharField(max_length=255, null=True, blank=True)
|
|
143
|
+
position_key = models.CharField(max_length=64, null=True, blank=True)
|
|
144
|
+
state = JSONField(default=dict)
|
|
145
|
+
|
|
146
|
+
class Meta:
|
|
147
|
+
indexes = [
|
|
148
|
+
models.Index(fields=['address', 'client'], name='view_address_client_idx'),
|
|
149
|
+
]
|
|
150
|
+
constraints = [
|
|
151
|
+
models.UniqueConstraint(
|
|
152
|
+
fields=['position_key'], name='uniq_view_position_key',
|
|
153
|
+
condition=models.Q(position_key__isnull=False),
|
|
154
|
+
),
|
|
155
|
+
]
|
|
156
|
+
|
|
157
|
+
def __str__(self):
|
|
158
|
+
return f"ViewModel(entity_id={self.entity_id}, address={self.address}, slot={self.slot})"
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
class DeploymentModel(EntityModel):
|
|
162
|
+
"""The single `Deployment`; `singleton` is unique, so concurrent
|
|
163
|
+
seeding cannot create a second one."""
|
|
164
|
+
singleton = models.BooleanField(default=True, unique=True, editable=False)
|
|
165
|
+
new_user_group_ids = models.JSONField(default=list)
|
|
166
|
+
new_user_roles = models.JSONField(default=list)
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
class UserModel(EntityModel):
|
|
170
|
+
"""
|
|
171
|
+
Django model for User.
|
|
172
|
+
"""
|
|
173
|
+
# The issuer's `preferred_username`, resynced on sign-in; for display.
|
|
174
|
+
username = models.CharField(max_length=150, null=True, blank=True)
|
|
175
|
+
# Assumes one external identity per user. If account linking is ever
|
|
176
|
+
# needed, these migrate cleanly to a `user 1—* identities` table.
|
|
177
|
+
issuer = models.CharField(max_length=255, null=True, blank=True)
|
|
178
|
+
subject = models.CharField(max_length=255, null=True, blank=True)
|
|
179
|
+
|
|
180
|
+
class Meta:
|
|
181
|
+
constraints = [
|
|
182
|
+
models.UniqueConstraint(
|
|
183
|
+
fields=['issuer', 'subject'],
|
|
184
|
+
name='uniq_user_iss_sub',
|
|
185
|
+
condition=models.Q(issuer__isnull=False, subject__isnull=False),
|
|
186
|
+
),
|
|
187
|
+
]
|
|
188
|
+
|
|
189
|
+
def __str__(self):
|
|
190
|
+
return f"UserModel(entity_id={self.entity_id}, issuer={self.issuer}, subject={self.subject})"
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
class ServiceAccountModel(EntityModel):
|
|
194
|
+
"""
|
|
195
|
+
Django model for ServiceAccount.
|
|
196
|
+
"""
|
|
197
|
+
app_id = models.CharField(max_length=100, null=True, blank=True)
|
|
198
|
+
client_name = models.CharField(max_length=100, null=True, blank=True)
|
|
199
|
+
client_id = models.CharField(max_length=255, null=True, blank=True)
|
|
200
|
+
issuer = models.CharField(max_length=255, null=True, blank=True)
|
|
201
|
+
|
|
202
|
+
class Meta:
|
|
203
|
+
constraints = [
|
|
204
|
+
models.UniqueConstraint(
|
|
205
|
+
fields=['client_id'],
|
|
206
|
+
name='uniq_service_account_client_id',
|
|
207
|
+
condition=models.Q(client_id__isnull=False),
|
|
208
|
+
),
|
|
209
|
+
]
|
|
210
|
+
|
|
211
|
+
def __str__(self):
|
|
212
|
+
return f"ServiceAccountModel(entity_id={self.entity_id}, client_id={self.client_id})"
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
class StrategyRequestModel(EntityModel):
|
|
216
|
+
"""One run of a strategy and its outcome."""
|
|
217
|
+
strategy_name = models.CharField(max_length=255)
|
|
218
|
+
param_config = models.JSONField(default=dict)
|
|
219
|
+
target_entity_id = models.CharField(max_length=255, null=True, blank=True)
|
|
220
|
+
callbacks = models.JSONField(default=list)
|
|
221
|
+
callback_channel = models.CharField(max_length=255, null=True, blank=True)
|
|
222
|
+
client_request_id = models.CharField(max_length=255, null=True, blank=True)
|
|
223
|
+
status = models.CharField(max_length=16, default='pending')
|
|
224
|
+
attempt = models.IntegerField(default=0)
|
|
225
|
+
attempt_deadline = models.FloatField(null=True, blank=True)
|
|
226
|
+
ret_val = models.JSONField(default=dict)
|
|
227
|
+
error = models.TextField(null=True, blank=True)
|
|
228
|
+
error_code = models.CharField(max_length=64, null=True, blank=True)
|
|
229
|
+
error_details = models.JSONField(default=dict)
|
|
230
|
+
template_id = models.CharField(max_length=255, null=True, blank=True)
|
|
231
|
+
|
|
232
|
+
class Meta:
|
|
233
|
+
indexes = [
|
|
234
|
+
# The run reconciler's scan: running requests past their deadline.
|
|
235
|
+
models.Index(fields=['status', 'attempt_deadline'], name='request_status_deadline_idx'),
|
|
236
|
+
]
|
|
237
|
+
|
|
238
|
+
def __str__(self):
|
|
239
|
+
return f"StrategyRequestModel(name={self.strategy_name}, entity_id={self.entity_id})"
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
class RequestTemplateModel(EntityModel):
|
|
243
|
+
"""A request to make later, optionally on a schedule."""
|
|
244
|
+
strategy_name = models.CharField(max_length=255)
|
|
245
|
+
param_config = models.JSONField(default=dict)
|
|
246
|
+
target_entity_id = models.CharField(max_length=255, null=True, blank=True, db_index=True)
|
|
247
|
+
callbacks = models.JSONField(default=list)
|
|
248
|
+
cron = models.CharField(max_length=100, null=True, blank=True)
|
|
249
|
+
enabled = models.BooleanField(default=True)
|
|
250
|
+
|
|
251
|
+
def __str__(self):
|
|
252
|
+
return f"RequestTemplateModel(name={self.strategy_name}, entity_id={self.entity_id})"
|