From 0e3ba5cc3665555b1b28da19a4758e783d439a56 Mon Sep 17 00:00:00 2001 From: Devdatta Kulkarni Date: Fri, 22 Jul 2016 11:43:06 -0500 Subject: [PATCH] Adding cfg module to contain creds Change-Id: I75f189c6597a83503810b6a4f6755581a797d845 Closes-Bug: #1605674 Closes-Bug: #1605286 --- solumclient/common/client.py | 12 +++++------- solumclient/config.py | 21 +++++++++++++++++++++ solumclient/solum.py | 14 +++++--------- 3 files changed, 31 insertions(+), 16 deletions(-) create mode 100644 solumclient/config.py diff --git a/solumclient/common/client.py b/solumclient/common/client.py index f14e640..ef53ed7 100644 --- a/solumclient/common/client.py +++ b/solumclient/common/client.py @@ -15,8 +15,8 @@ import logging import time -import solumclient from solumclient.common import exc +from solumclient import config from solumclient.openstack.common.apiclient import client as api_client @@ -36,14 +36,12 @@ class HTTPClient(api_client.HTTPClient): ' requests.Session.request (such as `headers`) or `json` that will be encoded as JSON and used as `data` argument """ + kwargs.setdefault("headers", kwargs.get("headers", {})) kwargs["headers"]["User-Agent"] = self.user_agent - kwargs["headers"]["X-User-ID"] = ( - solumclient.solum.AppCommands.username) - kwargs["headers"]["X-Password"] = ( - solumclient.solum.AppCommands.password) - kwargs["headers"]["X-Project"] = ( - solumclient.solum.AppCommands.tenant) + kwargs["headers"]["X-User-ID"] = config.username + kwargs["headers"]["X-Password"] = config.password + kwargs["headers"]["X-Project"] = config.tenant if self.original_ip: kwargs["headers"]["Forwarded"] = "for=%s;by=%s" % ( self.original_ip, self.user_agent) diff --git a/solumclient/config.py b/solumclient/config.py new file mode 100644 index 0000000..87a533e --- /dev/null +++ b/solumclient/config.py @@ -0,0 +1,21 @@ +# Copyright (c) 2016 Rackspace +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +username = '' +password = '' +tenant = '' +auth_url = '' +tenant_name = '' diff --git a/solumclient/solum.py b/solumclient/solum.py index fbc8487..6b234aa 100644 --- a/solumclient/solum.py +++ b/solumclient/solum.py @@ -51,6 +51,7 @@ from solumclient.common import cli_utils from solumclient.common import exc from solumclient.common import github from solumclient.common import yamlutils +from solumclient import config from solumclient.openstack.common.apiclient import exceptions from solumclient.v1 import app as cli_app from solumclient.v1 import languagepack as cli_lp @@ -518,12 +519,6 @@ Available commands: are displayed. """ - username = '' - password = '' - tenant = '' - auth_url = '' - tenant_name = '' - def _validate_app_file(self, app_data): if ('workflow_config' in app_data and app_data.get('workflow_config') is None): @@ -767,9 +762,10 @@ Available commands: def create(self): parsed, _ = self.parser.parse_known_args() - AppCommands.username = parsed.os_username - AppCommands.password = parsed.os_password - AppCommands.tenant = parsed.os_tenant_name + config.username = parsed.os_username + config.password = parsed.os_password + config.tenant = parsed.os_tenant_name + self.register() def register(self):