Example #1
0
 def to_response(self, response: Response) -> Response:
     if self.message != "":
         response.add_info(self.message)
     for l in self.logs:
         if isinstance(l, str):
             response.add_info(l)
         else:
             response.add_data(l)
     return response
Example #2
0
    def trigger_schedule(self, schedule_name: str, response: Response):
        refresh_glue_table_response = self.refresh_glue_table(schedule_name)
        error, status, message = self.parse_response(
            refresh_glue_table_response)

        response.add_response(refresh_glue_table_response)

        if error == "CrawlerRunningException":
            response.add_warning(
                f"Table crawler {schedule_name} is already refreshing.")
            response.add_data({})
            response.set_status(202)
        elif status:
            if 200 <= status < 300:
                response.add_info(f"Refreshing Table Crawler: {schedule_name}")
                response.add_data({})
                response.set_status(201)
        else:
            response.add_error(message)
            response.set_status(status)
        return response
Example #3
0
        def parse_response(
                result: dict,
                response: Response) -> Result[TableList, InvalidTables]:
            contents: Optional[List[dict]] = result.get("Contents")
            prefixes: Optional[List[dict]] = result.get("CommonPrefixes")

            if contents:
                tables: List[Union[Table, InvalidTables]] = []
                for c in contents:
                    key: Optional[str] = c.get("Key")
                    if key:
                        table, response = self.get_table(
                            database_name.split("/")[0],
                            key,
                            response=response)
                        tables.append(table)
                valid, invalid = sequence(tables, Table, InvalidTables)
                if len(valid) > 0:
                    return Success(TableList(valid))
                else:
                    invalid_tables: List[InvalidTable] = []
                    for i in invalid:
                        invalid_tables += (i.invalid_tables)

                    return Failure(
                        InvalidTables(invalid_tables,
                                      f"No valid tables at {database_name}"))
            elif prefixes:
                for p in prefixes:
                    response.add_data(p)
                return Failure(
                    InvalidTables(
                        [],
                        f"No valid tables at {database_name}.  Try appending '/' or specify deeper key."
                    ))
            else:
                return Failure(InvalidTables([], "No Data returned from AWS"))
Example #4
0
 def to_response(self, response: Response):
     data = {'Tables': list(map(lambda t: t.to_dict(), self.tables))}
     response.add_data(data)
     return response
Example #5
0
 def to_response(self, response: Response):
     response.add_data(self.to_dict())
     return response
Example #6
0
 def to_response(self, response: Response):
     response.add_error(self.reason)
     response.add_data(self.schema_conflict.to_dict())
     response.set_status(403)
     return response