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,59 @@
|
|
|
1
|
+
"""User lookup through the entity-store port, so sign-in reads whichever
|
|
2
|
+
repository the runtime was built with. Only keys the store keeps unique are
|
|
3
|
+
offered, so a match is the user rather than one of several."""
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
from graphcore.domain.entity.user.User import User
|
|
7
|
+
from graphcore.errors import DuplicateEntity
|
|
8
|
+
from graphcore.execution.strategy_context import kernel_internal_context
|
|
9
|
+
from graphcore.graph.EntityService import EntityService
|
|
10
|
+
from graphcore.types.identity import Principal
|
|
11
|
+
from graphcore.types.query import AllOf, Equal, Predicate
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
async def find_user_by_identity(entity_service: EntityService, issuer: str, subject: str) -> Optional[User]:
|
|
15
|
+
return await _find_user(entity_service, AllOf((Equal('issuer', issuer), Equal('subject', subject))))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
async def find_users_by_username(entity_service: EntityService, username: str) -> list[User]:
|
|
19
|
+
users = await entity_service.find_entities(AllOf((
|
|
20
|
+
Equal('entity_type_id', User.get_entity_type_id()),
|
|
21
|
+
Equal('username', username),
|
|
22
|
+
)))
|
|
23
|
+
return list(users.values())
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
async def _find_user(entity_service: EntityService, predicate: Predicate) -> Optional[User]:
|
|
27
|
+
users = await entity_service.find_entities(AllOf((
|
|
28
|
+
Equal('entity_type_id', User.get_entity_type_id()),
|
|
29
|
+
predicate,
|
|
30
|
+
)))
|
|
31
|
+
return next(iter(users.values()), None)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _username(claims: dict) -> str:
|
|
35
|
+
return str(claims.get('preferred_username') or claims.get('email') or claims['sub'])[:150]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
async def resolve_user(entity_service: EntityService, executor, claims: dict) -> str:
|
|
39
|
+
"""The `User` of a verified token's `(iss, sub)`: created and onboarded on
|
|
40
|
+
first contact, its username kept in step with `preferred_username`."""
|
|
41
|
+
from graphcore.auth.authn.principals import create_principal
|
|
42
|
+
|
|
43
|
+
iss, sub = claims['iss'], str(claims['sub'])
|
|
44
|
+
user = await find_user_by_identity(entity_service, iss, sub)
|
|
45
|
+
if user is None:
|
|
46
|
+
try:
|
|
47
|
+
user = await create_principal(entity_service, executor, username=_username(claims), issuer=iss, subject=sub)
|
|
48
|
+
except DuplicateEntity:
|
|
49
|
+
# A concurrent first sign-in created it.
|
|
50
|
+
user = await find_user_by_identity(entity_service, iss, sub)
|
|
51
|
+
if user is None:
|
|
52
|
+
raise
|
|
53
|
+
return user.entity_id
|
|
54
|
+
username = claims.get('preferred_username')
|
|
55
|
+
if username and user.username != username[:150]:
|
|
56
|
+
user.username = username[:150]
|
|
57
|
+
with kernel_internal_context():
|
|
58
|
+
await entity_service.save_entity(user, Principal(principal_entity_id=user.entity_id))
|
|
59
|
+
return user.entity_id
|
|
File without changes
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"""The authorization contract: the interface every adapter implements, and
|
|
2
|
+
the only surface the rest of the system calls to ask authorization
|
|
3
|
+
questions or interpret grants.
|
|
4
|
+
|
|
5
|
+
See docs/AUTHORIZATION_TECHNICAL_TDD.md (The AccessPort, Port consumers).
|
|
6
|
+
Grant *mutation* is never on this port - grants are entities, mutated
|
|
7
|
+
through kernel strategies like any other write (domain/strategy/GrantStrategies.py).
|
|
8
|
+
|
|
9
|
+
Every method below takes plain ids (or the entity/model instance a hook is
|
|
10
|
+
genuinely handed), never an id-or-object union - a caller with an object in
|
|
11
|
+
hand passes `entity.entity_id`, not the object itself.
|
|
12
|
+
"""
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
from abc import ABC, abstractmethod
|
|
16
|
+
from typing import Iterable, Optional
|
|
17
|
+
|
|
18
|
+
from graphcore.domain.entity.Entity import Entity
|
|
19
|
+
from graphcore.types.access import AccessChange, GrantInfo, Perm, Role
|
|
20
|
+
from graphcore.types.identity import Principal
|
|
21
|
+
from graphcore.types.query import Predicate
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class AccessPort(ABC):
|
|
25
|
+
|
|
26
|
+
# --- decisions ---
|
|
27
|
+
|
|
28
|
+
@abstractmethod
|
|
29
|
+
async def allows(self, principal: Principal, perm: Perm, entity_id: str) -> bool:
|
|
30
|
+
"""Whether `principal` holds `perm` on `entity_id` - directly, via an
|
|
31
|
+
ancestor scope's grant, via owner-implicit Admin, or via a
|
|
32
|
+
type-wide public perm. The port knows no per-type read policy: the
|
|
33
|
+
engine asks for the exact perm it needs."""
|
|
34
|
+
|
|
35
|
+
@abstractmethod
|
|
36
|
+
async def read_filters(self, principal: Principal, perms: Iterable[Perm]) -> dict[Perm, Predicate]:
|
|
37
|
+
"""Per perm, a predicate over entity fields selecting what
|
|
38
|
+
`principal` holds it on - predicate pushdown, not a materialized id
|
|
39
|
+
set, so a caller can page the result without ever loading the
|
|
40
|
+
principal's full readable closure into memory. The engine combines
|
|
41
|
+
them with each type's read permission and its own filter, and hands
|
|
42
|
+
the whole thing to the repository in one statement."""
|
|
43
|
+
|
|
44
|
+
# --- grant interpretation (mutation is kernel strategies; see Grant storage) ---
|
|
45
|
+
|
|
46
|
+
@abstractmethod
|
|
47
|
+
async def available_roles(self, resource_id: str) -> list[Role]:
|
|
48
|
+
"""The roles grantable on this resource's type."""
|
|
49
|
+
|
|
50
|
+
@abstractmethod
|
|
51
|
+
async def list_grants(self, principal: Principal, resource_id: str) -> list[GrantInfo]:
|
|
52
|
+
"""Each entry carries subject, role, and provenance: direct,
|
|
53
|
+
inherited-from-<scope>, owner, or type-policy."""
|
|
54
|
+
|
|
55
|
+
# --- sync support ---
|
|
56
|
+
|
|
57
|
+
@abstractmethod
|
|
58
|
+
async def granted_resources(self, principal: Principal, *, include_public: bool = True) -> set[str]:
|
|
59
|
+
"""Resource ids the principal holds a grant on themselves, directly
|
|
60
|
+
or via group membership. `include_public=False` leaves out grants to
|
|
61
|
+
`PUBLIC`: what is shared with the principal, not with everyone."""
|
|
62
|
+
|
|
63
|
+
@abstractmethod
|
|
64
|
+
async def owner_principals(self, resource_ids: set[str]) -> set[str]:
|
|
65
|
+
"""Owner principal ids for these resources, used for live fan-out."""
|
|
66
|
+
|
|
67
|
+
@abstractmethod
|
|
68
|
+
async def holders(self, perm: Perm, scope_ids: set[str]) -> tuple[set[str], bool]:
|
|
69
|
+
"""`(principal_ids, everyone)`: the principals holding `perm` on any
|
|
70
|
+
of these scopes, and whether every principal does. Live fan-out for
|
|
71
|
+
a type whose read permission is not Read."""
|
|
72
|
+
|
|
73
|
+
@abstractmethod
|
|
74
|
+
async def scopes(self, entity_id: str, ancestor_ids) -> set[str]:
|
|
75
|
+
"""entity_id plus every ancestor scope whose grants cover this
|
|
76
|
+
entity. Takes these fields explicitly rather than an entity object:
|
|
77
|
+
the caller (the broadcaster, publishing a just-committed delete)
|
|
78
|
+
may only have a lightweight stand-in for the entity, not a real one
|
|
79
|
+
- but it always has these two fields, so that's all this asks for."""
|
|
80
|
+
|
|
81
|
+
@abstractmethod
|
|
82
|
+
async def covers(self, subject_id: str, principal_ids: list[str]) -> set[str]:
|
|
83
|
+
"""Which of these principal ids the subject resolves to."""
|
|
84
|
+
|
|
85
|
+
# --- entity-write checks (the lockout rule) ---
|
|
86
|
+
|
|
87
|
+
@abstractmethod
|
|
88
|
+
async def check_save(self, entity: Entity, existing: Entity) -> None:
|
|
89
|
+
"""Raise `Forbidden` if updating `existing` to `entity` would leave
|
|
90
|
+
some resource with nobody able to manage access to it."""
|
|
91
|
+
|
|
92
|
+
@abstractmethod
|
|
93
|
+
async def check_delete(self, entity_ids: set[str]) -> None:
|
|
94
|
+
"""Raise `Forbidden` if deleting these entities together would leave
|
|
95
|
+
some surviving resource with nobody able to manage access to it."""
|
|
96
|
+
|
|
97
|
+
# --- entity-write notification ---
|
|
98
|
+
|
|
99
|
+
@abstractmethod
|
|
100
|
+
async def entity_saved(
|
|
101
|
+
self, entity: Entity, previous: Optional[Entity]
|
|
102
|
+
) -> Optional[AccessChange] | list[AccessChange]:
|
|
103
|
+
"""Called by EntityService once a save has committed. `previous` is
|
|
104
|
+
the entity exactly as it stood before this write (None for a new
|
|
105
|
+
entity), from the repository's save receipt. Usually a single change
|
|
106
|
+
(or None); a group roster change returns one synthetic change per
|
|
107
|
+
affected member - revoke-shaped for a removed member, so
|
|
108
|
+
the broadcaster can leave their connections from covered scopes, and
|
|
109
|
+
fresh-grant-shaped for an added member, so the broadcaster can join
|
|
110
|
+
them live instead of waiting for their next reconnect."""
|
|
111
|
+
|
|
112
|
+
@abstractmethod
|
|
113
|
+
async def prepare_delete(self, entity_ids: list[str]) -> object:
|
|
114
|
+
"""Called by EntityService before a delete, while the rows still
|
|
115
|
+
exist. Returns an opaque plan for `entities_deleted`."""
|
|
116
|
+
|
|
117
|
+
@abstractmethod
|
|
118
|
+
async def entities_deleted(self, plan: object) -> list[AccessChange]:
|
|
119
|
+
"""Called by EntityService once the delete `plan` was prepared for
|
|
120
|
+
has committed."""
|
|
File without changes
|