Skip to content

Commit

Permalink
Merge "Only set X-Auth-User, X-Auth-Key on stack create/update."
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Jul 16, 2013
2 parents 710f751 + 4259289 commit b417688
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
10 changes: 6 additions & 4 deletions heatclient/common/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,6 @@ def _http_request(self, url, method, **kwargs):
kwargs['headers'].setdefault('X-Auth-Token', self.auth_token)
if self.auth_url:
kwargs['headers'].setdefault('X-Auth-Url', self.auth_url)
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()
Expand Down Expand Up @@ -178,6 +174,12 @@ def _http_request(self, url, method, **kwargs):

return resp, body_str

def credentials_headers(self):
return {
'X-Auth-User': self.username,
'X-Auth-Key': self.password
}

def json_request(self, method, url, **kwargs):
kwargs.setdefault('headers', {})
kwargs['headers'].setdefault('Content-Type', 'application/json')
Expand Down
9 changes: 3 additions & 6 deletions heatclient/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ def get_base_parser(self):
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.')
help='DEPRECATED! Has no effect')

return parser

Expand Down Expand Up @@ -303,15 +302,13 @@ def main(self, argv):
'ca_file': args.ca_file,
'cert_file': args.cert_file,
'key_file': args.key_file,
'username': args.os_username
'username': args.os_username,
'password': args.os_password
}

if not endpoint:
endpoint = self._get_endpoint(_ksclient, **kwargs)

if not args.token_only:
kwargs['password'] = args.os_password

client = heatclient.Client(api_version, endpoint, **kwargs)

try:
Expand Down
16 changes: 12 additions & 4 deletions heatclient/tests/test_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,9 @@ def test_create(self):
{'location': 'http://no.where/v1/tenant_id/stacks/teststack2/2'},
None)
v1client.Client.json_request(
'POST', '/stacks', body=mox.IgnoreArg()).AndReturn((resp, None))
'POST', '/stacks', body=mox.IgnoreArg(),
headers={'X-Auth-Key': 'password', 'X-Auth-User': 'username'}
).AndReturn((resp, None))
fakes.script_heat_list()

self.m.ReplayAll()
Expand Down Expand Up @@ -344,7 +346,9 @@ def test_create_url(self):
{'location': 'http://no.where/v1/tenant_id/stacks/teststack2/2'},
None)
v1client.Client.json_request(
'POST', '/stacks', body=mox.IgnoreArg()).AndReturn((resp, None))
'POST', '/stacks', body=mox.IgnoreArg(),
headers={'X-Auth-Key': 'password', 'X-Auth-User': 'username'}
).AndReturn((resp, None))
fakes.script_heat_list()

self.m.ReplayAll()
Expand Down Expand Up @@ -381,7 +385,9 @@ def test_create_object(self):
{'location': 'http://no.where/v1/tenant_id/stacks/teststack2/2'},
None)
v1client.Client.json_request(
'POST', '/stacks', body=mox.IgnoreArg()).AndReturn((resp, None))
'POST', '/stacks', body=mox.IgnoreArg(),
headers={'X-Auth-Key': 'password', 'X-Auth-User': 'username'}
).AndReturn((resp, None))

fakes.script_heat_list()

Expand Down Expand Up @@ -412,7 +418,9 @@ def test_update(self):
'The request is accepted for processing.')
v1client.Client.json_request(
'PUT', '/stacks/teststack2/2',
body=mox.IgnoreArg()).AndReturn((resp, None))
body=mox.IgnoreArg(),
headers={'X-Auth-Key': 'password', 'X-Auth-User': 'username'}
).AndReturn((resp, None))
fakes.script_heat_list()

self.m.ReplayAll()
Expand Down
7 changes: 5 additions & 2 deletions heatclient/v1/stacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,16 @@ def paginate(qp, seen=0):

def create(self, **kwargs):
"""Create a stack."""
resp, body = self.api.json_request('POST', '/stacks', body=kwargs)
headers = self.api.credentials_headers()
resp, body = self.api.json_request('POST', '/stacks',
body=kwargs, headers=headers)

def update(self, **kwargs):
"""Update a stack."""
stack_id = kwargs.pop('stack_id')
headers = self.api.credentials_headers()
resp, body = self.api.json_request('PUT', '/stacks/%s' % stack_id,
body=kwargs)
body=kwargs, headers=headers)

def delete(self, stack_id):
"""Delete a stack."""
Expand Down

0 comments on commit b417688

Please sign in to comment.