Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Values are not properly encoded in URLs #61

Open
rveznaver opened this issue Nov 17, 2017 · 0 comments
Open

Values are not properly encoded in URLs #61

rveznaver opened this issue Nov 17, 2017 · 0 comments
Assignees

Comments

@rveznaver
Copy link

Hi,

For a given metric name or dimension key/value the fields are simply joined with a / instead of encoding it before, and then joining it.

Example:
A dimension with a key AwsUniqueId and value applicationelb_app/myalb/id will send a PUT request upon calling dimension_update to the URL https://api.signalfx.com/v2/dimension/AWSUniqueId/applicationelb_app/myalb/id instead of https://api.signalfx.com/v2/dimension/AWSUniqueId/applicationelb_app%2Fmyalb%2Fid.

Workaround for given example is possible by monkey patching the object instance:

import urllib.parse
import types
import signalfx

def monkeypatch_update_dimension(self, key, value, description=None,
                                 custom_properties=None, tags=None, **kwargs):
    '''monkeypatch dimension update'''
    data = {'description': description or '',
            'customProperties': custom_properties or {},
            'tags': tags or [],
            'key': key,
            'value': value}

    resp = self._put(self._u(self._DIMENSION_ENDPOINT_SUFFIX,
                             urllib.parse.quote(key, safe=''),
                             urllib.parse.quote(value, safe='')),
                     data=data, **kwargs)
    resp.raise_for_status()
    return resp.json()

def main():
    sfx = signalfx.SignalFx()
    rest = sfx.rest(args.token)
    rest.update_dimension = types.MethodType(monkeypatch_update_dimension, rest)

This only solves the use case provided in the example, but I believe the same would apply to other methods as well. I unfortunately do not have the time to write a proper pull request for all methods that would need patching, but I believe the latter should provide enough information for a fix.

I was thinking it would be more elegant to patch the _u function, but since the endpoints have slashes inside that actually need to be non-encoded, it would not really work to apply the encoding to all arguments.

Let me know if you need any more info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants