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 HTTPS_PROXY as variable to the credentials helper #102

Merged
merged 2 commits into from
Nov 17, 2022
Merged
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
18 changes: 17 additions & 1 deletion geti_sdk/utils/credentials_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ def get_server_details_from_env(

VERIFY_CERT -> boolean, pass 1 or True to verify

HTTPS_PROXY -> Address of the proxy to be used for https communication. Make
sure to specify the full address, including port number. For
example: HTTPS_PROXY=http://proxy.my-company.com:900

In addition, authentication via credentials is also supported. In that case, the
following variables should be provided:
Expand Down Expand Up @@ -96,6 +99,7 @@ def get_server_details_from_env(
username_key = "GETI_USERNAME"
password_key = "GETI_PASSWORD" # nosec: B105
cert_key = "GETI_VERIFY_CERT"
https_proxy_key = "GETI_HTTPS_PROXY"

retrieval_func = os.environ.get
env_name = "environment variables"
Expand All @@ -105,6 +109,7 @@ def get_server_details_from_env(
username_key = "USERNAME"
password_key = "PASSWORD" # nosec: B105
cert_key = "VERIFY_CERT"
https_proxy_key = "HTTPS_PROXY"

env_variables = dotenv_values(dotenv_path=env_file_path)
if not env_variables:
Expand All @@ -128,6 +133,13 @@ def get_server_details_from_env(
value=retrieval_func(cert_key, None), default_value=True
)

# Extract https proxy configuration
https_proxy = retrieval_func(https_proxy_key, None)
if https_proxy is not None:
proxies = {"https": https_proxy}
else:
proxies = None

# Extract token/credentials
token = retrieval_func(token_key, None)
if token is None:
Expand All @@ -144,9 +156,13 @@ def get_server_details_from_env(
username=user,
password=password,
has_valid_certificate=verify_certificate,
proxies=proxies,
)
else:
server_config = ServerTokenConfig(
host=hostname, token=token, has_valid_certificate=verify_certificate
host=hostname,
token=token,
has_valid_certificate=verify_certificate,
proxies=proxies,
)
return server_config
1 change: 1 addition & 0 deletions tests/data/mock.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ USERNAME=dummy_user
PASSWORD=dummy_password
HOST=dummy_host
TOKEN=this_is_a_fake_token
HTTPS_PROXY="http://dummy_proxy.com:900"
2 changes: 2 additions & 0 deletions tests/pre-merge/integration/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def test_get_server_details_from_env(self, fxt_env_filepath: str):

assert server_config.host == f"https://{DUMMY_HOST}"
assert server_config.token == "this_is_a_fake_token"
assert "https" in server_config.proxies.keys()
assert not hasattr(server_config, "username")
assert not hasattr(server_config, "password")

Expand All @@ -86,4 +87,5 @@ def test_get_server_details_from_env(self, fxt_env_filepath: str):
].replace("https://", "")
assert server_config.username == expected_results["GETI_USERNAME"]
assert server_config.password == expected_results["GETI_PASSWORD"]
assert server_config.proxies is None
assert not hasattr(server_config, "token")