litellm/tests/integration/_support/vertex.py
Mrinal Chanshetty 5a3cfacab2 test(integration): add the vertex service-account helper the safeguards wire test imports
Backport prerequisite for #43955 on stable/1.103.x.
Copied from tests/integration/_support/vertex.py on main (added by #43900).
2026-10-20 16:23:41 -07:00

31 lines
960 B
Python

from __future__ import annotations
import json
from typing import Final
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import rsa
def service_account_json(project: str, token_url: str) -> str:
private_key: Final = (
rsa.generate_private_key(public_exponent=65537, key_size=2048)
.private_bytes(
serialization.Encoding.PEM,
serialization.PrivateFormat.PKCS8,
serialization.NoEncryption(),
)
.decode()
)
return json.dumps(
{
"type": "service_account",
"project_id": project,
"private_key_id": "scripted",
"private_key": private_key,
"client_email": f"scripted@{project}.iam.gserviceaccount.com",
"client_id": "0",
"auth_uri": f"{token_url}/_oauth/authorize",
"token_uri": f"{token_url}/_oauth/token",
}
)