Spaces:
Configuration error
Configuration error
Download scripts/bootstrap_api_client.py from Pankaj10346/GUVI-hackathon-project: direct link, hf CLI and curl.
- Browser
- Download file 1.14 kB
-
https://huggingface.co/spaces/Pankaj10346/GUVI-hackathon-project/resolve/main/scripts/bootstrap_api_client.py
- Command line
-
hf download hf://spaces/Pankaj10346/GUVI-hackathon-project/scripts/bootstrap_api_client.py
-
curl -L -o bootstrap_api_client.py https://huggingface.co/spaces/Pankaj10346/GUVI-hackathon-project/resolve/main/scripts/bootstrap_api_client.py
1.14 kB
| from __future__ import annotations | |
| import argparse | |
| from app.auth import hash_api_key | |
| from app.db import SessionLocal, engine | |
| from app.models import ApiClient, Base | |
| def main() -> None: | |
| p = argparse.ArgumentParser(description="Insert an API client with a hashed x-api-key.") | |
| p.add_argument("--name", required=True) | |
| p.add_argument("--api-key", required=True) | |
| p.add_argument("--create-all", action="store_true", help="Create tables via SQLAlchemy create_all first.") | |
| args = p.parse_args() | |
| if args.create_all: | |
| Base.metadata.create_all(bind=engine) | |
| key_hash = hash_api_key(args.api_key) | |
| with SessionLocal() as db: | |
| existing = db.query(ApiClient).filter(ApiClient.api_key_hash == key_hash).one_or_none() | |
| if existing: | |
| existing.is_active = True | |
| existing.name = args.name | |
| db.commit() | |
| print("API client already existed; updated to active.") | |
| return | |
| db.add(ApiClient(name=args.name, api_key_hash=key_hash, is_active=True)) | |
| db.commit() | |
| print("Inserted API client.") | |
| if __name__ == "__main__": | |
| main() | |