Move the code over from private repository (#3)
This commit is contained in:
47
scripts/create_api_key.py
Normal file
47
scripts/create_api_key.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
|
||||
import typer
|
||||
|
||||
from skyvern.forge.app import DATABASE
|
||||
from skyvern.forge.sdk.core import security
|
||||
from skyvern.forge.sdk.models import OrganizationAuthToken, OrganizationAuthTokenType
|
||||
|
||||
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
|
||||
organization = await DATABASE.get_organization(org_id)
|
||||
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
|
||||
org_auth_token = await DATABASE.create_org_auth_token(
|
||||
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:
|
||||
asyncio.run(create_org_api_token(org_id))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
typer.run(main)
|
||||
21
scripts/create_organization.py
Normal file
21
scripts/create_organization.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import asyncio
|
||||
from typing import Annotated, Optional
|
||||
|
||||
import typer
|
||||
|
||||
from scripts.create_api_key import create_org_api_token
|
||||
from skyvern.forge.app import DATABASE
|
||||
|
||||
|
||||
async def create_org(org_name: str, webhook_callback_url: str | None = None) -> None:
|
||||
organization = await DATABASE.create_organization(org_name, webhook_callback_url)
|
||||
print(f"Created organization: {organization}")
|
||||
await create_org_api_token(organization.organization_id)
|
||||
|
||||
|
||||
def main(org_name: str, webhook_callback_url: Annotated[Optional[str], typer.Argument()] = None) -> None:
|
||||
asyncio.run(create_org(org_name, webhook_callback_url))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
typer.run(main)
|
||||
Reference in New Issue
Block a user