def create_stac(self) -> pystac.Collection: stac = pystac.Collection( id=str(ulid.ULID()), description=None, license=None, providers=GLOBAL_PROVIDERS, extent=pystac.SpatialExtent(bboxes=[0, 0, 0, 0]), ) return stac
async def post(self): values = self.get_request_body() values.update({ 'token': uuid.UUID(ulid.ULID().hex), 'username': self.current_user.username }) result = await self.postgres_execute(self.CREATE_SQL, values, 'create-authentication-token') self.send_response(result.row)
def _set_formated_changes_json(self): for record in self.stream_event["Records"]: new_item = {} primary_key_string = "" for k, v in record["dynamodb"]["Keys"].items(): key_name = k key_value = list(v.values())[0] new_item[key_name] = key_value primary_key_string = str(ulid.ULID()) new_item["key"] = primary_key_string old_image = record["dynamodb"].get("OldImage", None) new_image = record["dynamodb"].get("NewImage", None) action = self._determine_action(old_image, new_image) tmsp_epoch = record["dynamodb"]["ApproximateCreationDateTime"] new_item["tmsp"] = datetime.fromtimestamp(tmsp_epoch).isoformat() new_item["action"] = action changes = "" if new_image != None: for k, dynamodb_v in new_image.items(): new_value = list(dynamodb_v.values())[0] old_value = "*" if old_image != None: if k in old_image: old_value = list(old_image[k].values())[0] if old_value != new_value: field = f"{k}: '{old_value}' -> '{new_value}'" changes = changes + field + " | " else: changes = " -> X" new_item["changes"] = changes self.changes.append(new_item)
def generate_ulid(): return str(ulid.ULID())
class Report(_BaseModel): name: str ulid: str = pydantic.Field(default_factory=lambda: str(ulid.ULID())) date: datetime.datetime = pydantic.Field(default_factory=datetime.datetime.now) sections: list[Section] = [] @property def succeeded(self): for s in self.sections: for i in s.items: if isinstance(i, PassFailItem): if not i.value: return False return True def save(self, file=None): if file is None: file = pathlib.Path(f"reports/{self.name.lower()}-{self.ulid}.json") file.parent.mkdir(parents=True, exist_ok=True) if isinstance(file, (str, pathlib.Path)): with open(file, "w") as fh: fh.write(self.json()) rich.print(f"[green]Report saved to {file}") return pathlib.Path(file) elif file: file.write(self.json()) @classmethod def load(self, file): if isinstance(file, (str, pathlib.Path)): with open(file, "r") as fh: return self.parse_raw(fh.read()) elif file: return self.parse_raw(file.read()) def __rich__(self): name_color = "green" if self.succeeded else "red" renderables = [ rich.padding.Padding( rich.text.Text(self.name, style=f"{name_color} bold underline"), (1, 0) ), rich.text.Text(self.ulid, style=""), rich.text.Text(f"{self.date.isoformat()}", style="italic"), *self.sections, ] if self.succeeded: renderables.append( rich.align.Align.center( rich.padding.Padding( "SUCCEEDED", pad=(1, 5), style="bold black on green", expand=True, ) ) ) else: renderables.append( rich.align.Align.center( rich.padding.Padding( "FAILED", pad=(1, 5), style="bold white on red", expand=True, ) ) ) return rich.panel.Panel.fit( rich.console.Group( *renderables, fit=True, ), width=_MAX_CONSOLE_WIDTH, )