Skip to content

Commit

Permalink
V2 dev (#13)
Browse files Browse the repository at this point in the history
* Fix for percentile not visible in payload

* Bearer Token support added

* Review comments' changes
  • Loading branch information
lmsohamdeshmukh committed May 18, 2022
1 parent f6f0794 commit 5058d3f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
22 changes: 11 additions & 11 deletions logicmonitor_data_sdk/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def __init__(self, company=None, authentication=None, id=None, key=None,bearerTo
# Default Base url
self._authentication = {}
self.bearerflag = False
self.LMV1authflag = False
company = company or os.environ.get('LM_COMPANY')
if company == None or company == '':
raise ValueError(
Expand All @@ -82,22 +81,23 @@ def __init__(self, company=None, authentication=None, id=None, key=None,bearerTo
# type = os.environ.get('LM_ACCESS_TYPE', 'LMv1')
if (id and key):
authentication = {'id': id, 'key': key}
self.LMV1authflag = True
elif not bearerToken:
bearerToken = os.environ.get('LM_BEARER_TOKEN',bearerToken)

if authentication is None and bearerToken:
self._bearertoken = self.check_bearertoken(bearerToken)
self.bearerflag = True

if self.LMV1authflag and (not authentication or not isinstance(authentication,
if not self.bearerflag and (not authentication or not isinstance(authentication,
dict) or 'id' not in authentication or 'key' not in authentication):
raise ValueError(
'Authentication must provide the `id` and `key`'
)
if self.LMV1authflag and not objectNameValidator.is_valid_auth_id(authentication.get('id', None)):
if not self.bearerflag and not objectNameValidator.is_valid_auth_id(authentication.get('id', None)):
raise ValueError(
'Invalid Access ID'
)
if self.LMV1authflag and authentication.get('key', None):
if not self.bearerflag and authentication.get('key', None):
if not objectNameValidator.is_valid_auth_key(authentication.get('key', None)):
raise ValueError(
'Invalid Access Key'
Expand All @@ -109,7 +109,7 @@ def __init__(self, company=None, authentication=None, id=None, key=None,bearerTo
)
self._company = company
self._host = "https://" + self._company + ".logicmonitor.com/rest"
if self.LMV1authflag:
if not self.bearerflag:
self.check_authentication(authentication)
elif self.bearerflag:
self.check_bearertoken(bearerToken)
Expand Down Expand Up @@ -303,7 +303,7 @@ def check_authentication(self, authentication):
'Authentication must provide the `id` and `key`'
)
self._authentication = authentication
self._authentication['type'] = 'LMv1'
self._authentication['type'] = 'LMV1'

def check_bearertoken(self,bearertoken):
if not bearertoken:
Expand All @@ -318,7 +318,7 @@ def host(self):
return self._host

def auth_settings(self):
if self.LMV1authflag==True and self._authentication != None and 'type' in self._authentication and 'key' in self._authentication and 'id' in self._authentication:
if self.bearerflag==False and self._authentication != None and 'type' in self._authentication and 'key' in self._authentication and 'id' in self._authentication:
return {
self._authentication['type']:
{
Expand Down Expand Up @@ -361,8 +361,8 @@ def to_debug_report(self):
arch=platform.machine().lower(),
)
def ret_flags(self):
"""Returns the status of the BearerTokenFlag and LMV1Flag variables
"""Returns the status of the BearerTokenFlag
:return: A list with first element bearerflag and second element LMV1authflag
:return: A list with first element as bearerflag
"""
return [self.bearerflag,self.LMV1authflag]
return [self.bearerflag]
2 changes: 1 addition & 1 deletion logicmonitor_data_sdk/internal/internal_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def make_request(self, path, method, **kwargs): # noqa: E501
auth_type_list = self.api_client.configuration.ret_flags()
if auth_type_list[0]:
auth_settings = ['bearertoken']
elif auth_type_list[1]:
else:
auth_settings = ['LMV1'] # noqa: E501
# if the response type is a file, set _preload_content_value=false.
# Because python 3.0+ 'utf-8' codec can't decode the binary string
Expand Down
2 changes: 1 addition & 1 deletion logicmonitor_data_sdk/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
=======
"""

__version__ = "0.0.2.beta2"
__version__ = "0.0.4.beta1"

0 comments on commit 5058d3f

Please sign in to comment.