Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .last-synced-sha
Original file line number Diff line number Diff line change
@@ -1 +1 @@
92db0495807c86fbbc4d45bd266a6c1f5bcbb59c
a10d9ecb766d2dd996aecb19aa9c801d78bb7c26
106 changes: 64 additions & 42 deletions .oagen-manifest.json

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions src/workos/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
WorkOSClient as _SyncBase,
AsyncWorkOSClient as _AsyncBase,
)
from .api_keys._resource import ApiKeys, AsyncApiKeys
from .multi_factor_auth._resource import MultiFactorAuth, AsyncMultiFactorAuth
from .connect._resource import Connect, AsyncConnect
from .authorization._resource import Authorization, AsyncAuthorization
Expand All @@ -22,6 +21,7 @@
AsyncOrganizationDomains,
)
from .organizations._resource import Organizations, AsyncOrganizations
from .api_keys._resource import ApiKeys, AsyncApiKeys
from .groups._resource import Groups, AsyncGroups
from .admin_portal._resource import AdminPortal, AsyncAdminPortal
from .radar._resource import Radar, AsyncRadar
Expand All @@ -42,11 +42,6 @@
class WorkOSClient(_SyncBase):
"""Synchronous WorkOS API client with service accessors."""

@functools.cached_property
def api_keys(self) -> ApiKeys:
"""Api Keys API resources."""
return ApiKeys(self)

@functools.cached_property
def multi_factor_auth(self) -> MultiFactorAuth:
"""Multi Factor Auth API resources."""
Expand Down Expand Up @@ -97,6 +92,11 @@ def organizations(self) -> Organizations:
"""Organizations API resources."""
return Organizations(self)

@functools.cached_property
def api_keys(self) -> ApiKeys:
"""Api Keys API resources."""
return ApiKeys(self)

@functools.cached_property
def groups(self) -> Groups:
"""Groups API resources."""
Expand Down Expand Up @@ -172,11 +172,6 @@ def pkce(self) -> PKCE:
class AsyncWorkOSClient(_AsyncBase):
"""Asynchronous WorkOS API client with service accessors."""

@functools.cached_property
def api_keys(self) -> AsyncApiKeys:
"""Api Keys API resources."""
return AsyncApiKeys(self)

@functools.cached_property
def multi_factor_auth(self) -> AsyncMultiFactorAuth:
"""Multi Factor Auth API resources."""
Expand Down Expand Up @@ -227,6 +222,11 @@ def organizations(self) -> AsyncOrganizations:
"""Organizations API resources."""
return AsyncOrganizations(self)

@functools.cached_property
def api_keys(self) -> AsyncApiKeys:
"""Api Keys API resources."""
return AsyncApiKeys(self)

@functools.cached_property
def groups(self) -> AsyncGroups:
"""Groups API resources."""
Expand Down
193 changes: 99 additions & 94 deletions src/workos/api_keys/_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
from urllib.parse import quote

if TYPE_CHECKING:
from .._client import AsyncWorkOSClient, WorkOSClient

from .._types import RequestOptions, enum_value
from .models import ApiKey, ApiKeyValidationResponse, ApiKeyWithValue
from .models import OrganizationsApiKeysOrder
from .models import (
ApiKeyValidationResponse,
OrganizationApiKey,
OrganizationApiKeyWithValue,
)
from workos.authorization.models.pagination_order import PaginationOrder
from .._pagination import AsyncPage, SyncPage


Expand All @@ -19,76 +24,16 @@ class ApiKeys:
def __init__(self, client: "WorkOSClient") -> None:
self._client = client

def create_validation(
self,
*,
value: str,
request_options: Optional[RequestOptions] = None,
) -> ApiKeyValidationResponse:
"""Validate API key

Validate an API key value and return the API key object if valid.

Args:
value: The value for an API key.
request_options: Per-request options. Supports extra_headers, timeout, max_retries, and base_url override.

Returns:
ApiKeyValidationResponse

Raises:
AuthenticationError: If the API key is invalid (401).
UnprocessableEntityError: If the request data is unprocessable (422).
RateLimitExceededError: If rate limited (429).
ServerError: If the server returns a 5xx error.
"""
body: Dict[str, Any] = {
"value": value,
}
return self._client.request(
method="post",
path="api_keys/validations",
body=body,
model=ApiKeyValidationResponse,
request_options=request_options,
)

def delete_api_key(
self,
id: str,
*,
request_options: Optional[RequestOptions] = None,
) -> None:
"""Delete an API key

Permanently deletes an API key. This action cannot be undone. Once deleted, any requests using this API key will fail authentication.

Args:
id: The unique ID of the API key.
request_options: Per-request options. Supports extra_headers, timeout, max_retries, and base_url override.

Raises:
NotFoundError: If the resource is not found (404).
AuthenticationError: If the API key is invalid (401).
RateLimitExceededError: If rate limited (429).
ServerError: If the server returns a 5xx error.
"""
self._client.request(
method="delete",
path=f"api_keys/{id}",
request_options=request_options,
)

def list_organization_api_keys(
self,
organization_id: str,
*,
limit: Optional[int] = None,
before: Optional[str] = None,
after: Optional[str] = None,
order: Optional[Union[OrganizationsApiKeysOrder, str]] = "desc",
order: Optional[Union[PaginationOrder, str]] = "desc",
request_options: Optional[RequestOptions] = None,
) -> SyncPage[ApiKey]:
) -> SyncPage[OrganizationApiKey]:
"""List API keys for an organization

Get a list of all API keys for an organization.
Expand All @@ -98,11 +43,11 @@ def list_organization_api_keys(
limit: Upper limit on the number of objects to return, between `1` and `100`. Defaults to `10`.
before: An object ID that defines your place in the list. When the ID is not present, you are at the end of the list.
after: An object ID that defines your place in the list. When the ID is not present, you are at the end of the list.
order: Order the results by the creation time. Defaults to `desc`.
order: Order the results by the creation time.
request_options: Per-request options. Supports extra_headers, timeout, max_retries, and base_url override.

Returns:
SyncPage[ApiKey]
SyncPage[OrganizationApiKey]

Raises:
NotFoundError: If the resource is not found (404).
Expand All @@ -122,8 +67,8 @@ def list_organization_api_keys(
}
return self._client.request_page(
method="get",
path=f"organizations/{organization_id}/api_keys",
model=ApiKey,
path=f"organizations/{quote(str(organization_id), safe='')}/api_keys",
model=OrganizationApiKey,
params=params,
request_options=request_options,
)
Expand All @@ -135,7 +80,7 @@ def create_organization_api_key(
name: str,
permissions: Optional[List[str]] = None,
request_options: Optional[RequestOptions] = None,
) -> ApiKeyWithValue:
) -> OrganizationApiKeyWithValue:
"""Create an API key for an organization

Create a new API key for an organization.
Expand All @@ -147,7 +92,7 @@ def create_organization_api_key(
request_options: Per-request options. Supports extra_headers, timeout, max_retries, and base_url override.

Returns:
ApiKeyWithValue
OrganizationApiKeyWithValue

Raises:
NotFoundError: If the resource is not found (404).
Expand All @@ -166,20 +111,13 @@ def create_organization_api_key(
}
return self._client.request(
method="post",
path=f"organizations/{organization_id}/api_keys",
path=f"organizations/{quote(str(organization_id), safe='')}/api_keys",
body=body,
model=ApiKeyWithValue,
model=OrganizationApiKeyWithValue,
request_options=request_options,
)


class AsyncApiKeys:
"""Api Keys API resources (async)."""

def __init__(self, client: "AsyncWorkOSClient") -> None:
self._client = client

async def create_validation(
def create_validation(
self,
*,
value: str,
Expand All @@ -205,15 +143,15 @@ async def create_validation(
body: Dict[str, Any] = {
"value": value,
}
return await self._client.request(
return self._client.request(
method="post",
path="api_keys/validations",
body=body,
model=ApiKeyValidationResponse,
request_options=request_options,
)

async def delete_api_key(
def delete_api_key(
self,
id: str,
*,
Expand All @@ -233,22 +171,29 @@ async def delete_api_key(
RateLimitExceededError: If rate limited (429).
ServerError: If the server returns a 5xx error.
"""
await self._client.request(
self._client.request(
method="delete",
path=f"api_keys/{id}",
path=f"api_keys/{quote(str(id), safe='')}",
request_options=request_options,
)


class AsyncApiKeys:
"""Api Keys API resources (async)."""

def __init__(self, client: "AsyncWorkOSClient") -> None:
self._client = client

async def list_organization_api_keys(
self,
organization_id: str,
*,
limit: Optional[int] = None,
before: Optional[str] = None,
after: Optional[str] = None,
order: Optional[Union[OrganizationsApiKeysOrder, str]] = "desc",
order: Optional[Union[PaginationOrder, str]] = "desc",
request_options: Optional[RequestOptions] = None,
) -> AsyncPage[ApiKey]:
) -> AsyncPage[OrganizationApiKey]:
"""List API keys for an organization

Get a list of all API keys for an organization.
Expand All @@ -258,11 +203,11 @@ async def list_organization_api_keys(
limit: Upper limit on the number of objects to return, between `1` and `100`. Defaults to `10`.
before: An object ID that defines your place in the list. When the ID is not present, you are at the end of the list.
after: An object ID that defines your place in the list. When the ID is not present, you are at the end of the list.
order: Order the results by the creation time. Defaults to `desc`.
order: Order the results by the creation time.
request_options: Per-request options. Supports extra_headers, timeout, max_retries, and base_url override.

Returns:
AsyncPage[ApiKey]
AsyncPage[OrganizationApiKey]

Raises:
NotFoundError: If the resource is not found (404).
Expand All @@ -282,8 +227,8 @@ async def list_organization_api_keys(
}
return await self._client.request_page(
method="get",
path=f"organizations/{organization_id}/api_keys",
model=ApiKey,
path=f"organizations/{quote(str(organization_id), safe='')}/api_keys",
model=OrganizationApiKey,
params=params,
request_options=request_options,
)
Expand All @@ -295,7 +240,7 @@ async def create_organization_api_key(
name: str,
permissions: Optional[List[str]] = None,
request_options: Optional[RequestOptions] = None,
) -> ApiKeyWithValue:
) -> OrganizationApiKeyWithValue:
"""Create an API key for an organization

Create a new API key for an organization.
Expand All @@ -307,7 +252,7 @@ async def create_organization_api_key(
request_options: Per-request options. Supports extra_headers, timeout, max_retries, and base_url override.

Returns:
ApiKeyWithValue
OrganizationApiKeyWithValue

Raises:
NotFoundError: If the resource is not found (404).
Expand All @@ -326,8 +271,68 @@ async def create_organization_api_key(
}
return await self._client.request(
method="post",
path=f"organizations/{organization_id}/api_keys",
path=f"organizations/{quote(str(organization_id), safe='')}/api_keys",
body=body,
model=OrganizationApiKeyWithValue,
request_options=request_options,
)

async def create_validation(
self,
*,
value: str,
request_options: Optional[RequestOptions] = None,
) -> ApiKeyValidationResponse:
"""Validate API key

Validate an API key value and return the API key object if valid.

Args:
value: The value for an API key.
request_options: Per-request options. Supports extra_headers, timeout, max_retries, and base_url override.

Returns:
ApiKeyValidationResponse

Raises:
AuthenticationError: If the API key is invalid (401).
UnprocessableEntityError: If the request data is unprocessable (422).
RateLimitExceededError: If rate limited (429).
ServerError: If the server returns a 5xx error.
"""
body: Dict[str, Any] = {
"value": value,
}
return await self._client.request(
method="post",
path="api_keys/validations",
body=body,
model=ApiKeyWithValue,
model=ApiKeyValidationResponse,
request_options=request_options,
)

async def delete_api_key(
self,
id: str,
*,
request_options: Optional[RequestOptions] = None,
) -> None:
"""Delete an API key

Permanently deletes an API key. This action cannot be undone. Once deleted, any requests using this API key will fail authentication.

Args:
id: The unique ID of the API key.
request_options: Per-request options. Supports extra_headers, timeout, max_retries, and base_url override.

Raises:
NotFoundError: If the resource is not found (404).
AuthenticationError: If the API key is invalid (401).
RateLimitExceededError: If rate limited (429).
ServerError: If the server returns a 5xx error.
"""
await self._client.request(
method="delete",
path=f"api_keys/{quote(str(id), safe='')}",
request_options=request_options,
)
Loading
Loading