Skip to content

Make _validate_relation a public method #215

Description

@DnPlas

Context

In a recent integration with the dex-oidc-config library, it was discovered that the requirers could use the _validate_relation method for validating that the relation exists. Right now the way a requirer would validate the relation is by calling get_data(), which requires to wrap the logic in a method like this:

    def _check_dex_oidc_config_relation(self) -> None:
        """Check for exceptions from the library and raises ErrorWithStatus to set the unit status.
        Raises:
            ErrorWithStatus: if the relation hasn't been established, set unit to BlockedStatus
            ErrorWithStatus: if the relation has empty or missing data, set unit to WaitingStatus
        """
        try:
            self._dex_oidc_config_requirer.get_data()
        except DexOidcConfigRelationMissingError as rel_error:
            raise ErrorWithStatus(
                f"{rel_error.message} Please add the missing relation.", BlockedStatus
            )
        except DexOidcConfigRelationDataMissingError as data_error:
            self.logger.error(f"Empty or missing data. Got: {data_error.message}")
            raise ErrorWithStatus(
                f"Empty or missing data in {OIDC_PROVIDER_INFO_RELATION} relation."
                " This may be transient, but if it persists it is likely an error.",
                WaitingStatus,
            )

Ideally the requirer object could provide a way to directly check the relation w/o this awkward wrap.

What needs to get done

  1. Make _validate_relation a public method or create a new method
  2. Alternatively, the library could emit a custom event

Definition of Done

The library provides a way for checking the relation from the requirer side.

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