Pass username and password as well as token.

This matches the behaviour of heat-cfn.
One day Heat will support doing all operations with only a token. Today is not that day.
Also add a --token-only option to suppress sending username/password.

Change-Id: Ib439d770e90d381ffc83babf7fca85c9f1e32e64
This commit is contained in:
Steve Baker
2012-11-07 16:21:23 +13:00
parent 0d4f3565a8
commit c1dbaa986d
4 changed files with 32 additions and 4 deletions

View File

@@ -51,6 +51,8 @@ class HTTPClient(object):
def __init__(self, endpoint, **kwargs):
self.endpoint = endpoint
self.auth_token = kwargs.get('token')
self.username = kwargs.get('username')
self.password = kwargs.get('password')
self.connection_params = self.get_connection_params(endpoint, **kwargs)
@staticmethod
@@ -129,6 +131,10 @@ class HTTPClient(object):
kwargs['headers'].setdefault('User-Agent', USER_AGENT)
if self.auth_token:
kwargs['headers'].setdefault('X-Auth-Token', self.auth_token)
if self.username:
kwargs['headers'].setdefault('X-Auth-User', self.username)
if self.password:
kwargs['headers'].setdefault('X-Auth-Key', self.password)
self.log_curl_request(method, url, kwargs)
conn = self.get_connection()

View File

@@ -157,6 +157,12 @@ class HeatShell(object):
parser.add_argument('--os_endpoint_type',
help=argparse.SUPPRESS)
parser.add_argument('-t', '--token-only',
default=bool(False),
action='store_true',
help='Only send a token for auth, do not send username and '
'password as well.')
return parser
def get_subcommand_parser(self, version):
@@ -293,6 +299,9 @@ class HeatShell(object):
'cert_file': args.cert_file,
'key_file': args.key_file,
}
if not args.token_only:
kwargs['username'] = args.os_username
kwargs['password'] = args.os_password
client = heatclient.Client(api_version, endpoint, **kwargs)

View File

@@ -1 +1 @@
0.0.11.3c9c859
0.0.27.0d4f356

View File

@@ -1,7 +1,7 @@
import cStringIO
import os
import httplib2
import httplib
import re
import sys
import mox
@@ -21,7 +21,20 @@ TEST_VAR_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__),
'var'))
class ShellValidationTest(unittest.TestCase):
class TestCase(unittest.TestCase):
# required for testing with Python 2.6
def assertRegexpMatches(self, text, expected_regexp, msg=None):
"""Fail the test unless the text matches the regular expression."""
if isinstance(expected_regexp, basestring):
expected_regexp = re.compile(expected_regexp)
if not expected_regexp.search(text):
msg = msg or "Regexp didn't match"
msg = '%s: %r not found in %r' % (msg, expected_regexp.pattern,
text)
raise self.failureException(msg)
class ShellValidationTest(TestCase):
def test_missing_auth(self):
_old_env, os.environ = os.environ, {
@@ -123,7 +136,7 @@ class ShellValidationTest(unittest.TestCase):
return err
class ShellTest(unittest.TestCase):
class ShellTest(TestCase):
# Patch os.environ to avoid required auth info.
def setUp(self):