redhat-cop / openshift-toolkit

A collection of code samples to help you get started with OpenShift
Apache License 2.0
234 stars 150 forks source link

Enable working with SSL Proxies #6

Closed etsauer closed 7 years ago

etsauer commented 7 years ago

Adds SSL Proxy capabilities.

To test:

Set up a web proxy

sudo yum install tinyproxy -y
sudo tinyproxy

Set proxy variables incorrectly, and ensure it breaks the script

export https_proxy=127.0.0.1:8887
./docker-registry-sync.py --from=registry.access.redhat.com --to=registry.c1-ocp.myorg.com:5000 --file=./docker_tags.json --openshift-version=3.4
requests.packages.urllib3.connectionpool: INFO     Starting new HTTPS connection (1): registry.access.redhat.com
Traceback (most recent call last):
  File "./docker-registry-sync.py", line 168, in <module>
    get_latest_tag_from_api(retrieve_v_tags_from_redhat_list, latest_tag_list, failed_images)
  File "./docker-registry-sync.py", line 75, in get_latest_tag_from_api
    redhat_registry = session.get(url)
  File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 487, in get
    return self.request('GET', url, **kwargs)
  File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 475, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 585, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python2.7/site-packages/requests/adapters.py", line 465, in send
    raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='registry.access.redhat.com', port=443): Max retries exceeded with url: /v2/openshift3/ose-deployer/tags/list (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7fecea09d850>: Failed to establish a new connection: [Errno 111] Connection refused',)))

Now correct the proxy, and re-run the script

export https_proxy=127.0.0.1:8888
./docker-registry-sync.py --from=registry.access.redhat.com --to=registry.c1-ocp.myorg.com:5000 --file=./docker_tags.json --openshift-version=3.4
requests.packages.urllib3.connectionpool: INFO     Starting new HTTPS connection (1): registry.access.redhat.com
requests.packages.urllib3.connectionpool: INFO     Starting new HTTPS connection (1): access.redhat.com
...

Addresses https://github.com/redhat-cop/openshift-toolkit/issues/4

@redhat-cop/cant-contain-this

adam-power commented 7 years ago

Tested this code and it worked for me with our proxy environment variables set.

mmckinst commented 7 years ago

This also worked for me.