Skip to content

Commit

Permalink
[issue 141] Allow configuring ofrep provider requests to api at base …
Browse files Browse the repository at this point in the history
…path other than /
  • Loading branch information
atmask committed Jan 3, 2025
1 parent 6801522 commit 8347076
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ def resolve_object_details(
FlagType.OBJECT, flag_key, default_value, evaluation_context
)

def _get_ofrep_api_url(self, api_version: str = "v1") -> str:
ofrep_base_url = (
self.base_url if self.base_url.endswith("/") else f"{self.base_url}/"
)
return urljoin(ofrep_base_url, f"ofrep/{api_version}/")

def _resolve(
self,
flag_type: FlagType,
Expand All @@ -124,7 +130,7 @@ def _resolve(

try:
response = self.session.post(
urljoin(self.base_url, f"/ofrep/v1/evaluate/flags/{flag_key}"),
urljoin(self._get_ofrep_api_url(), f"evaluate/flags/{flag_key}"),
json=_build_request_data(evaluation_context),
timeout=self.timeout,
headers=self.headers_factory() if self.headers_factory else None,
Expand Down
14 changes: 14 additions & 0 deletions providers/openfeature-provider-ofrep/tests/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,17 @@ def test_provider_typecheck_flag_value(ofrep_provider, requests_mock):

with pytest.raises(TypeMismatchError):
ofrep_provider.resolve_boolean_details("flag_key", False)


@pytest.mark.parametrize(
"base_url",
[
"https://localhost:8080",
"https://localhost:8080/",
"https://localhost:8080/tools/feature_flags",
"https://localhost:8080/tools/feature_flags/",
],
)
def test_provider_api_path_resolution(base_url):
provider = OFREPProvider(base_url=base_url)
assert provider._get_ofrep_api_url() == f"{base_url.rstrip("/")}/ofrep/v1/"

0 comments on commit 8347076

Please sign in to comment.