Пример #1
0
 def __check_if_db_is_up():
     first = True
     while True:
         try:
             PDPManager.get_pdp(user_id="admin", pdp_id=None)
         except sqlalchemy.exc.ProgrammingError:
             time.sleep(1)
             if first:
                 logger.warning("Waiting for the database...")
                 first = False
         else:
             logger.warning("Database is up, resuming operations...")
             break
Пример #2
0
 def _export_pdps(self, json_content):
     pdps = PDPManager.get_pdp(self._user_id)
     pdps_array = []
     for pdp_key in pdps:
         logger.info("Exporting pdp {}".format(pdps[pdp_key]))
         pdps_array.append(pdps[pdp_key])
     if len(pdps_array) > 0:
         json_content["pdps"] = pdps_array
Пример #3
0
    def get(self, uuid=None, user_id=None):
        """Retrieve all pdp

        :param uuid: uuid of the pdp
        :param user_id: user ID who do the request
        :return: {
            "pdp_id1": {
                "name": "...",
                "security_pipeline": [...],
                "keystone_project_id": "keystone_project_id1",
                "description": "... (optional)",
            }
        }
        :internal_api: get_pdp
        """

        data = PDPManager.get_pdp(user_id=user_id, pdp_id=uuid)

        return {"pdps": data}
Пример #4
0
    def get(self, uuid=None, user_id=None):
        """Retrieve all pdp

        :param uuid: uuid of the pdp
        :param user_id: user ID who do the request
        :return: {
            "pdp_id1": {
                "name": "...",
                "security_pipeline": [...],
                "keystone_project_id": "keystone_project_id1",
                "description": "...",
            }
        }
        :internal_api: get_pdp
        """
        try:
            data = PDPManager.get_pdp(user_id=user_id, pdp_id=uuid)
        except Exception as e:
            logger.error(e, exc_info=True)
            return {"result": False, "error": str(e)}, 500
        return {"pdps": data}
Пример #5
0
    def _import_pdps(self, json_pdps):
        if not isinstance(json_pdps, list):
            raise InvalidJson("pdps shall be a list!")

        for json_pdp in json_pdps:
            json_to_use = dict()
            JsonUtils.copy_field_if_exists(json_pdp, json_to_use, "name", str)
            JsonUtils.copy_field_if_exists(json_pdp, json_to_use,
                                           "keystone_project_id", str)
            JsonUtils.copy_field_if_exists(json_pdp, json_to_use,
                                           "security_pipeline", list)
            JsonUtils.copy_field_if_exists(json_pdp, json_to_use,
                                           "description", str)

            pdps = PDPManager.get_pdp(self._user_id)
            exists = False
            for pdp_key in pdps:
                if pdps[pdp_key]["name"] == json_to_use["name"]:
                    PDPManager.update_pdp(self._user_id,
                                          pdp_id=pdp_key,
                                          value=json_to_use)
                    exists = True
            if exists is False:
                PDPManager.add_pdp(self._user_id, value=json_to_use)
Пример #6
0
def check_keystone_pid(k_pid):
    data = PDPManager.get_pdp(user_id="admin")
    for pdp_key, pdp_value in data.items():
        logger.info("pdp={}".format(pdp_value))
        if pdp_value["keystone_project_id"] == k_pid:
            return True
Пример #7
0
def get_pdp(pdp_id=None):
    from python_moondb.core import PDPManager
    return PDPManager.get_pdp("", pdp_id)