Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input type QoL improvements #313

Merged
merged 8 commits into from
Aug 5, 2024
Merged
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
3 changes: 1 addition & 2 deletions tests/test_audit_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import pytest

from workos.audit_logs import AuditLogs
from workos.audit_logs import AuditLogEvent, AuditLogs
from workos.exceptions import AuthenticationException, BadRequestException
from workos.resources.audit_logs import AuditLogEvent
from workos.utils.http_client import SyncHTTPClient


Expand Down
1 change: 0 additions & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest

from workos import async_client, client
from workos.exceptions import ConfigurationException

Expand Down
6 changes: 2 additions & 4 deletions tests/test_sso.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import json

from six.moves.urllib.parse import parse_qsl, urlparse
import pytest

from tests.utils.fixtures.mock_profile import MockProfile
from tests.utils.list_resource import list_data_to_dicts, list_response_of
import workos
from workos.sso import SSO, AsyncSSO
from workos.resources.sso import Profile, SsoProviderType
from workos.sso import SSO, AsyncSSO, SsoProviderType
from workos.resources.sso import Profile
from workos.utils.http_client import AsyncHTTPClient, SyncHTTPClient
from workos.utils.request_helper import RESPONSE_TYPE_CODE
from tests.utils.fixtures.mock_connection import MockConnection
Expand Down
38 changes: 37 additions & 1 deletion workos/audit_logs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from typing import Optional, Protocol, Sequence
from typing_extensions import TypedDict, NotRequired

import workos
from workos.resources.audit_logs import AuditLogEvent, AuditLogExport
from workos.resources.audit_logs import AuditLogExport
from workos.utils.http_client import SyncHTTPClient
from workos.utils.request_helper import REQUEST_METHOD_GET, REQUEST_METHOD_POST
from workos.utils.validation import AUDIT_LOGS_MODULE, validate_settings
Expand All @@ -10,6 +11,41 @@
EXPORTS_PATH = "audit_logs/exports"


class AuditLogEventTarget(TypedDict):
"""Describes the entity that was targeted by the event."""

id: str
metadata: NotRequired[dict]
name: NotRequired[str]
type: str


class AuditLogEventActor(TypedDict):
"""Describes the entity that generated the event."""

id: str
metadata: NotRequired[dict]
name: NotRequired[str]
type: str


class AuditLogEventContext(TypedDict):
"""Attributes of audit log event context."""

location: str
user_agent: NotRequired[str]


class AuditLogEvent(TypedDict):
action: str
version: NotRequired[int]
occurred_at: str # ISO-8601 datetime of when an event occurred
actor: AuditLogEventActor
targets: Sequence[AuditLogEventTarget]
context: AuditLogEventContext
metadata: NotRequired[dict]


class AuditLogsModule(Protocol):
def create_event(
self,
Expand Down
2 changes: 1 addition & 1 deletion workos/events.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional, Protocol, Sequence, Union
from typing import Literal, Optional, Protocol, Sequence, Union

import workos
from workos.typing.sync_or_async import SyncOrAsync
Expand Down
9 changes: 7 additions & 2 deletions workos/mfa.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional, Protocol
from typing import Literal, Optional, Protocol

import workos
from workos.utils.http_client import SyncHTTPClient
Expand All @@ -15,9 +15,14 @@
AuthenticationFactor,
AuthenticationFactorSms,
AuthenticationFactorTotp,
EnrollAuthenticationFactorType,
SmsAuthenticationFactorType,
TotpAuthenticationFactorType,
)

EnrollAuthenticationFactorType = Literal[
SmsAuthenticationFactorType, TotpAuthenticationFactorType
]


class MFAModule(Protocol):
def enroll_factor(
Expand Down
4 changes: 3 additions & 1 deletion workos/passwordless.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
from workos.utils.http_client import SyncHTTPClient
from workos.utils.request_helper import REQUEST_METHOD_POST
from workos.utils.validation import PASSWORDLESS_MODULE, validate_settings
from workos.resources.passwordless import PasswordlessSession, PasswordlessSessionType
from workos.resources.passwordless import PasswordlessSession

PasswordlessSessionType = Literal["MagicLink"]


class PasswordlessModule(Protocol):
Expand Down
39 changes: 1 addition & 38 deletions workos/resources/audit_logs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from typing import Literal, Optional, Sequence, TypedDict
from typing_extensions import NotRequired

from typing import Literal, Optional
from workos.resources.workos_model import WorkOSModel

AuditLogExportState = Literal["error", "pending", "ready"]
Expand All @@ -15,38 +13,3 @@ class AuditLogExport(WorkOSModel):
updated_at: str
state: AuditLogExportState
url: Optional[str] = None


class AuditLogEventActor(TypedDict):
"""Describes the entity that generated the event."""

id: str
metadata: NotRequired[dict]
name: NotRequired[str]
type: str


class AuditLogEventTarget(TypedDict):
"""Describes the entity that was targeted by the event."""

id: str
metadata: NotRequired[dict]
name: NotRequired[str]
type: str


class AuditLogEventContext(TypedDict):
"""Attributes of audit log event context."""

location: str
user_agent: NotRequired[str]


class AuditLogEvent(TypedDict):
action: str
version: NotRequired[int]
occurred_at: str # ISO-8601 datetime of when an event occurred
actor: AuditLogEventActor
targets: Sequence[AuditLogEventTarget]
context: AuditLogEventContext
metadata: NotRequired[dict]
2 changes: 1 addition & 1 deletion workos/resources/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
from workos.types.user_management.invitation_common import InvitationCommon
from workos.types.user_management.magic_auth_common import MagicAuthCommon
from workos.types.user_management.password_reset_common import PasswordResetCommon
from workos.typing.literals import LiteralOrUntyped

EventType = Literal[
"authentication.email_verification_succeeded",
Expand Down Expand Up @@ -89,6 +88,7 @@
"user.deleted",
"user.updated",
]

EventTypeDiscriminator = TypeVar("EventTypeDiscriminator", bound=EventType)
EventPayload = TypeVar(
"EventPayload",
Expand Down
2 changes: 1 addition & 1 deletion workos/resources/list.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import abc
from pydantic import BaseModel, Field
from typing import (
AsyncIterator,
Awaitable,
Expand All @@ -22,7 +23,6 @@
from workos.resources.events import Event
from workos.resources.mfa import AuthenticationFactor
from workos.resources.organizations import Organization
from pydantic import BaseModel, Field
from workos.resources.sso import ConnectionWithDomains
from workos.resources.user_management import Invitation, OrganizationMembership, User
from workos.resources.workos_model import WorkOSModel
Expand Down
3 changes: 0 additions & 3 deletions workos/resources/mfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
AuthenticationFactorType = Literal[
"generic_otp", SmsAuthenticationFactorType, TotpAuthenticationFactorType
]
EnrollAuthenticationFactorType = Literal[
SmsAuthenticationFactorType, TotpAuthenticationFactorType
]


class TotpFactor(WorkOSModel):
Expand Down
2 changes: 0 additions & 2 deletions workos/resources/passwordless.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from typing import Literal
from workos.resources.workos_model import WorkOSModel

PasswordlessSessionType = Literal["MagicLink"]


class PasswordlessSession(WorkOSModel):
"""Representation of a WorkOS Passwordless Session Response."""
Expand Down
12 changes: 1 addition & 11 deletions workos/resources/sso.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from typing import Literal, Sequence, Union

from workos.resources.workos_model import WorkOSModel
from workos.types.sso.connection import Connection
from workos.types.sso.connection import Connection, ConnectionType
from workos.typing.literals import LiteralOrUntyped
from workos.utils.connection_types import ConnectionType


class Profile(WorkOSModel):
Expand Down Expand Up @@ -39,11 +37,3 @@ class ConnectionWithDomains(Connection):
"""Representation of a Connection Response as returned by WorkOS through the SSO feature."""

domains: Sequence[ConnectionDomain]


SsoProviderType = Literal[
"AppleOAuth",
"GitHubOAuth",
"GoogleOAuth",
"MicrosoftOAuth",
]
5 changes: 1 addition & 4 deletions workos/resources/user_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from workos.types.user_management.password_reset_common import PasswordResetCommon


PasswordHashType = Literal["bcrypt", "firebase-scrypt", "ssha"]
OrganizationMembershipStatus = Literal["active", "inactive", "pending"]

AuthenticationMethod = Literal[
"SSO",
Expand Down Expand Up @@ -87,9 +87,6 @@ class OrganizationMembershipRole(TypedDict):
slug: str


OrganizationMembershipStatus = Literal["active", "inactive", "pending"]


class OrganizationMembership(WorkOSModel):
"""Representation of an WorkOS Organization Membership."""

Expand Down
13 changes: 9 additions & 4 deletions workos/sso.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
from typing import Optional, Protocol, Union

from typing import Literal, Optional, Protocol, Union
import workos
from workos.typing.sync_or_async import SyncOrAsync
from workos.utils.http_client import AsyncHTTPClient, SyncHTTPClient
from workos.utils.pagination_order import PaginationOrder
from workos.resources.sso import (
ConnectionType,
ConnectionWithDomains,
Profile,
ProfileAndToken,
SsoProviderType,
)
from workos.utils.connection_types import ConnectionType
from workos.utils.request_helper import (
DEFAULT_LIST_RESPONSE_LIMIT,
RESPONSE_TYPE_CODE,
Expand All @@ -35,6 +33,13 @@

OAUTH_GRANT_TYPE = "authorization_code"

SsoProviderType = Literal[
"AppleOAuth",
"GitHubOAuth",
"GoogleOAuth",
"MicrosoftOAuth",
]


class ConnectionsListFilters(ListArgs, total=False):
connection_type: Optional[ConnectionType]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from typing import Literal
from workos.resources.sso import ConnectionWithDomains


Expand Down
39 changes: 37 additions & 2 deletions workos/types/sso/connection.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,48 @@
from typing import Literal

from workos.resources.workos_model import WorkOSModel
from workos.typing.literals import LiteralOrUntyped
from workos.utils.connection_types import ConnectionType

ConnectionState = Literal[
"active", "deleting", "inactive", "requires_type", "validating"
]

ConnectionType = Literal[
"ADFSSAML",
"AdpOidc",
"AppleOAuth",
"Auth0SAML",
"AzureSAML",
"CasSAML",
"CloudflareSAML",
"ClassLinkSAML",
"CyberArkSAML",
"DuoSAML",
"GenericOIDC",
"GenericSAML",
"GitHubOAuth",
"GoogleOAuth",
"GoogleSAML",
"JumpCloudSAML",
"KeycloakSAML",
"LastPassSAML",
"LoginGovOidc",
"MagicLink",
"MicrosoftOAuth",
"MiniOrangeSAML",
"NetIqSAML",
"OktaSAML",
"OneLoginSAML",
"OracleSAML",
"PingFederateSAML",
"PingOneSAML",
"RipplingSAML",
"SalesforceSAML",
"ShibbolethGenericSAML",
"ShibbolethSAML",
"SimpleSamlPhpSAML",
"VMwareSAML",
]


class Connection(WorkOSModel):
object: Literal["connection"]
Expand Down
10 changes: 7 additions & 3 deletions workos/user_management.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional, Protocol, Set, Union
from typing import Literal, Optional, Protocol, Set, Union

import workos
from workos.resources.list import (
Expand All @@ -20,14 +20,12 @@
MagicAuth,
OrganizationMembership,
OrganizationMembershipStatus,
PasswordHashType,
PasswordReset,
RefreshTokenAuthenticationResponse,
User,
)
from workos.utils.http_client import AsyncHTTPClient, SyncHTTPClient
from workos.utils.pagination_order import PaginationOrder
from workos.utils.um_provider_types import UserManagementProviderType
from workos.utils.request_helper import (
DEFAULT_LIST_RESPONSE_LIMIT,
RESPONSE_TYPE_CODE,
Expand Down Expand Up @@ -68,6 +66,12 @@
PASSWORD_RESET_DETAIL_PATH = "user_management/password_reset/{0}"


PasswordHashType = Literal["bcrypt", "firebase-scrypt", "ssha"]
UserManagementProviderType = Literal[
"authkit", "AppleOAuth", "GitHubOAuth", "GoogleOAuth", "MicrosoftOAuth"
]


class UsersListFilters(ListArgs, total=False):
email: Optional[str]
organization_id: Optional[str]
Expand Down
Loading
Loading