Skip to content

Commit 6728716

Browse files
author
Zoltan Varga
committed
Add authentication method to device structure
1 parent 34e63e4 commit 6728716

File tree

8 files changed

+40
-7
lines changed

8 files changed

+40
-7
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .iothub_client import *
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .iothub_client import *
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .iothub_service_client import *
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .iothub_service_client import *

c

Submodule c updated 93 files

service/samples/iothub_registrymanager_sample.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ def printDeviceInfo(title, iothubDevice):
2727
print("iothubDevice.statusReason = {0}".format(iothubDevice.statusReason))
2828
print("iothubDevice.statusUpdatedTime = {0}".format(iothubDevice.statusUpdatedTime))
2929
print("iothubDevice.lastActivityTime = {0}".format(iothubDevice.lastActivityTime))
30+
print("iothubDevice.cloudToDeviceMessageCount = {0}".format(iothubDevice.cloudToDeviceMessageCount))
31+
print("iothubDevice.isManaged = {0}".format(iothubDevice.isManaged))
32+
print("iothubDevice.configuration = {0}".format(iothubDevice.configuration))
33+
print("iothubDevice.deviceProperties = {0}".format(iothubDevice.deviceProperties))
34+
print("iothubDevice.serviceProperties = {0}".format(iothubDevice.serviceProperties))
35+
print("iothubDevice.authMethod = {0}".format(iothubDevice.authMethod))
3036
print("")
3137

3238
def iothub_registrymanager_sample_run():
@@ -38,7 +44,8 @@ def iothub_registrymanager_sample_run():
3844
# CreateDevice
3945
primaryKey = "aaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnoo"
4046
secondaryKey = "111222333444555666777888999000aaabbbcccdddee"
41-
newDevice = iothubRegistryManager.create_device(device_id, primaryKey, secondaryKey)
47+
authMethod = IoTHubRegistryManagerAuthMethod.SHARED_PRIVATE_KEY;
48+
newDevice = iothubRegistryManager.create_device(device_id, primaryKey, secondaryKey, authMethod)
4249
printDeviceInfo("CreateDevice", newDevice)
4350

4451
# GetDevice
@@ -49,7 +56,8 @@ def iothub_registrymanager_sample_run():
4956
primaryKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
5057
secondaryKey = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
5158
status = IoTHubDeviceStatus.DISABLED
52-
iothubRegistryManager.update_device(device_id, primaryKey, secondaryKey, status)
59+
authMethod = IoTHubRegistryManagerAuthMethod.SHARED_PRIVATE_KEY;
60+
iothubRegistryManager.update_device(device_id, primaryKey, secondaryKey, status, authMethod)
5361
updatedDevice = iothubRegistryManager.get_device(device_id)
5462
printDeviceInfo("UpdateDevice", updatedDevice)
5563

service/src/iothub_service_client_python.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,8 @@ class IoTHubRegistryManager
869869
IOTHUB_DEVICE CreateDevice(
870870
std::string deviceId,
871871
std::string primaryKey,
872-
std::string secondaryKey
872+
std::string secondaryKey,
873+
IOTHUB_REGISTRYMANAGER_AUTH_METHOD authMethod
873874
)
874875
{
875876
IOTHUB_DEVICE iothubDevice;
@@ -879,6 +880,7 @@ class IoTHubRegistryManager
879880
deviceCreate.deviceId = deviceId.c_str();
880881
deviceCreate.primaryKey = primaryKey.c_str();
881882
deviceCreate.secondaryKey = secondaryKey.c_str();
883+
deviceCreate.authMethod = authMethod;
882884

883885
ScopedGILRelease release;
884886
result = IoTHubRegistryManager_CreateDevice(_iothubRegistryManagerHandle, &deviceCreate, &iothubDevice);
@@ -911,7 +913,8 @@ class IoTHubRegistryManager
911913
std::string deviceId,
912914
std::string primaryKey,
913915
std::string secondaryKey,
914-
IOTHUB_DEVICE_STATUS status
916+
IOTHUB_DEVICE_STATUS status,
917+
IOTHUB_REGISTRYMANAGER_AUTH_METHOD authMethod
915918
)
916919
{
917920
IOTHUB_REGISTRYMANAGER_RESULT result = IOTHUB_REGISTRYMANAGER_OK;
@@ -921,6 +924,7 @@ class IoTHubRegistryManager
921924
deviceUpdate.primaryKey = primaryKey.c_str();
922925
deviceUpdate.secondaryKey = secondaryKey.c_str();
923926
deviceUpdate.status = status;
927+
deviceUpdate.authMethod = authMethod;
924928

925929
ScopedGILRelease release;
926930
result = IoTHubRegistryManager_UpdateDevice(_iothubRegistryManagerHandle, &deviceUpdate);
@@ -1772,6 +1776,11 @@ BOOST_PYTHON_MODULE(IMPORT_NAME)
17721776
.value("CALLBACK_NOT_SET", IOTHUB_REGISTRYMANAGER_CALLBACK_NOT_SET)
17731777
;
17741778

1779+
enum_<IOTHUB_REGISTRYMANAGER_AUTH_METHOD>("IoTHubRegistryManagerAuthMethod")
1780+
.value("SHARED_PRIVATE_KEY", IOTHUB_REGISTRYMANAGER_AUTH_SPK)
1781+
.value("X509_THUMBPRINT", IOTHUB_REGISTRYMANAGER_AUTH_X509_THUMBPRINT)
1782+
;
1783+
17751784
enum_<IOTHUB_MESSAGING_RESULT>("IoTHubMessagingResult")
17761785
.value("OK", IOTHUB_MESSAGING_OK)
17771786
.value("INVALID_ARG", IOTHUB_MESSAGING_INVALID_ARG)
@@ -1849,6 +1858,12 @@ BOOST_PYTHON_MODULE(IMPORT_NAME)
18491858
.add_property("statusReason", &IOTHUB_DEVICE::statusReason)
18501859
.add_property("statusUpdatedTime", &IOTHUB_DEVICE::statusUpdatedTime)
18511860
.add_property("lastActivityTime", &IOTHUB_DEVICE::lastActivityTime)
1861+
.add_property("cloudToDeviceMessageCount", &IOTHUB_DEVICE::cloudToDeviceMessageCount)
1862+
.add_property("isManaged", &IOTHUB_DEVICE::isManaged)
1863+
.add_property("configuration", &IOTHUB_DEVICE::configuration)
1864+
.add_property("deviceProperties", &IOTHUB_DEVICE::deviceProperties)
1865+
.add_property("serviceProperties", &IOTHUB_DEVICE::serviceProperties)
1866+
.add_property("authMethod", &IOTHUB_DEVICE::authMethod)
18521867
;
18531868

18541869
class_<IOTHUB_REGISTRY_STATISTICS>("IoTHubRegistryStatistics", no_init)

service/tests/iothub_service_client_ut.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@ def test_IoTHubRegistryManager(self):
621621
deviceId = "deviceId"
622622
primaryKey = "primaryKey"
623623
secondaryKey = "secondaryKey"
624+
authMethod = IoTHubRegistryManagerAuthMethod.SHARED_PRIVATE_KEY;
624625
with self.assertRaises(AttributeError):
625626
regManClient.CreateDevice()
626627
with self.assertRaises(Exception):
@@ -629,7 +630,9 @@ def test_IoTHubRegistryManager(self):
629630
regManClient.create_device(deviceId)
630631
with self.assertRaises(Exception):
631632
regManClient.create_device(deviceId, primaryKey)
632-
result = regManClient.create_device(deviceId, primaryKey, secondaryKey)
633+
with self.assertRaises(Exception):
634+
regManClient.create_device(deviceId, primaryKey, secondaryKey)
635+
result = regManClient.create_device(deviceId, primaryKey, secondaryKey, authMethod)
633636
self.assertIsInstance(result, IoTHubDevice)
634637

635638
# get_device
@@ -646,6 +649,7 @@ def test_IoTHubRegistryManager(self):
646649
primaryKey = "primaryKey"
647650
secondaryKey = "secondaryKey"
648651
status = IoTHubDeviceStatus.ENABLED
652+
authMethod = IoTHubRegistryManagerAuthMethod.SHARED_PRIVATE_KEY;
649653
with self.assertRaises(AttributeError):
650654
regManClient.UpdateDevice()
651655
with self.assertRaises(Exception):
@@ -656,7 +660,9 @@ def test_IoTHubRegistryManager(self):
656660
regManClient.update_device(deviceId, primaryKey)
657661
with self.assertRaises(Exception):
658662
regManClient.update_device(deviceId, primaryKey, secondaryKey)
659-
regManClient.update_device(deviceId, primaryKey, secondaryKey, status)
663+
with self.assertRaises(Exception):
664+
regManClient.create_device(deviceId, primaryKey, secondaryKey, status)
665+
regManClient.update_device(deviceId, primaryKey, secondaryKey, status, authMethod)
660666

661667
# delete_device
662668
deviceId = "deviceId"

0 commit comments

Comments
 (0)