Commit 8e03d7ed authored by guillecxb's avatar guillecxb
Browse files

implementation with the negotiated hex inside of the dict

parent ba88c40c
Loading
Loading
Loading
Loading
Loading
+10 −25
Original line number Diff line number Diff line
@@ -16,21 +16,16 @@ from ..util import dict_to_camel_case, clean_empty, serialize_clean_camel_case


TOTAL_FEATURES = 2
SUPPORTED_FEATURES_HEX = "1"
SUPPORTED_FEATURES_HEX = "0"

def negotiate_supported_features(supp_feat):
def return_negotiated_supp_feat_dict(supp_feat):
    final_supp_feat = bin(int(supp_feat, 16) & int(SUPPORTED_FEATURES_HEX, 16))[2:].zfill(TOTAL_FEATURES)[::-1]
    return {
        "PatchUpdate": True if final_supp_feat[0] == "1" else False,
        "RNAA": True if final_supp_feat[1] == "1" else False,
        "Final": hex(int(final_supp_feat[::-1], 2))[2:]
    }


def negotiate_supported_features_hex(supp_feat):
    negotiated = int(supp_feat, 16) & int(SUPPORTED_FEATURES_HEX, 16)
    return format(negotiated, 'x')


class ProviderManagementOperations(Resource):

    def __check_api_provider_domain(self, api_prov_dom_id):
@@ -66,18 +61,8 @@ class ProviderManagementOperations(Resource):
            api_provider_enrolment_details.api_prov_dom_id = secrets.token_hex(
                15)
            
            if api_provider_enrolment_details.supp_feat is None:
                return bad_request_error(
                    detail="supportedFeatures not present in request",
                    cause="supportedFeatures not present",
                    invalid_params=[{"param": "supp_feat", "reason": "not defined"}]
                )
            
            # Supported Features Negotiation
            client_feat = api_provider_enrolment_details.supp_feat
            negotiated_hex = negotiate_supported_features_hex(client_feat)
            api_provider_enrolment_details.supp_feat = negotiated_hex
            negotiated_flags = negotiate_supported_features(negotiated_hex)
            negotiated_supported_features = return_negotiated_supp_feat_dict(api_provider_enrolment_details.supp_feat)
            api_provider_enrolment_details.supp_feat = negotiated_supported_features["Final"]

            current_app.logger.debug("Generating certs to api prov funcs")

@@ -101,12 +86,9 @@ class ProviderManagementOperations(Resource):

            current_app.logger.debug("Provider inserted in database")

            response_obj = serialize_clean_camel_case(api_provider_enrolment_details)

            # ← Aquí aplicamos el cambio: sustituimos suppFeat por los flags interpretados
            response_obj["suppFeat"] = negotiated_flags
            res = make_response(object=serialize_clean_camel_case(
                api_provider_enrolment_details), status=201)

            res = make_response(object=response_obj, status=201)
            res.headers['Location'] = f"https://{os.getenv("CAPIF_HOSTNAME")}/api-provider-management/v1/registrations/{str(api_provider_enrolment_details.api_prov_dom_id)}"
            return res

@@ -168,6 +150,9 @@ class ProviderManagementOperations(Resource):
            if isinstance(result, Response):
                return result
            
            negotiated_supported_features = return_negotiated_supp_feat_dict(api_provider_enrolment_details.supp_feat)
            api_provider_enrolment_details.supp_feat = negotiated_supported_features["Final"]

            for func in api_provider_enrolment_details.api_prov_funcs:
                if func.api_prov_func_id is None:
                    func.api_prov_func_id = func.api_prov_func_role + \