88
99import arrow
1010from fastapi import FastAPI
11+ from models_library .groups import GroupID
1112from models_library .services import ServiceMetaDataPublished
1213from models_library .services_types import ServiceKey , ServiceVersion
1314from packaging .version import Version
@@ -41,21 +42,32 @@ async def _is_old_service(app: FastAPI, service: ServiceMetaDataPublished) -> bo
4142 return bool (service_build_data < _LEGACY_SERVICES_DATE )
4243
4344
44- async def evaluate_default_policy (
45+ async def evaluate_service_ownership_and_rights (
4546 app : FastAPI , service : ServiceMetaDataPublished
46- ) -> tuple [PositiveInt | None , list [ServiceAccessRightsDB ]]:
47- """Given a service, it returns the owner's group-id (gid) and a list of access rights following
48- default access-rights policies
49-
50- - DEFAULT Access Rights policies:
51- 1. All services published in osparc prior 19.08.2020 will be visible to everyone (refered as 'old service').
52- 2. Services published after 19.08.2020 will be visible ONLY to his/her owner
53- 3. Front-end services are have execute-access to everyone
47+ ) -> tuple [GroupID | None , list [ServiceAccessRightsDB ]]:
48+ """Evaluates the owner (group_id) and the access rights for a service
49+
50+ This function determines:
51+ 1. Who owns the service (based on contact or author email)
52+ 2. Who can access the service based on the following rules:
53+ - All services published before August 19, 2020 (_LEGACY_SERVICES_DATE) are accessible to everyone
54+ - Services published after August 19, 2020 are only accessible to their owner
55+ - Frontend services are accessible to everyone regardless of publication date
56+
57+ Args:
58+ app: FastAPI application instance containing database engine and settings
59+ service: Service metadata including key, version, contact and authors information
60+
61+ Returns:
62+ A tuple containing:
63+ - The owner's group ID (gid) if found, None otherwise
64+ - A list of ServiceAccessRightsDB objects representing the default access rights
65+ for the service, including who can execute and/or modify the service
5466
5567 Raises:
56- HTTPException: from calls to director 's rest API. Maps director errors into catalog's server error
57- SQLAlchemyError: from access to pg database
58- ValidationError: from pydantic model errors
68+ HTTPException: If there 's an error communicating with the director API
69+ SQLAlchemyError: If there's an error accessing the database
70+ ValidationError: If there's an error validating the Pydantic models
5971 """
6072 db_engine : AsyncEngine = app .state .engine
6173
@@ -83,7 +95,7 @@ async def evaluate_default_policy(
8395 if possible_gid and not owner_gid :
8496 owner_gid = possible_gid
8597 if not owner_gid :
86- _logger .warning ("service %s:%s has no owner" , service .key , service .version )
98+ _logger .warning ("Service %s:%s has no owner" , service .key , service .version )
8799 else :
88100 group_ids .append (owner_gid )
89101
@@ -106,16 +118,29 @@ async def evaluate_default_policy(
106118
107119
108120async def evaluate_auto_upgrade_policy (
109- service_metadata : ServiceMetaDataPublished , services_repo : ServicesRepository
121+ services_repo : ServicesRepository , * , service_metadata : ServiceMetaDataPublished
110122) -> list [ServiceAccessRightsDB ]:
111- # AUTO-UPGRADE PATCH policy:
112- #
113- # - Any new patch released, inherits the access rights from previous compatible version
114- # - IDEA: add as option in the publication contract, i.e. in ServiceDockerData?
115- # - Does NOT apply to front-end services
116- #
117- # SEE https://github.com/ITISFoundation/osparc-simcore/issues/2244)
118- #
123+ """
124+ Evaluates the access rights for a service based on the auto-upgrade patch policy.
125+
126+ The AUTO-UPGRADE PATCH policy ensures that:
127+ - Any new patch release of a service automatically inherits the access rights from the previous compatible version.
128+ - This policy does NOT apply to frontend services.
129+
130+ Args:
131+ services_repo: Instance of ServicesRepository for database access.
132+ service_metadata: Metadata of the service being evaluated.
133+
134+ Returns:
135+ A list of ServiceAccessRightsDB objects representing the inherited access rights for the new patch version.
136+ Returns an empty list if the service is a frontend service or if no previous compatible version is found.
137+
138+ Notes:
139+ - The policy is described in https://github.com/ITISFoundation/osparc-simcore/issues/2244
140+ - Inheritance is only for patch releases (i.e., same major and minor version).
141+ - Future improvement: Consider making this behavior configurable in the service publication contract.
142+
143+ """
119144 if _is_frontend_service (service_metadata ):
120145 return []
121146
@@ -129,8 +154,8 @@ async def evaluate_auto_upgrade_policy(
129154
130155 previous_release = None
131156 for release in latest_releases :
132- # NOTE: latest_release is sorted from newer to older
133- # Here we search for the previous version patched by new-version
157+ # latest_releases is sorted from newer to older
158+ # Find the previous version that is patched by new_version
134159 if is_patch_release (new_version , release .version ):
135160 previous_release = release
136161 break
0 commit comments