* Adds support for X.509 Certificates in IoT Hub.

* Modifies release notes and changes help link.

* Cleans up .gitignore, and HISTORY.rst. Passes a single factory in commands.py. Moves test utilities. Adds a file completer.

* Updates style after rebase based on additional linter restrictions.
This commit is contained in:
Andrew Buckley 2017-11-07 15:20:56 -08:00 коммит произвёл Willie Xu
Родитель febec631d7
Коммит 55b7b73170
16 изменённых файлов: 3967 добавлений и 2542 удалений

Просмотреть файл

@ -377,8 +377,10 @@
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\mgmt_iot_hub_device\lib\__init__.py" />
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\mgmt_iot_hub_device\__init__.py" />
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\sas_token_auth.py" />
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\tests\test_iot_certificate_commands.py" />
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\tests\test_iot_commands.py" />
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\tests\test_sas_token_auth.py" />
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\_constants.py" />
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\_factory.py" />
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\_help.py" />
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\_params.py" />

Просмотреть файл

@ -358,8 +358,10 @@
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\mgmt_iot_hub_device\lib\version.py" />
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\mgmt_iot_hub_device\lib\__init__.py" />
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\sas_token_auth.py" />
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\tests\test_iot_certificate_commands.py" />
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\tests\test_iot_commands.py" />
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\tests\test_sas_token_auth.py" />
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\_constants.py" />
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\_factory.py" />
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\_help.py" />
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\_params.py" />

4
src/command_modules/azure-cli-iot/.gitignore поставляемый Normal file
Просмотреть файл

@ -0,0 +1,4 @@
# Certificate files
*.key
*.cer
*.pem

Просмотреть файл

@ -5,13 +5,13 @@ Release History
0.1.14
++++++
* Adds support for certificate authorities (CA) and certificate chains.
* Minor fixes.
0.1.13
++++++
* minor fixes
0.1.12 (2017-09-22)
+++++++++++++++++++
* minor fixes

Просмотреть файл

@ -0,0 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
certificate_help = """For a detailed explanation of CA certificates in Azure IoT Hub,
see https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-x509ca-overview """

Просмотреть файл

@ -7,7 +7,7 @@
def iot_hub_service_factory(_):
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azure.mgmt.iothub.iot_hub_client import IotHubClient
return get_mgmt_service_client(IotHubClient).iot_hub_resource
return get_mgmt_service_client(IotHubClient)
def resource_service_factory(**_):

Просмотреть файл

@ -4,6 +4,7 @@
# --------------------------------------------------------------------------------------------
from azure.cli.core.help_files import helps
from ._constants import certificate_help
helps['iot'] = """
type: group
@ -20,10 +21,97 @@ helps['iot hub'] = """
short-summary: (PREVIEW) Manage Azure IoT hubs.
"""
helps['iot hub certificate'] = """
type: group
short-summary: Manage IoT Hub certificates.
"""
helps['iot hub certificate create'] = """
type: command
short-summary: Create/upload an Azure IoT Hub certificate.
long-summary: {0}
examples:
- name: Uploads a CA certificate PEM file to an IoT hub.
text: >
az iot hub certificate create --hub-name MyIotHub --name MyCertificate --path /certificates/Certificate.pem
- name: Uploads a CA certificate CER file to an IoT hub.
text: >
az iot hub certificate create --hub-name MyIotHub --name MyCertificate --path /certificates/Certificate.cer
""".format(certificate_help)
helps['iot hub certificate update'] = """
type: command
short-summary: Update an Azure IoT Hub certificate.
long-summary: Uploads a new certificate to replace the existing certificate with the same name. {0}
examples:
- name: Updates a CA certificate in an IoT hub by uploading a new PEM file.
text: >
az iot hub certificate update --hub-name MyIotHub --name MyCertificate --path /certificates/NewCertificate.pem --etag
AAAAAAAAAAA=
- name: Updates a CA certificate in an IoT hub by uploading a new CER file.
text: >
az iot hub certificate update --hub-name MyIotHub --name MyCertificate --path /certificates/NewCertificate.cer --etag
AAAAAAAAAAA=
""".format(certificate_help)
helps['iot hub certificate delete'] = """
type: command
short-summary: Deletes an Azure IoT Hub certificate.
long-summary: {0}
examples:
- name: Deletes MyCertificate
text: >
az iot hub certificate delete --hub-name MyIotHub --name MyCertificate --etag AAAAAAAAAAA=
""".format(certificate_help)
helps['iot hub certificate show'] = """
type: command
short-summary: Shows information about a particular Azure IoT Hub certificate.
long-summary: {0}
examples:
- name: Show details about MyCertificate
text: >
az iot hub certificate show --hub-name MyIotHub --name MyCertificate
""".format(certificate_help)
helps['iot hub certificate list'] = """
type: command
short-summary: Lists all certificates contained within an Azure IoT Hub
long-summary: {0}
examples:
- name: List all certificates in MyIotHub
text: >
az iot hub certificate list --hub-name MyIotHub
""".format(certificate_help)
helps['iot hub certificate generate-verification-code'] = """
type: command
short-summary: Generates a verification code for an Azure IoT Hub certificate.
long-summary: This verification code is used to complete the proof of possession step for a certificate. Use this
verification code as the CN of a new certificate signed with the root certificates private key. {0}
examples:
- name: Generates a verification code for MyCertificate
text: >
az iot hub certificate generate-verification-code --hub-name MyIotHub --name MyCertificate --etag
AAAAAAAAAAA=
""".format(certificate_help)
helps['iot hub certificate verify'] = """
type: command
short-summary: Verifies an Azure IoT Hub certificate.
long-summary: Verifies a certificate by uploading a verification certificate containing the verification code obtained
by calling generate-verification-code. This is the last step in the proof of possession process. {0}
examples:
- name: Verifies ownership of the MyCertificate private key.
text: >
az iot hub certificate verify --hub-name MyIotHub --name MyCertificate --path /certificates/Verification.pem --etag
AAAAAAAAAAA=
""".format(certificate_help)
helps['iot hub create'] = """
type: command
short-summary: Create an Azure IoT hub.
long-summary: 'For an introduction to Azure IoT Hub, see https://docs.microsoft.com/azure/iot-hub/'
long-summary: For an introduction to Azure IoT Hub, see https://docs.microsoft.com/azure/iot-hub/
examples:
- name: Create an IoT Hub with the free pricing tier F1, in the region of the resource group.
text: >
@ -288,11 +376,11 @@ helps['iot device message abandon'] = """
helps['iot device export'] = """
type: command
short-summary: Export all the device identities in the IoT hub identity registry to an Azure Storage blob container.
long-summary: 'For more information, see https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-identity-registry#import-and-export-device-identities'
long-summary: For more information, see https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-identity-registry#import-and-export-device-identities
"""
helps['iot device import'] = """
type: command
short-summary: Import, update, or delete device identities in the IoT hub identity registry from a blob.
long-summary: 'For more information, see https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-identity-registry#import-and-export-device-identities'
long-summary: For more information, see https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-identity-registry#import-and-export-device-identities
"""

Просмотреть файл

@ -3,7 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
from azure.cli.core.commands.parameters import (location_type, enum_choice_list,
from argcomplete.completers import FilesCompleter
from azure.cli.core.commands.parameters import (location_type, enum_choice_list, file_type,
get_resource_name_completion_list, CliArgumentType)
from azure.cli.core.commands import register_cli_argument
from azure.mgmt.iothub.models.iot_hub_client_enums import IotHubSku
@ -23,9 +24,15 @@ hub_name_type = CliArgumentType(
completer=get_resource_name_completion_list('Microsoft.Devices/IotHubs'),
help='IoT Hub name.')
register_cli_argument('iot hub', 'hub_name', hub_name_type, options_list=('--name', '-n'),
id_part='name')
for subgroup in ['consumer-group', 'policy', 'job']:
etag_type = CliArgumentType(
None, help='Entity Tag (etag) of the object.')
register_cli_argument('iot hub', 'hub_name', hub_name_type, options_list=('--name', '-n'), id_part='name')
register_cli_argument('iot hub', 'etag', etag_type, options_list=('--etag', '-e'))
for subgroup in ['consumer-group', 'policy', 'job', 'certificate']:
register_cli_argument('iot hub {}'.format(subgroup), 'hub_name', options_list=('--hub-name',))
register_cli_argument('iot device', 'hub_name', hub_name_type)
@ -33,6 +40,14 @@ register_cli_argument('iot device', 'hub_name', hub_name_type)
register_cli_argument('iot', 'device_id', options_list=('--device-id', '-d'), help='Device Id.',
completer=get_device_id_completion_list)
# Arguments for 'iot hub certificate' group
register_cli_argument('iot hub certificate', 'certificate_path', options_list=('--path', '-p'), type=file_type,
completer=FilesCompleter([".cer", ".pem"]),
help='The path to the file containing the certificate.')
register_cli_argument('iot hub certificate', 'certificate_name', options_list=('--name', '-n'),
help='A friendly name for the certificate.')
# Arguments for 'iot hub consumer-group' group
register_cli_argument('iot hub consumer-group', 'consumer_group_name',
options_list=('--name', '-n'),

Просмотреть файл

@ -4,6 +4,7 @@
# --------------------------------------------------------------------------------------------
from os.path import exists, join
import base64
from OpenSSL import crypto
@ -37,3 +38,15 @@ def create_self_signed_certificate(device_id, valid_days, cert_output_dir):
'privateKey': key_dump,
'thumbprint': thumbprint
}
def open_certificate(certificate_path):
certificate = ""
if certificate_path.endswith('.pem') or certificate_path.endswith('.cer'):
with open(certificate_path, "rb") as cert_file:
certificate = cert_file.read()
try:
certificate = certificate.decode("utf-8")
except UnicodeError:
certificate = base64.b64encode(certificate).decode("utf-8")
return certificate

Просмотреть файл

@ -31,6 +31,22 @@ if not supported_api_version(PROFILE_TYPE, max_api='2017-03-09-profile'):
raise e
return None
# iot hub certificate commands
cli_command(__name__, 'iot hub certificate list', custom_path.format('iot_hub_certificate_list'),
factory)
cli_command(__name__, 'iot hub certificate show', custom_path.format('iot_hub_certificate_get'),
factory)
cli_command(__name__, 'iot hub certificate create', custom_path.format('iot_hub_certificate_create'),
factory)
cli_command(__name__, 'iot hub certificate delete', custom_path.format('iot_hub_certificate_delete'),
factory)
cli_command(__name__, 'iot hub certificate generate-verification-code',
custom_path.format('iot_hub_certificate_gen_code'), factory)
cli_command(__name__, 'iot hub certificate verify', custom_path.format('iot_hub_certificate_verify'),
factory)
cli_command(__name__, 'iot hub certificate update', custom_path.format('iot_hub_certificate_update'),
factory)
# iot hub commands
cli_command(__name__, 'iot hub create', custom_path.format('iot_hub_create'), factory)
cli_command(__name__, 'iot hub list', custom_path.format('iot_hub_list'), factory)

Просмотреть файл

@ -18,7 +18,7 @@ from azure.cli.command_modules.iot.mgmt_iot_hub_device.lib.models.device_descrip
from azure.cli.command_modules.iot.mgmt_iot_hub_device.lib.models.x509_thumbprint import X509Thumbprint
from azure.cli.command_modules.iot.sas_token_auth import SasTokenAuthentication
from ._factory import resource_service_factory
from ._utils import create_self_signed_certificate
from ._utils import create_self_signed_certificate, open_certificate
# CUSTOM TYPE
@ -41,16 +41,70 @@ class SimpleAccessRights(Enum):
# CUSTOM METHODS
def iot_hub_certificate_list(client, hub_name, resource_group_name=None):
resource_group_name = _ensure_resource_group_name(client, resource_group_name, hub_name)
return client.certificates.list_by_iot_hub(resource_group_name, hub_name)
def iot_hub_certificate_get(client, hub_name, certificate_name, resource_group_name=None):
resource_group_name = _ensure_resource_group_name(client, resource_group_name, hub_name)
return client.certificates.get(resource_group_name, hub_name, certificate_name)
def iot_hub_certificate_create(client, hub_name, certificate_name, certificate_path, resource_group_name=None):
resource_group_name = _ensure_resource_group_name(client, resource_group_name, hub_name)
# Get list of certs
cert_list = client.certificates.list_by_iot_hub(resource_group_name, hub_name)
for cert in cert_list.value:
if cert.name == certificate_name:
raise CLIError("Certificate '{0}' already exists. Use 'iot hub certificate update'"
" to update an existing certificate.".format(certificate_name))
certificate = open_certificate(certificate_path)
if not certificate:
raise CLIError("Error uploading certificate '{0}'.".format(certificate_path))
return client.certificates.create_or_update(resource_group_name, hub_name, certificate_name, None, certificate)
def iot_hub_certificate_update(client, hub_name, certificate_name, certificate_path, etag, resource_group_name=None):
resource_group_name = _ensure_resource_group_name(client, resource_group_name, hub_name)
cert_list = client.certificates.list_by_iot_hub(resource_group_name, hub_name)
for cert in cert_list.value:
if cert.name == certificate_name:
certificate = open_certificate(certificate_path)
if not certificate:
raise CLIError("Error uploading certificate '{0}'.".format(certificate_path))
return client.certificates.create_or_update(resource_group_name, hub_name, certificate_name, etag, certificate)
raise CLIError("Certificate '{0}' does not exist. Use 'iot hub certificate create' to create a new certificate.".format(certificate_name))
def iot_hub_certificate_delete(client, hub_name, certificate_name, etag, resource_group_name=None):
resource_group_name = _ensure_resource_group_name(client, resource_group_name, hub_name)
return client.certificates.delete(resource_group_name, hub_name, certificate_name, etag)
def iot_hub_certificate_gen_code(client, hub_name, certificate_name, etag, resource_group_name=None):
resource_group_name = _ensure_resource_group_name(client, resource_group_name, hub_name)
return client.certificates.generate_verification_code(resource_group_name, hub_name, certificate_name, etag)
def iot_hub_certificate_verify(client, hub_name, certificate_name, certificate_path, etag, resource_group_name=None):
resource_group_name = _ensure_resource_group_name(client, resource_group_name, hub_name)
certificate = open_certificate(certificate_path)
if not certificate:
raise CLIError("Error uploading certificate '{0}'.".format(certificate_path))
return client.certificates.verify(resource_group_name, hub_name, certificate_name, etag, certificate)
def iot_hub_create(client, hub_name, resource_group_name, location=None, sku=IotHubSku.f1.value, unit=1):
_check_name_availability(client, hub_name)
_check_name_availability(client.iot_hub_resource, hub_name)
location = _ensure_location(resource_group_name, location)
hub_description = IotHubDescription(location, client.config.subscription_id, resource_group_name,
hub_description = IotHubDescription(location, client.iot_hub_resource.config.subscription_id, resource_group_name,
IotHubSkuInfo(name=sku, capacity=unit))
return client.create_or_update(resource_group_name, hub_name, hub_description)
return client.iot_hub_resource.create_or_update(resource_group_name, hub_name, hub_description)
def _check_name_availability(client, hub_name):
name_availability = client.check_name_availability(hub_name)
def _check_name_availability(iot_hub_resource, hub_name):
name_availability = iot_hub_resource.check_name_availability(hub_name)
if name_availability is not None and not name_availability.name_available:
raise CLIError(name_availability.message)
@ -58,23 +112,23 @@ def _check_name_availability(client, hub_name):
def iot_hub_get(client, hub_name, resource_group_name=None):
if resource_group_name is None:
return _get_iot_hub_by_name(client, hub_name)
return client.get(resource_group_name, hub_name)
return client.iot_hub_resource.get(resource_group_name, hub_name)
def iot_hub_list(client, resource_group_name=None):
if resource_group_name is None:
return client.list_by_subscription()
return client.list_by_resource_group(resource_group_name)
return client.iot_hub_resource.list_by_subscription()
return client.iot_hub_resource.list_by_resource_group(resource_group_name)
def iot_hub_update(client, hub_name, parameters, resource_group_name=None):
resource_group_name = _ensure_resource_group_name(client, resource_group_name, hub_name)
return client.create_or_update(resource_group_name, hub_name, parameters, {'IF-MATCH': parameters.etag})
return client.iot_hub_resource.create_or_update(resource_group_name, hub_name, parameters, {'IF-MATCH': parameters.etag})
def iot_hub_delete(client, hub_name, resource_group_name=None):
resource_group_name = _ensure_resource_group_name(client, resource_group_name, hub_name)
return client.delete(resource_group_name, hub_name)
return client.iot_hub_resource.delete(resource_group_name, hub_name)
def iot_hub_show_connection_string(client, hub_name=None, resource_group_name=None, policy_name='iothubowner',
@ -82,7 +136,7 @@ def iot_hub_show_connection_string(client, hub_name=None, resource_group_name=No
if hub_name is None:
hubs = iot_hub_list(client, resource_group_name)
if hubs is None:
raise CLIError('No IoT Hub found.')
raise CLIError("No IoT Hub found.")
def conn_str_getter(h):
return _get_single_hub_connection_string(client, h.name, h.resourcegroup, policy_name, key_type)
@ -102,37 +156,37 @@ def _get_single_hub_connection_string(client, hub_name, resource_group_name, pol
def iot_hub_sku_list(client, hub_name, resource_group_name=None):
resource_group_name = _ensure_resource_group_name(client, resource_group_name, hub_name)
return client.get_valid_skus(resource_group_name, hub_name)
return client.iot_hub_resource.get_valid_skus(resource_group_name, hub_name)
def iot_hub_consumer_group_create(client, hub_name, consumer_group_name, resource_group_name=None, event_hub_name='events'):
resource_group_name = _ensure_resource_group_name(client, resource_group_name, hub_name)
return client.create_event_hub_consumer_group(resource_group_name, hub_name, event_hub_name, consumer_group_name)
return client.iot_hub_resource.create_event_hub_consumer_group(resource_group_name, hub_name, event_hub_name, consumer_group_name)
def iot_hub_consumer_group_list(client, hub_name, resource_group_name=None, event_hub_name='events'):
resource_group_name = _ensure_resource_group_name(client, resource_group_name, hub_name)
return client.list_event_hub_consumer_groups(resource_group_name, hub_name, event_hub_name)
return client.iot_hub_resource.list_event_hub_consumer_groups(resource_group_name, hub_name, event_hub_name)
def iot_hub_consumer_group_get(client, hub_name, consumer_group_name, resource_group_name=None, event_hub_name='events'):
resource_group_name = _ensure_resource_group_name(client, resource_group_name, hub_name)
return client.get_event_hub_consumer_group(resource_group_name, hub_name, event_hub_name, consumer_group_name)
return client.iot_hub_resource.get_event_hub_consumer_group(resource_group_name, hub_name, event_hub_name, consumer_group_name)
def iot_hub_consumer_group_delete(client, hub_name, consumer_group_name, resource_group_name=None, event_hub_name='events'):
resource_group_name = _ensure_resource_group_name(client, resource_group_name, hub_name)
return client.delete_event_hub_consumer_group(resource_group_name, hub_name, event_hub_name, consumer_group_name)
return client.iot_hub_resource.delete_event_hub_consumer_group(resource_group_name, hub_name, event_hub_name, consumer_group_name)
def iot_hub_policy_list(client, hub_name, resource_group_name=None):
resource_group_name = _ensure_resource_group_name(client, resource_group_name, hub_name)
return client.list_keys(resource_group_name, hub_name)
return client.iot_hub_resource.list_keys(resource_group_name, hub_name)
def iot_hub_policy_get(client, hub_name, policy_name, resource_group_name=None):
resource_group_name = _ensure_resource_group_name(client, resource_group_name, hub_name)
return client.get_keys_for_key_name(resource_group_name, hub_name, policy_name)
return client.iot_hub_resource.get_keys_for_key_name(resource_group_name, hub_name, policy_name)
def iot_hub_policy_create(client, hub_name, policy_name, permissions, resource_group_name=None):
@ -141,10 +195,10 @@ def iot_hub_policy_create(client, hub_name, policy_name, permissions, resource_g
policies = []
policies.extend(iot_hub_policy_list(client, hub_name, hub.resourcegroup))
if _is_policy_existed(policies, policy_name):
raise CLIError('Policy {0} already existed.'.format(policy_name))
raise CLIError("Policy {0} already existed.".format(policy_name))
policies.append(SharedAccessSignatureAuthorizationRule(policy_name, rights))
hub.properties.authorization_policies = policies
return client.create_or_update(hub.resourcegroup, hub_name, hub, {'IF-MATCH': hub.etag})
return client.iot_hub_resource.create_or_update(hub.resourcegroup, hub_name, hub, {'IF-MATCH': hub.etag})
def iot_hub_policy_delete(client, hub_name, policy_name, resource_group_name=None):
@ -152,10 +206,10 @@ def iot_hub_policy_delete(client, hub_name, policy_name, resource_group_name=Non
hub = iot_hub_get(client, hub_name, resource_group_name)
policies = iot_hub_policy_list(client, hub_name, hub.resourcegroup)
if not _is_policy_existed(copy.deepcopy(policies), policy_name):
raise CLIError('Policy {0} not found.'.format(policy_name))
raise CLIError("Policy {0} not found.".format(policy_name))
updated_policies = [p for p in policies if p.key_name.lower() != policy_name.lower()]
hub.properties.authorization_policies = updated_policies
return client.create_or_update(hub.resourcegroup, hub_name, hub, {'IF-MATCH': hub.etag})
return client.iot_hub_resource.create_or_update(hub.resourcegroup, hub_name, hub, {'IF-MATCH': hub.etag})
def _is_policy_existed(policies, policy_name):
@ -165,12 +219,12 @@ def _is_policy_existed(policies, policy_name):
def iot_hub_job_list(client, hub_name, resource_group_name=None):
resource_group_name = _ensure_resource_group_name(client, resource_group_name, hub_name)
return client.list_jobs(resource_group_name, hub_name)
return client.iot_hub_resource.list_jobs(resource_group_name, hub_name)
def iot_hub_job_get(client, hub_name, job_id, resource_group_name=None):
resource_group_name = _ensure_resource_group_name(client, resource_group_name, hub_name)
return client.get_job(resource_group_name, hub_name, job_id)
return client.iot_hub_resource.get_job(resource_group_name, hub_name, job_id)
def iot_hub_job_cancel(client, hub_name, job_id, resource_group_name=None):
@ -180,12 +234,12 @@ def iot_hub_job_cancel(client, hub_name, job_id, resource_group_name=None):
def iot_hub_get_quota_metrics(client, hub_name, resource_group_name=None):
resource_group_name = _ensure_resource_group_name(client, resource_group_name, hub_name)
return client.get_quota_metrics(resource_group_name, hub_name)
return client.iot_hub_resource.get_quota_metrics(resource_group_name, hub_name)
def iot_hub_get_stats(client, hub_name, resource_group_name=None):
resource_group_name = _ensure_resource_group_name(client, resource_group_name, hub_name)
return client.get_stats(resource_group_name, hub_name)
return client.iot_hub_resource.get_stats(resource_group_name, hub_name)
def iot_device_create(client, hub_name, device_id, resource_group_name=None, x509=False, primary_thumbprint=None,
@ -203,14 +257,14 @@ def iot_device_create(client, hub_name, device_id, resource_group_name=None, x50
def _validate_x509_parameters(x509, primary_thumbprint, secondary_thumbprint, valid_days, output_dir):
if x509 is True:
if any([primary_thumbprint, secondary_thumbprint]) and any([valid_days, output_dir]):
raise CLIError('Certificate thumbprint parameters are used for existing certificates.\n'
'Certificate valid days and output directory are used to generate self-signed certificate.\n'
'They must not be used together.')
raise CLIError("Certificate thumbprint parameters are used for existing certificates.\n"
"Certificate valid days and output directory are used to generate self-signed certificate.\n"
"They must not be used together.")
if output_dir is not None and not exists(output_dir):
raise CLIError('Directory not exist: {0}'.format(output_dir))
raise CLIError("Directory not exist: {0}".format(output_dir))
else:
if any([primary_thumbprint, secondary_thumbprint, valid_days, output_dir]):
raise CLIError('X.509 certificate parameters must be used with --x509 flag.')
raise CLIError("X.509 certificate parameters must be used with --x509 flag.")
def _construct_x509_auth(device_id, primary_thumbprint, secondary_thumbprint, valid_days, output_dir):
@ -248,7 +302,7 @@ def iot_device_show_connection_string(client, hub_name, device_id=None, resource
if device_id is None:
devices = iot_device_list(client, hub_name, resource_group_name, top)
if devices is None:
raise CLIError('No devices found in IoT Hub {}.'.format(hub_name))
raise CLIError("No devices found in IoT Hub {}.".format(hub_name))
def conn_str_getter(d):
return _get_single_device_connection_string(client, hub_name, d.device_id, resource_group_name, key_type)
@ -300,26 +354,26 @@ def iot_device_abandon_message(client, hub_name, device_id, lock_token, resource
def iot_device_export(client, hub_name, blob_container_uri, include_keys=False, resource_group_name=None):
resource_group_name = _ensure_resource_group_name(client, resource_group_name, hub_name)
return client.export_devices(resource_group_name, hub_name, blob_container_uri, not include_keys)
return client.iot_hub_resource.export_devices(resource_group_name, hub_name, blob_container_uri, not include_keys)
def iot_device_import(client, hub_name, input_blob_container_uri, output_blob_container_uri, resource_group_name=None):
resource_group_name = _ensure_resource_group_name(client, resource_group_name, hub_name)
return client.import_devices(resource_group_name, hub_name, input_blob_container_uri, output_blob_container_uri)
return client.iot_hub_resource.import_devices(resource_group_name, hub_name, input_blob_container_uri, output_blob_container_uri)
def _get_single_device_connection_string(client, hub_name, device_id, resource_group_name, key_type):
device_client = _get_device_client(client, resource_group_name, hub_name, device_id)
device = device_client.get(device_id)
if device is None:
raise CLIError('Device {} not found.'.format(device_id))
raise CLIError("Device {} not found.".format(device_id))
conn_str_template = 'HostName={0}.azure-devices.net;DeviceId={1};{2}={3}'
conn_str_template = "HostName={0}.azure-devices.net;DeviceId={1};{2}={3}"
keys = device.authentication.symmetric_key
if any([keys.primary_key, keys.secondary_key]):
key = keys.secondary_key if key_type == KeyType.secondary else keys.primary_key
if key is None:
raise CLIError('{0} key not found.'.format(key_type))
raise CLIError("{0} key not found.".format(key_type))
return conn_str_template.format(hub_name, device_id, 'SharedAccessKey', key)
else:
return conn_str_template.format(hub_name, device_id, 'x509', 'true')
@ -331,17 +385,17 @@ def _get_device_client(client, resource_group_name, hub_name, device_id):
uri = '{0}/devices/{1}'.format(base_url, device_id)
access_policy = iot_hub_policy_get(client, hub_name, 'iothubowner', resource_group_name)
creds = SasTokenAuthentication(uri, access_policy.key_name, access_policy.primary_key)
return IotHubDeviceClient(creds, client.config.subscription_id, base_url='https://' + base_url).iot_hub_devices
return IotHubDeviceClient(creds, client.iot_hub_resource.config.subscription_id, base_url='https://' + base_url).iot_hub_devices
def _get_iot_hub_by_name(client, hub_name):
all_hubs = iot_hub_list(client)
if all_hubs is None:
raise CLIError('No IoT Hub found in current subscription.')
raise CLIError("No IoT Hub found in current subscription.")
try:
target_hub = next(x for x in all_hubs if hub_name.lower() == x.name.lower())
except StopIteration:
raise CLIError('No IoT Hub found with name {} in current subscription.'.format(hub_name))
raise CLIError("No IoT Hub found with name {} in current subscription.".format(hub_name))
return target_hub

Просмотреть файл

@ -0,0 +1,80 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
from os.path import exists
import os
from OpenSSL import crypto
def _create_test_cert(cert_file, key_file, subject, valid_days, serial_number):
# create a key pair
k = crypto.PKey()
k.generate_key(crypto.TYPE_RSA, 2046)
# create a self-signed cert with some basic constraints
cert = crypto.X509()
cert.get_subject().CN = subject
cert.gmtime_adj_notBefore(-1 * 24 * 60 * 60)
cert.gmtime_adj_notAfter(valid_days * 24 * 60 * 60)
cert.set_version(2)
cert.set_serial_number(serial_number)
cert.add_extensions([
crypto.X509Extension(b"basicConstraints", True, b"CA:TRUE, pathlen:1"),
crypto.X509Extension(b"subjectKeyIdentifier", False, b"hash",
subject=cert),
])
cert.add_extensions([
crypto.X509Extension(b"authorityKeyIdentifier", False, b"keyid:always",
issuer=cert)
])
cert.set_issuer(cert.get_subject())
cert.set_pubkey(k)
cert.sign(k, 'sha256')
cert_str = crypto.dump_certificate(crypto.FILETYPE_PEM, cert).decode('ascii')
key_str = crypto.dump_privatekey(crypto.FILETYPE_PEM, k).decode('ascii')
open(cert_file, 'w').write(cert_str)
open(key_file, 'w').write(key_str)
def _delete_test_cert(cert_file, key_file, verification_file):
if exists(cert_file) and exists(key_file):
os.remove(cert_file)
os.remove(key_file)
if exists(verification_file):
os.remove(verification_file)
def _create_verification_cert(cert_file, key_file, verification_file, nonce, valid_days, serial_number):
if exists(cert_file) and exists(key_file):
# create a key pair
public_key = crypto.PKey()
public_key.generate_key(crypto.TYPE_RSA, 2046)
# open the root cert and key
signing_cert = crypto.load_certificate(crypto.FILETYPE_PEM, open(cert_file).read())
k = crypto.load_privatekey(crypto.FILETYPE_PEM, open(key_file).read())
# create a cert signed by the root
verification_cert = crypto.X509()
verification_cert.get_subject().CN = nonce
verification_cert.gmtime_adj_notBefore(0)
verification_cert.gmtime_adj_notAfter(valid_days * 24 * 60 * 60)
verification_cert.set_version(2)
verification_cert.set_serial_number(serial_number)
verification_cert.set_pubkey(public_key)
verification_cert.set_issuer(signing_cert.get_subject())
verification_cert.add_extensions([
crypto.X509Extension(b"authorityKeyIdentifier", False, b"keyid:always",
issuer=signing_cert)
])
verification_cert.sign(k, 'sha256')
verification_cert_str = crypto.dump_certificate(crypto.FILETYPE_PEM, verification_cert).decode('ascii')
open(verification_file, 'w').write(verification_cert_str)

Просмотреть файл

@ -0,0 +1,565 @@
interactions:
- request:
body: '{"tags": {"use": "az-test"}, "location": "westus"}'
headers:
Accept: [application/json]
Accept-Encoding: ['gzip, deflate']
CommandName: [group create]
Connection: [keep-alive]
Content-Length: ['50']
Content-Type: [application/json; charset=utf-8]
User-Agent: [python/3.5.3 (Windows-10-10.0.14393-SP0) requests/2.18.4 msrest/0.4.18
msrest_azure/0.4.16 resourcemanagementclient/1.2.1 Azure-SDK-For-Python
AZURECLI/2.0.21]
accept-language: [en-US]
method: PUT
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clitest.rg000002?api-version=2017-05-10
response:
body: {string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000002","name":"clitest.rg000002","location":"westus","tags":{"use":"az-test"},"properties":{"provisioningState":"Succeeded"}}'}
headers:
cache-control: [no-cache]
content-length: ['328']
content-type: [application/json; charset=utf-8]
date: ['Mon, 06 Nov 2017 19:47:24 GMT']
expires: ['-1']
pragma: [no-cache]
strict-transport-security: [max-age=31536000; includeSubDomains]
x-ms-ratelimit-remaining-subscription-writes: ['1199']
status: {code: 201, message: Created}
- request:
body: 'b''{"Name": "iot-hub-for-cert-test000003"}'''
headers:
Accept: [application/json]
Accept-Encoding: ['gzip, deflate']
CommandName: [iot hub create]
Connection: [keep-alive]
Content-Length: ['60']
Content-Type: [application/json; charset=utf-8]
User-Agent: [python/3.5.3 (Windows-10-10.0.14393-SP0) requests/2.18.4 msrest/0.4.18
msrest_azure/0.4.16 iothubclient/0.4.0 Azure-SDK-For-Python AZURECLI/2.0.21]
accept-language: [en-US]
method: POST
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Devices/checkNameAvailability?api-version=2017-07-01
response:
body: {string: '{"nameAvailable":true,"reason":"Invalid","message":null}'}
headers:
cache-control: [no-cache]
content-length: ['56']
content-type: [application/json; charset=utf-8]
date: ['Mon, 06 Nov 2017 19:47:23 GMT']
expires: ['-1']
pragma: [no-cache]
server: [Microsoft-HTTPAPI/2.0]
strict-transport-security: [max-age=31536000; includeSubDomains]
transfer-encoding: [chunked]
vary: [Accept-Encoding]
x-ms-ratelimit-remaining-subscription-writes: ['1198']
status: {code: 200, message: OK}
- request:
body: null
headers:
Accept: [application/json]
Accept-Encoding: ['gzip, deflate']
CommandName: [iot hub create]
Connection: [keep-alive]
Content-Type: [application/json; charset=utf-8]
User-Agent: [python/3.5.3 (Windows-10-10.0.14393-SP0) requests/2.18.4 msrest/0.4.18
msrest_azure/0.4.16 resourcemanagementclient/1.2.1 Azure-SDK-For-Python
AZURECLI/2.0.21]
accept-language: [en-US]
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clitest.rg000002?api-version=2017-05-10
response:
body: {string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000002","name":"clitest.rg000002","location":"westus","tags":{"use":"az-test"},"properties":{"provisioningState":"Succeeded"}}'}
headers:
cache-control: [no-cache]
content-length: ['328']
content-type: [application/json; charset=utf-8]
date: ['Mon, 06 Nov 2017 19:47:24 GMT']
expires: ['-1']
pragma: [no-cache]
strict-transport-security: [max-age=31536000; includeSubDomains]
vary: [Accept-Encoding]
status: {code: 200, message: OK}
- request:
body: 'b''{"subscriptionid": "377c3343-75bb-4244-98a3-0fb84a830c4b", "location":
"westus", "sku": {"name": "S1", "capacity": 1}, "resourcegroup": "clitest.rg000002"}'''
headers:
Accept: [application/json]
Accept-Encoding: ['gzip, deflate']
CommandName: [iot hub create]
Connection: [keep-alive]
Content-Length: ['214']
Content-Type: [application/json; charset=utf-8]
User-Agent: [python/3.5.3 (Windows-10-10.0.14393-SP0) requests/2.18.4 msrest/0.4.18
msrest_azure/0.4.16 iothubclient/0.4.0 Azure-SDK-For-Python AZURECLI/2.0.21]
accept-language: [en-US]
method: PUT
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000002/providers/Microsoft.Devices/IotHubs/iot-hub-for-cert-test000003?api-version=2017-07-01
response:
body: {string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000002/providers/Microsoft.Devices/IotHubs/iot-hub-for-cert-test000003","name":"iot-hub-for-cert-test000003","type":"Microsoft.Devices/IotHubs","location":"westus","tags":{},"subscriptionid":"377c3343-75bb-4244-98a3-0fb84a830c4b","resourcegroup":"clitest.rg000002","properties":{"state":"Activating","provisioningState":"Accepted","enableFileUploadNotifications":false,"cloudToDevice":{"maxDeliveryCount":10,"defaultTtlAsIso8601":"PT1H","feedback":{"lockDurationAsIso8601":"PT1M","ttlAsIso8601":"PT1H","maxDeliveryCount":10}},"features":"None"},"sku":{"name":"S1","tier":"Standard","capacity":1}}'}
headers:
azure-asyncoperation: ['https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000002/providers/Microsoft.Devices/IotHubs/iot-hub-for-cert-test000003/operationResults/ODg1NDVhNDAtMWZmZC00MGU5LWI5MWItM2IwYWEwZTJlM2Nk?api-version=2017-07-01&asyncinfo']
cache-control: [no-cache]
content-length: ['840']
content-type: [application/json; charset=utf-8]
date: ['Mon, 06 Nov 2017 19:47:28 GMT']
expires: ['-1']
pragma: [no-cache]
server: [Microsoft-HTTPAPI/2.0]
strict-transport-security: [max-age=31536000; includeSubDomains]
x-ms-ratelimit-remaining-subscription-resource-requests: ['4998']
status: {code: 201, message: Created}
- request:
body: null
headers:
Accept: [application/json]
Accept-Encoding: ['gzip, deflate']
CommandName: [iot hub create]
Connection: [keep-alive]
Content-Type: [application/json; charset=utf-8]
User-Agent: [python/3.5.3 (Windows-10-10.0.14393-SP0) requests/2.18.4 msrest/0.4.18
msrest_azure/0.4.16 iothubclient/0.4.0 Azure-SDK-For-Python AZURECLI/2.0.21]
accept-language: [en-US]
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000002/providers/Microsoft.Devices/IotHubs/iot-hub-for-cert-test000003/operationResults/ODg1NDVhNDAtMWZmZC00MGU5LWI5MWItM2IwYWEwZTJlM2Nk?api-version=2017-07-01&asyncinfo
response:
body: {string: '{"status":"Running"}'}
headers:
cache-control: [no-cache]
content-length: ['20']
content-type: [application/json; charset=utf-8]
date: ['Mon, 06 Nov 2017 19:47:58 GMT']
expires: ['-1']
pragma: [no-cache]
server: [Microsoft-HTTPAPI/2.0]
strict-transport-security: [max-age=31536000; includeSubDomains]
transfer-encoding: [chunked]
vary: [Accept-Encoding]
status: {code: 200, message: OK}
- request:
body: null
headers:
Accept: [application/json]
Accept-Encoding: ['gzip, deflate']
CommandName: [iot hub create]
Connection: [keep-alive]
Content-Type: [application/json; charset=utf-8]
User-Agent: [python/3.5.3 (Windows-10-10.0.14393-SP0) requests/2.18.4 msrest/0.4.18
msrest_azure/0.4.16 iothubclient/0.4.0 Azure-SDK-For-Python AZURECLI/2.0.21]
accept-language: [en-US]
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000002/providers/Microsoft.Devices/IotHubs/iot-hub-for-cert-test000003/operationResults/ODg1NDVhNDAtMWZmZC00MGU5LWI5MWItM2IwYWEwZTJlM2Nk?api-version=2017-07-01&asyncinfo
response:
body: {string: '{"status":"Running"}'}
headers:
cache-control: [no-cache]
content-length: ['20']
content-type: [application/json; charset=utf-8]
date: ['Mon, 06 Nov 2017 19:48:29 GMT']
expires: ['-1']
pragma: [no-cache]
server: [Microsoft-HTTPAPI/2.0]
strict-transport-security: [max-age=31536000; includeSubDomains]
transfer-encoding: [chunked]
vary: [Accept-Encoding]
status: {code: 200, message: OK}
- request:
body: null
headers:
Accept: [application/json]
Accept-Encoding: ['gzip, deflate']
CommandName: [iot hub create]
Connection: [keep-alive]
Content-Type: [application/json; charset=utf-8]
User-Agent: [python/3.5.3 (Windows-10-10.0.14393-SP0) requests/2.18.4 msrest/0.4.18
msrest_azure/0.4.16 iothubclient/0.4.0 Azure-SDK-For-Python AZURECLI/2.0.21]
accept-language: [en-US]
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000002/providers/Microsoft.Devices/IotHubs/iot-hub-for-cert-test000003/operationResults/ODg1NDVhNDAtMWZmZC00MGU5LWI5MWItM2IwYWEwZTJlM2Nk?api-version=2017-07-01&asyncinfo
response:
body: {string: '{"status":"Running"}'}
headers:
cache-control: [no-cache]
content-length: ['20']
content-type: [application/json; charset=utf-8]
date: ['Mon, 06 Nov 2017 19:49:03 GMT']
expires: ['-1']
pragma: [no-cache]
server: [Microsoft-HTTPAPI/2.0]
strict-transport-security: [max-age=31536000; includeSubDomains]
transfer-encoding: [chunked]
vary: [Accept-Encoding]
status: {code: 200, message: OK}
- request:
body: null
headers:
Accept: [application/json]
Accept-Encoding: ['gzip, deflate']
CommandName: [iot hub create]
Connection: [keep-alive]
Content-Type: [application/json; charset=utf-8]
User-Agent: [python/3.5.3 (Windows-10-10.0.14393-SP0) requests/2.18.4 msrest/0.4.18
msrest_azure/0.4.16 iothubclient/0.4.0 Azure-SDK-For-Python AZURECLI/2.0.21]
accept-language: [en-US]
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000002/providers/Microsoft.Devices/IotHubs/iot-hub-for-cert-test000003/operationResults/ODg1NDVhNDAtMWZmZC00MGU5LWI5MWItM2IwYWEwZTJlM2Nk?api-version=2017-07-01&asyncinfo
response:
body: {string: '{"status":"Running"}'}
headers:
cache-control: [no-cache]
content-length: ['20']
content-type: [application/json; charset=utf-8]
date: ['Mon, 06 Nov 2017 19:49:33 GMT']
expires: ['-1']
pragma: [no-cache]
server: [Microsoft-HTTPAPI/2.0]
strict-transport-security: [max-age=31536000; includeSubDomains]
transfer-encoding: [chunked]
vary: [Accept-Encoding]
status: {code: 200, message: OK}
- request:
body: null
headers:
Accept: [application/json]
Accept-Encoding: ['gzip, deflate']
CommandName: [iot hub create]
Connection: [keep-alive]
Content-Type: [application/json; charset=utf-8]
User-Agent: [python/3.5.3 (Windows-10-10.0.14393-SP0) requests/2.18.4 msrest/0.4.18
msrest_azure/0.4.16 iothubclient/0.4.0 Azure-SDK-For-Python AZURECLI/2.0.21]
accept-language: [en-US]
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000002/providers/Microsoft.Devices/IotHubs/iot-hub-for-cert-test000003/operationResults/ODg1NDVhNDAtMWZmZC00MGU5LWI5MWItM2IwYWEwZTJlM2Nk?api-version=2017-07-01&asyncinfo
response:
body: {string: '{"status":"Running"}'}
headers:
cache-control: [no-cache]
content-length: ['20']
content-type: [application/json; charset=utf-8]
date: ['Mon, 06 Nov 2017 19:50:03 GMT']
expires: ['-1']
pragma: [no-cache]
server: [Microsoft-HTTPAPI/2.0]
strict-transport-security: [max-age=31536000; includeSubDomains]
transfer-encoding: [chunked]
vary: [Accept-Encoding]
status: {code: 200, message: OK}
- request:
body: null
headers:
Accept: [application/json]
Accept-Encoding: ['gzip, deflate']
CommandName: [iot hub create]
Connection: [keep-alive]
Content-Type: [application/json; charset=utf-8]
User-Agent: [python/3.5.3 (Windows-10-10.0.14393-SP0) requests/2.18.4 msrest/0.4.18
msrest_azure/0.4.16 iothubclient/0.4.0 Azure-SDK-For-Python AZURECLI/2.0.21]
accept-language: [en-US]
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000002/providers/Microsoft.Devices/IotHubs/iot-hub-for-cert-test000003/operationResults/ODg1NDVhNDAtMWZmZC00MGU5LWI5MWItM2IwYWEwZTJlM2Nk?api-version=2017-07-01&asyncinfo
response:
body: {string: '{"status":"Running"}'}
headers:
cache-control: [no-cache]
content-length: ['20']
content-type: [application/json; charset=utf-8]
date: ['Mon, 06 Nov 2017 19:50:34 GMT']
expires: ['-1']
pragma: [no-cache]
server: [Microsoft-HTTPAPI/2.0]
strict-transport-security: [max-age=31536000; includeSubDomains]
transfer-encoding: [chunked]
vary: [Accept-Encoding]
status: {code: 200, message: OK}
- request:
body: null
headers:
Accept: [application/json]
Accept-Encoding: ['gzip, deflate']
CommandName: [iot hub create]
Connection: [keep-alive]
Content-Type: [application/json; charset=utf-8]
User-Agent: [python/3.5.3 (Windows-10-10.0.14393-SP0) requests/2.18.4 msrest/0.4.18
msrest_azure/0.4.16 iothubclient/0.4.0 Azure-SDK-For-Python AZURECLI/2.0.21]
accept-language: [en-US]
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000002/providers/Microsoft.Devices/IotHubs/iot-hub-for-cert-test000003/operationResults/ODg1NDVhNDAtMWZmZC00MGU5LWI5MWItM2IwYWEwZTJlM2Nk?api-version=2017-07-01&asyncinfo
response:
body: {string: '{"status":"Succeeded"}'}
headers:
cache-control: [no-cache]
content-length: ['22']
content-type: [application/json; charset=utf-8]
date: ['Mon, 06 Nov 2017 19:51:05 GMT']
expires: ['-1']
pragma: [no-cache]
server: [Microsoft-HTTPAPI/2.0]
strict-transport-security: [max-age=31536000; includeSubDomains]
transfer-encoding: [chunked]
vary: [Accept-Encoding]
status: {code: 200, message: OK}
- request:
body: null
headers:
Accept: [application/json]
Accept-Encoding: ['gzip, deflate']
CommandName: [iot hub create]
Connection: [keep-alive]
Content-Type: [application/json; charset=utf-8]
User-Agent: [python/3.5.3 (Windows-10-10.0.14393-SP0) requests/2.18.4 msrest/0.4.18
msrest_azure/0.4.16 iothubclient/0.4.0 Azure-SDK-For-Python AZURECLI/2.0.21]
accept-language: [en-US]
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000002/providers/Microsoft.Devices/IotHubs/iot-hub-for-cert-test000003?api-version=2017-07-01
response:
body: {string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000002/providers/Microsoft.Devices/IotHubs/iot-hub-for-cert-test000003","name":"iot-hub-for-cert-test000003","type":"Microsoft.Devices/IotHubs","location":"westus","tags":{},"subscriptionid":"377c3343-75bb-4244-98a3-0fb84a830c4b","resourcegroup":"clitest.rg000002","etag":"AAAAAAE/R30=","properties":{"operationsMonitoringProperties":{"events":{"None":"None","Connections":"None","DeviceTelemetry":"None","C2DCommands":"None","DeviceIdentityOperations":"None","FileUploadOperations":"None","Routes":"None"}},"state":"Active","provisioningState":"Succeeded","ipFilterRules":[],"hostName":"iot-hub-for-cert-test000003.azure-devices.net","eventHubEndpoints":{"events":{"retentionTimeInDays":1,"partitionCount":4,"partitionIds":["0","1","2","3"],"path":"iot-hub-for-cert-testh4ru","endpoint":"sb://iothub-ns-iot-hub-fo-255400-caaa04e2c4.servicebus.windows.net/"},"operationsMonitoringEvents":{"retentionTimeInDays":1,"partitionCount":4,"partitionIds":["0","1","2","3"],"path":"iot-hub-for-cert-testh4ru-operationmonitoring","endpoint":"sb://iothub-ns-iot-hub-fo-255400-caaa04e2c4.servicebus.windows.net/"}},"routing":{"endpoints":{"serviceBusQueues":[],"serviceBusTopics":[],"eventHubs":[],"storageContainers":[]},"routes":[],"fallbackRoute":{"name":"$fallback","source":"DeviceMessages","condition":"true","endpointNames":["events"],"isEnabled":true}},"storageEndpoints":{"$default":{"sasTtlAsIso8601":"PT1H","connectionString":"","containerName":""}},"messagingEndpoints":{"fileNotifications":{"lockDurationAsIso8601":"PT1M","ttlAsIso8601":"PT1H","maxDeliveryCount":10}},"enableFileUploadNotifications":false,"cloudToDevice":{"maxDeliveryCount":10,"defaultTtlAsIso8601":"PT1H","feedback":{"lockDurationAsIso8601":"PT1M","ttlAsIso8601":"PT1H","maxDeliveryCount":10}},"features":"None"},"sku":{"name":"S1","tier":"Standard","capacity":1}}'}
headers:
cache-control: [no-cache]
content-length: ['2099']
content-type: [application/json; charset=utf-8]
date: ['Mon, 06 Nov 2017 19:51:05 GMT']
expires: ['-1']
pragma: [no-cache]
server: [Microsoft-HTTPAPI/2.0]
strict-transport-security: [max-age=31536000; includeSubDomains]
transfer-encoding: [chunked]
vary: [Accept-Encoding]
status: {code: 200, message: OK}
- request:
body: null
headers:
Accept: [application/json]
Accept-Encoding: ['gzip, deflate']
CommandName: [iot hub certificate create]
Connection: [keep-alive]
Content-Type: [application/json; charset=utf-8]
User-Agent: [python/3.5.3 (Windows-10-10.0.14393-SP0) requests/2.18.4 msrest/0.4.18
msrest_azure/0.4.16 iothubclient/0.4.0 Azure-SDK-For-Python AZURECLI/2.0.21]
accept-language: [en-US]
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000002/providers/Microsoft.Devices/IotHubs/iot-hub-for-cert-test000003/certificates?api-version=2017-07-01
response:
body: {string: '{"value":[]}'}
headers:
cache-control: [no-cache]
content-length: ['12']
content-type: [application/json; charset=utf-8]
date: ['Mon, 06 Nov 2017 19:51:07 GMT']
expires: ['-1']
pragma: [no-cache]
server: [Microsoft-HTTPAPI/2.0]
strict-transport-security: [max-age=31536000; includeSubDomains]
transfer-encoding: [chunked]
vary: [Accept-Encoding]
status: {code: 200, message: OK}
- request:
body: '{"certificate": "-----BEGIN CERTIFICATE-----\r\nMIIDHTCCAgWgAwIBAgIIUJQOLVy1PG4wDQYJKoZIhvcNAQELBQAwIzEhMB8GA1UE\r\nAwwYVEVTVENFUlRiYzVkNnN5d2dqemNpdGZ5MB4XDTE3MTEwNTE5NDcyMloXDTE3\r\nMTEwOTE5NDcyMlowIzEhMB8GA1UEAwwYVEVTVENFUlRiYzVkNnN5d2dqemNpdGZ5\r\nMIIBITANBgkqhkiG9w0BAQEFAAOCAQ4AMIIBCQKCAQAtGh2+z2up4mgCGgsm9Opf\r\nGAts1MbAe8f1XlS5IoOnWFSh5ufYyBljZZFgjs/xYwvXK7uYWv8MzsPrIlCc3YAd\r\nc2fIYybMWAw5qlTwNWVv6D5j5WSDtHSTxCxDMlFsBi1BUCQvoXnaz/vm9s8+GtmL\r\n4eMsSC+ODNkw+1U1UgsXlDC5/7mU0TvpQv0/2e3Cp665o9qL8sf+Pcvcj0yGisAi\r\nBT/4DBEZUyql0cCs6vC7lWDpnoq1jJFiD9Eoj1vMx77yWZoNGhsYFvRKEa1ZNhp1\r\ndkNfdRPM6WJrh41VyCl/vWoma2/IhVFLWmaLMHIxGKNqryG5LOORfDXXPmljZ2wD\r\nAgMBAAGjVjBUMBIGA1UdEwEB/wQIMAYBAf8CAQEwHQYDVR0OBBYEFNo5o+5ea0sN\r\nMlW/75VgGJCv2AcJMB8GA1UdIwQYMBaAFNo5o+5ea0sNMlW/75VgGJCv2AcJMA0G\r\nCSqGSIb3DQEBCwUAA4IBAQACvQmlkrRLhP4CU/9AhZs4dLVk72jXRdPUj6dyM3y6\r\nny8mp4rN7dbnDkILYptIpynXDCvWERxAD9gXuPBw8vlc+rzgJF5xpiakX7e/JI3Z\r\nC0H9Izek0rgSDcbLWupP4NAb2VJH7FDFY/jIXfuNCEzgKqMHNdmaSlGdC3exItr0\r\nyVSrHD8XpoaPm/VSMPBX/u97uPx5AVfgDKe4Ph/ZCVQggU2fkDiB4Dj0s5uWvLc8\r\nTggjjNTzwLK/7vYY/cVM6jqC1pYrLK93p4Gf1O7KE+4SnOk3QbR77IicREjlUmeq\r\nwMtBVLlSN+tBXLtLfnlYCI8GXjOJATcLh+kHaMathlOW\r\n-----END
CERTIFICATE-----\r\n"}'
headers:
Accept: [application/json]
Accept-Encoding: ['gzip, deflate']
CommandName: [iot hub certificate create]
Connection: [keep-alive]
Content-Length: ['1215']
Content-Type: [application/json; charset=utf-8]
User-Agent: [python/3.5.3 (Windows-10-10.0.14393-SP0) requests/2.18.4 msrest/0.4.18
msrest_azure/0.4.16 iothubclient/0.4.0 Azure-SDK-For-Python AZURECLI/2.0.21]
accept-language: [en-US]
method: PUT
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000002/providers/Microsoft.Devices/IotHubs/iot-hub-for-cert-test000003/certificates/certificate-000004?api-version=2017-07-01
response:
body: {string: '{"properties":{"subject":"CN=TESTCERT000001","expiry":"Thu, 09
Nov 2017 19:47:22 GMT","thumbprint":"E41723011FB219976860998BB2F22D7332B9C708","isVerified":false,"created":"Mon,
06 Nov 2017 19:51:06 GMT","updated":"Mon, 06 Nov 2017 19:51:06 GMT"},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000002/providers/Microsoft.Devices/IotHubs/iot-hub-for-cert-test000003/certificates/certificate-000004","name":"certificate-000004","type":"Microsoft.Devices/IotHubs/Certificates","etag":"AAAAAAE/R4g="}'}
headers:
cache-control: [no-cache]
content-length: ['681']
content-type: [application/json; charset=utf-8]
date: ['Mon, 06 Nov 2017 19:51:07 GMT']
expires: ['-1']
pragma: [no-cache]
server: [Microsoft-HTTPAPI/2.0]
strict-transport-security: [max-age=31536000; includeSubDomains]
transfer-encoding: [chunked]
vary: [Accept-Encoding]
x-ms-ratelimit-remaining-subscription-writes: ['1199']
status: {code: 200, message: OK}
- request:
body: null
headers:
Accept: [application/json]
Accept-Encoding: ['gzip, deflate']
CommandName: [iot hub certificate list]
Connection: [keep-alive]
Content-Type: [application/json; charset=utf-8]
User-Agent: [python/3.5.3 (Windows-10-10.0.14393-SP0) requests/2.18.4 msrest/0.4.18
msrest_azure/0.4.16 iothubclient/0.4.0 Azure-SDK-For-Python AZURECLI/2.0.21]
accept-language: [en-US]
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000002/providers/Microsoft.Devices/IotHubs/iot-hub-for-cert-test000003/certificates?api-version=2017-07-01
response:
body: {string: '{"value":[{"properties":{"subject":"CN=TESTCERT000001","expiry":"Thu,
09 Nov 2017 19:47:22 GMT","thumbprint":"E41723011FB219976860998BB2F22D7332B9C708","isVerified":false,"created":"Mon,
06 Nov 2017 19:51:06 GMT","updated":"Mon, 06 Nov 2017 19:51:06 GMT"},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000002/providers/Microsoft.Devices/IotHubs/iot-hub-for-cert-test000003/certificates/certificate-000004","name":"certificate-000004","type":"Microsoft.Devices/IotHubs/Certificates","etag":"AAAAAAE/R4g="}]}'}
headers:
cache-control: [no-cache]
content-length: ['693']
content-type: [application/json; charset=utf-8]
date: ['Mon, 06 Nov 2017 19:51:08 GMT']
expires: ['-1']
pragma: [no-cache]
server: [Microsoft-HTTPAPI/2.0]
strict-transport-security: [max-age=31536000; includeSubDomains]
transfer-encoding: [chunked]
vary: [Accept-Encoding]
status: {code: 200, message: OK}
- request:
body: null
headers:
Accept: [application/json]
Accept-Encoding: ['gzip, deflate']
CommandName: [iot hub certificate show]
Connection: [keep-alive]
Content-Type: [application/json; charset=utf-8]
User-Agent: [python/3.5.3 (Windows-10-10.0.14393-SP0) requests/2.18.4 msrest/0.4.18
msrest_azure/0.4.16 iothubclient/0.4.0 Azure-SDK-For-Python AZURECLI/2.0.21]
accept-language: [en-US]
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000002/providers/Microsoft.Devices/IotHubs/iot-hub-for-cert-test000003/certificates/certificate-000004?api-version=2017-07-01
response:
body: {string: '{"properties":{"subject":"CN=TESTCERT000001","expiry":"Thu, 09
Nov 2017 19:47:22 GMT","thumbprint":"E41723011FB219976860998BB2F22D7332B9C708","isVerified":false,"created":"Mon,
06 Nov 2017 19:51:06 GMT","updated":"Mon, 06 Nov 2017 19:51:06 GMT"},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000002/providers/Microsoft.Devices/IotHubs/iot-hub-for-cert-test000003/certificates/certificate-000004","name":"certificate-000004","type":"Microsoft.Devices/IotHubs/Certificates","etag":"AAAAAAE/R4g="}'}
headers:
cache-control: [no-cache]
content-length: ['681']
content-type: [application/json; charset=utf-8]
date: ['Mon, 06 Nov 2017 19:51:08 GMT']
expires: ['-1']
pragma: [no-cache]
server: [Microsoft-HTTPAPI/2.0]
strict-transport-security: [max-age=31536000; includeSubDomains]
transfer-encoding: [chunked]
vary: [Accept-Encoding]
status: {code: 200, message: OK}
- request:
body: null
headers:
Accept: [application/json]
Accept-Encoding: ['gzip, deflate']
CommandName: [iot hub certificate generate-verification-code]
Connection: [keep-alive]
Content-Length: ['0']
Content-Type: [application/json; charset=utf-8]
If-Match: [AAAAAAE/R4g=]
User-Agent: [python/3.5.3 (Windows-10-10.0.14393-SP0) requests/2.18.4 msrest/0.4.18
msrest_azure/0.4.16 iothubclient/0.4.0 Azure-SDK-For-Python AZURECLI/2.0.21]
accept-language: [en-US]
method: POST
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000002/providers/Microsoft.Devices/IotHubs/iot-hub-for-cert-test000003/certificates/certificate-000004/generateVerificationCode?api-version=2017-07-01
response:
body: {string: '{"properties":{"verificationCode":"07E479750BE69E1EDB8B3D200BA30DA85A23FA7473F3711F","subject":"CN=TESTCERT000001","expiry":"Thu,
09 Nov 2017 19:47:22 GMT","thumbprint":"E41723011FB219976860998BB2F22D7332B9C708","isVerified":false,"created":"Mon,
06 Nov 2017 19:51:06 GMT","updated":"Mon, 06 Nov 2017 19:51:08 GMT"},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000002/providers/Microsoft.Devices/IotHubs/iot-hub-for-cert-test000003/certificates/certificate-000004","name":"certificate-000004","type":"Microsoft.Devices/IotHubs/Certificates","etag":"AAAAAAE/R4s="}'}
headers:
cache-control: [no-cache]
content-length: ['751']
content-type: [application/json; charset=utf-8]
date: ['Mon, 06 Nov 2017 19:51:09 GMT']
expires: ['-1']
pragma: [no-cache]
server: [Microsoft-HTTPAPI/2.0]
strict-transport-security: [max-age=31536000; includeSubDomains]
transfer-encoding: [chunked]
vary: [Accept-Encoding]
x-ms-ratelimit-remaining-subscription-writes: ['1199']
status: {code: 200, message: OK}
- request:
body: '{"certificate": "-----BEGIN CERTIFICATE-----\r\nMIIDAjCCAeqgAwIBAgIIUwpTnYyhlTQwDQYJKoZIhvcNAQELBQAwIzEhMB8GA1UE\r\nAwwYVEVTVENFUlRiYzVkNnN5d2dqemNpdGZ5MB4XDTE3MTEwNjE5NTExMFoXDTE3\r\nMTEwOTE5NTExMFowOzE5MDcGA1UEAwwwMDdFNDc5NzUwQkU2OUUxRURCOEIzRDIw\r\nMEJBMzBEQTg1QTIzRkE3NDczRjM3MTFGMIIBITANBgkqhkiG9w0BAQEFAAOCAQ4A\r\nMIIBCQKCAQAnKGaUqICF3NR4EEcwmJr7gxP9LKKudIN9PYXaJtAG6oL9z0iGpZe8\r\nyYW+h9MyfDV2jK4erdaI7rTYy8tKwTSQ4re9+Fc7AGnSZkmH77axZqjcbajjL7dG\r\nFBIb2To9uf+lcOmsM11M669csBa4LT+3VkXsakB0SGKXFwAKKp0ZbJZw7VFxSEGA\r\ndZScSsBdtmXGq95H0sHx6xv2Uu4PVQ5pXldQO9QJWjMM2DVARvI79cXwBtVZPoW2\r\nyfBN0Dl99S2X61Z9pVLaffY1XMoLM6jgJY1OEjTXJrNx8yCw1eKNJb29NvIxFryV\r\nQQ4+zXkEbT5IzANydZYlwxUcFK4vck+bAgMBAAGjIzAhMB8GA1UdIwQYMBaAFNo5\r\no+5ea0sNMlW/75VgGJCv2AcJMA0GCSqGSIb3DQEBCwUAA4IBAQAa8o8w0zF+sb9c\r\nNnQ+I2JsaSFmcKKSDZYbLxw9KFzjkPZjpTD9mzSgOsYL0+iDwXtYyzkp/yqQkPCS\r\nOCxQfsstd7O1bMW4dyZy2DMDmZEAI2Keb1WEavSDrsiuqY1FxUGPSnx1GpsoPlNu\r\nG3whar65w+oSqH0wXopspEau05g3KejnxjKqRQQlPWObAMAiy8c2fJHTI/ul7iDQ\r\nibueQHemccNzS3PWUSaNGMxqi1LOyREDC9BzzrsQpriAp0aAJakk2yfqk6hsgpQ+\r\npLRCFgdGHipeIRzsChzOcCuU1D1WpXH3RLP9x9z3An/3ScYhZObujDmBIhzOMrdo\r\nkb+RY7Gn\r\n-----END
CERTIFICATE-----\r\n"}'
headers:
Accept: [application/json]
Accept-Encoding: ['gzip, deflate']
CommandName: [iot hub certificate verify]
Connection: [keep-alive]
Content-Length: ['1179']
Content-Type: [application/json; charset=utf-8]
If-Match: [AAAAAAE/R4s=]
User-Agent: [python/3.5.3 (Windows-10-10.0.14393-SP0) requests/2.18.4 msrest/0.4.18
msrest_azure/0.4.16 iothubclient/0.4.0 Azure-SDK-For-Python AZURECLI/2.0.21]
accept-language: [en-US]
method: POST
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000002/providers/Microsoft.Devices/IotHubs/iot-hub-for-cert-test000003/certificates/certificate-000004/verify?api-version=2017-07-01
response:
body: {string: '{"properties":{"subject":"CN=TESTCERT000001","expiry":"Thu, 09
Nov 2017 19:47:22 GMT","thumbprint":"E41723011FB219976860998BB2F22D7332B9C708","isVerified":true,"created":"Mon,
06 Nov 2017 19:51:06 GMT","updated":"Mon, 06 Nov 2017 19:51:09 GMT"},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000002/providers/Microsoft.Devices/IotHubs/iot-hub-for-cert-test000003/certificates/certificate-000004","name":"certificate-000004","type":"Microsoft.Devices/IotHubs/Certificates","etag":"AAAAAAE/R44="}'}
headers:
cache-control: [no-cache]
content-length: ['680']
content-type: [application/json; charset=utf-8]
date: ['Mon, 06 Nov 2017 19:51:11 GMT']
expires: ['-1']
pragma: [no-cache]
server: [Microsoft-HTTPAPI/2.0]
strict-transport-security: [max-age=31536000; includeSubDomains]
transfer-encoding: [chunked]
vary: [Accept-Encoding]
x-ms-ratelimit-remaining-subscription-writes: ['1199']
status: {code: 200, message: OK}
- request:
body: null
headers:
Accept: [application/json]
Accept-Encoding: ['gzip, deflate']
CommandName: [iot hub certificate delete]
Connection: [keep-alive]
Content-Length: ['0']
Content-Type: [application/json; charset=utf-8]
If-Match: [AAAAAAE/R44=]
User-Agent: [python/3.5.3 (Windows-10-10.0.14393-SP0) requests/2.18.4 msrest/0.4.18
msrest_azure/0.4.16 iothubclient/0.4.0 Azure-SDK-For-Python AZURECLI/2.0.21]
accept-language: [en-US]
method: DELETE
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000002/providers/Microsoft.Devices/IotHubs/iot-hub-for-cert-test000003/certificates/certificate-000004?api-version=2017-07-01
response:
body: {string: ''}
headers:
cache-control: [no-cache]
content-length: ['0']
date: ['Mon, 06 Nov 2017 19:51:12 GMT']
expires: ['-1']
pragma: [no-cache]
server: [Microsoft-HTTPAPI/2.0]
strict-transport-security: [max-age=31536000; includeSubDomains]
x-ms-ratelimit-remaining-subscription-writes: ['1199']
status: {code: 200, message: OK}
- request:
body: null
headers:
Accept: [application/json]
Accept-Encoding: ['gzip, deflate']
CommandName: [group delete]
Connection: [keep-alive]
Content-Length: ['0']
Content-Type: [application/json; charset=utf-8]
User-Agent: [python/3.5.3 (Windows-10-10.0.14393-SP0) requests/2.18.4 msrest/0.4.18
msrest_azure/0.4.16 resourcemanagementclient/1.2.1 Azure-SDK-For-Python
AZURECLI/2.0.21]
accept-language: [en-US]
method: DELETE
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clitest.rg000002?api-version=2017-05-10
response:
body: {string: ''}
headers:
cache-control: [no-cache]
content-length: ['0']
date: ['Mon, 06 Nov 2017 19:51:15 GMT']
expires: ['-1']
location: ['https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/operationresults/eyJqb2JJZCI6IlJFU09VUkNFR1JPVVBERUxFVElPTkpPQi1DTElURVNUOjJFUkdaR1pKTFFSSTNVTUlENlAyNldHSk5JM1NXR0lHVUlMWjRRSHw1MjJGRENENjk3RkQyRDM3LVdFU1RVUyIsImpvYkxvY2F0aW9uIjoid2VzdHVzIn0?api-version=2017-05-10']
pragma: [no-cache]
strict-transport-security: [max-age=31536000; includeSubDomains]
x-ms-ratelimit-remaining-subscription-writes: ['1199']
status: {code: 202, message: Accepted}
version: 1

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -0,0 +1,79 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# pylint: disable=line-too-long,too-many-statements
from azure.cli.testsdk import ResourceGroupPreparer, ScenarioTest, JMESPathCheck
from OpenSSL import crypto, SSL
from os.path import exists, join
from ._test_utils import _create_test_cert, _delete_test_cert, _create_verification_cert
import random
VERIFICATION_FILE = "verify.cer"
CERT_FILE = "testcert.cer"
KEY_FILE = "testkey.pvk"
MAX_INT = 9223372036854775807
class IotHubCertificateTest(ScenarioTest):
def __init__(self, test_method):
super(IotHubCertificateTest, self).__init__('test_certificate_lifecycle')
self.hub_name = 'iot-hub-for-cert-test'
_create_test_cert(CERT_FILE, KEY_FILE, self.create_random_name(prefix='TESTCERT', length=24), 3, random.randint(0, MAX_INT))
def __del__(self):
_delete_test_cert(CERT_FILE, KEY_FILE, VERIFICATION_FILE)
@ResourceGroupPreparer()
def test_certificate_lifecycle(self, resource_group):
hub = self._create_test_hub(resource_group)
cert_name = self.create_random_name(prefix='certificate-', length=48)
# Create certificate
self.cmd('iot hub certificate create --hub-name {0} -g {1} -n {2} -p {3}'.format(hub, resource_group, cert_name, CERT_FILE),
checks=[JMESPathCheck('name', cert_name),
JMESPathCheck('properties.isVerified', False)])
# List certificates
output = self.cmd('iot hub certificate list --hub-name {0} -g {1}'.format(hub, resource_group),
checks=[JMESPathCheck('length(@)', 1),
JMESPathCheck('value[0].name', cert_name),
JMESPathCheck('value[0].properties.isVerified', False)]).get_output_in_json()
assert len(output) == 1
# Get certificate
etag = self.cmd('iot hub certificate show --hub-name {0} -g {1} -n {2}'.format(hub, resource_group, cert_name),
checks=[JMESPathCheck('name', cert_name),
JMESPathCheck('properties.isVerified', False)]).get_output_in_json()['etag']
# Generate verification code
output = self.cmd('iot hub certificate generate-verification-code --hub-name {0} -g {1} -n {2} --etag {3}'.format(hub, resource_group, cert_name, etag),
checks=[JMESPathCheck('name', cert_name)]).get_output_in_json()
assert 'verificationCode' in output['properties']
verification_code = output['properties']['verificationCode']
etag = output['etag']
_create_verification_cert(CERT_FILE, KEY_FILE, VERIFICATION_FILE, verification_code, 3, random.randint(0, MAX_INT))
# Verify certificate
etag = self.cmd('iot hub certificate verify --hub-name {0} -g {1} -n {2} -p {3} --etag {4}'.format(hub, resource_group, cert_name, VERIFICATION_FILE, etag),
checks=[JMESPathCheck('name', cert_name),
JMESPathCheck('properties.isVerified', True)]).get_output_in_json()['etag']
# Delete certificate
self.cmd('iot hub certificate delete --hub-name {0} -g {1} -n {2} --etag {3}'.format(hub, resource_group, cert_name, etag))
def _create_test_hub(self, resource_group):
hub = self.create_random_name(prefix='iot-hub-for-cert-test', length=48)
self.cmd('iot hub create -n {0} -g {1} --sku S1'.format(hub, resource_group),
checks=[JMESPathCheck('resourceGroup', resource_group),
JMESPathCheck('name', hub),
JMESPathCheck('sku.name', 'S1')])
return hub

Просмотреть файл

@ -32,7 +32,7 @@ CLASSIFIERS = [
]
DEPENDENCIES = [
'azure-mgmt-iothub==0.2.2',
'azure-mgmt-iothub==0.4.0',
'pyOpenSSL',
'azure-cli-core',
]