mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-28 06:23:07 +00:00
Backport prerequisite for #43955 on stable/1.103.x. Copied from tests/integration/_support/vertex.py on main (added by #43900).
31 lines
960 B
Python
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",
|
|
}
|
|
)
|