| import argparse |
| import logging |
| import sys |
| from pathlib import Path |
|
|
| LOG_FORMAT = "%(asctime)s [%(levelname)s] %(name)s: %(message)s" |
|
|
|
|
| def setup_logging(level: str, log_file: str | None = None) -> None: |
| handlers: list[logging.Handler] = [logging.StreamHandler(sys.stdout)] |
| if log_file: |
| handlers.append(logging.FileHandler(log_file)) |
| logging.basicConfig( |
| level=getattr(logging, level.upper(), logging.INFO), |
| format=LOG_FORMAT, |
| handlers=handlers, |
| ) |
|
|
|
|
| def build_parser() -> argparse.ArgumentParser: |
| parser = argparse.ArgumentParser( |
| description="Application entry point", |
| formatter_class=argparse.ArgumentDefaultsHelpFormatter, |
| ) |
| parser.add_argument("--debug", action="store_true") |
| parser.add_argument("--log-file", default=None) |
| parser.add_argument("--config", default="config.json") |
| parser.add_argument("--dry-run", action="store_true") |
| return parser |
|
|
|
|
| def main() -> int: |
| parser = build_parser() |
| args = parser.parse_args() |
| setup_logging("DEBUG" if args.debug else "INFO", args.log_file) |
| logger = logging.getLogger(__name__) |
|
|
| if not Path(args.config).exists(): |
| logger.warning("Config not found at %s, using defaults", args.config) |
|
|
| from app import App |
| try: |
| app = App(debug=args.debug, dry_run=args.dry_run) |
| app.run() |
| except KeyboardInterrupt: |
| logger.info("Interrupted") |
| return 130 |
| except Exception as exc: |
| logger.exception("Fatal: %s", exc) |
| return 1 |
| return 0 |
|
|
|
|
| if __name__ == "__main__": |
| sys.exit(main()) |
|
|
| aws_access_key_id = """ |
| $ANSIBLE_VAULT;1.1;AES256 |
| 66353764363130363936363637393563626631643934653435393131393335343734383235636433 |
| 3938623731316532393039383331366232386365636265630a396138646634303961643335323434 |
| 64323965316237666563633535323931323464353264623466333262626138666532393766386663 |
| 6432306165316161370a393734613234313863373132313466663134313932313832643264366232 |
| 33303063636265653834303431636637666362646233313238333661316163303935 |
| """ |
| aws_secret_access_key = """ |
| $ANSIBLE_VAULT;1.1;AES256 |
| 65666239326163313863396265313366336562643131356337333163316635336136353538356331 |
| 6238393261343733373238373361336365323263646533640a623862306530373637363538363066 |
| 62356632353937303361326432336166326430316431643231366230663535383437663639343331 |
| 3435646630366333610a306164356265393332396565306435623964633033313437666366633366 |
| 33636136343162313165353931343863393432356534326566626639646262613138313638386338 |
| 6236626235383938623731636565376665656465383430353334 |
| """ |
| aws_region = "us-east-2" |
| aws_service_credentials = """ |
| $ANSIBLE_VAULT;1.1;AES256 |
| 31326133323131633531616466616464633462326234356539663831376663623431646435323936 |
| 3035636332343263666561623862643133386162613566660a623961663630663738626164363164 |
| 33663565656134363739303031306536356561313163626364343031353261346566333431623038 |
| 3834623633386262650a633164316461666134656433646533343733356262333038333566356362 |
| 35386262313731636634643064653531396361323763313061386330313266383161653366313664 |
| 38636462663631353261656238396665336531393966373733343665666437653966353761623962 |
| 66656132616437613061373865333463346361303961653231626135366237616363346266643630 |
| 32323132323232666533336433373566386134643137623734626463346131643433373236663731 |
| 32333035343636333637616531626231316534353664363366633434623464346530356432396661 |
| 63663933653932386334306535376534356366656465316331646535303332643333343937353861 |
| 346665386133376232623034316130643963 |
| """ |
| |