Skip to content

Commit

Permalink
use new StrEnum
Browse files Browse the repository at this point in the history
The old way has a different string representation in python 3.11
See https://tsak.dev/posts/python-enum/
  • Loading branch information
helylle committed Oct 9, 2024
1 parent 12fa717 commit f4f90e0
Show file tree
Hide file tree
Showing 30 changed files with 84 additions and 84 deletions.
6 changes: 3 additions & 3 deletions src/eduid/common/config/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from collections.abc import Iterable, Mapping, Sequence
from datetime import timedelta
from enum import Enum, unique
from enum import Enum, StrEnum, unique
from pathlib import Path
from re import Pattern
from typing import IO, Annotated, Any, TypeVar
Expand Down Expand Up @@ -69,7 +69,7 @@ class CookieConfig(BaseModel):
TRootConfigSubclass = TypeVar("TRootConfigSubclass", bound="RootConfig")


class EduidEnvironment(str, Enum):
class EduidEnvironment(StrEnum):
dev = "dev"
staging = "staging"
production = "production"
Expand All @@ -89,7 +89,7 @@ class RootConfig(BaseModel):
TEduIDBaseAppConfigSubclass = TypeVar("TEduIDBaseAppConfigSubclass", bound="EduIDBaseAppConfig")


class LoggingFilters(str, Enum):
class LoggingFilters(StrEnum):
"""Identifiers to coherently map elements in LocalContext.filters to filter classes in logging dictConfig."""

DEBUG_TRUE: str = "require_debug_true"
Expand Down
6 changes: 3 additions & 3 deletions src/eduid/common/models/amapi_user.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from enum import Enum
from enum import StrEnum

from pydantic import BaseModel, Field

Expand All @@ -10,7 +10,7 @@
__author__ = "masv"


class Reason(str, Enum):
class Reason(StrEnum):
USER_DECEASED = "user_deceased"
USER_DEREGISTERED = "user_deregistered"
NAME_CHANGED = "name_changed"
Expand All @@ -19,7 +19,7 @@ class Reason(str, Enum):
TEST = "test"


class Source(str, Enum):
class Source(StrEnum):
SKV_NAVET_V2 = "swedish_tax_agency_navet_v2"
NO_SOURCE = "no_source"
TEST = "test"
Expand Down
4 changes: 2 additions & 2 deletions src/eduid/common/models/bearer_token.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
from collections.abc import Mapping
from copy import copy
from enum import Enum
from enum import StrEnum
from typing import Any

from pydantic import BaseModel, Field, StrictInt, field_validator, model_validator
Expand All @@ -11,7 +11,7 @@
from eduid.userdb.scimapi.groupdb import ScimApiGroupDB


class AuthSource(str, Enum):
class AuthSource(StrEnum):
INTERACTION = "interaction"
CONFIG = "config"
MDQ = "mdq"
Expand Down
6 changes: 3 additions & 3 deletions src/eduid/common/models/gnap_models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from enum import Enum
from enum import StrEnum
from typing import Any

from pydantic import AnyUrl, BaseModel, ConfigDict, Field, field_validator
Expand All @@ -21,7 +21,7 @@ class GnapBaseModel(BaseModel):
model_config = ConfigDict(populate_by_name=True)


class ProofMethod(str, Enum):
class ProofMethod(StrEnum):
DPOP = "dpop"
HTTPSIGN = "httpsign"
JWSD = "jwsd"
Expand Down Expand Up @@ -51,7 +51,7 @@ def expand_proof(cls, v: str | dict[str, Any]) -> dict[str, Any]:
return v


class AccessTokenFlags(str, Enum):
class AccessTokenFlags(StrEnum):
BEARER = "bearer"
DURABLE = "durable"

Expand Down
14 changes: 7 additions & 7 deletions src/eduid/common/models/jose_models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import datetime
from enum import Enum
from enum import StrEnum
from typing import Any

from pydantic import AnyUrl, BaseModel, Field
Expand All @@ -9,18 +9,18 @@
__author__ = "lundberg"


class KeyType(str, Enum):
class KeyType(StrEnum):
EC = "EC"
RSA = "RSA"
OCT = "oct"


class KeyUse(str, Enum):
class KeyUse(StrEnum):
SIGN = "sig"
ENCRYPT = "enc"


class KeyOptions(str, Enum):
class KeyOptions(StrEnum):
SIGN = "sign"
VERIFY = "verify"
ENCRYPT = "encrypt"
Expand All @@ -31,13 +31,13 @@ class KeyOptions(str, Enum):
DERIVE_BITS = "deriveBits"


class SupportedAlgorithms(str, Enum):
class SupportedAlgorithms(StrEnum):
RS256 = "RS256"
ES256 = "ES256"
ES384 = "ES384"


class SupportedHTTPMethods(str, Enum):
class SupportedHTTPMethods(StrEnum):
POST = "POST"


Expand Down Expand Up @@ -84,7 +84,7 @@ class JWKS(BaseModel):
keys: list[ECJWK | RSAJWK | SymmetricJWK]


class SupportedJWSType(str, Enum):
class SupportedJWSType(StrEnum):
JWS = "gnap-binding+jws"
JWSD = "gnap-binding+jwsd"

Expand Down
4 changes: 2 additions & 2 deletions src/eduid/common/models/saml2.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from enum import Enum, unique
from enum import StrEnum, unique

__author__ = "lundberg"


@unique
class EduidAuthnContextClass(str, Enum):
class EduidAuthnContextClass(StrEnum):
DIGG_LOA2 = "http://id.elegnamnden.se/loa/1.0/loa2"
REFEDS_MFA = "https://refeds.org/profile/mfa"
REFEDS_SFA = "https://refeds.org/profile/sfa"
Expand Down
10 changes: 5 additions & 5 deletions src/eduid/common/models/scim_base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from enum import Enum
from enum import StrEnum
from typing import Annotated, Any, Self
from uuid import UUID

Expand Down Expand Up @@ -57,7 +57,7 @@
ScimDatetime = Annotated[datetime, PlainSerializer(serialize_xml_datetime)]


class SCIMSchema(str, Enum):
class SCIMSchema(StrEnum):
CORE_20_USER = "urn:ietf:params:scim:schemas:core:2.0:User"
CORE_20_GROUP = "urn:ietf:params:scim:schemas:core:2.0:Group"
API_MESSAGES_20_SEARCH_REQUEST = "urn:ietf:params:scim:api:messages:2.0:SearchRequest"
Expand All @@ -72,20 +72,20 @@ class SCIMSchema(str, Enum):
DEBUG_V1 = "https://scim.eduid.se/schema/nutid-DEBUG/v1"


class SCIMResourceType(str, Enum):
class SCIMResourceType(StrEnum):
USER = "User"
GROUP = "Group"
INVITE = "Invite"
EVENT = "Event"


class EmailType(str, Enum):
class EmailType(StrEnum):
HOME = "home"
WORK = "work"
OTHER = "other"


class PhoneNumberType(str, Enum):
class PhoneNumberType(StrEnum):
HOME = "home"
WORK = "work"
OTHER = "other"
Expand Down
6 changes: 3 additions & 3 deletions src/eduid/common/rpc/msg_relay.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from enum import Enum
from enum import StrEnum

from pydantic import BaseModel, ConfigDict, Field, ValidationError

Expand Down Expand Up @@ -70,7 +70,7 @@ class RelationId(NavetModelConfig):
birth_time_number: str | None = Field(default=None, alias="BirthTimeNumber")


class RelationType(str, Enum):
class RelationType(StrEnum):
CHILD = "B"
MOTHER = "MO"
FATHER = "FA"
Expand All @@ -94,7 +94,7 @@ class PostalAddresses(NavetModelConfig):
official_address: OfficialAddress = Field(alias="OfficialAddress")


class DeregisteredCauseCode(str, Enum):
class DeregisteredCauseCode(StrEnum):
DECEASED = "AV"
EMIGRATED = "UV"
OLD_NIN = "GN"
Expand Down
4 changes: 2 additions & 2 deletions src/eduid/userdb/authninfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from collections.abc import Mapping
from dataclasses import dataclass
from datetime import datetime
from enum import Enum
from enum import StrEnum

from eduid.userdb import User
from eduid.userdb.credentials import U2F, Password, Webauthn
Expand All @@ -14,7 +14,7 @@
__author__ = "eperez"


class AuthnCredType(str, Enum):
class AuthnCredType(StrEnum):
password = "security.password_credential_type"
u2f = "security.u2f_credential_type"
unknown = "security.unknown_credential_type"
Expand Down
4 changes: 2 additions & 2 deletions src/eduid/userdb/credentials/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from enum import Enum
from enum import StrEnum
from typing import Any

from eduid.userdb.element import TVerifiedElementSubclass, VerifiedElement
Expand All @@ -9,7 +9,7 @@


# well-known proofing methods
class CredentialProofingMethod(str, Enum):
class CredentialProofingMethod(StrEnum):
SWAMID_AL2_MFA_HI = "SWAMID_AL2_MFA_HI" # deprecated and replaced by SWAMID_AL3_MFA
SWAMID_AL3_MFA = "SWAMID_AL3_MFA"

Expand Down
4 changes: 2 additions & 2 deletions src/eduid/userdb/credentials/external.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from collections.abc import Mapping
from enum import Enum
from enum import StrEnum
from typing import Any, Literal

from bson import ObjectId
Expand All @@ -12,7 +12,7 @@
from eduid.userdb.util import objectid_str


class TrustFramework(str, Enum):
class TrustFramework(StrEnum):
SWECONN = "SWECONN"
EIDAS = "EIDAS"
SVIPE = "SVIPE"
Expand Down
4 changes: 2 additions & 2 deletions src/eduid/userdb/group_management/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import datetime
from collections.abc import Mapping
from dataclasses import asdict, dataclass, field, fields
from enum import Enum, unique
from enum import StrEnum, unique
from typing import Any

import bson
Expand All @@ -16,7 +16,7 @@


@unique
class GroupRole(str, Enum):
class GroupRole(StrEnum):
OWNER = "owner"
MEMBER = "member"

Expand Down
12 changes: 6 additions & 6 deletions src/eduid/userdb/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
from abc import ABC
from datetime import datetime
from enum import Enum
from enum import StrEnum
from typing import Any, Literal

from pydantic import Field
Expand All @@ -15,14 +15,14 @@
logger = logging.getLogger(__name__)


class IdentityType(str, Enum):
class IdentityType(StrEnum):
NIN = "nin"
EIDAS = "eidas"
SVIPE = "svipe"
FREJA = "freja"


class IdentityProofingMethod(str, Enum):
class IdentityProofingMethod(StrEnum):
# difference in capitalization/underscore/hyphen is intentional as to follow existing proofing log entries
SVIPE_ID = "svipe_id"
LETTER = "letter"
Expand Down Expand Up @@ -124,13 +124,13 @@ class ForeignIdentityElement(IdentityElement, ABC):
date_of_birth: datetime


class PridPersistence(str, Enum):
class PridPersistence(StrEnum):
A = "A" # Persistence over time is expected to be comparable or better than a Swedish nin
B = "B" # Persistence over time is expected to be relatively stable, but lower than a Swedish nin
C = "C" # No expectations regarding persistence over time


class EIDASLoa(str, Enum):
class EIDASLoa(StrEnum):
NF_LOW = "eidas-nf-low"
NF_SUBSTANTIAL = "eidas-nf-sub"
NF_HIGH = "eidas-nf-high"
Expand Down Expand Up @@ -188,7 +188,7 @@ def unique_value(self) -> str:
return self.svipe_id


class FrejaRegistrationLevel(str, Enum):
class FrejaRegistrationLevel(StrEnum):
EXTENDED = "EXTENDED"
PLUS = "PLUS"

Expand Down
4 changes: 2 additions & 2 deletions src/eduid/userdb/idp/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import logging
from dataclasses import dataclass
from enum import Enum, unique
from enum import StrEnum, unique
from typing import Any

from eduid.common.models.saml2 import EduidAuthnContextClass
Expand Down Expand Up @@ -52,7 +52,7 @@ class SAMLAttributeSettings:


@unique
class SubjectIDRequest(str, Enum):
class SubjectIDRequest(StrEnum):
ANY = "any"
NONE = "none"
PAIRWISE_ID = "pairwise-id"
Expand Down
4 changes: 2 additions & 2 deletions src/eduid/userdb/meta.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from enum import Enum
from enum import StrEnum
from typing import Annotated

from bson import ObjectId
Expand All @@ -10,7 +10,7 @@
__author__ = "lundberg"


class CleanerType(str, Enum):
class CleanerType(StrEnum):
SKV = "skatteverket"
TELE = "teleadress"
LADOK = "ladok"
Expand Down
Loading

0 comments on commit f4f90e0

Please sign in to comment.