diff --git a/gso/api/v1/imports.py b/gso/api/v1/imports.py index 70e0906984e6c56fea8ab433d6e868d89db88c31..bd8c0d5f2cb41b654e198d84f093d8d204714215 100644 --- a/gso/api/v1/imports.py +++ b/gso/api/v1/imports.py @@ -1,4 +1,4 @@ -from typing import Any, Dict +from typing import Any from uuid import UUID from fastapi import Depends, HTTPException, status @@ -30,20 +30,16 @@ def _start_process(process_name: str, data: dict) -> UUID: @router.post("/sites", status_code=status.HTTP_201_CREATED, response_model=ImportResponseModel) -def import_site(site: SiteImportModel) -> Dict[str, Any]: +def import_site(site: SiteImportModel) -> dict[str, Any]: """Import a site by running the import_site workflow. - Args: - ----- - site (SiteImportModel): The site information to be imported. + :param site: The site information to be imported. + :type site: SiteImportModel - Returns: - -------- - dict: A dictionary containing the process id of the started process and detail message. + :return: A dictionary containing the process id of the started process and detail message. + :rtype: dict[str, Any] - Raises: - ------- - HTTPException: If the site already exists or if there's an error in the process. + :raises HTTPException: If the site already exists or if there's an error in the process. """ try: subscription = subscriptions.retrieve_subscription_by_subscription_instance_value( @@ -59,20 +55,16 @@ def import_site(site: SiteImportModel) -> Dict[str, Any]: @router.post("/routers", status_code=status.HTTP_201_CREATED, response_model=ImportResponseModel) -def import_router(router_data: RouterImportModel) -> Dict[str, Any]: +def import_router(router_data: RouterImportModel) -> dict[str, Any]: """Import a router by running the import_router workflow. - Args: - ----- - router_data (RouterImportModel): The router information to be imported. + :param router_data: The router information to be imported. + :type router_data: RouterImportModel - Returns: - -------- - dict: A dictionary containing the process id of the started process and detail message. + :return: A dictionary containing the process id of the started process and detail message. + :rtype: dict[str, Any] - Raises: - ------- - HTTPException: If there's an error in the process. + :raises HTTPException: If there's an error in the process. """ pid = _start_process("import_router", router_data.dict()) @@ -80,20 +72,16 @@ def import_router(router_data: RouterImportModel) -> Dict[str, Any]: @router.post("/iptrunks", status_code=status.HTTP_201_CREATED, response_model=ImportResponseModel) -def import_iptrunk(iptrunk_data: IptrunkImportModel) -> Dict[str, Any]: +def import_iptrunk(iptrunk_data: IptrunkImportModel) -> dict[str, Any]: """Import an iptrunk by running the import_iptrunk workflow. - Args: - ----- - iptrunk_data (IptrunkImportModel): The iptrunk information to be imported. + :param iptrunk_data: The iptrunk information to be imported. + :type iptrunk_data: IptrunkImportModel - Returns: - -------- - dict: A dictionary containing the process id of the started process and detail message. + :return: A dictionary containing the process id of the started process and detail message. + :rtype: dict[str, Any] - Raises: - ------- - HTTPException: If there's an error in the process. + :raises HTTPException: If there's an error in the process. """ pid = _start_process("import_iptrunk", iptrunk_data.dict()) diff --git a/gso/services/subscriptions.py b/gso/services/subscriptions.py index e11211c56f5b0e438c4fbb6606ad541545e90ebd..5e234813f34dba4818da1e7504e0d33a023070ab 100644 --- a/gso/services/subscriptions.py +++ b/gso/services/subscriptions.py @@ -18,14 +18,13 @@ def get_active_subscriptions( ) -> list[Subscription]: """Retrieve active subscriptions for a specific product type. - Args: - ----- - product_type (str): The type of the product for which to retrieve subscriptions. - fields (list[str]): List of fields to be included in the returned Subscription objects. - - Returns: - -------- - list[Subscription]: A list of Subscription objects that match the query. + :param product_type: The type of the product for which to retrieve subscriptions. + :type product_type: str + :param fields: List of fields to be included in the returned Subscription objects. + :type fields: list[str] + + :return: A list of Subscription objects that match the query. + :rtype: list[Subscription] """ dynamic_fields = [getattr(SubscriptionTable, field) for field in fields] @@ -43,13 +42,11 @@ def get_active_subscriptions( def get_active_site_subscriptions(fields: list[str]) -> list[Subscription]: """Retrieve active subscriptions specifically for sites. - Args: - ----- - fields (list[str]): The fields to be included in the returned Subscription objects. + :param fields: The fields to be included in the returned Subscription objects. + :type fields: list[str] - Returns: - -------- - list[Subscription]: A list of Subscription objects for sites. + :return: A list of Subscription objects for sites. + :rtype: list[Subscription] """ return get_active_subscriptions(ProductType.SITE, fields) @@ -57,13 +54,11 @@ def get_active_site_subscriptions(fields: list[str]) -> list[Subscription]: def get_active_router_subscriptions(fields: list[str]) -> list[Subscription]: """Retrieve active subscriptions specifically for routers. - Args: - ----- - fields (list[str]): The fields to be included in the returned Subscription objects. + :param fields: The fields to be included in the returned Subscription objects. + :type fields: list[str] - Returns: - -------- - list[Subscription]: A list of Subscription objects for routers. + :return: A list of Subscription objects for routers. + :rtype: list[Subscription] """ return get_active_subscriptions(product_type=ProductType.ROUTER, fields=fields) @@ -71,13 +66,11 @@ def get_active_router_subscriptions(fields: list[str]) -> list[Subscription]: def get_product_id_by_name(product_name: ProductType) -> UUID: """Retrieve the :term:`UUID` of a product by its name. - Args: - ----- - product_name (ProductType): The name of the product. + :param product_name: The name of the product. + :type product_name: ProductType - Returns: - -------- - :term:`UUID`: The :term:`UUID` of the product. + :return UUID: The :term:`UUID` of the product. + :rtype: UUID """ return ProductTable.query.filter_by(name=product_name).first().product_id @@ -85,13 +78,11 @@ def get_product_id_by_name(product_name: ProductType) -> UUID: def get_active_site_subscription_by_name(site_name: str) -> Subscription: """Retrieve an active subscription for a site by the site's name. - Args: - ----- - site_name (str): The name of the site for which to retrieve the subscription. + :param site_name: The name of the site for which to retrieve the subscription. + :type site_name: str - Returns: - -------- - Subscription: The Subscription object for the site. + :return: The Subscription object for the site. + :rtype: Subscription """ return ( SubscriptionTable.query.join(ProductTable)