Commit 5d728dc7 authored by Stavros's avatar Stavros
Browse files

Draft implementation of extensibility feature in Discover API

parent d0d08c02
Loading
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ from service_apis import util

from ..core.discoveredapis import DiscoverApisOperations
from flask import Response, request, current_app
import json

discover_apis = DiscoverApisOperations()

@@ -67,8 +68,24 @@ def all_service_apis_get(api_invoker_id, api_name=None, api_version=None, comm_t
    if request.is_json:
        service_kpis =  ServiceKpis.from_dict(request.get_json()())  # noqa: E501
    current_app.logger.info("Discovering service apis")
    current_app.logger.info(request.args)
    query_params = {"api_name":api_name, "api_version":api_version, "comm_type":comm_type, 
    "protocol":protocol, "aef_id":aef_id, "data_format":data_format, 
    "api_cat":api_cat, "supported_features":supported_features, "api_supported_features":api_supported_features}

    # current_app.logger.info(supported_features)
    if supported_features is not None:
        supp_feat_dict = DiscoveredAPIs.return_supp_feat_dict(supported_features)
        if supp_feat_dict['VendSpecQueryParams']:
            # current_app.logger.info("**************************")
            # current_app.logger.info(request.args)
            # current_app.logger.info("**************************")
            for q_params  in request.args:
                # current_app.logger.info(q_params)
                # current_app.logger.info(request.args[q_params])
                if "vend-spec" in q_params:
                    query_params[q_params] = json.loads(request.args[q_params])

    # current_app.logger.info(query_params)
    response = discover_apis.get_discoveredapis(api_invoker_id, query_params)
    return response
+10 −2
Original line number Diff line number Diff line
@@ -27,10 +27,18 @@ class DiscoverApisOperations(Resource):
            "protocol":"aef_profiles.0.protocol", "aef_id":"aef_profiles.0.aef_id", "data_format":"aef_profiles.0.data_format", 
            "api_cat":"service_api_category", "supported_features":"supported_features", "api_supported_features":"api_supp_feats"}

            # current_app.logger.info(query_params)
            for param in query_params:
                if query_params[param] is not None:
                    if "vend-spec" in param:
                        current_app.logger.info("vend-spec in param")
                        attribute_path = query_params[param]["target"].split('/')
                        attribute = "aef_profiles.0." + attribute_path[1] + "." + attribute_path[2]
                        my_params.append({attribute: query_params[param]["value"]})
                    else:
                        my_params.append({quey_params_name[param]: query_params[param]})

            # current_app.logger.info(my_params)
            if my_params:
                my_query = {"$and": my_params}

+11 −0
Original line number Diff line number Diff line
@@ -30,6 +30,17 @@ class DiscoveredAPIs(Model):

        self._service_api_descriptions = service_api_descriptions

    @classmethod
    def return_supp_feat_dict(cls, supp_feat):
        supp_feat_in_hex = int(supp_feat, 16)
        supp_feat_in_bin = bin(supp_feat_in_hex)[2:]

        return {
            "RNAA": True if supp_feat_in_bin[0] == "1" else False,
            "VendSpecQueryParams": True if supp_feat_in_bin[1] == "1" else False,
            "ApiSupportedFeatureQuery": True if supp_feat_in_bin[2] == "1" else False,
        }

    @classmethod
    def from_dict(cls, dikt) -> 'DiscoveredAPIs':
        """Returns the dict as a model
+1 −1
Original line number Diff line number Diff line
@@ -78,7 +78,7 @@ def apf_id_service_apis_post(apf_id, body): # noqa: E501
    current_app.logger.info("Publishing service")

    supp_feat_dict = ServiceAPIDescription.return_supp_feat_dict(body['supportedFeatures'])
    current_app.logger.info(supp_feat_dict)
    # current_app.logger.info(supp_feat_dict)

    vendor_specific_list = []

+5 −4
Original line number Diff line number Diff line
@@ -109,10 +109,11 @@ class PublishServiceOperations(Resource):
                    # current_app.logger.info(vend_spec_lst)
                    for profile in serviceapidescription_dict['aef_profiles']:
                        if profile['aef_id'] == vend_spec_lst[0][0]:
                            # snake_case the vendor specific key and value to store in mongo
                            key = ''.join(['_'+ i.lower() if i.isupper() else i for i in vend_spec_lst[0][1]]).lstrip('_').replace("-", "_")
                            value = dict_to_camel_case(vend_spec_lst[0][2])
                            profile[key] = value
                            # ##### snake_case the vendor specific key and value to store in mongo
                            # key = ''.join(['_'+ i.lower() if i.isupper() else i for i in vend_spec_lst[0][1]]).lstrip('_').replace("-", "_")
                            # value = dict_to_camel_case(vend_spec_lst[0][2])
                            # profile[key] = value
                            profile[vend_spec_lst[0][1]] = vend_spec_lst[0][2]
            rec.update(serviceapidescription_dict)

            mycol.insert_one(rec)