-
Notifications
You must be signed in to change notification settings - Fork 72
Extend generate-sas-token to take a device connection string #319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1611,6 +1611,7 @@ def iot_get_sas_token( | |
| cmd, | ||
| hub_name=None, | ||
| device_id=None, | ||
| device_connection_string=None, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of supporting an offline mode just for device connection strings, I'm thinking it would be valuable to support either hub, device or module offline SAS token generation via generic
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @digimaun absolutely agree. This just happened to cover my use case for IoT Central but agree that there's no reason to restrict to only device connection strings |
||
| policy_name="iothubowner", | ||
| key_type="primary", | ||
| duration=3600, | ||
|
|
@@ -1639,6 +1640,7 @@ def iot_get_sas_token( | |
| cmd, | ||
| hub_name, | ||
| device_id, | ||
| device_connection_string, | ||
| module_id, | ||
| policy_name, | ||
| key_type, | ||
|
|
@@ -1653,6 +1655,7 @@ def _iot_build_sas_token( | |
| cmd, | ||
| hub_name=None, | ||
| device_id=None, | ||
| device_connection_string=None, | ||
| module_id=None, | ||
| policy_name="iothubowner", | ||
| key_type="primary", | ||
|
|
@@ -1665,16 +1668,30 @@ def _iot_build_sas_token( | |
| parse_iot_device_module_connection_string, | ||
| ) | ||
|
|
||
| uri = None | ||
| policy = None | ||
| key = None | ||
|
|
||
| if device_connection_string: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets add tests to exercise the scenario
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've noticed it creates a bunch of regression issues in my az iot cli which I need to look at before I go further with it |
||
| try: | ||
| parsed_device_cs = parse_iot_device_connection_string(device_connection_string) | ||
| except ValueError as e: | ||
| logger.debug(e) | ||
| raise CLIError("This device does not support SAS auth.") | ||
|
|
||
| uri = "{}/devices/{}".format(parsed_device_cs["HostName"], parsed_device_cs["DeviceId"]) | ||
| key = parsed_device_cs["SharedAccessKey"] | ||
|
|
||
| return SasTokenAuthentication(uri, policy, key, duration) | ||
|
|
||
| discovery = IotHubDiscovery(cmd) | ||
| target = discovery.get_target( | ||
| hub_name=hub_name, | ||
| resource_group_name=resource_group_name, | ||
| policy_name=policy_name, | ||
| login=login, | ||
| ) | ||
| uri = None | ||
| policy = None | ||
| key = None | ||
|
|
||
| if device_id: | ||
| logger.info( | ||
| 'Obtaining device "%s" details from registry, using IoT Hub policy "%s"', | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove the extra spaces.