generated from coulomb/repo-seed
Implement Stripe publication layer and close WP-0007
This commit is contained in:
52
projects/coulomb-pricing/observatory/publish.py
Normal file
52
projects/coulomb-pricing/observatory/publish.py
Normal file
@@ -0,0 +1,52 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from .load import default_data_dir, load_pricing_models, load_product
|
||||
from .publication import (
|
||||
build_stripe_publication_preview,
|
||||
publish_to_stripe_shadow,
|
||||
rollback_stripe_shadow,
|
||||
)
|
||||
|
||||
|
||||
def main(argv: list[str] | None = None) -> int:
|
||||
parser = argparse.ArgumentParser(description="Preview or apply Stripe publication for pricing models")
|
||||
parser.add_argument("--data-dir", type=Path, default=default_data_dir())
|
||||
parser.add_argument("--model-id", help="Pricing model id to preview or publish")
|
||||
parser.add_argument("--provider", default="stripe", choices=["stripe"])
|
||||
parser.add_argument("--state-path", type=Path, help="Override provider shadow-state path")
|
||||
parser.add_argument("--apply", action="store_true", help="Apply the publication plan to the local Stripe shadow state")
|
||||
parser.add_argument("--rollback", help="Rollback the local Stripe shadow state to a prior revision id")
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
product = load_product(args.data_dir)
|
||||
models = load_pricing_models(args.data_dir)
|
||||
|
||||
if args.rollback:
|
||||
payload = rollback_stripe_shadow(args.data_dir, args.rollback, state_path=args.state_path)
|
||||
elif args.apply:
|
||||
payload = publish_to_stripe_shadow(
|
||||
product,
|
||||
models,
|
||||
args.data_dir,
|
||||
model_id=args.model_id,
|
||||
state_path=args.state_path,
|
||||
)
|
||||
else:
|
||||
payload = build_stripe_publication_preview(
|
||||
product,
|
||||
models,
|
||||
args.data_dir,
|
||||
model_id=args.model_id,
|
||||
state_path=args.state_path,
|
||||
)
|
||||
|
||||
print(json.dumps(payload, indent=2))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user