mirror of
https://github.com/rubenhensen/k8scd.git
synced 2026-09-17 02:12:55 +02:00
Update python script dns
This commit is contained in:
+1
-1
@@ -21,7 +21,7 @@ spec:
|
|||||||
- sh
|
- sh
|
||||||
- -c
|
- -c
|
||||||
- |
|
- |
|
||||||
pip install --quiet PyJWT cryptography requests pyyaml &&
|
pip install --quiet cryptography requests pyyaml &&
|
||||||
python /config/sync.py
|
python /config/sync.py
|
||||||
env:
|
env:
|
||||||
- name: TRANSIP_ACCOUNT_NAME
|
- name: TRANSIP_ACCOUNT_NAME
|
||||||
|
|||||||
+15
-15
@@ -5,14 +5,14 @@ import base64
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
|
||||||
import uuid
|
import uuid
|
||||||
from glob import glob
|
from glob import glob
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import jwt
|
|
||||||
import requests
|
import requests
|
||||||
import yaml
|
import yaml
|
||||||
|
from cryptography.hazmat.primitives import hashes, serialization
|
||||||
|
from cryptography.hazmat.primitives.asymmetric import padding
|
||||||
|
|
||||||
TRANSIP_API = "https://api.transip.nl/v6"
|
TRANSIP_API = "https://api.transip.nl/v6"
|
||||||
DOMAINS_DIR = "/config/domains"
|
DOMAINS_DIR = "/config/domains"
|
||||||
@@ -20,24 +20,24 @@ DOMAINS_DIR = "/config/domains"
|
|||||||
|
|
||||||
def get_access_token(account_name: str, private_key: str) -> str:
|
def get_access_token(account_name: str, private_key: str) -> str:
|
||||||
"""Authenticate with TransIP API and return a bearer token."""
|
"""Authenticate with TransIP API and return a bearer token."""
|
||||||
now = int(time.time())
|
body = json.dumps({
|
||||||
payload = {
|
"login": account_name,
|
||||||
"iss": account_name,
|
"nonce": uuid.uuid4().hex,
|
||||||
"sub": account_name,
|
"read_only": False,
|
||||||
"aud": "api.transip.nl",
|
"expiration_time": "5 minutes",
|
||||||
"jti": str(uuid.uuid4()),
|
|
||||||
"iat": now,
|
|
||||||
"nbf": now,
|
|
||||||
"exp": now + 300,
|
|
||||||
"global_key": True,
|
"global_key": True,
|
||||||
}
|
})
|
||||||
token = jwt.encode(payload, private_key, algorithm="RS512")
|
|
||||||
|
key = serialization.load_pem_private_key(private_key.encode(), password=None)
|
||||||
|
signature = key.sign(body.encode(), padding.PKCS1v15(), hashes.SHA512())
|
||||||
|
signature_b64 = base64.b64encode(signature).decode()
|
||||||
|
|
||||||
resp = requests.post(
|
resp = requests.post(
|
||||||
f"{TRANSIP_API}/auth",
|
f"{TRANSIP_API}/auth",
|
||||||
json={"login": account_name, "nonce": payload["jti"], "global_key": True},
|
data=body,
|
||||||
headers={
|
headers={
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"Authorization": f"Bearer {token}",
|
"Signature": signature_b64,
|
||||||
},
|
},
|
||||||
timeout=30,
|
timeout=30,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user