2024-03-01 10:09:30 -08:00
|
|
|
import asyncio
|
|
|
|
|
from datetime import timedelta
|
|
|
|
|
|
|
|
|
|
import typer
|
|
|
|
|
|
2025-12-02 15:49:51 -07:00
|
|
|
from skyvern.forge import app
|
|
|
|
|
from skyvern.forge.forge_app_initializer import start_forge_app
|
2024-03-01 10:09:30 -08:00
|
|
|
from skyvern.forge.sdk.core import security
|
2024-12-06 17:15:11 -08:00
|
|
|
from skyvern.forge.sdk.schemas.organizations import OrganizationAuthToken, OrganizationAuthTokenType
|
2024-03-01 10:09:30 -08:00
|
|
|
|
|
|
|
|
API_KEY_LIFETIME = timedelta(weeks=5200)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def create_org_api_token(org_id: str) -> OrganizationAuthToken:
|
|
|
|
|
"""Creates an API token for the specified org_id.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
org_id: The org_id for which to create an API token.
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
The API token created for the specified org_id.
|
|
|
|
|
"""
|
|
|
|
|
# get the organization
|
2025-12-02 15:49:51 -07:00
|
|
|
organization = await app.DATABASE.get_organization(org_id)
|
2024-03-01 10:09:30 -08:00
|
|
|
if not organization:
|
|
|
|
|
raise Exception(f"Organization id {org_id} not found")
|
|
|
|
|
|
|
|
|
|
# [START create_org_api_token]
|
|
|
|
|
api_key = security.create_access_token(
|
|
|
|
|
org_id,
|
|
|
|
|
expires_delta=API_KEY_LIFETIME,
|
|
|
|
|
)
|
|
|
|
|
# generate OrganizationAutoToken
|
2025-12-02 15:49:51 -07:00
|
|
|
org_auth_token = await app.DATABASE.create_org_auth_token(
|
2024-03-01 10:09:30 -08:00
|
|
|
organization_id=org_id,
|
|
|
|
|
token=api_key,
|
|
|
|
|
token_type=OrganizationAuthTokenType.api,
|
|
|
|
|
)
|
|
|
|
|
print(f"Created API token for organization {org_auth_token}")
|
|
|
|
|
return org_auth_token
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main(org_id: str) -> None:
|
2025-12-02 15:49:51 -07:00
|
|
|
start_forge_app()
|
2024-03-01 10:09:30 -08:00
|
|
|
asyncio.run(create_org_api_token(org_id))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
typer.run(main)
|