Skip to content

Commit

Permalink
fix: return proper metadata object in FlagdProvider (#59)
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Bond <federicobond@gmail.com>
  • Loading branch information
federicobond authored Feb 24, 2024
1 parent ddd79a4 commit 6508234
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"""

import typing
from dataclasses import dataclass
from numbers import Number

import grpc
Expand All @@ -43,12 +44,16 @@
from .proto.schema.v1 import schema_pb2, schema_pb2_grpc


@dataclass
class Metadata:
name: str


class FlagdProvider(AbstractProvider):
"""Flagd OpenFeature Provider"""

def __init__(
self,
name: str = "flagd",
schema: str = Defaults.SCHEMA,
host: str = Defaults.HOST,
port: int = Defaults.PORT,
Expand All @@ -57,13 +62,11 @@ def __init__(
"""
Create an instance of the FlagdProvider
:param name: the name of the provider to be stored in metadata
:param schema: the schema for the transport protocol, e.g. 'http', 'https'
:param host: the host to make requests to
:param port: the port the flagd service is available on
:param timeout: the maximum to wait before a request times out
"""
self.provider_name = name
self.schema = schema
self.host = host
self.port = port
Expand All @@ -80,17 +83,7 @@ def shutdown(self):

def get_metadata(self):
"""Returns provider metadata"""
return {
"name": self.get_name(),
"schema": self.schema,
"host": self.host,
"port": self.port,
"timeout": self.timeout,
}

def get_name(self) -> str:
"""Returns provider name"""
return self.provider_name
return Metadata(name="FlagdProvider")

def resolve_boolean_details(
self,
Expand Down
8 changes: 8 additions & 0 deletions providers/openfeature-provider-flagd/tests/test_flagd.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from numbers import Number

from openfeature.contrib.provider.flagd import FlagdProvider


def test_should_get_boolean_flag_from_flagd(flagd_provider_client):
# Given
Expand Down Expand Up @@ -69,3 +71,9 @@ def test_should_get_object_flag_from_flagd(flagd_provider_client):
assert flag is not None
assert flag.value == return_value
assert isinstance(flag.value, dict)


def test_get_metadata_returns_metadata_object_with_name():
provider = FlagdProvider()
metadata = provider.get_metadata()
assert metadata.name == "FlagdProvider"

0 comments on commit 6508234

Please sign in to comment.