Commit 940efcb6 authored by Stavros-Anastasios Charismiadis's avatar Stavros-Anastasios Charismiadis
Browse files

Add neccesary file to vaildate user in Audit

parent 941d69d3
Loading
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
import json

from flask import Response, current_app

from ..encoder import CustomJSONEncoder
from ..models.problem_details import ProblemDetails
from ..util import serialize_clean_camel_case
from .resources import Resource
from .responses import internal_server_error


class ControlAccess(Resource):

    def validate_user_cert(self, cert_signature):

        cert_col = self.db.get_col_by_name(self.db.certs_col)

        try:
            my_query = {'cert_signature': cert_signature}
            cert_entry = cert_col.find_one(my_query)

            if cert_entry is not None:
                if cert_entry["role"] != "AMF":
                    prob = ProblemDetails(title="Unauthorized", detail="User not authorized", cause="You are not the owner of this resource")
                    prob = serialize_clean_camel_case(prob)
                    return Response(json.dumps(prob, cls=CustomJSONEncoder), status=401, mimetype="application/json")

        except Exception as e:
            exception = "An exception occurred in validate invoker"
            current_app.logger.error(exception + "::" + str(e))
            return internal_server_error(detail=exception, cause=str(e))
 No newline at end of file