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

Iotc command versioning #340

Merged
merged 21 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Release History
0.10.12
+++++++++++++++

**IoT Central updates**

* Public API GA update - add support for preview and 1.0 routes
* Addition of the optional '--av' argument to specify the version of API for the requested operation.
**IoT Hub updates**

* Removed deprecated edge offline commands and artifacts.
Expand Down
2 changes: 1 addition & 1 deletion azext_iot/central/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def _load_central_devices_help():
az iot central device create
--app-id {appid}
--device-id {deviceid}
--instance-of {devicetemplateid}
--template {devicetemplateid}
--simulated
"""

Expand Down
55 changes: 43 additions & 12 deletions azext_iot/central/commands_api_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@


from azext_iot.constants import CENTRAL_ENDPOINT
from azext_iot.central.providers import CentralApiTokenProvider
from azext_iot.central.models.enum import Role
from azext_iot.central.providers.preview import CentralApiTokenProviderPreview
from azext_iot.central.providers.v1 import CentralApiTokenProviderV1
from azext_iot.central.models.enum import Role, ApiVersion


def add_api_token(
Expand All @@ -18,36 +19,66 @@ def add_api_token(
role: str,
token=None,
central_dns_suffix=CENTRAL_ENDPOINT,
api_version=ApiVersion.v1.value,
):
provider = CentralApiTokenProvider(cmd=cmd, app_id=app_id, token=token)
if api_version == ApiVersion.preview.value:
provider = CentralApiTokenProviderPreview(cmd=cmd, app_id=app_id, token=token)
else:
provider = CentralApiTokenProviderV1(cmd=cmd, app_id=app_id, token=token)

return provider.add_api_token(
token_id=token_id, role=Role[role], central_dns_suffix=central_dns_suffix,
)


def list_api_tokens(
cmd, app_id: str, token=None, central_dns_suffix=CENTRAL_ENDPOINT,
cmd,
app_id: str,
token=None,
central_dns_suffix=CENTRAL_ENDPOINT,
api_version=ApiVersion.v1.value,
):
provider = CentralApiTokenProvider(cmd=cmd, app_id=app_id, token=token)

return provider.get_api_token_list(central_dns_suffix=central_dns_suffix,)
if api_version == ApiVersion.preview.value:
provider = CentralApiTokenProviderPreview(cmd=cmd, app_id=app_id, token=token)
else:
provider = CentralApiTokenProviderV1(cmd=cmd, app_id=app_id, token=token)

return provider.get_api_token_list(central_dns_suffix=central_dns_suffix)


def get_api_token(
cmd, app_id: str, token_id: str, token=None, central_dns_suffix=CENTRAL_ENDPOINT,
cmd,
app_id: str,
token_id: str,
token=None,
central_dns_suffix=CENTRAL_ENDPOINT,
api_version=ApiVersion.v1.value,
):
provider = CentralApiTokenProvider(cmd=cmd, app_id=app_id, token=token)

if api_version == ApiVersion.preview.value:
provider = CentralApiTokenProviderPreview(cmd=cmd, app_id=app_id, token=token)
else:
provider = CentralApiTokenProviderV1(cmd=cmd, app_id=app_id, token=token)

return provider.get_api_token(
token_id=token_id, central_dns_suffix=central_dns_suffix
token_id=token_id, central_dns_suffix=central_dns_suffix,
)


def delete_api_token(
cmd, app_id: str, token_id: str, token=None, central_dns_suffix=CENTRAL_ENDPOINT,
cmd,
app_id: str,
token_id: str,
token=None,
central_dns_suffix=CENTRAL_ENDPOINT,
api_version=ApiVersion.v1.value,
):
provider = CentralApiTokenProvider(cmd=cmd, app_id=app_id, token=token)
if api_version == ApiVersion.preview.value:
provider = CentralApiTokenProviderPreview(cmd=cmd, app_id=app_id, token=token)
else:
provider = CentralApiTokenProviderV1(cmd=cmd, app_id=app_id, token=token)

return provider.delete_api_token(
token_id=token_id, central_dns_suffix=central_dns_suffix
token_id=token_id, central_dns_suffix=central_dns_suffix,
)
105 changes: 74 additions & 31 deletions azext_iot/central/commands_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,39 @@

from azext_iot.common import utility
from azext_iot.constants import CENTRAL_ENDPOINT
from azext_iot.central.providers import CentralDeviceProvider
from azext_iot.central.providers.preview import CentralDeviceProviderPreview
from azext_iot.central.providers.v1 import CentralDeviceProviderV1
from azext_iot.central.models.enum import ApiVersion


def list_devices(cmd, app_id: str, token=None, central_dns_suffix=CENTRAL_ENDPOINT):
provider = CentralDeviceProvider(cmd=cmd, app_id=app_id, token=token)
def list_devices(
cmd,
app_id: str,
token=None,
central_dns_suffix=CENTRAL_ENDPOINT,
api_version=ApiVersion.v1.value,
):
if api_version == ApiVersion.preview.value:
provider = CentralDeviceProviderPreview(cmd=cmd, app_id=app_id, token=token)
else:
provider = CentralDeviceProviderV1(cmd=cmd, app_id=app_id, token=token)

return provider.list_devices(central_dns_suffix=central_dns_suffix)


def get_device(
cmd, app_id: str, device_id: str, token=None, central_dns_suffix=CENTRAL_ENDPOINT,
cmd,
app_id: str,
device_id: str,
token=None,
central_dns_suffix=CENTRAL_ENDPOINT,
api_version=ApiVersion.v1.value,
):
provider = CentralDeviceProvider(cmd=cmd, app_id=app_id, token=token)
if api_version == ApiVersion.preview.value:
provider = CentralDeviceProviderPreview(cmd=cmd, app_id=app_id, token=token)
else:
provider = CentralDeviceProviderV1(cmd=cmd, app_id=app_id, token=token)

return provider.get_device(device_id, central_dns_suffix=central_dns_suffix)


Expand All @@ -29,38 +50,51 @@ def create_device(
app_id: str,
device_id: str,
device_name=None,
instance_of=None,
template=None,
simulated=False,
token=None,
central_dns_suffix=CENTRAL_ENDPOINT,
api_version=ApiVersion.v1.value,
):
if simulated and not instance_of:
if simulated and not template:
raise CLIError(
"Error: if you supply --simulated you must also specify --instance-of"
"Error: if you supply --simulated you must also specify --template"
)
provider = CentralDeviceProvider(cmd=cmd, app_id=app_id, token=token)

if api_version == ApiVersion.preview.value:
provider = CentralDeviceProviderPreview(cmd=cmd, app_id=app_id, token=token)
else:
provider = CentralDeviceProviderV1(cmd=cmd, app_id=app_id, token=token)

return provider.create_device(
device_id=device_id,
device_name=device_name,
instance_of=instance_of,
template=template,
simulated=simulated,
central_dns_suffix=central_dns_suffix,
)


def delete_device(
cmd, app_id: str, device_id: str, token=None, central_dns_suffix=CENTRAL_ENDPOINT,
cmd,
app_id: str,
device_id: str,
token=None,
central_dns_suffix=CENTRAL_ENDPOINT,
api_version=ApiVersion.v1.value,
):
provider = CentralDeviceProvider(cmd=cmd, app_id=app_id, token=token)
return provider.delete_device(
device_id=device_id,
central_dns_suffix=central_dns_suffix)
if api_version == ApiVersion.preview.value:
provider = CentralDeviceProviderPreview(cmd=cmd, app_id=app_id, token=token)
else:
provider = CentralDeviceProviderV1(cmd=cmd, app_id=app_id, token=token)

return provider.delete_device(device_id, central_dns_suffix=central_dns_suffix)


def registration_info(
cmd, app_id: str, device_id, token=None, central_dns_suffix=CENTRAL_ENDPOINT,
):
provider = CentralDeviceProvider(cmd=cmd, app_id=app_id, token=token,)
provider = CentralDeviceProviderV1(cmd=cmd, app_id=app_id, token=token)

return provider.get_device_registration_info(
device_id=device_id, central_dns_suffix=central_dns_suffix, device_status=None,
Expand All @@ -76,18 +110,24 @@ def run_command(
content: str,
token=None,
central_dns_suffix=CENTRAL_ENDPOINT,
api_version=ApiVersion.v1.value,
):
if not isinstance(content, str):
raise CLIError("content must be a string: {}".format(content))

payload = utility.process_json_arg(content, argument_name="content")

provider = CentralDeviceProvider(cmd=cmd, app_id=app_id, token=token)
if api_version == ApiVersion.preview.value:
provider = CentralDeviceProviderPreview(cmd=cmd, app_id=app_id, token=token)
else:
provider = CentralDeviceProviderV1(cmd=cmd, app_id=app_id, token=token)

return provider.run_component_command(
device_id=device_id,
interface_id=interface_id,
command_name=command_name,
payload=payload,
central_dns_suffix=central_dns_suffix,
)


Expand All @@ -102,25 +142,20 @@ def run_manual_failover(
if ttl_minutes and ttl_minutes < 1:
raise CLIError("TTL value should be a positive integer: {}".format(ttl_minutes))

provider = CentralDeviceProvider(cmd=cmd, app_id=app_id, token=token)
provider = CentralDeviceProviderV1(cmd=cmd, app_id=app_id, token=token)
return provider.run_manual_failover(
device_id=device_id,
ttl_minutes=ttl_minutes,
central_dns_suffix=central_dns_suffix
central_dns_suffix=central_dns_suffix,
)


def run_manual_failback(
cmd,
app_id: str,
device_id: str,
token=None,
central_dns_suffix=CENTRAL_ENDPOINT,
cmd, app_id: str, device_id: str, token=None, central_dns_suffix=CENTRAL_ENDPOINT,
):
provider = CentralDeviceProvider(cmd=cmd, app_id=app_id, token=token)
provider = CentralDeviceProviderV1(cmd=cmd, app_id=app_id, token=token)
return provider.run_manual_failback(
device_id=device_id,
central_dns_suffix=central_dns_suffix
device_id=device_id, central_dns_suffix=central_dns_suffix
)


Expand All @@ -132,17 +167,25 @@ def get_command_history(
command_name: str,
token=None,
central_dns_suffix=CENTRAL_ENDPOINT,
api_version=ApiVersion.v1.value,
):
provider = CentralDeviceProvider(cmd=cmd, app_id=app_id, token=token)
if api_version == ApiVersion.preview.value:
provider = CentralDeviceProviderPreview(cmd=cmd, app_id=app_id, token=token)
else:
provider = CentralDeviceProviderV1(cmd=cmd, app_id=app_id, token=token)

return provider.get_component_command_history(
device_id=device_id, interface_id=interface_id, command_name=command_name,
device_id=device_id,
interface_id=interface_id,
command_name=command_name,
central_dns_suffix=central_dns_suffix,
)


def registration_summary(
cmd, app_id: str, token=None, central_dns_suffix=CENTRAL_ENDPOINT,
):
provider = CentralDeviceProvider(cmd=cmd, app_id=app_id, token=token,)
provider = CentralDeviceProviderV1(cmd=cmd, app_id=app_id, token=token,)
return provider.get_device_registration_summary(
central_dns_suffix=central_dns_suffix,
)
Expand All @@ -151,7 +194,7 @@ def registration_summary(
def get_credentials(
cmd, app_id: str, device_id, token=None, central_dns_suffix=CENTRAL_ENDPOINT,
):
provider = CentralDeviceProvider(cmd=cmd, app_id=app_id, token=token,)
provider = CentralDeviceProviderV1(cmd=cmd, app_id=app_id, token=token,)
return provider.get_device_credentials(
device_id=device_id, central_dns_suffix=central_dns_suffix,
)
Expand Down
Loading