Skip to content

Commit f80ff02

Browse files
Nirupma-Vermaramavenkata-loya
authored andcommitted
fixed the cyclic import issue
1 parent eb62fd5 commit f80ff02

File tree

4 files changed

+108
-59
lines changed

4 files changed

+108
-59
lines changed

conjur_api/client.py

Lines changed: 68 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
from conjur_api.models import SslVerificationMode, CreateHostData, CreateTokenData, ListMembersOfData, \
2020
ListPermittedRolesData, ConjurConnectionInfo, Resource, CredentialsData
2121
from conjur_api.utils.decorators import allow_sync_invocation
22-
from conjur_api.wrappers.http_wrapper import set_header_value
23-
from conjur_api import __version__
22+
from conjur_api.wrappers.http_wrapper import set_telemetry_header_value
23+
from importlib.metadata import version, PackageNotFoundError
2424

2525
LOGGING_FORMAT = '%(asctime)s %(levelname)s: %(message)s'
2626
LOGGING_FORMAT_WARNING = 'WARNING: %(message)s'
@@ -34,30 +34,30 @@ class Client:
3434
3535
This class is used to construct a client for API interaction
3636
"""
37-
integration_name = 'SecretsManager Python SDK'
38-
integration_version = __version__
37+
integration_name = 'SecretsManagerPython SDK'
38+
try:
39+
integration_version = version("conjur_api")
40+
except PackageNotFoundError:
41+
integration_version = 'No Version Found'
3942
integration_type = 'cybr-secretsmanager'
4043
vendor_name = 'CyberArk'
4144
vendor_version = None
4245

43-
def set_source_name_header(self):
46+
def set_telemetry_header(self):
4447
"""
4548
Build http header
4649
"""
47-
final_string = ""
48-
if Client.integration_name is not None:
49-
final_string += "in=" + Client.integration_name
50-
if Client.integration_type is not None:
51-
final_string += "&it=" + Client.integration_type
52-
if Client.integration_version is not None:
53-
final_string += "&iv=" + Client.integration_version
50+
final_telemetry_header = ""
5451

55-
if Client.vendor_name is not None:
56-
final_string += "&vn=" + Client.vendor_name
57-
if Client.vendor_version is not None:
58-
final_string += "&vv=" + Client.vendor_version
52+
final_telemetry_header += "in=" + Client.integration_name
53+
final_telemetry_header += "&it=" + Client.integration_type
54+
final_telemetry_header += "&iv=" + Client.integration_version
5955

60-
set_header_value(final_string)
56+
final_telemetry_header += "&vn=" + Client.vendor_name
57+
if Client.vendor_version is not None:
58+
final_telemetry_header += "&vv=" + Client.vendor_version
59+
60+
set_telemetry_header_value(final_telemetry_header)
6161

6262
# The method signature is long but we want to explicitly control
6363
# what parameters are allowed
@@ -96,28 +96,73 @@ def __init__(
9696
self.debug = debug
9797
self._api = self._create_api(http_debug, authn_strategy)
9898

99-
self.set_source_name_header()
99+
self.set_telemetry_header()
100100
logging.debug("Client initialized")
101101

102102
def set_integration_name( self, value ):
103+
"""
104+
Sets the integration name for the client and updates the telemetry header.
105+
106+
This function updates the integration name value for the client and triggers an update to the
107+
telemetry header to reflect the change.
108+
109+
Args:
110+
value (str): The integration name to be set for the client.
111+
"""
103112
Client.integration_name = value
104-
self.set_source_name_header()
113+
self.set_telemetry_header()
105114

106115
def set_integration_type( self, value ):
116+
"""
117+
Sets the integration type for the client and updates the telemetry header.
118+
119+
This function updates the integration type value for the client and triggers an update to the
120+
telemetry header to reflect the change.
121+
122+
Args:
123+
value (str): The integration type to be set for the client.
124+
"""
107125
Client.integration_type = value
108-
self.set_source_name_header()
126+
self.set_telemetry_header()
109127

110128
def set_integration_version( self, value ):
129+
"""
130+
Sets the integration version for the client and updates the telemetry header.
131+
132+
This function updates the integration version value for the client and triggers an update to the
133+
telemetry header to reflect the change.
134+
135+
Args:
136+
value (str): The integration version to be set for the client.
137+
"""
111138
Client.integration_version = value
112-
self.set_source_name_header()
139+
self.set_telemetry_header()
113140

114141
def set_vendor_name( self, value ):
142+
"""
143+
Sets the vendor name for the client and updates the telemetry header.
144+
145+
This function updates the vendor name value for the client and triggers an update to the
146+
telemetry header to reflect the change.
147+
148+
Args:
149+
value (str): The vendor name to be set for the client.
150+
"""
115151
Client.vendor_name = value
116-
self.set_source_name_header()
152+
self.set_telemetry_header()
117153

118154
def set_vendor_version( self, value ):
155+
"""
156+
Sets the vendor version for the client and updates the telemetry header.
157+
158+
This function updates the vendor version value for the client and triggers an update to the
159+
telemetry header to reflect the change.
160+
161+
Args:
162+
value (str): The vendor version to be set for the client.
163+
"""
119164
Client.vendor_version = value
120-
self.set_source_name_header()
165+
self.set_telemetry_header()
121166

122167
@staticmethod
123168
def configure_logger(debug: bool):

conjur_api/wrappers/http_wrapper.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ class Header():
3232
"""
3333
Set header value
3434
"""
35-
final = 'undefined'
35+
final_telemetry = 'undefined'
3636

37-
def set_value( self, value ):
37+
def set_telemetry_value( self, value ):
3838
"""
3939
Set header value
4040
"""
41-
self.final = value
41+
self.final_telemetry = value
4242

43-
def get_value( self ):
43+
def get_telemetry_value( self ):
4444
"""
4545
Get header value
4646
"""
47-
return self.final
47+
return self.final_telemetry
4848

4949
globalheader = Header()
5050
CONJUR_HEADER_NAME = "x-cybr-telemetry"
@@ -61,12 +61,16 @@ class HttpVerb(Enum):
6161
PATCH = 5
6262
HEAD = 6
6363

64-
def set_header_value(value:str): # pragma: no cover
64+
def set_telemetry_header_value(value:str): # pragma: no cover
6565
"""
66-
Set header value
66+
Set telemetry header value by encoding the provided string in base64 URL-safe format.
67+
68+
This function encodes the provided string `value` using URL-safe base64 encoding. The padding characters
69+
(`=`) are removed from the encoded string before being set in the global header through the
70+
`set_telemetry_value` method.
6771
"""
6872
encoded = base64.urlsafe_b64encode(value.encode()).rstrip(b'=').decode()
69-
globalheader.set_value( encoded )
73+
globalheader.set_telemetry_value( encoded )
7074

7175
# pylint: disable=too-many-locals,consider-using-f-string,too-many-arguments
7276
async def invoke_endpoint(http_verb: HttpVerb,
@@ -97,7 +101,7 @@ async def invoke_endpoint(http_verb: HttpVerb,
97101
if headers is None:
98102
headers = {}
99103

100-
headers[ CONJUR_HEADER_NAME ] = globalheader.get_value()
104+
headers[ CONJUR_HEADER_NAME ] = globalheader.get_telemetry_value()
101105

102106
urllib3.disable_warnings()
103107
orig_params = params or {}

tests/authentication_strategy/test_unit_authn_authentication_provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ async def test_missing_username(self):
2626

2727
self.assertRegex(context.exception.message, "Missing parameters")
2828

29-
# TODO: Mock a conjur authn server and test that it is called with the correct parameters
29+
# TODO: Mock a conjur authn server and test that it is called with the correct parameters

0 commit comments

Comments
 (0)