Adding cfg module to contain creds

Change-Id: I75f189c6597a83503810b6a4f6755581a797d845
Closes-Bug: #1605674
Closes-Bug: #1605286
This commit is contained in:
Devdatta Kulkarni 2016-07-22 11:43:06 -05:00
parent 661570fc20
commit 0e3ba5cc36
3 changed files with 31 additions and 16 deletions

View File

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

21
solumclient/config.py Normal file
View File

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

View File

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