From f5e31fb12526987a47dd80790714edb2e4be6a4e Mon Sep 17 00:00:00 2001 From: tamarrow Date: Thu, 4 May 2017 10:29:02 -0700 Subject: [PATCH] http: send auth token for requests matching package.cosmos_url (#984) --- cli/tests/integrations/test_package.py | 8 +++++++- dcos/http.py | 13 ++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/cli/tests/integrations/test_package.py b/cli/tests/integrations/test_package.py index b96bd6c..de1a1cd 100644 --- a/cli/tests/integrations/test_package.py +++ b/cli/tests/integrations/test_package.py @@ -7,7 +7,7 @@ import sys import pytest import six -from dcos import constants, subcommand +from dcos import config, constants, subcommand from .helpers.common import (assert_command, assert_lines, base64_to_dict, delete_zk_node, delete_zk_nodes, exec_command, @@ -72,8 +72,14 @@ def test_repo_list(): ).format(**UNIVERSE_TEST_REPOS), 'utf-8' ) + assert_command(['dcos', 'package', 'repo', 'list'], stdout=repo_list) + # test again, but override the dcos_url with a cosmos_url config + dcos_url = config.get_config_val("core.dcos_url") + with update_config('package.cosmos_url', dcos_url): + assert_command(['dcos', 'package', 'repo', 'list'], stdout=repo_list) + def test_repo_add(): repo_list = bytes( diff --git a/dcos/http.py b/dcos/http.py index 9b7aa9e..0c4e9f8 100644 --- a/dcos/http.py +++ b/dcos/http.py @@ -165,13 +165,20 @@ def request(method, auth_token = config.get_config_val("core.dcos_acs_token", toml_config) prompt_login = config.get_config_val("core.prompt_login", toml_config) dcos_url = urlparse(config.get_config_val("core.dcos_url", toml_config)) + cosmos_url = urlparse( + config.get_config_val("package.cosmos_url", toml_config)) parsed_url = urlparse(url) # only request with DC/OS Auth if request is to DC/OS cluster # request should match scheme + netloc - scheme_eq = parsed_url.scheme == dcos_url.scheme - netloc_eq = parsed_url.netloc == dcos_url.netloc - if auth_token and scheme_eq and netloc_eq: + def _request_match(expected_url, actual_url): + return expected_url.scheme == actual_url.scheme and \ + expected_url.netloc == actual_url.netloc + + request_to_cluster = _request_match(dcos_url, parsed_url) or \ + _request_match(cosmos_url, parsed_url) + + if auth_token and request_to_cluster: auth = DCOSAcsAuth(auth_token) else: auth = None