Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configurable user agent for CDPCLI interface #34

Merged
merged 2 commits into from
Oct 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/cdpy/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

from datetime import datetime
import pkg_resources
from time import time, sleep
import html
import io
Expand All @@ -16,7 +17,7 @@
from typing import Union

import cdpcli
from cdpcli import VERSION
from cdpcli import VERSION as CDPCLI_VERSION
from cdpcli.client import ClientCreator, Context
from cdpcli.credentials import Credentials
from cdpcli.endpoint import EndpointCreator, EndpointResolver
Expand Down Expand Up @@ -136,7 +137,8 @@ def __init__(self, access_key_id, private_key, access_token='', method='static')

class CdpcliWrapper(object):
def __init__(self, debug=False, tls_verify=False, strict_errors=False, tls_warnings=False, client_endpoint=None,
cdp_credentials=None, error_handler=None, warning_handler=None, scrub_inputs=True, cp_region='default'):
cdp_credentials=None, error_handler=None, warning_handler=None, scrub_inputs=True, cp_region='default',
agent_header=None):
# Init Params
self.debug = debug
self.tls_verify = tls_verify
Expand All @@ -146,6 +148,7 @@ def __init__(self, debug=False, tls_verify=False, strict_errors=False, tls_warni
self.cdp_credentials = cdp_credentials
self.scrub_inputs = scrub_inputs
self.cp_region = cp_region
self.agent_header = agent_header if agent_header is not None else 'CDPY'

# Setup
self.throw_error = error_handler if error_handler else self._default_throw_error
Expand Down Expand Up @@ -221,7 +224,7 @@ def _warning_format(message, category, filename, lineno, line=None):
'STOP_IN_PROGRESS',
'STOPPED',
'ENV_STOPPED',
'Stopped', # DW
'Stopped', # DW
'NOT_ENABLED' # DF
]

Expand Down Expand Up @@ -254,12 +257,15 @@ def _warning_format(message, category, filename, lineno, line=None):
self.CREDENTIAL_NAME_PATTERN = re.compile(r'[^a-z0-9-]')
self.OPERATION_REGEX = re.compile(r'operation ([0-9a-zA-Z-]{36}) running')

@staticmethod
def _make_user_agent_header():
return 'CDPSDK/%s Python/%s %s/%s' % (VERSION,
platform.python_version(),
platform.system(),
platform.release())
def _make_user_agent_header(self):
cdpy_version = pkg_resources.get_distribution('cdpy').version
return '%s CDPY/%s CDPCLI/%s Python/%s %s/%s' % (
self.agent_header,
cdpy_version,
CDPCLI_VERSION,
platform.python_version(),
platform.system(),
platform.release())

@staticmethod
def _load_retry_config(loader):
Expand Down