ibm_scc.common
This module provides common methods for use across all service modules.
1# coding: utf-8 2 3# Copyright 2019, 2020 IBM All Rights Reserved. 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17""" 18This module provides common methods for use across all service modules. 19""" 20 21import platform 22from ibm_scc.version import __version__ 23 24HEADER_NAME_USER_AGENT = 'User-Agent' 25SDK_NAME = 'scc-python-sdk' 26 27def get_system_info(): 28 """ 29 Get information about the system to be inserted into the User-Agent header. 30 """ 31 return 'lang={0}; arch={1}; os={2}; python.version={3}'.format('python', 32 platform.machine(), # Architecture 33 platform.system(), # OS 34 platform.python_version()) # Python version 35 36 37def get_user_agent(): 38 """ 39 Get the value to be sent in the User-Agent header. 40 """ 41 return USER_AGENT 42 43 44USER_AGENT = '{0}/{1} ({2})'.format(SDK_NAME, __version__, get_system_info()) 45 46 47def get_sdk_headers(service_name, service_version, operation_id): 48 #pylint: disable=unused-argument 49 """ 50 Get the request headers to be sent in requests by the SDK. 51 52 If you plan to gather metrics for your SDK, the User-Agent header value must 53 be a string similar to the following: 54 my-python-sdk/0.0.1 (lang=python; arch=x86_64; os=Linux; python.version=3.7.4) 55 In the example above, the analytics tool will parse the user-agent header and 56 use the following properties: 57 "my-python-sdk" - the name of your sdk 58 "0.0.1"- the version of your sdk 59 "lang=python" - the language of the current sdk 60 "arch=x86_64; os=Linux; python.version=3.7.4" - system information 61 Note: It is very important that the sdk name ends with the string `-sdk`, 62 as the analytics data collector uses this to gather usage data. 63 """ 64 headers = {} 65 headers[HEADER_NAME_USER_AGENT] = get_user_agent() 66 return headers
28def get_system_info(): 29 """ 30 Get information about the system to be inserted into the User-Agent header. 31 """ 32 return 'lang={0}; arch={1}; os={2}; python.version={3}'.format('python', 33 platform.machine(), # Architecture 34 platform.system(), # OS 35 platform.python_version()) # Python version
Get information about the system to be inserted into the User-Agent header.
38def get_user_agent(): 39 """ 40 Get the value to be sent in the User-Agent header. 41 """ 42 return USER_AGENT
Get the value to be sent in the User-Agent header.
48def get_sdk_headers(service_name, service_version, operation_id): 49 #pylint: disable=unused-argument 50 """ 51 Get the request headers to be sent in requests by the SDK. 52 53 If you plan to gather metrics for your SDK, the User-Agent header value must 54 be a string similar to the following: 55 my-python-sdk/0.0.1 (lang=python; arch=x86_64; os=Linux; python.version=3.7.4) 56 In the example above, the analytics tool will parse the user-agent header and 57 use the following properties: 58 "my-python-sdk" - the name of your sdk 59 "0.0.1"- the version of your sdk 60 "lang=python" - the language of the current sdk 61 "arch=x86_64; os=Linux; python.version=3.7.4" - system information 62 Note: It is very important that the sdk name ends with the string `-sdk`, 63 as the analytics data collector uses this to gather usage data. 64 """ 65 headers = {} 66 headers[HEADER_NAME_USER_AGENT] = get_user_agent() 67 return headers
Get the request headers to be sent in requests by the SDK.
If you plan to gather metrics for your SDK, the User-Agent header value must
be a string similar to the following:
my-python-sdk/0.0.1 (lang=python; arch=x86_64; os=Linux; python.version=3.7.4)
In the example above, the analytics tool will parse the user-agent header and
use the following properties:
"my-python-sdk" - the name of your sdk
"0.0.1"- the version of your sdk
"lang=python" - the language of the current sdk
"arch=x86_64; os=Linux; python.version=3.7.4" - system information
Note: It is very important that the sdk name ends with the string -sdk,
as the analytics data collector uses this to gather usage data.