Allow passing app_name and app_version for useragent

Keystoneauth now supports passing app_name and app_version when creating
the session to build a sensible user agent string including client
versions. osc-lib and OpenStack Client should be amongst the first to
support this.

Change-Id: Ia46c1eea29678824a5934d846a08dbe52f5058d0
This commit is contained in:
Jamie Lennox 2016-10-18 15:52:09 +11:00
parent f0d0a4d8b4
commit 5b0f4d27de
3 changed files with 34 additions and 10 deletions

View File

@ -11,12 +11,9 @@
# under the License.
#
from osc_lib import version as _version
__all__ = ['__version__']
import pbr.version
version_info = pbr.version.VersionInfo('osc-lib')
try:
__version__ = version_info.version_string()
except AttributeError:
__version__ = None
__version__ = _version.version_string

View File

@ -25,14 +25,13 @@ import six
from osc_lib.api import auth
from osc_lib import exceptions
from osc_lib import session as osc_session
from osc_lib import version
LOG = logging.getLogger(__name__)
PLUGIN_MODULES = []
USER_AGENT = 'osc-lib'
class ClientCache(object):
"""Descriptor class for caching created client handles."""
@ -62,6 +61,8 @@ class ClientManager(object):
cli_options=None,
api_version=None,
pw_func=None,
app_name=None,
app_version=None,
):
"""Set up a ClientManager
@ -73,11 +74,17 @@ class ClientManager(object):
Callback function for asking the user for a password. The function
takes an optional string for the prompt ('Password: ' on None) and
returns a string containing the password
:param app_name:
The name of the application for passing through to the useragent
:param app_version:
The version of the application for passing through to the useragent
"""
self._cli_options = cli_options
self._api_version = api_version
self._pw_callback = pw_func
self._app_name = app_name
self._app_version = app_version
self.region_name = self._cli_options.region_name
self.interface = self._cli_options.interface
@ -166,9 +173,10 @@ class ClientManager(object):
auth=self.auth,
verify=self.verify,
cert=self.cert,
user_agent=USER_AGENT,
app_name=self._app_name,
app_version=self._app_version,
additional_user_agent=[('osc-lib', version.version_string)],
)
self._auth_setup_completed = True
def validate_scope(self):

19
osc_lib/version.py Normal file
View File

@ -0,0 +1,19 @@
# 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.
import pbr.version
__all__ = ['version_info', 'version_string']
version_info = pbr.version.VersionInfo('osc-lib')
version_string = version_info.version_string()