Skip to content
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

feat: add bulk key regeneration to az iot hub device-identity renew-key and az iot hub module-identity renew-key #710

Merged
merged 34 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7ee11ca
new sdk
vilit1 Jun 13, 2024
d9ed85c
computer be slow
vilit1 Jun 18, 2024
456dcfa
make swap only support one device for now
vilit1 Jul 1, 2024
8964d7b
change error txt
vilit1 Jul 10, 2024
9623164
fix up sdk
vilit1 Jul 11, 2024
205ca28
work in progress; sdk update to make things work
vilit1 Jul 11, 2024
13744cd
fixing sdk and stuff
vilit1 Jul 17, 2024
863a23e
more general replace sdk fix
vilit1 Jul 17, 2024
caf27fb
final handcrafted sdk changes
vilit1 Jul 17, 2024
0300fd4
UNIT TEST
vilit1 Jul 17, 2024
4e57182
helapriogdgf
vilit1 Jul 17, 2024
a052b00
Merge branch 'dev' into hub_secret_update
vilit1 Jul 17, 2024
c36ac80
whoops
vilit1 Jul 17, 2024
81a6f12
Merge branch 'hub_secret_update' of https://github.com/vilit1/azure-i…
vilit1 Jul 17, 2024
2948c2d
FREEZE
vilit1 Jul 17, 2024
e4e146f
lazy fix
vilit1 Jul 17, 2024
abc5285
pylint
vilit1 Jul 17, 2024
33a8dd3
tests
vilit1 Aug 5, 2024
776612c
maybe
vilit1 Aug 5, 2024
d12deb9
maybe
vilit1 Aug 5, 2024
a9fd835
maybe mac
vilit1 Aug 5, 2024
299db6d
maybe mac
vilit1 Aug 5, 2024
6ecd964
maybe mac
vilit1 Aug 5, 2024
8662c7e
fixaroos
vilit1 Aug 7, 2024
b9e91fe
Set explicit agent images for tox workflow
c-ryan-k Aug 7, 2024
ff0b2b5
pr comemtns
vilit1 Aug 8, 2024
abc1d9c
Merge branch 'hub_secret_update' of https://github.com/vilit1/azure-i…
vilit1 Aug 8, 2024
a67057d
helapdjgdf
vilit1 Aug 8, 2024
5ad8203
testing for ryan and his chickens
vilit1 Aug 8, 2024
bac38b8
update macos agent version for ADO merge pipeline
c-ryan-k Aug 8, 2024
87092a7
Merge branch 'hub_secret_update' of https://github.com/vilit1/azure-i…
c-ryan-k Aug 8, 2024
389685c
pr comments
vilit1 Aug 8, 2024
316fe59
Merge branch 'hub_secret_update' of https://github.com/vilit1/azure-i…
vilit1 Aug 8, 2024
5a8d3f8
forgot to save constants
vilit1 Aug 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .azure-devops/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
- job: 'run_unit_tests_macOs'
dependsOn: ['build_and_publish_azure_iot_cli_ext', 'build_and_publish_azure_cli_test_sdk']
pool:
vmImage: 'macOS-11'
vmImage: 'macOS-13'

steps:
- template: templates/run-tests-parallel.yml
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ jobs:
unit-test:
name: Unit test ${{ matrix.py }} - ${{ matrix.os }}
continue-on-error: ${{ inputs.continue-on-error }}
runs-on: ${{ matrix.os }}-latest
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu
- windows
- macos
- ubuntu-22.04
- windows-2022
- macos-13
py:
- "3.11"
- "3.10"
Expand Down
18 changes: 16 additions & 2 deletions azext_iot/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,19 @@
"iot hub device-identity renew-key"
] = """
type: command
short-summary: Renew target keys of an IoT Hub device with sas authentication.
short-summary: Renew target keys of IoT Hub devices with sas authentication.
long-summary: |
Currently etags and key type `swap` are not supported for bulk key regeneration.
Bulk Key regeneration will yeild a different output format from single device key regeneration.
examples:
- name: Renew the primary key.
text: az iot hub device-identity renew-key -d {device_id} -n {iothub_name} --kt primary
- name: Swap the primary and secondary keys.
text: az iot hub device-identity renew-key -d {device_id} -n {iothub_name} --kt swap
- name: Renew the secondary key for two devices and their modules.
text: az iot hub device-identity renew-key -d {device_id} {device_id} -n {iothub_name} --kt secondary --include-modules
- name: Renew the both keys for all devices within the hub.
text: az iot hub device-identity renew-key -d * -n {iothub_name} --kt both
"""

helps[
Expand Down Expand Up @@ -557,12 +564,19 @@
"iot hub module-identity renew-key"
] = """
type: command
short-summary: Renew target keys of an IoT Hub device module with sas authentication.
short-summary: Renew target keys of IoT Hub device modules with sas authentication.
long-summary: |
Currently etags and key type `swap` are not supported for bulk key regeneration.
Bulk Key regeneration will yeild a different output format from single module key regeneration.
examples:
- name: Renew the primary key.
text: az iot hub module-identity renew-key -m {module_name} -d {device_id} -n {iothub_name} --kt primary
- name: Swap the primary and secondary keys.
text: az iot hub module-identity renew-key -m {module_name} -d {device_id} -n {iothub_name} --kt swap
- name: Renew the secondary key for two modules.
text: az iot hub module-identity renew-key -m {module_name} {module_name} -d {device_id} -n {iothub_name} --kt secondary
- name: Renew both keys for all modules in the device.
text: az iot hub module-identity renew-key -m * -d {device_id} -n {iothub_name} --kt both
"""

helps[
Expand Down
32 changes: 32 additions & 0 deletions azext_iot/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,25 @@ def load_arguments(self, _):
arg_type=get_enum_type(RenewKeyType),
help="Target key type to regenerate.",
)
context.argument(
"device_ids",
options_list=["--device-id", "-d"],
help="Space seperated list of target Device Ids. Use `*` for all devices.",
nargs="+",
action="extend"
)
context.argument(
"include_modules",
options_list=["--include-modules", "--im"],
help="Flag to include device modules during key regeneration.",
arg_type=get_three_state_flag()
)
context.argument(
"etag",
options_list=["--etag", "-e"],
help="Etag or entity tag corresponding to the last state of the resource. "
"If no etag is provided the value '*' is used. This arguement only applies to `swap`.",
)

with self.argument_context("iot hub device-identity export") as context:
context.argument(
Expand Down Expand Up @@ -614,6 +633,19 @@ def load_arguments(self, _):
arg_type=get_enum_type(RenewKeyType),
help="Target key type to regenerate.",
)
context.argument(
"module_ids",
options_list=["--module-id", "-m"],
help="Space seperated list of target Module Ids. Use `*` for all modules.",
nargs="+",
action="extend"
)
context.argument(
"etag",
options_list=["--etag", "-e"],
help="Etag or entity tag corresponding to the last state of the resource. "
"If no etag is provided the value '*' is used. This arguement only applies to `swap`.",
)

with self.argument_context("iot hub distributed-tracing update") as context:
context.argument(
Expand Down
1 change: 1 addition & 0 deletions azext_iot/common/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ class RenewKeyType(Enum):
primary = KeyType.primary.value
secondary = KeyType.secondary.value
swap = "swap"
both = "both"


class IoTHubStateType(Enum):
Expand Down
4 changes: 4 additions & 0 deletions azext_iot/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
IOTDPS_PROVISIONING_HOST = "global.azure-devices-provisioning.net"
DEVICETWIN_POLLING_INTERVAL_SEC = 10
DEVICETWIN_MONITOR_TIME_SEC = 15
IOTHUB_THROTTLE_MAX_TRIES = 3
IOTHUB_THROTTLE_SLEEP_SEC = 20
THROTTLE_HTTP_STATUS_CODE = 429
IOTHUB_RENEW_KEY_BATCH_SIZE = 100
# (Lib name, minimum version (including), maximum version (excluding))
EVENT_LIB = ("uamqp", "1.2", "1.3")
PNP_DTDLV2_COMPONENT_MARKER = "__t"
Loading