Buckets:

download
raw
5.16 kB
#!/usr/bin/env python3
"""
Cloudflare Secrets zu GitHub Repository hinzufügen
Verwendung:
export GITHUB_TOKEN=ghp_xxx
python add-cloudflare-secrets.py --token CF_API_TOKEN --account-id CF_ACCOUNT_ID
GitHub Token erstellen unter:
https://github.com/settings/tokens
Rechte: repo, workflow
"""
import argparse
import json
import os
import sys
import requests
def get_repo_info():
"""Versucht Repo-Info aus git remote zu ermitteln"""
import subprocess
try:
result = subprocess.run(
["git", "remote", "get-url", "origin"],
capture_output=True,
text=True,
check=True,
)
url = result.stdout.strip()
# Parse github.com/owner/repo.git
if "github.com" in url:
parts = url.replace("https://github.com/", "").replace("git@github.com:", "").replace(".git", "").split("/")
if len(parts) >= 2:
return parts[0], parts[1]
except Exception as e:
print(f"⚠️ Konnte Repo-Info nicht ermitteln: {e}")
return None, None
def create_secret(owner, repo, secret_name, secret_value, token):
"""Erstellt ein GitHub Secret"""
# GitHub API URL
# Get public key for encryption
key_url = f"https://api.github.com/repos/{owner}/{repo}/actions/secrets/public-key"
headers = {
"Accept": "application/vnd.github.v3+json",
"Authorization": f"token {token}",
"X-GitHub-Api-Version": "2022-11-28",
}
try:
# Get public key
response = requests.get(key_url, headers=headers, timeout=30)
response.raise_for_status()
response.json()
# For simplicity, we'll use the GitHub API with sodium encryption
# But actually, we need to encrypt the secret value with libsodium
# For this script, we'll use the PUT endpoint with encrypted_value
# However, doing libsodium encryption in pure Python is complex
print(f" ℹ️ Secret '{secret_name}' erfordert libsodium Verschlüsselung")
print(" 🔧 Manuelle Anleitung:")
print(f" 1. Gehe zu: https://github.com/{owner}/{repo}/settings/secrets/actions")
print(" 2. Klicke 'New repository secret'")
print(f" 3. Name: {secret_name}") # lgtm[py/clear-text-logging-sensitive-data]
print(" 4. Value: (ausgeblendet)")
return False
except requests.exceptions.RequestException as e:
print(f" ❌ Fehler: {e}")
return False
def main():
parser = argparse.ArgumentParser(description="Cloudflare Secrets zu GitHub hinzufügen")
parser.add_argument("--token", help="Cloudflare API Token", required=False)
parser.add_argument("--account-id", help="Cloudflare Account ID", required=False)
parser.add_argument("--kv-id", help="Cloudflare KV Namespace ID", required=False)
args = parser.parse_args()
print("☁️ Cloudflare Secrets Setup für GitHub Actions")
print("=" * 50)
# Get GitHub Token
github_token = os.environ.get("GITHUB_TOKEN")
if not github_token:
print("\n❌ GITHUB_TOKEN nicht gefunden!")
print("\nBitte erstelle einen GitHub Token:")
print(" https://github.com/settings/tokens")
print("\nErforderliche Rechte:")
print(" ☑️ repo")
print(" ☑️ workflow")
print("\nDann exportiere ihn:")
print(" export GITHUB_TOKEN=ghp_xxx")
sys.exit(1)
# Get repo info
owner, repo = get_repo_info()
if not owner or not repo:
print("\n❌ Konnte Repository nicht ermitteln!")
print("Stelle sicher, dass du im Git Repository bist.")
sys.exit(1)
print(f"\n📁 Repository: {owner}/{repo}")
# Get Cloudflare credentials
cf_token = args.token or input("\n🔑 Cloudflare API Token: ").strip()
cf_account = args.account_id or input("🔑 Cloudflare Account ID: ").strip()
cf_kv = args.kv_id or input("🔑 Cloudflare KV Namespace ID (optional): ").strip() or None
if not cf_token or not cf_account:
print("\n❌ Cloudflare Token und Account ID sind erforderlich!")
sys.exit(1)
print("\n📝 Füge Secrets hinzu...")
# We can't actually create secrets via API without libsodium encryption
# So we'll show the manual instructions
print("\n📋 Manuelle Schritte:")
print(f"\n1. Öffne: https://github.com/{owner}/{repo}/settings/secrets/actions")
print("\n2. Füge diese Secrets hinzu:\n")
secrets = [
("CLOUDFLARE_API_TOKEN", cf_token),
("CLOUDFLARE_ACCOUNT_ID", cf_account),
]
if cf_kv:
secrets.append(("CLOUDFLARE_KV_ID", cf_kv))
for name, value in secrets:
print(f" Name: {name}")
print(f" Value: {value[:10]}{'*' * (len(value) - 10) if len(value) > 10 else ''}")
print()
print("3. Klicke jeweils 'Add secret'")
print("\n✅ Danach ist die GitHub Actions CI/CD bereit!")
print("\n🚀 Testen mit:")
print(" git push origin main")
print("\n🌐 Danach verfügbar unter:")
print(" https://zen-ai-pentest.pages.dev")
if __name__ == "__main__":
main()

Xet Storage Details

Size:
5.16 kB
·
Xet hash:
f2f0520838e5ef241fc72bd187c5cd8cb85fd1e617462a44eb7a1f88de86aa1b

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.