open-feature / python-sdk-contrib

Community contributions for hooks and reference providers in python
https://openfeature.dev
10 stars 11 forks source link

get_path_for is broken #17

Closed agardnerIT closed 11 months ago

agardnerIT commented 11 months ago

The get_path_for method of WebApiUrlFactory doesn't work for me.

https://github.com/open-feature/python-sdk-contrib/blob/main/open_feature_contrib/providers/flagd/web_api_url_factory.py#L39-#L44

Fix

def get_path_for(self, flag_type: FlagType):

        # This is complex. Explainer
        # 1. Look up the appropriate string from __mapping for the incoming flag_type
        #    for example, FlagType.STRING should match and return the string "get_string_path"
        #    if an invalid flag_type or something goes wrong, fallback to __default_mapping_key
        #    which is "_invalid_flag_type_method"
        # 2. Use that string eg. "get_string_path" with getattr to "make it available" as a method to call
        #    Notice that each string in __mapping has a corresponding method
        #    Thus method_to_call() is dynamic, based on flag_type, so it could be get_string_path() or get_float_path() etc.
        # 3. Invoke that method and assign the return to formatted_endpoint which should be the full URL to flagd
        #    eg. http://localhost:8013/schema.v1.Service/ResolveString
        method_to_call = getattr(self, self.__mapping.get(flag_type, WebApiUrlFactory.__default_mapping_key))
        formatted_endpoint = method_to_call()
        return formatted_endpoint