-
-
Notifications
You must be signed in to change notification settings - Fork 782
Add no_proxy to index searches #5500
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
Changes from all commits
b8c1253
f886761
300f09a
b02db71
8ad5e5d
3d4f538
b147c70
6e76bb1
ae2dbc2
a7afece
80de473
2b41eda
224e0e2
9e975a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |||||||||||||||
|
|
||||||||||||||||
| import os | ||||||||||||||||
| import requests | ||||||||||||||||
| from requests.utils import should_bypass_proxies | ||||||||||||||||
| import six | ||||||||||||||||
| from six.moves import range | ||||||||||||||||
| from oslo_config import cfg | ||||||||||||||||
|
|
@@ -83,6 +84,7 @@ def _fetch_and_compile_index(index_urls, logger=None, proxy_config=None): | |||||||||||||||
| if proxy_config: | ||||||||||||||||
| https_proxy = proxy_config.get("https_proxy", None) | ||||||||||||||||
| http_proxy = proxy_config.get("http_proxy", None) | ||||||||||||||||
| no_proxy = proxy_config.get("no_proxy", None) | ||||||||||||||||
| ca_bundle_path = proxy_config.get("proxy_ca_bundle_path", None) | ||||||||||||||||
|
|
||||||||||||||||
| if https_proxy: | ||||||||||||||||
|
|
@@ -92,7 +94,17 @@ def _fetch_and_compile_index(index_urls, logger=None, proxy_config=None): | |||||||||||||||
| if http_proxy: | ||||||||||||||||
| proxies_dict["http"] = http_proxy | ||||||||||||||||
|
|
||||||||||||||||
| if no_proxy: | ||||||||||||||||
| proxies_dict["no"] = no_proxy | ||||||||||||||||
|
|
||||||||||||||||
| for index_url in index_urls: | ||||||||||||||||
|
|
||||||||||||||||
| # TODO: | ||||||||||||||||
| # Bug in requests doesn't bypass proxies, so we do it ourselves | ||||||||||||||||
| # If this issue ever gets fixed then we can remove it | ||||||||||||||||
| # https://github.com/psf/requests/issues/4871 | ||||||||||||||||
| bypass_proxy = should_bypass_proxies(index_url, proxies_dict.get("no")) | ||||||||||||||||
|
|
||||||||||||||||
| index_status = { | ||||||||||||||||
| "url": index_url, | ||||||||||||||||
| "packs": 0, | ||||||||||||||||
|
|
@@ -102,7 +114,11 @@ def _fetch_and_compile_index(index_urls, logger=None, proxy_config=None): | |||||||||||||||
| index_json = None | ||||||||||||||||
|
|
||||||||||||||||
| try: | ||||||||||||||||
| request = requests.get(index_url, proxies=proxies_dict, verify=verify) | ||||||||||||||||
| request = requests.get( | ||||||||||||||||
| index_url, | ||||||||||||||||
| proxies=proxies_dict if not bypass_proxy else None, | ||||||||||||||||
| verify=verify if not bypass_proxy else True, | ||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I still don't understand why adjusting the Could you perhaps provide more context or an example?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. st2/st2common/st2common/services/packs.py Lines 88 to 92 in 224e0e2
Because verify is overwritten with the path to your proxy's ca bundle if An example might be (without proxy_config = {
"https_proxy": "http://proxy.company.local",
"http_proxy": "http://proxy.company.local",
"no_proxy": "company.local,localhost,my.other.domain",
"proxy_ca_bundle_path": "/path/to/proxy/ca_bundle"
}
proxies_dict = {
"https": "http://proxy.company.local",
"http": "http://proxy.company.local",
"no": "company.local,localhost,my.other.domain",
}
# verify is now overwritten from True to '/path/to/proxy/ca_bundle'
verify="/path/to/proxy/ca_bundle"Now we enter loop: # Iteration 1
verify="/path/to/proxy/ca_bundle" # permanently set
index_url="https://index.stackstorm.com"
bypass_proxy = False
requests.get(
"https://index.stackstorm.com",
proxies={
"https": "http://proxy.company.local",
"http": "http://proxy.company.local",
"no": "company.local,localhost,my.other.domain",
},
verify="/path/to/proxy/ca_bundle",
)# Iteration 2
verify="/path/to/proxy/ca_bundle" # permanently set
index_url="https://index.mycompany.local"
bypass_proxy = True
requests.get(
"https://index.mycompany.local",
proxies=None
verify="/path/to/proxy/ca_bundle",
)So in Iteration 2 we would might end up failing because we're still trying to use our proxy's ca bundle, but not using the proxy.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see now, thanks for more context 👍 |
||||||||||||||||
| ) | ||||||||||||||||
| request.raise_for_status() | ||||||||||||||||
| index_json = request.json() | ||||||||||||||||
| except ValueError as e: | ||||||||||||||||
|
|
||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@minsis Did you test it BTW and can confirm no_proxy setting works this way via
nokey?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I swear this was working, but I guess not.
I'm pretty sure the
nokey is correct. I looked in the requests library and when building the proxy info it does a split. Hence the reason the other kyes arehttpandhttps.Looking at the requests docs they never mention no_proxy, but its mentioned in a release note saying its supposed to be
no_proxy.Regardless
noandno_proxydoesn't even seem to work at all. I tested this directly using the requests library.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
psf/requests#4871
Looks like maybe this has been broken for quite some time. There's a PR to fix it, but its still open for 15 months.
I suppose we could implement some similar logic as PR?
psf/requests@063f2ae
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just asking.
I'm good to merge it if you say if the code change was tested manually and works in your environment.
If you can confirm this is 👍 and fixes your case, - just let me know in the PR as the requests doc is a bit confusing indeed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add
noorno_proxydoesn't work unfortunately. So I guess back to square one.My thought now is to maybe use the same logic the PR is using. Basically if it detects the URL being used is in
no_proxyit will remove the proxy info from the request.