11# -*- coding: utf-8 -*-
22
33from datetime import datetime
4+ import pkg_resources
45from time import time , sleep
56import html
67import io
1617from typing import Union
1718
1819import cdpcli
19- from cdpcli import VERSION
20+ from cdpcli import VERSION as CDPCLI_VERSION
2021from cdpcli .client import ClientCreator , Context
2122from cdpcli .credentials import Credentials
2223from cdpcli .endpoint import EndpointCreator , EndpointResolver
@@ -136,7 +137,8 @@ def __init__(self, access_key_id, private_key, access_token='', method='static')
136137
137138class CdpcliWrapper (object ):
138139 def __init__ (self , debug = False , tls_verify = False , strict_errors = False , tls_warnings = False , client_endpoint = None ,
139- cdp_credentials = None , error_handler = None , warning_handler = None , scrub_inputs = True , cp_region = 'default' ):
140+ cdp_credentials = None , error_handler = None , warning_handler = None , scrub_inputs = True , cp_region = 'default' ,
141+ agent_header = None ):
140142 # Init Params
141143 self .debug = debug
142144 self .tls_verify = tls_verify
@@ -146,6 +148,7 @@ def __init__(self, debug=False, tls_verify=False, strict_errors=False, tls_warni
146148 self .cdp_credentials = cdp_credentials
147149 self .scrub_inputs = scrub_inputs
148150 self .cp_region = cp_region
151+ self .agent_header = agent_header if agent_header is not None else 'CDPY'
149152
150153 # Setup
151154 self .throw_error = error_handler if error_handler else self ._default_throw_error
@@ -221,7 +224,7 @@ def _warning_format(message, category, filename, lineno, line=None):
221224 'STOP_IN_PROGRESS' ,
222225 'STOPPED' ,
223226 'ENV_STOPPED' ,
224- 'Stopped' , # DW
227+ 'Stopped' , # DW
225228 'NOT_ENABLED' # DF
226229 ]
227230
@@ -254,12 +257,15 @@ def _warning_format(message, category, filename, lineno, line=None):
254257 self .CREDENTIAL_NAME_PATTERN = re .compile (r'[^a-z0-9-]' )
255258 self .OPERATION_REGEX = re .compile (r'operation ([0-9a-zA-Z-]{36}) running' )
256259
257- @staticmethod
258- def _make_user_agent_header ():
259- return 'CDPSDK/%s Python/%s %s/%s' % (VERSION ,
260- platform .python_version (),
261- platform .system (),
262- platform .release ())
260+ def _make_user_agent_header (self ):
261+ cdpy_version = pkg_resources .get_distribution ('cdpy' ).version
262+ return '%s CDPY/%s CDPCLI/%s Python/%s %s/%s' % (
263+ self .agent_header ,
264+ cdpy_version ,
265+ CDPCLI_VERSION ,
266+ platform .python_version (),
267+ platform .system (),
268+ platform .release ())
263269
264270 @staticmethod
265271 def _load_retry_config (loader ):
0 commit comments