Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /Extralit_extralit /.github /actions /generate-credentials /app /main.py
| import base64 | |
| import hashlib | |
| import logging | |
| import os | |
| from typing import Any, Dict | |
| SECRET = os.environ.get("ENVIRONMENT_CREDENTIALS_SECRET") | |
| GITHUB_REF = os.environ.get("GITHUB_REF") | |
| def generate_password_from_secret(secret: str, salt: str, length: int = 16) -> str: | |
| dk = hashlib.pbkdf2_hmac("sha256", secret.encode(), salt.encode(), 100000) | |
| password = base64.urlsafe_b64encode(dk).decode("utf-8") | |
| password = "".join(char for char in password if char.isalnum()) | |
| return password[:length] | |
| def generate_credentials() -> Dict[str, Any]: | |
| credentials = {} | |
| for user in ["owner", "admin", "annotator"]: | |
| logging.info(f"Generating random credential for user '{user}'") | |
| password = generate_password_from_secret( | |
| secret=SECRET, salt=f"{GITHUB_REF}/{user}", length=32 | |
| ) | |
| credentials[user] = password | |
| return credentials | |
| if __name__ == "__main__": | |
| logging.basicConfig(level=logging.INFO) | |
| if not SECRET: | |
| logging.error("`ENVIRONMENT_CREDENTIALS_SECRET` secret is not set!") | |
| raise KeyError("`ENVIRONMENT_CREDENTIALS_SECRET` secret is not set") | |
| credentials = generate_credentials() | |
| with open(os.environ["GITHUB_OUTPUT"], "a") as fh: | |
| for key, value in credentials.items(): | |
| print(f"::add-mask::{value}") | |
| print(f"{key}={value}", file=fh) | |
Xet Storage Details
- Size:
- 1.36 kB
- Xet hash:
- 815fdf67b1224afa30a330ecc48df43a98990d2f589c17d67c968ff3308873fd
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.