Example #1
0
    def __init__(
        self,
        token_refresh_endpoint: str,
        client_id: str,
        client_secret: str,
        refresh_token: str,
        config: Mapping[str, Any],
        scopes: List[str] = None,
        token_expiry_date: str = None,
        access_token_name: str = "access_token",
        expires_in_name: str = "expires_in",
        refresh_request_body: Mapping[str, Any] = None,
    ):
        self.config = config
        self.token_refresh_endpoint = InterpolatedString(token_refresh_endpoint)
        self.client_secret = InterpolatedString(client_secret)
        self.client_id = InterpolatedString(client_id)
        self.refresh_token = InterpolatedString(refresh_token)
        self.scopes = scopes
        self.access_token_name = InterpolatedString(access_token_name)
        self.expires_in_name = InterpolatedString(expires_in_name)
        self.refresh_request_body = InterpolatedMapping(refresh_request_body)

        self.token_expiry_date = (
            pendulum.parse(InterpolatedString(token_expiry_date).eval(self.config))
            if token_expiry_date
            else pendulum.now().subtract(days=1)
        )
        self.access_token = None
Example #2
0
 def __init__(self,
              *,
              next_page_token_template: Mapping[str, str],
              config: Config,
              decoder: Optional[Decoder] = None):
     self._next_page_token_template = InterpolatedMapping(
         next_page_token_template, JinjaInterpolation())
     self._decoder = decoder or JsonDecoder()
     self._config = config
    def __init__(self, *, config, request_inputs=None):
        self._config = config

        if request_inputs is None:
            request_inputs = {}
        if isinstance(request_inputs, str):
            self._interpolator = InterpolatedString(request_inputs, "")
        else:
            self._interpolator = InterpolatedMapping(request_inputs,
                                                     JinjaInterpolation())
Example #4
0
def test():
    d = {
        "field": "value",
        "number": 100,
        "field_to_interpolate_from_config": "{{ config['c'] }}",
        "field_to_interpolate_from_kwargs": "{{ kwargs['a'] }}",
    }
    config = {"c": "VALUE_FROM_CONFIG"}
    kwargs = {"a": "VALUE_FROM_KWARGS"}
    mapping = InterpolatedMapping(d)

    interpolated = mapping.eval(config, **{"kwargs": kwargs})

    assert interpolated["field"] == "value"
    assert interpolated["number"] == 100
    assert interpolated["field_to_interpolate_from_config"] == "VALUE_FROM_CONFIG"
    assert interpolated["field_to_interpolate_from_kwargs"] == "VALUE_FROM_KWARGS"
Example #5
0
    def newfunc(*fargs, **fkeywords):
        interpolation = JinjaInterpolation()
        all_keywords = {**keywords}
        all_keywords.update(fkeywords)

        # config is a special keyword used for interpolation
        config = all_keywords.pop("config", None)

        # options is a special keyword used for interpolation and propagation
        if "options" in all_keywords:
            options = all_keywords.pop("options")
        else:
            options = dict()

        # create object's partial parameters
        fully_created = _create_inner_objects(all_keywords, options)

        # interpolate the parameters
        interpolated_keywords = InterpolatedMapping(
            fully_created, interpolation).eval(config, **{"options": options})
        interpolated_keywords = {
            k: v
            for k, v in interpolated_keywords.items() if v
        }

        all_keywords.update(interpolated_keywords)

        # if config is not none, add it back to the keywords mapping
        if config is not None:
            all_keywords["config"] = config

        kwargs_to_pass_down = _get_kwargs_to_pass_to_func(func, options)
        all_keywords_to_pass_down = _get_kwargs_to_pass_to_func(
            func, all_keywords)
        try:
            ret = func(*args, *fargs, **{
                **all_keywords_to_pass_down,
                **kwargs_to_pass_down
            })
        except TypeError as e:
            raise Exception(
                f"failed to create object of type {func} because {e}")
        return ret
def test():
    d = {
        "field": "value",
        "field_to_interpolate_from_config": "{{ config['c'] }}",
        "field_to_interpolate_from_kwargs": "{{ kwargs['a'] }}",
        "a_field": "{{ value_passed_directly }}",
    }
    config = {"c": "VALUE_FROM_CONFIG"}
    kwargs = {"a": "VALUE_FROM_KWARGS"}
    mapping = InterpolatedMapping(d)

    value_passed_directly = "ABC"
    interpolated = mapping.eval(config,
                                **{"kwargs": kwargs},
                                value_passed_directly=value_passed_directly)

    assert interpolated["field"] == "value"
    assert interpolated[
        "field_to_interpolate_from_config"] == "VALUE_FROM_CONFIG"
    assert interpolated[
        "field_to_interpolate_from_kwargs"] == "VALUE_FROM_KWARGS"
    assert interpolated["a_field"] == value_passed_directly
Example #7
0
 def __init__(self, parent_streams: List[Stream], state: DictState,
              slice_definition: Mapping[str, Any]):
     self._parent_streams = parent_streams
     self._state = state
     self._interpolation = InterpolatedMapping(slice_definition,
                                               JinjaInterpolation())