Skip to content

Use real enum types instead of class vars #685

Description

@jooola

Feature Request

A lot of enums in our API are implemented as class variables under the domain it related to.

Those should be replaced with real enum types to embrace good coding practices.

This should be implemented in a backward compatible way, deprecated before the next major version and removed afterwards.

For example:

class Zone(BaseDomain, DomainIdentityMixin):
    """
    Zone Domain.

    See https://docs.hetzner.cloud/reference/cloud#zones.
    """

    MODE_PRIMARY = "primary"
    """
    Zone in primary mode, resource record sets (RRSets) and resource records (RRs) are
    managed via the Cloud API or Cloud Console.
    """
    MODE_SECONDARY = "secondary"
    """
    Zone in secondary mode, Hetzner's nameservers query RRSets and RRs from given
    primary nameservers via AXFR.
    """

    STATUS_OK = "ok"
    """The Zone is pushed to the authoritative nameservers."""
    STATUS_UPDATING = "updating"
    """The Zone is currently being published to the authoritative nameservers."""
    STATUS_ERROR = "error"
    """The Zone could not be published to the authoritative nameservers."""

    REGISTRAR_HETZNER = "hetzner"
    REGISTRAR_OTHER = "other"
    REGISTRAR_UNKNOWN = "unknown"

Could become:

class Zone(BaseDomain, DomainIdentityMixin):
    """
    Zone Domain.

    See https://docs.hetzner.cloud/reference/cloud#zones.
    """

    class Mode(Enum):
        PRIMARY = "primary"
        """
        Zone in primary mode, resource record sets (RRSets) and resource records (RRs) are
        managed via the Cloud API or Cloud Console.
        """
        SECONDARY = "secondary"
        """
        Zone in secondary mode, Hetzner's nameservers query RRSets and RRs from given
        primary nameservers via AXFR.
        """

    class Status(Enum):
        OK = "ok"
        """The Zone is pushed to the authoritative nameservers."""
        UPDATING = "updating"
        """The Zone is currently being published to the authoritative nameservers."""
        ERROR = "error"
        """The Zone could not be published to the authoritative nameservers."""

    class Registrar(Enum):
        HETZNER = "hetzner"
        OTHER = "other"
        UNKNOWN = "unknown"

We could also not put those enums under the class namespace, and have them as top level class in the module.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions