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

Add sample to get config versions for a device. #1310

Merged
merged 1 commit into from
Jan 11, 2018
Merged
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
29 changes: 29 additions & 0 deletions iot/api-client/manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,29 @@ def set_config(
name=device_path, body=config_body).execute()


def get_config_versions(
service_account_json, project_id, cloud_region, registry_id,
device_id):
"""Lists versions of a device config in descending order (newest first)."""
client = get_client(service_account_json)
registry_name = 'projects/{}/locations/{}/registries/{}'.format(
project_id, cloud_region, registry_id)

device_name = '{}/devices/{}'.format(registry_name, device_id)
devices = client.projects().locations().registries().devices()
configs = devices.configVersions().list(
name=device_name).execute().get(
'deviceConfigs', [])

for config in configs:
print('version: {}\n\tcloudUpdateTime: {}\n\t binaryData: {}'.format(
config.get('version'),
config.get('cloudUpdateTime'),
config.get('binaryData')))

return configs


def parse_command_line_args():
"""Parse command line arguments."""
default_registry = 'cloudiot_device_manager_example_registry_{}'.format(
Expand Down Expand Up @@ -469,6 +492,7 @@ def parse_command_line_args():
command.add_parser('patch-es256', help=patch_es256_auth.__doc__)
command.add_parser('patch-rs256', help=patch_rsa256_auth.__doc__)
command.add_parser('set-config', help=patch_rsa256_auth.__doc__)
command.add_parser('get-config-versions', help=get_config_versions.__doc__)

return parser.parse_args()

Expand Down Expand Up @@ -571,6 +595,11 @@ def run_command(args):
args.cloud_region, args.registry_id, args.device_id,
args.version, args.config)

elif args.command == 'get-config-versions':
get_device(
args.service_account_json, args.project_id,
args.cloud_region, args.registry_id, args.device_id)


def main():
args = parse_command_line_args()
Expand Down