Commit abe6a384 authored by Pelayo Torres's avatar Pelayo Torres
Browse files

Merge branch 'OCF132-audit-api-supported-feature-negotiation' into 'staging'

Resolve "Audit API supported feature negotiation"

Closes #132

See merge request !133
parents 1d1a9e9b ee54204a
Loading
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -9,6 +9,17 @@ from .resources import Resource
from .responses import bad_request_error, internal_server_error, make_response, not_found_error


TOTAL_FEATURES = 2
SUPPORTED_FEATURES_HEX = "1"

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 {
        "EnQueryInvokeLog": True if final_supp_feat[0] == "1" else False,
        "SliceBasedAPIExposure": True if final_supp_feat[1] == "1" else False,
        "Final": hex(int(final_supp_feat[::-1], 2))[2:]
    }

class AuditOperations (Resource):

    def get_logs(self, query_parameters):
@@ -55,6 +66,13 @@ class AuditOperations (Resource):
            if not result['logs']:
                return not_found_error(detail="Parameters do not match any log entry", cause="No logs found")

            client_features = query_parameters.get('supported_features')
            if client_features:
                negotiated = return_negotiated_supp_feat_dict(client_features)
                result['supported_features'] = negotiated["Final"]
            else:
                result['supported_features'] = client_features

            invocation_log = InvocationLog(result['aef_id'], result['api_invoker_id'], result['logs'],
                                           result['supported_features'])
            res = make_response(object=serialize_clean_camel_case(invocation_log), status=200)