http: send auth token for requests matching package.cosmos_url (#984)

This commit is contained in:
tamarrow 2017-05-04 10:29:02 -07:00 committed by GitHub
parent 024cdbe058
commit f5e31fb125
2 changed files with 17 additions and 4 deletions

View File

@ -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(

View File

@ -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