id
int64 0
843k
| repository_name
stringlengths 7
55
| file_path
stringlengths 9
332
| class_name
stringlengths 3
290
| human_written_code
stringlengths 12
4.36M
| class_skeleton
stringlengths 19
2.2M
| total_program_units
int64 1
9.57k
| total_doc_str
int64 0
4.2k
| AvgCountLine
float64 0
7.89k
| AvgCountLineBlank
float64 0
300
| AvgCountLineCode
float64 0
7.89k
| AvgCountLineComment
float64 0
7.89k
| AvgCyclomatic
float64 0
130
| CommentToCodeRatio
float64 0
176
| CountClassBase
float64 0
48
| CountClassCoupled
float64 0
589
| CountClassCoupledModified
float64 0
581
| CountClassDerived
float64 0
5.37k
| CountDeclInstanceMethod
float64 0
4.2k
| CountDeclInstanceVariable
float64 0
299
| CountDeclMethod
float64 0
4.2k
| CountDeclMethodAll
float64 0
4.2k
| CountLine
float64 1
115k
| CountLineBlank
float64 0
9.01k
| CountLineCode
float64 0
94.4k
| CountLineCodeDecl
float64 0
46.1k
| CountLineCodeExe
float64 0
91.3k
| CountLineComment
float64 0
27k
| CountStmt
float64 1
93.2k
| CountStmtDecl
float64 0
46.1k
| CountStmtExe
float64 0
90.2k
| MaxCyclomatic
float64 0
759
| MaxInheritanceTree
float64 0
16
| MaxNesting
float64 0
34
| SumCyclomatic
float64 0
6k
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2,200 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/tests/unit/foundation/test_fields.py
|
tests.unit.foundation.test_fields.TestDateTimeField
|
class TestDateTimeField(BaseCase):
def test_datetime_object(self):
field = fields.DateTimeField(value=datetime.datetime(2019, 3, 28, 23, 58, 0))
self.assertEqual(field.to_api(), "2019-03-28T23:58:00Z")
self.assertEqual(field.to_literal(), "2019-03-28T23:58:00")
def test_datetime_object_with_tz(self):
field = fields.DateTimeField(value=datetime.datetime(2019, 3, 28, 23, 58, 0, tzinfo=TZ()))
self.assertEqual(field.to_api(), "2019-03-29T01:58:00Z")
self.assertEqual(field.to_literal(), "2019-03-28T23:58:00-02:00")
def test_datetime_string(self):
field = fields.DateTimeField(value="2019-03-28T23:58:00")
self.assertEqual(field.to_api(), "2019-03-28T23:58:00Z")
self.assertEqual(field.to_literal(), "2019-03-28T23:58:00")
def test_datetime_string_with_tz(self):
field = fields.DateTimeField(value="2019-03-28T23:58:00Z")
self.assertEqual(field.to_api(), "2019-03-28T23:58:00Z")
self.assertEqual(field.to_literal(), "2019-03-28T23:58:00+00:00")
def test_datetime_string_with_offset(self):
field = fields.DateTimeField(value="2019-03-28T23:58:00-02:00")
self.assertEqual(field.to_api(), "2019-03-29T01:58:00Z")
self.assertEqual(field.to_literal(), "2019-03-28T23:58:00-02:00")
|
class TestDateTimeField(BaseCase):
def test_datetime_object(self):
pass
def test_datetime_object_with_tz(self):
pass
def test_datetime_string(self):
pass
def test_datetime_string_with_tz(self):
pass
def test_datetime_string_with_offset(self):
pass
| 6 | 0 | 4 | 0 | 4 | 0 | 1 | 0 | 1 | 3 | 2 | 0 | 5 | 0 | 5 | 77 | 25 | 4 | 21 | 11 | 15 | 0 | 21 | 11 | 15 | 1 | 3 | 0 | 5 |
2,201 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/tests/unit/foundation/test_instantiations.py
|
tests.unit.foundation.test_instantiations.TestEquality
|
class TestEquality(BaseCase):
def test_fast(self):
from mbed_cloud.foundation import User
a = User()
b = a
c = 'cat'
self.assertEqual(a, b)
self.assertNotEqual(a, c)
def test_ids(self):
from mbed_cloud.foundation import User
a = User(id='1')
b = User(id='1')
c = User(id='cat')
self.assertEqual(a, b)
self.assertNotEqual(a, c)
def test_values(self):
from mbed_cloud.foundation import User
a = User(full_name='1')
b = User(full_name='1')
c = User(full_name='cat')
self.assertEqual(a, b)
self.assertNotEqual(a, c)
|
class TestEquality(BaseCase):
def test_fast(self):
pass
def test_ids(self):
pass
def test_values(self):
pass
| 4 | 0 | 7 | 0 | 7 | 0 | 1 | 0 | 1 | 1 | 1 | 0 | 3 | 0 | 3 | 75 | 25 | 3 | 22 | 16 | 15 | 0 | 22 | 16 | 15 | 1 | 3 | 0 | 3 |
2,202 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/tests/unit/foundation/test_instantiations.py
|
tests.unit.foundation.test_instantiations.TestExplicitSDK
|
class TestExplicitSDK(TestUserFactory):
# can instantiate models with a client
def get_user(self, **kwargs):
sdk = SDK()
return User(_client=sdk.client, **kwargs)
|
class TestExplicitSDK(TestUserFactory):
def get_user(self, **kwargs):
pass
| 2 | 0 | 3 | 0 | 3 | 0 | 1 | 0.25 | 1 | 1 | 1 | 0 | 1 | 0 | 1 | 76 | 5 | 0 | 4 | 3 | 2 | 1 | 4 | 3 | 2 | 1 | 4 | 0 | 1 |
2,203 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/tests/unit/test_pagination.py
|
tests.unit.test_pagination.ListCompatMixin
|
class ListCompatMixin(object):
def assert_list_compat(self, a, b):
return (
getattr(self, 'assertCountEqual', None) or
getattr(self, 'assertItemsEqual', None) # Python2 compat
)(a, b)
|
class ListCompatMixin(object):
def assert_list_compat(self, a, b):
pass
| 2 | 0 | 5 | 0 | 5 | 1 | 1 | 0.17 | 1 | 0 | 0 | 2 | 1 | 0 | 1 | 1 | 6 | 0 | 6 | 2 | 4 | 1 | 3 | 2 | 1 | 1 | 1 | 0 | 1 |
2,204 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/tests/unit/foundation/test_instantiations.py
|
tests.unit.foundation.test_instantiations.TestImplicitSDK
|
class TestImplicitSDK(TestUserFactory):
# magically uses global SDK instance
def get_user(self, **kwargs):
return User(**kwargs)
|
class TestImplicitSDK(TestUserFactory):
def get_user(self, **kwargs):
pass
| 2 | 0 | 2 | 0 | 2 | 0 | 1 | 0.33 | 1 | 1 | 1 | 0 | 1 | 0 | 1 | 76 | 4 | 0 | 3 | 2 | 1 | 1 | 3 | 2 | 1 | 1 | 4 | 0 | 1 |
2,205 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/tests/unit/foundation/test_instantiations.py
|
tests.unit.foundation.test_instantiations.TestUserLazyExplicit
|
class TestUserLazyExplicit(TestUserFactory):
# can set a client before calling apis
def get_user(self, **kwargs):
sdk = SDK()
u = User(**kwargs)
u._client = sdk.client
return u
|
class TestUserLazyExplicit(TestUserFactory):
def get_user(self, **kwargs):
pass
| 2 | 0 | 5 | 0 | 5 | 0 | 1 | 0.17 | 1 | 1 | 1 | 0 | 1 | 0 | 1 | 76 | 7 | 0 | 6 | 4 | 4 | 1 | 6 | 4 | 4 | 1 | 4 | 0 | 1 |
2,206 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/tests/unit/test_config.py
|
tests.unit.test_config.TempConf
|
class TempConf(object):
def __init__(self, data):
self.data = data
def __enter__(self):
self.temp_dir = tempfile.mkdtemp(prefix='mbed_sdk_test')
temp_path = self.temp_dir + 'conf.json'
with open(temp_path, 'w') as fh:
json.dump(self.data, fh)
os.environ['MBED_CLOUD_SDK_CONFIG'] = temp_path
def __exit__(self, exc_type, exc_val, exc_tb):
shutil.rmtree(self.temp_dir, ignore_errors=True)
os.environ.pop('MBED_CLOUD_SDK_CONFIG', None)
|
class TempConf(object):
def __init__(self, data):
pass
def __enter__(self):
pass
def __exit__(self, exc_type, exc_val, exc_tb):
pass
| 4 | 0 | 4 | 0 | 4 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 3 | 2 | 3 | 3 | 14 | 2 | 12 | 8 | 8 | 0 | 12 | 7 | 8 | 1 | 1 | 1 | 3 |
2,207 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/tests/unit/test_config.py
|
tests.unit.test_config.TestConfigObj
|
class TestConfigObj(BaseCase):
def test_config_default_codegen(self):
# check host default from codegen is set to production
api = EndpointsApi()
self.assertIn('api.us-east-1', api.api_client.configuration.host)
def test_config_set_user_config(self):
# check top-level config setter
key = 'test_key'
config = {'api_key': key}
api = BaseAPI(config)
self.assertIn(key, api.config.get('api_key'))
def test_unicode_config(self):
# host format validation - check trailing slash trimmed
uft8_host = 'http://\xf0\x9f\x8c\x90.example.com/'
if hasattr(str, 'decode'):
# in python2, convert to unicode
uft8_host = uft8_host.decode('utf8')
api = BaseAPI(dict(host=uft8_host))
self.assertEqual('http://\xf0\x9f\x8c\x90.example.com', api.config.get('host'))
def test_config_invalid_host(self):
# regression check - give a sane error for invalid hosts
api = ConnectAPI(dict(api_key='fake_key', host='invalid'))
with mock.patch('urllib3.PoolManager.request') as mocked:
mocked.side_effect = RuntimeError
with self.assertRaises(RuntimeError):
api.list_connected_devices().next()
def test_config_singleton(self):
# check two different api configs don't clobber each other
a = ConnectAPI(dict(api_key='apple'))
b = ConnectAPI(dict(api_key='banana'))
api_key = EndpointsApi
self.assertEqual(a.apis[api_key].api_client.configuration.api_key, {'Authorization': 'apple'})
self.assertEqual(b.apis[api_key].api_client.configuration.api_key, {'Authorization': 'banana'})
def test_logging(self):
q = queue.Queue()
class FakeLogHandler(Handler):
def emit(self, record):
q.put(record)
top_logger = logging.getLogger(mbed_cloud.__name__)
logging.getLogger('mbed_cloud.utils').addHandler(FakeLogHandler(level=logging.DEBUG))
top_logger.setLevel(level=logging.INFO) # enables >'INFO' (but our config should have got there first anyway)
utils.logging_check() # this iterates all log levels, and should include up to 'INFO'
levels_seen = {log.levelname for log in list(q.queue)}
self.assertIn('INFO', levels_seen)
self.assertNotIn('DEBUG', levels_seen)
q.queue.clear()
top_logger.setLevel(level=logging.DEBUG) # explicitly enable >'DEBUG' at top level
utils.logging_check() # this iterates all log levels, and should now include up to 'DEBUG'
levels_seen = {log.levelname for log in list(q.queue)}
self.assertIn('INFO', levels_seen) # check that module-level log config has cascaded
self.assertIn('DEBUG', levels_seen)
|
class TestConfigObj(BaseCase):
def test_config_default_codegen(self):
pass
def test_config_set_user_config(self):
pass
def test_unicode_config(self):
pass
def test_config_invalid_host(self):
pass
def test_config_singleton(self):
pass
def test_logging(self):
pass
class FakeLogHandler(Handler):
def emit(self, record):
pass
| 9 | 0 | 8 | 1 | 7 | 2 | 1 | 0.27 | 1 | 9 | 4 | 0 | 6 | 0 | 6 | 78 | 60 | 9 | 45 | 23 | 36 | 12 | 45 | 22 | 36 | 2 | 3 | 2 | 8 |
2,208 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/tests/unit/test_config.py
|
tests.unit.test_config.TestConfigSources
|
class TestConfigSources(BaseCase):
dummy_key = 'ak_1234567'
dummy_host = 'https://dummy_host_url'
def setUp(self):
self.host = os.environ.pop(configuration.ENVVAR_API_HOST, '')
self.key = os.environ.pop(configuration.ENVVAR_API_KEY, '')
def tearDown(self):
os.environ.setdefault(configuration.ENVVAR_API_HOST, self.host)
os.environ.setdefault(configuration.ENVVAR_API_KEY, self.key)
def test_no_config_file_default(self):
with TempConf(dict(api_key=self.dummy_key)):
# when we get a config object, force it not to look at existing paths (to see what it defaults to)
with mock.patch.object(Config, attribute='paths') as mocked:
mocked.return_value = [os.environ.get("MBED_CLOUD_SDK_CONFIG")]
a = ConnectAPI(dict(api_key=self.dummy_key))
self.assertIn('api.us-east-1', a.apis[EndpointsApi].api_client.configuration.host)
def test_config_file_from_env(self):
# fully define a config at a custom location, and verify it is loaded
with TempConf(dict(api_key=self.dummy_key, host=self.dummy_host)):
c = Config()
self.assertEqual(self.dummy_key, c.get('api_key'))
self.assertIn('dummy_host_url', c['host'])
# verify custom config reaches the internal api
a = ConnectAPI()
self.assertIn(self.dummy_key, str(a.apis[EndpointsApi].api_client.configuration.api_key))
def test_config_from_envvar(self):
# fully define a config at a custom location
# as well as setting config through environment
with TempConf(dict(api_key='not this one', host=self.dummy_host)):
os.environ.setdefault(configuration.ENVVAR_API_KEY, self.dummy_key)
c = Config()
self.assertEqual(self.dummy_key, c.get('api_key'))
self.assertIn('dummy_host_url', c['host'])
# verify custom config reaches the internal api
a = ConnectAPI()
self.assertIn(self.dummy_key, str(a.apis[EndpointsApi].api_client.configuration.api_key))
|
class TestConfigSources(BaseCase):
def setUp(self):
pass
def tearDown(self):
pass
def test_no_config_file_default(self):
pass
def test_config_file_from_env(self):
pass
def test_config_from_envvar(self):
pass
| 6 | 0 | 7 | 1 | 5 | 1 | 1 | 0.2 | 1 | 6 | 4 | 0 | 5 | 2 | 5 | 77 | 44 | 8 | 30 | 16 | 24 | 6 | 30 | 15 | 24 | 1 | 3 | 2 | 5 |
2,209 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/tests/unit/test_connect.py
|
tests.unit.test_connect.TestBase64Encode
|
class TestBase64Encode(BaseCase):
def test_string(self):
self.assertEqual(ConnectAPI._base64_encode("Hello World"), "SGVsbG8gV29ybGQ=")
def test_empty_string(self):
self.assertEqual(ConnectAPI._base64_encode(""), "")
def test_positive_int(self):
self.assertEqual(ConnectAPI._base64_encode(1), "MQ==")
def test_negative_int(self):
self.assertEqual(ConnectAPI._base64_encode(-1), "LTE=")
def test_positive_float(self):
self.assertEqual(ConnectAPI._base64_encode(1.0), "MS4w")
def test_negative_float(self):
self.assertEqual(ConnectAPI._base64_encode(-1.0), "LTEuMA==")
def test_none(self):
self.assertEqual(ConnectAPI._base64_encode(None), "")
|
class TestBase64Encode(BaseCase):
def test_string(self):
pass
def test_empty_string(self):
pass
def test_positive_int(self):
pass
def test_negative_int(self):
pass
def test_positive_float(self):
pass
def test_negative_float(self):
pass
def test_none(self):
pass
| 8 | 0 | 2 | 0 | 2 | 0 | 1 | 0 | 1 | 1 | 1 | 0 | 7 | 0 | 7 | 79 | 21 | 6 | 15 | 8 | 7 | 0 | 15 | 8 | 7 | 1 | 3 | 0 | 7 |
2,210 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/tests/unit/test_filters.py
|
tests.unit.test_filters.TestFilters
|
class TestFilters(BaseCase):
@classmethod
def setUpClass(cls):
cls.api = BaseAPI()
def _run(self, expected, encode=True, **kwargs):
outcome = self.api._verify_filters(kwargs, Device, encode)
self.assertEqual(expected, outcome)
def test_simple_invalid(self):
with self.assertRaises(CloudValueError):
self._run(None, filters=1337)
def test_simple_valid(self):
self._run(
{u'filter': 'created_at__gte=2017-01-01T00%3A00%3A00Z&created_at__lte=2017-12-31T00%3A00%3A00Z'},
filter=simple_filter
)
def test_simple_plural_valid(self):
self._run(
{u'filter': 'created_at__gte=2017-01-01T00%3A00%3A00Z&created_at__lte=2017-12-31T00%3A00%3A00Z'},
# note plural 'filters' phrase
filters=simple_filter
)
def test_noencode(self):
self._run(
{
'vendor_id__eq': 'green', 'deployment__eq': 'yellow', 'deployment__gte': '2017-01-01T00:00:00Z',
'firmware_checksum__eq': None, 'name__eq': False, 'state__eq': True, 'device_execution_mode__gte': 5,
},
filters=many_types_filter,
encode=False
)
def test_encode(self):
this_filter = {'device_class': 'red & "yellow", <green>'}
this_filter.update(many_types_filter)
self._run(
{'filter': (
'deployment=yellow'
'&deployment__gte=2017-01-01T00%3A00%3A00Z'
'&device_class=red+%26+%22yellow%22%2C+%3Cgreen%3E'
'&device_execution_mode__gte=5'
'&firmware_checksum=None'
'&name=False'
'&state=True'
'&vendor_id=green'
)},
filters=this_filter,
encode=True
)
def test_simple_empty(self):
filters = {}
self._run({}, filter=filters)
def test_simple_plural_empty(self):
filters = {}
self._run({}, filters=filters)
def test_empty_with_other_params(self):
# noop for non-filter fields
filters = {}
self._run(dict(sort=5, order=6, other='yes'), filter=filters, sort=5, order=6, other='yes')
def test_simple_unknown_field(self):
filters = {
'nuthing': {'$gte': datetime.datetime(2017, 1, 1),
'$lte': datetime.datetime(2017, 12, 31)
}
}
with self.assertRaises(CloudValueError):
self._run(
{
u'filter': 'nuthing__gte=2017-01-01T00%3A00%3A00Z&nuthing__lte=2017-12-31T00%3A00%3A00Z',
'other_stuff': None
},
filters=filters,
other_stuff=None
)
def test_simple_known_field_remap(self):
# 'alias' -> 'endpoint_name'
filters = {
'alias': {'$eq': 5}
}
self._run({u'filter': 'endpoint_name=5'}, filters=filters)
def test_dont_mutate_my_stuff(self):
# a direct call to the filter generator, checking that the input kwargs dictionary
# is not modified by the call
kwargs = dict(
filters={
'alias': {'$eq': 5}
},
other_thing={
5: [6, 7, 8]
}
)
before = json.dumps(kwargs)
result = self.api._verify_filters(kwargs, Device, True)
self.assertEqual(dict(filter='endpoint_name=5', other_thing={5: [6, 7, 8]}), result)
self.assertEqual(before, json.dumps(kwargs))
def test_custom_fields(self):
filters = {
'custom_attributes': many_types_filter,
'name': 'red & yellow'
}
self.maxDiff = 1e5
self._run({u'filter': (
'custom_attributes__device_execution_mode__gte=5'
'&custom_attributes__firmware_checksum=None'
'&custom_attributes__last_deployment=yellow'
'&custom_attributes__last_deployment__gte=2017-01-01T00%3A00%3A00Z'
'&custom_attributes__name=False'
'&custom_attributes__state=True'
'&custom_attributes__vendor_id=green'
'&name=red+%26+yellow'
),
'other_stuff': 'yes'
}, filters=filters, other_stuff='yes')
|
class TestFilters(BaseCase):
@classmethod
def setUpClass(cls):
pass
def _run(self, expected, encode=True, **kwargs):
pass
def test_simple_invalid(self):
pass
def test_simple_valid(self):
pass
def test_simple_plural_valid(self):
pass
def test_noencode(self):
pass
def test_encode(self):
pass
def test_simple_empty(self):
pass
def test_simple_plural_empty(self):
pass
def test_empty_with_other_params(self):
pass
def test_simple_unknown_field(self):
pass
def test_simple_known_field_remap(self):
pass
def test_dont_mutate_my_stuff(self):
pass
def test_custom_fields(self):
pass
| 16 | 0 | 8 | 0 | 7 | 0 | 1 | 0.05 | 1 | 5 | 3 | 0 | 13 | 1 | 14 | 86 | 125 | 14 | 106 | 28 | 90 | 5 | 45 | 27 | 30 | 1 | 3 | 1 | 14 |
2,211 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/tests/unit/test_http_requests.py
|
tests.unit.test_http_requests.RequestCallException
|
class RequestCallException(Exception):
"""Derived an exception so an explicitly defined exception can be caught."""
pass
|
class RequestCallException(Exception):
'''Derived an exception so an explicitly defined exception can be caught.'''
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0.5 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 10 | 3 | 0 | 2 | 1 | 1 | 1 | 2 | 1 | 1 | 0 | 3 | 0 | 0 |
2,212 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/tests/unit/test_http_requests.py
|
tests.unit.test_http_requests.TestUserAgent
|
class TestUserAgent(BaseCase):
"""Test a User-Agent HTTP header is set for the SDK.
Pick one method of each API to check header is as expected.
"""
def setUp(self):
"""Setup mocks for testing with urlib3."""
patcher = patch.object(urllib3.PoolManager, 'request')
self.addCleanup(patcher.stop)
self.mocked_pool_manager = patcher.start()
# Create a side effect of raising a known exception when 'request' is
# called. This avoids mocking all the properties of the object returned
# by the call to 'request' which are accessed by the calling code.
self.mocked_pool_manager.side_effect = RequestCallException()
def check_user_agent(self, list_method):
"""Issue a GET request and check contents of User-Agent HTTP header.
:param PaginatedResponse list_method: An API list method
"""
# Attempt to get the first item from the paginated response which will
# call 'urllib3.PoolManager.request'.
try:
list_method.first()
except RequestCallException:
pass
# Retrieve header from call arguments and check User-Agent header is set.
user_agent = self.mocked_pool_manager.call_args[1]['headers'].get('User-Agent')
self.assertIsNotNone(user_agent, "User-Agent header missing")
# Check User-Agent header, it should look something like:
# "mbed-cloud-sdk-python/1.2.6.850 (Darwin-17.4.0-x86_64-i386-64bit) Python/3.6.3"
self.assertRegexpMatches(
user_agent,
r"^mbed-cloud-sdk-python/\d+\.\d+\.\d+\.?\w* \(\S*\) Python/\d+\.\d+\.\d+$",
"User-Agent does not have the expected format")
def test_account_management_api(self):
self.check_user_agent(mbed_cloud.AccountManagementAPI().list_api_keys())
def test_certificates_api(self):
self.check_user_agent(mbed_cloud.CertificatesAPI().list_certificates())
def test_connect_api(self):
self.check_user_agent(mbed_cloud.ConnectAPI().list_connected_devices())
def test_device_directory_api(self):
self.check_user_agent(mbed_cloud.DeviceDirectoryAPI().list_devices())
def test_enrollment_api(self):
self.check_user_agent(mbed_cloud.EnrollmentAPI().list_enrollment_claims())
def test_update_api(self):
self.check_user_agent(mbed_cloud.UpdateAPI().list_campaigns())
|
class TestUserAgent(BaseCase):
'''Test a User-Agent HTTP header is set for the SDK.
Pick one method of each API to check header is as expected.
'''
def setUp(self):
'''Setup mocks for testing with urlib3.'''
pass
def check_user_agent(self, list_method):
'''Issue a GET request and check contents of User-Agent HTTP header.
:param PaginatedResponse list_method: An API list method
'''
pass
def test_account_management_api(self):
pass
def test_certificates_api(self):
pass
def test_connect_api(self):
pass
def test_device_directory_api(self):
pass
def test_enrollment_api(self):
pass
def test_update_api(self):
pass
| 9 | 3 | 5 | 0 | 4 | 2 | 1 | 0.52 | 1 | 8 | 7 | 0 | 8 | 1 | 8 | 80 | 56 | 12 | 29 | 12 | 20 | 15 | 26 | 12 | 17 | 2 | 3 | 1 | 9 |
2,213 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/tests/unit/test_metadata.py
|
tests.unit.test_metadata.TestFilters
|
class TestFilters(BaseCase):
"""Check filters"""
@classmethod
def setUpClass(cls):
cls.api = DeviceDirectoryAPI()
with mock.patch('urllib3.PoolManager.request') as mocked:
mocked.return_value = mock.MagicMock()
mocked.return_value.status = 200
mocked.return_value.data = '{"data":[{"a":1}]}'.encode()
cls.devices = cls.api.list_devices(filter=dict(state='registered')).next()
def test_meta(self):
# exercise all the getters for metadata objects
meta = self.api.get_last_api_metadata()
props = (
'url',
'method',
'status_code',
'date',
'headers',
'request_id',
'error_message',
)
parts = {prop: getattr(meta, prop, None) for prop in props}
self.assertEqual(parts['method'], 'GET')
self.assertIn('200', repr(meta))
as_dict = meta.to_dict()
for prop in props:
self.assertIn(prop, as_dict)
def test_meta_exception(self):
# check what happens if an exception is passed to the metadata object
msg = 'just a test'
exception = Exception(msg)
exception.status = 5
exception.body = 'the body'
meta = ApiMetadata('http://not.real', 'GET', exception=exception)
self.assertEqual(meta.error_message, msg)
|
class TestFilters(BaseCase):
'''Check filters'''
@classmethod
def setUpClass(cls):
pass
def test_meta(self):
pass
def test_meta_exception(self):
pass
| 5 | 1 | 11 | 0 | 10 | 1 | 1 | 0.09 | 1 | 4 | 2 | 0 | 2 | 0 | 3 | 75 | 39 | 3 | 33 | 13 | 28 | 3 | 24 | 11 | 20 | 2 | 3 | 1 | 4 |
2,214 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/tests/unit/test_metrics.py
|
tests.unit.test_metrics.TestMetrics
|
class TestMetrics(BaseCase):
@classmethod
def setUpClass(cls):
cls.api = ConnectAPI()
# some arbitrary period
cls.metrics = cls.api.list_metrics(
start=start,
end=end,
)
def test_verify_arguments(self):
kwargs = dict(irrelevant=5)
with self.assertRaises(CloudValueError) as e:
self.api._verify_arguments(interval='1d', kwargs=kwargs)
self.assertIn('period is not specified', e.exception.message)
def test_verify_arguments_interval_invalid(self):
kwargs = dict(period='3h')
with self.assertRaises(CloudValueError) as e:
self.api._verify_arguments(interval='1dog', kwargs=kwargs)
self.assertIn('interval is incorrect', e.exception.message)
def test_verify_arguments_period(self):
kwargs = dict(period='3h')
self.api._verify_arguments(interval='1d', kwargs=kwargs)
self.assertEqual({'period': '3h'}, kwargs)
def test_verify_arguments_period_invalid(self):
kwargs = dict(period='3horses')
with self.assertRaises(CloudValueError) as e:
self.api._verify_arguments(interval='1d', kwargs=kwargs)
self.assertIn('period is incorrect', e.exception.message)
def test_verify_arguments_start(self):
kwargs = dict(period=5, start=start)
with self.assertRaises(CloudValueError) as e:
self.api._verify_arguments(interval='1d', kwargs=kwargs)
self.assertIn('end is required', e.exception.message)
def test_verify_arguments_end(self):
kwargs = dict(period=5, end=end)
with self.assertRaises(CloudValueError) as e:
self.api._verify_arguments(interval='1d', kwargs=kwargs)
self.assertIn('start is required', e.exception.message)
def test_metrics(self):
props = Metric._get_attributes_map()
inverse_props = {v: k for k, v in props.items()}
a_metric = Metric(inverse_props)
parts = {prop: getattr(a_metric, prop) for prop in props}
self.assertEqual(parts['successful_bootstraps'], 'successful_bootstraps')
def test_metrics_map_include(self):
included = Metric._map_includes(['handshakes'])
self.assertEqual('handshakes_successful', included)
|
class TestMetrics(BaseCase):
@classmethod
def setUpClass(cls):
pass
def test_verify_arguments(self):
pass
def test_verify_arguments_interval_invalid(self):
pass
def test_verify_arguments_period(self):
pass
def test_verify_arguments_period_invalid(self):
pass
def test_verify_arguments_start(self):
pass
def test_verify_arguments_end(self):
pass
def test_metrics(self):
pass
def test_metrics_map_include(self):
pass
| 11 | 0 | 5 | 0 | 5 | 0 | 1 | 0.02 | 1 | 3 | 2 | 0 | 8 | 0 | 9 | 81 | 56 | 9 | 46 | 27 | 35 | 1 | 42 | 21 | 32 | 1 | 3 | 1 | 9 |
2,215 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/tests/unit/test_notifications.py
|
tests.unit.test_notifications.Test
|
class Test(BaseCase):
def test_autostart_enabled(self):
with mock.patch('urllib3.PoolManager.request') as mocked:
mocked.return_value = mock.MagicMock()
mocked.return_value.data = b''
mocked.return_value.status = 200
a = ConnectAPI(dict(autostart_notification_thread=True))
self.assertFalse(a.has_active_notification_thread)
a.get_resource_value_async('abc123', '/3/4/5')
self.assertTrue(a.has_active_notification_thread)
a.stop_notifications()
def test_autostart_disabled(self):
with mock.patch('urllib3.PoolManager.request') as mocked:
mocked.return_value = mock.MagicMock()
mocked.return_value.data = b''
mocked.return_value.status = 200
a = ConnectAPI(dict(autostart_notification_thread=False))
self.assertFalse(a.has_active_notification_thread)
a.get_resource_value_async('abc123', '/3/4/5')
self.assertFalse(a.has_active_notification_thread)
a.stop_notifications()
|
class Test(BaseCase):
def test_autostart_enabled(self):
pass
def test_autostart_disabled(self):
pass
| 3 | 0 | 10 | 0 | 10 | 0 | 1 | 0 | 1 | 2 | 1 | 0 | 2 | 0 | 2 | 74 | 22 | 1 | 21 | 7 | 18 | 0 | 21 | 5 | 18 | 1 | 3 | 1 | 2 |
2,216 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/tests/unit/foundation/test_instantiations.py
|
tests.unit.foundation.test_instantiations.TestUserFactory
|
class TestUserFactory(BaseCase):
def get_user(self, **kwargs):
sdk = SDK()
return sdk.foundation.user(**kwargs)
def test_attr(self):
user = self.get_user()
self.assertIsNone(user.phone_number)
def test_attr_set(self):
user = self.get_user(id='1')
self.assertEqual(user.id, '1')
|
class TestUserFactory(BaseCase):
def get_user(self, **kwargs):
pass
def test_attr(self):
pass
def test_attr_set(self):
pass
| 4 | 0 | 3 | 0 | 3 | 0 | 1 | 0 | 1 | 0 | 0 | 3 | 3 | 0 | 3 | 75 | 13 | 3 | 10 | 7 | 6 | 0 | 10 | 7 | 6 | 1 | 3 | 0 | 3 |
2,217 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/branding/enums.py
|
mbed_cloud.foundation.entities.branding.enums.DarkThemeColorReferenceEnum
|
class DarkThemeColorReferenceEnum(BaseEnum):
"""Represents expected values of `DarkThemeColorReferenceEnum`
This is used by Entities in the "branding" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
"""
CANVAS_BACKGROUND = "canvas_background"
CANVAS_BACKGROUND_FONT_COLOR = "canvas_background_font_color"
ERROR_COLOR = "error_color"
ERROR_FONT_COLOR = "error_font_color"
INFO_COLOR = "info_color"
INFO_FONT_COLOR = "info_font_color"
PRIMARY = "primary"
PRIMARY_FONT_COLOR = "primary_font_color"
SECONDARY = "secondary"
SECONDARY_FONT_COLOR = "secondary_font_color"
SUCCESS_COLOR = "success_color"
SUCCESS_FONT_COLOR = "success_font_color"
WARNING_COLOR = "warning_color"
WARNING_FONT_COLOR = "warning_font_color"
WORKSPACE_BACKGROUND = "workspace_background"
WORKSPACE_BACKGROUND_FONT_COLOR = "workspace_background_font_color"
values = frozenset(
(
"canvas_background",
"canvas_background_font_color",
"error_color",
"error_font_color",
"info_color",
"info_font_color",
"primary",
"primary_font_color",
"secondary",
"secondary_font_color",
"success_color",
"success_font_color",
"warning_color",
"warning_font_color",
"workspace_background",
"workspace_background_font_color",
)
)
|
class DarkThemeColorReferenceEnum(BaseEnum):
'''Represents expected values of `DarkThemeColorReferenceEnum`
This is used by Entities in the "branding" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
'''
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0.16 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 47 | 4 | 37 | 18 | 36 | 6 | 18 | 18 | 17 | 0 | 2 | 0 | 0 |
2,218 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/exceptions.py
|
mbed_cloud.exceptions.CloudTimeoutError
|
class CloudTimeoutError(CloudApiException):
"""Thrown when running in synchronized/blocking mode, and the request times out."""
def __init__(self, message, reason=None, status=0):
"""Initialize CloudApiException class"""
super(CloudTimeoutError, self).__init__(message, reason=reason, status=status)
def __str__(self):
"""Print the exception"""
return self.message
|
class CloudTimeoutError(CloudApiException):
'''Thrown when running in synchronized/blocking mode, and the request times out.'''
def __init__(self, message, reason=None, status=0):
'''Initialize CloudApiException class'''
pass
def __str__(self):
'''Print the exception'''
pass
| 3 | 3 | 3 | 0 | 2 | 1 | 1 | 0.6 | 1 | 1 | 0 | 0 | 2 | 0 | 2 | 14 | 10 | 2 | 5 | 3 | 2 | 3 | 5 | 3 | 2 | 1 | 4 | 0 | 2 |
2,219 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/branding/dark_theme_color.py
|
mbed_cloud.foundation.entities.branding.dark_theme_color.DarkThemeColor
|
class DarkThemeColor(Entity):
"""Represents the `DarkThemeColor` entity in Pelion Device Management"""
# List of fields that are serialised between the API and SDK
_api_fieldnames = ["color", "reference", "updated_at"]
# List of fields that are available for the user of the SDK
_sdk_fieldnames = _api_fieldnames
# Renames to be performed by the SDK when receiving data {<API Field Name>: <SDK Field Name>}
_renames = {}
# Renames to be performed by the SDK when sending data {<SDK Field Name>: <API Field Name>}
_renames_to_api = {}
def __init__(self, _client=None, color=None, reference=None, updated_at=None):
"""Creates a local `DarkThemeColor` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param color: The color given as name (purple) or as a hex code.
:type color: str
:param reference: Color name.
:type reference: str
:param updated_at: Last update time in UTC.
:type updated_at: datetime
"""
super().__init__(_client=_client)
# inline imports for avoiding circular references and bulk imports
# fields
self._color = fields.StringField(value=color)
self._reference = fields.StringField(value=reference, enum=enums.DarkThemeColorReferenceEnum)
self._updated_at = fields.DateTimeField(value=updated_at)
@property
def color(self):
"""The color given as name (purple) or as a hex code.
api example: '#f3f93e'
:rtype: str
"""
return self._color.value
@color.setter
def color(self, value):
"""Set value of `color`
:param value: value to set
:type value: str
"""
self._color.set(value)
@property
def reference(self):
"""Color name.
:rtype: str
"""
return self._reference.value
@reference.setter
def reference(self, value):
"""Set value of `reference`
:param value: value to set
:type value: str
"""
self._reference.set(value)
@property
def updated_at(self):
"""Last update time in UTC.
api example: '2018-02-14T15:24:14Z'
:rtype: datetime
"""
return self._updated_at.value
def delete(self):
"""Reset branding color to default.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/branding-colors/dark/{reference}>`_.
:rtype:
"""
return self._client.call_api(
method="delete",
path="/v3/branding-colors/dark/{reference}",
content_type="application/json",
path_params={"reference": self._reference.to_api()},
unpack=self,
)
def list(self, filter=None, order=None, max_results=None, page_size=None, include=None):
"""Get dark theme branding colors.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/branding-colors/dark>`_.
:param filter: Filtering when listing entities is not supported by the API for this
entity.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: The order of the records based on creation time, ASC or DESC. Default
value is ASC
:type order: str
:param max_results: Total maximum number of results to retrieve
:type max_results: int
:param page_size: The number of results to return for each page.
:type page_size: int
:param include: Comma separated additional data to return.
:type include: str
:return: An iterator object which yields instances of an entity.
:rtype: mbed_cloud.pagination.PaginatedResponse(DarkThemeColor)
"""
from mbed_cloud.foundation._custom_methods import paginate
from mbed_cloud.foundation import DarkThemeColor
from mbed_cloud import ApiFilter
# Be permissive and accept an instance of a dictionary as this was how the Legacy interface worked.
if isinstance(filter, dict):
filter = ApiFilter(filter_definition=filter, field_renames=DarkThemeColor._renames_to_api)
# The preferred method is an ApiFilter instance as this should be easier to use.
elif isinstance(filter, ApiFilter):
# If filter renames have not be defined then configure the ApiFilter so that any renames
# performed by the SDK are reversed when the query parameters are created.
if filter.field_renames is None:
filter.field_renames = DarkThemeColor._renames_to_api
elif filter is not None:
raise TypeError("The 'filter' parameter may be either 'dict' or 'ApiFilter'.")
return paginate(
self=self,
foreign_key=DarkThemeColor,
filter=filter,
order=order,
max_results=max_results,
page_size=page_size,
include=include,
wraps=self._paginate_list,
)
def _paginate_list(self, after=None, filter=None, order=None, limit=None, include=None):
"""Get dark theme branding colors.
:param after: Not supported by the API.
:type after: str
:param filter: Optional API filter for listing resources.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Not supported by the API.
:type order: str
:param limit: Not supported by the API.
:type limit: int
:param include: Not supported by the API.
:type include: str
:rtype: mbed_cloud.pagination.PaginatedResponse
"""
# Filter query parameters
query_params = filter.to_api() if filter else {}
# Add in other query parameters
return self._client.call_api(
method="get", path="/v3/branding-colors/dark", content_type="application/json", unpack=False
)
def read(self):
"""Get dark theme branding color.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/branding-colors/dark/{reference}>`_.
:rtype: DarkThemeColor
"""
return self._client.call_api(
method="get",
path="/v3/branding-colors/dark/{reference}",
content_type="application/json",
path_params={"reference": self._reference.to_api()},
unpack=self,
)
def update(self):
"""Updates a dark theme branding color.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/branding-colors/dark/{reference}>`_.
:rtype: DarkThemeColor
"""
# Conditionally setup the message body, fields which have not been set will not be sent to the API.
# This avoids null fields being rejected and allows the default value to be used.
body_params = {}
if self._color.value_set:
body_params["color"] = self._color.to_api()
if self._updated_at.value_set:
body_params["updated_at"] = self._updated_at.to_api()
return self._client.call_api(
method="put",
path="/v3/branding-colors/dark/{reference}",
content_type="application/json",
body_params=body_params,
path_params={"reference": self._reference.to_api()},
unpack=self,
)
|
class DarkThemeColor(Entity):
'''Represents the `DarkThemeColor` entity in Pelion Device Management'''
def __init__(self, _client=None, color=None, reference=None, updated_at=None):
'''Creates a local `DarkThemeColor` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param color: The color given as name (purple) or as a hex code.
:type color: str
:param reference: Color name.
:type reference: str
:param updated_at: Last update time in UTC.
:type updated_at: datetime
'''
pass
@property
def color(self):
'''The color given as name (purple) or as a hex code.
api example: '#f3f93e'
:rtype: str
'''
pass
@color.setter
def color(self):
'''Set value of `color`
:param value: value to set
:type value: str
'''
pass
@property
def reference(self):
'''Color name.
:rtype: str
'''
pass
@reference.setter
def reference(self):
'''Set value of `reference`
:param value: value to set
:type value: str
'''
pass
@property
def updated_at(self):
'''Last update time in UTC.
api example: '2018-02-14T15:24:14Z'
:rtype: datetime
'''
pass
def delete(self):
'''Reset branding color to default.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/branding-colors/dark/{reference}>`_.
:rtype:
'''
pass
def list(self, filter=None, order=None, max_results=None, page_size=None, include=None):
'''Get dark theme branding colors.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/branding-colors/dark>`_.
:param filter: Filtering when listing entities is not supported by the API for this
entity.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: The order of the records based on creation time, ASC or DESC. Default
value is ASC
:type order: str
:param max_results: Total maximum number of results to retrieve
:type max_results: int
:param page_size: The number of results to return for each page.
:type page_size: int
:param include: Comma separated additional data to return.
:type include: str
:return: An iterator object which yields instances of an entity.
:rtype: mbed_cloud.pagination.PaginatedResponse(DarkThemeColor)
'''
pass
def _paginate_list(self, after=None, filter=None, order=None, limit=None, include=None):
'''Get dark theme branding colors.
:param after: Not supported by the API.
:type after: str
:param filter: Optional API filter for listing resources.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Not supported by the API.
:type order: str
:param limit: Not supported by the API.
:type limit: int
:param include: Not supported by the API.
:type include: str
:rtype: mbed_cloud.pagination.PaginatedResponse
'''
pass
def read(self):
'''Get dark theme branding color.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/branding-colors/dark/{reference}>`_.
:rtype: DarkThemeColor
'''
pass
def updated_at(self):
'''Updates a dark theme branding color.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/branding-colors/dark/{reference}>`_.
:rtype: DarkThemeColor
'''
pass
| 17 | 12 | 18 | 4 | 6 | 8 | 2 | 1.1 | 1 | 7 | 4 | 0 | 11 | 3 | 11 | 22 | 231 | 61 | 81 | 29 | 61 | 89 | 44 | 24 | 29 | 5 | 2 | 2 | 18 |
2,220 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/common/fields.py
|
mbed_cloud.foundation.common.fields.FileField
|
class FileField(Field):
"""A file object
nb. potential to provide some overloaded behaviours here
e.g. use a stream/file object, otherwise if user provides a string,
we can either open that as a file if it exists,
or, finally, treat it as raw data to pass in (StringIO)
"""
base_type = BufferedIOBase
|
class FileField(Field):
'''A file object
nb. potential to provide some overloaded behaviours here
e.g. use a stream/file object, otherwise if user provides a string,
we can either open that as a file if it exists,
or, finally, treat it as raw data to pass in (StringIO)
'''
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 3 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 8 | 10 | 2 | 2 | 2 | 1 | 6 | 2 | 2 | 1 | 0 | 2 | 0 | 0 |
2,221 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/common/fields.py
|
mbed_cloud.foundation.common.fields.Field
|
class Field(object):
base_type = None
def __init__(self, value, enum=None, entity=None):
self._val = None
self._enum = enum
self._entity = entity
self.value_set = False
# Work out the valid valid types that the set method can use
if self._entity:
self._valid_types = (self.base_type, self._entity, type(None))
else:
self._valid_types = (self.base_type, type(None))
self.set(value)
# If the initial value provided was not None and was accepted then flag that the value has been set.
if self._val is None:
self.value_set = False
@property
def value(self):
return self._val
def set(self, value):
if not isinstance(value, self._valid_types):
raise TypeError("%r is not one of the valid types %s" % (value, self._valid_types))
if value is not None and self._enum and value not in self._enum.values:
LOG.warning("Unknown enum value '%s' received from API for %s", value, self._enum)
self._val = value
self.value_set = True
return self
def to_literal(self):
return self.value
def to_api(self):
return self.value.to_api() if self.value and self._entity else self.value
def from_api(self, value):
if value and self._entity:
new_entity = self._entity().from_api(**value)
return self.set(new_entity)
else:
return self.set(value)
def from_literal(self, value):
return self.set(self._entity().from_literal(**value)) if value and self._entity else self.set(value)
def to_query_param(self):
"""Generate a format which is appropriate to representing a a query param
Note: This will not URL encode as this will be performed by the `requests` library
"""
return json.dumps(self.value) if self.value is None else self.to_api()
|
class Field(object):
def __init__(self, value, enum=None, entity=None):
pass
@property
def value(self):
pass
def set(self, value):
pass
def to_literal(self):
pass
def to_api(self):
pass
def from_api(self, value):
pass
def from_literal(self, value):
pass
def to_query_param(self):
'''Generate a format which is appropriate to representing a a query param
Note: This will not URL encode as this will be performed by the `requests` library
'''
pass
| 10 | 1 | 6 | 1 | 5 | 1 | 2 | 0.13 | 1 | 2 | 0 | 9 | 8 | 5 | 8 | 8 | 56 | 12 | 39 | 17 | 29 | 5 | 36 | 16 | 27 | 3 | 1 | 1 | 16 |
2,222 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/common/fields.py
|
mbed_cloud.foundation.common.fields.DictField
|
class DictField(Field):
base_type = dict
def to_query_param(self):
"""Generate a format which is appropriate to representing a a query param
Note: This will not URL encode as this will be performed by the `requests` library
"""
return json.dumps(self.value)
def set(self, value):
"""Handle entities being provided as dictionaries."""
# If this is an entity field, the type is valid then handle being given a value which is not an entity
if self._entity and isinstance(value, self._valid_types) and not isinstance(value, self._entity):
# Pass the dict to the entity as kwargs for create a blank entity if the value is None
new_entity = self._entity(**value) if value else self._entity()
return super().set(new_entity)
# Revert to default behaviour if not handling an entity
return super().set(value)
|
class DictField(Field):
def to_query_param(self):
'''Generate a format which is appropriate to representing a a query param
Note: This will not URL encode as this will be performed by the `requests` library
'''
pass
def set(self, value):
'''Handle entities being provided as dictionaries.'''
pass
| 3 | 2 | 8 | 1 | 4 | 4 | 2 | 0.78 | 1 | 1 | 0 | 0 | 2 | 0 | 2 | 10 | 19 | 3 | 9 | 5 | 6 | 7 | 9 | 5 | 6 | 3 | 2 | 1 | 4 |
2,223 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/common/fields.py
|
mbed_cloud.foundation.common.fields.DateTimeField
|
class DateTimeField(Field):
base_type = datetime
def set(self, value):
"""Set the date/time using a datetime object or a date/time like string."""
if isinstance(value, six.string_types):
# Use dateutil.parser to accept various input
self._val = parse(value)
self.value_set = True
else:
return super().set(value)
return self
def to_literal(self):
return self.value.isoformat() if self.value else None
def to_api(self):
if self.value:
if self.value.tzinfo:
# Convert to UTC timezone and clear the timezone so isoformat renders with offset
naive_datetime = self.value.astimezone(pytz.utc).replace(tzinfo=None)
else:
naive_datetime = self.value
# Render date, manually appending `Z` UTC indicator
return naive_datetime.isoformat() + "Z"
else:
return None
def from_api(self, value):
return self.set(value)
from_literal = from_api
|
class DateTimeField(Field):
def set(self, value):
'''Set the date/time using a datetime object or a date/time like string.'''
pass
def to_literal(self):
pass
def to_api(self):
pass
def from_api(self, value):
pass
| 5 | 1 | 6 | 0 | 5 | 1 | 2 | 0.17 | 1 | 1 | 0 | 1 | 4 | 2 | 4 | 12 | 32 | 5 | 23 | 10 | 18 | 4 | 20 | 10 | 15 | 3 | 2 | 2 | 8 |
2,224 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/common/fields.py
|
mbed_cloud.foundation.common.fields.DateField
|
class DateField(DateTimeField):
base_type = date
def to_api(self):
# ISO dates do not have a trailing Z
return self.value.isoformat() if self.value else None
def set(self, value):
"""Set the date using a date object or a date/time like string."""
super().set(value)
# Use dateutil.parser to accept various input if a string is passed in but then convert to a date object
if isinstance(self._val, datetime):
self._val = self._val.date()
self.value_set = True
return self
|
class DateField(DateTimeField):
def to_api(self):
pass
def set(self, value):
'''Set the date using a date object or a date/time like string.'''
pass
| 3 | 1 | 6 | 0 | 4 | 2 | 2 | 0.3 | 1 | 2 | 0 | 0 | 2 | 2 | 2 | 14 | 15 | 2 | 10 | 6 | 7 | 3 | 10 | 6 | 7 | 2 | 3 | 1 | 4 |
2,225 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/common/fields.py
|
mbed_cloud.foundation.common.fields.BooleanField
|
class BooleanField(Field):
base_type = bool
def to_query_param(self):
"""Generate a format which is appropriate to representing a a query param
Note: This will not URL encode as this will be performed by the `requests` library
"""
return json.dumps(self.value)
|
class BooleanField(Field):
def to_query_param(self):
'''Generate a format which is appropriate to representing a a query param
Note: This will not URL encode as this will be performed by the `requests` library
'''
pass
| 2 | 1 | 6 | 1 | 2 | 3 | 1 | 0.75 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 9 | 9 | 2 | 4 | 3 | 2 | 3 | 4 | 3 | 2 | 1 | 2 | 0 | 1 |
2,226 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/common/fields.py
|
mbed_cloud.foundation.common.fields.BinaryField
|
class BinaryField(Field):
# Python 2 and 3 compatible binary type
base_type = six.binary_type
|
class BinaryField(Field):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0.5 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 8 | 3 | 0 | 2 | 2 | 1 | 1 | 2 | 2 | 1 | 0 | 2 | 0 | 0 |
2,227 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/common/enum_base.py
|
mbed_cloud.foundation.common.enum_base.BaseEnum
|
class BaseEnum(object):
values = frozenset()
def __setattr__(self, name, value):
raise Exception("enum container values cannot be modified")
|
class BaseEnum(object):
def __setattr__(self, name, value):
pass
| 2 | 0 | 2 | 0 | 2 | 0 | 1 | 0 | 1 | 1 | 0 | 41 | 1 | 0 | 1 | 1 | 5 | 1 | 4 | 3 | 2 | 0 | 4 | 3 | 2 | 1 | 1 | 0 | 1 |
2,228 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/common/entity_base.py
|
mbed_cloud.foundation.common.entity_base.Entity
|
class Entity(object):
"""Base Class for Foundation Entities"""
# List of fields that are serialised between the API and SDK
_sdk_fieldnames = []
# List of fields that are available for the user of the SDK
_api_fieldnames = []
# Renames to be performed by the SDK when receiving data {<API Field Name>: <SDK Field Name>}
_renames = {}
# Renames to be performed by the SDK when sending data {<SDK Field Name>: <API Field Name>}
_renames_to_api = {}
def __init__(self, _client, **kwargs):
"""Create a new Entity
:param client:
:type client: Client
:param kwargs:
"""
if _client is None:
from mbed_cloud.sdk.sdk import get_or_create_global_sdk_instance
_client = get_or_create_global_sdk_instance().client
self._client = _client
self._logger = self._client.config.logger.getChild(self.__class__.__name__)
def __str__(self):
"""Human readable short format text"""
entity_id = getattr(self, "id", None)
entity_id = entity_id if entity_id else "?"
return "<%s %s>" % (self.__class__.__name__, entity_id)
def __repr__(self):
"""Long format text (object might be re-instantiatable from this)"""
return repr(self.to_dict())
def _repr_pretty_(self, p, cycle):
"""Defining repr_pretty helps control output in IPython:
https://ipython.readthedocs.io/en/stable/api/generated/IPython.lib.pretty.html
"""
p.text(str(self))
def __eq__(self, other):
"""Equality comparison"""
# TODO: 'primary key' behaviour
return (
# very fast - they are the same instance
(self is other)
or
# fast - they are at least the same class
isinstance(other, self.__class__)
and (
# pretty fast - they have the same id [state may be different though ...]
(getattr(self, "id", None) is not None and getattr(self, "id", None) == getattr(other, "id", None))
or
# much slower - deep comparison of dictionaries
(
getattr(self, "id", None) is None
and getattr(other, "id", None) is None
and self.to_dict() == other.to_dict()
)
)
)
def to_literal(self):
"""Return all fields from object in a format suitable for serialisation"""
return {field: getattr(self, "_" + field).to_literal() for field in self._sdk_fieldnames}
def to_dict(self):
"""Return all fields as key-value pairs"""
return {field: getattr(self, field) for field in self._sdk_fieldnames}
def to_api(self):
"""Return all fields in API format"""
body_params = {}
for sdk_field in self._api_fieldnames:
api_fieldname = self._renames.get(sdk_field, sdk_field)
if getattr(self, "_" + sdk_field).value_set:
body_params[api_fieldname] = getattr(self, "_" + sdk_field).to_api()
return body_params
def from_literal(self, **kwargs):
"""Load values into object from pure literals"""
for field_name, value in kwargs.items():
field = getattr(self, "_" + field_name, None)
try:
field and field.from_literal(value)
except Exception:
# we don't care why loading the field fails. maybe it's bad data? log it.
self._logger.exception("unable to deserialise literal field: %s %s %s", self, field_name, value)
return self
def from_dict(self, *args, **kwargs):
"""Load values into object from a dictionary
Equivalent to a dictionary update method
Ignores unknown keys
"""
for arg in args:
self.from_dict(**arg)
for field_name, value in kwargs.items():
field = getattr(self, "_" + field_name, None)
if isinstance(field, fields.Field):
field.set(value)
return self
def from_api(self, **kwargs):
"""Load values into object from an API response"""
for api_field_name, value in kwargs.items():
field = getattr(self, "_" + self._renames.get(api_field_name, api_field_name), None)
try:
field and field.from_api(value)
except Exception: # noqa
# we don't care why loading the field fails. maybe the API changed? log it.
self._logger.exception("unable to deserialise received field: %s %s %r", self, api_field_name, value)
return self
|
class Entity(object):
'''Base Class for Foundation Entities'''
def __init__(self, _client, **kwargs):
'''Create a new Entity
:param client:
:type client: Client
:param kwargs:
'''
pass
def __str__(self):
'''Human readable short format text'''
pass
def __repr__(self):
'''Long format text (object might be re-instantiatable from this)'''
pass
def _repr_pretty_(self, p, cycle):
'''Defining repr_pretty helps control output in IPython:
https://ipython.readthedocs.io/en/stable/api/generated/IPython.lib.pretty.html
'''
pass
def __eq__(self, other):
'''Equality comparison'''
pass
def to_literal(self):
'''Return all fields from object in a format suitable for serialisation'''
pass
def to_dict(self):
'''Return all fields as key-value pairs'''
pass
def to_api(self):
'''Return all fields in API format'''
pass
def from_literal(self, **kwargs):
'''Load values into object from pure literals'''
pass
def from_dict(self, *args, **kwargs):
'''Load values into object from a dictionary
Equivalent to a dictionary update method
Ignores unknown keys
'''
pass
def from_api(self, **kwargs):
'''Load values into object from an API response'''
pass
| 12 | 12 | 9 | 0 | 6 | 3 | 2 | 0.48 | 1 | 3 | 1 | 44 | 11 | 2 | 11 | 11 | 120 | 19 | 69 | 30 | 56 | 33 | 56 | 30 | 43 | 4 | 1 | 2 | 22 |
2,229 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/filters.py
|
mbed_cloud.filters.OP
|
class OP: # noqa
"""Filter Operators"""
NE = 'ne'
EQ = 'eq'
GTE = 'gte'
LTE = 'lte'
NIN = 'nin'
IN = 'in'
|
class OP:
'''Filter Operators'''
pass
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0.29 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 9 | 1 | 7 | 7 | 6 | 2 | 7 | 7 | 6 | 0 | 0 | 0 | 0 |
2,230 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/exceptions.py
|
mbed_cloud.exceptions.CloudValueError
|
class CloudValueError(CloudApiException):
"""Common exception thrown when ApiException is raised from backend API.
CloudApiException typically means that something went wrong in communicating
with the cloud API. This can be authentication errors, connectivity issues
or invalid usage of the API.
"""
pass
|
class CloudValueError(CloudApiException):
'''Common exception thrown when ApiException is raised from backend API.
CloudApiException typically means that something went wrong in communicating
with the cloud API. This can be authentication errors, connectivity issues
or invalid usage of the API.
'''
pass
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 2.5 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 12 | 9 | 2 | 2 | 1 | 1 | 5 | 2 | 1 | 1 | 0 | 4 | 0 | 0 |
2,231 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/exceptions.py
|
mbed_cloud.exceptions.CloudUnhandledError
|
class CloudUnhandledError(CloudApiException):
"""Thrown when function returns async consumer, but the error isn't handled.
Only applicable when threads are setup and the user needs to call `is_done`
and `error` before getting value.
"""
pass
|
class CloudUnhandledError(CloudApiException):
'''Thrown when function returns async consumer, but the error isn't handled.
Only applicable when threads are setup and the user needs to call `is_done`
and `error` before getting value.
'''
pass
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 2 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 12 | 8 | 2 | 2 | 1 | 1 | 4 | 2 | 1 | 1 | 0 | 4 | 0 | 0 |
2,232 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/tests/unit/asynchronous/test_routing.py
|
tests.unit.asynchronous.test_routing.Test
|
class Test(BaseCase):
def test_add_and_list_one_item(self):
a = object()
router = RoutingBase()
router.create_route(a, ('a',))
self.assertEqual([a], router.list_all())
def test_add_and_get_one_item(self):
a = object()
router = RoutingBase()
router.create_route(a, ('a',))
self.assertIn(a, router.get_route_items('a'))
def test_missing_item(self):
router = RoutingBase()
self.assertEqual([], router.get_route_items('a'))
def test_same_items(self):
a = 12345
b = a
router = RoutingBase()
router.create_route(a, ('a',))
router.create_route(b, ('b',))
self.assertEqual([a], sorted(router.list_all()))
# index a single item
items = router.get_route_items('a')
self.assertIn(a, items)
# index a single item
items = router.get_route_items('b')
self.assertIn(b, items)
def test_same_routes(self):
a = 12345
b = 54321
router = RoutingBase()
router.create_route(a, ('a',))
router.create_route(b, ('a',))
self.assertEqual(sorted([a, b]), sorted(router.list_all()))
# index a single item
items = router.get_route_items('a')
self.assertIn(a, items)
# explicit sort needed for Python2
self.assertEqual(sorted([a, b]), sorted(items))
def test_remove_item(self):
a = object()
router = RoutingBase()
router.create_route(a, ('a',))
router.remove_routes(a, ('a',))
self.assertEqual([], router.get_route_items('a'))
|
class Test(BaseCase):
def test_add_and_list_one_item(self):
pass
def test_add_and_get_one_item(self):
pass
def test_missing_item(self):
pass
def test_same_items(self):
pass
def test_same_routes(self):
pass
def test_remove_item(self):
pass
| 7 | 0 | 8 | 1 | 7 | 1 | 1 | 0.1 | 1 | 1 | 1 | 0 | 6 | 0 | 6 | 78 | 53 | 8 | 41 | 22 | 34 | 4 | 41 | 22 | 34 | 1 | 3 | 0 | 6 |
2,233 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/exceptions.py
|
mbed_cloud.exceptions.CloudBackendError
|
class CloudBackendError(CloudApiException):
"""Common exception thrown when ApiException is raised from backend API.
CloudBackendError typically means that something went wrong in communicating
with the cloud API. This can be authentication errors, connectivity issues
or invalid usage of the API.
"""
pass
|
class CloudBackendError(CloudApiException):
'''Common exception thrown when ApiException is raised from backend API.
CloudBackendError typically means that something went wrong in communicating
with the cloud API. This can be authentication errors, connectivity issues
or invalid usage of the API.
'''
pass
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 2.5 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 12 | 9 | 2 | 2 | 1 | 1 | 5 | 2 | 1 | 1 | 0 | 4 | 0 | 0 |
2,234 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/exceptions.py
|
mbed_cloud.exceptions.CloudAsyncError
|
class CloudAsyncError(CloudApiException):
"""Thrown when running in synchronized/blocking mode, but an error is raised.
Typically only found when an error is raised from the backend. Should be
handled by the user.
"""
pass
|
class CloudAsyncError(CloudApiException):
'''Thrown when running in synchronized/blocking mode, but an error is raised.
Typically only found when an error is raised from the backend. Should be
handled by the user.
'''
pass
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 2 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 12 | 8 | 2 | 2 | 1 | 1 | 4 | 2 | 1 | 1 | 0 | 4 | 0 | 0 |
2,235 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/exceptions.py
|
mbed_cloud.exceptions.CloudApiException
|
class CloudApiException(Exception):
"""Exception thrown when an Exception is thrown is SDK"""
def __init__(self, message, reason=None, status=400):
"""Initialize CloudApiException class"""
super(CloudApiException, self).__init__(message)
self.message = message
self.status = status
self.reason = reason
def __str__(self):
"""Print the exception"""
return ("(%s) '%s' %s" % (
self.status,
self.reason,
self.message)
)
|
class CloudApiException(Exception):
'''Exception thrown when an Exception is thrown is SDK'''
def __init__(self, message, reason=None, status=400):
'''Initialize CloudApiException class'''
pass
def __str__(self):
'''Print the exception'''
pass
| 3 | 3 | 7 | 0 | 6 | 1 | 1 | 0.25 | 1 | 1 | 0 | 5 | 2 | 3 | 2 | 12 | 17 | 2 | 12 | 6 | 9 | 3 | 8 | 6 | 5 | 1 | 3 | 0 | 2 |
2,236 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/enrollment/enrollment.py
|
mbed_cloud.enrollment.enrollment.EnrollmentClaim
|
class EnrollmentClaim(BaseObject):
"""Describes device object from the catalog."""
@staticmethod
def _get_attributes_map():
return {
"account_id": "account_id",
"claimed_at": "claimed_at",
"created_at": "created_at",
"device_id": "enrolled_device_id",
"claim_id": "enrollment_identity",
"expires_at": "expires_at",
"id": "id",
}
@property
def account_id(self):
"""Gets the account_id of this EnrollmentIdentity.
:return: The account_id of this EnrollmentIdentity.
:rtype: str
"""
return self._account_id
@property
def claimed_at(self):
"""Gets the claimed_at of this EnrollmentIdentity.
The time of claiming the device to be assigned to the account.
:return: The claimed_at of this EnrollmentIdentity.
:rtype: datetime
"""
return self._claimed_at
@property
def created_at(self):
"""Gets the created_at of this EnrollmentIdentity.
The time of the enrollment identity creation.
:return: The created_at of this EnrollmentIdentity.
:rtype: datetime
"""
return self._created_at
@property
def device_id(self):
"""Gets the enrolled_device_id of this EnrollmentIdentity.
Enrolled device internal ID
:return: The enrolled_device_id of this EnrollmentIdentity.
:rtype: str
"""
return self._device_id
@property
def claim_id(self):
"""Gets the claim_id of this EnrollmentIdentity.
Enrollment identity.
:return: The claim_id of this EnrollmentIdentity.
:rtype: str
"""
return self._claim_id
@property
def expires_at(self):
"""Gets the expires_at of this EnrollmentIdentity.
The enrollment claim expiration time. If the device does not connect to Pelion Device Management
before the expiration, the claim is removed without a separate notice
:return: The expires_at of this EnrollmentIdentity.
:rtype: datetime
"""
return self._expires_at
@property
def id(self):
"""Gets the id of this EnrollmentIdentity.
Enrollment identity internal id
:return: The id of this EnrollmentIdentity.
:rtype: str
"""
return self._id
|
class EnrollmentClaim(BaseObject):
'''Describes device object from the catalog.'''
@staticmethod
def _get_attributes_map():
pass
@property
def account_id(self):
'''Gets the account_id of this EnrollmentIdentity.
:return: The account_id of this EnrollmentIdentity.
:rtype: str
'''
pass
@property
def claimed_at(self):
'''Gets the claimed_at of this EnrollmentIdentity.
The time of claiming the device to be assigned to the account.
:return: The claimed_at of this EnrollmentIdentity.
:rtype: datetime
'''
pass
@property
def created_at(self):
'''Gets the created_at of this EnrollmentIdentity.
The time of the enrollment identity creation.
:return: The created_at of this EnrollmentIdentity.
:rtype: datetime
'''
pass
@property
def device_id(self):
'''Gets the enrolled_device_id of this EnrollmentIdentity.
Enrolled device internal ID
:return: The enrolled_device_id of this EnrollmentIdentity.
:rtype: str
'''
pass
@property
def claim_id(self):
'''Gets the claim_id of this EnrollmentIdentity.
Enrollment identity.
:return: The claim_id of this EnrollmentIdentity.
:rtype: str
'''
pass
@property
def expires_at(self):
'''Gets the expires_at of this EnrollmentIdentity.
The enrollment claim expiration time. If the device does not connect to Pelion Device Management
before the expiration, the claim is removed without a separate notice
:return: The expires_at of this EnrollmentIdentity.
:rtype: datetime
'''
pass
@property
def id(self):
'''Gets the id of this EnrollmentIdentity.
Enrollment identity internal id
:return: The id of this EnrollmentIdentity.
:rtype: str
'''
pass
| 17 | 8 | 9 | 2 | 3 | 4 | 1 | 1.09 | 1 | 0 | 0 | 0 | 7 | 0 | 8 | 16 | 90 | 21 | 33 | 17 | 16 | 36 | 17 | 9 | 8 | 1 | 2 | 0 | 8 |
2,237 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/device_directory/device_directory.py
|
mbed_cloud.device_directory.device_directory.Query
|
class Query(BaseObject):
"""Describes device query object."""
@staticmethod
def _get_attributes_map():
return {
"created_at": "created_at",
"description": "description",
"id": "id",
"name": "name",
"updated_at": "updated_at",
"filter": "query"
}
@property
def created_at(self):
"""Get the created_at of this Query.
The time the object was created
:return: The created_at of this Query.
:rtype: datetime
"""
return self._created_at
@property
def description(self):
"""Get the description of this Query.
The description of the object
:return: The description of this Query.
:rtype: str
"""
return self._description
@property
def id(self):
"""Get the id of this Query.
The ID of the query
:return: The id of this Query.
:rtype: str
"""
return self._id
@property
def name(self):
"""Get the name of this Query.
The name of the query
:return: The name of this Query.
:rtype: str
"""
return self._name
@property
def updated_at(self):
"""Get the updated_at of this Query.
The time the object was updated
:return: The updated_at of this Query.
:rtype: datetime
"""
return self._updated_at
@property
def filter(self):
"""Get the query of this Query.
The device query
:return: The query of this Query.
:rtype: dict
"""
if isinstance(self._filter, str):
return self._decode_query(self._filter)
return self._filter
@filter.setter
def filter(self, value):
self._filter = value
|
class Query(BaseObject):
'''Describes device query object.'''
@staticmethod
def _get_attributes_map():
pass
@property
def created_at(self):
'''Get the created_at of this Query.
The time the object was created
:return: The created_at of this Query.
:rtype: datetime
'''
pass
@property
def description(self):
'''Get the description of this Query.
The description of the object
:return: The description of this Query.
:rtype: str
'''
pass
@property
def id(self):
'''Get the id of this Query.
The ID of the query
:return: The id of this Query.
:rtype: str
'''
pass
@property
def name(self):
'''Get the name of this Query.
The name of the query
:return: The name of this Query.
:rtype: str
'''
pass
@property
def updated_at(self):
'''Get the updated_at of this Query.
The time the object was updated
:return: The updated_at of this Query.
:rtype: datetime
'''
pass
@property
def filter(self):
'''Get the query of this Query.
The device query
:return: The query of this Query.
:rtype: dict
'''
pass
@filter.setter
def filter(self):
pass
| 17 | 7 | 8 | 2 | 3 | 4 | 1 | 0.91 | 1 | 1 | 0 | 0 | 7 | 1 | 8 | 16 | 85 | 20 | 34 | 18 | 17 | 31 | 19 | 10 | 10 | 2 | 2 | 1 | 9 |
2,238 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/device_directory/device_directory.py
|
mbed_cloud.device_directory.device_directory.DeviceEvent
|
class DeviceEvent(DeviceEventData):
"""Describes device event object."""
@ staticmethod
def _get_attributes_map():
return None
def __init__(self, device_event_obj):
"""Override __init__ and allow passing in backend object."""
super(DeviceEvent, self).__init__(**device_event_obj.to_dict())
|
class DeviceEvent(DeviceEventData):
'''Describes device event object.'''
@staticmethod
def _get_attributes_map():
pass
def __init__(self, device_event_obj):
'''Override __init__ and allow passing in backend object.'''
pass
| 4 | 2 | 3 | 0 | 2 | 1 | 1 | 0.33 | 1 | 1 | 0 | 0 | 1 | 0 | 2 | 34 | 10 | 2 | 6 | 4 | 2 | 2 | 5 | 3 | 2 | 1 | 2 | 0 | 2 |
2,239 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/device_directory/device_directory.py
|
mbed_cloud.device_directory.device_directory.Device
|
class Device(BaseObject):
"""Describes device object from the catalog."""
@staticmethod
def _get_attributes_map():
return {
"account_id": "account_id",
"bootstrapped_timestamp": "bootstrapped_timestamp",
"created_at": "created_at",
"custom_attributes": "custom_attributes",
"deployed_state": "deployed_state",
"last_deployment": "deployment",
"description": "description",
"device_class": "device_class",
"id": "id",
"manifest_url": "manifest",
"mechanism": "mechanism",
"mechanism_url": "mechanism_url",
"name": "name",
"host_gateway": "host_gateway",
"device_type": "endpoint_type",
"serial_number": "serial_number",
"state": "state",
"updated_at": "updated_at",
"vendor_id": "vendor_id",
"alias": "endpoint_name",
"bootstrap_certificate_expiration": "bootstrap_expiration_date",
"certificate_fingerprint": "device_key",
"certificate_issuer_id": "ca_id",
"connector_certificate_expiration": "connector_expiration_date",
"device_execution_mode": "device_execution_mode",
"firmware_checksum": "firmware_checksum",
"manifest_timestamp": "manifest_timestamp",
"claimed_at": "enrolment_list_timestamp",
}
@property
def account_id(self):
"""The owning IAM account ID.
:rtype: str
"""
return self._account_id
@property
def bootstrapped_timestamp(self):
"""The time the device was created.
:rtype: datetime
"""
return self._bootstrapped_timestamp
@property
def created_at(self):
"""The time the device was created.
:rtype: datetime
"""
return self._created_at
@property
def custom_attributes(self):
"""Up to 5 custom JSON attributes.
:rtype: object
"""
return self._custom_attributes
@property
def deployed_state(self):
"""State of the device's deployment.
:rtype: str
"""
return self._deployed_state
@property
def last_deployment(self):
"""The last deployment used on the device.
:rtype: datetime
"""
return self._last_deployment
@property
def description(self):
"""The description of the device.
:rtype: str
"""
return self._description
@property
def device_class(self):
"""Class of the device.
:rtype: str
"""
return self._device_class
@property
def id(self):
"""The ID of the device.
:rtype: str
"""
return self._id
@property
def manifest_url(self):
"""URL for the current device manifest.
:rtype: str
"""
return self._manifest_url
@property
def mechanism(self):
"""The ID of the channel used to communicate with the device.
:rtype: str
"""
return self._mechanism
@property
def mechanism_url(self):
"""The address of the connector to use.
:rtype: str
"""
return self._mechanism_url
@property
def name(self):
"""The name of the device.
:rtype: str
"""
return self._name
@property
def host_gateway(self):
"""The device name of the host gateway, if appropriate.
:rtype: str
"""
return self._host_gateway
@property
def device_type(self):
"""The type of the device - e.g. if the device is a gateway.
:rtype: str
"""
return self._device_type
@property
def serial_number(self):
"""The serial number of the device.
:rtype: str
"""
return self._serial_number
@property
def state(self):
"""The current state of the device.
:rtype: str
"""
return self._state
@property
def updated_at(self):
"""The time the device was updated.
:rtype: datetime
"""
return self._updated_at
@property
def vendor_id(self):
"""The device vendor ID.
:rtype: str
"""
return self._vendor_id
@property
def alias(self):
"""The alias of the device.
:rtype: str
"""
return self._alias
@property
def bootstrap_certificate_expiration(self):
"""Expiration date of certificate.
:rtype: datetime
"""
return self._bootstrap_certificate_expiration
@property
def certificate_fingerprint(self):
"""Fingerprint of the device certificate.
This is not part of the certificate but rather the SH-256 hash of the certificate.
:rtype: str
"""
return self._certificate_fingerprint
@property
def certificate_issuer_id(self):
"""ID of the issuer of the certificate.
This is the value of the CN field (in the Subject) of the Issuer of the certificate.
:rtype: str
"""
return self._certificate_issuer_id
@property
def connector_certificate_expiration(self):
"""Expiration date of the certificate used to connect to connector server.
:rtype: datetime
"""
return self._connector_certificate_expiration
@property
def device_execution_mode(self):
"""The device class.
:rtype: int
"""
return self._device_execution_mode
@property
def firmware_checksum(self):
"""The SHA256 checksum of the current firmware image.
:rtype: str
"""
return self._firmware_checksum
@property
def manifest_timestamp(self):
"""The timestamp of the current manifest version.
:rtype: datetime
"""
return self._manifest_timestamp
@property
def claimed_at(self):
"""When the device was first claimed/enrolled.
:rtype: datetime
"""
return self._claimed_at
|
class Device(BaseObject):
'''Describes device object from the catalog.'''
@staticmethod
def _get_attributes_map():
pass
@property
def account_id(self):
'''The owning IAM account ID.
:rtype: str
'''
pass
@property
def bootstrapped_timestamp(self):
'''The time the device was created.
:rtype: datetime
'''
pass
@property
def created_at(self):
'''The time the device was created.
:rtype: datetime
'''
pass
@property
def custom_attributes(self):
'''Up to 5 custom JSON attributes.
:rtype: object
'''
pass
@property
def deployed_state(self):
'''State of the device's deployment.
:rtype: str
'''
pass
@property
def last_deployment(self):
'''The last deployment used on the device.
:rtype: datetime
'''
pass
@property
def description(self):
'''The description of the device.
:rtype: str
'''
pass
@property
def device_class(self):
'''Class of the device.
:rtype: str
'''
pass
@property
def id(self):
'''The ID of the device.
:rtype: str
'''
pass
@property
def manifest_url(self):
'''URL for the current device manifest.
:rtype: str
'''
pass
@property
def mechanism(self):
'''The ID of the channel used to communicate with the device.
:rtype: str
'''
pass
@property
def mechanism_url(self):
'''The address of the connector to use.
:rtype: str
'''
pass
@property
def name(self):
'''The name of the device.
:rtype: str
'''
pass
@property
def host_gateway(self):
'''The device name of the host gateway, if appropriate.
:rtype: str
'''
pass
@property
def device_type(self):
'''The type of the device - e.g. if the device is a gateway.
:rtype: str
'''
pass
@property
def serial_number(self):
'''The serial number of the device.
:rtype: str
'''
pass
@property
def state(self):
'''The current state of the device.
:rtype: str
'''
pass
@property
def updated_at(self):
'''The time the device was updated.
:rtype: datetime
'''
pass
@property
def vendor_id(self):
'''The device vendor ID.
:rtype: str
'''
pass
@property
def alias(self):
'''The alias of the device.
:rtype: str
'''
pass
@property
def bootstrap_certificate_expiration(self):
'''Expiration date of certificate.
:rtype: datetime
'''
pass
@property
def certificate_fingerprint(self):
'''Fingerprint of the device certificate.
This is not part of the certificate but rather the SH-256 hash of the certificate.
:rtype: str
'''
pass
@property
def certificate_issuer_id(self):
'''ID of the issuer of the certificate.
This is the value of the CN field (in the Subject) of the Issuer of the certificate.
:rtype: str
'''
pass
@property
def connector_certificate_expiration(self):
'''Expiration date of the certificate used to connect to connector server.
:rtype: datetime
'''
pass
@property
def device_execution_mode(self):
'''The device class.
:rtype: int
'''
pass
@property
def firmware_checksum(self):
'''The SHA256 checksum of the current firmware image.
:rtype: str
'''
pass
@property
def manifest_timestamp(self):
'''The timestamp of the current manifest version.
:rtype: datetime
'''
pass
@property
def claimed_at(self):
'''When the device was first claimed/enrolled.
:rtype: datetime
'''
pass
| 59 | 29 | 7 | 1 | 3 | 3 | 1 | 0.74 | 1 | 0 | 0 | 0 | 28 | 0 | 29 | 37 | 263 | 59 | 117 | 59 | 58 | 87 | 59 | 30 | 29 | 1 | 2 | 0 | 29 |
2,240 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/core.py
|
mbed_cloud.core.StubAPI
|
class StubAPI(BaseAPI):
"""Used in test framework"""
def __init__(self, params):
"""For use in test verification"""
# because we take a positional dictionary rather than **kwargs
# we have to be careful to replicate this for the testrunner
self.kwargs = params
def exception(self):
"""Raises an exception"""
raise ValueError('just a test')
def success(self, **kwargs):
"""Returns all arguments received in init and this method call"""
response = {'success': True}
# check dates can be manipulated
response.update(kwargs)
response.update(self.kwargs)
response['test_argument3'] = datetime.timedelta(days=1) + response['test_argument3']
return response
|
class StubAPI(BaseAPI):
'''Used in test framework'''
def __init__(self, params):
'''For use in test verification'''
pass
def exception(self):
'''Raises an exception'''
pass
def success(self, **kwargs):
'''Returns all arguments received in init and this method call'''
pass
| 4 | 4 | 5 | 0 | 3 | 2 | 1 | 0.64 | 1 | 2 | 0 | 0 | 3 | 1 | 3 | 10 | 21 | 3 | 11 | 6 | 7 | 7 | 11 | 6 | 7 | 1 | 2 | 0 | 3 |
2,241 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/core.py
|
mbed_cloud.core.BaseObject
|
class BaseObject(object):
"""Base class for APIs classes."""
def __init__(self, dictionary):
"""Initialize object."""
self.update_attributes(dictionary)
def update_attributes(self, updates):
"""Update attributes."""
if not isinstance(updates, dict):
updates = updates.to_dict()
for sdk_key, spec_key in self._get_attributes_map().items():
attr = '_%s' % sdk_key
if spec_key in updates and not hasattr(self, attr):
setattr(self, attr, updates[spec_key])
@staticmethod
def _get_attributes_map():
"""Override in child class."""
pass
@classmethod
def _create_request_map(cls, input_map):
"""Create request map."""
field_map = cls._get_attributes_map()
return {field_map[k]: v for k, v in input_map.items() if k in field_map}
def to_dict(self):
"""Return dictionary of object."""
return {sdk_key: getattr(self, sdk_key, None) for sdk_key in self._get_attributes_map()}
def _get_operator(self, key):
operator = ""
if key.endswith("__eq"):
operator = "eq"
elif key.endswith("__neq"):
operator = "neq"
elif key.endswith("__lte"):
operator = "lte"
elif key.endswith("__gte"):
operator = "gte"
return operator
def _decode_query(self, query):
qs = urllib.parse.parse_qs(urllib.parse.unquote(query))
query = {}
for (key, value) in list(qs.items()):
operator = self._get_operator(key)
if operator != "":
key = key.replace("__%s" % (operator), "")
else:
operator = "eq"
if key.startswith("custom_attributes"):
key = key.replace("custom_attributes__", "")
if "custom_attributes" not in query:
query["custom_attributes"] = {}
val = query["custom_attributes"].get(key, {})
val["$%s" % (operator)] = value[0]
query["custom_attributes"][key] = val
else:
val = query.get(key, {})
val["$%s" % (operator)] = value[0]
query[key] = val
return query
def __repr__(self):
"""For print and pprint."""
return str(self.to_dict())
|
class BaseObject(object):
'''Base class for APIs classes.'''
def __init__(self, dictionary):
'''Initialize object.'''
pass
def update_attributes(self, updates):
'''Update attributes.'''
pass
@staticmethod
def _get_attributes_map():
'''Override in child class.'''
pass
@classmethod
def _create_request_map(cls, input_map):
'''Create request map.'''
pass
def to_dict(self):
'''Return dictionary of object.'''
pass
def _get_operator(self, key):
pass
def _decode_query(self, query):
pass
def __repr__(self):
'''For print and pprint.'''
pass
| 11 | 7 | 7 | 0 | 6 | 1 | 2 | 0.13 | 1 | 3 | 0 | 19 | 6 | 0 | 8 | 8 | 68 | 8 | 53 | 19 | 42 | 7 | 46 | 17 | 37 | 5 | 1 | 3 | 19 |
2,242 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/core.py
|
mbed_cloud.core.BaseAPI
|
class BaseAPI(object):
"""BaseAPI is parent class for all APIs. Ensuring config is valid and available."""
api_structure = {}
def __init__(self, params=None):
"""A module to access this section of the Pelion Device Management API.
:param params: Dictionary to override configuration values
"""
self.config = Config(params)
self.apis = {}
self.api_clients = {}
for api_parent_class, child_classes in self.api_structure.items():
self._init_api(api_parent_class, child_classes)
def _get_api(self, api_class):
return self.apis.get(api_class, None)
def _init_api(self, api_parent_class, apis):
api_client = api_parent_class.ApiClient()
self.api_clients[api_parent_class] = api_client
api_client.user_agent = utils.get_user_agent()
api_client.configuration.api_key_prefix['Authorization'] = 'Bearer'
api_client.configuration.safe_chars_for_path_param = "/" # don't encode (resource paths)
self._update_api_client(api_parent_class)
self.apis.update({api_cls: api_cls(api_client) for api_cls in apis})
def _update_api_client(self, api_parent_class=None):
"""Updates the ApiClient object of specified parent api (or all of them)"""
clients = ([self.api_clients[api_parent_class]]
if api_parent_class else self.api_clients.values())
for api_client in clients:
api_client.configuration.host = (self.config.get('host') or
api_client.configuration.host)
api_client.configuration.api_key['Authorization'] = self.config['api_key']
def _verify_sort_options(self, kwargs):
if kwargs.get('order'):
order = kwargs.get('order').upper()
if order not in ["ASC", "DESC"]:
raise ValueError("Key 'order' needs to be either 'ASC' or 'DESC'. "
"Currently: %r" % order)
kwargs['order'] = order
if kwargs.get('limit') is not None:
if kwargs.get('limit') < 2 or kwargs.get('limit') > 1000:
raise ValueError("Limit needs to be between 2 and 1000. "
"Currently: %r" % kwargs.get('limit'))
return kwargs
def _verify_filters(self, kwargs, obj, encode=False):
"""Legacy entrypoint with 'encode' flag"""
return (filters.legacy_filter_formatter if encode else filters.filter_formatter)(
kwargs,
obj._get_attributes_map()
)
def get_last_api_metadata(self):
"""Get meta data for the last Pelion Device Management API call.
:returns: meta data of the last Pelion Device Management API call
:rtype: ApiMetadata
"""
last_metadata = None
for key, api in iteritems(self.apis):
api_client = api.api_client
if api_client is not None:
metadata = api_client.get_last_metadata()
if metadata is not None and metadata.get('timestamp', None) is not None:
if last_metadata is None:
last_metadata = metadata
elif metadata["timestamp"] >= last_metadata["timestamp"]:
last_metadata = metadata
if last_metadata is not None:
last_metadata = ApiMetadata(last_metadata.get("url"),
last_metadata.get("method"),
last_metadata.get("response", None),
last_metadata.get("return_data", None),
last_metadata.get("exception", None))
return last_metadata
|
class BaseAPI(object):
'''BaseAPI is parent class for all APIs. Ensuring config is valid and available.'''
def __init__(self, params=None):
'''A module to access this section of the Pelion Device Management API.
:param params: Dictionary to override configuration values
'''
pass
def _get_api(self, api_class):
pass
def _init_api(self, api_parent_class, apis):
pass
def _update_api_client(self, api_parent_class=None):
'''Updates the ApiClient object of specified parent api (or all of them)'''
pass
def _verify_sort_options(self, kwargs):
pass
def _verify_filters(self, kwargs, obj, encode=False):
'''Legacy entrypoint with 'encode' flag'''
pass
def get_last_api_metadata(self):
'''Get meta data for the last Pelion Device Management API call.
:returns: meta data of the last Pelion Device Management API call
:rtype: ApiMetadata
'''
pass
| 8 | 5 | 10 | 1 | 8 | 1 | 3 | 0.18 | 1 | 3 | 2 | 9 | 7 | 3 | 7 | 7 | 84 | 14 | 60 | 21 | 52 | 11 | 48 | 21 | 40 | 7 | 1 | 4 | 21 |
2,243 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/common/fields.py
|
mbed_cloud.foundation.common.fields.FloatField
|
class FloatField(Field):
base_type = float
def set(self, value):
"""Attempt to convert to a float if not already."""
try:
float_value = float(value)
except TypeError:
float_value = value
return super().set(float_value)
|
class FloatField(Field):
def set(self, value):
'''Attempt to convert to a float if not already.'''
pass
| 2 | 1 | 7 | 0 | 6 | 1 | 2 | 0.13 | 1 | 3 | 0 | 0 | 1 | 0 | 1 | 9 | 10 | 1 | 8 | 4 | 6 | 1 | 8 | 4 | 6 | 2 | 2 | 1 | 2 |
2,244 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/common/fields.py
|
mbed_cloud.foundation.common.fields.IntegerField
|
class IntegerField(Field):
base_type = int
def set(self, value):
"""Attempt to convert to an integer if not already."""
try:
int_value = int(value)
except TypeError:
int_value = value
return super().set(int_value)
|
class IntegerField(Field):
def set(self, value):
'''Attempt to convert to an integer if not already.'''
pass
| 2 | 1 | 7 | 0 | 6 | 1 | 2 | 0.13 | 1 | 3 | 0 | 0 | 1 | 0 | 1 | 9 | 10 | 1 | 8 | 4 | 6 | 1 | 8 | 4 | 6 | 2 | 2 | 1 | 2 |
2,245 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/common/fields.py
|
mbed_cloud.foundation.common.fields.ListField
|
class ListField(Field):
base_type = list
def set(self, value):
if isinstance(value, list) and self._entity:
# Convert a list of dictionaries into a list of entities
self._val = [self._entity(**item) if isinstance(item, dict) else item for item in value]
self.value_set = True
else:
return super().set(value)
return self
def to_literal(self):
if self._entity:
return [item.to_literal() for item in self._val] if self._val else None
else:
return super().to_literal()
def to_api(self):
if self._entity:
return [item.to_api() for item in self._val] if self._val else None
else:
return super().to_api()
def from_api(self, value):
if self._entity:
return self.set([self._entity().from_api(**item) for item in value] if value else None)
else:
return super().from_api(value)
def from_literal(self, value):
if self._entity:
return self.set([self._entity().from_literal(**item) for item in value] if value else None)
else:
return super().from_api(value)
def to_query_param(self):
"""Generate a format which is appropriate to representing a a query param
Note: This will not URL encode as this will be performed by the `requests` library
"""
return ",".join(self.value)
|
class ListField(Field):
def set(self, value):
pass
def to_literal(self):
pass
def to_api(self):
pass
def from_api(self, value):
pass
def from_literal(self, value):
pass
def to_query_param(self):
'''Generate a format which is appropriate to representing a a query param
Note: This will not URL encode as this will be performed by the `requests` library
'''
pass
| 7 | 1 | 6 | 0 | 5 | 1 | 3 | 0.13 | 1 | 3 | 0 | 0 | 6 | 2 | 6 | 14 | 42 | 7 | 31 | 10 | 24 | 4 | 26 | 10 | 19 | 3 | 2 | 1 | 16 |
2,246 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/common/fields.py
|
mbed_cloud.foundation.common.fields.StringField
|
class StringField(Field):
# Python 2 and 3 compatible string type
base_type = six.string_types
|
class StringField(Field):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0.5 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 8 | 3 | 0 | 2 | 2 | 1 | 1 | 2 | 2 | 1 | 0 | 2 | 0 | 0 |
2,247 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/accounts/user_invitation.py
|
mbed_cloud.foundation.entities.accounts.user_invitation.UserInvitation
|
class UserInvitation(Entity):
"""Represents the `UserInvitation` entity in Pelion Device Management"""
# List of fields that are serialised between the API and SDK
_api_fieldnames = [
"account_id",
"created_at",
"email",
"expiration",
"id",
"login_profiles",
"updated_at",
"user_id",
]
# List of fields that are available for the user of the SDK
_sdk_fieldnames = _api_fieldnames
# Renames to be performed by the SDK when receiving data {<API Field Name>: <SDK Field Name>}
_renames = {}
# Renames to be performed by the SDK when sending data {<SDK Field Name>: <API Field Name>}
_renames_to_api = {}
def __init__(
self,
_client=None,
account_id=None,
created_at=None,
email=None,
expiration=None,
id=None,
login_profiles=None,
updated_at=None,
user_id=None,
):
"""Creates a local `UserInvitation` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param account_id: The ID of the account the user is invited to.
:type account_id: str
:param created_at: Creation UTC time RFC3339.
:type created_at: datetime
:param email: (Required) Email address of the invited user.
:type email: str
:param expiration: Invitation expiration as UTC time RFC3339.
:type expiration: datetime
:param id: (Required) The ID of the invitation.
:type id: str
:param login_profiles: A list of login profiles for the user. Specified as the identity
providers the user is associated with.
:type login_profiles: list
:param updated_at: Last update UTC time RFC3339.
:type updated_at: datetime
:param user_id: The ID of the invited user.
:type user_id: str
"""
super().__init__(_client=_client)
# inline imports for avoiding circular references and bulk imports
from mbed_cloud.foundation.entities.accounts.login_profile import LoginProfile
# fields
self._account_id = fields.StringField(value=account_id)
self._created_at = fields.DateTimeField(value=created_at)
self._email = fields.StringField(value=email)
self._expiration = fields.DateTimeField(value=expiration)
self._id = fields.StringField(value=id)
self._login_profiles = fields.ListField(value=login_profiles, entity=LoginProfile)
self._updated_at = fields.DateTimeField(value=updated_at)
self._user_id = fields.StringField(value=user_id)
@property
def account_id(self):
"""The ID of the account the user is invited to.
api example: '01619571e2e90242ac12000600000000'
:rtype: str
"""
return self._account_id.value
@property
def created_at(self):
"""Creation UTC time RFC3339.
api example: '2018-02-13T09:35:20Z'
:rtype: datetime
"""
return self._created_at.value
@property
def email(self):
"""Email address of the invited user.
This field must be set when creating a new UserInvitation Entity.
api example: 'friend@arm.com'
:rtype: str
"""
return self._email.value
@email.setter
def email(self, value):
"""Set value of `email`
:param value: value to set
:type value: str
"""
self._email.set(value)
@property
def expiration(self):
"""Invitation expiration as UTC time RFC3339.
api example: '2018-02-14T15:24:14Z'
:rtype: datetime
"""
return self._expiration.value
@property
def id(self):
"""The ID of the invitation.
This field must be set when updating or deleting an existing UserInvitation Entity.
api example: '01619571e2e89242ac12000600000000'
:rtype: str
"""
return self._id.value
@id.setter
def id(self, value):
"""Set value of `id`
:param value: value to set
:type value: str
"""
self._id.set(value)
@property
def login_profiles(self):
"""A list of login profiles for the user. Specified as the identity providers the
user is associated with.
:rtype: list[LoginProfile]
"""
return self._login_profiles.value
@login_profiles.setter
def login_profiles(self, value):
"""Set value of `login_profiles`
:param value: value to set
:type value: list[LoginProfile]
"""
self._login_profiles.set(value)
@property
def updated_at(self):
"""Last update UTC time RFC3339.
api example: '2018-02-14T15:24:14Z'
:rtype: datetime
"""
return self._updated_at.value
@property
def user_id(self):
"""The ID of the invited user.
api example: '01619571e2e90242ac12000600000000'
:rtype: str
"""
return self._user_id.value
def create(self, valid_for_days=30):
"""Create a user invitation.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/user-invitations>`_.
:param valid_for_days: Specifies how many days the invitation will be valid for.
:type valid_for_days: int
:rtype: UserInvitation
"""
# Conditionally setup the message body, fields which have not been set will not be sent to the API.
# This avoids null fields being rejected and allows the default value to be used.
body_params = {}
if self._email.value_set:
body_params["email"] = self._email.to_api()
if self._login_profiles.value_set:
body_params["login_profiles"] = self._login_profiles.to_api()
# Method parameters are unconditionally sent even if set to None
body_params["valid_for_days"] = fields.IntegerField(valid_for_days).to_api()
return self._client.call_api(
method="post",
path="/v3/user-invitations",
content_type="application/json",
body_params=body_params,
unpack=self,
)
def delete(self):
"""Delete a user invitation.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/user-invitations/{invitation_id}>`_.
:rtype: UserInvitation
"""
return self._client.call_api(
method="delete",
path="/v3/user-invitations/{invitation_id}",
content_type="application/json",
path_params={"invitation_id": self._id.to_api()},
unpack=self,
)
def list(self, filter=None, order="ASC", max_results=None, page_size=50, include=None):
"""Get the details of all user invitations.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/user-invitations>`_.
**API Filters**
The following filters are supported by the API when listing UserInvitation entities:
+----------------+------+------+------+------+------+------+------+
| Field | eq | neq | gte | lte | in | nin | like |
+================+======+======+======+======+======+======+======+
| login_profiles | Y | | | | | | |
+----------------+------+------+------+------+------+------+------+
**Example Usage**
.. code-block:: python
from mbed_cloud.foundation import UserInvitation
from mbed_cloud import ApiFilter
api_filter = ApiFilter()
api_filter.add_filter("login_profiles", "eq", <filter value>)
for user_invitation in UserInvitation().list(filter=api_filter):
print(user_invitation.login_profiles)
:param filter: An optional filter to apply when listing entities, please see the
above **API Filters** table for supported filters.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order based on creation time. Acceptable values: ASC, DESC.
Default: ASC.
:type order: str
:param max_results: Total maximum number of results to retrieve
:type max_results: int
:param page_size: The number of results to return (2-1000). Default 50.
:type page_size: int
:param include: Comma separated additional data to return.
:type include: str
:return: An iterator object which yields instances of an entity.
:rtype: mbed_cloud.pagination.PaginatedResponse(UserInvitation)
"""
from mbed_cloud.foundation._custom_methods import paginate
from mbed_cloud.foundation import UserInvitation
from mbed_cloud import ApiFilter
# Be permissive and accept an instance of a dictionary as this was how the Legacy interface worked.
if isinstance(filter, dict):
filter = ApiFilter(filter_definition=filter, field_renames=UserInvitation._renames_to_api)
# The preferred method is an ApiFilter instance as this should be easier to use.
elif isinstance(filter, ApiFilter):
# If filter renames have not be defined then configure the ApiFilter so that any renames
# performed by the SDK are reversed when the query parameters are created.
if filter.field_renames is None:
filter.field_renames = UserInvitation._renames_to_api
elif filter is not None:
raise TypeError("The 'filter' parameter may be either 'dict' or 'ApiFilter'.")
return paginate(
self=self,
foreign_key=UserInvitation,
filter=filter,
order=order,
max_results=max_results,
page_size=page_size,
include=include,
wraps=self._paginate_list,
)
def _paginate_list(self, after=None, filter=None, order="ASC", limit=50, include=None):
"""Get the details of all user invitations.
:param after: The entity ID to fetch after the given one.
:type after: str
:param filter: Optional API filter for listing resources.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order based on creation time. Acceptable values: ASC, DESC.
Default: ASC.
:type order: str
:param limit: The number of results to return (2-1000). Default 50.
:type limit: int
:param include: Not supported by the API.
:type include: str
:rtype: mbed_cloud.pagination.PaginatedResponse
"""
# Filter query parameters
query_params = filter.to_api() if filter else {}
# Add in other query parameters
query_params["after"] = fields.StringField(after).to_api()
query_params["order"] = fields.StringField(order, enum=enums.UserInvitationOrderEnum).to_api()
query_params["limit"] = fields.IntegerField(limit).to_api()
query_params["include"] = fields.StringField(include).to_api()
return self._client.call_api(
method="get",
path="/v3/user-invitations",
content_type="application/json",
query_params=query_params,
unpack=False,
)
def read(self):
"""Details of a user invitation.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/user-invitations/{invitation_id}>`_.
:rtype: UserInvitation
"""
return self._client.call_api(
method="get",
path="/v3/user-invitations/{invitation_id}",
content_type="application/json",
path_params={"invitation_id": self._id.to_api()},
unpack=self,
)
|
class UserInvitation(Entity):
'''Represents the `UserInvitation` entity in Pelion Device Management'''
def __init__(
self,
_client=None,
account_id=None,
created_at=None,
email=None,
expiration=None,
id=None,
login_profiles=None,
updated_at=None,
user_id=None,
):
'''Creates a local `UserInvitation` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param account_id: The ID of the account the user is invited to.
:type account_id: str
:param created_at: Creation UTC time RFC3339.
:type created_at: datetime
:param email: (Required) Email address of the invited user.
:type email: str
:param expiration: Invitation expiration as UTC time RFC3339.
:type expiration: datetime
:param id: (Required) The ID of the invitation.
:type id: str
:param login_profiles: A list of login profiles for the user. Specified as the identity
providers the user is associated with.
:type login_profiles: list
:param updated_at: Last update UTC time RFC3339.
:type updated_at: datetime
:param user_id: The ID of the invited user.
:type user_id: str
'''
pass
@property
def account_id(self):
'''The ID of the account the user is invited to.
api example: '01619571e2e90242ac12000600000000'
:rtype: str
'''
pass
@property
def created_at(self):
'''Creation UTC time RFC3339.
api example: '2018-02-13T09:35:20Z'
:rtype: datetime
'''
pass
@property
def email(self):
'''Email address of the invited user.
This field must be set when creating a new UserInvitation Entity.
api example: 'friend@arm.com'
:rtype: str
'''
pass
@email.setter
def email(self):
'''Set value of `email`
:param value: value to set
:type value: str
'''
pass
@property
def expiration(self):
'''Invitation expiration as UTC time RFC3339.
api example: '2018-02-14T15:24:14Z'
:rtype: datetime
'''
pass
@property
def id(self):
'''The ID of the invitation.
This field must be set when updating or deleting an existing UserInvitation Entity.
api example: '01619571e2e89242ac12000600000000'
:rtype: str
'''
pass
@id.setter
def id(self):
'''Set value of `id`
:param value: value to set
:type value: str
'''
pass
@property
def login_profiles(self):
'''A list of login profiles for the user. Specified as the identity providers the
user is associated with.
:rtype: list[LoginProfile]
'''
pass
@login_profiles.setter
def login_profiles(self):
'''Set value of `login_profiles`
:param value: value to set
:type value: list[LoginProfile]
'''
pass
@property
def updated_at(self):
'''Last update UTC time RFC3339.
api example: '2018-02-14T15:24:14Z'
:rtype: datetime
'''
pass
@property
def user_id(self):
'''The ID of the invited user.
api example: '01619571e2e90242ac12000600000000'
:rtype: str
'''
pass
def created_at(self):
'''Create a user invitation.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/user-invitations>`_.
:param valid_for_days: Specifies how many days the invitation will be valid for.
:type valid_for_days: int
:rtype: UserInvitation
'''
pass
def delete(self):
'''Delete a user invitation.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/user-invitations/{invitation_id}>`_.
:rtype: UserInvitation
'''
pass
def list(self, filter=None, order="ASC", max_results=None, page_size=50, include=None):
'''Get the details of all user invitations.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/user-invitations>`_.
**API Filters**
The following filters are supported by the API when listing UserInvitation entities:
+----------------+------+------+------+------+------+------+------+
| Field | eq | neq | gte | lte | in | nin | like |
+================+======+======+======+======+======+======+======+
| login_profiles | Y | | | | | | |
+----------------+------+------+------+------+------+------+------+
**Example Usage**
.. code-block:: python
from mbed_cloud.foundation import UserInvitation
from mbed_cloud import ApiFilter
api_filter = ApiFilter()
api_filter.add_filter("login_profiles", "eq", <filter value>)
for user_invitation in UserInvitation().list(filter=api_filter):
print(user_invitation.login_profiles)
:param filter: An optional filter to apply when listing entities, please see the
above **API Filters** table for supported filters.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order based on creation time. Acceptable values: ASC, DESC.
Default: ASC.
:type order: str
:param max_results: Total maximum number of results to retrieve
:type max_results: int
:param page_size: The number of results to return (2-1000). Default 50.
:type page_size: int
:param include: Comma separated additional data to return.
:type include: str
:return: An iterator object which yields instances of an entity.
:rtype: mbed_cloud.pagination.PaginatedResponse(UserInvitation)
'''
pass
def _paginate_list(self, after=None, filter=None, order="ASC", limit=50, include=None):
'''Get the details of all user invitations.
:param after: The entity ID to fetch after the given one.
:type after: str
:param filter: Optional API filter for listing resources.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order based on creation time. Acceptable values: ASC, DESC.
Default: ASC.
:type order: str
:param limit: The number of results to return (2-1000). Default 50.
:type limit: int
:param include: Not supported by the API.
:type include: str
:rtype: mbed_cloud.pagination.PaginatedResponse
'''
pass
def read(self):
'''Details of a user invitation.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/user-invitations/{invitation_id}>`_.
:rtype: UserInvitation
'''
pass
| 29 | 18 | 19 | 4 | 6 | 8 | 1 | 1.1 | 1 | 10 | 7 | 0 | 17 | 8 | 17 | 28 | 374 | 95 | 133 | 58 | 89 | 146 | 67 | 36 | 45 | 5 | 2 | 2 | 24 |
2,248 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/accounts/user.py
|
mbed_cloud.foundation.entities.accounts.user.User
|
class User(Entity):
"""Represents the `User` entity in Pelion Device Management"""
# List of fields that are serialised between the API and SDK
_api_fieldnames = [
"account_id",
"active_sessions",
"address",
"created_at",
"creation_time",
"custom_fields",
"email",
"email_verified",
"full_name",
"id",
"is_gtc_accepted",
"is_marketing_accepted",
"is_totp_enabled",
"last_login_time",
"login_history",
"login_profiles",
"password",
"password_changed_time",
"phone_number",
"status",
"totp_scratch_codes",
"updated_at",
"username",
]
# List of fields that are available for the user of the SDK
_sdk_fieldnames = _api_fieldnames
# Renames to be performed by the SDK when receiving data {<API Field Name>: <SDK Field Name>}
_renames = {}
# Renames to be performed by the SDK when sending data {<SDK Field Name>: <API Field Name>}
_renames_to_api = {}
def __init__(
self,
_client=None,
account_id=None,
active_sessions=None,
address=None,
created_at=None,
creation_time=None,
custom_fields=None,
email=None,
email_verified=None,
full_name=None,
id=None,
is_gtc_accepted=None,
is_marketing_accepted=None,
is_totp_enabled=None,
last_login_time=None,
login_history=None,
login_profiles=None,
password=None,
password_changed_time=None,
phone_number=None,
status=None,
totp_scratch_codes=None,
updated_at=None,
username=None,
):
"""Creates a local `User` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param account_id: The ID of the account.
:type account_id: str
:param active_sessions: List of active user sessions.
:type active_sessions: list
:param address: Address.
:type address: str
:param created_at: Creation UTC time RFC3339.
:type created_at: datetime
:param creation_time: A timestamp of the user creation in the storage, in milliseconds.
:type creation_time: int
:param custom_fields: User's account-specific custom properties. The value is a string.
:type custom_fields: dict
:param email: (Required) The email address.
:type email: str
:param email_verified: A flag indicating whether the user's email address has been
verified or not.
:type email_verified: bool
:param full_name: The full name of the user.
:type full_name: str
:param id: (Required) The ID of the user.
:type id: str
:param is_gtc_accepted: A flag indicating that the user has accepted General Terms and
Conditions.
:type is_gtc_accepted: bool
:param is_marketing_accepted: A flag indicating that the user has consented to receive marketing
information.
:type is_marketing_accepted: bool
:param is_totp_enabled: A flag indicating whether two-factor authentication (TOTP) has
been enabled.
:type is_totp_enabled: bool
:param last_login_time: A timestamp of the latest login of the user, in milliseconds.
:type last_login_time: int
:param login_history: Timestamps, succeedings, IP addresses and user agent information
of the last five logins of the user, with timestamps in RFC3339
format.
:type login_history: list
:param login_profiles: A list of login profiles for the user. Specified as the identity
providers the user is associated with.
:type login_profiles: list
:param password: The password when creating a new user. It will be generated when
not present in the request.
:type password: str
:param password_changed_time: A timestamp of the latest change of the user password, in
milliseconds.
:type password_changed_time: int
:param phone_number: Phone number.
:type phone_number: str
:param status: The status of the user. ENROLLING state indicates that the user is
in the middle of the enrollment process. INVITED means that the
user has not accepted the invitation request. RESET means that the
password must be changed immediately. INACTIVE users are locked
out and not permitted to use the system.
:type status: str
:param totp_scratch_codes: A list of scratch codes for the two-factor authentication. Visible
only when 2FA is requested to be enabled or the codes regenerated.
:type totp_scratch_codes: list
:param updated_at: Last update UTC time RFC3339.
:type updated_at: datetime
:param username: A username.
:type username: str
"""
super().__init__(_client=_client)
# inline imports for avoiding circular references and bulk imports
from mbed_cloud.foundation.entities.accounts.active_session import ActiveSession
from mbed_cloud.foundation.entities.accounts.login_history import LoginHistory
from mbed_cloud.foundation.entities.accounts.login_profile import LoginProfile
# fields
self._account_id = fields.StringField(value=account_id)
self._active_sessions = fields.ListField(value=active_sessions, entity=ActiveSession)
self._address = fields.StringField(value=address)
self._created_at = fields.DateTimeField(value=created_at)
self._creation_time = fields.IntegerField(value=creation_time)
self._custom_fields = fields.DictField(value=custom_fields)
self._email = fields.StringField(value=email)
self._email_verified = fields.BooleanField(value=email_verified)
self._full_name = fields.StringField(value=full_name)
self._id = fields.StringField(value=id)
self._is_gtc_accepted = fields.BooleanField(value=is_gtc_accepted)
self._is_marketing_accepted = fields.BooleanField(value=is_marketing_accepted)
self._is_totp_enabled = fields.BooleanField(value=is_totp_enabled)
self._last_login_time = fields.IntegerField(value=last_login_time)
self._login_history = fields.ListField(value=login_history, entity=LoginHistory)
self._login_profiles = fields.ListField(value=login_profiles, entity=LoginProfile)
self._password = fields.StringField(value=password)
self._password_changed_time = fields.IntegerField(value=password_changed_time)
self._phone_number = fields.StringField(value=phone_number)
self._status = fields.StringField(value=status, enum=enums.UserStatusEnum)
self._totp_scratch_codes = fields.ListField(value=totp_scratch_codes)
self._updated_at = fields.DateTimeField(value=updated_at)
self._username = fields.StringField(value=username)
@property
def account_id(self):
"""The ID of the account.
api example: '01619571e2e90242ac12000600000000'
:rtype: str
"""
return self._account_id.value
@property
def active_sessions(self):
"""List of active user sessions.
:rtype: list[ActiveSession]
"""
return self._active_sessions.value
@property
def address(self):
"""Address.
api example: '110 Fulbourn Rd, Cambridge, United Kingdom'
:rtype: str
"""
return self._address.value
@address.setter
def address(self, value):
"""Set value of `address`
:param value: value to set
:type value: str
"""
self._address.set(value)
@property
def created_at(self):
"""Creation UTC time RFC3339.
api example: '2018-02-13T09:35:20Z'
:rtype: datetime
"""
return self._created_at.value
@property
def creation_time(self):
"""A timestamp of the user creation in the storage, in milliseconds.
api example: 1518630727683
:rtype: int
"""
return self._creation_time.value
@property
def custom_fields(self):
"""User's account-specific custom properties. The value is a string.
:rtype: dict
"""
return self._custom_fields.value
@property
def email(self):
"""The email address.
This field must be set when creating a new User Entity.
api example: 'user@arm.com'
:rtype: str
"""
return self._email.value
@email.setter
def email(self, value):
"""Set value of `email`
:param value: value to set
:type value: str
"""
self._email.set(value)
@property
def email_verified(self):
"""A flag indicating whether the user's email address has been verified or not.
api example: True
:rtype: bool
"""
return self._email_verified.value
@property
def full_name(self):
"""The full name of the user.
api example: 'User Doe'
:rtype: str
"""
return self._full_name.value
@full_name.setter
def full_name(self, value):
"""Set value of `full_name`
:param value: value to set
:type value: str
"""
self._full_name.set(value)
@property
def id(self):
"""The ID of the user.
This field must be set when updating or deleting an existing User Entity.
api example: '01619571e2e89242ac12000600000000'
:rtype: str
"""
return self._id.value
@id.setter
def id(self, value):
"""Set value of `id`
:param value: value to set
:type value: str
"""
self._id.set(value)
@property
def is_gtc_accepted(self):
"""A flag indicating that the user has accepted General Terms and Conditions.
api example: True
:rtype: bool
"""
return self._is_gtc_accepted.value
@is_gtc_accepted.setter
def is_gtc_accepted(self, value):
"""Set value of `is_gtc_accepted`
:param value: value to set
:type value: bool
"""
self._is_gtc_accepted.set(value)
@property
def is_marketing_accepted(self):
"""A flag indicating that the user has consented to receive marketing
information.
api example: True
:rtype: bool
"""
return self._is_marketing_accepted.value
@is_marketing_accepted.setter
def is_marketing_accepted(self, value):
"""Set value of `is_marketing_accepted`
:param value: value to set
:type value: bool
"""
self._is_marketing_accepted.set(value)
@property
def is_totp_enabled(self):
"""A flag indicating whether two-factor authentication (TOTP) has been enabled.
api example: True
:rtype: bool
"""
return self._is_totp_enabled.value
@is_totp_enabled.setter
def is_totp_enabled(self, value):
"""Set value of `is_totp_enabled`
:param value: value to set
:type value: bool
"""
self._is_totp_enabled.set(value)
@property
def last_login_time(self):
"""A timestamp of the latest login of the user, in milliseconds.
api example: 1518630727688
:rtype: int
"""
return self._last_login_time.value
@property
def login_history(self):
"""Timestamps, succeedings, IP addresses and user agent information of the last
five logins of the user, with timestamps in RFC3339 format.
:rtype: list[LoginHistory]
"""
return self._login_history.value
@property
def login_profiles(self):
"""A list of login profiles for the user. Specified as the identity providers the
user is associated with.
:rtype: list[LoginProfile]
"""
return self._login_profiles.value
@login_profiles.setter
def login_profiles(self, value):
"""Set value of `login_profiles`
:param value: value to set
:type value: list[LoginProfile]
"""
self._login_profiles.set(value)
@property
def password(self):
"""The password when creating a new user. It will be generated when not present
in the request.
api example: 'PZf9eEUH43DAPE9ULINFeuj'
:rtype: str
"""
return self._password.value
@password.setter
def password(self, value):
"""Set value of `password`
:param value: value to set
:type value: str
"""
self._password.set(value)
@property
def password_changed_time(self):
"""A timestamp of the latest change of the user password, in milliseconds.
api example: 1518630727688
:rtype: int
"""
return self._password_changed_time.value
@property
def phone_number(self):
"""Phone number.
api example: '+44 (1223) 400 400'
:rtype: str
"""
return self._phone_number.value
@phone_number.setter
def phone_number(self, value):
"""Set value of `phone_number`
:param value: value to set
:type value: str
"""
self._phone_number.set(value)
@property
def status(self):
"""The status of the user. ENROLLING state indicates that the user is in the
middle of the enrollment process. INVITED means that the user has not accepted
the invitation request. RESET means that the password must be changed
immediately. INACTIVE users are locked out and not permitted to use the
system.
api example: 'ACTIVE'
:rtype: str
"""
return self._status.value
@status.setter
def status(self, value):
"""Set value of `status`
:param value: value to set
:type value: str
"""
self._status.set(value)
@property
def totp_scratch_codes(self):
"""A list of scratch codes for the two-factor authentication. Visible only when
2FA is requested to be enabled or the codes regenerated.
:rtype: list
"""
return self._totp_scratch_codes.value
@property
def updated_at(self):
"""Last update UTC time RFC3339.
api example: '2018-02-14T15:24:14Z'
:rtype: datetime
"""
return self._updated_at.value
@property
def username(self):
"""A username.
api example: 'admin'
:rtype: str
"""
return self._username.value
@username.setter
def username(self, value):
"""Set value of `username`
:param value: value to set
:type value: str
"""
self._username.set(value)
def create(self, action="create"):
"""Create a new user.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/users>`_.
:param action: Action, either `create` or `invite`.
:type action: str
:rtype: User
"""
# Conditionally setup the message body, fields which have not been set will not be sent to the API.
# This avoids null fields being rejected and allows the default value to be used.
body_params = {}
if self._address.value_set:
body_params["address"] = self._address.to_api()
if self._email.value_set:
body_params["email"] = self._email.to_api()
if self._full_name.value_set:
body_params["full_name"] = self._full_name.to_api()
if self._is_gtc_accepted.value_set:
body_params["is_gtc_accepted"] = self._is_gtc_accepted.to_api()
if self._is_marketing_accepted.value_set:
body_params["is_marketing_accepted"] = self._is_marketing_accepted.to_api()
if self._login_profiles.value_set:
body_params["login_profiles"] = self._login_profiles.to_api()
if self._password.value_set:
body_params["password"] = self._password.to_api()
if self._phone_number.value_set:
body_params["phone_number"] = self._phone_number.to_api()
if self._username.value_set:
body_params["username"] = self._username.to_api()
return self._client.call_api(
method="post",
path="/v3/users",
content_type="application/json",
query_params={"action": fields.StringField(action).to_api()},
body_params=body_params,
unpack=self,
)
def delete(self):
"""Delete a user.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/users/{user_id}>`_.
:rtype: User
"""
return self._client.call_api(
method="delete",
path="/v3/users/{user_id}",
content_type="application/json",
path_params={"user_id": self._id.to_api()},
unpack=self,
)
def list(self, filter=None, order="ASC", max_results=None, page_size=50, include=None):
"""Get the details of all users.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/users>`_.
**API Filters**
The following filters are supported by the API when listing User entities:
+----------------+------+------+------+------+------+------+------+
| Field | eq | neq | gte | lte | in | nin | like |
+================+======+======+======+======+======+======+======+
| email | Y | | | | | | |
+----------------+------+------+------+------+------+------+------+
| login_profiles | Y | | | | | | |
+----------------+------+------+------+------+------+------+------+
| status | Y | | | | Y | Y | |
+----------------+------+------+------+------+------+------+------+
**Example Usage**
.. code-block:: python
from mbed_cloud.foundation import User
from mbed_cloud import ApiFilter
api_filter = ApiFilter()
api_filter.add_filter("email", "eq", <filter value>)
for user in User().list(filter=api_filter):
print(user.email)
:param filter: An optional filter to apply when listing entities, please see the
above **API Filters** table for supported filters.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order based on creation time. Acceptable values: ASC, DESC.
Default: ASC.
:type order: str
:param max_results: Total maximum number of results to retrieve
:type max_results: int
:param page_size: The number of results to return (2-1000). Default 50.
:type page_size: int
:param include: Comma-separated additional data to return. Currently supported:
total_count.
:type include: str
:return: An iterator object which yields instances of an entity.
:rtype: mbed_cloud.pagination.PaginatedResponse(User)
"""
from mbed_cloud.foundation._custom_methods import paginate
from mbed_cloud.foundation import User
from mbed_cloud import ApiFilter
# Be permissive and accept an instance of a dictionary as this was how the Legacy interface worked.
if isinstance(filter, dict):
filter = ApiFilter(filter_definition=filter, field_renames=User._renames_to_api)
# The preferred method is an ApiFilter instance as this should be easier to use.
elif isinstance(filter, ApiFilter):
# If filter renames have not be defined then configure the ApiFilter so that any renames
# performed by the SDK are reversed when the query parameters are created.
if filter.field_renames is None:
filter.field_renames = User._renames_to_api
elif filter is not None:
raise TypeError("The 'filter' parameter may be either 'dict' or 'ApiFilter'.")
return paginate(
self=self,
foreign_key=User,
filter=filter,
order=order,
max_results=max_results,
page_size=page_size,
include=include,
wraps=self._paginate_list,
)
def _paginate_list(self, after=None, filter=None, order="ASC", limit=50, include=None):
"""Get the details of all users.
:param after: The entity ID to fetch after the given one.
:type after: str
:param filter: Optional API filter for listing resources.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order based on creation time. Acceptable values: ASC, DESC.
Default: ASC.
:type order: str
:param limit: The number of results to return (2-1000). Default 50.
:type limit: int
:param include: Comma-separated additional data to return. Currently supported:
total_count.
:type include: str
:rtype: mbed_cloud.pagination.PaginatedResponse
"""
# Filter query parameters
query_params = filter.to_api() if filter else {}
# Add in other query parameters
query_params["after"] = fields.StringField(after).to_api()
query_params["order"] = fields.StringField(order, enum=enums.UserOrderEnum).to_api()
query_params["limit"] = fields.IntegerField(limit).to_api()
query_params["include"] = fields.StringField(include).to_api()
return self._client.call_api(
method="get", path="/v3/users", content_type="application/json", query_params=query_params, unpack=False
)
def read(self):
"""Details of a user.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/users/{user_id}>`_.
:rtype: User
"""
return self._client.call_api(
method="get",
path="/v3/users/{user_id}",
content_type="application/json",
path_params={"user_id": self._id.to_api()},
unpack=self,
)
def update(self):
"""Update user details.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/users/{user_id}>`_.
:rtype: User
"""
# Conditionally setup the message body, fields which have not been set will not be sent to the API.
# This avoids null fields being rejected and allows the default value to be used.
body_params = {}
if self._address.value_set:
body_params["address"] = self._address.to_api()
if self._full_name.value_set:
body_params["full_name"] = self._full_name.to_api()
if self._is_gtc_accepted.value_set:
body_params["is_gtc_accepted"] = self._is_gtc_accepted.to_api()
if self._is_marketing_accepted.value_set:
body_params["is_marketing_accepted"] = self._is_marketing_accepted.to_api()
if self._is_totp_enabled.value_set:
body_params["is_totp_enabled"] = self._is_totp_enabled.to_api()
if self._login_profiles.value_set:
body_params["login_profiles"] = self._login_profiles.to_api()
if self._phone_number.value_set:
body_params["phone_number"] = self._phone_number.to_api()
if self._username.value_set:
body_params["username"] = self._username.to_api()
return self._client.call_api(
method="put",
path="/v3/users/{user_id}",
content_type="application/json",
body_params=body_params,
path_params={"user_id": self._id.to_api()},
unpack=self,
)
|
class User(Entity):
'''Represents the `User` entity in Pelion Device Management'''
def __init__(
self,
_client=None,
account_id=None,
active_sessions=None,
address=None,
created_at=None,
creation_time=None,
custom_fields=None,
email=None,
email_verified=None,
full_name=None,
id=None,
is_gtc_accepted=None,
is_marketing_accepted=None,
is_totp_enabled=None,
last_login_time=None,
login_history=None,
login_profiles=None,
password=None,
password_changed_time=None,
phone_number=None,
status=None,
totp_scratch_codes=None,
updated_at=None,
username=None,
):
'''Creates a local `User` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param account_id: The ID of the account.
:type account_id: str
:param active_sessions: List of active user sessions.
:type active_sessions: list
:param address: Address.
:type address: str
:param created_at: Creation UTC time RFC3339.
:type created_at: datetime
:param creation_time: A timestamp of the user creation in the storage, in milliseconds.
:type creation_time: int
:param custom_fields: User's account-specific custom properties. The value is a string.
:type custom_fields: dict
:param email: (Required) The email address.
:type email: str
:param email_verified: A flag indicating whether the user's email address has been
verified or not.
:type email_verified: bool
:param full_name: The full name of the user.
:type full_name: str
:param id: (Required) The ID of the user.
:type id: str
:param is_gtc_accepted: A flag indicating that the user has accepted General Terms and
Conditions.
:type is_gtc_accepted: bool
:param is_marketing_accepted: A flag indicating that the user has consented to receive marketing
information.
:type is_marketing_accepted: bool
:param is_totp_enabled: A flag indicating whether two-factor authentication (TOTP) has
been enabled.
:type is_totp_enabled: bool
:param last_login_time: A timestamp of the latest login of the user, in milliseconds.
:type last_login_time: int
:param login_history: Timestamps, succeedings, IP addresses and user agent information
of the last five logins of the user, with timestamps in RFC3339
format.
:type login_history: list
:param login_profiles: A list of login profiles for the user. Specified as the identity
providers the user is associated with.
:type login_profiles: list
:param password: The password when creating a new user. It will be generated when
not present in the request.
:type password: str
:param password_changed_time: A timestamp of the latest change of the user password, in
milliseconds.
:type password_changed_time: int
:param phone_number: Phone number.
:type phone_number: str
:param status: The status of the user. ENROLLING state indicates that the user is
in the middle of the enrollment process. INVITED means that the
user has not accepted the invitation request. RESET means that the
password must be changed immediately. INACTIVE users are locked
out and not permitted to use the system.
:type status: str
:param totp_scratch_codes: A list of scratch codes for the two-factor authentication. Visible
only when 2FA is requested to be enabled or the codes regenerated.
:type totp_scratch_codes: list
:param updated_at: Last update UTC time RFC3339.
:type updated_at: datetime
:param username: A username.
:type username: str
'''
pass
@property
def account_id(self):
'''The ID of the account.
api example: '01619571e2e90242ac12000600000000'
:rtype: str
'''
pass
@property
def active_sessions(self):
'''List of active user sessions.
:rtype: list[ActiveSession]
'''
pass
@property
def address(self):
'''Address.
api example: '110 Fulbourn Rd, Cambridge, United Kingdom'
:rtype: str
'''
pass
@address.setter
def address(self):
'''Set value of `address`
:param value: value to set
:type value: str
'''
pass
@property
def created_at(self):
'''Creation UTC time RFC3339.
api example: '2018-02-13T09:35:20Z'
:rtype: datetime
'''
pass
@property
def creation_time(self):
'''A timestamp of the user creation in the storage, in milliseconds.
api example: 1518630727683
:rtype: int
'''
pass
@property
def custom_fields(self):
'''User's account-specific custom properties. The value is a string.
:rtype: dict
'''
pass
@property
def email(self):
'''The email address.
This field must be set when creating a new User Entity.
api example: 'user@arm.com'
:rtype: str
'''
pass
@email.setter
def email(self):
'''Set value of `email`
:param value: value to set
:type value: str
'''
pass
@property
def email_verified(self):
'''A flag indicating whether the user's email address has been verified or not.
api example: True
:rtype: bool
'''
pass
@property
def full_name(self):
'''The full name of the user.
api example: 'User Doe'
:rtype: str
'''
pass
@full_name.setter
def full_name(self):
'''Set value of `full_name`
:param value: value to set
:type value: str
'''
pass
@property
def id(self):
'''The ID of the user.
This field must be set when updating or deleting an existing User Entity.
api example: '01619571e2e89242ac12000600000000'
:rtype: str
'''
pass
@id.setter
def id(self):
'''Set value of `id`
:param value: value to set
:type value: str
'''
pass
@property
def is_gtc_accepted(self):
'''A flag indicating that the user has accepted General Terms and Conditions.
api example: True
:rtype: bool
'''
pass
@is_gtc_accepted.setter
def is_gtc_accepted(self):
'''Set value of `is_gtc_accepted`
:param value: value to set
:type value: bool
'''
pass
@property
def is_marketing_accepted(self):
'''A flag indicating that the user has consented to receive marketing
information.
api example: True
:rtype: bool
'''
pass
@is_marketing_accepted.setter
def is_marketing_accepted(self):
'''Set value of `is_marketing_accepted`
:param value: value to set
:type value: bool
'''
pass
@property
def is_totp_enabled(self):
'''A flag indicating whether two-factor authentication (TOTP) has been enabled.
api example: True
:rtype: bool
'''
pass
@is_totp_enabled.setter
def is_totp_enabled(self):
'''Set value of `is_totp_enabled`
:param value: value to set
:type value: bool
'''
pass
@property
def last_login_time(self):
'''A timestamp of the latest login of the user, in milliseconds.
api example: 1518630727688
:rtype: int
'''
pass
@property
def login_history(self):
'''Timestamps, succeedings, IP addresses and user agent information of the last
five logins of the user, with timestamps in RFC3339 format.
:rtype: list[LoginHistory]
'''
pass
@property
def login_profiles(self):
'''A list of login profiles for the user. Specified as the identity providers the
user is associated with.
:rtype: list[LoginProfile]
'''
pass
@login_profiles.setter
def login_profiles(self):
'''Set value of `login_profiles`
:param value: value to set
:type value: list[LoginProfile]
'''
pass
@property
def password(self):
'''The password when creating a new user. It will be generated when not present
in the request.
api example: 'PZf9eEUH43DAPE9ULINFeuj'
:rtype: str
'''
pass
@password.setter
def password(self):
'''Set value of `password`
:param value: value to set
:type value: str
'''
pass
@property
def password_changed_time(self):
'''A timestamp of the latest change of the user password, in milliseconds.
api example: 1518630727688
:rtype: int
'''
pass
@property
def phone_number(self):
'''Phone number.
api example: '+44 (1223) 400 400'
:rtype: str
'''
pass
@phone_number.setter
def phone_number(self):
'''Set value of `phone_number`
:param value: value to set
:type value: str
'''
pass
@property
def status(self):
'''The status of the user. ENROLLING state indicates that the user is in the
middle of the enrollment process. INVITED means that the user has not accepted
the invitation request. RESET means that the password must be changed
immediately. INACTIVE users are locked out and not permitted to use the
system.
api example: 'ACTIVE'
:rtype: str
'''
pass
@status.setter
def status(self):
'''Set value of `status`
:param value: value to set
:type value: str
'''
pass
@property
def totp_scratch_codes(self):
'''A list of scratch codes for the two-factor authentication. Visible only when
2FA is requested to be enabled or the codes regenerated.
:rtype: list
'''
pass
@property
def updated_at(self):
'''Last update UTC time RFC3339.
api example: '2018-02-14T15:24:14Z'
:rtype: datetime
'''
pass
@property
def username(self):
'''A username.
api example: 'admin'
:rtype: str
'''
pass
@username.setter
def username(self):
'''Set value of `username`
:param value: value to set
:type value: str
'''
pass
def created_at(self):
'''Create a new user.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/users>`_.
:param action: Action, either `create` or `invite`.
:type action: str
:rtype: User
'''
pass
def delete(self):
'''Delete a user.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/users/{user_id}>`_.
:rtype: User
'''
pass
def list(self, filter=None, order="ASC", max_results=None, page_size=50, include=None):
'''Get the details of all users.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/users>`_.
**API Filters**
The following filters are supported by the API when listing User entities:
+----------------+------+------+------+------+------+------+------+
| Field | eq | neq | gte | lte | in | nin | like |
+================+======+======+======+======+======+======+======+
| email | Y | | | | | | |
+----------------+------+------+------+------+------+------+------+
| login_profiles | Y | | | | | | |
+----------------+------+------+------+------+------+------+------+
| status | Y | | | | Y | Y | |
+----------------+------+------+------+------+------+------+------+
**Example Usage**
.. code-block:: python
from mbed_cloud.foundation import User
from mbed_cloud import ApiFilter
api_filter = ApiFilter()
api_filter.add_filter("email", "eq", <filter value>)
for user in User().list(filter=api_filter):
print(user.email)
:param filter: An optional filter to apply when listing entities, please see the
above **API Filters** table for supported filters.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order based on creation time. Acceptable values: ASC, DESC.
Default: ASC.
:type order: str
:param max_results: Total maximum number of results to retrieve
:type max_results: int
:param page_size: The number of results to return (2-1000). Default 50.
:type page_size: int
:param include: Comma-separated additional data to return. Currently supported:
total_count.
:type include: str
:return: An iterator object which yields instances of an entity.
:rtype: mbed_cloud.pagination.PaginatedResponse(User)
'''
pass
def _paginate_list(self, after=None, filter=None, order="ASC", limit=50, include=None):
'''Get the details of all users.
:param after: The entity ID to fetch after the given one.
:type after: str
:param filter: Optional API filter for listing resources.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order based on creation time. Acceptable values: ASC, DESC.
Default: ASC.
:type order: str
:param limit: The number of results to return (2-1000). Default 50.
:type limit: int
:param include: Comma-separated additional data to return. Currently supported:
total_count.
:type include: str
:rtype: mbed_cloud.pagination.PaginatedResponse
'''
pass
def read(self):
'''Details of a user.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/users/{user_id}>`_.
:rtype: User
'''
pass
def updated_at(self):
'''Update user details.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/users/{user_id}>`_.
:rtype: User
'''
pass
| 78 | 43 | 16 | 3 | 5 | 7 | 2 | 1.04 | 1 | 15 | 12 | 0 | 42 | 23 | 42 | 53 | 771 | 183 | 288 | 140 | 178 | 300 | 164 | 79 | 115 | 10 | 2 | 2 | 64 |
2,249 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/accounts/subtenant_user_invitation.py
|
mbed_cloud.foundation.entities.accounts.subtenant_user_invitation.SubtenantUserInvitation
|
class SubtenantUserInvitation(Entity):
"""Represents the `SubtenantUserInvitation` entity in Pelion Device Management"""
# List of fields that are serialised between the API and SDK
_api_fieldnames = [
"account_id",
"created_at",
"email",
"expiration",
"id",
"login_profiles",
"updated_at",
"user_id",
]
# List of fields that are available for the user of the SDK
_sdk_fieldnames = _api_fieldnames
# Renames to be performed by the SDK when receiving data {<API Field Name>: <SDK Field Name>}
_renames = {}
# Renames to be performed by the SDK when sending data {<SDK Field Name>: <API Field Name>}
_renames_to_api = {}
def __init__(
self,
_client=None,
account_id=None,
created_at=None,
email=None,
expiration=None,
id=None,
login_profiles=None,
updated_at=None,
user_id=None,
):
"""Creates a local `SubtenantUserInvitation` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param account_id: (Required) The ID of the account the user is invited to.
:type account_id: str
:param created_at: Creation UTC time RFC3339.
:type created_at: datetime
:param email: (Required) Email address of the invited user.
:type email: str
:param expiration: Invitation expiration as UTC time RFC3339.
:type expiration: datetime
:param id: (Required) The ID of the invitation.
:type id: str
:param login_profiles: A list of login profiles for the user. Specified as the identity
providers the user is associated with.
:type login_profiles: list
:param updated_at: Last update UTC time RFC3339.
:type updated_at: datetime
:param user_id: The ID of the invited user.
:type user_id: str
"""
super().__init__(_client=_client)
# inline imports for avoiding circular references and bulk imports
from mbed_cloud.foundation.entities.accounts.login_profile import LoginProfile
# fields
self._account_id = fields.StringField(value=account_id)
self._created_at = fields.DateTimeField(value=created_at)
self._email = fields.StringField(value=email)
self._expiration = fields.DateTimeField(value=expiration)
self._id = fields.StringField(value=id)
self._login_profiles = fields.ListField(value=login_profiles, entity=LoginProfile)
self._updated_at = fields.DateTimeField(value=updated_at)
self._user_id = fields.StringField(value=user_id)
@property
def account_id(self):
"""The ID of the account the user is invited to.
This field must be set when creating a new SubtenantUserInvitation Entity.
api example: '01619571e2e90242ac12000600000000'
:rtype: str
"""
return self._account_id.value
@account_id.setter
def account_id(self, value):
"""Set value of `account_id`
:param value: value to set
:type value: str
"""
self._account_id.set(value)
@property
def created_at(self):
"""Creation UTC time RFC3339.
api example: '2018-02-13T09:35:20Z'
:rtype: datetime
"""
return self._created_at.value
@property
def email(self):
"""Email address of the invited user.
This field must be set when creating a new SubtenantUserInvitation Entity.
api example: 'friend@arm.com'
:rtype: str
"""
return self._email.value
@email.setter
def email(self, value):
"""Set value of `email`
:param value: value to set
:type value: str
"""
self._email.set(value)
@property
def expiration(self):
"""Invitation expiration as UTC time RFC3339.
api example: '2018-02-14T15:24:14Z'
:rtype: datetime
"""
return self._expiration.value
@property
def id(self):
"""The ID of the invitation.
This field must be set when updating or deleting an existing SubtenantUserInvitation Entity.
api example: '01619571e2e89242ac12000600000000'
:rtype: str
"""
return self._id.value
@id.setter
def id(self, value):
"""Set value of `id`
:param value: value to set
:type value: str
"""
self._id.set(value)
@property
def login_profiles(self):
"""A list of login profiles for the user. Specified as the identity providers the
user is associated with.
:rtype: list[LoginProfile]
"""
return self._login_profiles.value
@login_profiles.setter
def login_profiles(self, value):
"""Set value of `login_profiles`
:param value: value to set
:type value: list[LoginProfile]
"""
self._login_profiles.set(value)
@property
def updated_at(self):
"""Last update UTC time RFC3339.
api example: '2018-02-14T15:24:14Z'
:rtype: datetime
"""
return self._updated_at.value
@property
def user_id(self):
"""The ID of the invited user.
api example: '01619571e2e90242ac12000600000000'
:rtype: str
"""
return self._user_id.value
def create(self, valid_for_days=30):
"""Create a user invitation.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/user-invitations>`_.
:param valid_for_days: Specifies how many days the invitation will be valid for.
:type valid_for_days: int
:rtype: SubtenantUserInvitation
"""
# Conditionally setup the message body, fields which have not been set will not be sent to the API.
# This avoids null fields being rejected and allows the default value to be used.
body_params = {}
if self._email.value_set:
body_params["email"] = self._email.to_api()
if self._login_profiles.value_set:
body_params["login_profiles"] = self._login_profiles.to_api()
# Method parameters are unconditionally sent even if set to None
body_params["valid_for_days"] = fields.IntegerField(valid_for_days).to_api()
return self._client.call_api(
method="post",
path="/v3/accounts/{account_id}/user-invitations",
content_type="application/json",
path_params={"account_id": self._account_id.to_api()},
body_params=body_params,
unpack=self,
)
def delete(self):
"""Delete a user invitation.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/user-invitations/{invitation_id}>`_.
:rtype: SubtenantUserInvitation
"""
return self._client.call_api(
method="delete",
path="/v3/accounts/{account_id}/user-invitations/{invitation_id}",
content_type="application/json",
path_params={"account_id": self._account_id.to_api(), "invitation_id": self._id.to_api()},
unpack=self,
)
def read(self):
"""Details of a user invitation.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/user-invitations/{invitation_id}>`_.
:rtype: SubtenantUserInvitation
"""
return self._client.call_api(
method="get",
path="/v3/accounts/{account_id}/user-invitations/{invitation_id}",
content_type="application/json",
path_params={"account_id": self._account_id.to_api(), "invitation_id": self._id.to_api()},
unpack=self,
)
|
class SubtenantUserInvitation(Entity):
'''Represents the `SubtenantUserInvitation` entity in Pelion Device Management'''
def __init__(
self,
_client=None,
account_id=None,
created_at=None,
email=None,
expiration=None,
id=None,
login_profiles=None,
updated_at=None,
user_id=None,
):
'''Creates a local `SubtenantUserInvitation` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param account_id: (Required) The ID of the account the user is invited to.
:type account_id: str
:param created_at: Creation UTC time RFC3339.
:type created_at: datetime
:param email: (Required) Email address of the invited user.
:type email: str
:param expiration: Invitation expiration as UTC time RFC3339.
:type expiration: datetime
:param id: (Required) The ID of the invitation.
:type id: str
:param login_profiles: A list of login profiles for the user. Specified as the identity
providers the user is associated with.
:type login_profiles: list
:param updated_at: Last update UTC time RFC3339.
:type updated_at: datetime
:param user_id: The ID of the invited user.
:type user_id: str
'''
pass
@property
def account_id(self):
'''The ID of the account the user is invited to.
This field must be set when creating a new SubtenantUserInvitation Entity.
api example: '01619571e2e90242ac12000600000000'
:rtype: str
'''
pass
@account_id.setter
def account_id(self):
'''Set value of `account_id`
:param value: value to set
:type value: str
'''
pass
@property
def created_at(self):
'''Creation UTC time RFC3339.
api example: '2018-02-13T09:35:20Z'
:rtype: datetime
'''
pass
@property
def email(self):
'''Email address of the invited user.
This field must be set when creating a new SubtenantUserInvitation Entity.
api example: 'friend@arm.com'
:rtype: str
'''
pass
@email.setter
def email(self):
'''Set value of `email`
:param value: value to set
:type value: str
'''
pass
@property
def expiration(self):
'''Invitation expiration as UTC time RFC3339.
api example: '2018-02-14T15:24:14Z'
:rtype: datetime
'''
pass
@property
def id(self):
'''The ID of the invitation.
This field must be set when updating or deleting an existing SubtenantUserInvitation Entity.
api example: '01619571e2e89242ac12000600000000'
:rtype: str
'''
pass
@id.setter
def id(self):
'''Set value of `id`
:param value: value to set
:type value: str
'''
pass
@property
def login_profiles(self):
'''A list of login profiles for the user. Specified as the identity providers the
user is associated with.
:rtype: list[LoginProfile]
'''
pass
@login_profiles.setter
def login_profiles(self):
'''Set value of `login_profiles`
:param value: value to set
:type value: list[LoginProfile]
'''
pass
@property
def updated_at(self):
'''Last update UTC time RFC3339.
api example: '2018-02-14T15:24:14Z'
:rtype: datetime
'''
pass
@property
def user_id(self):
'''The ID of the invited user.
api example: '01619571e2e90242ac12000600000000'
:rtype: str
'''
pass
def created_at(self):
'''Create a user invitation.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/user-invitations>`_.
:param valid_for_days: Specifies how many days the invitation will be valid for.
:type valid_for_days: int
:rtype: SubtenantUserInvitation
'''
pass
def delete(self):
'''Delete a user invitation.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/user-invitations/{invitation_id}>`_.
:rtype: SubtenantUserInvitation
'''
pass
def read(self):
'''Details of a user invitation.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/user-invitations/{invitation_id}>`_.
:rtype: SubtenantUserInvitation
'''
pass
| 29 | 17 | 14 | 3 | 5 | 6 | 1 | 0.96 | 1 | 6 | 5 | 0 | 16 | 8 | 16 | 27 | 274 | 72 | 103 | 54 | 62 | 99 | 52 | 31 | 34 | 3 | 2 | 1 | 18 |
2,250 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/accounts/subtenant_user.py
|
mbed_cloud.foundation.entities.accounts.subtenant_user.SubtenantUser
|
class SubtenantUser(Entity):
"""Represents the `SubtenantUser` entity in Pelion Device Management"""
# List of fields that are serialised between the API and SDK
_api_fieldnames = [
"account_id",
"active_sessions",
"address",
"created_at",
"creation_time",
"custom_fields",
"email",
"email_verified",
"full_name",
"id",
"is_gtc_accepted",
"is_marketing_accepted",
"is_totp_enabled",
"last_login_time",
"login_history",
"login_profiles",
"password",
"password_changed_time",
"phone_number",
"status",
"totp_scratch_codes",
"updated_at",
"username",
]
# List of fields that are available for the user of the SDK
_sdk_fieldnames = _api_fieldnames
# Renames to be performed by the SDK when receiving data {<API Field Name>: <SDK Field Name>}
_renames = {}
# Renames to be performed by the SDK when sending data {<SDK Field Name>: <API Field Name>}
_renames_to_api = {}
def __init__(
self,
_client=None,
account_id=None,
active_sessions=None,
address=None,
created_at=None,
creation_time=None,
custom_fields=None,
email=None,
email_verified=None,
full_name=None,
id=None,
is_gtc_accepted=None,
is_marketing_accepted=None,
is_totp_enabled=None,
last_login_time=None,
login_history=None,
login_profiles=None,
password=None,
password_changed_time=None,
phone_number=None,
status=None,
totp_scratch_codes=None,
updated_at=None,
username=None,
):
"""Creates a local `SubtenantUser` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param account_id: (Required) The ID of the account.
:type account_id: str
:param active_sessions: List of active user sessions.
:type active_sessions: list
:param address: Address.
:type address: str
:param created_at: Creation UTC time RFC3339.
:type created_at: datetime
:param creation_time: A timestamp of the user creation in the storage, in milliseconds.
:type creation_time: int
:param custom_fields: User's account-specific custom properties. The value is a string.
:type custom_fields: dict
:param email: (Required) The email address.
:type email: str
:param email_verified: A flag indicating whether the user's email address has been
verified or not.
:type email_verified: bool
:param full_name: The full name of the user.
:type full_name: str
:param id: (Required) The ID of the user.
:type id: str
:param is_gtc_accepted: A flag indicating that the user has accepted General Terms and
Conditions.
:type is_gtc_accepted: bool
:param is_marketing_accepted: A flag indicating that the user has consented to receive marketing
information.
:type is_marketing_accepted: bool
:param is_totp_enabled: A flag indicating whether two-factor authentication (TOTP) has
been enabled.
:type is_totp_enabled: bool
:param last_login_time: A timestamp of the latest login of the user, in milliseconds.
:type last_login_time: int
:param login_history: Timestamps, succeedings, IP addresses and user agent information
of the last five logins of the user, with timestamps in RFC3339
format.
:type login_history: list
:param login_profiles: A list of login profiles for the user. Specified as the identity
providers the user is associated with.
:type login_profiles: list
:param password: The password when creating a new user. It will be generated when
not present in the request.
:type password: str
:param password_changed_time: A timestamp of the latest change of the user password, in
milliseconds.
:type password_changed_time: int
:param phone_number: Phone number.
:type phone_number: str
:param status: The status of the user. ENROLLING state indicates that the user is
in the middle of the enrollment process. INVITED means that the
user has not accepted the invitation request. RESET means that the
password must be changed immediately. INACTIVE users are locked
out and not permitted to use the system.
:type status: str
:param totp_scratch_codes: A list of scratch codes for the two-factor authentication. Visible
only when 2FA is requested to be enabled or the codes regenerated.
:type totp_scratch_codes: list
:param updated_at: Last update UTC time RFC3339.
:type updated_at: datetime
:param username: A username.
:type username: str
"""
super().__init__(_client=_client)
# inline imports for avoiding circular references and bulk imports
from mbed_cloud.foundation.entities.accounts.active_session import ActiveSession
from mbed_cloud.foundation.entities.accounts.login_history import LoginHistory
from mbed_cloud.foundation.entities.accounts.login_profile import LoginProfile
# fields
self._account_id = fields.StringField(value=account_id)
self._active_sessions = fields.ListField(value=active_sessions, entity=ActiveSession)
self._address = fields.StringField(value=address)
self._created_at = fields.DateTimeField(value=created_at)
self._creation_time = fields.IntegerField(value=creation_time)
self._custom_fields = fields.DictField(value=custom_fields)
self._email = fields.StringField(value=email)
self._email_verified = fields.BooleanField(value=email_verified)
self._full_name = fields.StringField(value=full_name)
self._id = fields.StringField(value=id)
self._is_gtc_accepted = fields.BooleanField(value=is_gtc_accepted)
self._is_marketing_accepted = fields.BooleanField(value=is_marketing_accepted)
self._is_totp_enabled = fields.BooleanField(value=is_totp_enabled)
self._last_login_time = fields.IntegerField(value=last_login_time)
self._login_history = fields.ListField(value=login_history, entity=LoginHistory)
self._login_profiles = fields.ListField(value=login_profiles, entity=LoginProfile)
self._password = fields.StringField(value=password)
self._password_changed_time = fields.IntegerField(value=password_changed_time)
self._phone_number = fields.StringField(value=phone_number)
self._status = fields.StringField(value=status, enum=enums.SubtenantUserStatusEnum)
self._totp_scratch_codes = fields.ListField(value=totp_scratch_codes)
self._updated_at = fields.DateTimeField(value=updated_at)
self._username = fields.StringField(value=username)
@property
def account_id(self):
"""The ID of the account.
This field must be set when creating a new SubtenantUser Entity.
api example: '01619571e2e90242ac12000600000000'
:rtype: str
"""
return self._account_id.value
@account_id.setter
def account_id(self, value):
"""Set value of `account_id`
:param value: value to set
:type value: str
"""
self._account_id.set(value)
@property
def active_sessions(self):
"""List of active user sessions.
:rtype: list[ActiveSession]
"""
return self._active_sessions.value
@property
def address(self):
"""Address.
api example: '110 Fulbourn Rd, Cambridge, United Kingdom'
:rtype: str
"""
return self._address.value
@address.setter
def address(self, value):
"""Set value of `address`
:param value: value to set
:type value: str
"""
self._address.set(value)
@property
def created_at(self):
"""Creation UTC time RFC3339.
api example: '2018-02-13T09:35:20Z'
:rtype: datetime
"""
return self._created_at.value
@property
def creation_time(self):
"""A timestamp of the user creation in the storage, in milliseconds.
api example: 1518630727683
:rtype: int
"""
return self._creation_time.value
@property
def custom_fields(self):
"""User's account-specific custom properties. The value is a string.
:rtype: dict
"""
return self._custom_fields.value
@property
def email(self):
"""The email address.
This field must be set when creating a new SubtenantUser Entity.
api example: 'user@arm.com'
:rtype: str
"""
return self._email.value
@email.setter
def email(self, value):
"""Set value of `email`
:param value: value to set
:type value: str
"""
self._email.set(value)
@property
def email_verified(self):
"""A flag indicating whether the user's email address has been verified or not.
api example: True
:rtype: bool
"""
return self._email_verified.value
@property
def full_name(self):
"""The full name of the user.
api example: 'User Doe'
:rtype: str
"""
return self._full_name.value
@full_name.setter
def full_name(self, value):
"""Set value of `full_name`
:param value: value to set
:type value: str
"""
self._full_name.set(value)
@property
def id(self):
"""The ID of the user.
This field must be set when updating or deleting an existing SubtenantUser Entity.
api example: '01619571e2e89242ac12000600000000'
:rtype: str
"""
return self._id.value
@id.setter
def id(self, value):
"""Set value of `id`
:param value: value to set
:type value: str
"""
self._id.set(value)
@property
def is_gtc_accepted(self):
"""A flag indicating that the user has accepted General Terms and Conditions.
api example: True
:rtype: bool
"""
return self._is_gtc_accepted.value
@is_gtc_accepted.setter
def is_gtc_accepted(self, value):
"""Set value of `is_gtc_accepted`
:param value: value to set
:type value: bool
"""
self._is_gtc_accepted.set(value)
@property
def is_marketing_accepted(self):
"""A flag indicating that the user has consented to receive marketing
information.
api example: True
:rtype: bool
"""
return self._is_marketing_accepted.value
@is_marketing_accepted.setter
def is_marketing_accepted(self, value):
"""Set value of `is_marketing_accepted`
:param value: value to set
:type value: bool
"""
self._is_marketing_accepted.set(value)
@property
def is_totp_enabled(self):
"""A flag indicating whether two-factor authentication (TOTP) has been enabled.
api example: True
:rtype: bool
"""
return self._is_totp_enabled.value
@is_totp_enabled.setter
def is_totp_enabled(self, value):
"""Set value of `is_totp_enabled`
:param value: value to set
:type value: bool
"""
self._is_totp_enabled.set(value)
@property
def last_login_time(self):
"""A timestamp of the latest login of the user, in milliseconds.
api example: 1518630727688
:rtype: int
"""
return self._last_login_time.value
@property
def login_history(self):
"""Timestamps, succeedings, IP addresses and user agent information of the last
five logins of the user, with timestamps in RFC3339 format.
:rtype: list[LoginHistory]
"""
return self._login_history.value
@property
def login_profiles(self):
"""A list of login profiles for the user. Specified as the identity providers the
user is associated with.
:rtype: list[LoginProfile]
"""
return self._login_profiles.value
@login_profiles.setter
def login_profiles(self, value):
"""Set value of `login_profiles`
:param value: value to set
:type value: list[LoginProfile]
"""
self._login_profiles.set(value)
@property
def password(self):
"""The password when creating a new user. It will be generated when not present
in the request.
api example: 'PZf9eEUH43DAPE9ULINFeuj'
:rtype: str
"""
return self._password.value
@password.setter
def password(self, value):
"""Set value of `password`
:param value: value to set
:type value: str
"""
self._password.set(value)
@property
def password_changed_time(self):
"""A timestamp of the latest change of the user password, in milliseconds.
api example: 1518630727688
:rtype: int
"""
return self._password_changed_time.value
@property
def phone_number(self):
"""Phone number.
api example: '+44 (1223) 400 400'
:rtype: str
"""
return self._phone_number.value
@phone_number.setter
def phone_number(self, value):
"""Set value of `phone_number`
:param value: value to set
:type value: str
"""
self._phone_number.set(value)
@property
def status(self):
"""The status of the user. ENROLLING state indicates that the user is in the
middle of the enrollment process. INVITED means that the user has not accepted
the invitation request. RESET means that the password must be changed
immediately. INACTIVE users are locked out and not permitted to use the
system.
api example: 'ACTIVE'
:rtype: str
"""
return self._status.value
@status.setter
def status(self, value):
"""Set value of `status`
:param value: value to set
:type value: str
"""
self._status.set(value)
@property
def totp_scratch_codes(self):
"""A list of scratch codes for the two-factor authentication. Visible only when
2FA is requested to be enabled or the codes regenerated.
:rtype: list
"""
return self._totp_scratch_codes.value
@property
def updated_at(self):
"""Last update UTC time RFC3339.
api example: '2018-02-14T15:24:14Z'
:rtype: datetime
"""
return self._updated_at.value
@property
def username(self):
"""A username.
api example: 'admin'
:rtype: str
"""
return self._username.value
@username.setter
def username(self, value):
"""Set value of `username`
:param value: value to set
:type value: str
"""
self._username.set(value)
def create(self, action="create"):
"""Create a new user.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/users>`_.
:param action: Create or invite user.
:type action: str
:rtype: SubtenantUser
"""
# Conditionally setup the message body, fields which have not been set will not be sent to the API.
# This avoids null fields being rejected and allows the default value to be used.
body_params = {}
if self._address.value_set:
body_params["address"] = self._address.to_api()
if self._email.value_set:
body_params["email"] = self._email.to_api()
if self._full_name.value_set:
body_params["full_name"] = self._full_name.to_api()
if self._is_gtc_accepted.value_set:
body_params["is_gtc_accepted"] = self._is_gtc_accepted.to_api()
if self._is_marketing_accepted.value_set:
body_params["is_marketing_accepted"] = self._is_marketing_accepted.to_api()
if self._login_profiles.value_set:
body_params["login_profiles"] = self._login_profiles.to_api()
if self._password.value_set:
body_params["password"] = self._password.to_api()
if self._phone_number.value_set:
body_params["phone_number"] = self._phone_number.to_api()
if self._username.value_set:
body_params["username"] = self._username.to_api()
return self._client.call_api(
method="post",
path="/v3/accounts/{account_id}/users",
content_type="application/json",
path_params={"account_id": self._account_id.to_api()},
query_params={"action": fields.StringField(action).to_api()},
body_params=body_params,
unpack=self,
)
def delete(self):
"""Delete a user.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/users/{user_id}>`_.
:rtype: SubtenantUser
"""
return self._client.call_api(
method="delete",
path="/v3/accounts/{account_id}/users/{user_id}",
content_type="application/json",
path_params={"account_id": self._account_id.to_api(), "user_id": self._id.to_api()},
unpack=self,
)
def read(self):
"""Details of the user.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/users/{user_id}>`_.
:rtype: SubtenantUser
"""
return self._client.call_api(
method="get",
path="/v3/accounts/{account_id}/users/{user_id}",
content_type="application/json",
path_params={"account_id": self._account_id.to_api(), "user_id": self._id.to_api()},
unpack=self,
)
def update(self):
"""Update user details.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/users/{user_id}>`_.
:rtype: SubtenantUser
"""
# Conditionally setup the message body, fields which have not been set will not be sent to the API.
# This avoids null fields being rejected and allows the default value to be used.
body_params = {}
if self._address.value_set:
body_params["address"] = self._address.to_api()
if self._full_name.value_set:
body_params["full_name"] = self._full_name.to_api()
if self._is_gtc_accepted.value_set:
body_params["is_gtc_accepted"] = self._is_gtc_accepted.to_api()
if self._is_marketing_accepted.value_set:
body_params["is_marketing_accepted"] = self._is_marketing_accepted.to_api()
if self._is_totp_enabled.value_set:
body_params["is_totp_enabled"] = self._is_totp_enabled.to_api()
if self._login_profiles.value_set:
body_params["login_profiles"] = self._login_profiles.to_api()
if self._phone_number.value_set:
body_params["phone_number"] = self._phone_number.to_api()
if self._username.value_set:
body_params["username"] = self._username.to_api()
return self._client.call_api(
method="put",
path="/v3/accounts/{account_id}/users/{user_id}",
content_type="application/json",
path_params={"account_id": self._account_id.to_api(), "user_id": self._id.to_api()},
body_params=body_params,
unpack=self,
)
def validate_email(self):
"""Validate the user email.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/users/{user_id}/validate-email>`_.
:rtype: SubtenantUser
"""
return self._client.call_api(
method="post",
path="/v3/accounts/{account_id}/users/{user_id}/validate-email",
content_type="application/json",
path_params={"account_id": self._account_id.to_api(), "user_id": self._id.to_api()},
unpack=self,
)
|
class SubtenantUser(Entity):
'''Represents the `SubtenantUser` entity in Pelion Device Management'''
def __init__(
self,
_client=None,
account_id=None,
active_sessions=None,
address=None,
created_at=None,
creation_time=None,
custom_fields=None,
email=None,
email_verified=None,
full_name=None,
id=None,
is_gtc_accepted=None,
is_marketing_accepted=None,
is_totp_enabled=None,
last_login_time=None,
login_history=None,
login_profiles=None,
password=None,
password_changed_time=None,
phone_number=None,
status=None,
totp_scratch_codes=None,
updated_at=None,
username=None,
):
'''Creates a local `SubtenantUser` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param account_id: (Required) The ID of the account.
:type account_id: str
:param active_sessions: List of active user sessions.
:type active_sessions: list
:param address: Address.
:type address: str
:param created_at: Creation UTC time RFC3339.
:type created_at: datetime
:param creation_time: A timestamp of the user creation in the storage, in milliseconds.
:type creation_time: int
:param custom_fields: User's account-specific custom properties. The value is a string.
:type custom_fields: dict
:param email: (Required) The email address.
:type email: str
:param email_verified: A flag indicating whether the user's email address has been
verified or not.
:type email_verified: bool
:param full_name: The full name of the user.
:type full_name: str
:param id: (Required) The ID of the user.
:type id: str
:param is_gtc_accepted: A flag indicating that the user has accepted General Terms and
Conditions.
:type is_gtc_accepted: bool
:param is_marketing_accepted: A flag indicating that the user has consented to receive marketing
information.
:type is_marketing_accepted: bool
:param is_totp_enabled: A flag indicating whether two-factor authentication (TOTP) has
been enabled.
:type is_totp_enabled: bool
:param last_login_time: A timestamp of the latest login of the user, in milliseconds.
:type last_login_time: int
:param login_history: Timestamps, succeedings, IP addresses and user agent information
of the last five logins of the user, with timestamps in RFC3339
format.
:type login_history: list
:param login_profiles: A list of login profiles for the user. Specified as the identity
providers the user is associated with.
:type login_profiles: list
:param password: The password when creating a new user. It will be generated when
not present in the request.
:type password: str
:param password_changed_time: A timestamp of the latest change of the user password, in
milliseconds.
:type password_changed_time: int
:param phone_number: Phone number.
:type phone_number: str
:param status: The status of the user. ENROLLING state indicates that the user is
in the middle of the enrollment process. INVITED means that the
user has not accepted the invitation request. RESET means that the
password must be changed immediately. INACTIVE users are locked
out and not permitted to use the system.
:type status: str
:param totp_scratch_codes: A list of scratch codes for the two-factor authentication. Visible
only when 2FA is requested to be enabled or the codes regenerated.
:type totp_scratch_codes: list
:param updated_at: Last update UTC time RFC3339.
:type updated_at: datetime
:param username: A username.
:type username: str
'''
pass
@property
def account_id(self):
'''The ID of the account.
This field must be set when creating a new SubtenantUser Entity.
api example: '01619571e2e90242ac12000600000000'
:rtype: str
'''
pass
@account_id.setter
def account_id(self):
'''Set value of `account_id`
:param value: value to set
:type value: str
'''
pass
@property
def active_sessions(self):
'''List of active user sessions.
:rtype: list[ActiveSession]
'''
pass
@property
def address(self):
'''Address.
api example: '110 Fulbourn Rd, Cambridge, United Kingdom'
:rtype: str
'''
pass
@address.setter
def address(self):
'''Set value of `address`
:param value: value to set
:type value: str
'''
pass
@property
def created_at(self):
'''Creation UTC time RFC3339.
api example: '2018-02-13T09:35:20Z'
:rtype: datetime
'''
pass
@property
def creation_time(self):
'''A timestamp of the user creation in the storage, in milliseconds.
api example: 1518630727683
:rtype: int
'''
pass
@property
def custom_fields(self):
'''User's account-specific custom properties. The value is a string.
:rtype: dict
'''
pass
@property
def email(self):
'''The email address.
This field must be set when creating a new SubtenantUser Entity.
api example: 'user@arm.com'
:rtype: str
'''
pass
@email.setter
def email(self):
'''Set value of `email`
:param value: value to set
:type value: str
'''
pass
@property
def email_verified(self):
'''A flag indicating whether the user's email address has been verified or not.
api example: True
:rtype: bool
'''
pass
@property
def full_name(self):
'''The full name of the user.
api example: 'User Doe'
:rtype: str
'''
pass
@full_name.setter
def full_name(self):
'''Set value of `full_name`
:param value: value to set
:type value: str
'''
pass
@property
def id(self):
'''The ID of the user.
This field must be set when updating or deleting an existing SubtenantUser Entity.
api example: '01619571e2e89242ac12000600000000'
:rtype: str
'''
pass
@id.setter
def id(self):
'''Set value of `id`
:param value: value to set
:type value: str
'''
pass
@property
def is_gtc_accepted(self):
'''A flag indicating that the user has accepted General Terms and Conditions.
api example: True
:rtype: bool
'''
pass
@is_gtc_accepted.setter
def is_gtc_accepted(self):
'''Set value of `is_gtc_accepted`
:param value: value to set
:type value: bool
'''
pass
@property
def is_marketing_accepted(self):
'''A flag indicating that the user has consented to receive marketing
information.
api example: True
:rtype: bool
'''
pass
@is_marketing_accepted.setter
def is_marketing_accepted(self):
'''Set value of `is_marketing_accepted`
:param value: value to set
:type value: bool
'''
pass
@property
def is_totp_enabled(self):
'''A flag indicating whether two-factor authentication (TOTP) has been enabled.
api example: True
:rtype: bool
'''
pass
@is_totp_enabled.setter
def is_totp_enabled(self):
'''Set value of `is_totp_enabled`
:param value: value to set
:type value: bool
'''
pass
@property
def last_login_time(self):
'''A timestamp of the latest login of the user, in milliseconds.
api example: 1518630727688
:rtype: int
'''
pass
@property
def login_history(self):
'''Timestamps, succeedings, IP addresses and user agent information of the last
five logins of the user, with timestamps in RFC3339 format.
:rtype: list[LoginHistory]
'''
pass
@property
def login_profiles(self):
'''A list of login profiles for the user. Specified as the identity providers the
user is associated with.
:rtype: list[LoginProfile]
'''
pass
@login_profiles.setter
def login_profiles(self):
'''Set value of `login_profiles`
:param value: value to set
:type value: list[LoginProfile]
'''
pass
@property
def password(self):
'''The password when creating a new user. It will be generated when not present
in the request.
api example: 'PZf9eEUH43DAPE9ULINFeuj'
:rtype: str
'''
pass
@password.setter
def password(self):
'''Set value of `password`
:param value: value to set
:type value: str
'''
pass
@property
def password_changed_time(self):
'''A timestamp of the latest change of the user password, in milliseconds.
api example: 1518630727688
:rtype: int
'''
pass
@property
def phone_number(self):
'''Phone number.
api example: '+44 (1223) 400 400'
:rtype: str
'''
pass
@phone_number.setter
def phone_number(self):
'''Set value of `phone_number`
:param value: value to set
:type value: str
'''
pass
@property
def status(self):
'''The status of the user. ENROLLING state indicates that the user is in the
middle of the enrollment process. INVITED means that the user has not accepted
the invitation request. RESET means that the password must be changed
immediately. INACTIVE users are locked out and not permitted to use the
system.
api example: 'ACTIVE'
:rtype: str
'''
pass
@status.setter
def status(self):
'''Set value of `status`
:param value: value to set
:type value: str
'''
pass
@property
def totp_scratch_codes(self):
'''A list of scratch codes for the two-factor authentication. Visible only when
2FA is requested to be enabled or the codes regenerated.
:rtype: list
'''
pass
@property
def updated_at(self):
'''Last update UTC time RFC3339.
api example: '2018-02-14T15:24:14Z'
:rtype: datetime
'''
pass
@property
def username(self):
'''A username.
api example: 'admin'
:rtype: str
'''
pass
@username.setter
def username(self):
'''Set value of `username`
:param value: value to set
:type value: str
'''
pass
def created_at(self):
'''Create a new user.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/users>`_.
:param action: Create or invite user.
:type action: str
:rtype: SubtenantUser
'''
pass
def delete(self):
'''Delete a user.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/users/{user_id}>`_.
:rtype: SubtenantUser
'''
pass
def read(self):
'''Details of the user.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/users/{user_id}>`_.
:rtype: SubtenantUser
'''
pass
def updated_at(self):
'''Update user details.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/users/{user_id}>`_.
:rtype: SubtenantUser
'''
pass
def validate_email(self):
'''Validate the user email.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/users/{user_id}/validate-email>`_.
:rtype: SubtenantUser
'''
pass
| 79 | 43 | 14 | 3 | 5 | 6 | 1 | 0.93 | 1 | 11 | 10 | 0 | 42 | 23 | 42 | 53 | 685 | 164 | 270 | 137 | 162 | 251 | 151 | 75 | 105 | 10 | 2 | 1 | 59 |
2,251 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/accounts/subtenant_api_key.py
|
mbed_cloud.foundation.entities.accounts.subtenant_api_key.SubtenantApiKey
|
class SubtenantApiKey(Entity):
"""Represents the `SubtenantApiKey` entity in Pelion Device Management"""
# List of fields that are serialised between the API and SDK
_api_fieldnames = [
"account_id",
"created_at",
"creation_time",
"id",
"key",
"last_login_time",
"name",
"owner",
"status",
"updated_at",
]
# List of fields that are available for the user of the SDK
_sdk_fieldnames = _api_fieldnames
# Renames to be performed by the SDK when receiving data {<API Field Name>: <SDK Field Name>}
_renames = {}
# Renames to be performed by the SDK when sending data {<SDK Field Name>: <API Field Name>}
_renames_to_api = {}
def __init__(
self,
_client=None,
account_id=None,
created_at=None,
creation_time=None,
id=None,
key=None,
last_login_time=None,
name=None,
owner=None,
status=None,
updated_at=None,
):
"""Creates a local `SubtenantApiKey` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param account_id: (Required) The ID of the account.
:type account_id: str
:param created_at: Creation UTC time RFC3339.
:type created_at: datetime
:param creation_time: The timestamp of the API key creation in the storage, in
milliseconds.
:type creation_time: int
:param id: (Required) The ID of the API key.
:type id: str
:param key: The API key.
:type key: str
:param last_login_time: The timestamp of the latest API key usage, in milliseconds.
:type last_login_time: int
:param name: (Required) The display name for the API key.
:type name: str
:param owner: The owner of this API key, who is the creator by default.
:type owner: str
:param status: The status of the API key.
:type status: str
:param updated_at: Last update UTC time RFC3339.
:type updated_at: datetime
"""
super().__init__(_client=_client)
# inline imports for avoiding circular references and bulk imports
# fields
self._account_id = fields.StringField(value=account_id)
self._created_at = fields.DateTimeField(value=created_at)
self._creation_time = fields.IntegerField(value=creation_time)
self._id = fields.StringField(value=id)
self._key = fields.StringField(value=key)
self._last_login_time = fields.IntegerField(value=last_login_time)
self._name = fields.StringField(value=name)
self._owner = fields.StringField(value=owner)
self._status = fields.StringField(value=status, enum=enums.SubtenantApiKeyStatusEnum)
self._updated_at = fields.DateTimeField(value=updated_at)
@property
def account_id(self):
"""The ID of the account.
This field must be set when creating a new SubtenantApiKey Entity.
api example: '01619571e2e90242ac12000600000000'
:rtype: str
"""
return self._account_id.value
@account_id.setter
def account_id(self, value):
"""Set value of `account_id`
:param value: value to set
:type value: str
"""
self._account_id.set(value)
@property
def created_at(self):
"""Creation UTC time RFC3339.
api example: '2018-02-13T09:35:20Z'
:rtype: datetime
"""
return self._created_at.value
@property
def creation_time(self):
"""The timestamp of the API key creation in the storage, in milliseconds.
api example: 1518630727683
:rtype: int
"""
return self._creation_time.value
@property
def id(self):
"""The ID of the API key.
This field must be set when updating or deleting an existing SubtenantApiKey Entity.
api example: '01619571f7020242ac12000600000000'
:rtype: str
"""
return self._id.value
@id.setter
def id(self, value):
"""Set value of `id`
:param value: value to set
:type value: str
"""
self._id.set(value)
@property
def key(self):
"""The API key.
api example: 'ak_1MDE2MTk1NzFmNmU4MDI0MmFjMTIwMDA2MDAwMDAwMDA01619571f7020242ac120006000000
00'
:rtype: str
"""
return self._key.value
@property
def last_login_time(self):
"""The timestamp of the latest API key usage, in milliseconds.
api example: 1518630727688
:rtype: int
"""
return self._last_login_time.value
@property
def name(self):
"""The display name for the API key.
This field must be set when creating a new SubtenantApiKey Entity.
api example: 'API key gorgon'
:rtype: str
"""
return self._name.value
@name.setter
def name(self, value):
"""Set value of `name`
:param value: value to set
:type value: str
"""
self._name.set(value)
@property
def owner(self):
"""The owner of this API key, who is the creator by default.
api example: '01619571e2e89242ac12000600000000'
:rtype: str
"""
return self._owner.value
@owner.setter
def owner(self, value):
"""Set value of `owner`
:param value: value to set
:type value: str
"""
self._owner.set(value)
@property
def status(self):
"""The status of the API key.
api example: 'ACTIVE'
:rtype: str
"""
return self._status.value
@status.setter
def status(self, value):
"""Set value of `status`
:param value: value to set
:type value: str
"""
self._status.set(value)
@property
def updated_at(self):
"""Last update UTC time RFC3339.
api example: '2018-02-14T15:24:14Z'
:rtype: datetime
"""
return self._updated_at.value
def create(self):
"""Create a new API key.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/api-keys>`_.
:rtype: SubtenantApiKey
"""
# Conditionally setup the message body, fields which have not been set will not be sent to the API.
# This avoids null fields being rejected and allows the default value to be used.
body_params = {}
if self._name.value_set:
body_params["name"] = self._name.to_api()
if self._owner.value_set:
body_params["owner"] = self._owner.to_api()
if self._status.value_set:
body_params["status"] = self._status.to_api()
return self._client.call_api(
method="post",
path="/v3/accounts/{account_id}/api-keys",
content_type="application/json",
path_params={"account_id": self._account_id.to_api()},
body_params=body_params,
unpack=self,
)
def delete(self):
"""Delete the API key.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/api-keys/{apikey_id}>`_.
:rtype: SubtenantApiKey
"""
return self._client.call_api(
method="delete",
path="/v3/accounts/{account_id}/api-keys/{apikey_id}",
content_type="application/json",
path_params={"account_id": self._account_id.to_api(), "apikey_id": self._id.to_api()},
unpack=self,
)
def read(self):
"""Get API key details.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/api-keys/{apikey_id}>`_.
:rtype: SubtenantApiKey
"""
return self._client.call_api(
method="get",
path="/v3/accounts/{account_id}/api-keys/{apikey_id}",
content_type="application/json",
path_params={"account_id": self._account_id.to_api(), "apikey_id": self._id.to_api()},
unpack=self,
)
def update(self):
"""Update API key details.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/api-keys/{apikey_id}>`_.
:rtype: SubtenantApiKey
"""
# Conditionally setup the message body, fields which have not been set will not be sent to the API.
# This avoids null fields being rejected and allows the default value to be used.
body_params = {}
if self._name.value_set:
body_params["name"] = self._name.to_api()
if self._owner.value_set:
body_params["owner"] = self._owner.to_api()
if self._status.value_set:
body_params["status"] = self._status.to_api()
return self._client.call_api(
method="put",
path="/v3/accounts/{account_id}/api-keys/{apikey_id}",
content_type="application/json",
path_params={"account_id": self._account_id.to_api(), "apikey_id": self._id.to_api()},
body_params=body_params,
unpack=self,
)
|
class SubtenantApiKey(Entity):
'''Represents the `SubtenantApiKey` entity in Pelion Device Management'''
def __init__(
self,
_client=None,
account_id=None,
created_at=None,
creation_time=None,
id=None,
key=None,
last_login_time=None,
name=None,
owner=None,
status=None,
updated_at=None,
):
'''Creates a local `SubtenantApiKey` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param account_id: (Required) The ID of the account.
:type account_id: str
:param created_at: Creation UTC time RFC3339.
:type created_at: datetime
:param creation_time: The timestamp of the API key creation in the storage, in
milliseconds.
:type creation_time: int
:param id: (Required) The ID of the API key.
:type id: str
:param key: The API key.
:type key: str
:param last_login_time: The timestamp of the latest API key usage, in milliseconds.
:type last_login_time: int
:param name: (Required) The display name for the API key.
:type name: str
:param owner: The owner of this API key, who is the creator by default.
:type owner: str
:param status: The status of the API key.
:type status: str
:param updated_at: Last update UTC time RFC3339.
:type updated_at: datetime
'''
pass
@property
def account_id(self):
'''The ID of the account.
This field must be set when creating a new SubtenantApiKey Entity.
api example: '01619571e2e90242ac12000600000000'
:rtype: str
'''
pass
@account_id.setter
def account_id(self):
'''Set value of `account_id`
:param value: value to set
:type value: str
'''
pass
@property
def created_at(self):
'''Creation UTC time RFC3339.
api example: '2018-02-13T09:35:20Z'
:rtype: datetime
'''
pass
@property
def creation_time(self):
'''The timestamp of the API key creation in the storage, in milliseconds.
api example: 1518630727683
:rtype: int
'''
pass
@property
def id(self):
'''The ID of the API key.
This field must be set when updating or deleting an existing SubtenantApiKey Entity.
api example: '01619571f7020242ac12000600000000'
:rtype: str
'''
pass
@id.setter
def id(self):
'''Set value of `id`
:param value: value to set
:type value: str
'''
pass
@property
def key(self):
'''The API key.
api example: 'ak_1MDE2MTk1NzFmNmU4MDI0MmFjMTIwMDA2MDAwMDAwMDA01619571f7020242ac120006000000
00'
:rtype: str
'''
pass
@property
def last_login_time(self):
'''The timestamp of the latest API key usage, in milliseconds.
api example: 1518630727688
:rtype: int
'''
pass
@property
def name(self):
'''The display name for the API key.
This field must be set when creating a new SubtenantApiKey Entity.
api example: 'API key gorgon'
:rtype: str
'''
pass
@name.setter
def name(self):
'''Set value of `name`
:param value: value to set
:type value: str
'''
pass
@property
def owner(self):
'''The owner of this API key, who is the creator by default.
api example: '01619571e2e89242ac12000600000000'
:rtype: str
'''
pass
@owner.setter
def owner(self):
'''Set value of `owner`
:param value: value to set
:type value: str
'''
pass
@property
def status(self):
'''The status of the API key.
api example: 'ACTIVE'
:rtype: str
'''
pass
@status.setter
def status(self):
'''Set value of `status`
:param value: value to set
:type value: str
'''
pass
@property
def updated_at(self):
'''Last update UTC time RFC3339.
api example: '2018-02-14T15:24:14Z'
:rtype: datetime
'''
pass
def created_at(self):
'''Create a new API key.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/api-keys>`_.
:rtype: SubtenantApiKey
'''
pass
def delete(self):
'''Delete the API key.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/api-keys/{apikey_id}>`_.
:rtype: SubtenantApiKey
'''
pass
def read(self):
'''Get API key details.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/api-keys/{apikey_id}>`_.
:rtype: SubtenantApiKey
'''
pass
def updated_at(self):
'''Update API key details.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/api-keys/{apikey_id}>`_.
:rtype: SubtenantApiKey
'''
pass
| 36 | 21 | 14 | 3 | 5 | 6 | 1 | 0.89 | 1 | 5 | 4 | 0 | 20 | 10 | 20 | 31 | 340 | 87 | 134 | 65 | 85 | 119 | 69 | 37 | 48 | 4 | 2 | 1 | 26 |
2,252 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/accounts/policy.py
|
mbed_cloud.foundation.entities.accounts.policy.Policy
|
class Policy(Entity):
"""Represents the `Policy` entity in Pelion Device Management"""
# List of fields that are serialised between the API and SDK
_api_fieldnames = ["action", "allow", "feature", "inherited", "resource"]
# List of fields that are available for the user of the SDK
_sdk_fieldnames = _api_fieldnames
# Renames to be performed by the SDK when receiving data {<API Field Name>: <SDK Field Name>}
_renames = {}
# Renames to be performed by the SDK when sending data {<SDK Field Name>: <API Field Name>}
_renames_to_api = {}
def __init__(self, _client=None, action=None, allow=None, feature=None, inherited=None, resource=None):
"""Creates a local `Policy` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param action: Comma-separated list of actions, empty string represents all
actions.
:type action: str
:param allow: True or false controlling whether an action is allowed or not.
:type allow: bool
:param feature: Feature name corresponding to this policy.
:type feature: str
:param inherited: Flag indicating whether this feature is inherited or overwritten
specifically.
:type inherited: bool
:param resource: Resource that is protected by this policy.
:type resource: str
"""
super().__init__(_client=_client)
# inline imports for avoiding circular references and bulk imports
# fields
self._action = fields.StringField(value=action)
self._allow = fields.BooleanField(value=allow)
self._feature = fields.StringField(value=feature)
self._inherited = fields.BooleanField(value=inherited)
self._resource = fields.StringField(value=resource)
@property
def action(self):
"""Comma-separated list of actions, empty string represents all actions.
api example: 'GET'
:rtype: str
"""
return self._action.value
@property
def allow(self):
"""True or false controlling whether an action is allowed or not.
api example: True
:rtype: bool
"""
return self._allow.value
@property
def feature(self):
"""Feature name corresponding to this policy.
api example: 'update-campaigns'
:rtype: str
"""
return self._feature.value
@property
def inherited(self):
"""Flag indicating whether this feature is inherited or overwritten specifically.
:rtype: bool
"""
return self._inherited.value
@property
def resource(self):
"""Resource that is protected by this policy.
api example: '/v3/update-campaign'
:rtype: str
"""
return self._resource.value
|
class Policy(Entity):
'''Represents the `Policy` entity in Pelion Device Management'''
def __init__(self, _client=None, action=None, allow=None, feature=None, inherited=None, resource=None):
'''Creates a local `Policy` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param action: Comma-separated list of actions, empty string represents all
actions.
:type action: str
:param allow: True or false controlling whether an action is allowed or not.
:type allow: bool
:param feature: Feature name corresponding to this policy.
:type feature: str
:param inherited: Flag indicating whether this feature is inherited or overwritten
specifically.
:type inherited: bool
:param resource: Resource that is protected by this policy.
:type resource: str
'''
pass
@property
def action(self):
'''Comma-separated list of actions, empty string represents all actions.
api example: 'GET'
:rtype: str
'''
pass
@property
def allow(self):
'''True or false controlling whether an action is allowed or not.
api example: True
:rtype: bool
'''
pass
@property
def feature(self):
'''Feature name corresponding to this policy.
api example: 'update-campaigns'
:rtype: str
'''
pass
@property
def inherited(self):
'''Flag indicating whether this feature is inherited or overwritten specifically.
:rtype: bool
'''
pass
@property
def resource(self):
'''Resource that is protected by this policy.
api example: '/v3/update-campaign'
:rtype: str
'''
pass
| 12 | 7 | 13 | 3 | 3 | 7 | 1 | 1.67 | 1 | 3 | 2 | 0 | 6 | 5 | 6 | 17 | 102 | 30 | 27 | 21 | 15 | 45 | 22 | 16 | 15 | 1 | 2 | 0 | 6 |
2,253 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/accounts/password_policy.py
|
mbed_cloud.foundation.entities.accounts.password_policy.PasswordPolicy
|
class PasswordPolicy(Entity):
"""Represents the `PasswordPolicy` entity in Pelion Device Management"""
# List of fields that are serialised between the API and SDK
_api_fieldnames = ["minimum_length"]
# List of fields that are available for the user of the SDK
_sdk_fieldnames = _api_fieldnames
# Renames to be performed by the SDK when receiving data {<API Field Name>: <SDK Field Name>}
_renames = {}
# Renames to be performed by the SDK when sending data {<SDK Field Name>: <API Field Name>}
_renames_to_api = {}
def __init__(self, _client=None, minimum_length=None):
"""Creates a local `PasswordPolicy` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param minimum_length: Minimum length for the password.
:type minimum_length: int
"""
super().__init__(_client=_client)
# inline imports for avoiding circular references and bulk imports
# fields
self._minimum_length = fields.IntegerField(value=minimum_length)
@property
def minimum_length(self):
"""Minimum length for the password.
api example: '8'
:rtype: int
"""
return self._minimum_length.value
|
class PasswordPolicy(Entity):
'''Represents the `PasswordPolicy` entity in Pelion Device Management'''
def __init__(self, _client=None, minimum_length=None):
'''Creates a local `PasswordPolicy` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param minimum_length: Minimum length for the password.
:type minimum_length: int
'''
pass
@property
def minimum_length(self):
'''Minimum length for the password.
api example: '8'
:rtype: int
'''
pass
| 4 | 3 | 15 | 5 | 3 | 8 | 1 | 1.82 | 1 | 2 | 1 | 0 | 2 | 1 | 2 | 13 | 46 | 15 | 11 | 9 | 7 | 20 | 10 | 8 | 7 | 1 | 2 | 0 | 2 |
2,254 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/accounts/parent_account.py
|
mbed_cloud.foundation.entities.accounts.parent_account.ParentAccount
|
class ParentAccount(Entity):
"""Represents the `ParentAccount` entity in Pelion Device Management"""
# List of fields that are serialised between the API and SDK
_api_fieldnames = ["admin_email", "admin_name", "id"]
# List of fields that are available for the user of the SDK
_sdk_fieldnames = _api_fieldnames
# Renames to be performed by the SDK when receiving data {<API Field Name>: <SDK Field Name>}
_renames = {}
# Renames to be performed by the SDK when sending data {<SDK Field Name>: <API Field Name>}
_renames_to_api = {}
def __init__(self, _client=None, admin_email=None, admin_name=None, id=None):
"""Creates a local `ParentAccount` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param admin_email: The email address of the admin user who is the contact person of
the parent account.
:type admin_email: str
:param admin_name: The name of the admin user who is the contact person of the parent
account.
:type admin_name: str
:param id: The ID of the parent account.
:type id: str
"""
super().__init__(_client=_client)
# inline imports for avoiding circular references and bulk imports
# fields
self._admin_email = fields.StringField(value=admin_email)
self._admin_name = fields.StringField(value=admin_name)
self._id = fields.StringField(value=id)
@property
def admin_email(self):
"""The email address of the admin user who is the contact person of the parent
account.
api example: 'info@arm.com'
:rtype: str
"""
return self._admin_email.value
@property
def admin_name(self):
"""The name of the admin user who is the contact person of the parent account.
api example: 'J. Doe'
:rtype: str
"""
return self._admin_name.value
@property
def id(self):
"""The ID of the parent account.
api example: '01619571dad80242ac12000600000000'
:rtype: str
"""
return self._id.value
|
class ParentAccount(Entity):
'''Represents the `ParentAccount` entity in Pelion Device Management'''
def __init__(self, _client=None, admin_email=None, admin_name=None, id=None):
'''Creates a local `ParentAccount` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param admin_email: The email address of the admin user who is the contact person of
the parent account.
:type admin_email: str
:param admin_name: The name of the admin user who is the contact person of the parent
account.
:type admin_name: str
:param id: The ID of the parent account.
:type id: str
'''
pass
@property
def admin_email(self):
'''The email address of the admin user who is the contact person of the parent
account.
api example: 'info@arm.com'
:rtype: str
'''
pass
@property
def admin_name(self):
'''The name of the admin user who is the contact person of the parent account.
api example: 'J. Doe'
:rtype: str
'''
pass
@property
def id(self):
'''The ID of the parent account.
api example: '01619571dad80242ac12000600000000'
:rtype: str
'''
pass
| 8 | 5 | 14 | 4 | 3 | 8 | 1 | 1.84 | 1 | 2 | 1 | 0 | 4 | 3 | 4 | 15 | 77 | 23 | 19 | 15 | 11 | 35 | 16 | 12 | 11 | 1 | 2 | 0 | 4 |
2,255 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/accounts/login_profile.py
|
mbed_cloud.foundation.entities.accounts.login_profile.LoginProfile
|
class LoginProfile(Entity):
"""Represents the `LoginProfile` entity in Pelion Device Management"""
# List of fields that are serialised between the API and SDK
_api_fieldnames = ["id", "name"]
# List of fields that are available for the user of the SDK
_sdk_fieldnames = _api_fieldnames
# Renames to be performed by the SDK when receiving data {<API Field Name>: <SDK Field Name>}
_renames = {}
# Renames to be performed by the SDK when sending data {<SDK Field Name>: <API Field Name>}
_renames_to_api = {}
def __init__(self, _client=None, id=None, name=None):
"""Creates a local `LoginProfile` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param id: ID of the identity provider.
:type id: str
:param name: Name of the identity provider.
:type name: str
"""
super().__init__(_client=_client)
# inline imports for avoiding circular references and bulk imports
# fields
self._id = fields.StringField(value=id)
self._name = fields.StringField(value=name)
@property
def id(self):
"""ID of the identity provider.
:rtype: str
"""
return self._id.value
@id.setter
def id(self, value):
"""Set value of `id`
:param value: value to set
:type value: str
"""
self._id.set(value)
@property
def name(self):
"""Name of the identity provider.
:rtype: str
"""
return self._name.value
@name.setter
def name(self, value):
"""Set value of `name`
:param value: value to set
:type value: str
"""
self._name.set(value)
|
class LoginProfile(Entity):
'''Represents the `LoginProfile` entity in Pelion Device Management'''
def __init__(self, _client=None, id=None, name=None):
'''Creates a local `LoginProfile` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param id: ID of the identity provider.
:type id: str
:param name: Name of the identity provider.
:type name: str
'''
pass
@property
def id(self):
'''ID of the identity provider.
:rtype: str
'''
pass
@id.setter
def id(self):
'''Set value of `id`
:param value: value to set
:type value: str
'''
pass
@property
def name(self):
'''Name of the identity provider.
:rtype: str
'''
pass
@name.setter
def name(self):
'''Set value of `name`
:param value: value to set
:type value: str
'''
pass
| 10 | 6 | 11 | 3 | 2 | 5 | 1 | 1.52 | 1 | 2 | 1 | 0 | 5 | 2 | 5 | 16 | 76 | 23 | 21 | 16 | 11 | 32 | 17 | 12 | 11 | 1 | 2 | 0 | 5 |
2,256 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/accounts/login_history.py
|
mbed_cloud.foundation.entities.accounts.login_history.LoginHistory
|
class LoginHistory(Entity):
"""Represents the `LoginHistory` entity in Pelion Device Management"""
# List of fields that are serialised between the API and SDK
_api_fieldnames = ["date", "ip_address", "success", "user_agent"]
# List of fields that are available for the user of the SDK
_sdk_fieldnames = _api_fieldnames
# Renames to be performed by the SDK when receiving data {<API Field Name>: <SDK Field Name>}
_renames = {}
# Renames to be performed by the SDK when sending data {<SDK Field Name>: <API Field Name>}
_renames_to_api = {}
def __init__(self, _client=None, date=None, ip_address=None, success=None, user_agent=None):
"""Creates a local `LoginHistory` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param date: UTC time RFC3339 for this login attempt.
:type date: datetime
:param ip_address: IP address of the client.
:type ip_address: str
:param success: Flag indicating whether login attempt was successful or not.
:type success: bool
:param user_agent: User Agent header from the login request.
:type user_agent: str
"""
super().__init__(_client=_client)
# inline imports for avoiding circular references and bulk imports
# fields
self._date = fields.DateTimeField(value=date)
self._ip_address = fields.StringField(value=ip_address)
self._success = fields.BooleanField(value=success)
self._user_agent = fields.StringField(value=user_agent)
@property
def date(self):
"""UTC time RFC3339 for this login attempt.
api example: '2018-02-14T17:52:07Z'
:rtype: datetime
"""
return self._date.value
@property
def ip_address(self):
"""IP address of the client.
api example: '127.0.0.1'
:rtype: str
"""
return self._ip_address.value
@property
def success(self):
"""Flag indicating whether login attempt was successful or not.
api example: True
:rtype: bool
"""
return self._success.value
@property
def user_agent(self):
"""User Agent header from the login request.
api example: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/41.0.2227.1 Safari/537.36'
:rtype: str
"""
return self._user_agent.value
|
class LoginHistory(Entity):
'''Represents the `LoginHistory` entity in Pelion Device Management'''
def __init__(self, _client=None, date=None, ip_address=None, success=None, user_agent=None):
'''Creates a local `LoginHistory` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param date: UTC time RFC3339 for this login attempt.
:type date: datetime
:param ip_address: IP address of the client.
:type ip_address: str
:param success: Flag indicating whether login attempt was successful or not.
:type success: bool
:param user_agent: User Agent header from the login request.
:type user_agent: str
'''
pass
@property
def date(self):
'''UTC time RFC3339 for this login attempt.
api example: '2018-02-14T17:52:07Z'
:rtype: datetime
'''
pass
@property
def ip_address(self):
'''IP address of the client.
api example: '127.0.0.1'
:rtype: str
'''
pass
@property
def success(self):
'''Flag indicating whether login attempt was successful or not.
api example: True
:rtype: bool
'''
pass
@property
def user_agent(self):
'''User Agent header from the login request.
api example: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/41.0.2227.1 Safari/537.36'
:rtype: str
'''
pass
| 10 | 6 | 13 | 4 | 3 | 7 | 1 | 1.7 | 1 | 4 | 3 | 0 | 5 | 4 | 5 | 16 | 89 | 27 | 23 | 18 | 13 | 39 | 19 | 14 | 13 | 1 | 2 | 0 | 5 |
2,257 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/accounts/enums.py
|
mbed_cloud.foundation.entities.accounts.enums.UserStatusEnum
|
class UserStatusEnum(BaseEnum):
"""Represents expected values of `UserStatusEnum`
This is used by Entities in the "accounts" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
"""
ACTIVE = "ACTIVE"
ENROLLING = "ENROLLING"
INACTIVE = "INACTIVE"
INVITED = "INVITED"
RESET = "RESET"
values = frozenset(("ACTIVE", "ENROLLING", "INACTIVE", "INVITED", "RESET"))
|
class UserStatusEnum(BaseEnum):
'''Represents expected values of `UserStatusEnum`
This is used by Entities in the "accounts" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
'''
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0.86 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 17 | 4 | 7 | 7 | 6 | 6 | 7 | 7 | 6 | 0 | 2 | 0 | 0 |
2,258 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/branding/dark_theme_image.py
|
mbed_cloud.foundation.entities.branding.dark_theme_image.DarkThemeImage
|
class DarkThemeImage(Entity):
"""Represents the `DarkThemeImage` entity in Pelion Device Management"""
# List of fields that are serialised between the API and SDK
_api_fieldnames = ["reference", "static_uri", "updated_at"]
# List of fields that are available for the user of the SDK
_sdk_fieldnames = _api_fieldnames
# Renames to be performed by the SDK when receiving data {<API Field Name>: <SDK Field Name>}
_renames = {}
# Renames to be performed by the SDK when sending data {<SDK Field Name>: <API Field Name>}
_renames_to_api = {}
def __init__(self, _client=None, reference=None, static_uri=None, updated_at=None):
"""Creates a local `DarkThemeImage` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param reference: Name of the image.
:type reference: str
:param static_uri: The static link to the image.
:type static_uri: str
:param updated_at: Last update time in UTC.
:type updated_at: datetime
"""
super().__init__(_client=_client)
# inline imports for avoiding circular references and bulk imports
# fields
self._reference = fields.StringField(value=reference, enum=enums.DarkThemeImageReferenceEnum)
self._static_uri = fields.StringField(value=static_uri)
self._updated_at = fields.DateTimeField(value=updated_at)
@property
def reference(self):
"""Name of the image.
:rtype: str
"""
return self._reference.value
@reference.setter
def reference(self, value):
"""Set value of `reference`
:param value: value to set
:type value: str
"""
self._reference.set(value)
@property
def static_uri(self):
"""The static link to the image.
api example: 'https://static.mbed.com/123456789.jpg'
:rtype: str
"""
return self._static_uri.value
@property
def updated_at(self):
"""Last update time in UTC.
api example: '2018-02-14T15:24:14Z'
:rtype: datetime
"""
return self._updated_at.value
def delete(self):
"""Revert an image to dark theme default.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/branding-images/dark/{reference}/clear>`_.
:rtype: DarkThemeImage
"""
return self._client.call_api(
method="post",
path="/v3/branding-images/dark/{reference}/clear",
content_type="application/json",
path_params={"reference": self._reference.to_api()},
unpack=self,
)
def list(self, filter=None, order=None, max_results=None, page_size=None, include=None):
"""Get metadata of all dark theme images.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/branding-images/dark>`_.
:param filter: Filtering when listing entities is not supported by the API for this
entity.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: The order of the records based on creation time, ASC or DESC. Default
value is ASC
:type order: str
:param max_results: Total maximum number of results to retrieve
:type max_results: int
:param page_size: The number of results to return for each page.
:type page_size: int
:param include: Comma separated additional data to return.
:type include: str
:return: An iterator object which yields instances of an entity.
:rtype: mbed_cloud.pagination.PaginatedResponse(DarkThemeImage)
"""
from mbed_cloud.foundation._custom_methods import paginate
from mbed_cloud.foundation import DarkThemeImage
from mbed_cloud import ApiFilter
# Be permissive and accept an instance of a dictionary as this was how the Legacy interface worked.
if isinstance(filter, dict):
filter = ApiFilter(filter_definition=filter, field_renames=DarkThemeImage._renames_to_api)
# The preferred method is an ApiFilter instance as this should be easier to use.
elif isinstance(filter, ApiFilter):
# If filter renames have not be defined then configure the ApiFilter so that any renames
# performed by the SDK are reversed when the query parameters are created.
if filter.field_renames is None:
filter.field_renames = DarkThemeImage._renames_to_api
elif filter is not None:
raise TypeError("The 'filter' parameter may be either 'dict' or 'ApiFilter'.")
return paginate(
self=self,
foreign_key=DarkThemeImage,
filter=filter,
order=order,
max_results=max_results,
page_size=page_size,
include=include,
wraps=self._paginate_list,
)
def _paginate_list(self, after=None, filter=None, order=None, limit=None, include=None):
"""Get metadata of all dark theme images.
:param after: Not supported by the API.
:type after: str
:param filter: Optional API filter for listing resources.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Not supported by the API.
:type order: str
:param limit: Not supported by the API.
:type limit: int
:param include: Not supported by the API.
:type include: str
:rtype: mbed_cloud.pagination.PaginatedResponse
"""
# Filter query parameters
query_params = filter.to_api() if filter else {}
# Add in other query parameters
return self._client.call_api(
method="get", path="/v3/branding-images/dark", content_type="application/json", unpack=False
)
def read(self):
"""Get metadata of a dark theme image.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/branding-images/dark/{reference}>`_.
:rtype: DarkThemeImage
"""
return self._client.call_api(
method="get",
path="/v3/branding-images/dark/{reference}",
content_type="application/json",
path_params={"reference": self._reference.to_api()},
unpack=self,
)
def update(self, image):
"""Upload a dark theme image.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/branding-images/dark/{reference}/upload-multipart>`_.
:param image: The image in PNG or JPEG format as multipart form data. Files can be
provided as a file object or a path to an existing file on disk.
:type image: file
:rtype: DarkThemeImage
"""
auto_close_image = False
# If image is a string rather than a file, treat as a path and attempt to open the file.
if image and isinstance(image, six.string_types):
image = open(image, "rb")
auto_close_image = True
try:
return self._client.call_api(
method="post",
path="/v3/branding-images/dark/{reference}/upload-multipart",
stream_params={"image": ("image.png", image, "image/png")},
path_params={"reference": self._reference.to_api()},
unpack=self,
)
finally:
# Calling the API may result in an exception being raised so close the files in a finally statement.
# Note: Files are only closed if they were opened by the method.
if auto_close_image:
image.close()
|
class DarkThemeImage(Entity):
'''Represents the `DarkThemeImage` entity in Pelion Device Management'''
def __init__(self, _client=None, reference=None, static_uri=None, updated_at=None):
'''Creates a local `DarkThemeImage` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param reference: Name of the image.
:type reference: str
:param static_uri: The static link to the image.
:type static_uri: str
:param updated_at: Last update time in UTC.
:type updated_at: datetime
'''
pass
@property
def reference(self):
'''Name of the image.
:rtype: str
'''
pass
@reference.setter
def reference(self):
'''Set value of `reference`
:param value: value to set
:type value: str
'''
pass
@property
def static_uri(self):
'''The static link to the image.
api example: 'https://static.mbed.com/123456789.jpg'
:rtype: str
'''
pass
@property
def updated_at(self):
'''Last update time in UTC.
api example: '2018-02-14T15:24:14Z'
:rtype: datetime
'''
pass
def delete(self):
'''Revert an image to dark theme default.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/branding-images/dark/{reference}/clear>`_.
:rtype: DarkThemeImage
'''
pass
def list(self, filter=None, order=None, max_results=None, page_size=None, include=None):
'''Get metadata of all dark theme images.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/branding-images/dark>`_.
:param filter: Filtering when listing entities is not supported by the API for this
entity.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: The order of the records based on creation time, ASC or DESC. Default
value is ASC
:type order: str
:param max_results: Total maximum number of results to retrieve
:type max_results: int
:param page_size: The number of results to return for each page.
:type page_size: int
:param include: Comma separated additional data to return.
:type include: str
:return: An iterator object which yields instances of an entity.
:rtype: mbed_cloud.pagination.PaginatedResponse(DarkThemeImage)
'''
pass
def _paginate_list(self, after=None, filter=None, order=None, limit=None, include=None):
'''Get metadata of all dark theme images.
:param after: Not supported by the API.
:type after: str
:param filter: Optional API filter for listing resources.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Not supported by the API.
:type order: str
:param limit: Not supported by the API.
:type limit: int
:param include: Not supported by the API.
:type include: str
:rtype: mbed_cloud.pagination.PaginatedResponse
'''
pass
def read(self):
'''Get metadata of a dark theme image.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/branding-images/dark/{reference}>`_.
:rtype: DarkThemeImage
'''
pass
def updated_at(self):
'''Upload a dark theme image.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/branding-images/dark/{reference}/upload-multipart>`_.
:param image: The image in PNG or JPEG format as multipart form data. Files can be
provided as a file object or a path to an existing file on disk.
:type image: file
:rtype: DarkThemeImage
'''
pass
| 15 | 11 | 20 | 5 | 7 | 8 | 2 | 1.11 | 1 | 7 | 4 | 0 | 10 | 3 | 10 | 21 | 230 | 61 | 80 | 27 | 62 | 89 | 44 | 23 | 30 | 5 | 2 | 2 | 17 |
2,259 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/accounts/enums.py
|
mbed_cloud.foundation.entities.accounts.enums.UserOrderEnum
|
class UserOrderEnum(BaseEnum):
"""Represents expected values of `UserOrderEnum`
This is used by Entities in the "accounts" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
"""
ASC = "ASC"
DESC = "DESC"
values = frozenset(("ASC", "DESC"))
|
class UserOrderEnum(BaseEnum):
'''Represents expected values of `UserOrderEnum`
This is used by Entities in the "accounts" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
'''
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1.5 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 14 | 4 | 4 | 4 | 3 | 6 | 4 | 4 | 3 | 0 | 2 | 0 | 0 |
2,260 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/accounts/enums.py
|
mbed_cloud.foundation.entities.accounts.enums.SubtenantUserStatusEnum
|
class SubtenantUserStatusEnum(BaseEnum):
"""Represents expected values of `SubtenantUserStatusEnum`
This is used by Entities in the "accounts" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
"""
ACTIVE = "ACTIVE"
ENROLLING = "ENROLLING"
INACTIVE = "INACTIVE"
INVITED = "INVITED"
RESET = "RESET"
values = frozenset(("ACTIVE", "ENROLLING", "INACTIVE", "INVITED", "RESET"))
|
class SubtenantUserStatusEnum(BaseEnum):
'''Represents expected values of `SubtenantUserStatusEnum`
This is used by Entities in the "accounts" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
'''
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0.86 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 17 | 4 | 7 | 7 | 6 | 6 | 7 | 7 | 6 | 0 | 2 | 0 | 0 |
2,261 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/accounts/enums.py
|
mbed_cloud.foundation.entities.accounts.enums.SubtenantApiKeyStatusEnum
|
class SubtenantApiKeyStatusEnum(BaseEnum):
"""Represents expected values of `SubtenantApiKeyStatusEnum`
This is used by Entities in the "accounts" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
"""
ACTIVE = "ACTIVE"
INACTIVE = "INACTIVE"
values = frozenset(("ACTIVE", "INACTIVE"))
|
class SubtenantApiKeyStatusEnum(BaseEnum):
'''Represents expected values of `SubtenantApiKeyStatusEnum`
This is used by Entities in the "accounts" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
'''
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1.5 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 14 | 4 | 4 | 4 | 3 | 6 | 4 | 4 | 3 | 0 | 2 | 0 | 0 |
2,262 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/device_update/enums.py
|
mbed_cloud.foundation.entities.device_update.enums.CampaignStatisticsIdEnum
|
class CampaignStatisticsIdEnum(BaseEnum):
"""Represents expected values of `CampaignStatisticsIdEnum`
This is used by Entities in the "device_update" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
"""
FAIL = "fail"
INFO = "info"
SKIPPED = "skipped"
SUCCESS = "success"
values = frozenset(("fail", "info", "skipped", "success"))
|
class CampaignStatisticsIdEnum(BaseEnum):
'''Represents expected values of `CampaignStatisticsIdEnum`
This is used by Entities in the "device_update" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
'''
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 16 | 4 | 6 | 6 | 5 | 6 | 6 | 6 | 5 | 0 | 2 | 0 | 0 |
2,263 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/accounts/enums.py
|
mbed_cloud.foundation.entities.accounts.enums.ApiKeyStatusEnum
|
class ApiKeyStatusEnum(BaseEnum):
"""Represents expected values of `ApiKeyStatusEnum`
This is used by Entities in the "accounts" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
"""
ACTIVE = "ACTIVE"
INACTIVE = "INACTIVE"
values = frozenset(("ACTIVE", "INACTIVE"))
|
class ApiKeyStatusEnum(BaseEnum):
'''Represents expected values of `ApiKeyStatusEnum`
This is used by Entities in the "accounts" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
'''
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1.5 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 14 | 4 | 4 | 4 | 3 | 6 | 4 | 4 | 3 | 0 | 2 | 0 | 0 |
2,264 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/accounts/enums.py
|
mbed_cloud.foundation.entities.accounts.enums.ApiKeyOrderEnum
|
class ApiKeyOrderEnum(BaseEnum):
"""Represents expected values of `ApiKeyOrderEnum`
This is used by Entities in the "accounts" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
"""
ASC = "ASC"
DESC = "DESC"
values = frozenset(("ASC", "DESC"))
|
class ApiKeyOrderEnum(BaseEnum):
'''Represents expected values of `ApiKeyOrderEnum`
This is used by Entities in the "accounts" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
'''
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1.5 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 14 | 4 | 4 | 4 | 3 | 6 | 4 | 4 | 3 | 0 | 2 | 0 | 0 |
2,265 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/accounts/enums.py
|
mbed_cloud.foundation.entities.accounts.enums.AccountStatusEnum
|
class AccountStatusEnum(BaseEnum):
"""Represents expected values of `AccountStatusEnum`
This is used by Entities in the "accounts" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
"""
ACTIVE = "ACTIVE"
ENROLLING = "ENROLLING"
RESTRICTED = "RESTRICTED"
SUSPENDED = "SUSPENDED"
values = frozenset(("ACTIVE", "ENROLLING", "RESTRICTED", "SUSPENDED"))
|
class AccountStatusEnum(BaseEnum):
'''Represents expected values of `AccountStatusEnum`
This is used by Entities in the "accounts" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
'''
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 16 | 4 | 6 | 6 | 5 | 6 | 6 | 6 | 5 | 0 | 2 | 0 | 0 |
2,266 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/accounts/enums.py
|
mbed_cloud.foundation.entities.accounts.enums.AccountOrderEnum
|
class AccountOrderEnum(BaseEnum):
"""Represents expected values of `AccountOrderEnum`
This is used by Entities in the "accounts" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
"""
ASC = "ASC"
DESC = "DESC"
values = frozenset(("ASC", "DESC"))
|
class AccountOrderEnum(BaseEnum):
'''Represents expected values of `AccountOrderEnum`
This is used by Entities in the "accounts" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
'''
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1.5 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 14 | 4 | 4 | 4 | 3 | 6 | 4 | 4 | 3 | 0 | 2 | 0 | 0 |
2,267 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/accounts/enums.py
|
mbed_cloud.foundation.entities.accounts.enums.AccountMfaStatusEnum
|
class AccountMfaStatusEnum(BaseEnum):
"""Represents expected values of `AccountMfaStatusEnum`
This is used by Entities in the "accounts" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
"""
ENFORCED = "enforced"
OPTIONAL = "optional"
values = frozenset(("enforced", "optional"))
|
class AccountMfaStatusEnum(BaseEnum):
'''Represents expected values of `AccountMfaStatusEnum`
This is used by Entities in the "accounts" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
'''
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1.5 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 14 | 4 | 4 | 4 | 3 | 6 | 4 | 4 | 3 | 0 | 2 | 0 | 0 |
2,268 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/accounts/api_key.py
|
mbed_cloud.foundation.entities.accounts.api_key.ApiKey
|
class ApiKey(Entity):
"""Represents the `ApiKey` entity in Pelion Device Management"""
# List of fields that are serialised between the API and SDK
_api_fieldnames = [
"account_id",
"created_at",
"creation_time",
"id",
"key",
"last_login_time",
"name",
"owner",
"status",
"updated_at",
]
# List of fields that are available for the user of the SDK
_sdk_fieldnames = _api_fieldnames
# Renames to be performed by the SDK when receiving data {<API Field Name>: <SDK Field Name>}
_renames = {}
# Renames to be performed by the SDK when sending data {<SDK Field Name>: <API Field Name>}
_renames_to_api = {}
def __init__(
self,
_client=None,
account_id=None,
created_at=None,
creation_time=None,
id=None,
key=None,
last_login_time=None,
name=None,
owner=None,
status=None,
updated_at=None,
):
"""Creates a local `ApiKey` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param account_id: The ID of the account.
:type account_id: str
:param created_at: Creation UTC time RFC3339.
:type created_at: datetime
:param creation_time: The timestamp of the API key creation in the storage, in
milliseconds.
:type creation_time: int
:param id: (Required) The ID of the API key.
:type id: str
:param key: The API key.
:type key: str
:param last_login_time: The timestamp of the latest API key usage, in milliseconds.
:type last_login_time: int
:param name: (Required) The display name for the API key.
:type name: str
:param owner: The owner of this API key, who is the creator by default.
:type owner: str
:param status: The status of the API key.
:type status: str
:param updated_at: Last update UTC time RFC3339.
:type updated_at: datetime
"""
super().__init__(_client=_client)
# inline imports for avoiding circular references and bulk imports
# fields
self._account_id = fields.StringField(value=account_id)
self._created_at = fields.DateTimeField(value=created_at)
self._creation_time = fields.IntegerField(value=creation_time)
self._id = fields.StringField(value=id)
self._key = fields.StringField(value=key)
self._last_login_time = fields.IntegerField(value=last_login_time)
self._name = fields.StringField(value=name)
self._owner = fields.StringField(value=owner)
self._status = fields.StringField(value=status, enum=enums.ApiKeyStatusEnum)
self._updated_at = fields.DateTimeField(value=updated_at)
@property
def account_id(self):
"""The ID of the account.
api example: '01619571e2e90242ac12000600000000'
:rtype: str
"""
return self._account_id.value
@property
def created_at(self):
"""Creation UTC time RFC3339.
api example: '2018-02-13T09:35:20Z'
:rtype: datetime
"""
return self._created_at.value
@property
def creation_time(self):
"""The timestamp of the API key creation in the storage, in milliseconds.
api example: 1518630727683
:rtype: int
"""
return self._creation_time.value
@property
def id(self):
"""The ID of the API key.
This field must be set when updating or deleting an existing ApiKey Entity.
api example: '01619571f7020242ac12000600000000'
:rtype: str
"""
return self._id.value
@id.setter
def id(self, value):
"""Set value of `id`
:param value: value to set
:type value: str
"""
self._id.set(value)
@property
def key(self):
"""The API key.
api example: 'ak_1MDE2MTk1NzFmNmU4MDI0MmFjMTIwMDA2MDAwMDAwMDA01619571f7020242ac120006000000
00'
:rtype: str
"""
return self._key.value
@property
def last_login_time(self):
"""The timestamp of the latest API key usage, in milliseconds.
api example: 1518630727688
:rtype: int
"""
return self._last_login_time.value
@property
def name(self):
"""The display name for the API key.
This field must be set when creating a new ApiKey Entity.
api example: 'API key gorgon'
:rtype: str
"""
return self._name.value
@name.setter
def name(self, value):
"""Set value of `name`
:param value: value to set
:type value: str
"""
self._name.set(value)
@property
def owner(self):
"""The owner of this API key, who is the creator by default.
api example: '01619571e2e89242ac12000600000000'
:rtype: str
"""
return self._owner.value
@owner.setter
def owner(self, value):
"""Set value of `owner`
:param value: value to set
:type value: str
"""
self._owner.set(value)
@property
def status(self):
"""The status of the API key.
api example: 'ACTIVE'
:rtype: str
"""
return self._status.value
@status.setter
def status(self, value):
"""Set value of `status`
:param value: value to set
:type value: str
"""
self._status.set(value)
@property
def updated_at(self):
"""Last update UTC time RFC3339.
api example: '2018-02-14T15:24:14Z'
:rtype: datetime
"""
return self._updated_at.value
def create(self):
"""Create a new API key.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/api-keys>`_.
:rtype: ApiKey
"""
# Conditionally setup the message body, fields which have not been set will not be sent to the API.
# This avoids null fields being rejected and allows the default value to be used.
body_params = {}
if self._name.value_set:
body_params["name"] = self._name.to_api()
if self._owner.value_set:
body_params["owner"] = self._owner.to_api()
if self._status.value_set:
body_params["status"] = self._status.to_api()
return self._client.call_api(
method="post", path="/v3/api-keys", content_type="application/json", body_params=body_params, unpack=self
)
def delete(self):
"""Delete API key.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/api-keys/{apikey_id}>`_.
:rtype: ApiKey
"""
return self._client.call_api(
method="delete",
path="/v3/api-keys/{apikey_id}",
content_type="application/json",
path_params={"apikey_id": self._id.to_api()},
unpack=self,
)
def list(self, filter=None, order="ASC", max_results=None, page_size=50, include=None):
"""Get all API keys.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/api-keys>`_.
**API Filters**
The following filters are supported by the API when listing ApiKey entities:
+-------+------+------+------+------+------+------+------+
| Field | eq | neq | gte | lte | in | nin | like |
+=======+======+======+======+======+======+======+======+
| key | Y | | | | | | |
+-------+------+------+------+------+------+------+------+
| owner | Y | | | | | | |
+-------+------+------+------+------+------+------+------+
**Example Usage**
.. code-block:: python
from mbed_cloud.foundation import ApiKey
from mbed_cloud import ApiFilter
api_filter = ApiFilter()
api_filter.add_filter("key", "eq", <filter value>)
for api_key in ApiKey().list(filter=api_filter):
print(api_key.key)
:param filter: An optional filter to apply when listing entities, please see the
above **API Filters** table for supported filters.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order based on creation time. Acceptable values: ASC, DESC.
Default: ASC.
:type order: str
:param max_results: Total maximum number of results to retrieve
:type max_results: int
:param page_size: The number of results to return (2-1000). Default 50.
:type page_size: int
:param include: Comma-separated additional data to return. Currently supported:
total_count.
:type include: str
:return: An iterator object which yields instances of an entity.
:rtype: mbed_cloud.pagination.PaginatedResponse(ApiKey)
"""
from mbed_cloud.foundation._custom_methods import paginate
from mbed_cloud.foundation import ApiKey
from mbed_cloud import ApiFilter
# Be permissive and accept an instance of a dictionary as this was how the Legacy interface worked.
if isinstance(filter, dict):
filter = ApiFilter(filter_definition=filter, field_renames=ApiKey._renames_to_api)
# The preferred method is an ApiFilter instance as this should be easier to use.
elif isinstance(filter, ApiFilter):
# If filter renames have not be defined then configure the ApiFilter so that any renames
# performed by the SDK are reversed when the query parameters are created.
if filter.field_renames is None:
filter.field_renames = ApiKey._renames_to_api
elif filter is not None:
raise TypeError("The 'filter' parameter may be either 'dict' or 'ApiFilter'.")
return paginate(
self=self,
foreign_key=ApiKey,
filter=filter,
order=order,
max_results=max_results,
page_size=page_size,
include=include,
wraps=self._paginate_list,
)
def me(self):
"""Get API key details.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/api-keys/me>`_.
:rtype: ApiKey
"""
return self._client.call_api(method="get", path="/v3/api-keys/me", content_type="application/json", unpack=self)
def _paginate_list(self, after=None, filter=None, order="ASC", limit=50, include=None):
"""Get all API keys.
:param after: The entity ID to fetch after the given one.
:type after: str
:param filter: Optional API filter for listing resources.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order based on creation time. Acceptable values: ASC, DESC.
Default: ASC.
:type order: str
:param limit: The number of results to return (2-1000). Default 50.
:type limit: int
:param include: Comma-separated additional data to return. Currently supported:
total_count.
:type include: str
:rtype: mbed_cloud.pagination.PaginatedResponse
"""
# Filter query parameters
query_params = filter.to_api() if filter else {}
# Add in other query parameters
query_params["after"] = fields.StringField(after).to_api()
query_params["order"] = fields.StringField(order, enum=enums.ApiKeyOrderEnum).to_api()
query_params["limit"] = fields.IntegerField(limit).to_api()
query_params["include"] = fields.StringField(include).to_api()
return self._client.call_api(
method="get", path="/v3/api-keys", content_type="application/json", query_params=query_params, unpack=False
)
def read(self):
"""Get API key details.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/api-keys/{apikey_id}>`_.
:rtype: ApiKey
"""
return self._client.call_api(
method="get",
path="/v3/api-keys/{apikey_id}",
content_type="application/json",
path_params={"apikey_id": self._id.to_api()},
unpack=self,
)
def update(self):
"""Update API key details.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/api-keys/{apikey_id}>`_.
:rtype: ApiKey
"""
# Conditionally setup the message body, fields which have not been set will not be sent to the API.
# This avoids null fields being rejected and allows the default value to be used.
body_params = {}
if self._name.value_set:
body_params["name"] = self._name.to_api()
if self._owner.value_set:
body_params["owner"] = self._owner.to_api()
if self._status.value_set:
body_params["status"] = self._status.to_api()
return self._client.call_api(
method="put",
path="/v3/api-keys/{apikey_id}",
content_type="application/json",
path_params={"apikey_id": self._id.to_api()},
body_params=body_params,
unpack=self,
)
|
class ApiKey(Entity):
'''Represents the `ApiKey` entity in Pelion Device Management'''
def __init__(
self,
_client=None,
account_id=None,
created_at=None,
creation_time=None,
id=None,
key=None,
last_login_time=None,
name=None,
owner=None,
status=None,
updated_at=None,
):
'''Creates a local `ApiKey` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param account_id: The ID of the account.
:type account_id: str
:param created_at: Creation UTC time RFC3339.
:type created_at: datetime
:param creation_time: The timestamp of the API key creation in the storage, in
milliseconds.
:type creation_time: int
:param id: (Required) The ID of the API key.
:type id: str
:param key: The API key.
:type key: str
:param last_login_time: The timestamp of the latest API key usage, in milliseconds.
:type last_login_time: int
:param name: (Required) The display name for the API key.
:type name: str
:param owner: The owner of this API key, who is the creator by default.
:type owner: str
:param status: The status of the API key.
:type status: str
:param updated_at: Last update UTC time RFC3339.
:type updated_at: datetime
'''
pass
@property
def account_id(self):
'''The ID of the account.
api example: '01619571e2e90242ac12000600000000'
:rtype: str
'''
pass
@property
def created_at(self):
'''Creation UTC time RFC3339.
api example: '2018-02-13T09:35:20Z'
:rtype: datetime
'''
pass
@property
def creation_time(self):
'''The timestamp of the API key creation in the storage, in milliseconds.
api example: 1518630727683
:rtype: int
'''
pass
@property
def id(self):
'''The ID of the API key.
This field must be set when updating or deleting an existing ApiKey Entity.
api example: '01619571f7020242ac12000600000000'
:rtype: str
'''
pass
@id.setter
def id(self):
'''Set value of `id`
:param value: value to set
:type value: str
'''
pass
@property
def key(self):
'''The API key.
api example: 'ak_1MDE2MTk1NzFmNmU4MDI0MmFjMTIwMDA2MDAwMDAwMDA01619571f7020242ac120006000000
00'
:rtype: str
'''
pass
@property
def last_login_time(self):
'''The timestamp of the latest API key usage, in milliseconds.
api example: 1518630727688
:rtype: int
'''
pass
@property
def name(self):
'''The display name for the API key.
This field must be set when creating a new ApiKey Entity.
api example: 'API key gorgon'
:rtype: str
'''
pass
@name.setter
def name(self):
'''Set value of `name`
:param value: value to set
:type value: str
'''
pass
@property
def owner(self):
'''The owner of this API key, who is the creator by default.
api example: '01619571e2e89242ac12000600000000'
:rtype: str
'''
pass
@owner.setter
def owner(self):
'''Set value of `owner`
:param value: value to set
:type value: str
'''
pass
@property
def status(self):
'''The status of the API key.
api example: 'ACTIVE'
:rtype: str
'''
pass
@status.setter
def status(self):
'''Set value of `status`
:param value: value to set
:type value: str
'''
pass
@property
def updated_at(self):
'''Last update UTC time RFC3339.
api example: '2018-02-14T15:24:14Z'
:rtype: datetime
'''
pass
def created_at(self):
'''Create a new API key.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/api-keys>`_.
:rtype: ApiKey
'''
pass
def delete(self):
'''Delete API key.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/api-keys/{apikey_id}>`_.
:rtype: ApiKey
'''
pass
def list(self, filter=None, order="ASC", max_results=None, page_size=50, include=None):
'''Get all API keys.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/api-keys>`_.
**API Filters**
The following filters are supported by the API when listing ApiKey entities:
+-------+------+------+------+------+------+------+------+
| Field | eq | neq | gte | lte | in | nin | like |
+=======+======+======+======+======+======+======+======+
| key | Y | | | | | | |
+-------+------+------+------+------+------+------+------+
| owner | Y | | | | | | |
+-------+------+------+------+------+------+------+------+
**Example Usage**
.. code-block:: python
from mbed_cloud.foundation import ApiKey
from mbed_cloud import ApiFilter
api_filter = ApiFilter()
api_filter.add_filter("key", "eq", <filter value>)
for api_key in ApiKey().list(filter=api_filter):
print(api_key.key)
:param filter: An optional filter to apply when listing entities, please see the
above **API Filters** table for supported filters.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order based on creation time. Acceptable values: ASC, DESC.
Default: ASC.
:type order: str
:param max_results: Total maximum number of results to retrieve
:type max_results: int
:param page_size: The number of results to return (2-1000). Default 50.
:type page_size: int
:param include: Comma-separated additional data to return. Currently supported:
total_count.
:type include: str
:return: An iterator object which yields instances of an entity.
:rtype: mbed_cloud.pagination.PaginatedResponse(ApiKey)
'''
pass
def me(self):
'''Get API key details.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/api-keys/me>`_.
:rtype: ApiKey
'''
pass
def _paginate_list(self, after=None, filter=None, order="ASC", limit=50, include=None):
'''Get all API keys.
:param after: The entity ID to fetch after the given one.
:type after: str
:param filter: Optional API filter for listing resources.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order based on creation time. Acceptable values: ASC, DESC.
Default: ASC.
:type order: str
:param limit: The number of results to return (2-1000). Default 50.
:type limit: int
:param include: Comma-separated additional data to return. Currently supported:
total_count.
:type include: str
:rtype: mbed_cloud.pagination.PaginatedResponse
'''
pass
def read(self):
'''Get API key details.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/api-keys/{apikey_id}>`_.
:rtype: ApiKey
'''
pass
def updated_at(self):
'''Update API key details.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/api-keys/{apikey_id}>`_.
:rtype: ApiKey
'''
pass
| 37 | 23 | 18 | 4 | 6 | 8 | 2 | 1.1 | 1 | 9 | 6 | 0 | 22 | 10 | 22 | 33 | 446 | 114 | 158 | 70 | 105 | 174 | 86 | 43 | 60 | 5 | 2 | 2 | 33 |
2,269 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/accounts/active_session.py
|
mbed_cloud.foundation.entities.accounts.active_session.ActiveSession
|
class ActiveSession(Entity):
"""Represents the `ActiveSession` entity in Pelion Device Management"""
# List of fields that are serialised between the API and SDK
_api_fieldnames = ["account_id", "ip_address", "login_time", "reference_token", "user_agent"]
# List of fields that are available for the user of the SDK
_sdk_fieldnames = _api_fieldnames
# Renames to be performed by the SDK when receiving data {<API Field Name>: <SDK Field Name>}
_renames = {}
# Renames to be performed by the SDK when sending data {<SDK Field Name>: <API Field Name>}
_renames_to_api = {}
def __init__(
self, _client=None, account_id=None, ip_address=None, login_time=None, reference_token=None, user_agent=None
):
"""Creates a local `ActiveSession` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param account_id: The UUID of the account.
:type account_id: str
:param ip_address: IP address of the client.
:type ip_address: str
:param login_time: The login time of the user.
:type login_time: datetime
:param reference_token: The reference token.
:type reference_token: str
:param user_agent: User Agent header from the login request.
:type user_agent: str
"""
super().__init__(_client=_client)
# inline imports for avoiding circular references and bulk imports
# fields
self._account_id = fields.StringField(value=account_id)
self._ip_address = fields.StringField(value=ip_address)
self._login_time = fields.DateTimeField(value=login_time)
self._reference_token = fields.StringField(value=reference_token)
self._user_agent = fields.StringField(value=user_agent)
@property
def account_id(self):
"""The UUID of the account.
api example: '01619571e2e90242ac12000600000000'
:rtype: str
"""
return self._account_id.value
@property
def ip_address(self):
"""IP address of the client.
api example: '127.0.0.1'
:rtype: str
"""
return self._ip_address.value
@property
def login_time(self):
"""The login time of the user.
api example: '2018-02-14T17:52:07Z'
:rtype: datetime
"""
return self._login_time.value
@property
def reference_token(self):
"""The reference token.
api example: 'rt_CI6+5hS8p9DrCmkRyS6u4doUdiXr71dX7MqD+g0327hYQthEkYTxMMnCwHyf1rDdk'
:rtype: str
"""
return self._reference_token.value
@property
def user_agent(self):
"""User Agent header from the login request.
api example: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/41.0.2227.1 Safari/537.36'
:rtype: str
"""
return self._user_agent.value
|
class ActiveSession(Entity):
'''Represents the `ActiveSession` entity in Pelion Device Management'''
def __init__(
self, _client=None, account_id=None, ip_address=None, login_time=None, reference_token=None, user_agent=None
):
'''Creates a local `ActiveSession` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param account_id: The UUID of the account.
:type account_id: str
:param ip_address: IP address of the client.
:type ip_address: str
:param login_time: The login time of the user.
:type login_time: datetime
:param reference_token: The reference token.
:type reference_token: str
:param user_agent: User Agent header from the login request.
:type user_agent: str
'''
pass
@property
def account_id(self):
'''The UUID of the account.
api example: '01619571e2e90242ac12000600000000'
:rtype: str
'''
pass
@property
def ip_address(self):
'''IP address of the client.
api example: '127.0.0.1'
:rtype: str
'''
pass
@property
def login_time(self):
'''The login time of the user.
api example: '2018-02-14T17:52:07Z'
:rtype: datetime
'''
pass
@property
def reference_token(self):
'''The reference token.
api example: 'rt_CI6+5hS8p9DrCmkRyS6u4doUdiXr71dX7MqD+g0327hYQthEkYTxMMnCwHyf1rDdk'
:rtype: str
'''
pass
@property
def user_agent(self):
'''User Agent header from the login request.
api example: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/41.0.2227.1 Safari/537.36'
:rtype: str
'''
pass
| 12 | 7 | 13 | 4 | 3 | 7 | 1 | 1.55 | 1 | 3 | 2 | 0 | 6 | 5 | 6 | 17 | 105 | 31 | 29 | 23 | 15 | 45 | 22 | 16 | 15 | 1 | 2 | 0 | 6 |
2,270 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/accounts/account.py
|
mbed_cloud.foundation.entities.accounts.account.Account
|
class Account(Entity):
"""Represents the `Account` entity in Pelion Device Management"""
# List of fields that are serialised between the API and SDK
_api_fieldnames = [
"address_line1",
"address_line2",
"admin_email",
"admin_full_name",
"admin_id",
"admin_key",
"admin_name",
"admin_password",
"aliases",
"city",
"company",
"contact",
"contract_number",
"country",
"created_at",
"custom_fields",
"customer_number",
"display_name",
"email",
"end_market",
"expiration",
"expiration_warning_threshold",
"id",
"idle_timeout",
"limits",
"mfa_status",
"notification_emails",
"parent_account",
"parent_id",
"password_policy",
"password_recovery_expiration",
"phone_number",
"policies",
"postal_code",
"reason",
"reference_note",
"sales_contact",
"state",
"status",
"template_id",
"tier",
"updated_at",
"upgraded_at",
]
# List of fields that are available for the user of the SDK
_sdk_fieldnames = _api_fieldnames
# Renames to be performed by the SDK when receiving data {<API Field Name>: <SDK Field Name>}
_renames = {}
# Renames to be performed by the SDK when sending data {<SDK Field Name>: <API Field Name>}
_renames_to_api = {}
def __init__(
self,
_client=None,
address_line1=None,
address_line2=None,
admin_email=None,
admin_full_name=None,
admin_id=None,
admin_key=None,
admin_name=None,
admin_password=None,
aliases=None,
city=None,
company=None,
contact=None,
contract_number=None,
country=None,
created_at=None,
custom_fields=None,
customer_number=None,
display_name=None,
email=None,
end_market=None,
expiration=None,
expiration_warning_threshold=None,
id=None,
idle_timeout=None,
limits=None,
mfa_status=None,
notification_emails=None,
parent_account=None,
parent_id=None,
password_policy=None,
password_recovery_expiration=None,
phone_number=None,
policies=None,
postal_code=None,
reason=None,
reference_note=None,
sales_contact=None,
state=None,
status=None,
template_id=None,
tier=None,
updated_at=None,
upgraded_at=None,
):
"""Creates a local `Account` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param address_line1: Postal address line 1.
:type address_line1: str
:param address_line2: Postal address line 2.
:type address_line2: str
:param admin_email: The email address of the admin user created for this account.
Present only in the response for account creation.
:type admin_email: str
:param admin_full_name: The full name of the admin user created for this account. Present
only in the response for account creation.
:type admin_full_name: str
:param admin_id: The ID of the admin user created for this account.
:type admin_id: str
:param admin_key: The admin API key created for this account. Present only in the
response for account creation.
:type admin_key: str
:param admin_name: The username of the admin user created for this account. Present
only in the response for account creation.
:type admin_name: str
:param admin_password: The password of the admin user created for this account. Present
only in the response for account creation.
:type admin_password: str
:param aliases: An array of aliases.
:type aliases: list
:param city: The city part of the postal address.
:type city: str
:param company: The name of the company.
:type company: str
:param contact: The name of the contact person for this account.
:type contact: str
:param contract_number: Contract number of the customer.
:type contract_number: str
:param country: The country part of the postal address.
:type country: str
:param created_at: Creation UTC time RFC3339.
:type created_at: datetime
:param custom_fields: Account's custom properties as key-value pairs.
:type custom_fields: dict
:param customer_number: Customer number of the customer.
:type customer_number: str
:param display_name: The display name for the account.
:type display_name: str
:param email: The company email address for this account.
:type email: str
:param end_market: (Required) Account end market.
:type end_market: str
:param expiration: Expiration time of the account, as UTC time RFC3339.
:type expiration: datetime
:param expiration_warning_threshold: Indicates how many days (1-180) before account expiration a
notification email is sent.
:type expiration_warning_threshold: int
:param id: (Required) Account ID.
:type id: str
:param idle_timeout: The reference token expiration time, in minutes, for this account.
:type idle_timeout: int
:param limits: List of limits as key-value pairs if requested.
:type limits: dict
:param mfa_status: The enforcement status of multi-factor authentication, either
`enforced` or `optional`.
:type mfa_status: str
:param notification_emails: A list of notification email addresses.
:type notification_emails: list
:param parent_account: Represents parent account contact details in responses.
:type parent_account: dict
:param parent_id: The ID of the parent account, if any.
:type parent_id: str
:param password_policy: The password policy for this account.
:type password_policy: dict
:param password_recovery_expiration: Indicates for how many minutes a password recovery email is valid.
:type password_recovery_expiration: int
:param phone_number: The phone number of a company representative.
:type phone_number: str
:param policies: List of policies if requested.
:type policies: list
:param postal_code: The postal code part of the postal address.
:type postal_code: str
:param reason: A note with the reason for account status update.
:type reason: str
:param reference_note: A reference note for updating the status of the account.
:type reference_note: str
:param sales_contact: Email address of the sales contact.
:type sales_contact: str
:param state: The state part of the postal address.
:type state: str
:param status: The status of the account.
:type status: str
:param template_id: Account template ID.
:type template_id: str
:param tier: The tier level of the account; `0`: free tier, `1`: commercial
account, `2`: partner tier. Other values are reserved for the
future.
:type tier: str
:param updated_at: Last update UTC time RFC3339.
:type updated_at: datetime
:param upgraded_at: Time when upgraded to commercial account in UTC format RFC3339.
:type upgraded_at: datetime
"""
super().__init__(_client=_client)
# inline imports for avoiding circular references and bulk imports
from mbed_cloud.foundation.entities.accounts.parent_account import ParentAccount
from mbed_cloud.foundation.entities.accounts.password_policy import PasswordPolicy
from mbed_cloud.foundation.entities.accounts.policy import Policy
# fields
self._address_line1 = fields.StringField(value=address_line1)
self._address_line2 = fields.StringField(value=address_line2)
self._admin_email = fields.StringField(value=admin_email)
self._admin_full_name = fields.StringField(value=admin_full_name)
self._admin_id = fields.StringField(value=admin_id)
self._admin_key = fields.StringField(value=admin_key)
self._admin_name = fields.StringField(value=admin_name)
self._admin_password = fields.StringField(value=admin_password)
self._aliases = fields.ListField(value=aliases)
self._city = fields.StringField(value=city)
self._company = fields.StringField(value=company)
self._contact = fields.StringField(value=contact)
self._contract_number = fields.StringField(value=contract_number)
self._country = fields.StringField(value=country)
self._created_at = fields.DateTimeField(value=created_at)
self._custom_fields = fields.DictField(value=custom_fields)
self._customer_number = fields.StringField(value=customer_number)
self._display_name = fields.StringField(value=display_name)
self._email = fields.StringField(value=email)
self._end_market = fields.StringField(value=end_market)
self._expiration = fields.DateTimeField(value=expiration)
self._expiration_warning_threshold = fields.IntegerField(value=expiration_warning_threshold)
self._id = fields.StringField(value=id)
self._idle_timeout = fields.IntegerField(value=idle_timeout)
self._limits = fields.DictField(value=limits)
self._mfa_status = fields.StringField(value=mfa_status, enum=enums.AccountMfaStatusEnum)
self._notification_emails = fields.ListField(value=notification_emails)
self._parent_account = fields.DictField(value=parent_account, entity=ParentAccount)
self._parent_id = fields.StringField(value=parent_id)
self._password_policy = fields.DictField(value=password_policy, entity=PasswordPolicy)
self._password_recovery_expiration = fields.IntegerField(value=password_recovery_expiration)
self._phone_number = fields.StringField(value=phone_number)
self._policies = fields.ListField(value=policies, entity=Policy)
self._postal_code = fields.StringField(value=postal_code)
self._reason = fields.StringField(value=reason)
self._reference_note = fields.StringField(value=reference_note)
self._sales_contact = fields.StringField(value=sales_contact)
self._state = fields.StringField(value=state)
self._status = fields.StringField(value=status, enum=enums.AccountStatusEnum)
self._template_id = fields.StringField(value=template_id)
self._tier = fields.StringField(value=tier)
self._updated_at = fields.DateTimeField(value=updated_at)
self._upgraded_at = fields.DateTimeField(value=upgraded_at)
@property
def address_line1(self):
"""Postal address line 1.
api example: '110 Fulbourn Rd'
:rtype: str
"""
return self._address_line1.value
@address_line1.setter
def address_line1(self, value):
"""Set value of `address_line1`
:param value: value to set
:type value: str
"""
self._address_line1.set(value)
@property
def address_line2(self):
"""Postal address line 2.
api example: ' '
:rtype: str
"""
return self._address_line2.value
@address_line2.setter
def address_line2(self, value):
"""Set value of `address_line2`
:param value: value to set
:type value: str
"""
self._address_line2.set(value)
@property
def admin_email(self):
"""The email address of the admin user created for this account. Present only in
the response for account creation.
api example: 'admin@arm.com'
:rtype: str
"""
return self._admin_email.value
@admin_email.setter
def admin_email(self, value):
"""Set value of `admin_email`
:param value: value to set
:type value: str
"""
self._admin_email.set(value)
@property
def admin_full_name(self):
"""The full name of the admin user created for this account. Present only in the
response for account creation.
api example: 'Admin Doe'
:rtype: str
"""
return self._admin_full_name.value
@admin_full_name.setter
def admin_full_name(self, value):
"""Set value of `admin_full_name`
:param value: value to set
:type value: str
"""
self._admin_full_name.set(value)
@property
def admin_id(self):
"""The ID of the admin user created for this account.
api example: '01619571e2e89242ac12000600000000'
:rtype: str
"""
return self._admin_id.value
@property
def admin_key(self):
"""The admin API key created for this account. Present only in the response for
account creation.
api example: 'ak_1MDE2MTk1NzFmNmU4MDI0MmFjMTIwMDA2MDAwMDAwMDA01619571f7020242ac120006000000
00B40IkJADMANmAscAj0Ot0n2yeQnyt9tT'
:rtype: str
"""
return self._admin_key.value
@property
def admin_name(self):
"""The username of the admin user created for this account. Present only in the
response for account creation.
api example: 'admin'
:rtype: str
"""
return self._admin_name.value
@admin_name.setter
def admin_name(self, value):
"""Set value of `admin_name`
:param value: value to set
:type value: str
"""
self._admin_name.set(value)
@property
def admin_password(self):
"""The password of the admin user created for this account. Present only in the
response for account creation.
api example: 'PZf9eEUH43DAPE9ULINFeuj'
:rtype: str
"""
return self._admin_password.value
@admin_password.setter
def admin_password(self, value):
"""Set value of `admin_password`
:param value: value to set
:type value: str
"""
self._admin_password.set(value)
@property
def aliases(self):
"""An array of aliases.
:rtype: list
"""
return self._aliases.value
@aliases.setter
def aliases(self, value):
"""Set value of `aliases`
:param value: value to set
:type value: list
"""
self._aliases.set(value)
@property
def city(self):
"""The city part of the postal address.
api example: 'Cambridge'
:rtype: str
"""
return self._city.value
@city.setter
def city(self, value):
"""Set value of `city`
:param value: value to set
:type value: str
"""
self._city.set(value)
@property
def company(self):
"""The name of the company.
api example: 'ARM Holdings Plc'
:rtype: str
"""
return self._company.value
@company.setter
def company(self, value):
"""Set value of `company`
:param value: value to set
:type value: str
"""
self._company.set(value)
@property
def contact(self):
"""The name of the contact person for this account.
api example: 'J. Doe'
:rtype: str
"""
return self._contact.value
@contact.setter
def contact(self, value):
"""Set value of `contact`
:param value: value to set
:type value: str
"""
self._contact.set(value)
@property
def contract_number(self):
"""Contract number of the customer.
api example: '1NX25_0001'
:rtype: str
"""
return self._contract_number.value
@contract_number.setter
def contract_number(self, value):
"""Set value of `contract_number`
:param value: value to set
:type value: str
"""
self._contract_number.set(value)
@property
def country(self):
"""The country part of the postal address.
api example: 'United Kingdom'
:rtype: str
"""
return self._country.value
@country.setter
def country(self, value):
"""Set value of `country`
:param value: value to set
:type value: str
"""
self._country.set(value)
@property
def created_at(self):
"""Creation UTC time RFC3339.
api example: '2018-02-13T09:35:20Z'
:rtype: datetime
"""
return self._created_at.value
@property
def custom_fields(self):
"""Account's custom properties as key-value pairs.
:rtype: dict
"""
return self._custom_fields.value
@custom_fields.setter
def custom_fields(self, value):
"""Set value of `custom_fields`
:param value: value to set
:type value: dict
"""
self._custom_fields.set(value)
@property
def customer_number(self):
"""Customer number of the customer.
api example: '1NC25_0001'
:rtype: str
"""
return self._customer_number.value
@customer_number.setter
def customer_number(self, value):
"""Set value of `customer_number`
:param value: value to set
:type value: str
"""
self._customer_number.set(value)
@property
def display_name(self):
"""The display name for the account.
api example: 'ARM'
:rtype: str
"""
return self._display_name.value
@display_name.setter
def display_name(self, value):
"""Set value of `display_name`
:param value: value to set
:type value: str
"""
self._display_name.set(value)
@property
def email(self):
"""The company email address for this account.
api example: 'info@arm.com'
:rtype: str
"""
return self._email.value
@email.setter
def email(self, value):
"""Set value of `email`
:param value: value to set
:type value: str
"""
self._email.set(value)
@property
def end_market(self):
"""Account end market.
This field must be set when creating a new Account Entity.
api example: 'IT'
:rtype: str
"""
return self._end_market.value
@end_market.setter
def end_market(self, value):
"""Set value of `end_market`
:param value: value to set
:type value: str
"""
self._end_market.set(value)
@property
def expiration(self):
"""Expiration time of the account, as UTC time RFC3339.
:rtype: datetime
"""
return self._expiration.value
@property
def expiration_warning_threshold(self):
"""Indicates how many days (1-180) before account expiration a notification email
is sent.
api example: '180'
:rtype: int
"""
return self._expiration_warning_threshold.value
@expiration_warning_threshold.setter
def expiration_warning_threshold(self, value):
"""Set value of `expiration_warning_threshold`
:param value: value to set
:type value: int
"""
self._expiration_warning_threshold.set(value)
@property
def id(self):
"""Account ID.
This field must be set when updating or deleting an existing Account Entity.
api example: '01619571e2e90242ac12000600000000'
:rtype: str
"""
return self._id.value
@id.setter
def id(self, value):
"""Set value of `id`
:param value: value to set
:type value: str
"""
self._id.set(value)
@property
def idle_timeout(self):
"""The reference token expiration time, in minutes, for this account.
api example: '30'
:rtype: int
"""
return self._idle_timeout.value
@idle_timeout.setter
def idle_timeout(self, value):
"""Set value of `idle_timeout`
:param value: value to set
:type value: int
"""
self._idle_timeout.set(value)
@property
def limits(self):
"""List of limits as key-value pairs if requested.
:rtype: dict
"""
return self._limits.value
@property
def mfa_status(self):
"""The enforcement status of multi-factor authentication, either `enforced` or
`optional`.
:rtype: str
"""
return self._mfa_status.value
@mfa_status.setter
def mfa_status(self, value):
"""Set value of `mfa_status`
:param value: value to set
:type value: str
"""
self._mfa_status.set(value)
@property
def notification_emails(self):
"""A list of notification email addresses.
:rtype: list
"""
return self._notification_emails.value
@notification_emails.setter
def notification_emails(self, value):
"""Set value of `notification_emails`
:param value: value to set
:type value: list
"""
self._notification_emails.set(value)
@property
def parent_account(self):
"""Represents parent account contact details in responses.
:rtype: dict[ParentAccount]
"""
return self._parent_account.value
@property
def parent_id(self):
"""The ID of the parent account, if any.
api example: '01619571dad80242ac12000600000000'
:rtype: str
"""
return self._parent_id.value
@property
def password_policy(self):
"""The password policy for this account.
:rtype: dict[PasswordPolicy]
"""
return self._password_policy.value
@password_policy.setter
def password_policy(self, value):
"""Set value of `password_policy`
:param value: value to set
:type value: dict[PasswordPolicy]
"""
self._password_policy.set(value)
@property
def password_recovery_expiration(self):
"""Indicates for how many minutes a password recovery email is valid.
:rtype: int
"""
return self._password_recovery_expiration.value
@password_recovery_expiration.setter
def password_recovery_expiration(self, value):
"""Set value of `password_recovery_expiration`
:param value: value to set
:type value: int
"""
self._password_recovery_expiration.set(value)
@property
def phone_number(self):
"""The phone number of a company representative.
api example: '+44 (1223) 400 400'
:rtype: str
"""
return self._phone_number.value
@phone_number.setter
def phone_number(self, value):
"""Set value of `phone_number`
:param value: value to set
:type value: str
"""
self._phone_number.set(value)
@property
def policies(self):
"""List of policies if requested.
:rtype: list[Policy]
"""
return self._policies.value
@property
def postal_code(self):
"""The postal code part of the postal address.
api example: 'CB1 9NJ'
:rtype: str
"""
return self._postal_code.value
@postal_code.setter
def postal_code(self, value):
"""Set value of `postal_code`
:param value: value to set
:type value: str
"""
self._postal_code.set(value)
@property
def reason(self):
"""A note with the reason for account status update.
api example: 'Subscription paid.'
:rtype: str
"""
return self._reason.value
@property
def reference_note(self):
"""A reference note for updating the status of the account.
api example: 'ARM-INT-0001'
:rtype: str
"""
return self._reference_note.value
@property
def sales_contact(self):
"""Email address of the sales contact.
api example: 'sales@arm.com'
:rtype: str
"""
return self._sales_contact.value
@sales_contact.setter
def sales_contact(self, value):
"""Set value of `sales_contact`
:param value: value to set
:type value: str
"""
self._sales_contact.set(value)
@property
def state(self):
"""The state part of the postal address.
api example: ' '
:rtype: str
"""
return self._state.value
@state.setter
def state(self, value):
"""Set value of `state`
:param value: value to set
:type value: str
"""
self._state.set(value)
@property
def status(self):
"""The status of the account.
api example: 'ACTIVE'
:rtype: str
"""
return self._status.value
@property
def template_id(self):
"""Account template ID.
api example: '01619571e7160242ac12000600000000'
:rtype: str
"""
return self._template_id.value
@property
def tier(self):
"""The tier level of the account; `0`: free tier, `1`: commercial account, `2`:
partner tier. Other values are reserved for the future.
api example: '1'
:rtype: str
"""
return self._tier.value
@property
def updated_at(self):
"""Last update UTC time RFC3339.
api example: '2018-02-14T15:24:14Z'
:rtype: datetime
"""
return self._updated_at.value
@property
def upgraded_at(self):
"""Time when upgraded to commercial account in UTC format RFC3339.
api example: '2018-02-14T15:24:14Z'
:rtype: datetime
"""
return self._upgraded_at.value
def api_keys(self, filter=None, order="ASC", max_results=None, page_size=50, include=None):
"""Get all API keys.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/api-keys>`_.
**API Filters**
The following filters are supported by the API when listing Account entities:
+-------+------+------+------+------+------+------+------+
| Field | eq | neq | gte | lte | in | nin | like |
+=======+======+======+======+======+======+======+======+
| key | Y | | | | | | |
+-------+------+------+------+------+------+------+------+
| owner | Y | | | | | | |
+-------+------+------+------+------+------+------+------+
**Example Usage**
.. code-block:: python
from mbed_cloud.foundation import Account
from mbed_cloud import ApiFilter
api_filter = ApiFilter()
api_filter.add_filter("key", "eq", <filter value>)
for api_key in Account().api_keys(filter=api_filter):
print(api_key.key)
:param filter: An optional filter to apply when listing entities, please see the
above **API Filters** table for supported filters.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order based on creation time. Acceptable values: ASC, DESC.
Default: ASC.
:type order: str
:param max_results: Total maximum number of results to retrieve
:type max_results: int
:param page_size: The number of results to return (2-1000). Default 50.
:type page_size: int
:param include: Comma-separated additional data to return. Currently supported:
total_count.
:type include: str
:return: An iterator object which yields instances of an entity.
:rtype: mbed_cloud.pagination.PaginatedResponse(SubtenantApiKey)
"""
from mbed_cloud.foundation._custom_methods import paginate
from mbed_cloud.foundation import SubtenantApiKey
from mbed_cloud import ApiFilter
# Be permissive and accept an instance of a dictionary as this was how the Legacy interface worked.
if isinstance(filter, dict):
filter = ApiFilter(filter_definition=filter, field_renames=SubtenantApiKey._renames_to_api)
# The preferred method is an ApiFilter instance as this should be easier to use.
elif isinstance(filter, ApiFilter):
# If filter renames have not be defined then configure the ApiFilter so that any renames
# performed by the SDK are reversed when the query parameters are created.
if filter.field_renames is None:
filter.field_renames = SubtenantApiKey._renames_to_api
elif filter is not None:
raise TypeError("The 'filter' parameter may be either 'dict' or 'ApiFilter'.")
return paginate(
self=self,
foreign_key=SubtenantApiKey,
filter=filter,
order=order,
max_results=max_results,
page_size=page_size,
include=include,
wraps=self._paginate_api_keys,
)
def create(self, action="create"):
"""Create a new account.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts>`_.
:param action: Action, either `create` or `enroll`.
<ul>
<li>`create` creates the
account where its admin user has ACTIVE status if `admin_password` was
defined in the request, or RESET status if no `admin_password` was
defined. If the user already exists, its status is not modified. </li>
<li>`enroll` creates the account where its admin user has ENROLLING
status. If the user already exists, its status is not modified. Email
to finish enrollment or notify the existing user about the new account
is sent to the `admin_email` defined in the request. </li></ul>
:type action: str
:rtype: Account
"""
# Conditionally setup the message body, fields which have not been set will not be sent to the API.
# This avoids null fields being rejected and allows the default value to be used.
body_params = {}
if self._address_line1.value_set:
body_params["address_line1"] = self._address_line1.to_api()
if self._address_line2.value_set:
body_params["address_line2"] = self._address_line2.to_api()
if self._admin_email.value_set:
body_params["admin_email"] = self._admin_email.to_api()
if self._admin_full_name.value_set:
body_params["admin_full_name"] = self._admin_full_name.to_api()
if self._admin_name.value_set:
body_params["admin_name"] = self._admin_name.to_api()
if self._admin_password.value_set:
body_params["admin_password"] = self._admin_password.to_api()
if self._aliases.value_set:
body_params["aliases"] = self._aliases.to_api()
if self._city.value_set:
body_params["city"] = self._city.to_api()
if self._company.value_set:
body_params["company"] = self._company.to_api()
if self._contact.value_set:
body_params["contact"] = self._contact.to_api()
if self._contract_number.value_set:
body_params["contract_number"] = self._contract_number.to_api()
if self._country.value_set:
body_params["country"] = self._country.to_api()
if self._customer_number.value_set:
body_params["customer_number"] = self._customer_number.to_api()
if self._display_name.value_set:
body_params["display_name"] = self._display_name.to_api()
if self._email.value_set:
body_params["email"] = self._email.to_api()
if self._end_market.value_set:
body_params["end_market"] = self._end_market.to_api()
if self._phone_number.value_set:
body_params["phone_number"] = self._phone_number.to_api()
if self._postal_code.value_set:
body_params["postal_code"] = self._postal_code.to_api()
if self._state.value_set:
body_params["state"] = self._state.to_api()
return self._client.call_api(
method="post",
path="/v3/accounts",
content_type="application/json",
query_params={"action": fields.StringField(action).to_api()},
body_params=body_params,
unpack=self,
)
def dark_theme_branding_colors(self, filter=None, order=None, max_results=None, page_size=None, include=None):
"""Get dark theme branding colors.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/branding-colors/dark>`_.
:param filter: Filtering when listing entities is not supported by the API for this
entity.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: The order of the records based on creation time, ASC or DESC. Default
value is ASC
:type order: str
:param max_results: Total maximum number of results to retrieve
:type max_results: int
:param page_size: The number of results to return for each page.
:type page_size: int
:param include: Comma separated additional data to return.
:type include: str
:return: An iterator object which yields instances of an entity.
:rtype: mbed_cloud.pagination.PaginatedResponse(SubtenantDarkThemeColor)
"""
from mbed_cloud.foundation._custom_methods import paginate
from mbed_cloud.foundation import SubtenantDarkThemeColor
from mbed_cloud import ApiFilter
# Be permissive and accept an instance of a dictionary as this was how the Legacy interface worked.
if isinstance(filter, dict):
filter = ApiFilter(filter_definition=filter, field_renames=SubtenantDarkThemeColor._renames_to_api)
# The preferred method is an ApiFilter instance as this should be easier to use.
elif isinstance(filter, ApiFilter):
# If filter renames have not be defined then configure the ApiFilter so that any renames
# performed by the SDK are reversed when the query parameters are created.
if filter.field_renames is None:
filter.field_renames = SubtenantDarkThemeColor._renames_to_api
elif filter is not None:
raise TypeError("The 'filter' parameter may be either 'dict' or 'ApiFilter'.")
return paginate(
self=self,
foreign_key=SubtenantDarkThemeColor,
filter=filter,
order=order,
max_results=max_results,
page_size=page_size,
include=include,
wraps=self._paginate_dark_theme_branding_colors,
)
def dark_theme_branding_images(self, filter=None, order=None, max_results=None, page_size=None, include=None):
"""Get metadata of all dark theme images.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/branding-images/dark>`_.
:param filter: Filtering when listing entities is not supported by the API for this
entity.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: The order of the records based on creation time, ASC or DESC. Default
value is ASC
:type order: str
:param max_results: Total maximum number of results to retrieve
:type max_results: int
:param page_size: The number of results to return for each page.
:type page_size: int
:param include: Comma separated additional data to return.
:type include: str
:return: An iterator object which yields instances of an entity.
:rtype: mbed_cloud.pagination.PaginatedResponse(SubtenantDarkThemeImage)
"""
from mbed_cloud.foundation._custom_methods import paginate
from mbed_cloud.foundation import SubtenantDarkThemeImage
from mbed_cloud import ApiFilter
# Be permissive and accept an instance of a dictionary as this was how the Legacy interface worked.
if isinstance(filter, dict):
filter = ApiFilter(filter_definition=filter, field_renames=SubtenantDarkThemeImage._renames_to_api)
# The preferred method is an ApiFilter instance as this should be easier to use.
elif isinstance(filter, ApiFilter):
# If filter renames have not be defined then configure the ApiFilter so that any renames
# performed by the SDK are reversed when the query parameters are created.
if filter.field_renames is None:
filter.field_renames = SubtenantDarkThemeImage._renames_to_api
elif filter is not None:
raise TypeError("The 'filter' parameter may be either 'dict' or 'ApiFilter'.")
return paginate(
self=self,
foreign_key=SubtenantDarkThemeImage,
filter=filter,
order=order,
max_results=max_results,
page_size=page_size,
include=include,
wraps=self._paginate_dark_theme_branding_images,
)
def light_theme_branding_colors(self, filter=None, order=None, max_results=None, page_size=None, include=None):
"""Get light theme branding colors.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/branding-colors/light>`_.
:param filter: Filtering when listing entities is not supported by the API for this
entity.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: The order of the records based on creation time, ASC or DESC. Default
value is ASC
:type order: str
:param max_results: Total maximum number of results to retrieve
:type max_results: int
:param page_size: The number of results to return for each page.
:type page_size: int
:param include: Comma separated additional data to return.
:type include: str
:return: An iterator object which yields instances of an entity.
:rtype: mbed_cloud.pagination.PaginatedResponse(SubtenantLightThemeColor)
"""
from mbed_cloud.foundation._custom_methods import paginate
from mbed_cloud.foundation import SubtenantLightThemeColor
from mbed_cloud import ApiFilter
# Be permissive and accept an instance of a dictionary as this was how the Legacy interface worked.
if isinstance(filter, dict):
filter = ApiFilter(filter_definition=filter, field_renames=SubtenantLightThemeColor._renames_to_api)
# The preferred method is an ApiFilter instance as this should be easier to use.
elif isinstance(filter, ApiFilter):
# If filter renames have not be defined then configure the ApiFilter so that any renames
# performed by the SDK are reversed when the query parameters are created.
if filter.field_renames is None:
filter.field_renames = SubtenantLightThemeColor._renames_to_api
elif filter is not None:
raise TypeError("The 'filter' parameter may be either 'dict' or 'ApiFilter'.")
return paginate(
self=self,
foreign_key=SubtenantLightThemeColor,
filter=filter,
order=order,
max_results=max_results,
page_size=page_size,
include=include,
wraps=self._paginate_light_theme_branding_colors,
)
def light_theme_branding_images(self, filter=None, order=None, max_results=None, page_size=None, include=None):
"""Get metadata of all light theme images.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/branding-images/light>`_.
:param filter: Filtering when listing entities is not supported by the API for this
entity.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: The order of the records based on creation time, ASC or DESC. Default
value is ASC
:type order: str
:param max_results: Total maximum number of results to retrieve
:type max_results: int
:param page_size: The number of results to return for each page.
:type page_size: int
:param include: Comma separated additional data to return.
:type include: str
:return: An iterator object which yields instances of an entity.
:rtype: mbed_cloud.pagination.PaginatedResponse(SubtenantLightThemeImage)
"""
from mbed_cloud.foundation._custom_methods import paginate
from mbed_cloud.foundation import SubtenantLightThemeImage
from mbed_cloud import ApiFilter
# Be permissive and accept an instance of a dictionary as this was how the Legacy interface worked.
if isinstance(filter, dict):
filter = ApiFilter(filter_definition=filter, field_renames=SubtenantLightThemeImage._renames_to_api)
# The preferred method is an ApiFilter instance as this should be easier to use.
elif isinstance(filter, ApiFilter):
# If filter renames have not be defined then configure the ApiFilter so that any renames
# performed by the SDK are reversed when the query parameters are created.
if filter.field_renames is None:
filter.field_renames = SubtenantLightThemeImage._renames_to_api
elif filter is not None:
raise TypeError("The 'filter' parameter may be either 'dict' or 'ApiFilter'.")
return paginate(
self=self,
foreign_key=SubtenantLightThemeImage,
filter=filter,
order=order,
max_results=max_results,
page_size=page_size,
include=include,
wraps=self._paginate_light_theme_branding_images,
)
def list(
self, filter=None, order="ASC", max_results=None, page_size=1000, include=None, format=None, properties=None
):
"""Get all accounts.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts>`_.
**API Filters**
The following filters are supported by the API when listing Account entities:
+------------+------+------+------+------+------+------+------+
| Field | eq | neq | gte | lte | in | nin | like |
+============+======+======+======+======+======+======+======+
| country | | | | | | | Y |
+------------+------+------+------+------+------+------+------+
| end_market | Y | | | | | | |
+------------+------+------+------+------+------+------+------+
| parent | Y | | | | | | |
+------------+------+------+------+------+------+------+------+
| status | Y | | | | Y | Y | |
+------------+------+------+------+------+------+------+------+
| tier | Y | | | | | | |
+------------+------+------+------+------+------+------+------+
**Example Usage**
.. code-block:: python
from mbed_cloud.foundation import Account
from mbed_cloud import ApiFilter
api_filter = ApiFilter()
api_filter.add_filter("country", "like", <filter value>)
for account in Account().list(filter=api_filter):
print(account.country)
:param filter: An optional filter to apply when listing entities, please see the
above **API Filters** table for supported filters.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order. Acceptable values: ASC, DESC. Default: ASC.
:type order: str
:param max_results: Total maximum number of results to retrieve
:type max_results: int
:param page_size: The number of results to return (2-1000). Default 1000.
:type page_size: int
:param include: Comma-separated additional data to return. Currently supported:
limits, policies, sub_accounts.
:type include: str
:param format: Format information for the query response. Supported:
format=breakdown.
:type format: str
:param properties: Property name returned from account-specific properties.
:type properties: str
:return: An iterator object which yields instances of an entity.
:rtype: mbed_cloud.pagination.PaginatedResponse(Account)
"""
from mbed_cloud.foundation._custom_methods import paginate
from mbed_cloud.foundation import Account
from mbed_cloud import ApiFilter
# Be permissive and accept an instance of a dictionary as this was how the Legacy interface worked.
if isinstance(filter, dict):
filter = ApiFilter(filter_definition=filter, field_renames=Account._renames_to_api)
# The preferred method is an ApiFilter instance as this should be easier to use.
elif isinstance(filter, ApiFilter):
# If filter renames have not be defined then configure the ApiFilter so that any renames
# performed by the SDK are reversed when the query parameters are created.
if filter.field_renames is None:
filter.field_renames = Account._renames_to_api
elif filter is not None:
raise TypeError("The 'filter' parameter may be either 'dict' or 'ApiFilter'.")
return paginate(
self=self,
foreign_key=Account,
filter=filter,
order=order,
max_results=max_results,
page_size=page_size,
include=include,
format=format,
properties=properties,
wraps=self._paginate_list,
)
def me(self, include=None, properties=None):
"""Get account info.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/me>`_.
:param include: Comma-separated additional data to return. Currently supported:
limits, policies, sub_accounts.
:type include: str
:param properties: Property name to return from account-specific properties.
:type properties: str
:rtype: Account
"""
return self._client.call_api(
method="get",
path="/v3/accounts/me",
content_type="application/json",
query_params={
"include": fields.StringField(include).to_api(),
"properties": fields.StringField(properties).to_api(),
},
unpack=self,
)
def _paginate_api_keys(self, after=None, filter=None, order="ASC", limit=50, include=None):
"""Get all API keys.
:param after: The entity ID to fetch after the given one.
:type after: str
:param filter: Optional API filter for listing resources.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order based on creation time. Acceptable values: ASC, DESC.
Default: ASC.
:type order: str
:param limit: The number of results to return (2-1000). Default 50.
:type limit: int
:param include: Comma-separated additional data to return. Currently supported:
total_count.
:type include: str
:rtype: mbed_cloud.pagination.PaginatedResponse
"""
# Filter query parameters
query_params = filter.to_api() if filter else {}
# Add in other query parameters
query_params["after"] = fields.StringField(after).to_api()
query_params["order"] = fields.StringField(order, enum=enums.AccountOrderEnum).to_api()
query_params["limit"] = fields.IntegerField(limit).to_api()
query_params["include"] = fields.StringField(include).to_api()
return self._client.call_api(
method="get",
path="/v3/accounts/{account_id}/api-keys",
content_type="application/json",
query_params=query_params,
path_params={"account_id": self._id.to_api()},
unpack=False,
)
def _paginate_dark_theme_branding_colors(self, after=None, filter=None, order=None, limit=None, include=None):
"""Get dark theme branding colors.
:param after: Not supported by the API.
:type after: str
:param filter: Optional API filter for listing resources.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Not supported by the API.
:type order: str
:param limit: Not supported by the API.
:type limit: int
:param include: Not supported by the API.
:type include: str
:rtype: mbed_cloud.pagination.PaginatedResponse
"""
# Filter query parameters
query_params = filter.to_api() if filter else {}
# Add in other query parameters
return self._client.call_api(
method="get",
path="/v3/accounts/{account_id}/branding-colors/dark",
content_type="application/json",
path_params={"account_id": self._id.to_api()},
unpack=False,
)
def _paginate_dark_theme_branding_images(self, after=None, filter=None, order=None, limit=None, include=None):
"""Get metadata of all dark theme images.
:param after: Not supported by the API.
:type after: str
:param filter: Optional API filter for listing resources.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Not supported by the API.
:type order: str
:param limit: Not supported by the API.
:type limit: int
:param include: Not supported by the API.
:type include: str
:rtype: mbed_cloud.pagination.PaginatedResponse
"""
# Filter query parameters
query_params = filter.to_api() if filter else {}
# Add in other query parameters
return self._client.call_api(
method="get",
path="/v3/accounts/{account_id}/branding-images/dark",
content_type="application/json",
path_params={"account_id": self._id.to_api()},
unpack=False,
)
def _paginate_light_theme_branding_colors(self, after=None, filter=None, order=None, limit=None, include=None):
"""Get light theme branding colors.
:param after: Not supported by the API.
:type after: str
:param filter: Optional API filter for listing resources.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Not supported by the API.
:type order: str
:param limit: Not supported by the API.
:type limit: int
:param include: Not supported by the API.
:type include: str
:rtype: mbed_cloud.pagination.PaginatedResponse
"""
# Filter query parameters
query_params = filter.to_api() if filter else {}
# Add in other query parameters
return self._client.call_api(
method="get",
path="/v3/accounts/{account_id}/branding-colors/light",
content_type="application/json",
path_params={"account_id": self._id.to_api()},
unpack=False,
)
def _paginate_light_theme_branding_images(self, after=None, filter=None, order=None, limit=None, include=None):
"""Get metadata of all light theme images.
:param after: Not supported by the API.
:type after: str
:param filter: Optional API filter for listing resources.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Not supported by the API.
:type order: str
:param limit: Not supported by the API.
:type limit: int
:param include: Not supported by the API.
:type include: str
:rtype: mbed_cloud.pagination.PaginatedResponse
"""
# Filter query parameters
query_params = filter.to_api() if filter else {}
# Add in other query parameters
return self._client.call_api(
method="get",
path="/v3/accounts/{account_id}/branding-images/light",
content_type="application/json",
path_params={"account_id": self._id.to_api()},
unpack=False,
)
def _paginate_list(
self, after=None, filter=None, order="ASC", limit=1000, include=None, format=None, properties=None
):
"""Get all accounts.
:param after: The entity ID to fetch after the given one.
:type after: str
:param filter: Optional API filter for listing resources.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order. Acceptable values: ASC, DESC. Default: ASC.
:type order: str
:param limit: The number of results to return (2-1000). Default 1000.
:type limit: int
:param include: Comma-separated additional data to return. Currently supported:
limits, policies, sub_accounts.
:type include: str
:param format: Format information for the query response. Supported:
format=breakdown.
:type format: str
:param properties: Property name returned from account-specific properties.
:type properties: str
:rtype: mbed_cloud.pagination.PaginatedResponse
"""
# Filter query parameters
query_params = filter.to_api() if filter else {}
# Add in other query parameters
query_params["after"] = fields.StringField(after).to_api()
query_params["order"] = fields.StringField(order, enum=enums.AccountOrderEnum).to_api()
query_params["limit"] = fields.IntegerField(limit).to_api()
query_params["include"] = fields.StringField(include).to_api()
query_params["format"] = fields.StringField(format).to_api()
query_params["properties"] = fields.StringField(properties).to_api()
return self._client.call_api(
method="get", path="/v3/accounts", content_type="application/json", query_params=query_params, unpack=False
)
def _paginate_trusted_certificates(self, after=None, filter=None, order="ASC", limit=50, include=None):
"""Get all trusted certificates.
:param after: The entity ID to fetch after the given one.
:type after: str
:param filter: Optional API filter for listing resources.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order based on creation time. Acceptable values: ASC, DESC.
Default: ASC.
:type order: str
:param limit: The number of results to return (2-1000). Default 50.
:type limit: int
:param include: Comma-separated additional data to return. Currently supported:
total_count.
:type include: str
:rtype: mbed_cloud.pagination.PaginatedResponse
"""
# Filter query parameters
query_params = filter.to_api() if filter else {}
# Add in other query parameters
query_params["after"] = fields.StringField(after).to_api()
query_params["order"] = fields.StringField(order, enum=enums.AccountOrderEnum).to_api()
query_params["limit"] = fields.IntegerField(limit).to_api()
query_params["include"] = fields.StringField(include).to_api()
return self._client.call_api(
method="get",
path="/v3/accounts/{account_id}/trusted-certificates",
content_type="application/json",
query_params=query_params,
path_params={"account_id": self._id.to_api()},
unpack=False,
)
def _paginate_user_invitations(self, after=None, filter=None, order="ASC", limit=50, include=None):
"""Get the details of all user invitations.
:param after: The entity ID to fetch after the given one.
:type after: str
:param filter: Optional API filter for listing resources.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order based on creation time. Acceptable values: ASC, DESC.
Default: ASC.
:type order: str
:param limit: The number of results to return (2-1000). Default 50.
:type limit: int
:param include: Not supported by the API.
:type include: str
:rtype: mbed_cloud.pagination.PaginatedResponse
"""
# Filter query parameters
query_params = filter.to_api() if filter else {}
# Add in other query parameters
query_params["after"] = fields.StringField(after).to_api()
query_params["order"] = fields.StringField(order, enum=enums.AccountOrderEnum).to_api()
query_params["limit"] = fields.IntegerField(limit).to_api()
query_params["include"] = fields.StringField(include).to_api()
return self._client.call_api(
method="get",
path="/v3/accounts/{account_id}/user-invitations",
content_type="application/json",
query_params=query_params,
path_params={"account_id": self._id.to_api()},
unpack=False,
)
def _paginate_users(self, after=None, filter=None, order="ASC", limit=50, include=None):
"""Get the details of all users.
:param after: The entity ID to fetch after the given one.
:type after: str
:param filter: Optional API filter for listing resources.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order based on creation time. Acceptable values: ASC, DESC.
Default: ASC.
:type order: str
:param limit: The number of results to return (2-1000). Default 50.
:type limit: int
:param include: Comma-separated additional data to return. Currently supported:
total_count.
:type include: str
:rtype: mbed_cloud.pagination.PaginatedResponse
"""
# Filter query parameters
query_params = filter.to_api() if filter else {}
# Add in other query parameters
query_params["after"] = fields.StringField(after).to_api()
query_params["order"] = fields.StringField(order, enum=enums.AccountOrderEnum).to_api()
query_params["limit"] = fields.IntegerField(limit).to_api()
query_params["include"] = fields.StringField(include).to_api()
return self._client.call_api(
method="get",
path="/v3/accounts/{account_id}/users",
content_type="application/json",
query_params=query_params,
path_params={"account_id": self._id.to_api()},
unpack=False,
)
def read(self, include=None, properties=None):
"""Get account info.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}>`_.
:param include: Comma-separated additional data to return. Currently supported:
limits, policies, sub_accounts.
:type include: str
:param properties: Property name to return from account-specific properties.
:type properties: str
:rtype: Account
"""
return self._client.call_api(
method="get",
path="/v3/accounts/{account_id}",
content_type="application/json",
path_params={"account_id": self._id.to_api()},
query_params={
"include": fields.StringField(include).to_api(),
"properties": fields.StringField(properties).to_api(),
},
unpack=self,
)
def trusted_certificates(self, filter=None, order="ASC", max_results=None, page_size=50, include=None):
"""Get all trusted certificates.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/trusted-certificates>`_.
**API Filters**
The following filters are supported by the API when listing Account entities:
+-----------------------+------+------+------+------+------+------+------+
| Field | eq | neq | gte | lte | in | nin | like |
+=======================+======+======+======+======+======+======+======+
| device_execution_mode | Y | Y | | | | | |
+-----------------------+------+------+------+------+------+------+------+
| enrollment_mode | Y | | | | | | |
+-----------------------+------+------+------+------+------+------+------+
| expire | Y | | | | | | |
+-----------------------+------+------+------+------+------+------+------+
| issuer | | | | | | | Y |
+-----------------------+------+------+------+------+------+------+------+
| name | Y | | | | | | |
+-----------------------+------+------+------+------+------+------+------+
| owner | Y | | | | | | |
+-----------------------+------+------+------+------+------+------+------+
| service | Y | | | | | | |
+-----------------------+------+------+------+------+------+------+------+
| status | Y | | | | | | |
+-----------------------+------+------+------+------+------+------+------+
| subject | | | | | | | Y |
+-----------------------+------+------+------+------+------+------+------+
| valid | Y | | | | | | |
+-----------------------+------+------+------+------+------+------+------+
**Example Usage**
.. code-block:: python
from mbed_cloud.foundation import Account
from mbed_cloud import ApiFilter
api_filter = ApiFilter()
api_filter.add_filter("device_execution_mode", "eq", <filter value>)
for trusted_certificate in Account().trusted_certificates(filter=api_filter):
print(trusted_certificate.device_execution_mode)
:param filter: An optional filter to apply when listing entities, please see the
above **API Filters** table for supported filters.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order based on creation time. Acceptable values: ASC, DESC.
Default: ASC.
:type order: str
:param max_results: Total maximum number of results to retrieve
:type max_results: int
:param page_size: The number of results to return (2-1000). Default 50.
:type page_size: int
:param include: Comma-separated additional data to return. Currently supported:
total_count.
:type include: str
:return: An iterator object which yields instances of an entity.
:rtype: mbed_cloud.pagination.PaginatedResponse(SubtenantTrustedCertificate)
"""
from mbed_cloud.foundation._custom_methods import paginate
from mbed_cloud.foundation import SubtenantTrustedCertificate
from mbed_cloud import ApiFilter
# Be permissive and accept an instance of a dictionary as this was how the Legacy interface worked.
if isinstance(filter, dict):
filter = ApiFilter(filter_definition=filter, field_renames=SubtenantTrustedCertificate._renames_to_api)
# The preferred method is an ApiFilter instance as this should be easier to use.
elif isinstance(filter, ApiFilter):
# If filter renames have not be defined then configure the ApiFilter so that any renames
# performed by the SDK are reversed when the query parameters are created.
if filter.field_renames is None:
filter.field_renames = SubtenantTrustedCertificate._renames_to_api
elif filter is not None:
raise TypeError("The 'filter' parameter may be either 'dict' or 'ApiFilter'.")
return paginate(
self=self,
foreign_key=SubtenantTrustedCertificate,
filter=filter,
order=order,
max_results=max_results,
page_size=page_size,
include=include,
wraps=self._paginate_trusted_certificates,
)
def update(self):
"""Update attributes of an existing account.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}>`_.
:rtype: Account
"""
# Conditionally setup the message body, fields which have not been set will not be sent to the API.
# This avoids null fields being rejected and allows the default value to be used.
body_params = {}
if self._address_line1.value_set:
body_params["address_line1"] = self._address_line1.to_api()
if self._address_line2.value_set:
body_params["address_line2"] = self._address_line2.to_api()
if self._aliases.value_set:
body_params["aliases"] = self._aliases.to_api()
if self._city.value_set:
body_params["city"] = self._city.to_api()
if self._company.value_set:
body_params["company"] = self._company.to_api()
if self._contact.value_set:
body_params["contact"] = self._contact.to_api()
if self._contract_number.value_set:
body_params["contract_number"] = self._contract_number.to_api()
if self._country.value_set:
body_params["country"] = self._country.to_api()
if self._custom_fields.value_set:
body_params["custom_fields"] = self._custom_fields.to_api()
if self._customer_number.value_set:
body_params["customer_number"] = self._customer_number.to_api()
if self._display_name.value_set:
body_params["display_name"] = self._display_name.to_api()
if self._email.value_set:
body_params["email"] = self._email.to_api()
if self._end_market.value_set:
body_params["end_market"] = self._end_market.to_api()
if self._expiration_warning_threshold.value_set:
body_params["expiration_warning_threshold"] = self._expiration_warning_threshold.to_api()
if self._idle_timeout.value_set:
body_params["idle_timeout"] = self._idle_timeout.to_api()
if self._mfa_status.value_set:
body_params["mfa_status"] = self._mfa_status.to_api()
if self._notification_emails.value_set:
body_params["notification_emails"] = self._notification_emails.to_api()
if self._password_policy.value_set:
body_params["password_policy"] = self._password_policy.to_api()
if self._password_recovery_expiration.value_set:
body_params["password_recovery_expiration"] = self._password_recovery_expiration.to_api()
if self._phone_number.value_set:
body_params["phone_number"] = self._phone_number.to_api()
if self._postal_code.value_set:
body_params["postal_code"] = self._postal_code.to_api()
if self._sales_contact.value_set:
body_params["sales_contact"] = self._sales_contact.to_api()
if self._state.value_set:
body_params["state"] = self._state.to_api()
return self._client.call_api(
method="put",
path="/v3/accounts/{account_id}",
content_type="application/json",
body_params=body_params,
path_params={"account_id": self._id.to_api()},
unpack=self,
)
def user_invitations(self, filter=None, order="ASC", max_results=None, page_size=50, include=None):
"""Get the details of all user invitations.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/user-invitations>`_.
**API Filters**
The following filters are supported by the API when listing Account entities:
+----------------+------+------+------+------+------+------+------+
| Field | eq | neq | gte | lte | in | nin | like |
+================+======+======+======+======+======+======+======+
| login_profiles | Y | | | | | | |
+----------------+------+------+------+------+------+------+------+
**Example Usage**
.. code-block:: python
from mbed_cloud.foundation import Account
from mbed_cloud import ApiFilter
api_filter = ApiFilter()
api_filter.add_filter("login_profiles", "eq", <filter value>)
for user_invitation in Account().user_invitations(filter=api_filter):
print(user_invitation.login_profiles)
:param filter: An optional filter to apply when listing entities, please see the
above **API Filters** table for supported filters.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order based on creation time. Acceptable values: ASC, DESC.
Default: ASC.
:type order: str
:param max_results: Total maximum number of results to retrieve
:type max_results: int
:param page_size: The number of results to return (2-1000). Default 50.
:type page_size: int
:param include: Comma separated additional data to return.
:type include: str
:return: An iterator object which yields instances of an entity.
:rtype: mbed_cloud.pagination.PaginatedResponse(SubtenantUserInvitation)
"""
from mbed_cloud.foundation._custom_methods import paginate
from mbed_cloud.foundation import SubtenantUserInvitation
from mbed_cloud import ApiFilter
# Be permissive and accept an instance of a dictionary as this was how the Legacy interface worked.
if isinstance(filter, dict):
filter = ApiFilter(filter_definition=filter, field_renames=SubtenantUserInvitation._renames_to_api)
# The preferred method is an ApiFilter instance as this should be easier to use.
elif isinstance(filter, ApiFilter):
# If filter renames have not be defined then configure the ApiFilter so that any renames
# performed by the SDK are reversed when the query parameters are created.
if filter.field_renames is None:
filter.field_renames = SubtenantUserInvitation._renames_to_api
elif filter is not None:
raise TypeError("The 'filter' parameter may be either 'dict' or 'ApiFilter'.")
return paginate(
self=self,
foreign_key=SubtenantUserInvitation,
filter=filter,
order=order,
max_results=max_results,
page_size=page_size,
include=include,
wraps=self._paginate_user_invitations,
)
def users(self, filter=None, order="ASC", max_results=None, page_size=50, include=None):
"""Get the details of all users.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/users>`_.
**API Filters**
The following filters are supported by the API when listing Account entities:
+----------------+------+------+------+------+------+------+------+
| Field | eq | neq | gte | lte | in | nin | like |
+================+======+======+======+======+======+======+======+
| email | Y | | | | | | |
+----------------+------+------+------+------+------+------+------+
| login_profiles | Y | | | | | | |
+----------------+------+------+------+------+------+------+------+
| status | Y | | | | Y | Y | |
+----------------+------+------+------+------+------+------+------+
**Example Usage**
.. code-block:: python
from mbed_cloud.foundation import Account
from mbed_cloud import ApiFilter
api_filter = ApiFilter()
api_filter.add_filter("email", "eq", <filter value>)
for user in Account().users(filter=api_filter):
print(user.email)
:param filter: An optional filter to apply when listing entities, please see the
above **API Filters** table for supported filters.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order based on creation time. Acceptable values: ASC, DESC.
Default: ASC.
:type order: str
:param max_results: Total maximum number of results to retrieve
:type max_results: int
:param page_size: The number of results to return (2-1000). Default 50.
:type page_size: int
:param include: Comma-separated additional data to return. Currently supported:
total_count.
:type include: str
:return: An iterator object which yields instances of an entity.
:rtype: mbed_cloud.pagination.PaginatedResponse(SubtenantUser)
"""
from mbed_cloud.foundation._custom_methods import paginate
from mbed_cloud.foundation import SubtenantUser
from mbed_cloud import ApiFilter
# Be permissive and accept an instance of a dictionary as this was how the Legacy interface worked.
if isinstance(filter, dict):
filter = ApiFilter(filter_definition=filter, field_renames=SubtenantUser._renames_to_api)
# The preferred method is an ApiFilter instance as this should be easier to use.
elif isinstance(filter, ApiFilter):
# If filter renames have not be defined then configure the ApiFilter so that any renames
# performed by the SDK are reversed when the query parameters are created.
if filter.field_renames is None:
filter.field_renames = SubtenantUser._renames_to_api
elif filter is not None:
raise TypeError("The 'filter' parameter may be either 'dict' or 'ApiFilter'.")
return paginate(
self=self,
foreign_key=SubtenantUser,
filter=filter,
order=order,
max_results=max_results,
page_size=page_size,
include=include,
wraps=self._paginate_users,
)
|
class Account(Entity):
'''Represents the `Account` entity in Pelion Device Management'''
def __init__(
self,
_client=None,
address_line1=None,
address_line2=None,
admin_email=None,
admin_full_name=None,
admin_id=None,
admin_key=None,
admin_name=None,
admin_password=None,
aliases=None,
city=None,
company=None,
contact=None,
contract_number=None,
country=None,
created_at=None,
custom_fields=None,
customer_number=None,
display_name=None,
email=None,
end_market=None,
expiration=None,
expiration_warning_threshold=None,
id=None,
idle_timeout=None,
limits=None,
mfa_status=None,
notification_emails=None,
parent_account=None,
parent_id=None,
password_policy=None,
password_recovery_expiration=None,
phone_number=None,
policies=None,
postal_code=None,
reason=None,
reference_note=None,
sales_contact=None,
state=None,
status=None,
template_id=None,
tier=None,
updated_at=None,
upgraded_at=None,
):
'''Creates a local `Account` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param address_line1: Postal address line 1.
:type address_line1: str
:param address_line2: Postal address line 2.
:type address_line2: str
:param admin_email: The email address of the admin user created for this account.
Present only in the response for account creation.
:type admin_email: str
:param admin_full_name: The full name of the admin user created for this account. Present
only in the response for account creation.
:type admin_full_name: str
:param admin_id: The ID of the admin user created for this account.
:type admin_id: str
:param admin_key: The admin API key created for this account. Present only in the
response for account creation.
:type admin_key: str
:param admin_name: The username of the admin user created for this account. Present
only in the response for account creation.
:type admin_name: str
:param admin_password: The password of the admin user created for this account. Present
only in the response for account creation.
:type admin_password: str
:param aliases: An array of aliases.
:type aliases: list
:param city: The city part of the postal address.
:type city: str
:param company: The name of the company.
:type company: str
:param contact: The name of the contact person for this account.
:type contact: str
:param contract_number: Contract number of the customer.
:type contract_number: str
:param country: The country part of the postal address.
:type country: str
:param created_at: Creation UTC time RFC3339.
:type created_at: datetime
:param custom_fields: Account's custom properties as key-value pairs.
:type custom_fields: dict
:param customer_number: Customer number of the customer.
:type customer_number: str
:param display_name: The display name for the account.
:type display_name: str
:param email: The company email address for this account.
:type email: str
:param end_market: (Required) Account end market.
:type end_market: str
:param expiration: Expiration time of the account, as UTC time RFC3339.
:type expiration: datetime
:param expiration_warning_threshold: Indicates how many days (1-180) before account expiration a
notification email is sent.
:type expiration_warning_threshold: int
:param id: (Required) Account ID.
:type id: str
:param idle_timeout: The reference token expiration time, in minutes, for this account.
:type idle_timeout: int
:param limits: List of limits as key-value pairs if requested.
:type limits: dict
:param mfa_status: The enforcement status of multi-factor authentication, either
`enforced` or `optional`.
:type mfa_status: str
:param notification_emails: A list of notification email addresses.
:type notification_emails: list
:param parent_account: Represents parent account contact details in responses.
:type parent_account: dict
:param parent_id: The ID of the parent account, if any.
:type parent_id: str
:param password_policy: The password policy for this account.
:type password_policy: dict
:param password_recovery_expiration: Indicates for how many minutes a password recovery email is valid.
:type password_recovery_expiration: int
:param phone_number: The phone number of a company representative.
:type phone_number: str
:param policies: List of policies if requested.
:type policies: list
:param postal_code: The postal code part of the postal address.
:type postal_code: str
:param reason: A note with the reason for account status update.
:type reason: str
:param reference_note: A reference note for updating the status of the account.
:type reference_note: str
:param sales_contact: Email address of the sales contact.
:type sales_contact: str
:param state: The state part of the postal address.
:type state: str
:param status: The status of the account.
:type status: str
:param template_id: Account template ID.
:type template_id: str
:param tier: The tier level of the account; `0`: free tier, `1`: commercial
account, `2`: partner tier. Other values are reserved for the
future.
:type tier: str
:param updated_at: Last update UTC time RFC3339.
:type updated_at: datetime
:param upgraded_at: Time when upgraded to commercial account in UTC format RFC3339.
:type upgraded_at: datetime
'''
pass
@property
def address_line1(self):
'''Postal address line 1.
api example: '110 Fulbourn Rd'
:rtype: str
'''
pass
@address_line1.setter
def address_line1(self):
'''Set value of `address_line1`
:param value: value to set
:type value: str
'''
pass
@property
def address_line2(self):
'''Postal address line 2.
api example: ' '
:rtype: str
'''
pass
@address_line2.setter
def address_line2(self):
'''Set value of `address_line2`
:param value: value to set
:type value: str
'''
pass
@property
def admin_email(self):
'''The email address of the admin user created for this account. Present only in
the response for account creation.
api example: 'admin@arm.com'
:rtype: str
'''
pass
@admin_email.setter
def admin_email(self):
'''Set value of `admin_email`
:param value: value to set
:type value: str
'''
pass
@property
def admin_full_name(self):
'''The full name of the admin user created for this account. Present only in the
response for account creation.
api example: 'Admin Doe'
:rtype: str
'''
pass
@admin_full_name.setter
def admin_full_name(self):
'''Set value of `admin_full_name`
:param value: value to set
:type value: str
'''
pass
@property
def admin_id(self):
'''The ID of the admin user created for this account.
api example: '01619571e2e89242ac12000600000000'
:rtype: str
'''
pass
@property
def admin_key(self):
'''The admin API key created for this account. Present only in the response for
account creation.
api example: 'ak_1MDE2MTk1NzFmNmU4MDI0MmFjMTIwMDA2MDAwMDAwMDA01619571f7020242ac120006000000
00B40IkJADMANmAscAj0Ot0n2yeQnyt9tT'
:rtype: str
'''
pass
@property
def admin_name(self):
'''The username of the admin user created for this account. Present only in the
response for account creation.
api example: 'admin'
:rtype: str
'''
pass
@admin_name.setter
def admin_name(self):
'''Set value of `admin_name`
:param value: value to set
:type value: str
'''
pass
@property
def admin_password(self):
'''The password of the admin user created for this account. Present only in the
response for account creation.
api example: 'PZf9eEUH43DAPE9ULINFeuj'
:rtype: str
'''
pass
@admin_password.setter
def admin_password(self):
'''Set value of `admin_password`
:param value: value to set
:type value: str
'''
pass
@property
def aliases(self):
'''An array of aliases.
:rtype: list
'''
pass
@aliases.setter
def aliases(self):
'''Set value of `aliases`
:param value: value to set
:type value: list
'''
pass
@property
def city(self):
'''The city part of the postal address.
api example: 'Cambridge'
:rtype: str
'''
pass
@city.setter
def city(self):
'''Set value of `city`
:param value: value to set
:type value: str
'''
pass
@property
def company(self):
'''The name of the company.
api example: 'ARM Holdings Plc'
:rtype: str
'''
pass
@company.setter
def company(self):
'''Set value of `company`
:param value: value to set
:type value: str
'''
pass
@property
def contact(self):
'''The name of the contact person for this account.
api example: 'J. Doe'
:rtype: str
'''
pass
@contact.setter
def contact(self):
'''Set value of `contact`
:param value: value to set
:type value: str
'''
pass
@property
def contract_number(self):
'''Contract number of the customer.
api example: '1NX25_0001'
:rtype: str
'''
pass
@contract_number.setter
def contract_number(self):
'''Set value of `contract_number`
:param value: value to set
:type value: str
'''
pass
@property
def country(self):
'''The country part of the postal address.
api example: 'United Kingdom'
:rtype: str
'''
pass
@country.setter
def country(self):
'''Set value of `country`
:param value: value to set
:type value: str
'''
pass
@property
def created_at(self):
'''Creation UTC time RFC3339.
api example: '2018-02-13T09:35:20Z'
:rtype: datetime
'''
pass
@property
def custom_fields(self):
'''Account's custom properties as key-value pairs.
:rtype: dict
'''
pass
@custom_fields.setter
def custom_fields(self):
'''Set value of `custom_fields`
:param value: value to set
:type value: dict
'''
pass
@property
def customer_number(self):
'''Customer number of the customer.
api example: '1NC25_0001'
:rtype: str
'''
pass
@customer_number.setter
def customer_number(self):
'''Set value of `customer_number`
:param value: value to set
:type value: str
'''
pass
@property
def display_name(self):
'''The display name for the account.
api example: 'ARM'
:rtype: str
'''
pass
@display_name.setter
def display_name(self):
'''Set value of `display_name`
:param value: value to set
:type value: str
'''
pass
@property
def email(self):
'''The company email address for this account.
api example: 'info@arm.com'
:rtype: str
'''
pass
@email.setter
def email(self):
'''Set value of `email`
:param value: value to set
:type value: str
'''
pass
@property
def end_market(self):
'''Account end market.
This field must be set when creating a new Account Entity.
api example: 'IT'
:rtype: str
'''
pass
@end_market.setter
def end_market(self):
'''Set value of `end_market`
:param value: value to set
:type value: str
'''
pass
@property
def expiration(self):
'''Expiration time of the account, as UTC time RFC3339.
:rtype: datetime
'''
pass
@property
def expiration_warning_threshold(self):
'''Indicates how many days (1-180) before account expiration a notification email
is sent.
api example: '180'
:rtype: int
'''
pass
@expiration_warning_threshold.setter
def expiration_warning_threshold(self):
'''Set value of `expiration_warning_threshold`
:param value: value to set
:type value: int
'''
pass
@property
def id(self):
'''Account ID.
This field must be set when updating or deleting an existing Account Entity.
api example: '01619571e2e90242ac12000600000000'
:rtype: str
'''
pass
@id.setter
def id(self):
'''Set value of `id`
:param value: value to set
:type value: str
'''
pass
@property
def idle_timeout(self):
'''The reference token expiration time, in minutes, for this account.
api example: '30'
:rtype: int
'''
pass
@idle_timeout.setter
def idle_timeout(self):
'''Set value of `idle_timeout`
:param value: value to set
:type value: int
'''
pass
@property
def limits(self):
'''List of limits as key-value pairs if requested.
:rtype: dict
'''
pass
@property
def mfa_status(self):
'''The enforcement status of multi-factor authentication, either `enforced` or
`optional`.
:rtype: str
'''
pass
@mfa_status.setter
def mfa_status(self):
'''Set value of `mfa_status`
:param value: value to set
:type value: str
'''
pass
@property
def notification_emails(self):
'''A list of notification email addresses.
:rtype: list
'''
pass
@notification_emails.setter
def notification_emails(self):
'''Set value of `notification_emails`
:param value: value to set
:type value: list
'''
pass
@property
def parent_account(self):
'''Represents parent account contact details in responses.
:rtype: dict[ParentAccount]
'''
pass
@property
def parent_id(self):
'''The ID of the parent account, if any.
api example: '01619571dad80242ac12000600000000'
:rtype: str
'''
pass
@property
def password_policy(self):
'''The password policy for this account.
:rtype: dict[PasswordPolicy]
'''
pass
@password_policy.setter
def password_policy(self):
'''Set value of `password_policy`
:param value: value to set
:type value: dict[PasswordPolicy]
'''
pass
@property
def password_recovery_expiration(self):
'''Indicates for how many minutes a password recovery email is valid.
:rtype: int
'''
pass
@password_recovery_expiration.setter
def password_recovery_expiration(self):
'''Set value of `password_recovery_expiration`
:param value: value to set
:type value: int
'''
pass
@property
def phone_number(self):
'''The phone number of a company representative.
api example: '+44 (1223) 400 400'
:rtype: str
'''
pass
@phone_number.setter
def phone_number(self):
'''Set value of `phone_number`
:param value: value to set
:type value: str
'''
pass
@property
def policies(self):
'''List of policies if requested.
:rtype: list[Policy]
'''
pass
@property
def postal_code(self):
'''The postal code part of the postal address.
api example: 'CB1 9NJ'
:rtype: str
'''
pass
@postal_code.setter
def postal_code(self):
'''Set value of `postal_code`
:param value: value to set
:type value: str
'''
pass
@property
def reason(self):
'''A note with the reason for account status update.
api example: 'Subscription paid.'
:rtype: str
'''
pass
@property
def reference_note(self):
'''A reference note for updating the status of the account.
api example: 'ARM-INT-0001'
:rtype: str
'''
pass
@property
def sales_contact(self):
'''Email address of the sales contact.
api example: 'sales@arm.com'
:rtype: str
'''
pass
@sales_contact.setter
def sales_contact(self):
'''Set value of `sales_contact`
:param value: value to set
:type value: str
'''
pass
@property
def state(self):
'''The state part of the postal address.
api example: ' '
:rtype: str
'''
pass
@state.setter
def state(self):
'''Set value of `state`
:param value: value to set
:type value: str
'''
pass
@property
def status(self):
'''The status of the account.
api example: 'ACTIVE'
:rtype: str
'''
pass
@property
def template_id(self):
'''Account template ID.
api example: '01619571e7160242ac12000600000000'
:rtype: str
'''
pass
@property
def tier(self):
'''The tier level of the account; `0`: free tier, `1`: commercial account, `2`:
partner tier. Other values are reserved for the future.
api example: '1'
:rtype: str
'''
pass
@property
def updated_at(self):
'''Last update UTC time RFC3339.
api example: '2018-02-14T15:24:14Z'
:rtype: datetime
'''
pass
@property
def upgraded_at(self):
'''Time when upgraded to commercial account in UTC format RFC3339.
api example: '2018-02-14T15:24:14Z'
:rtype: datetime
'''
pass
def api_keys(self, filter=None, order="ASC", max_results=None, page_size=50, include=None):
'''Get all API keys.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/api-keys>`_.
**API Filters**
The following filters are supported by the API when listing Account entities:
+-------+------+------+------+------+------+------+------+
| Field | eq | neq | gte | lte | in | nin | like |
+=======+======+======+======+======+======+======+======+
| key | Y | | | | | | |
+-------+------+------+------+------+------+------+------+
| owner | Y | | | | | | |
+-------+------+------+------+------+------+------+------+
**Example Usage**
.. code-block:: python
from mbed_cloud.foundation import Account
from mbed_cloud import ApiFilter
api_filter = ApiFilter()
api_filter.add_filter("key", "eq", <filter value>)
for api_key in Account().api_keys(filter=api_filter):
print(api_key.key)
:param filter: An optional filter to apply when listing entities, please see the
above **API Filters** table for supported filters.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order based on creation time. Acceptable values: ASC, DESC.
Default: ASC.
:type order: str
:param max_results: Total maximum number of results to retrieve
:type max_results: int
:param page_size: The number of results to return (2-1000). Default 50.
:type page_size: int
:param include: Comma-separated additional data to return. Currently supported:
total_count.
:type include: str
:return: An iterator object which yields instances of an entity.
:rtype: mbed_cloud.pagination.PaginatedResponse(SubtenantApiKey)
'''
pass
def created_at(self):
'''Create a new account.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts>`_.
:param action: Action, either `create` or `enroll`.
<ul>
<li>`create` creates the
account where its admin user has ACTIVE status if `admin_password` was
defined in the request, or RESET status if no `admin_password` was
defined. If the user already exists, its status is not modified. </li>
<li>`enroll` creates the account where its admin user has ENROLLING
status. If the user already exists, its status is not modified. Email
to finish enrollment or notify the existing user about the new account
is sent to the `admin_email` defined in the request. </li></ul>
:type action: str
:rtype: Account
'''
pass
def dark_theme_branding_colors(self, filter=None, order=None, max_results=None, page_size=None, include=None):
'''Get dark theme branding colors.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/branding-colors/dark>`_.
:param filter: Filtering when listing entities is not supported by the API for this
entity.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: The order of the records based on creation time, ASC or DESC. Default
value is ASC
:type order: str
:param max_results: Total maximum number of results to retrieve
:type max_results: int
:param page_size: The number of results to return for each page.
:type page_size: int
:param include: Comma separated additional data to return.
:type include: str
:return: An iterator object which yields instances of an entity.
:rtype: mbed_cloud.pagination.PaginatedResponse(SubtenantDarkThemeColor)
'''
pass
def dark_theme_branding_images(self, filter=None, order=None, max_results=None, page_size=None, include=None):
'''Get metadata of all dark theme images.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/branding-images/dark>`_.
:param filter: Filtering when listing entities is not supported by the API for this
entity.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: The order of the records based on creation time, ASC or DESC. Default
value is ASC
:type order: str
:param max_results: Total maximum number of results to retrieve
:type max_results: int
:param page_size: The number of results to return for each page.
:type page_size: int
:param include: Comma separated additional data to return.
:type include: str
:return: An iterator object which yields instances of an entity.
:rtype: mbed_cloud.pagination.PaginatedResponse(SubtenantDarkThemeImage)
'''
pass
def light_theme_branding_colors(self, filter=None, order=None, max_results=None, page_size=None, include=None):
'''Get light theme branding colors.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/branding-colors/light>`_.
:param filter: Filtering when listing entities is not supported by the API for this
entity.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: The order of the records based on creation time, ASC or DESC. Default
value is ASC
:type order: str
:param max_results: Total maximum number of results to retrieve
:type max_results: int
:param page_size: The number of results to return for each page.
:type page_size: int
:param include: Comma separated additional data to return.
:type include: str
:return: An iterator object which yields instances of an entity.
:rtype: mbed_cloud.pagination.PaginatedResponse(SubtenantLightThemeColor)
'''
pass
def light_theme_branding_images(self, filter=None, order=None, max_results=None, page_size=None, include=None):
'''Get metadata of all light theme images.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/branding-images/light>`_.
:param filter: Filtering when listing entities is not supported by the API for this
entity.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: The order of the records based on creation time, ASC or DESC. Default
value is ASC
:type order: str
:param max_results: Total maximum number of results to retrieve
:type max_results: int
:param page_size: The number of results to return for each page.
:type page_size: int
:param include: Comma separated additional data to return.
:type include: str
:return: An iterator object which yields instances of an entity.
:rtype: mbed_cloud.pagination.PaginatedResponse(SubtenantLightThemeImage)
'''
pass
def list(
self, filter=None, order="ASC", max_results=None, page_size=1000, include=None, format=None, properties=None
):
'''Get all accounts.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts>`_.
**API Filters**
The following filters are supported by the API when listing Account entities:
+------------+------+------+------+------+------+------+------+
| Field | eq | neq | gte | lte | in | nin | like |
+============+======+======+======+======+======+======+======+
| country | | | | | | | Y |
+------------+------+------+------+------+------+------+------+
| end_market | Y | | | | | | |
+------------+------+------+------+------+------+------+------+
| parent | Y | | | | | | |
+------------+------+------+------+------+------+------+------+
| status | Y | | | | Y | Y | |
+------------+------+------+------+------+------+------+------+
| tier | Y | | | | | | |
+------------+------+------+------+------+------+------+------+
**Example Usage**
.. code-block:: python
from mbed_cloud.foundation import Account
from mbed_cloud import ApiFilter
api_filter = ApiFilter()
api_filter.add_filter("country", "like", <filter value>)
for account in Account().list(filter=api_filter):
print(account.country)
:param filter: An optional filter to apply when listing entities, please see the
above **API Filters** table for supported filters.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order. Acceptable values: ASC, DESC. Default: ASC.
:type order: str
:param max_results: Total maximum number of results to retrieve
:type max_results: int
:param page_size: The number of results to return (2-1000). Default 1000.
:type page_size: int
:param include: Comma-separated additional data to return. Currently supported:
limits, policies, sub_accounts.
:type include: str
:param format: Format information for the query response. Supported:
format=breakdown.
:type format: str
:param properties: Property name returned from account-specific properties.
:type properties: str
:return: An iterator object which yields instances of an entity.
:rtype: mbed_cloud.pagination.PaginatedResponse(Account)
'''
pass
def me(self, include=None, properties=None):
'''Get account info.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/me>`_.
:param include: Comma-separated additional data to return. Currently supported:
limits, policies, sub_accounts.
:type include: str
:param properties: Property name to return from account-specific properties.
:type properties: str
:rtype: Account
'''
pass
def _paginate_api_keys(self, after=None, filter=None, order="ASC", limit=50, include=None):
'''Get all API keys.
:param after: The entity ID to fetch after the given one.
:type after: str
:param filter: Optional API filter for listing resources.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order based on creation time. Acceptable values: ASC, DESC.
Default: ASC.
:type order: str
:param limit: The number of results to return (2-1000). Default 50.
:type limit: int
:param include: Comma-separated additional data to return. Currently supported:
total_count.
:type include: str
:rtype: mbed_cloud.pagination.PaginatedResponse
'''
pass
def _paginate_dark_theme_branding_colors(self, after=None, filter=None, order=None, limit=None, include=None):
'''Get dark theme branding colors.
:param after: Not supported by the API.
:type after: str
:param filter: Optional API filter for listing resources.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Not supported by the API.
:type order: str
:param limit: Not supported by the API.
:type limit: int
:param include: Not supported by the API.
:type include: str
:rtype: mbed_cloud.pagination.PaginatedResponse
'''
pass
def _paginate_dark_theme_branding_images(self, after=None, filter=None, order=None, limit=None, include=None):
'''Get metadata of all dark theme images.
:param after: Not supported by the API.
:type after: str
:param filter: Optional API filter for listing resources.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Not supported by the API.
:type order: str
:param limit: Not supported by the API.
:type limit: int
:param include: Not supported by the API.
:type include: str
:rtype: mbed_cloud.pagination.PaginatedResponse
'''
pass
def _paginate_light_theme_branding_colors(self, after=None, filter=None, order=None, limit=None, include=None):
'''Get light theme branding colors.
:param after: Not supported by the API.
:type after: str
:param filter: Optional API filter for listing resources.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Not supported by the API.
:type order: str
:param limit: Not supported by the API.
:type limit: int
:param include: Not supported by the API.
:type include: str
:rtype: mbed_cloud.pagination.PaginatedResponse
'''
pass
def _paginate_light_theme_branding_images(self, after=None, filter=None, order=None, limit=None, include=None):
'''Get metadata of all light theme images.
:param after: Not supported by the API.
:type after: str
:param filter: Optional API filter for listing resources.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Not supported by the API.
:type order: str
:param limit: Not supported by the API.
:type limit: int
:param include: Not supported by the API.
:type include: str
:rtype: mbed_cloud.pagination.PaginatedResponse
'''
pass
def _paginate_list(
self, after=None, filter=None, order="ASC", limit=1000, include=None, format=None, properties=None
):
'''Get all accounts.
:param after: The entity ID to fetch after the given one.
:type after: str
:param filter: Optional API filter for listing resources.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order. Acceptable values: ASC, DESC. Default: ASC.
:type order: str
:param limit: The number of results to return (2-1000). Default 1000.
:type limit: int
:param include: Comma-separated additional data to return. Currently supported:
limits, policies, sub_accounts.
:type include: str
:param format: Format information for the query response. Supported:
format=breakdown.
:type format: str
:param properties: Property name returned from account-specific properties.
:type properties: str
:rtype: mbed_cloud.pagination.PaginatedResponse
'''
pass
def _paginate_trusted_certificates(self, after=None, filter=None, order="ASC", limit=50, include=None):
'''Get all trusted certificates.
:param after: The entity ID to fetch after the given one.
:type after: str
:param filter: Optional API filter for listing resources.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order based on creation time. Acceptable values: ASC, DESC.
Default: ASC.
:type order: str
:param limit: The number of results to return (2-1000). Default 50.
:type limit: int
:param include: Comma-separated additional data to return. Currently supported:
total_count.
:type include: str
:rtype: mbed_cloud.pagination.PaginatedResponse
'''
pass
def _paginate_user_invitations(self, after=None, filter=None, order="ASC", limit=50, include=None):
'''Get the details of all user invitations.
:param after: The entity ID to fetch after the given one.
:type after: str
:param filter: Optional API filter for listing resources.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order based on creation time. Acceptable values: ASC, DESC.
Default: ASC.
:type order: str
:param limit: The number of results to return (2-1000). Default 50.
:type limit: int
:param include: Not supported by the API.
:type include: str
:rtype: mbed_cloud.pagination.PaginatedResponse
'''
pass
def _paginate_users(self, after=None, filter=None, order="ASC", limit=50, include=None):
'''Get the details of all users.
:param after: The entity ID to fetch after the given one.
:type after: str
:param filter: Optional API filter for listing resources.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order based on creation time. Acceptable values: ASC, DESC.
Default: ASC.
:type order: str
:param limit: The number of results to return (2-1000). Default 50.
:type limit: int
:param include: Comma-separated additional data to return. Currently supported:
total_count.
:type include: str
:rtype: mbed_cloud.pagination.PaginatedResponse
'''
pass
def read(self, include=None, properties=None):
'''Get account info.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}>`_.
:param include: Comma-separated additional data to return. Currently supported:
limits, policies, sub_accounts.
:type include: str
:param properties: Property name to return from account-specific properties.
:type properties: str
:rtype: Account
'''
pass
def trusted_certificates(self, filter=None, order="ASC", max_results=None, page_size=50, include=None):
'''Get all trusted certificates.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/trusted-certificates>`_.
**API Filters**
The following filters are supported by the API when listing Account entities:
+-----------------------+------+------+------+------+------+------+------+
| Field | eq | neq | gte | lte | in | nin | like |
+=======================+======+======+======+======+======+======+======+
| device_execution_mode | Y | Y | | | | | |
+-----------------------+------+------+------+------+------+------+------+
| enrollment_mode | Y | | | | | | |
+-----------------------+------+------+------+------+------+------+------+
| expire | Y | | | | | | |
+-----------------------+------+------+------+------+------+------+------+
| issuer | | | | | | | Y |
+-----------------------+------+------+------+------+------+------+------+
| name | Y | | | | | | |
+-----------------------+------+------+------+------+------+------+------+
| owner | Y | | | | | | |
+-----------------------+------+------+------+------+------+------+------+
| service | Y | | | | | | |
+-----------------------+------+------+------+------+------+------+------+
| status | Y | | | | | | |
+-----------------------+------+------+------+------+------+------+------+
| subject | | | | | | | Y |
+-----------------------+------+------+------+------+------+------+------+
| valid | Y | | | | | | |
+-----------------------+------+------+------+------+------+------+------+
**Example Usage**
.. code-block:: python
from mbed_cloud.foundation import Account
from mbed_cloud import ApiFilter
api_filter = ApiFilter()
api_filter.add_filter("device_execution_mode", "eq", <filter value>)
for trusted_certificate in Account().trusted_certificates(filter=api_filter):
print(trusted_certificate.device_execution_mode)
:param filter: An optional filter to apply when listing entities, please see the
above **API Filters** table for supported filters.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order based on creation time. Acceptable values: ASC, DESC.
Default: ASC.
:type order: str
:param max_results: Total maximum number of results to retrieve
:type max_results: int
:param page_size: The number of results to return (2-1000). Default 50.
:type page_size: int
:param include: Comma-separated additional data to return. Currently supported:
total_count.
:type include: str
:return: An iterator object which yields instances of an entity.
:rtype: mbed_cloud.pagination.PaginatedResponse(SubtenantTrustedCertificate)
'''
pass
def updated_at(self):
'''Update attributes of an existing account.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}>`_.
:rtype: Account
'''
pass
def user_invitations(self, filter=None, order="ASC", max_results=None, page_size=50, include=None):
'''Get the details of all user invitations.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/user-invitations>`_.
**API Filters**
The following filters are supported by the API when listing Account entities:
+----------------+------+------+------+------+------+------+------+
| Field | eq | neq | gte | lte | in | nin | like |
+================+======+======+======+======+======+======+======+
| login_profiles | Y | | | | | | |
+----------------+------+------+------+------+------+------+------+
**Example Usage**
.. code-block:: python
from mbed_cloud.foundation import Account
from mbed_cloud import ApiFilter
api_filter = ApiFilter()
api_filter.add_filter("login_profiles", "eq", <filter value>)
for user_invitation in Account().user_invitations(filter=api_filter):
print(user_invitation.login_profiles)
:param filter: An optional filter to apply when listing entities, please see the
above **API Filters** table for supported filters.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order based on creation time. Acceptable values: ASC, DESC.
Default: ASC.
:type order: str
:param max_results: Total maximum number of results to retrieve
:type max_results: int
:param page_size: The number of results to return (2-1000). Default 50.
:type page_size: int
:param include: Comma separated additional data to return.
:type include: str
:return: An iterator object which yields instances of an entity.
:rtype: mbed_cloud.pagination.PaginatedResponse(SubtenantUserInvitation)
'''
pass
def users(self, filter=None, order="ASC", max_results=None, page_size=50, include=None):
'''Get the details of all users.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/users>`_.
**API Filters**
The following filters are supported by the API when listing Account entities:
+----------------+------+------+------+------+------+------+------+
| Field | eq | neq | gte | lte | in | nin | like |
+================+======+======+======+======+======+======+======+
| email | Y | | | | | | |
+----------------+------+------+------+------+------+------+------+
| login_profiles | Y | | | | | | |
+----------------+------+------+------+------+------+------+------+
| status | Y | | | | Y | Y | |
+----------------+------+------+------+------+------+------+------+
**Example Usage**
.. code-block:: python
from mbed_cloud.foundation import Account
from mbed_cloud import ApiFilter
api_filter = ApiFilter()
api_filter.add_filter("email", "eq", <filter value>)
for user in Account().users(filter=api_filter):
print(user.email)
:param filter: An optional filter to apply when listing entities, please see the
above **API Filters** table for supported filters.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order based on creation time. Acceptable values: ASC, DESC.
Default: ASC.
:type order: str
:param max_results: Total maximum number of results to retrieve
:type max_results: int
:param page_size: The number of results to return (2-1000). Default 50.
:type page_size: int
:param include: Comma-separated additional data to return. Currently supported:
total_count.
:type include: str
:return: An iterator object which yields instances of an entity.
:rtype: mbed_cloud.pagination.PaginatedResponse(SubtenantUser)
'''
pass
| 166 | 95 | 21 | 4 | 7 | 9 | 2 | 1.14 | 1 | 23 | 20 | 0 | 94 | 43 | 94 | 105 | 2,170 | 502 | 781 | 304 | 535 | 887 | 428 | 183 | 303 | 24 | 2 | 2 | 181 |
2,271 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/accounts/enums.py
|
mbed_cloud.foundation.entities.accounts.enums.UserInvitationOrderEnum
|
class UserInvitationOrderEnum(BaseEnum):
"""Represents expected values of `UserInvitationOrderEnum`
This is used by Entities in the "accounts" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
"""
ASC = "ASC"
DESC = "DESC"
values = frozenset(("ASC", "DESC"))
|
class UserInvitationOrderEnum(BaseEnum):
'''Represents expected values of `UserInvitationOrderEnum`
This is used by Entities in the "accounts" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
'''
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1.5 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 14 | 4 | 4 | 4 | 3 | 6 | 4 | 4 | 3 | 0 | 2 | 0 | 0 |
2,272 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/tests/unit/asynchronous/test_resource_value_channel.py
|
tests.unit.asynchronous.test_resource_value_channel.TestMatchingDeviceResources
|
class TestMatchingDeviceResources(BaseCase):
def test_observable_single(self):
channel = channels.ResourceValues(
device_id="Device1",
resource_path="/10252/0/3")
# Mock the Connect API to return connected devices and available resources
channel._api = mock.Mock().method.return_value = FakeConnectAPI()
self.assertEqual([], channel._matching_device_resources(), "The specified resource was not observable")
def test_observable_list(self):
channel = channels.ResourceValues(
device_id="Device1",
resource_path=["/10252/0/1", "/10252/0/5"])
# Mock the Connect API to return connected devices and available resources
channel._api = mock.Mock().method.return_value = FakeConnectAPI()
self.assertEqual([('Device1', '/10252/0/5')],
channel._matching_device_resources(),
"Only the observable resources in the specified list, on Device1 should be returned")
def test_observable_pattern(self):
channel = channels.ResourceValues(
device_id="Device1",
resource_path="/10252/0/*")
# Mock the Connect API to return connected devices and available resources
channel._api = mock.Mock().method.return_value = FakeConnectAPI()
self.assertEqual(
[('Device1', '/10252/0/5'), ('Device1', '/10252/0/2')],
channel._matching_device_resources(),
"Only the observable resources beginning '/10252/0/' on Device1 should be returned")
def test_wildcard_resource(self):
channel = channels.ResourceValues(
device_id="Device1",
resource_path="/35011/0*")
# Mock the Connect API to return connected devices and available resources
channel._api = mock.Mock().method.return_value = FakeConnectAPI()
self.assertEqual(
[('Device1', '/35011/0'), ('Device1', '/35011/0/27002')],
channel._matching_device_resources(),
"'/35011/0*' should match all resource beginning '/35011/0'")
def test_list_device(self):
channel = channels.ResourceValues(
device_id=["Device1", "Device2"],
resource_path="/10252/0/5")
# Mock the Connect API to return connected devices and available resources
channel._api = mock.Mock().method.return_value = FakeConnectAPI()
self.assertEqual(
[('Device1', '/10252/0/5'), ('Device2', '/10252/0/5')],
channel._matching_device_resources(),
"Defining devices as a list should explicitly match device IDs")
def test_wildcard_device(self):
channel = channels.ResourceValues(
# device_id=["Device1", "Device2"],
device_id="Device*",
resource_path="/10252/0/5")
# Mock the Connect API to return connected devices and available resources
channel._api = mock.Mock().method.return_value = FakeConnectAPI()
self.assertEqual(
[('Device1', '/10252/0/5'), ('Device2', '/10252/0/5'), ('Device3', '/10252/0/5')],
channel._matching_device_resources(),
"'Device*' should not match all devices starting with 'Device'")
def test_device_no_match(self):
channel = channels.ResourceValues(
device_id="Device",
resource_path="*")
# Mock the Connect API to return connected devices and available resources
channel._api = mock.Mock().method.return_value = FakeConnectAPI()
self.assertEqual([], channel._matching_device_resources(), "'Device' should not match any devices")
def test_multiple_matches(self):
channel = channels.ResourceValues(
device_id=["Device1", "Device*"],
resource_path=["/35011/0", "/35011*"])
# Mock the Connect API to return connected devices and available resources
channel._api = mock.Mock().method.return_value = FakeConnectAPI()
self.assertEqual([('Device1', '/35011/0'), ('Device1', '/35011/0/27002'), ('Device2', '/35011/0'),
('Device2', '/35011/0/27002'), ('Device3', '/35011/0'), ('Device3', '/35011/0/27002')],
channel._matching_device_resources(),
"Each Device and resource path should be listed once")
|
class TestMatchingDeviceResources(BaseCase):
def test_observable_single(self):
pass
def test_observable_list(self):
pass
def test_observable_pattern(self):
pass
def test_wildcard_resource(self):
pass
def test_list_device(self):
pass
def test_wildcard_device(self):
pass
def test_device_no_match(self):
pass
def test_multiple_matches(self):
pass
| 9 | 0 | 10 | 1 | 8 | 1 | 1 | 0.14 | 1 | 2 | 2 | 0 | 8 | 0 | 8 | 80 | 91 | 16 | 66 | 17 | 57 | 9 | 33 | 17 | 24 | 1 | 3 | 0 | 8 |
2,273 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/tests/common.py
|
tests.common.BaseCase
|
class BaseCase(unittest.TestCase):
# path assuming that this file is at `tests\common.py`
_project_root_dir = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
_skip_in_ci = staticmethod(unittest.skipIf(os.environ.get('CI'), 'Do not run in CI'))
|
class BaseCase(unittest.TestCase):
pass
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0.33 | 1 | 0 | 0 | 55 | 0 | 0 | 0 | 72 | 4 | 0 | 3 | 3 | 2 | 1 | 3 | 3 | 2 | 0 | 2 | 0 | 0 |
2,274 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/tests/unit/asynchronous/test_resource_value_channel.py
|
tests.unit.asynchronous.test_resource_value_channel.FakeResource
|
class FakeResource(object):
def __init__(self, observable, path):
self.observable = observable
self.path = path
|
class FakeResource(object):
def __init__(self, observable, path):
pass
| 2 | 0 | 3 | 0 | 3 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 2 | 1 | 1 | 4 | 0 | 4 | 4 | 2 | 0 | 4 | 4 | 2 | 1 | 1 | 0 | 1 |
2,275 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/security/enums.py
|
mbed_cloud.foundation.entities.security.enums.CertificateEnrollmentIncludeEnum
|
class CertificateEnrollmentIncludeEnum(BaseEnum):
"""Represents expected values of `CertificateEnrollmentIncludeEnum`
This is used by Entities in the "security" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
"""
TOTAL_COUNT = "total_count"
values = frozenset(("total_count",))
|
class CertificateEnrollmentIncludeEnum(BaseEnum):
'''Represents expected values of `CertificateEnrollmentIncludeEnum`
This is used by Entities in the "security" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
'''
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 2 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 13 | 4 | 3 | 3 | 2 | 6 | 3 | 3 | 2 | 0 | 2 | 0 | 0 |
2,276 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/security/enums.py
|
mbed_cloud.foundation.entities.security.enums.CertificateEnrollmentOrderEnum
|
class CertificateEnrollmentOrderEnum(BaseEnum):
"""Represents expected values of `CertificateEnrollmentOrderEnum`
This is used by Entities in the "security" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
"""
ASC = "ASC"
DESC = "DESC"
values = frozenset(("ASC", "DESC"))
|
class CertificateEnrollmentOrderEnum(BaseEnum):
'''Represents expected values of `CertificateEnrollmentOrderEnum`
This is used by Entities in the "security" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
'''
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1.5 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 14 | 4 | 4 | 4 | 3 | 6 | 4 | 4 | 3 | 0 | 2 | 0 | 0 |
2,277 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/security/enums.py
|
mbed_cloud.foundation.entities.security.enums.CertificateIssuerTypeEnum
|
class CertificateIssuerTypeEnum(BaseEnum):
"""Represents expected values of `CertificateIssuerTypeEnum`
This is used by Entities in the "security" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
"""
CFSSL_AUTH = "CFSSL_AUTH"
GLOBAL_SIGN = "GLOBAL_SIGN"
values = frozenset(("CFSSL_AUTH", "GLOBAL_SIGN"))
|
class CertificateIssuerTypeEnum(BaseEnum):
'''Represents expected values of `CertificateIssuerTypeEnum`
This is used by Entities in the "security" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
'''
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1.5 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 14 | 4 | 4 | 4 | 3 | 6 | 4 | 4 | 3 | 0 | 2 | 0 | 0 |
2,278 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/security/enums.py
|
mbed_cloud.foundation.entities.security.enums.SubtenantTrustedCertificateServiceEnum
|
class SubtenantTrustedCertificateServiceEnum(BaseEnum):
"""Represents expected values of `SubtenantTrustedCertificateServiceEnum`
This is used by Entities in the "security" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
"""
BOOTSTRAP = "bootstrap"
LWM2M = "lwm2m"
values = frozenset(("bootstrap", "lwm2m"))
|
class SubtenantTrustedCertificateServiceEnum(BaseEnum):
'''Represents expected values of `SubtenantTrustedCertificateServiceEnum`
This is used by Entities in the "security" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
'''
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1.5 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 14 | 4 | 4 | 4 | 3 | 6 | 4 | 4 | 3 | 0 | 2 | 0 | 0 |
2,279 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/security/enums.py
|
mbed_cloud.foundation.entities.security.enums.SubtenantTrustedCertificateStatusEnum
|
class SubtenantTrustedCertificateStatusEnum(BaseEnum):
"""Represents expected values of `SubtenantTrustedCertificateStatusEnum`
This is used by Entities in the "security" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
"""
ACTIVE = "ACTIVE"
INACTIVE = "INACTIVE"
values = frozenset(("ACTIVE", "INACTIVE"))
|
class SubtenantTrustedCertificateStatusEnum(BaseEnum):
'''Represents expected values of `SubtenantTrustedCertificateStatusEnum`
This is used by Entities in the "security" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
'''
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1.5 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 14 | 4 | 4 | 4 | 3 | 6 | 4 | 4 | 3 | 0 | 2 | 0 | 0 |
2,280 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/security/enums.py
|
mbed_cloud.foundation.entities.security.enums.TrustedCertificateOrderEnum
|
class TrustedCertificateOrderEnum(BaseEnum):
"""Represents expected values of `TrustedCertificateOrderEnum`
This is used by Entities in the "security" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
"""
ASC = "ASC"
DESC = "DESC"
values = frozenset(("ASC", "DESC"))
|
class TrustedCertificateOrderEnum(BaseEnum):
'''Represents expected values of `TrustedCertificateOrderEnum`
This is used by Entities in the "security" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
'''
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1.5 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 14 | 4 | 4 | 4 | 3 | 6 | 4 | 4 | 3 | 0 | 2 | 0 | 0 |
2,281 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/security/enums.py
|
mbed_cloud.foundation.entities.security.enums.TrustedCertificateServiceEnum
|
class TrustedCertificateServiceEnum(BaseEnum):
"""Represents expected values of `TrustedCertificateServiceEnum`
This is used by Entities in the "security" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
"""
BOOTSTRAP = "bootstrap"
LWM2M = "lwm2m"
values = frozenset(("bootstrap", "lwm2m"))
|
class TrustedCertificateServiceEnum(BaseEnum):
'''Represents expected values of `TrustedCertificateServiceEnum`
This is used by Entities in the "security" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
'''
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1.5 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 14 | 4 | 4 | 4 | 3 | 6 | 4 | 4 | 3 | 0 | 2 | 0 | 0 |
2,282 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/security/enums.py
|
mbed_cloud.foundation.entities.security.enums.TrustedCertificateStatusEnum
|
class TrustedCertificateStatusEnum(BaseEnum):
"""Represents expected values of `TrustedCertificateStatusEnum`
This is used by Entities in the "security" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
"""
ACTIVE = "ACTIVE"
INACTIVE = "INACTIVE"
values = frozenset(("ACTIVE", "INACTIVE"))
|
class TrustedCertificateStatusEnum(BaseEnum):
'''Represents expected values of `TrustedCertificateStatusEnum`
This is used by Entities in the "security" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
'''
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1.5 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 14 | 4 | 4 | 4 | 3 | 6 | 4 | 4 | 3 | 0 | 2 | 0 | 0 |
2,283 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/security/pre_shared_key.py
|
mbed_cloud.foundation.entities.security.pre_shared_key.PreSharedKey
|
class PreSharedKey(Entity):
"""Represents the `PreSharedKey` entity in Pelion Device Management"""
# List of fields that are serialised between the API and SDK
_api_fieldnames = ["created_at", "endpoint_name", "id"]
# List of fields that are available for the user of the SDK
_sdk_fieldnames = _api_fieldnames
# Renames to be performed by the SDK when receiving data {<API Field Name>: <SDK Field Name>}
_renames = {}
# Renames to be performed by the SDK when sending data {<SDK Field Name>: <API Field Name>}
_renames_to_api = {}
def __init__(self, _client=None, created_at=None, endpoint_name=None, id=None):
"""Creates a local `PreSharedKey` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param created_at: The date-time (RFC3339) when this PSK was uploaded to Device
Management.
:type created_at: datetime
:param endpoint_name: The unique endpoint identifier that this PSK applies to. 16-64 [pr
intable](https://en.wikipedia.org/wiki/ASCII#Printable_characters)
(non-control) ASCII characters.
:type endpoint_name: str
:param id: The Id of the pre_shared_key, shadows the endpoint_name
:type id: str
"""
super().__init__(_client=_client)
# inline imports for avoiding circular references and bulk imports
# fields
self._created_at = fields.DateTimeField(value=created_at)
self._endpoint_name = fields.StringField(value=endpoint_name)
self._id = fields.StringField(value=id)
@property
def created_at(self):
"""The date-time (RFC3339) when this PSK was uploaded to Device Management.
api example: '2017-07-21T17:32:28.012Z'
:rtype: datetime
"""
return self._created_at.value
@property
def endpoint_name(self):
"""The unique endpoint identifier that this PSK applies to. 16-64
[printable](https://en.wikipedia.org/wiki/ASCII#Printable_characters) (non-
control) ASCII characters.
api example: 'my-endpoint-0001'
:rtype: str
"""
from mbed_cloud.foundation._custom_methods import pre_shared_key_id_getter
return pre_shared_key_id_getter(self=self)
@endpoint_name.setter
def endpoint_name(self, value):
"""Set value of `endpoint_name`
:param value: value to set
:type value: str
"""
from mbed_cloud.foundation._custom_methods import pre_shared_key_id_setter
pre_shared_key_id_setter(self=self, value=value)
@property
def id(self):
"""The Id of the pre_shared_key, shadows the endpoint_name
:rtype: str
"""
from mbed_cloud.foundation._custom_methods import pre_shared_key_id_getter
return pre_shared_key_id_getter(self=self)
@id.setter
def id(self, value):
"""Set value of `id`
:param value: value to set
:type value: str
"""
from mbed_cloud.foundation._custom_methods import pre_shared_key_id_setter
pre_shared_key_id_setter(self=self, value=value)
def create(self, secret_hex):
"""Upload a PSK to Pelion Device Management.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v2/device-shared-keys>`_.
:param secret_hex: The secret of the PSK in hexadecimal. It is not case sensitive; 4a is
same as 4A, and it is allowed with or without 0x in the beginning. The
minimum length of the secret is 128 bits and maximum 256 bits.
:type secret_hex: str
:rtype: PreSharedKey
"""
# Conditionally setup the message body, fields which have not been set will not be sent to the API.
# This avoids null fields being rejected and allows the default value to be used.
body_params = {}
if self._id.value_set:
body_params["endpoint_name"] = self._id.to_api()
# Method parameters are unconditionally sent even if set to None
body_params["secret_hex"] = fields.StringField(secret_hex).to_api()
return self._client.call_api(
method="post",
path="/v2/device-shared-keys",
content_type="application/json",
body_params=body_params,
unpack=self,
)
def delete(self):
"""Remove a PSK.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v2/device-shared-keys/{endpoint_name}>`_.
:rtype: PreSharedKey
"""
return self._client.call_api(
method="delete",
path="/v2/device-shared-keys/{endpoint_name}",
content_type="application/json",
path_params={"endpoint_name": self._id.to_api()},
unpack=self,
)
def list(self, filter=None, order=None, max_results=None, page_size=None, include=None):
"""List PSKs.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v2/device-shared-keys>`_.
:param filter: Filtering when listing entities is not supported by the API for this
entity.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: The order of the records based on creation time, ASC or DESC. Default
value is ASC
:type order: str
:param max_results: Total maximum number of results to retrieve
:type max_results: int
:param page_size: The number of entries per page.
:type page_size: int
:param include: Comma separated additional data to return.
:type include: str
:return: An iterator object which yields instances of an entity.
:rtype: mbed_cloud.pagination.PaginatedResponse(PreSharedKey)
"""
from mbed_cloud.foundation._custom_methods import paginate
from mbed_cloud.foundation import PreSharedKey
from mbed_cloud import ApiFilter
# Be permissive and accept an instance of a dictionary as this was how the Legacy interface worked.
if isinstance(filter, dict):
filter = ApiFilter(filter_definition=filter, field_renames=PreSharedKey._renames_to_api)
# The preferred method is an ApiFilter instance as this should be easier to use.
elif isinstance(filter, ApiFilter):
# If filter renames have not be defined then configure the ApiFilter so that any renames
# performed by the SDK are reversed when the query parameters are created.
if filter.field_renames is None:
filter.field_renames = PreSharedKey._renames_to_api
elif filter is not None:
raise TypeError("The 'filter' parameter may be either 'dict' or 'ApiFilter'.")
return paginate(
self=self,
foreign_key=PreSharedKey,
filter=filter,
order=order,
max_results=max_results,
page_size=page_size,
include=include,
wraps=self._paginate_list,
)
def _paginate_list(self, after=None, filter=None, order=None, limit=None, include=None):
"""List PSKs.
:param after: An offset token for fetching a specific page. Provided by the server.
:type after: str
:param filter: Optional API filter for listing resources.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Not supported by the API.
:type order: str
:param limit: The number of entries per page.
:type limit: int
:param include: Not supported by the API.
:type include: str
:rtype: mbed_cloud.pagination.PaginatedResponse
"""
# Filter query parameters
query_params = filter.to_api() if filter else {}
# Add in other query parameters
query_params["after"] = fields.StringField(after).to_api()
query_params["order"] = fields.StringField(order).to_api()
query_params["limit"] = fields.IntegerField(limit).to_api()
query_params["include"] = fields.StringField(include).to_api()
return self._client.call_api(
method="get",
path="/v2/device-shared-keys",
content_type="application/json",
query_params=query_params,
unpack=False,
)
def read(self):
"""Get a PSK.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v2/device-shared-keys/{endpoint_name}>`_.
:rtype: PreSharedKey
"""
return self._client.call_api(
method="get",
path="/v2/device-shared-keys/{endpoint_name}",
content_type="application/json",
path_params={"endpoint_name": self._id.to_api()},
unpack=self,
)
|
class PreSharedKey(Entity):
'''Represents the `PreSharedKey` entity in Pelion Device Management'''
def __init__(self, _client=None, created_at=None, endpoint_name=None, id=None):
'''Creates a local `PreSharedKey` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param created_at: The date-time (RFC3339) when this PSK was uploaded to Device
Management.
:type created_at: datetime
:param endpoint_name: The unique endpoint identifier that this PSK applies to. 16-64 [pr
intable](https://en.wikipedia.org/wiki/ASCII#Printable_characters)
(non-control) ASCII characters.
:type endpoint_name: str
:param id: The Id of the pre_shared_key, shadows the endpoint_name
:type id: str
'''
pass
@property
def created_at(self):
'''The date-time (RFC3339) when this PSK was uploaded to Device Management.
api example: '2017-07-21T17:32:28.012Z'
:rtype: datetime
'''
pass
@property
def endpoint_name(self):
'''The unique endpoint identifier that this PSK applies to. 16-64
[printable](https://en.wikipedia.org/wiki/ASCII#Printable_characters) (non-
control) ASCII characters.
api example: 'my-endpoint-0001'
:rtype: str
'''
pass
@endpoint_name.setter
def endpoint_name(self):
'''Set value of `endpoint_name`
:param value: value to set
:type value: str
'''
pass
@property
def id(self):
'''The Id of the pre_shared_key, shadows the endpoint_name
:rtype: str
'''
pass
@id.setter
def id(self):
'''Set value of `id`
:param value: value to set
:type value: str
'''
pass
def created_at(self):
'''Upload a PSK to Pelion Device Management.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v2/device-shared-keys>`_.
:param secret_hex: The secret of the PSK in hexadecimal. It is not case sensitive; 4a is
same as 4A, and it is allowed with or without 0x in the beginning. The
minimum length of the secret is 128 bits and maximum 256 bits.
:type secret_hex: str
:rtype: PreSharedKey
'''
pass
def delete(self):
'''Remove a PSK.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v2/device-shared-keys/{endpoint_name}>`_.
:rtype: PreSharedKey
'''
pass
def list(self, filter=None, order=None, max_results=None, page_size=None, include=None):
'''List PSKs.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v2/device-shared-keys>`_.
:param filter: Filtering when listing entities is not supported by the API for this
entity.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: The order of the records based on creation time, ASC or DESC. Default
value is ASC
:type order: str
:param max_results: Total maximum number of results to retrieve
:type max_results: int
:param page_size: The number of entries per page.
:type page_size: int
:param include: Comma separated additional data to return.
:type include: str
:return: An iterator object which yields instances of an entity.
:rtype: mbed_cloud.pagination.PaginatedResponse(PreSharedKey)
'''
pass
def _paginate_list(self, after=None, filter=None, order=None, limit=None, include=None):
'''List PSKs.
:param after: An offset token for fetching a specific page. Provided by the server.
:type after: str
:param filter: Optional API filter for listing resources.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Not supported by the API.
:type order: str
:param limit: The number of entries per page.
:type limit: int
:param include: Not supported by the API.
:type include: str
:rtype: mbed_cloud.pagination.PaginatedResponse
'''
pass
def read(self):
'''Get a PSK.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v2/device-shared-keys/{endpoint_name}>`_.
:rtype: PreSharedKey
'''
pass
| 17 | 12 | 21 | 5 | 7 | 9 | 2 | 1.09 | 1 | 7 | 4 | 0 | 11 | 3 | 11 | 22 | 256 | 66 | 91 | 33 | 67 | 99 | 51 | 28 | 32 | 5 | 2 | 2 | 17 |
2,284 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/security/server_credentials.py
|
mbed_cloud.foundation.entities.security.server_credentials.ServerCredentials
|
class ServerCredentials(Entity):
"""Represents the `ServerCredentials` entity in Pelion Device Management"""
# List of fields that are serialised between the API and SDK
_api_fieldnames = ["created_at", "id", "server_certificate", "server_uri"]
# List of fields that are available for the user of the SDK
_sdk_fieldnames = _api_fieldnames
# Renames to be performed by the SDK when receiving data {<API Field Name>: <SDK Field Name>}
_renames = {}
# Renames to be performed by the SDK when sending data {<SDK Field Name>: <API Field Name>}
_renames_to_api = {}
def __init__(self, _client=None, created_at=None, id=None, server_certificate=None, server_uri=None):
"""Creates a local `ServerCredentials` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param created_at: Creation UTC time RFC3339.
:type created_at: datetime
:param id: Unique entity ID.
:type id: str
:param server_certificate: PEM-format X.509 server certificate used to validate the server
certificate received during the TLS/DTLS handshake.
:type server_certificate: str
:param server_uri: Server URI that the client connects to.
:type server_uri: str
"""
super().__init__(_client=_client)
# inline imports for avoiding circular references and bulk imports
# fields
self._created_at = fields.DateTimeField(value=created_at)
self._id = fields.StringField(value=id)
self._server_certificate = fields.StringField(value=server_certificate)
self._server_uri = fields.StringField(value=server_uri)
@property
def created_at(self):
"""Creation UTC time RFC3339.
:rtype: datetime
"""
return self._created_at.value
@property
def id(self):
"""Unique entity ID.
:rtype: str
"""
return self._id.value
@property
def server_certificate(self):
"""PEM-format X.509 server certificate used to validate the server certificate
received during the TLS/DTLS handshake.
:rtype: str
"""
return self._server_certificate.value
@property
def server_uri(self):
"""Server URI that the client connects to.
:rtype: str
"""
return self._server_uri.value
def get_bootstrap(self):
"""Fetch bootstrap server credentials.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/server-credentials/bootstrap>`_.
:rtype: ServerCredentials
"""
return self._client.call_api(
method="get", path="/v3/server-credentials/bootstrap", content_type="application/json", unpack=self
)
def get_lwm2m(self):
"""Fetch LwM2M server credentials.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/server-credentials/lwm2m>`_.
:rtype: ServerCredentials
"""
return self._client.call_api(
method="get", path="/v3/server-credentials/lwm2m", content_type="application/json", unpack=self
)
|
class ServerCredentials(Entity):
'''Represents the `ServerCredentials` entity in Pelion Device Management'''
def __init__(self, _client=None, created_at=None, id=None, server_certificate=None, server_uri=None):
'''Creates a local `ServerCredentials` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param created_at: Creation UTC time RFC3339.
:type created_at: datetime
:param id: Unique entity ID.
:type id: str
:param server_certificate: PEM-format X.509 server certificate used to validate the server
certificate received during the TLS/DTLS handshake.
:type server_certificate: str
:param server_uri: Server URI that the client connects to.
:type server_uri: str
'''
pass
@property
def created_at(self):
'''Creation UTC time RFC3339.
:rtype: datetime
'''
pass
@property
def id(self):
'''Unique entity ID.
:rtype: str
'''
pass
@property
def server_certificate(self):
'''PEM-format X.509 server certificate used to validate the server certificate
received during the TLS/DTLS handshake.
:rtype: str
'''
pass
@property
def server_uri(self):
'''Server URI that the client connects to.
:rtype: str
'''
pass
def get_bootstrap(self):
'''Fetch bootstrap server credentials.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/server-credentials/bootstrap>`_.
:rtype: ServerCredentials
'''
pass
def get_lwm2m(self):
'''Fetch LwM2M server credentials.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/server-credentials/lwm2m>`_.
:rtype: ServerCredentials
'''
pass
| 12 | 8 | 12 | 3 | 3 | 6 | 1 | 1.42 | 1 | 3 | 2 | 0 | 7 | 4 | 7 | 18 | 106 | 31 | 31 | 20 | 19 | 44 | 23 | 16 | 15 | 1 | 2 | 0 | 7 |
2,285 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/security/subtenant_trusted_certificate.py
|
mbed_cloud.foundation.entities.security.subtenant_trusted_certificate.SubtenantTrustedCertificate
|
class SubtenantTrustedCertificate(Entity):
"""Represents the `SubtenantTrustedCertificate` entity in Pelion Device Management"""
# List of fields that are serialised between the API and SDK
_api_fieldnames = [
"account_id",
"certificate",
"certificate_fingerprint",
"created_at",
"description",
"device_execution_mode",
"enrollment_mode",
"id",
"is_developer_certificate",
"issuer",
"name",
"owner_id",
"service",
"status",
"subject",
"updated_at",
"valid",
"validity",
]
# List of fields that are available for the user of the SDK
_sdk_fieldnames = _api_fieldnames
# Renames to be performed by the SDK when receiving data {<API Field Name>: <SDK Field Name>}
_renames = {}
# Renames to be performed by the SDK when sending data {<SDK Field Name>: <API Field Name>}
_renames_to_api = {}
def __init__(
self,
_client=None,
account_id=None,
certificate=None,
certificate_fingerprint=None,
created_at=None,
description=None,
device_execution_mode=None,
enrollment_mode=None,
id=None,
is_developer_certificate=None,
issuer=None,
name=None,
owner_id=None,
service=None,
status=None,
subject=None,
updated_at=None,
valid=None,
validity=None,
):
"""Creates a local `SubtenantTrustedCertificate` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param account_id: (Required) The ID of the account.
:type account_id: str
:param certificate: (Required) X509.v3 trusted certificate in PEM format.
:type certificate: str
:param certificate_fingerprint: A SHA-256 fingerprint of the certificate.
:type certificate_fingerprint: str
:param created_at: Creation UTC time RFC3339.
:type created_at: datetime
:param description: Human readable description of this certificate.
:type description: str
:param device_execution_mode: Device execution mode where 1 means a developer certificate.
:type device_execution_mode: int
:param enrollment_mode: If true, signature is not required. Default value false.
:type enrollment_mode: bool
:param id: (Required) Entity ID.
:type id: str
:param is_developer_certificate: Whether or not this certificate is a developer certificate.
:type is_developer_certificate: bool
:param issuer: Issuer of the certificate.
:type issuer: str
:param name: (Required) Certificate name.
:type name: str
:param owner_id: The ID of the owner.
:type owner_id: str
:param service: (Required) Service name where the certificate is used.
:type service: str
:param status: Status of the certificate.
:type status: str
:param subject: Subject of the certificate.
:type subject: str
:param updated_at: Last update UTC time RFC3339.
:type updated_at: datetime
:param valid: This read-only flag indicates whether the certificate is valid or
not.
:type valid: bool
:param validity: Expiration time in UTC formatted as RFC3339.
:type validity: datetime
"""
super().__init__(_client=_client)
# inline imports for avoiding circular references and bulk imports
# fields
self._account_id = fields.StringField(value=account_id)
self._certificate = fields.StringField(value=certificate)
self._certificate_fingerprint = fields.StringField(value=certificate_fingerprint)
self._created_at = fields.DateTimeField(value=created_at)
self._description = fields.StringField(value=description)
self._device_execution_mode = fields.IntegerField(value=device_execution_mode)
self._enrollment_mode = fields.BooleanField(value=enrollment_mode)
self._id = fields.StringField(value=id)
self._is_developer_certificate = fields.BooleanField(value=is_developer_certificate)
self._issuer = fields.StringField(value=issuer)
self._name = fields.StringField(value=name)
self._owner_id = fields.StringField(value=owner_id)
self._service = fields.StringField(value=service, enum=enums.SubtenantTrustedCertificateServiceEnum)
self._status = fields.StringField(value=status, enum=enums.SubtenantTrustedCertificateStatusEnum)
self._subject = fields.StringField(value=subject)
self._updated_at = fields.DateTimeField(value=updated_at)
self._valid = fields.BooleanField(value=valid)
self._validity = fields.DateTimeField(value=validity)
@property
def account_id(self):
"""The ID of the account.
This field must be set when creating a new SubtenantTrustedCertificate Entity.
api example: '01619571e2e90242ac12000600000000'
:rtype: str
"""
return self._account_id.value
@account_id.setter
def account_id(self, value):
"""Set value of `account_id`
:param value: value to set
:type value: str
"""
self._account_id.set(value)
@property
def certificate(self):
"""X509.v3 trusted certificate in PEM format.
This field must be set when creating a new SubtenantTrustedCertificate Entity.
api example: '-----BEGIN CERTIFICATE----- ... -----END CERTIFICATE-----'
:rtype: str
"""
return self._certificate.value
@certificate.setter
def certificate(self, value):
"""Set value of `certificate`
:param value: value to set
:type value: str
"""
self._certificate.set(value)
@property
def certificate_fingerprint(self):
"""A SHA-256 fingerprint of the certificate.
api example: 'a10fb2c8ba90e6de927bd0ae391dcc38f6115685de2d7024712af37ead0608f1'
:rtype: str
"""
return self._certificate_fingerprint.value
@property
def created_at(self):
"""Creation UTC time RFC3339.
api example: '2018-02-13T09:35:20Z'
:rtype: datetime
"""
return self._created_at.value
@property
def description(self):
"""Human readable description of this certificate.
api example: 'Certificate created by me.'
:rtype: str
"""
return self._description.value
@description.setter
def description(self, value):
"""Set value of `description`
:param value: value to set
:type value: str
"""
self._description.set(value)
@property
def device_execution_mode(self):
"""Device execution mode where 1 means a developer certificate.
api example: 1
:rtype: int
"""
return self._device_execution_mode.value
@property
def enrollment_mode(self):
"""If true, signature is not required. Default value false.
:rtype: bool
"""
return self._enrollment_mode.value
@enrollment_mode.setter
def enrollment_mode(self, value):
"""Set value of `enrollment_mode`
:param value: value to set
:type value: bool
"""
self._enrollment_mode.set(value)
@property
def id(self):
"""Entity ID.
This field must be set when updating or deleting an existing SubtenantTrustedCertificate Entity.
api example: '01619571d01d0242ac12000600000000'
:rtype: str
"""
return self._id.value
@id.setter
def id(self, value):
"""Set value of `id`
:param value: value to set
:type value: str
"""
self._id.set(value)
@property
def is_developer_certificate(self):
"""Whether or not this certificate is a developer certificate.
api example: True
:rtype: bool
"""
from mbed_cloud.foundation._custom_methods import is_developer_certificate_getter
return is_developer_certificate_getter(self=self)
@property
def issuer(self):
"""Issuer of the certificate.
api example: 'CN=issuer'
:rtype: str
"""
return self._issuer.value
@property
def name(self):
"""Certificate name.
This field must be set when creating a new SubtenantTrustedCertificate Entity.
api example: 'My certificate'
:rtype: str
"""
return self._name.value
@name.setter
def name(self, value):
"""Set value of `name`
:param value: value to set
:type value: str
"""
self._name.set(value)
@property
def owner_id(self):
"""The ID of the owner.
api example: '01619571dad80242ac12000600000000'
:rtype: str
"""
return self._owner_id.value
@property
def service(self):
"""Service name where the certificate is used.
This field must be set when creating a new SubtenantTrustedCertificate Entity.
:rtype: str
"""
return self._service.value
@service.setter
def service(self, value):
"""Set value of `service`
:param value: value to set
:type value: str
"""
self._service.set(value)
@property
def status(self):
"""Status of the certificate.
api example: 'ACTIVE'
:rtype: str
"""
return self._status.value
@status.setter
def status(self, value):
"""Set value of `status`
:param value: value to set
:type value: str
"""
self._status.set(value)
@property
def subject(self):
"""Subject of the certificate.
api example: 'CN=subject'
:rtype: str
"""
return self._subject.value
@property
def updated_at(self):
"""Last update UTC time RFC3339.
api example: '2018-02-14T15:24:14Z'
:rtype: datetime
"""
return self._updated_at.value
@property
def valid(self):
"""This read-only flag indicates whether the certificate is valid or not.
api example: True
:rtype: bool
"""
return self._valid.value
@property
def validity(self):
"""Expiration time in UTC formatted as RFC3339.
api example: '2038-02-14T15:24:14Z'
:rtype: datetime
"""
return self._validity.value
def create(self):
"""Upload new trusted certificate.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/trusted-certificates>`_.
:rtype: SubtenantTrustedCertificate
"""
# Conditionally setup the message body, fields which have not been set will not be sent to the API.
# This avoids null fields being rejected and allows the default value to be used.
body_params = {}
if self._certificate.value_set:
body_params["certificate"] = self._certificate.to_api()
if self._description.value_set:
body_params["description"] = self._description.to_api()
if self._enrollment_mode.value_set:
body_params["enrollment_mode"] = self._enrollment_mode.to_api()
if self._name.value_set:
body_params["name"] = self._name.to_api()
if self._service.value_set:
body_params["service"] = self._service.to_api()
if self._status.value_set:
body_params["status"] = self._status.to_api()
return self._client.call_api(
method="post",
path="/v3/accounts/{account_id}/trusted-certificates",
content_type="application/json",
path_params={"account_id": self._account_id.to_api()},
body_params=body_params,
unpack=self,
)
def delete(self):
"""Delete trusted certificate by ID.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/trusted-certificates/{cert_id}>`_.
:rtype: SubtenantTrustedCertificate
"""
return self._client.call_api(
method="delete",
path="/v3/accounts/{account_id}/trusted-certificates/{cert_id}",
content_type="application/json",
path_params={"account_id": self._account_id.to_api(), "cert_id": self._id.to_api()},
unpack=self,
)
def get_developer_certificate_info(self):
"""Fetch an existing developer certificate to connect to the bootstrap server.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/developer-certificates/{developerCertificateId}>`_.
:rtype: DeveloperCertificate
"""
from mbed_cloud.foundation import DeveloperCertificate
return self._client.call_api(
method="get",
path="/v3/developer-certificates/{developerCertificateId}",
content_type="application/json",
path_params={"developerCertificateId": self._id.to_api()},
unpack=DeveloperCertificate,
)
def read(self):
"""Get trusted certificate by ID.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/trusted-certificates/{cert_id}>`_.
:rtype: SubtenantTrustedCertificate
"""
return self._client.call_api(
method="get",
path="/v3/accounts/{account_id}/trusted-certificates/{cert_id}",
content_type="application/json",
path_params={"account_id": self._account_id.to_api(), "cert_id": self._id.to_api()},
unpack=self,
)
def update(self):
"""Update trusted certificate.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/trusted-certificates/{cert_id}>`_.
:rtype: SubtenantTrustedCertificate
"""
# Conditionally setup the message body, fields which have not been set will not be sent to the API.
# This avoids null fields being rejected and allows the default value to be used.
body_params = {}
if self._certificate.value_set:
body_params["certificate"] = self._certificate.to_api()
if self._description.value_set:
body_params["description"] = self._description.to_api()
if self._enrollment_mode.value_set:
body_params["enrollment_mode"] = self._enrollment_mode.to_api()
if self._name.value_set:
body_params["name"] = self._name.to_api()
if self._service.value_set:
body_params["service"] = self._service.to_api()
if self._status.value_set:
body_params["status"] = self._status.to_api()
return self._client.call_api(
method="put",
path="/v3/accounts/{account_id}/trusted-certificates/{cert_id}",
content_type="application/json",
path_params={"account_id": self._account_id.to_api(), "cert_id": self._id.to_api()},
body_params=body_params,
unpack=self,
)
|
class SubtenantTrustedCertificate(Entity):
'''Represents the `SubtenantTrustedCertificate` entity in Pelion Device Management'''
def __init__(
self,
_client=None,
account_id=None,
certificate=None,
certificate_fingerprint=None,
created_at=None,
description=None,
device_execution_mode=None,
enrollment_mode=None,
id=None,
is_developer_certificate=None,
issuer=None,
name=None,
owner_id=None,
service=None,
status=None,
subject=None,
updated_at=None,
valid=None,
validity=None,
):
'''Creates a local `SubtenantTrustedCertificate` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param account_id: (Required) The ID of the account.
:type account_id: str
:param certificate: (Required) X509.v3 trusted certificate in PEM format.
:type certificate: str
:param certificate_fingerprint: A SHA-256 fingerprint of the certificate.
:type certificate_fingerprint: str
:param created_at: Creation UTC time RFC3339.
:type created_at: datetime
:param description: Human readable description of this certificate.
:type description: str
:param device_execution_mode: Device execution mode where 1 means a developer certificate.
:type device_execution_mode: int
:param enrollment_mode: If true, signature is not required. Default value false.
:type enrollment_mode: bool
:param id: (Required) Entity ID.
:type id: str
:param is_developer_certificate: Whether or not this certificate is a developer certificate.
:type is_developer_certificate: bool
:param issuer: Issuer of the certificate.
:type issuer: str
:param name: (Required) Certificate name.
:type name: str
:param owner_id: The ID of the owner.
:type owner_id: str
:param service: (Required) Service name where the certificate is used.
:type service: str
:param status: Status of the certificate.
:type status: str
:param subject: Subject of the certificate.
:type subject: str
:param updated_at: Last update UTC time RFC3339.
:type updated_at: datetime
:param valid: This read-only flag indicates whether the certificate is valid or
not.
:type valid: bool
:param validity: Expiration time in UTC formatted as RFC3339.
:type validity: datetime
'''
pass
@property
def account_id(self):
'''The ID of the account.
This field must be set when creating a new SubtenantTrustedCertificate Entity.
api example: '01619571e2e90242ac12000600000000'
:rtype: str
'''
pass
@account_id.setter
def account_id(self):
'''Set value of `account_id`
:param value: value to set
:type value: str
'''
pass
@property
def certificate(self):
'''X509.v3 trusted certificate in PEM format.
This field must be set when creating a new SubtenantTrustedCertificate Entity.
api example: '-----BEGIN CERTIFICATE----- ... -----END CERTIFICATE-----'
:rtype: str
'''
pass
@certificate.setter
def certificate(self):
'''Set value of `certificate`
:param value: value to set
:type value: str
'''
pass
@property
def certificate_fingerprint(self):
'''A SHA-256 fingerprint of the certificate.
api example: 'a10fb2c8ba90e6de927bd0ae391dcc38f6115685de2d7024712af37ead0608f1'
:rtype: str
'''
pass
@property
def created_at(self):
'''Creation UTC time RFC3339.
api example: '2018-02-13T09:35:20Z'
:rtype: datetime
'''
pass
@property
def description(self):
'''Human readable description of this certificate.
api example: 'Certificate created by me.'
:rtype: str
'''
pass
@description.setter
def description(self):
'''Set value of `description`
:param value: value to set
:type value: str
'''
pass
@property
def device_execution_mode(self):
'''Device execution mode where 1 means a developer certificate.
api example: 1
:rtype: int
'''
pass
@property
def enrollment_mode(self):
'''If true, signature is not required. Default value false.
:rtype: bool
'''
pass
@enrollment_mode.setter
def enrollment_mode(self):
'''Set value of `enrollment_mode`
:param value: value to set
:type value: bool
'''
pass
@property
def id(self):
'''Entity ID.
This field must be set when updating or deleting an existing SubtenantTrustedCertificate Entity.
api example: '01619571d01d0242ac12000600000000'
:rtype: str
'''
pass
@id.setter
def id(self):
'''Set value of `id`
:param value: value to set
:type value: str
'''
pass
@property
def is_developer_certificate(self):
'''Whether or not this certificate is a developer certificate.
api example: True
:rtype: bool
'''
pass
@property
def issuer(self):
'''Issuer of the certificate.
api example: 'CN=issuer'
:rtype: str
'''
pass
@property
def name(self):
'''Certificate name.
This field must be set when creating a new SubtenantTrustedCertificate Entity.
api example: 'My certificate'
:rtype: str
'''
pass
@name.setter
def name(self):
'''Set value of `name`
:param value: value to set
:type value: str
'''
pass
@property
def owner_id(self):
'''The ID of the owner.
api example: '01619571dad80242ac12000600000000'
:rtype: str
'''
pass
@property
def service(self):
'''Service name where the certificate is used.
This field must be set when creating a new SubtenantTrustedCertificate Entity.
:rtype: str
'''
pass
@service.setter
def service(self):
'''Set value of `service`
:param value: value to set
:type value: str
'''
pass
@property
def status(self):
'''Status of the certificate.
api example: 'ACTIVE'
:rtype: str
'''
pass
@status.setter
def status(self):
'''Set value of `status`
:param value: value to set
:type value: str
'''
pass
@property
def subject(self):
'''Subject of the certificate.
api example: 'CN=subject'
:rtype: str
'''
pass
@property
def updated_at(self):
'''Last update UTC time RFC3339.
api example: '2018-02-14T15:24:14Z'
:rtype: datetime
'''
pass
@property
def valid(self):
'''This read-only flag indicates whether the certificate is valid or not.
api example: True
:rtype: bool
'''
pass
@property
def validity(self):
'''Expiration time in UTC formatted as RFC3339.
api example: '2038-02-14T15:24:14Z'
:rtype: datetime
'''
pass
def created_at(self):
'''Upload new trusted certificate.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/trusted-certificates>`_.
:rtype: SubtenantTrustedCertificate
'''
pass
def delete(self):
'''Delete trusted certificate by ID.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/trusted-certificates/{cert_id}>`_.
:rtype: SubtenantTrustedCertificate
'''
pass
def get_developer_certificate_info(self):
'''Fetch an existing developer certificate to connect to the bootstrap server.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/developer-certificates/{developerCertificateId}>`_.
:rtype: DeveloperCertificate
'''
pass
def read(self):
'''Get trusted certificate by ID.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/trusted-certificates/{cert_id}>`_.
:rtype: SubtenantTrustedCertificate
'''
pass
def updated_at(self):
'''Update trusted certificate.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/accounts/{account_id}/trusted-certificates/{cert_id}>`_.
:rtype: SubtenantTrustedCertificate
'''
pass
| 59 | 33 | 14 | 3 | 5 | 6 | 1 | 0.85 | 1 | 8 | 7 | 0 | 32 | 18 | 32 | 43 | 529 | 134 | 213 | 106 | 131 | 182 | 115 | 59 | 80 | 7 | 2 | 1 | 44 |
2,286 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/security/enums.py
|
mbed_cloud.foundation.entities.security.enums.CertificateEnrollmentEnrollStatusEnum
|
class CertificateEnrollmentEnrollStatusEnum(BaseEnum):
"""Represents expected values of `CertificateEnrollmentEnrollStatusEnum`
This is used by Entities in the "security" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
"""
COMPLETED = "completed"
NEW = "new"
values = frozenset(("completed", "new"))
|
class CertificateEnrollmentEnrollStatusEnum(BaseEnum):
'''Represents expected values of `CertificateEnrollmentEnrollStatusEnum`
This is used by Entities in the "security" category.
.. note::
If new values are added to the enum in the API they will be passed through unchanged by the SDK,
but will not be on this list. If this occurs please update the SDK to the most recent version.
'''
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1.5 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 14 | 4 | 4 | 4 | 3 | 6 | 4 | 4 | 3 | 0 | 2 | 0 | 0 |
2,287 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/security/trusted_certificate.py
|
mbed_cloud.foundation.entities.security.trusted_certificate.TrustedCertificate
|
class TrustedCertificate(Entity):
"""Represents the `TrustedCertificate` entity in Pelion Device Management"""
# List of fields that are serialised between the API and SDK
_api_fieldnames = [
"account_id",
"certificate",
"certificate_fingerprint",
"created_at",
"description",
"device_execution_mode",
"enrollment_mode",
"id",
"is_developer_certificate",
"issuer",
"name",
"owner_id",
"service",
"status",
"subject",
"updated_at",
"valid",
"validity",
]
# List of fields that are available for the user of the SDK
_sdk_fieldnames = _api_fieldnames
# Renames to be performed by the SDK when receiving data {<API Field Name>: <SDK Field Name>}
_renames = {}
# Renames to be performed by the SDK when sending data {<SDK Field Name>: <API Field Name>}
_renames_to_api = {}
def __init__(
self,
_client=None,
account_id=None,
certificate=None,
certificate_fingerprint=None,
created_at=None,
description=None,
device_execution_mode=None,
enrollment_mode=None,
id=None,
is_developer_certificate=None,
issuer=None,
name=None,
owner_id=None,
service=None,
status=None,
subject=None,
updated_at=None,
valid=None,
validity=None,
):
"""Creates a local `TrustedCertificate` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param account_id: The ID of the account.
:type account_id: str
:param certificate: (Required) X509.v3 trusted certificate in PEM format.
:type certificate: str
:param certificate_fingerprint: A SHA-256 fingerprint of the certificate.
:type certificate_fingerprint: str
:param created_at: Creation UTC time RFC3339.
:type created_at: datetime
:param description: Human readable description of this certificate.
:type description: str
:param device_execution_mode: Device execution mode where 1 means a developer certificate.
:type device_execution_mode: int
:param enrollment_mode: If true, signature is not required. Default value false.
:type enrollment_mode: bool
:param id: (Required) Entity ID.
:type id: str
:param is_developer_certificate: Whether or not this certificate is a developer certificate.
:type is_developer_certificate: bool
:param issuer: Issuer of the certificate.
:type issuer: str
:param name: (Required) Certificate name.
:type name: str
:param owner_id: The ID of the owner.
:type owner_id: str
:param service: (Required) Service name where the certificate is used.
:type service: str
:param status: Status of the certificate.
:type status: str
:param subject: Subject of the certificate.
:type subject: str
:param updated_at: Last update UTC time RFC3339.
:type updated_at: datetime
:param valid: This read-only flag indicates whether the certificate is valid or
not.
:type valid: bool
:param validity: Expiration time in UTC formatted as RFC3339.
:type validity: datetime
"""
super().__init__(_client=_client)
# inline imports for avoiding circular references and bulk imports
# fields
self._account_id = fields.StringField(value=account_id)
self._certificate = fields.StringField(value=certificate)
self._certificate_fingerprint = fields.StringField(value=certificate_fingerprint)
self._created_at = fields.DateTimeField(value=created_at)
self._description = fields.StringField(value=description)
self._device_execution_mode = fields.IntegerField(value=device_execution_mode)
self._enrollment_mode = fields.BooleanField(value=enrollment_mode)
self._id = fields.StringField(value=id)
self._is_developer_certificate = fields.BooleanField(value=is_developer_certificate)
self._issuer = fields.StringField(value=issuer)
self._name = fields.StringField(value=name)
self._owner_id = fields.StringField(value=owner_id)
self._service = fields.StringField(value=service, enum=enums.TrustedCertificateServiceEnum)
self._status = fields.StringField(value=status, enum=enums.TrustedCertificateStatusEnum)
self._subject = fields.StringField(value=subject)
self._updated_at = fields.DateTimeField(value=updated_at)
self._valid = fields.BooleanField(value=valid)
self._validity = fields.DateTimeField(value=validity)
@property
def account_id(self):
"""The ID of the account.
api example: '01619571e2e90242ac12000600000000'
:rtype: str
"""
return self._account_id.value
@property
def certificate(self):
"""X509.v3 trusted certificate in PEM format.
This field must be set when creating a new TrustedCertificate Entity.
api example: '-----BEGIN CERTIFICATE----- ... -----END CERTIFICATE-----'
:rtype: str
"""
return self._certificate.value
@certificate.setter
def certificate(self, value):
"""Set value of `certificate`
:param value: value to set
:type value: str
"""
self._certificate.set(value)
@property
def certificate_fingerprint(self):
"""A SHA-256 fingerprint of the certificate.
api example: 'a10fb2c8ba90e6de927bd0ae391dcc38f6115685de2d7024712af37ead0608f1'
:rtype: str
"""
return self._certificate_fingerprint.value
@property
def created_at(self):
"""Creation UTC time RFC3339.
api example: '2018-02-13T09:35:20Z'
:rtype: datetime
"""
return self._created_at.value
@property
def description(self):
"""Human readable description of this certificate.
api example: 'Certificate created by me.'
:rtype: str
"""
return self._description.value
@description.setter
def description(self, value):
"""Set value of `description`
:param value: value to set
:type value: str
"""
self._description.set(value)
@property
def device_execution_mode(self):
"""Device execution mode where 1 means a developer certificate.
api example: 1
:rtype: int
"""
return self._device_execution_mode.value
@property
def enrollment_mode(self):
"""If true, signature is not required. Default value false.
:rtype: bool
"""
return self._enrollment_mode.value
@enrollment_mode.setter
def enrollment_mode(self, value):
"""Set value of `enrollment_mode`
:param value: value to set
:type value: bool
"""
self._enrollment_mode.set(value)
@property
def id(self):
"""Entity ID.
This field must be set when updating or deleting an existing TrustedCertificate Entity.
api example: '01619571d01d0242ac12000600000000'
:rtype: str
"""
return self._id.value
@id.setter
def id(self, value):
"""Set value of `id`
:param value: value to set
:type value: str
"""
self._id.set(value)
@property
def is_developer_certificate(self):
"""Whether or not this certificate is a developer certificate.
api example: True
:rtype: bool
"""
from mbed_cloud.foundation._custom_methods import is_developer_certificate_getter
return is_developer_certificate_getter(self=self)
@property
def issuer(self):
"""Issuer of the certificate.
api example: 'CN=issuer'
:rtype: str
"""
return self._issuer.value
@property
def name(self):
"""Certificate name.
This field must be set when creating a new TrustedCertificate Entity.
api example: 'My certificate'
:rtype: str
"""
return self._name.value
@name.setter
def name(self, value):
"""Set value of `name`
:param value: value to set
:type value: str
"""
self._name.set(value)
@property
def owner_id(self):
"""The ID of the owner.
api example: '01619571dad80242ac12000600000000'
:rtype: str
"""
return self._owner_id.value
@property
def service(self):
"""Service name where the certificate is used.
This field must be set when creating a new TrustedCertificate Entity.
:rtype: str
"""
return self._service.value
@service.setter
def service(self, value):
"""Set value of `service`
:param value: value to set
:type value: str
"""
self._service.set(value)
@property
def status(self):
"""Status of the certificate.
api example: 'ACTIVE'
:rtype: str
"""
return self._status.value
@status.setter
def status(self, value):
"""Set value of `status`
:param value: value to set
:type value: str
"""
self._status.set(value)
@property
def subject(self):
"""Subject of the certificate.
api example: 'CN=subject'
:rtype: str
"""
return self._subject.value
@property
def updated_at(self):
"""Last update UTC time RFC3339.
api example: '2018-02-14T15:24:14Z'
:rtype: datetime
"""
return self._updated_at.value
@property
def valid(self):
"""This read-only flag indicates whether the certificate is valid or not.
api example: True
:rtype: bool
"""
return self._valid.value
@property
def validity(self):
"""Expiration time in UTC formatted as RFC3339.
api example: '2038-02-14T15:24:14Z'
:rtype: datetime
"""
return self._validity.value
def create(self):
"""Upload a new trusted certificate.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/trusted-certificates>`_.
:rtype: TrustedCertificate
"""
# Conditionally setup the message body, fields which have not been set will not be sent to the API.
# This avoids null fields being rejected and allows the default value to be used.
body_params = {}
if self._certificate.value_set:
body_params["certificate"] = self._certificate.to_api()
if self._description.value_set:
body_params["description"] = self._description.to_api()
if self._enrollment_mode.value_set:
body_params["enrollment_mode"] = self._enrollment_mode.to_api()
if self._name.value_set:
body_params["name"] = self._name.to_api()
if self._service.value_set:
body_params["service"] = self._service.to_api()
if self._status.value_set:
body_params["status"] = self._status.to_api()
return self._client.call_api(
method="post",
path="/v3/trusted-certificates",
content_type="application/json",
body_params=body_params,
unpack=self,
)
def delete(self):
"""Delete a trusted certificate by ID.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/trusted-certificates/{cert_id}>`_.
:rtype: TrustedCertificate
"""
return self._client.call_api(
method="delete",
path="/v3/trusted-certificates/{cert_id}",
content_type="application/json",
path_params={"cert_id": self._id.to_api()},
unpack=self,
)
def get_developer_certificate_info(self):
"""Fetch an existing developer certificate to connect to the bootstrap server.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/developer-certificates/{developerCertificateId}>`_.
:rtype: DeveloperCertificate
"""
from mbed_cloud.foundation import DeveloperCertificate
return self._client.call_api(
method="get",
path="/v3/developer-certificates/{developerCertificateId}",
content_type="application/json",
path_params={"developerCertificateId": self._id.to_api()},
unpack=DeveloperCertificate,
)
def list(self, filter=None, order="ASC", max_results=None, page_size=50, include=None):
"""Get all trusted certificates.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/trusted-certificates>`_.
**API Filters**
The following filters are supported by the API when listing TrustedCertificate entities:
+-----------------------+------+------+------+------+------+------+------+
| Field | eq | neq | gte | lte | in | nin | like |
+=======================+======+======+======+======+======+======+======+
| device_execution_mode | Y | Y | | | | | |
+-----------------------+------+------+------+------+------+------+------+
| enrollment_mode | Y | | | | | | |
+-----------------------+------+------+------+------+------+------+------+
| expire | Y | | | | | | |
+-----------------------+------+------+------+------+------+------+------+
| issuer | | | | | | | Y |
+-----------------------+------+------+------+------+------+------+------+
| name | Y | | | | | | |
+-----------------------+------+------+------+------+------+------+------+
| owner | Y | | | | | | |
+-----------------------+------+------+------+------+------+------+------+
| service | Y | | | | | | |
+-----------------------+------+------+------+------+------+------+------+
| status | Y | | | | | | |
+-----------------------+------+------+------+------+------+------+------+
| subject | | | | | | | Y |
+-----------------------+------+------+------+------+------+------+------+
| valid | Y | | | | | | |
+-----------------------+------+------+------+------+------+------+------+
**Example Usage**
.. code-block:: python
from mbed_cloud.foundation import TrustedCertificate
from mbed_cloud import ApiFilter
api_filter = ApiFilter()
api_filter.add_filter("device_execution_mode", "eq", <filter value>)
for trusted_certificate in TrustedCertificate().list(filter=api_filter):
print(trusted_certificate.device_execution_mode)
:param filter: An optional filter to apply when listing entities, please see the
above **API Filters** table for supported filters.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order based on creation time. Acceptable values: ASC, DESC.
Default: ASC.
:type order: str
:param max_results: Total maximum number of results to retrieve
:type max_results: int
:param page_size: The number of results to return (2-1000). Default 50.
:type page_size: int
:param include: Comma-separated additional data to return. Currently supported:
total_count.
:type include: str
:return: An iterator object which yields instances of an entity.
:rtype: mbed_cloud.pagination.PaginatedResponse(TrustedCertificate)
"""
from mbed_cloud.foundation._custom_methods import paginate
from mbed_cloud.foundation import TrustedCertificate
from mbed_cloud import ApiFilter
# Be permissive and accept an instance of a dictionary as this was how the Legacy interface worked.
if isinstance(filter, dict):
filter = ApiFilter(filter_definition=filter, field_renames=TrustedCertificate._renames_to_api)
# The preferred method is an ApiFilter instance as this should be easier to use.
elif isinstance(filter, ApiFilter):
# If filter renames have not be defined then configure the ApiFilter so that any renames
# performed by the SDK are reversed when the query parameters are created.
if filter.field_renames is None:
filter.field_renames = TrustedCertificate._renames_to_api
elif filter is not None:
raise TypeError("The 'filter' parameter may be either 'dict' or 'ApiFilter'.")
return paginate(
self=self,
foreign_key=TrustedCertificate,
filter=filter,
order=order,
max_results=max_results,
page_size=page_size,
include=include,
wraps=self._paginate_list,
)
def _paginate_list(self, after=None, filter=None, order="ASC", limit=50, include=None):
"""Get all trusted certificates.
:param after: The entity ID to fetch after the given one.
:type after: str
:param filter: Optional API filter for listing resources.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order based on creation time. Acceptable values: ASC, DESC.
Default: ASC.
:type order: str
:param limit: The number of results to return (2-1000). Default 50.
:type limit: int
:param include: Comma-separated additional data to return. Currently supported:
total_count.
:type include: str
:rtype: mbed_cloud.pagination.PaginatedResponse
"""
# Filter query parameters
query_params = filter.to_api() if filter else {}
# Add in other query parameters
query_params["after"] = fields.StringField(after).to_api()
query_params["order"] = fields.StringField(order, enum=enums.TrustedCertificateOrderEnum).to_api()
query_params["limit"] = fields.IntegerField(limit).to_api()
query_params["include"] = fields.StringField(include).to_api()
return self._client.call_api(
method="get",
path="/v3/trusted-certificates",
content_type="application/json",
query_params=query_params,
unpack=False,
)
def read(self):
"""Get trusted certificate by ID.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/trusted-certificates/{cert_id}>`_.
:rtype: TrustedCertificate
"""
return self._client.call_api(
method="get",
path="/v3/trusted-certificates/{cert_id}",
content_type="application/json",
path_params={"cert_id": self._id.to_api()},
unpack=self,
)
def update(self):
"""Update trusted certificate.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/trusted-certificates/{cert_id}>`_.
:rtype: TrustedCertificate
"""
# Conditionally setup the message body, fields which have not been set will not be sent to the API.
# This avoids null fields being rejected and allows the default value to be used.
body_params = {}
if self._certificate.value_set:
body_params["certificate"] = self._certificate.to_api()
if self._description.value_set:
body_params["description"] = self._description.to_api()
if self._enrollment_mode.value_set:
body_params["enrollment_mode"] = self._enrollment_mode.to_api()
if self._name.value_set:
body_params["name"] = self._name.to_api()
if self._service.value_set:
body_params["service"] = self._service.to_api()
if self._status.value_set:
body_params["status"] = self._status.to_api()
return self._client.call_api(
method="put",
path="/v3/trusted-certificates/{cert_id}",
content_type="application/json",
body_params=body_params,
path_params={"cert_id": self._id.to_api()},
unpack=self,
)
|
class TrustedCertificate(Entity):
'''Represents the `TrustedCertificate` entity in Pelion Device Management'''
def __init__(
self,
_client=None,
account_id=None,
certificate=None,
certificate_fingerprint=None,
created_at=None,
description=None,
device_execution_mode=None,
enrollment_mode=None,
id=None,
is_developer_certificate=None,
issuer=None,
name=None,
owner_id=None,
service=None,
status=None,
subject=None,
updated_at=None,
valid=None,
validity=None,
):
'''Creates a local `TrustedCertificate` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param account_id: The ID of the account.
:type account_id: str
:param certificate: (Required) X509.v3 trusted certificate in PEM format.
:type certificate: str
:param certificate_fingerprint: A SHA-256 fingerprint of the certificate.
:type certificate_fingerprint: str
:param created_at: Creation UTC time RFC3339.
:type created_at: datetime
:param description: Human readable description of this certificate.
:type description: str
:param device_execution_mode: Device execution mode where 1 means a developer certificate.
:type device_execution_mode: int
:param enrollment_mode: If true, signature is not required. Default value false.
:type enrollment_mode: bool
:param id: (Required) Entity ID.
:type id: str
:param is_developer_certificate: Whether or not this certificate is a developer certificate.
:type is_developer_certificate: bool
:param issuer: Issuer of the certificate.
:type issuer: str
:param name: (Required) Certificate name.
:type name: str
:param owner_id: The ID of the owner.
:type owner_id: str
:param service: (Required) Service name where the certificate is used.
:type service: str
:param status: Status of the certificate.
:type status: str
:param subject: Subject of the certificate.
:type subject: str
:param updated_at: Last update UTC time RFC3339.
:type updated_at: datetime
:param valid: This read-only flag indicates whether the certificate is valid or
not.
:type valid: bool
:param validity: Expiration time in UTC formatted as RFC3339.
:type validity: datetime
'''
pass
@property
def account_id(self):
'''The ID of the account.
api example: '01619571e2e90242ac12000600000000'
:rtype: str
'''
pass
@property
def certificate(self):
'''X509.v3 trusted certificate in PEM format.
This field must be set when creating a new TrustedCertificate Entity.
api example: '-----BEGIN CERTIFICATE----- ... -----END CERTIFICATE-----'
:rtype: str
'''
pass
@certificate.setter
def certificate(self):
'''Set value of `certificate`
:param value: value to set
:type value: str
'''
pass
@property
def certificate_fingerprint(self):
'''A SHA-256 fingerprint of the certificate.
api example: 'a10fb2c8ba90e6de927bd0ae391dcc38f6115685de2d7024712af37ead0608f1'
:rtype: str
'''
pass
@property
def created_at(self):
'''Creation UTC time RFC3339.
api example: '2018-02-13T09:35:20Z'
:rtype: datetime
'''
pass
@property
def description(self):
'''Human readable description of this certificate.
api example: 'Certificate created by me.'
:rtype: str
'''
pass
@description.setter
def description(self):
'''Set value of `description`
:param value: value to set
:type value: str
'''
pass
@property
def device_execution_mode(self):
'''Device execution mode where 1 means a developer certificate.
api example: 1
:rtype: int
'''
pass
@property
def enrollment_mode(self):
'''If true, signature is not required. Default value false.
:rtype: bool
'''
pass
@enrollment_mode.setter
def enrollment_mode(self):
'''Set value of `enrollment_mode`
:param value: value to set
:type value: bool
'''
pass
@property
def id(self):
'''Entity ID.
This field must be set when updating or deleting an existing TrustedCertificate Entity.
api example: '01619571d01d0242ac12000600000000'
:rtype: str
'''
pass
@id.setter
def id(self):
'''Set value of `id`
:param value: value to set
:type value: str
'''
pass
@property
def is_developer_certificate(self):
'''Whether or not this certificate is a developer certificate.
api example: True
:rtype: bool
'''
pass
@property
def issuer(self):
'''Issuer of the certificate.
api example: 'CN=issuer'
:rtype: str
'''
pass
@property
def name(self):
'''Certificate name.
This field must be set when creating a new TrustedCertificate Entity.
api example: 'My certificate'
:rtype: str
'''
pass
@name.setter
def name(self):
'''Set value of `name`
:param value: value to set
:type value: str
'''
pass
@property
def owner_id(self):
'''The ID of the owner.
api example: '01619571dad80242ac12000600000000'
:rtype: str
'''
pass
@property
def service(self):
'''Service name where the certificate is used.
This field must be set when creating a new TrustedCertificate Entity.
:rtype: str
'''
pass
@service.setter
def service(self):
'''Set value of `service`
:param value: value to set
:type value: str
'''
pass
@property
def status(self):
'''Status of the certificate.
api example: 'ACTIVE'
:rtype: str
'''
pass
@status.setter
def status(self):
'''Set value of `status`
:param value: value to set
:type value: str
'''
pass
@property
def subject(self):
'''Subject of the certificate.
api example: 'CN=subject'
:rtype: str
'''
pass
@property
def updated_at(self):
'''Last update UTC time RFC3339.
api example: '2018-02-14T15:24:14Z'
:rtype: datetime
'''
pass
@property
def valid(self):
'''This read-only flag indicates whether the certificate is valid or not.
api example: True
:rtype: bool
'''
pass
@property
def validity(self):
'''Expiration time in UTC formatted as RFC3339.
api example: '2038-02-14T15:24:14Z'
:rtype: datetime
'''
pass
def created_at(self):
'''Upload a new trusted certificate.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/trusted-certificates>`_.
:rtype: TrustedCertificate
'''
pass
def delete(self):
'''Delete a trusted certificate by ID.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/trusted-certificates/{cert_id}>`_.
:rtype: TrustedCertificate
'''
pass
def get_developer_certificate_info(self):
'''Fetch an existing developer certificate to connect to the bootstrap server.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/developer-certificates/{developerCertificateId}>`_.
:rtype: DeveloperCertificate
'''
pass
def list(self, filter=None, order="ASC", max_results=None, page_size=50, include=None):
'''Get all trusted certificates.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/trusted-certificates>`_.
**API Filters**
The following filters are supported by the API when listing TrustedCertificate entities:
+-----------------------+------+------+------+------+------+------+------+
| Field | eq | neq | gte | lte | in | nin | like |
+=======================+======+======+======+======+======+======+======+
| device_execution_mode | Y | Y | | | | | |
+-----------------------+------+------+------+------+------+------+------+
| enrollment_mode | Y | | | | | | |
+-----------------------+------+------+------+------+------+------+------+
| expire | Y | | | | | | |
+-----------------------+------+------+------+------+------+------+------+
| issuer | | | | | | | Y |
+-----------------------+------+------+------+------+------+------+------+
| name | Y | | | | | | |
+-----------------------+------+------+------+------+------+------+------+
| owner | Y | | | | | | |
+-----------------------+------+------+------+------+------+------+------+
| service | Y | | | | | | |
+-----------------------+------+------+------+------+------+------+------+
| status | Y | | | | | | |
+-----------------------+------+------+------+------+------+------+------+
| subject | | | | | | | Y |
+-----------------------+------+------+------+------+------+------+------+
| valid | Y | | | | | | |
+-----------------------+------+------+------+------+------+------+------+
**Example Usage**
.. code-block:: python
from mbed_cloud.foundation import TrustedCertificate
from mbed_cloud import ApiFilter
api_filter = ApiFilter()
api_filter.add_filter("device_execution_mode", "eq", <filter value>)
for trusted_certificate in TrustedCertificate().list(filter=api_filter):
print(trusted_certificate.device_execution_mode)
:param filter: An optional filter to apply when listing entities, please see the
above **API Filters** table for supported filters.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order based on creation time. Acceptable values: ASC, DESC.
Default: ASC.
:type order: str
:param max_results: Total maximum number of results to retrieve
:type max_results: int
:param page_size: The number of results to return (2-1000). Default 50.
:type page_size: int
:param include: Comma-separated additional data to return. Currently supported:
total_count.
:type include: str
:return: An iterator object which yields instances of an entity.
:rtype: mbed_cloud.pagination.PaginatedResponse(TrustedCertificate)
'''
pass
def _paginate_list(self, after=None, filter=None, order="ASC", limit=50, include=None):
'''Get all trusted certificates.
:param after: The entity ID to fetch after the given one.
:type after: str
:param filter: Optional API filter for listing resources.
:type filter: mbed_cloud.client.api_filter.ApiFilter
:param order: Record order based on creation time. Acceptable values: ASC, DESC.
Default: ASC.
:type order: str
:param limit: The number of results to return (2-1000). Default 50.
:type limit: int
:param include: Comma-separated additional data to return. Currently supported:
total_count.
:type include: str
:rtype: mbed_cloud.pagination.PaginatedResponse
'''
pass
def read(self):
'''Get trusted certificate by ID.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/trusted-certificates/{cert_id}>`_.
:rtype: TrustedCertificate
'''
pass
def updated_at(self):
'''Update trusted certificate.
`REST API Documentation <https://os.mbed.com/search/?q=Service+API+References+/v3/trusted-certificates/{cert_id}>`_.
:rtype: TrustedCertificate
'''
pass
| 59 | 34 | 17 | 4 | 6 | 7 | 2 | 1.02 | 1 | 12 | 9 | 0 | 33 | 18 | 33 | 44 | 649 | 157 | 243 | 110 | 158 | 249 | 130 | 64 | 91 | 7 | 2 | 2 | 50 |
2,288 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/pagination.py
|
mbed_cloud.pagination.PaginatedResponse
|
class PaginatedResponse(object):
"""Represents a sequence of results from the API
To represent the potentially large number of results
returned from an API query, the PaginatedResponse provides
a lazily-evaluated generator which can be used to step through
the full result set, fetching new pages of results as needed.
Usage:
- response = PaginatedResponse(api_function)
- response.first() {} first item
- response.all() [{}, ...] all items
- list(response) [{}, ...] all items from generator
- [item for item in response] [{}, ...] iteration over generator
"""
def __init__(
self,
func,
lwrap_type=None,
_results_cache=True,
page_size=None,
max_results=None,
**kwargs
):
"""Initialize wrapper by passing in object with metadata structure.
:param func: API function called to obtain a page of results
:param lwrap_type: Wrapper class called for each returned result object
:param _results_cache: Retains a copy of all returned results to reduce API calls
Set to None to disable (for use as a pure generator,
and to reduce memory usage)
:param page_size: Number of results to request per page
:param max_results: Total maximum number of results to retrieve
"""
self._api_func = func
self._lwrap_type = lwrap_type
self._kwargs = {}
self._kwargs.update(kwargs)
# Initial values, will be updated in first response
self._total_count = None
self._next_id = None
self._has_more = True
self._is_exhausted = False
self._results_cache = [] if _results_cache else None
self._current_data_page = []
self._current_count = 0
# 'limit' parameter is deprecated, but used to approximate both values:
self._max_results = max_results if max_results is not None else kwargs.get('limit')
self._page_size = kwargs.get('limit') or page_size
def _api_func_wrapper(self, *args, **kwargs):
"""Wrapper around API function to handle erroneous 404s from the API.
:param args: Positional arguments for the API function.
:param kwargs: Key word arguments for the API function.
:return: The result of calling the API function.
"""
try:
return self._api_func(*args, **kwargs)
except ApiErrorResponse as api_error:
# Suppress 404s for listing as they are sometimes returned by the API rather than an empty list
if api_error.status_code == 404:
# Fake an empty response for a list method
return {"total_count": 0, "data": []}
else:
# Re-raise the exception if not a 404
raise
@property
def _is_caching(self):
return self._results_cache is not None
@property
def _is_at_query_limit(self):
# we track query limit ourselves in case the API is too lenient
return self._max_results is not None and self._current_count >= self._max_results
def _get_total_concrete(self):
# total number of results seen for certain, ignoring 'total_count' responses
return self._current_count + len(self._current_data_page)
def _response_dictionary(self, response):
# shim to handle converting response to a dictionary
# e.g. from a model, dict or requests.response
if isinstance(response, dict):
pass
elif hasattr(response, 'to_dict'):
response = response.to_dict()
elif hasattr(response, 'json'):
response = response.json()
else:
response = vars(response)
return response
def _get_next_page(self):
query = {}
query.update(self._kwargs)
if self._next_id is not None:
query['after'] = self._next_id
if self._page_size is not None:
query['limit'] = self._page_size
raw_function_response = self._api_func_wrapper(**query)
resp = self._response_dictionary(raw_function_response)
for item in resp.get('data') or []:
# some hoop jumping for compatibility with Foundation API
if hasattr(raw_function_response, 'to_dict'):
item = ToDictWrapper(item)
# 'lwrap' presumably meant 'list wrap' or something
# we wrap each item with this function call before storing it in the results list
self._current_data_page.append(self._lwrap_type(item) if self._lwrap_type else item)
self._has_more = resp.get('has_more')
self._total_count = resp.get('total_count')
if self._has_more and self._current_data_page:
# we need to find the marker for the next page
# 'continuation_marker' is used by connector_bootstrap
# everything else uses id of last item
self._next_id = (
resp.get('continuation_marker') or self._current_data_page[-1].id
)
def _get_total_count(self):
from mbed_cloud.bootstrap.bootstrap import PreSharedKey
if self._lwrap_type == PreSharedKey:
return 0
len_query = {}
len_query['include'] = 'total_count'
len_query.update(self._kwargs)
len_query['limit'] = 2
resp = self._response_dictionary(self._api_func_wrapper(**len_query))
return resp.get('total_count', 0)
def count(self):
"""Approximate number of results, according to the API"""
if self._total_count is None:
self._total_count = self._get_total_count()
return self._total_count
def all(self):
"""All results"""
all = list(self)
if self._results_cache:
return iter(self._results_cache)
return all
def first(self):
"""Returns the first item from the query, or None if there are no results"""
if self._results_cache:
return self._results_cache[0]
query = PaginatedResponse(func=self._api_func, lwrap_type=self._lwrap_type, **self._kwargs)
try:
return next(query)
except StopIteration:
return None
def next(self):
"""Next item in sequence (Python 2 compatibility)"""
return self.__next__()
def __next__(self):
"""Get the next element"""
if not self._current_data_page and self._has_more:
self._get_next_page()
if not self._current_data_page or self._is_at_query_limit:
self._is_exhausted = True
raise StopIteration()
self._current_count += 1
result = self._current_data_page.pop(0)
if self._is_caching:
self._results_cache.append(result)
return result
def __iter__(self):
"""This instance can be iterated"""
if not self._is_exhausted:
return self
if self._is_caching:
return iter(self._results_cache)
raise StopIteration()
def __len__(self):
"""Most accurate known number of results"""
return self._get_total_concrete() if self._is_exhausted else self.count()
def __repr__(self):
"""First few elements of a query result"""
limit = 3
some = list(islice(self.all(), limit + 1))
return '<%s %s%s>' % (
self.__class__.__name__,
','.join(str(s) for s in some[:limit]),
'...' if len(some) > limit else ''
)
def to_dict(self):
"""Internal state"""
return dict(
after=self._kwargs.get('after'),
data=list(self),
has_more=self._has_more,
limit=self._max_results,
order=self._kwargs.get('order', 'ASC'),
page_size=self._page_size,
total_count=self.count(),
)
@property
def data(self):
"""Deprecated. Returns the data as a `list`"""
import warnings
warnings.warn(
'`data` attribute is deprecated and will be removed in a future release, '
'use %s as an iterable instead' % (PaginatedResponse,),
category=DeprecationWarning,
stacklevel=2 # log wherever '.data' is referenced, rather than this line
)
return list(self)
|
class PaginatedResponse(object):
'''Represents a sequence of results from the API
To represent the potentially large number of results
returned from an API query, the PaginatedResponse provides
a lazily-evaluated generator which can be used to step through
the full result set, fetching new pages of results as needed.
Usage:
- response = PaginatedResponse(api_function)
- response.first() {} first item
- response.all() [{}, ...] all items
- list(response) [{}, ...] all items from generator
- [item for item in response] [{}, ...] iteration over generator
'''
def __init__(
self,
func,
lwrap_type=None,
_results_cache=True,
page_size=None,
max_results=None,
**kwargs
):
'''Initialize wrapper by passing in object with metadata structure.
:param func: API function called to obtain a page of results
:param lwrap_type: Wrapper class called for each returned result object
:param _results_cache: Retains a copy of all returned results to reduce API calls
Set to None to disable (for use as a pure generator,
and to reduce memory usage)
:param page_size: Number of results to request per page
:param max_results: Total maximum number of results to retrieve
'''
pass
def _api_func_wrapper(self, *args, **kwargs):
'''Wrapper around API function to handle erroneous 404s from the API.
:param args: Positional arguments for the API function.
:param kwargs: Key word arguments for the API function.
:return: The result of calling the API function.
'''
pass
@property
def _is_caching(self):
pass
@property
def _is_at_query_limit(self):
pass
def _get_total_concrete(self):
pass
def _response_dictionary(self, response):
pass
def _get_next_page(self):
pass
def _get_total_count(self):
pass
def count(self):
'''Approximate number of results, according to the API'''
pass
def all(self):
'''All results'''
pass
def first(self):
'''Returns the first item from the query, or None if there are no results'''
pass
def next(self):
'''Next item in sequence (Python 2 compatibility)'''
pass
def __next__(self):
'''Get the next element'''
pass
def __iter__(self):
'''This instance can be iterated'''
pass
def __len__(self):
'''Most accurate known number of results'''
pass
def __repr__(self):
'''First few elements of a query result'''
pass
def to_dict(self):
'''Internal state'''
pass
@property
def data(self):
'''Deprecated. Returns the data as a `list`'''
pass
| 22 | 13 | 11 | 1 | 8 | 2 | 2 | 0.36 | 1 | 9 | 3 | 0 | 18 | 12 | 18 | 18 | 230 | 35 | 144 | 55 | 112 | 52 | 110 | 43 | 89 | 7 | 1 | 2 | 43 |
2,289 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/pagination.py
|
mbed_cloud.pagination.ToDictWrapper
|
class ToDictWrapper(object):
"""A wrapper to proxy any dictionary to have it look like an SDK object"""
def __init__(self, data):
"""Just holds data as a dictionary"""
self.data = data
def to_dict(self):
"""Return data as dictionary"""
return self.data
|
class ToDictWrapper(object):
'''A wrapper to proxy any dictionary to have it look like an SDK object'''
def __init__(self, data):
'''Just holds data as a dictionary'''
pass
def to_dict(self):
'''Return data as dictionary'''
pass
| 3 | 3 | 3 | 0 | 2 | 1 | 1 | 0.6 | 1 | 0 | 0 | 0 | 2 | 1 | 2 | 2 | 10 | 2 | 5 | 4 | 2 | 3 | 5 | 4 | 2 | 1 | 1 | 0 | 2 |
2,290 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/sdk/config.py
|
mbed_cloud.sdk.config.Config
|
class Config(object):
"""Configuration object for SDK"""
_tried_dotenv = False
api_key = None
host = None
_user_agent = None
def __init__(self, api_key=None, host=None):
"""Create a new configuration instance.
If configuration is not supplied then the default configuration from a `.env` file or environment variables will
be used.
:param api_key: (optional) API Key to use for Authentication, if provided this will override all other
configuration
:type api_key: str
:param host: (optional) Host of the Pelion Device Management API, if provided this will override all other
configuration
:type host: str
"""
self._logger = LOGGER.getChild(self.__class__.__name__)
config_dict = {}
if api_key:
config_dict["api_key"] = api_key
if host:
config_dict["host"] = host
self._update(**config_dict)
if not self.api_key and not Config._tried_dotenv:
# mark dotenv load complete, so we don't have to do it again
dotenv.load_dotenv(
dotenv.find_dotenv(usecwd=True, raise_error_if_not_found=False)
)
Config._tried_dotenv = True
self._set_defaults()
def _set_defaults(self):
"""Configures any default parameters"""
self.api_key = (
self.api_key
or os.getenv(constants.ENVVAR_API_KEY)
or constants.DEFAULT_API_KEY
)
self.host = (
self.host or os.getenv(constants.ENVVAR_HOST) or constants.DEFAULT_HOST
)
self._user_agent = utils.get_user_agent()
@property
def user_agent(self):
"""The user-agent used in HTTP requests."""
return self._user_agent
@property
def logger(self):
"""Instance of the logger."""
return self._logger
@logger.setter
def logger(self, value):
"""Set the logger instance"""
self._logger = value
def _update(self, *updates, **kwargs):
"""Update the current configuration with that provided in the arguments."""
for update in updates:
self.update(**update)
for k, v in kwargs.items():
setattr(self, k, v)
def _to_dict(self):
"""Return the current configuration as a dictionary."""
return {k: v for k, v in vars(self).items() if not k.startswith("_")}
|
class Config(object):
'''Configuration object for SDK'''
def __init__(self, api_key=None, host=None):
'''Create a new configuration instance.
If configuration is not supplied then the default configuration from a `.env` file or environment variables will
be used.
:param api_key: (optional) API Key to use for Authentication, if provided this will override all other
configuration
:type api_key: str
:param host: (optional) Host of the Pelion Device Management API, if provided this will override all other
configuration
:type host: str
'''
pass
def _set_defaults(self):
'''Configures any default parameters'''
pass
@property
def user_agent(self):
'''The user-agent used in HTTP requests.'''
pass
@property
def logger(self):
'''Instance of the logger.'''
pass
@logger.setter
def logger(self):
'''Set the logger instance'''
pass
def _update(self, *updates, **kwargs):
'''Update the current configuration with that provided in the arguments.'''
pass
def _to_dict(self):
'''Return the current configuration as a dictionary.'''
pass
| 11 | 8 | 8 | 1 | 5 | 2 | 2 | 0.4 | 1 | 0 | 0 | 0 | 7 | 1 | 7 | 7 | 75 | 12 | 45 | 19 | 34 | 18 | 34 | 16 | 26 | 4 | 1 | 1 | 12 |
2,291 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/sdk/exceptions.py
|
mbed_cloud.sdk.exceptions.ApiErrorResponse
|
class ApiErrorResponse(IOError):
"""Container for errors received when communicating with the cloud service"""
raw = None
status_code = None
all_parameters = None
|
class ApiErrorResponse(IOError):
'''Container for errors received when communicating with the cloud service'''
pass
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0.25 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 6 | 1 | 4 | 4 | 3 | 1 | 4 | 4 | 3 | 0 | 1 | 0 | 0 |
2,292 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/sdk/sdk.py
|
mbed_cloud.sdk.sdk.SDK
|
class SDK(object):
"""SDK Interface for interacting with Primary, Foundation and Client interfaces."""
def __init__(self, config=None, api_key=None, host=None):
"""Create a new SDK instance
If configuration is not supplied then the default configuration from a `.env` file or environment variables will
be used. For more information please see :mod:`mbed_cloud.sdk.config`.
:param config: (optional) An SDK configuration object, this will override settings in environment variables or
`.env` files.
:type config: mbed_cloud.sdk.config.Config
:param api_key: (optional) API Key to use for Authentication, if provided this will override all other
configuration
:type api_key: str
:param host: (optional) Host of the Pelion Device Management API, if provided this will override all other
configuration
:type host: str
"""
check_openssl_version()
# create a new config based on those we received
existing = config._to_dict() if config else {}
if api_key:
existing["api_key"] = api_key
if host:
existing["host"] = host
self._config = Config(**existing)
# create a new client for making http calls
self._client = Client(self._config)
self._entities = EntityFactory(self.client)
@property
def client(self):
"""Client Interface, which can be use for direct communication with the Pelion Device Management API
:return: Client Interface.
:rtype: mbed_cloud.client.client.Client
"""
return self._client
@property
def config(self):
"""Configuration in use by SDK instance.
:return: Configuration object.
:rtype: mbed_cloud.sdk.config.Config
"""
return self._config
@property
def foundation(self):
"""Foundation Interface Entities
This provides access to all Entities in the Foundation Interface via the returned factory class.
:return: Foundation Interface entity factory.
:rtype: mbed_cloud.foundation.entities.entity_factory.EntityFactory
"""
return self._entities
|
class SDK(object):
'''SDK Interface for interacting with Primary, Foundation and Client interfaces.'''
def __init__(self, config=None, api_key=None, host=None):
'''Create a new SDK instance
If configuration is not supplied then the default configuration from a `.env` file or environment variables will
be used. For more information please see :mod:`mbed_cloud.sdk.config`.
:param config: (optional) An SDK configuration object, this will override settings in environment variables or
`.env` files.
:type config: mbed_cloud.sdk.config.Config
:param api_key: (optional) API Key to use for Authentication, if provided this will override all other
configuration
:type api_key: str
:param host: (optional) Host of the Pelion Device Management API, if provided this will override all other
configuration
:type host: str
'''
pass
@property
def client(self):
'''Client Interface, which can be use for direct communication with the Pelion Device Management API
:return: Client Interface.
:rtype: mbed_cloud.client.client.Client
'''
pass
@property
def config(self):
'''Configuration in use by SDK instance.
:return: Configuration object.
:rtype: mbed_cloud.sdk.config.Config
'''
pass
@property
def foundation(self):
'''Foundation Interface Entities
This provides access to all Entities in the Foundation Interface via the returned factory class.
:return: Foundation Interface entity factory.
:rtype: mbed_cloud.foundation.entities.entity_factory.EntityFactory
'''
pass
| 8 | 5 | 13 | 2 | 4 | 7 | 2 | 1.45 | 1 | 2 | 2 | 0 | 4 | 3 | 4 | 4 | 62 | 13 | 20 | 12 | 12 | 29 | 17 | 9 | 12 | 4 | 1 | 1 | 7 |
2,293 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/subscribe/async_wrapper.py
|
mbed_cloud.subscribe.async_wrapper.AsyncWrapper
|
class AsyncWrapper(object):
"""Wraps a potentially asynchronous function to provide a consistent API"""
def __init__(self, func=None, concurrency_provider=None):
"""Creates a wrapper for a potentially asynchronous function.
:param func: blocking call, asyncio coroutine or future
:param concurrency_provider: ThreadPool or asyncio BaseEventLoop
or None: default ThreadPool
or False: default EventLoop
"""
self._func = func
self._concurrency_provider = (
concurrency_provider or
(
asyncio.get_event_loop() if six.PY3 and concurrency_provider is False
else ThreadPool(processes=1)
)
)
self._is_asyncio_provider = (
six.PY3 and not isinstance(self._concurrency_provider, ThreadPool)
)
self._is_awaitable = (
self._is_asyncio_provider and
(
isinstance(self._func, asyncio.Future) or
asyncio.iscoroutinefunction(self._func) or
asyncio.iscoroutine(self._func)
)
)
self._deferable = None
self._blocked = None
self._lock = threading.RLock()
def defer(self, *args, **kwargs):
"""Call the function and immediately return an asynchronous object.
The calling code will need to check for the result at a later time using:
In Python 2/3 using ThreadPools - an AsyncResult
(https://docs.python.org/2/library/multiprocessing.html#multiprocessing.pool.AsyncResult)
In Python 3 using Asyncio - a Future
(https://docs.python.org/3/library/asyncio-task.html#future)
:param args:
:param kwargs:
:return:
"""
LOG.debug(
'%s on %s (awaitable %s async %s provider %s)',
'deferring',
self._func,
self._is_awaitable,
self._is_asyncio_provider,
self._concurrency_provider
)
if self._blocked:
raise RuntimeError('Already activated this deferred call by blocking on it')
with self._lock:
if not self._deferable:
func_partial = functools.partial(self._func, *args, **kwargs)
# we are either:
# - pure asyncio
# - asyncio but with blocking function
# - not asyncio, use threadpool
self._deferable = (
# pure asyncio
asyncio.ensure_future(func_partial(), loop=self._concurrency_provider)
if self._is_awaitable else (
# asyncio blocked
self._concurrency_provider.run_in_executor(
func=func_partial,
executor=None
)
if self._is_asyncio_provider else (
# not asyncio
self._concurrency_provider.apply_async(func_partial)
)
)
)
return self._deferable
def block(self, *args, **kwargs):
"""Call the wrapped function, and wait for the result in a blocking fashion
Returns the result of the function call.
:param args:
:param kwargs:
:return: result of function call
"""
LOG.debug(
'%s on %s (awaitable %s async %s provider %s)',
'blocking',
self._func,
self._is_awaitable,
self._is_asyncio_provider,
self._concurrency_provider
)
if self._deferable:
raise RuntimeError('Already activated this call by deferring it')
with self._lock:
if not hasattr(self, '_result'):
try:
self._result = (
self._concurrency_provider.run_until_complete(self.defer(*args, **kwargs))
if self._is_asyncio_provider else self._func(*args, **kwargs)
)
except queue.Empty:
raise CloudTimeoutError("No data received after %.1f seconds." % kwargs.get("timeout", 0))
self._blocked = True
return self._result
|
class AsyncWrapper(object):
'''Wraps a potentially asynchronous function to provide a consistent API'''
def __init__(self, func=None, concurrency_provider=None):
'''Creates a wrapper for a potentially asynchronous function.
:param func: blocking call, asyncio coroutine or future
:param concurrency_provider: ThreadPool or asyncio BaseEventLoop
or None: default ThreadPool
or False: default EventLoop
'''
pass
def defer(self, *args, **kwargs):
'''Call the function and immediately return an asynchronous object.
The calling code will need to check for the result at a later time using:
In Python 2/3 using ThreadPools - an AsyncResult
(https://docs.python.org/2/library/multiprocessing.html#multiprocessing.pool.AsyncResult)
In Python 3 using Asyncio - a Future
(https://docs.python.org/3/library/asyncio-task.html#future)
:param args:
:param kwargs:
:return:
'''
pass
def block(self, *args, **kwargs):
'''Call the wrapped function, and wait for the result in a blocking fashion
Returns the result of the function call.
:param args:
:param kwargs:
:return: result of function call
'''
pass
| 4 | 4 | 37 | 4 | 24 | 10 | 4 | 0.41 | 1 | 4 | 1 | 0 | 3 | 8 | 3 | 3 | 117 | 14 | 73 | 13 | 69 | 30 | 30 | 13 | 26 | 5 | 1 | 3 | 12 |
2,294 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/subscribe/channels/channel.py
|
mbed_cloud.subscribe.channels.channel.ChannelIdentifiers
|
class ChannelIdentifiers(object):
"""API channels
Internal Pelion Device Management channel identifiers
"""
notifications = 'notifications'
async_responses = 'async_responses'
registrations = 'registrations'
de_registrations = 'de_registrations'
reg_updates = 'reg_updates'
registrations_expired = 'registrations_expired'
|
class ChannelIdentifiers(object):
'''API channels
Internal Pelion Device Management channel identifiers
'''
pass
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0.43 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 12 | 2 | 7 | 7 | 6 | 3 | 7 | 7 | 6 | 0 | 1 | 0 | 0 |
2,295 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/subscribe/channels/channel.py
|
mbed_cloud.subscribe.channels.channel.ChannelSubscription
|
class ChannelSubscription(object):
"""Represents a subscription to a channel
In pub/sub terms, this is one channel of notifications.
In Pelion Device Management terms, this may be a Presubscription or a Subscription.
There could be multiple references to a single Pelion Device Management channel (e.g. `notifications`),
with multiple receiving channels applying different filters, on the server or client-side.
"""
def __init__(self, *args, **kwargs):
"""New Channel Subscription Instance"""
self._active = False
self._api = None # type: mbed_cloud.connect.ConnectAPI
self._filter_func = None
self._filters = []
self._manager = None # type: mbed_cloud.subscribe.SubscriptionsManager
self._observer = None
self._observer_class = Observer
self._observer_params = None
self._optional_filters = None
self._route_keys = None
self.add_filter_function(self._filter_optional_keys)
self.name = None
super(ChannelSubscription, self).__init__()
def get_routing_keys(self):
"""Primary, mandatory routing keys (list of hashables)"""
return self._route_keys
def add_filter_function(self, func):
"""Adds a function for local notification filtering"""
self._filters.append(func)
return self
@property
def active(self):
"""Channel currently active"""
return self._active
@property
def observer(self):
"""The Observer instance for this channel
Each channel has one observer, which is notified whenever new
data is received by the channel. Observers can then notify
multiple listeners/futures in downstream code.
"""
return self._observer
def _filter_optional_keys(self, data):
"""Filtering for this channel, based on key-value matching"""
for filter_key, filter_value in (self._optional_filters or {}).items():
data_value = data.get(filter_key)
LOG.debug(
'optional keys filter %s: %s (%s)',
filter_key, filter_value, data_value
)
if data_value is None or data_value != filter_value:
LOG.debug(
'optional keys filter rejecting %s: %s (%s)',
filter_key, filter_value, data_value
)
return False
return True
def _notify(self, data):
self.observer.notify(data)
def notify(self, data):
"""Notify this channel of inbound data"""
for filter_function in self._filters:
if not filter_function(data):
return False
self._notify(data)
return True
def __enter__(self):
"""Enter"""
return self.ensure_started()
def __exit__(self, exc_type, exc_value, traceback):
"""Exit"""
return self.ensure_stopped()
def __repr__(self):
"""String representation"""
return '<%s %s>' % (self.__class__.__name__, self.name or self._route_keys)
def start(self):
"""Base method for starting the channel"""
pass
def stop(self):
"""Base method for stopping the channel"""
pass
def _configure(self, manager, connect_api_instance, observer_params):
"""Configure behind-the-scenes settings for the channel
These are required in addition to the parameters provided
on instantiation
"""
self._manager = manager
self._api = connect_api_instance
self._observer_params = self._observer_params or {}
self._observer_params.update(observer_params)
def ensure_started(self):
"""Idempotent channel start"""
if self.active:
return self
self._observer = self._observer_class(**self._observer_params)
self.start()
self._active = True
return self
def ensure_stopped(self):
"""Idempotent channel stop"""
if not self.active:
return self
self.stop()
self.observer.cancel()
self._manager.remove_routes(self, self.get_routing_keys())
self._active = False
return self
|
class ChannelSubscription(object):
'''Represents a subscription to a channel
In pub/sub terms, this is one channel of notifications.
In Pelion Device Management terms, this may be a Presubscription or a Subscription.
There could be multiple references to a single Pelion Device Management channel (e.g. `notifications`),
with multiple receiving channels applying different filters, on the server or client-side.
'''
def __init__(self, *args, **kwargs):
'''New Channel Subscription Instance'''
pass
def get_routing_keys(self):
'''Primary, mandatory routing keys (list of hashables)'''
pass
def add_filter_function(self, func):
'''Adds a function for local notification filtering'''
pass
@property
def active(self):
'''Channel currently active'''
pass
@property
def observer(self):
'''The Observer instance for this channel
Each channel has one observer, which is notified whenever new
data is received by the channel. Observers can then notify
multiple listeners/futures in downstream code.
'''
pass
def _filter_optional_keys(self, data):
'''Filtering for this channel, based on key-value matching'''
pass
def _notify(self, data):
pass
def notify(self, data):
'''Notify this channel of inbound data'''
pass
def __enter__(self):
'''Enter'''
pass
def __exit__(self, exc_type, exc_value, traceback):
'''Exit'''
pass
def __repr__(self):
'''String representation'''
pass
def start(self):
'''Base method for starting the channel'''
pass
def stop(self):
'''Base method for stopping the channel'''
pass
def _configure(self, manager, connect_api_instance, observer_params):
'''Configure behind-the-scenes settings for the channel
These are required in addition to the parameters provided
on instantiation
'''
pass
def ensure_started(self):
'''Idempotent channel start'''
pass
def ensure_stopped(self):
'''Idempotent channel stop'''
pass
| 19 | 16 | 6 | 0 | 5 | 2 | 1 | 0.38 | 1 | 2 | 1 | 3 | 16 | 11 | 16 | 16 | 126 | 20 | 78 | 33 | 59 | 30 | 70 | 31 | 53 | 3 | 1 | 2 | 22 |
2,296 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/subscribe/channels/channel.py
|
mbed_cloud.subscribe.channels.channel.FirstValue
|
class FirstValue(object):
"""Container for 'first value' modes
'First value' refers to how soon after requesting a subscription
the first resource value is fetched.
There is a tradeoff in terms of performance/api calls/device power usage
"""
# waits for a device to send re-register message. one api call. long wait.
on_registration = 'on_registration'
# sets up subscriptions on existing live resources. many api calls. medium wait.
on_value_update = 'on_value_update'
|
class FirstValue(object):
'''Container for 'first value' modes
'First value' refers to how soon after requesting a subscription
the first resource value is fetched.
There is a tradeoff in terms of performance/api calls/device power usage
'''
pass
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 2.33 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 14 | 4 | 3 | 3 | 2 | 7 | 3 | 3 | 2 | 0 | 1 | 0 | 0 |
2,297 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/subscribe/channels/current_resource_value.py
|
mbed_cloud.subscribe.channels.current_resource_value.CurrentResourceValue
|
class CurrentResourceValue(ChannelSubscription):
"""Triggers on response to a request for a current resource value"""
def __init__(self, device_id, resource_path, **extra_filters):
"""Triggers on response to a request for a current resource value
.. warning:: This functionality is considered experimental;
the interface may change in future releases
:param device_id: a device identifier
:param resource_path: a resource path
:param extra_filters:
"""
super(CurrentResourceValue, self).__init__()
self.device_id = device_id
self.resource_path = resource_path
# each request is unique
self.async_id = utils.new_async_id()
LOG.debug('new async id: %s', self.async_id)
self._route_keys = expand_dict_as_keys(dict(
id=self.async_id,
channel=ChannelIdentifiers.async_responses,
))
self._optional_filters = {}
self._optional_filters.update(extra_filters)
self._optional_filter_keys = expand_dict_as_keys(self._optional_filters)
def start(self):
"""Start the channel"""
# observers for this channel only need to wait for one value
self._observer_params.update(dict(once=True))
super(CurrentResourceValue, self).start()
self._api.ensure_notifications_thread()
self._api._mds_rpc_post(
device_id=self.device_id,
method='GET',
uri=self.resource_path,
async_id=self.async_id,
_wrap_with_consumer=False,
)
def _notify(self, data):
"""Notify this channel of inbound data"""
payload = tlv.decode(
payload=data.get('payload'),
content_type=data.get('ct'),
decode_b64=True
)
super(CurrentResourceValue, self)._notify(payload)
# after one response, close the channel
self.ensure_stopped()
|
class CurrentResourceValue(ChannelSubscription):
'''Triggers on response to a request for a current resource value'''
def __init__(self, device_id, resource_path, **extra_filters):
'''Triggers on response to a request for a current resource value
.. warning:: This functionality is considered experimental;
the interface may change in future releases
:param device_id: a device identifier
:param resource_path: a resource path
:param extra_filters:
'''
pass
def start(self):
'''Start the channel'''
pass
def _notify(self, data):
'''Notify this channel of inbound data'''
pass
| 4 | 4 | 16 | 1 | 11 | 4 | 1 | 0.39 | 1 | 3 | 1 | 0 | 3 | 6 | 3 | 19 | 53 | 7 | 33 | 11 | 29 | 13 | 20 | 11 | 16 | 1 | 2 | 0 | 3 |
2,298 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/subscribe/channels/device_state_changes.py
|
mbed_cloud.subscribe.channels.device_state_changes.DeviceStateChanges
|
class DeviceStateChanges(ChannelSubscription):
"""Triggers on changes to registration state of devices"""
def __init__(self, device_id=None, **extra_filters):
"""Triggers on changes to registration state of devices
.. warning:: This functionality is considered experimental;
the interface may change in future releases
:param device_id: a device identifier
:param extra_filters: additional filters e.g. dict(channel=API_CHANNELS.registrations)
"""
super(DeviceStateChanges, self).__init__()
self._route_keys = expand_dict_as_keys(dict(
channel=[
ChannelIdentifiers.de_registrations,
ChannelIdentifiers.reg_updates,
ChannelIdentifiers.registrations_expired,
ChannelIdentifiers.registrations,
],
))
self._optional_filters = {}
if device_id is not None:
self._optional_filters['device_id'] = device_id
self._optional_filters.update(extra_filters)
@staticmethod
def _map_resource_data(resource_data):
attribute_map = {
"path": "path",
"rt": "type",
"ct": "content_type",
"obs": "observable"
}
new_items = map(
lambda item: (item[1], resource_data.get(item[0], None)),
attribute_map.items()
)
return dict(new_items)
@staticmethod
def _map_endpoint_data(endpoint_data):
attribute_map = {
"ep": "device_id",
"original_ep": "alias",
"ept": "device_type",
"q": "queue_mode",
"channel": "channel"
}
output = dict(map(
lambda item: (item[1], endpoint_data.get(item[0], None)),
attribute_map.items()
))
output["resources"] = list(map(
DeviceStateChanges._map_resource_data, endpoint_data.get("resources", [])
))
return output
def start(self):
"""Start the channel"""
super(DeviceStateChanges, self).start()
# n.b. No true start/stop implementation as DeviceState is permanently subscribed
self._api.ensure_notifications_thread()
def notify(self, data):
"""Notify this channel of inbound data"""
string_channels = {
ChannelIdentifiers.de_registrations,
ChannelIdentifiers.registrations_expired
}
if data['channel'] in string_channels:
message = {'device_id': data["value"], 'channel': data["channel"]}
else:
message = DeviceStateChanges._map_endpoint_data(data)
return super(DeviceStateChanges, self).notify(message)
|
class DeviceStateChanges(ChannelSubscription):
'''Triggers on changes to registration state of devices'''
def __init__(self, device_id=None, **extra_filters):
'''Triggers on changes to registration state of devices
.. warning:: This functionality is considered experimental;
the interface may change in future releases
:param device_id: a device identifier
:param extra_filters: additional filters e.g. dict(channel=API_CHANNELS.registrations)
'''
pass
@staticmethod
def _map_resource_data(resource_data):
pass
@staticmethod
def _map_endpoint_data(endpoint_data):
pass
def start(self):
'''Start the channel'''
pass
def notify(self, data):
'''Notify this channel of inbound data'''
pass
| 8 | 4 | 15 | 2 | 11 | 2 | 1 | 0.17 | 1 | 5 | 1 | 0 | 3 | 2 | 5 | 21 | 82 | 14 | 58 | 16 | 50 | 10 | 26 | 14 | 20 | 2 | 2 | 1 | 7 |
2,299 |
ARMmbed/mbed-cloud-sdk-python
|
ARMmbed_mbed-cloud-sdk-python/src/mbed_cloud/foundation/entities/security/verification_response.py
|
mbed_cloud.foundation.entities.security.verification_response.VerificationResponse
|
class VerificationResponse(Entity):
"""Represents the `VerificationResponse` entity in Pelion Device Management"""
# List of fields that are serialised between the API and SDK
_api_fieldnames = ["message", "successful"]
# List of fields that are available for the user of the SDK
_sdk_fieldnames = _api_fieldnames
# Renames to be performed by the SDK when receiving data {<API Field Name>: <SDK Field Name>}
_renames = {}
# Renames to be performed by the SDK when sending data {<SDK Field Name>: <API Field Name>}
_renames_to_api = {}
def __init__(self, _client=None, message=None, successful=None):
"""Creates a local `VerificationResponse` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param message: Provides details in case of failure.
:type message: str
:param successful: Indicates whether the certificate issuer was verified
successfully.
:type successful: bool
"""
super().__init__(_client=_client)
# inline imports for avoiding circular references and bulk imports
# fields
self._message = fields.StringField(value=message)
self._successful = fields.BooleanField(value=successful)
@property
def message(self):
"""Provides details in case of failure.
api example: 'message describing the verification failure'
:rtype: str
"""
return self._message.value
@property
def successful(self):
"""Indicates whether the certificate issuer was verified successfully.
:rtype: bool
"""
return self._successful.value
|
class VerificationResponse(Entity):
'''Represents the `VerificationResponse` entity in Pelion Device Management'''
def __init__(self, _client=None, message=None, successful=None):
'''Creates a local `VerificationResponse` instance
Parameters can be supplied on creation of the instance or given by
setting the properties on the instance after creation.
Parameters marked as `required` must be set for one or more operations
on the entity. For details on when they are required please see the
documentation for the setter method.
:param message: Provides details in case of failure.
:type message: str
:param successful: Indicates whether the certificate issuer was verified
successfully.
:type successful: bool
'''
pass
@property
def message(self):
'''Provides details in case of failure.
api example: 'message describing the verification failure'
:rtype: str
'''
pass
@property
def successful(self):
'''Indicates whether the certificate issuer was verified successfully.
:rtype: bool
'''
pass
| 6 | 4 | 13 | 4 | 3 | 7 | 1 | 1.73 | 1 | 3 | 2 | 0 | 3 | 2 | 3 | 14 | 59 | 18 | 15 | 12 | 9 | 26 | 13 | 10 | 9 | 1 | 2 | 0 | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.