Skip to content
Commits on Source (3)
# [2.2.0](https://gitlab.ics.muni.cz/perun/perun-proxyidp/aup-manager/compare/v2.1.0...v2.2.0) (2024-07-17)
### Features
* performance optimization ([8ed2859](https://gitlab.ics.muni.cz/perun/perun-proxyidp/aup-manager/commit/8ed2859bf6e905b27bb91078770a5c0ab70d6c54))
# [2.1.0](https://gitlab.ics.muni.cz/perun/perun-proxyidp/aup-manager/compare/v2.0.6...v2.1.0) (2024-06-04)
......
......@@ -47,7 +47,7 @@ class AppProperties:
jwk_set.import_keyset(file.read())
self.json_web_key = jwk_set.get_key(key_id)
self.accept_aups_default_message = config.get(
self.accept_aups_message = config.get(
"accept_aups_message",
"Before proceeding to service, you have to accept following acceptable use "
"policies. These policies restrict the ways in which the service may be used "
......
......@@ -46,7 +46,7 @@ class PerunConnector(ConnectorInterface):
resources = self.connector.get_resources_for_facility(int(entity_id), True)
for resource in resources:
if not self.connector.get_groups_for_resource(resource, False):
if not self.connector.get_group_ids_for_resource(resource):
result |= {f"resource:{resource.id}", f"vo:{resource.vo.id}"}
else:
groups = self.connector.get_groups_where_user_is_active_resource(
......@@ -74,16 +74,24 @@ class PerunConnector(ConnectorInterface):
if isinstance(admin_uid, str):
admin_uid = int(admin_uid)
is_perun_admin = False
if self.perun_admin_get_all_entities and self.connector.is_user_perun_admin(
admin_uid
):
is_perun_admin = True
with concurrent.futures.ThreadPoolExecutor() as executor:
future_resources = executor.submit(
self._get_resources_from_perun_as_entities, admin_uid
self._get_resources_from_perun_as_entities, admin_uid, is_perun_admin
)
future_vos = executor.submit(
self._get_vo_from_perun_as_entities, admin_uid, is_perun_admin
)
future_vos = executor.submit(self._get_vo_from_perun_as_entities, admin_uid)
future_facilities = executor.submit(
self._get_facilities_from_perun_as_entities, admin_uid
self._get_facilities_from_perun_as_entities, admin_uid, is_perun_admin
)
future_groups = executor.submit(
self._get_groups_from_perun_as_entities, admin_uid
self._get_groups_from_perun_as_entities, admin_uid, is_perun_admin
)
resources = future_resources.result()
......@@ -98,48 +106,67 @@ class PerunConnector(ConnectorInterface):
}
def _get_resources_from_perun_as_entities(
self, admin_uid: Union[str, int] = None
self, admin_uid: Union[str, int] = None, is_perun_admin: bool = False
) -> List[Entity]:
resources = self.connector.get_resources_where_user_is_admin(
admin_uid,
check_perun_admin=self.perun_admin_get_all_entities,
fill_facility_rp_id=False,
fetch_related_vos=False,
fetch_related_facilities=False,
)
if is_perun_admin:
resources = self.connector.get_all_resources(
fill_facility_rp_id=False,
fetch_related_vos=False,
fetch_related_facilities=False,
)
else:
resources = self.connector.get_resources_where_user_is_admin(
admin_uid,
check_perun_admin=False,
fill_facility_rp_id=False,
fetch_related_vos=False,
fetch_related_facilities=False,
)
return [
Entity(resource.id, resource.name, "resource") for resource in resources
]
def _get_vo_from_perun_as_entities(
self, admin_uid: Union[str, int] = None
self, admin_uid: Union[str, int] = None, is_perun_admin: bool = False
) -> List[Entity]:
vos = self.connector.get_vos_where_user_is_admin(
admin_uid, check_perun_admin=self.perun_admin_get_all_entities
)
if is_perun_admin:
vos = self.connector.get_all_vos()
else:
vos = self.connector.get_vos_where_user_is_admin(
admin_uid, check_perun_admin=False
)
return [Entity(vo.id, vo.name, "vo") for vo in vos]
def _get_facilities_from_perun_as_entities(
self, admin_uid: Union[str, int] = None
self, admin_uid: Union[str, int] = None, is_perun_admin: bool = False
) -> List[Entity]:
facilities = self.connector.get_facilities_where_user_is_admin(
admin_uid,
check_perun_admin=self.perun_admin_get_all_entities,
fill_facility_rp_id=False,
)
if is_perun_admin:
facilities = self.connector.get_all_facilities(fill_facility_rp_id=False)
else:
facilities = self.connector.get_facilities_where_user_is_admin(
admin_uid,
check_perun_admin=False,
fill_facility_rp_id=False,
)
return [
Entity(facility.id, facility.name, "facility") for facility in facilities
]
def _get_groups_from_perun_as_entities(
self, admin_uid: Union[str, int] = None
self, admin_uid: Union[str, int] = None, is_perun_admin: bool = False
) -> List[Entity]:
groups = self.connector.get_groups_where_user_is_admin(
admin_uid,
check_perun_admin=self.perun_admin_get_all_entities,
fill_group_unique_name=False,
fetch_related_vos=False,
)
if is_perun_admin:
groups = self.connector.get_all_groups(
fill_group_unique_name=False,
fetch_related_vos=False,
)
else:
groups = self.connector.get_groups_where_user_is_admin(
admin_uid,
check_perun_admin=False,
fill_group_unique_name=False,
fetch_related_vos=False,
)
return [Entity(group.id, group.name, "group") for group in groups]
def get_user_id(self, ext_login: str, ext_name: str = None) -> Union[int, str]:
......
from connexion import FlaskApp
from flask_pyoidc import OIDCAuthentication
from flask_pyoidc.provider_configuration import ProviderConfiguration, ClientMetadata
from perun.connector import Logger
from swagger_ui_bundle import swagger_ui_3_path
from aup_manager.app_properties import AppProperties
from aup_manager.gui import construct_gui_blueprint
logger = Logger.get_logger(__name__)
def exception_handler(error):
return {
......
import json
import time
from urllib import parse
from urllib.parse import urlparse, urlencode
from flask import Blueprint
from flask import Response, render_template, redirect, session, url_for, request
......@@ -85,7 +85,10 @@ def construct_gui_blueprint(auth: OIDCAuthentication):
)
if len(aups) == 0:
database.save_request(Request(nonce, user_id, status=Status.SUCCESS))
return redirect(callback_url + "?" + parse.urlencode({"nonce": nonce}))
callback_url += ("&" if urlparse(callback_url).query else "?") + urlencode(
{"nonce": nonce}
)
return redirect(callback_url)
aups_as_dict = [aup.__dict__ for aup in aups]
session["accept_user_id"] = user_id
......@@ -118,7 +121,10 @@ def construct_gui_blueprint(auth: OIDCAuthentication):
return Response(json.dumps({"fail": "Invalid nonce."}), 403)
save_acceptances_to_db(user_id, aup_ids, database)
database.make_request_success(internal_request.get_id())
return redirect(callback_url + "?" + parse.urlencode({"nonce": nonce}))
callback_url += ("&" if urlparse(callback_url).query else "?") + urlencode(
{"nonce": nonce}
)
return redirect(callback_url)
@gui.route("/get_accept_result/<message>")
def get_accept_result(message):
......
[metadata]
version = 2.1.0
version = 2.2.0
license_files = LICENSE
......@@ -39,7 +39,7 @@ setuptools.setup(
"urllib3~=1.21",
],
extras_require={
"perun": ["perun.connector~=3.9"],
"perun": ["perun.connector~=3.11"],
},
cmdclass={
"install": PostInstallCommand,
......