Skip to content
This repository was archived by the owner on Mar 13, 2022. It is now read-only.

added configuration 'http_proxy' to allow the usage of a proxy #8

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# ref: https://docs.travis-ci.com/user/languages/python
language: python

# Keep this matrix in sync with main repo's test matrix
matrix:
include:
- python: 2.7
env: TOXENV=py27
- python: 2.7
env: TOXENV=py27-functional
- python: 2.7
env: TOXENV=update-pep8
- python: 2.7
env: TOXENV=docs
- python: 2.7
env: TOXENV=coverage,codecov
- python: 3.4
env: TOXENV=py34
- python: 3.5
env: TOXENV=py35
- python: 3.5
env: TOXENV=py35-functional
- python: 3.6
env: TOXENV=py36
- python: 3.6
env: TOXENV=py36-functional

install:
- pip install tox

script:
- tox

4 changes: 4 additions & 0 deletions configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ def __init__(self):
# Set this to True/False to enable/disable SSL hostname verification.
self.assert_hostname = None

# http proxy setting
self.http_proxy_url = None


@property
def logger_file(self):
"""
Expand Down
11 changes: 8 additions & 3 deletions rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,14 @@ def __init__(self, pools_size=4, config=configuration):
kwargs['assert_hostname'] = config.assert_hostname

# https pool manager
self.pool_manager = urllib3.PoolManager(
**kwargs
)
if config.http_proxy_url is not None:
self.pool_manager = urllib3.proxy_from_url(
Copy link

Choose a reason for hiding this comment

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

Maybe we should add a test that mocks proxy_from_url and we ensure it's called when seting config.http_proxy_url

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I asked the original developer to add test and he didn't have time to do it I guess, I will try to add something. Though I am now short on time and this can take a while.

config.http_proxy_url, **kwargs
)
else:
self.pool_manager = urllib3.PoolManager(
**kwargs
)

def request(self, method, url, query_params=None, headers=None,
body=None, post_params=None, _preload_content=True, _request_timeout=None):
Expand Down
49 changes: 49 additions & 0 deletions run_tox.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

# Copyright 2017 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Script to fetch latest swagger spec.
# Puts the updated spec at api/swagger-spec/

set -o errexit
set -o nounset
set -o pipefail

RUNNING_DIR=$(pwd)
TMP_DIR=$(mktemp -d)

function cleanup()
{
cd "${RUNNING_DIR}"
# rm -rf "${TMP_DIR}"
}
trap cleanup EXIT SIGINT


SCRIPT_ROOT=$(dirname "${BASH_SOURCE}")
pushd "${SCRIPT_ROOT}" > /dev/null
SCRIPT_ROOT=`pwd`
popd > /dev/null

cd "${TMP_DIR}"
git clone https://github.com/kubernetes-incubator/client-python.git
cd client-python
cp -r "${SCRIPT_ROOT}/." kubernetes/base
pip install -r requirements.txt
pip install -r test-requirements.txt

# Run the user-provided command.
"${@}"

11 changes: 11 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[tox]
skipsdist = True
envlist = py27, py34, py35, py36, py27-functional, py36-functional, py35-functional, coverage, codecov

[testenv]
passenv = TOXENV CI TRAVIS TRAVIS_*
commands =
python -V
pip install nose
./run_tox.sh nosetests []