Skip to content
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
9 changes: 9 additions & 0 deletions open_feature/open_feature_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import typing
from dataclasses import dataclass

from open_feature.evaluation_context.evaluation_context import EvaluationContext
from open_feature.exception.error_code import ErrorCode
Expand Down Expand Up @@ -45,6 +46,11 @@
]


@dataclass
class ClientMetadata:
name: str


class OpenFeatureClient:
def __init__(
self,
Expand All @@ -60,6 +66,9 @@ def __init__(
self.hooks = hooks or []
self.provider = provider

def get_metadata(self):
return ClientMetadata(name=self.name)

def add_hooks(self, hooks: typing.List[Hook]):
self.hooks = self.hooks + hooks

Expand Down
12 changes: 12 additions & 0 deletions tests/test_open_feature_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from open_feature.exception.exceptions import OpenFeatureError
from open_feature.flag_evaluation.reason import Reason
from open_feature.hooks.hook import Hook
from open_feature.open_feature_client import OpenFeatureClient
from open_feature.provider.no_op_provider import NoOpProvider


@pytest.mark.parametrize(
Expand Down Expand Up @@ -132,3 +134,13 @@ def test_should_handle_an_open_feature_exception_thrown_by_a_provider(
assert isinstance(flag_details.value, bool)
assert flag_details.reason == Reason.ERROR.value
assert flag_details.error_message == "error_message"


def test_should_return_client_metadata_with_name():
# Given
client = OpenFeatureClient("my-client", None, NoOpProvider())
# When
metadata = client.get_metadata()
# Then
assert metadata is not None
assert metadata.name == "my-client"