Skip to content

Commit 91abcc9

Browse files
authored
Merge pull request #3 from logicmonitor/validation-fix
Validation fix
2 parents 449ceb7 + 98a7e76 commit 91abcc9

File tree

5 files changed

+44
-13
lines changed

5 files changed

+44
-13
lines changed

docs/source/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ The :mod:`logicmonitor_data_sdk` module provides
2727
Requirements.
2828
*************
2929

30-
Python 2.7 and 3.4+
30+
Python 3.4+
3131

3232
.. _RST Installation:
3333

@@ -175,4 +175,4 @@ ResponseInterface
175175

176176
Get in Touch
177177
============
178-
If you have questions in general, reach out to our support@logicmonitor.com
178+
If you have questions in general, reach out to our support@logicmonitor.com

logicmonitor_data_sdk/configuration.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77
import multiprocessing
88
import os
99
import platform
10-
1110
import six
1211
from six.moves import http_client as httplib
1312

13+
from logicmonitor_data_sdk.utils.object_name_validator import ObjectNameValidator
1414
from logicmonitor_data_sdk.version import __version__
1515

16-
17-
# logging.basicConfig()
18-
16+
objectNameValidator = ObjectNameValidator()
1917

2018
class TypeWithDefault(type):
2119
def __init__(cls, name, bases, dct):
@@ -61,6 +59,10 @@ def __init__(self, company=None, authentication=None, id=None, key=None):
6159
raise ValueError(
6260
'Company must have your account name'
6361
)
62+
if not objectNameValidator.is_valid_company_name(company):
63+
raise ValueError(
64+
'Invalid Company Name'
65+
)
6466
if not authentication:
6567
id = os.environ.get('LM_ACCESS_ID', id)
6668
key = os.environ.get('LM_ACCESS_KEY', key)
@@ -72,6 +74,15 @@ def __init__(self, company=None, authentication=None, id=None, key=None):
7274
raise ValueError(
7375
'Authentication must provide the `id` and `key`'
7476
)
77+
if not objectNameValidator.is_valid_auth_id(id):
78+
raise ValueError(
79+
'Invalid Access ID'
80+
)
81+
if key:
82+
if not objectNameValidator.is_valid_auth_key(key):
83+
raise ValueError(
84+
'Invalid Access Key'
85+
)
7586
self._company = company
7687
self._host = "https://" + self._company + ".logicmonitor.com/rest"
7788
self.check_authentication(authentication)

logicmonitor_data_sdk/models/datapoint.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ class DataPoint(object):
1919
name (:obj:`str`): Datapoint name. If no existing datapoint matches for specified
2020
DataSource, a new datapoint is created with this name.
2121
aggregation_type (:obj:`str`, optional): The aggregation method, if any, that should be used
22-
if data is pushed in sub-minute intervals. Only considered when creating
22+
if data is pushed in sub-minute intervals. Allowed options are "sum", "average" and "none"(default)
23+
where "none" would take last value for that minute. Only considered when creating
2324
a new datapoint. See the About the Push Metrics REST API section of this
2425
guide for more information on datapoint value aggregation intervals.
2526
description (:obj:`str`, optional) : Datapoint description. Only considered when creating a
2627
new datapoint.
27-
type (:obj:`str`, optional) : Metric type as a number in string format. Only considered when
28-
creating a new datapoint.
28+
type (:obj:`str`, optional) : Metric type as a number in string format. Allowed options are
29+
"guage" (default) and "counter". Only considered when creating a new datapoint.
2930
3031
Examples:
3132
>>> from logicmonitor_data_sdk.models.datapoint import DataPoint
@@ -74,7 +75,7 @@ def __hash__(self):
7475
@property
7576
def aggregation_type(self):
7677
"""The aggregation method, if any, that should be used if data is pushed in
77-
sub-minute intervals. Only considered when creating a new datapoint.
78+
sub-minute intervals. Aloowed values are 'sum', 'average' and 'none'(default). Only considered when creating a new datapoint.
7879
7980
:return: The type of this DataPoint.
8081
:rtype: str
@@ -128,9 +129,9 @@ def name(self, name):
128129

129130
@property
130131
def type(self):
131-
"""Metric type as a number in string format. Only considered when creating a new datapoint.
132+
"""Metric type (guage or counter) as a number in string format. Only considered when creating a new datapoint.
132133
133-
:return: The aggregation_type of this DataPoint.
134+
:return: The type of this DataPoint.
134135
:rtype: str
135136
"""
136137
return self._type

logicmonitor_data_sdk/utils/object_name_validator.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@
3030
REGEX_DATA_SOURCE_GROUP_NAME = "[a-zA-Z0-9_\\- ]+$"
3131
PATTERN_DATA_SOURCE_GROUP_NAME = re.compile(REGEX_DATA_SOURCE_GROUP_NAME)
3232

33+
REGEX_COMPANY_NAME = "^[a-zA-Z0-9_.\\-]+$"
34+
PATTERN_COMPANY_NAME = re.compile(REGEX_COMPANY_NAME)
35+
36+
REGEX_AUTH_ID = "^[a-zA-Z0-9]+$"
37+
PATTERN_AUTH_ID = re.compile(REGEX_AUTH_ID)
38+
39+
REGEX_AUTH_KEY = "[\s]"
40+
PATTERN_AUTH_KEY = re.compile(REGEX_AUTH_KEY)
41+
3342
_INVALID_DATA_POINT_NAME_SET = {
3443
"SIN",
3544
"COS",
@@ -109,7 +118,7 @@ def is_valid_resource_name(self, resource_name):
109118
return bool(PATTERN_RESOURCE_NAME.match(resource_name))
110119

111120
def is_valid_resource_id(self, resource_id):
112-
return not bool(PATTERN_REGEX_INVALID_RESOURCE_NAME.match(resource_id))
121+
return not bool(PATTERN_REGEX_INVALID_RESOURCE_NAME.search(resource_id))
113122

114123
def is_valid_datasource_name(self, name):
115124
return len(self.validate_datasource_name(name)) == 0
@@ -150,6 +159,15 @@ def _validate(self, name, field_name, invalid_patten):
150159
def is_valid_instance_name(self, instance_name):
151160
return bool(PATTERN_INSTANCE_NAME.match(instance_name))
152161

162+
def is_valid_company_name(self, company_name):
163+
return bool(PATTERN_COMPANY_NAME.match(company_name))
164+
165+
def is_valid_auth_id(self, auth_id):
166+
return bool(PATTERN_AUTH_ID.match(auth_id))
167+
168+
def is_valid_auth_key(self, auth_key):
169+
return not bool(PATTERN_AUTH_KEY.search(auth_key))
170+
153171
def validate_device_display_name(self, name):
154172
return self._validate(name, "instance display name",
155173
PATTERN_INVALID_DEVICE_DISPLAY_NAME)

logicmonitor_data_sdk/version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "0.0.1.beta1"

0 commit comments

Comments
 (0)