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

Add basic proxy support #19

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Add basic proxy support #19

wants to merge 2 commits into from

Conversation

AlwxSin
Copy link

@AlwxSin AlwxSin commented Apr 16, 2018

There are several questions left

  1. Style guide. I'm not sure that I filled help text and placeholder properly
  2. For using proxy there should be requests[socks] requirement. I'm not sure, how combine it with sentry.

@AlwxSin AlwxSin mentioned this pull request Apr 16, 2018
@butorov
Copy link
Owner

butorov commented Apr 17, 2018

Thanks for attention and contribution!
Placeholder looks good. I will check it on my Sentry's instance.
I've written a few comments about the request.

Also, this functionality should be covered by tests.

def send_message_through_proxy(self, url, payload, receiver, proxy):
payload['chat_id'] = receiver
self.logger.debug('Sending message to %s . Using proxy' % receiver)
response = requests.post(url, data=payload, proxies=dict(http=proxy, https=proxy))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to refrain from the direct use of requests. Sentry has internal, unified utils to interact with network.
Please, look for safe_urlopen() built-in function. It supports params to pass additional options, like proxy-settings.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't use params because this argument for query data https://github.com/requests/requests/blob/master/requests/sessions.py#L455
Is it worth to add PR to sentry for adding proxy functionality?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, there is already one getsentry/sentry#6784

@@ -124,6 +138,12 @@ def send_message(self, url, payload, receiver):
)
self.logger.debug('Response code: %s, content: %s' % (response.status_code, response.content))

def send_message_through_proxy(self, url, payload, receiver, proxy):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method looks like almost copy of send_message method.
I propose to use one send_message, and add proxies like this:

response = safe_urlopen(
    method='POST',
    url=url,
    json=payload,
    params=self.get_request_params(),
)

Where get_request_params() will return proxies settings, if it required.

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

Successfully merging this pull request may close these issues.

2 participants