Skip to content

Commit

Permalink
APP-3811 - Provisioning wrappers (#179)
Browse files Browse the repository at this point in the history
* generate draft provisioning protos

* add provisioning client wrappers

* add provisioning client tests

* add export, make NetworkType enum

* add provisioning to viam impl

* generate more proto stuff

* update channel for provisioning client

* comment typos - make fields not requried
  • Loading branch information
clintpurser authored Feb 9, 2024
1 parent 980d8cb commit 9a37a9b
Show file tree
Hide file tree
Showing 14 changed files with 1,576 additions and 5 deletions.
10 changes: 10 additions & 0 deletions lib/protos/provisioning/provisioning.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/// The proto definitions for provisioning
/// {@category Protobuf Definitions}
library viam_protos.provisioning.provisioning;

// THIS FILE IS AUTOMATICALLY GENERATED
// DO NOT OVERWRITE
export '../../../src/gen/provisioning/v1/provisioning.pb.dart';
export '../../../src/gen/provisioning/v1/provisioning.pbenum.dart';
export '../../../src/gen/provisioning/v1/provisioning.pbgrpc.dart';
export '../../../src/gen/provisioning/v1/provisioning.pbjson.dart';
52 changes: 52 additions & 0 deletions lib/src/app/provisioning.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import 'dart:async';

import '../gen/provisioning/v1/provisioning.pbgrpc.dart';

enum NetworkType { wifi, wired }

/// gRPC client for connecting to Viam's Provisioning Service
///
/// All calls must be authenticated.
class ProvisioningClient {
final ProvisioningServiceClient _client;

ProvisioningClient(this._client);

/// Get the status of the Smart Machine
Future<GetSmartMachineStatusResponse> getSmartMachineStatus() async {
final request = GetSmartMachineStatusRequest();
final response = await _client.getSmartMachineStatus(request);
return response;
}

/// Set the network credentials of the smart machine, so it can connect to the internet.
///
/// [ssid] is the networks ssid
/// [psk] is the networks passkey
Future<void> setNetworkCredentials({NetworkType type = NetworkType.wifi, String? ssid, String? psk}) async {
final request = SetNetworkCredentialsRequest(type: type.name, ssid: ssid, psk: psk);
await _client.setNetworkCredentials(request);
}

/// Set the Viam credentials of the smart machine, so it can connect to the Cloud.
///
/// [id] is the RobotPart id
/// [secret] is the RobotPart secret
/// [appAddress] is the cloud address that the robot will authenticate against
Future<void> setSmartMachineCredentials({
required String id,
required String secret,
String appAddress = 'https://app.viam.com:443',
}) async {
final cloud = CloudConfig(id: id, secret: secret, appAddress: appAddress);
final request = SetSmartMachineCredentialsRequest(cloud: cloud);
await _client.setSmartMachineCredentials(request);
}

/// Get the networks that are visible to the Smart Machine.
Future<Iterable<NetworkInfo>> getNetworkList() async {
final request = GetNetworkListRequest();
final response = await _client.getNetworkList(request);
return response.networks;
}
}
703 changes: 703 additions & 0 deletions lib/src/gen/provisioning/v1/provisioning.pb.dart

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions lib/src/gen/provisioning/v1/provisioning.pbenum.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// Generated code. Do not modify.
// source: provisioning/v1/provisioning.proto
//
// @dart = 2.12

// ignore_for_file: annotate_overrides, camel_case_types, comment_references
// ignore_for_file: constant_identifier_names, library_prefixes
// ignore_for_file: non_constant_identifier_names, prefer_final_fields
// ignore_for_file: unnecessary_import, unnecessary_this, unused_import

119 changes: 119 additions & 0 deletions lib/src/gen/provisioning/v1/provisioning.pbgrpc.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
//
// Generated code. Do not modify.
// source: provisioning/v1/provisioning.proto
//
// @dart = 2.12

// ignore_for_file: annotate_overrides, camel_case_types, comment_references
// ignore_for_file: constant_identifier_names, library_prefixes
// ignore_for_file: non_constant_identifier_names, prefer_final_fields
// ignore_for_file: unnecessary_import, unnecessary_this, unused_import

import 'dart:async' as $async;
import 'dart:core' as $core;

import 'package:grpc/service_api.dart' as $grpc;
import 'package:protobuf/protobuf.dart' as $pb;

import 'provisioning.pb.dart' as $0;

export 'provisioning.pb.dart';

@$pb.GrpcServiceName('viam.provisioning.v1.ProvisioningService')
class ProvisioningServiceClient extends $grpc.Client {
static final _$getSmartMachineStatus = $grpc.ClientMethod<$0.GetSmartMachineStatusRequest, $0.GetSmartMachineStatusResponse>(
'/viam.provisioning.v1.ProvisioningService/GetSmartMachineStatus',
($0.GetSmartMachineStatusRequest value) => value.writeToBuffer(),
($core.List<$core.int> value) => $0.GetSmartMachineStatusResponse.fromBuffer(value));
static final _$setNetworkCredentials = $grpc.ClientMethod<$0.SetNetworkCredentialsRequest, $0.SetNetworkCredentialsResponse>(
'/viam.provisioning.v1.ProvisioningService/SetNetworkCredentials',
($0.SetNetworkCredentialsRequest value) => value.writeToBuffer(),
($core.List<$core.int> value) => $0.SetNetworkCredentialsResponse.fromBuffer(value));
static final _$setSmartMachineCredentials = $grpc.ClientMethod<$0.SetSmartMachineCredentialsRequest, $0.SetSmartMachineCredentialsResponse>(
'/viam.provisioning.v1.ProvisioningService/SetSmartMachineCredentials',
($0.SetSmartMachineCredentialsRequest value) => value.writeToBuffer(),
($core.List<$core.int> value) => $0.SetSmartMachineCredentialsResponse.fromBuffer(value));
static final _$getNetworkList = $grpc.ClientMethod<$0.GetNetworkListRequest, $0.GetNetworkListResponse>(
'/viam.provisioning.v1.ProvisioningService/GetNetworkList',
($0.GetNetworkListRequest value) => value.writeToBuffer(),
($core.List<$core.int> value) => $0.GetNetworkListResponse.fromBuffer(value));

ProvisioningServiceClient($grpc.ClientChannel channel,
{$grpc.CallOptions? options,
$core.Iterable<$grpc.ClientInterceptor>? interceptors})
: super(channel, options: options,
interceptors: interceptors);

$grpc.ResponseFuture<$0.GetSmartMachineStatusResponse> getSmartMachineStatus($0.GetSmartMachineStatusRequest request, {$grpc.CallOptions? options}) {
return $createUnaryCall(_$getSmartMachineStatus, request, options: options);
}

$grpc.ResponseFuture<$0.SetNetworkCredentialsResponse> setNetworkCredentials($0.SetNetworkCredentialsRequest request, {$grpc.CallOptions? options}) {
return $createUnaryCall(_$setNetworkCredentials, request, options: options);
}

$grpc.ResponseFuture<$0.SetSmartMachineCredentialsResponse> setSmartMachineCredentials($0.SetSmartMachineCredentialsRequest request, {$grpc.CallOptions? options}) {
return $createUnaryCall(_$setSmartMachineCredentials, request, options: options);
}

$grpc.ResponseFuture<$0.GetNetworkListResponse> getNetworkList($0.GetNetworkListRequest request, {$grpc.CallOptions? options}) {
return $createUnaryCall(_$getNetworkList, request, options: options);
}
}

@$pb.GrpcServiceName('viam.provisioning.v1.ProvisioningService')
abstract class ProvisioningServiceBase extends $grpc.Service {
$core.String get $name => 'viam.provisioning.v1.ProvisioningService';

ProvisioningServiceBase() {
$addMethod($grpc.ServiceMethod<$0.GetSmartMachineStatusRequest, $0.GetSmartMachineStatusResponse>(
'GetSmartMachineStatus',
getSmartMachineStatus_Pre,
false,
false,
($core.List<$core.int> value) => $0.GetSmartMachineStatusRequest.fromBuffer(value),
($0.GetSmartMachineStatusResponse value) => value.writeToBuffer()));
$addMethod($grpc.ServiceMethod<$0.SetNetworkCredentialsRequest, $0.SetNetworkCredentialsResponse>(
'SetNetworkCredentials',
setNetworkCredentials_Pre,
false,
false,
($core.List<$core.int> value) => $0.SetNetworkCredentialsRequest.fromBuffer(value),
($0.SetNetworkCredentialsResponse value) => value.writeToBuffer()));
$addMethod($grpc.ServiceMethod<$0.SetSmartMachineCredentialsRequest, $0.SetSmartMachineCredentialsResponse>(
'SetSmartMachineCredentials',
setSmartMachineCredentials_Pre,
false,
false,
($core.List<$core.int> value) => $0.SetSmartMachineCredentialsRequest.fromBuffer(value),
($0.SetSmartMachineCredentialsResponse value) => value.writeToBuffer()));
$addMethod($grpc.ServiceMethod<$0.GetNetworkListRequest, $0.GetNetworkListResponse>(
'GetNetworkList',
getNetworkList_Pre,
false,
false,
($core.List<$core.int> value) => $0.GetNetworkListRequest.fromBuffer(value),
($0.GetNetworkListResponse value) => value.writeToBuffer()));
}

$async.Future<$0.GetSmartMachineStatusResponse> getSmartMachineStatus_Pre($grpc.ServiceCall call, $async.Future<$0.GetSmartMachineStatusRequest> request) async {
return getSmartMachineStatus(call, await request);
}

$async.Future<$0.SetNetworkCredentialsResponse> setNetworkCredentials_Pre($grpc.ServiceCall call, $async.Future<$0.SetNetworkCredentialsRequest> request) async {
return setNetworkCredentials(call, await request);
}

$async.Future<$0.SetSmartMachineCredentialsResponse> setSmartMachineCredentials_Pre($grpc.ServiceCall call, $async.Future<$0.SetSmartMachineCredentialsRequest> request) async {
return setSmartMachineCredentials(call, await request);
}

$async.Future<$0.GetNetworkListResponse> getNetworkList_Pre($grpc.ServiceCall call, $async.Future<$0.GetNetworkListRequest> request) async {
return getNetworkList(call, await request);
}

$async.Future<$0.GetSmartMachineStatusResponse> getSmartMachineStatus($grpc.ServiceCall call, $0.GetSmartMachineStatusRequest request);
$async.Future<$0.SetNetworkCredentialsResponse> setNetworkCredentials($grpc.ServiceCall call, $0.SetNetworkCredentialsRequest request);
$async.Future<$0.SetSmartMachineCredentialsResponse> setSmartMachineCredentials($grpc.ServiceCall call, $0.SetSmartMachineCredentialsRequest request);
$async.Future<$0.GetNetworkListResponse> getNetworkList($grpc.ServiceCall call, $0.GetNetworkListRequest request);
}
163 changes: 163 additions & 0 deletions lib/src/gen/provisioning/v1/provisioning.pbjson.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
//
// Generated code. Do not modify.
// source: provisioning/v1/provisioning.proto
//
// @dart = 2.12

// ignore_for_file: annotate_overrides, camel_case_types, comment_references
// ignore_for_file: constant_identifier_names, library_prefixes
// ignore_for_file: non_constant_identifier_names, prefer_final_fields
// ignore_for_file: unnecessary_import, unnecessary_this, unused_import

import 'dart:convert' as $convert;
import 'dart:core' as $core;
import 'dart:typed_data' as $typed_data;

@$core.Deprecated('Use getSmartMachineStatusRequestDescriptor instead')
const GetSmartMachineStatusRequest$json = {
'1': 'GetSmartMachineStatusRequest',
};

/// Descriptor for `GetSmartMachineStatusRequest`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List getSmartMachineStatusRequestDescriptor = $convert.base64Decode(
'ChxHZXRTbWFydE1hY2hpbmVTdGF0dXNSZXF1ZXN0');

@$core.Deprecated('Use getSmartMachineStatusResponseDescriptor instead')
const GetSmartMachineStatusResponse$json = {
'1': 'GetSmartMachineStatusResponse',
'2': [
{'1': 'provisioning_info', '3': 1, '4': 1, '5': 11, '6': '.viam.provisioning.v1.ProvisioningInfo', '10': 'provisioningInfo'},
{'1': 'has_smart_machine_credentials', '3': 2, '4': 1, '5': 8, '10': 'hasSmartMachineCredentials'},
{'1': 'is_online', '3': 3, '4': 1, '5': 8, '10': 'isOnline'},
{'1': 'latest_connection_attempt', '3': 4, '4': 1, '5': 11, '6': '.viam.provisioning.v1.NetworkInfo', '10': 'latestConnectionAttempt'},
{'1': 'errors', '3': 5, '4': 3, '5': 9, '10': 'errors'},
],
};

/// Descriptor for `GetSmartMachineStatusResponse`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List getSmartMachineStatusResponseDescriptor = $convert.base64Decode(
'Ch1HZXRTbWFydE1hY2hpbmVTdGF0dXNSZXNwb25zZRJTChFwcm92aXNpb25pbmdfaW5mbxgBIA'
'EoCzImLnZpYW0ucHJvdmlzaW9uaW5nLnYxLlByb3Zpc2lvbmluZ0luZm9SEHByb3Zpc2lvbmlu'
'Z0luZm8SQQodaGFzX3NtYXJ0X21hY2hpbmVfY3JlZGVudGlhbHMYAiABKAhSGmhhc1NtYXJ0TW'
'FjaGluZUNyZWRlbnRpYWxzEhsKCWlzX29ubGluZRgDIAEoCFIIaXNPbmxpbmUSXQoZbGF0ZXN0'
'X2Nvbm5lY3Rpb25fYXR0ZW1wdBgEIAEoCzIhLnZpYW0ucHJvdmlzaW9uaW5nLnYxLk5ldHdvcm'
'tJbmZvUhdsYXRlc3RDb25uZWN0aW9uQXR0ZW1wdBIWCgZlcnJvcnMYBSADKAlSBmVycm9ycw==');

@$core.Deprecated('Use setNetworkCredentialsRequestDescriptor instead')
const SetNetworkCredentialsRequest$json = {
'1': 'SetNetworkCredentialsRequest',
'2': [
{'1': 'type', '3': 1, '4': 1, '5': 9, '10': 'type'},
{'1': 'ssid', '3': 2, '4': 1, '5': 9, '10': 'ssid'},
{'1': 'psk', '3': 3, '4': 1, '5': 9, '10': 'psk'},
],
};

/// Descriptor for `SetNetworkCredentialsRequest`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List setNetworkCredentialsRequestDescriptor = $convert.base64Decode(
'ChxTZXROZXR3b3JrQ3JlZGVudGlhbHNSZXF1ZXN0EhIKBHR5cGUYASABKAlSBHR5cGUSEgoEc3'
'NpZBgCIAEoCVIEc3NpZBIQCgNwc2sYAyABKAlSA3Bzaw==');

@$core.Deprecated('Use setNetworkCredentialsResponseDescriptor instead')
const SetNetworkCredentialsResponse$json = {
'1': 'SetNetworkCredentialsResponse',
};

/// Descriptor for `SetNetworkCredentialsResponse`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List setNetworkCredentialsResponseDescriptor = $convert.base64Decode(
'Ch1TZXROZXR3b3JrQ3JlZGVudGlhbHNSZXNwb25zZQ==');

@$core.Deprecated('Use setSmartMachineCredentialsRequestDescriptor instead')
const SetSmartMachineCredentialsRequest$json = {
'1': 'SetSmartMachineCredentialsRequest',
'2': [
{'1': 'cloud', '3': 1, '4': 1, '5': 11, '6': '.viam.provisioning.v1.CloudConfig', '10': 'cloud'},
],
};

/// Descriptor for `SetSmartMachineCredentialsRequest`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List setSmartMachineCredentialsRequestDescriptor = $convert.base64Decode(
'CiFTZXRTbWFydE1hY2hpbmVDcmVkZW50aWFsc1JlcXVlc3QSNwoFY2xvdWQYASABKAsyIS52aW'
'FtLnByb3Zpc2lvbmluZy52MS5DbG91ZENvbmZpZ1IFY2xvdWQ=');

@$core.Deprecated('Use setSmartMachineCredentialsResponseDescriptor instead')
const SetSmartMachineCredentialsResponse$json = {
'1': 'SetSmartMachineCredentialsResponse',
};

/// Descriptor for `SetSmartMachineCredentialsResponse`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List setSmartMachineCredentialsResponseDescriptor = $convert.base64Decode(
'CiJTZXRTbWFydE1hY2hpbmVDcmVkZW50aWFsc1Jlc3BvbnNl');

@$core.Deprecated('Use getNetworkListRequestDescriptor instead')
const GetNetworkListRequest$json = {
'1': 'GetNetworkListRequest',
};

/// Descriptor for `GetNetworkListRequest`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List getNetworkListRequestDescriptor = $convert.base64Decode(
'ChVHZXROZXR3b3JrTGlzdFJlcXVlc3Q=');

@$core.Deprecated('Use getNetworkListResponseDescriptor instead')
const GetNetworkListResponse$json = {
'1': 'GetNetworkListResponse',
'2': [
{'1': 'networks', '3': 1, '4': 3, '5': 11, '6': '.viam.provisioning.v1.NetworkInfo', '10': 'networks'},
],
};

/// Descriptor for `GetNetworkListResponse`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List getNetworkListResponseDescriptor = $convert.base64Decode(
'ChZHZXROZXR3b3JrTGlzdFJlc3BvbnNlEj0KCG5ldHdvcmtzGAEgAygLMiEudmlhbS5wcm92aX'
'Npb25pbmcudjEuTmV0d29ya0luZm9SCG5ldHdvcmtz');

@$core.Deprecated('Use provisioningInfoDescriptor instead')
const ProvisioningInfo$json = {
'1': 'ProvisioningInfo',
'2': [
{'1': 'fragment_id', '3': 1, '4': 1, '5': 9, '10': 'fragmentId'},
{'1': 'model', '3': 2, '4': 1, '5': 9, '10': 'model'},
{'1': 'manufacturer', '3': 3, '4': 1, '5': 9, '10': 'manufacturer'},
],
};

/// Descriptor for `ProvisioningInfo`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List provisioningInfoDescriptor = $convert.base64Decode(
'ChBQcm92aXNpb25pbmdJbmZvEh8KC2ZyYWdtZW50X2lkGAEgASgJUgpmcmFnbWVudElkEhQKBW'
'1vZGVsGAIgASgJUgVtb2RlbBIiCgxtYW51ZmFjdHVyZXIYAyABKAlSDG1hbnVmYWN0dXJlcg==');

@$core.Deprecated('Use networkInfoDescriptor instead')
const NetworkInfo$json = {
'1': 'NetworkInfo',
'2': [
{'1': 'type', '3': 1, '4': 1, '5': 9, '10': 'type'},
{'1': 'ssid', '3': 2, '4': 1, '5': 9, '10': 'ssid'},
{'1': 'security', '3': 3, '4': 1, '5': 9, '10': 'security'},
{'1': 'signal', '3': 4, '4': 1, '5': 5, '10': 'signal'},
{'1': 'connected', '3': 5, '4': 1, '5': 8, '10': 'connected'},
{'1': 'last_error', '3': 6, '4': 1, '5': 9, '10': 'lastError'},
],
};

/// Descriptor for `NetworkInfo`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List networkInfoDescriptor = $convert.base64Decode(
'CgtOZXR3b3JrSW5mbxISCgR0eXBlGAEgASgJUgR0eXBlEhIKBHNzaWQYAiABKAlSBHNzaWQSGg'
'oIc2VjdXJpdHkYAyABKAlSCHNlY3VyaXR5EhYKBnNpZ25hbBgEIAEoBVIGc2lnbmFsEhwKCWNv'
'bm5lY3RlZBgFIAEoCFIJY29ubmVjdGVkEh0KCmxhc3RfZXJyb3IYBiABKAlSCWxhc3RFcnJvcg'
'==');

@$core.Deprecated('Use cloudConfigDescriptor instead')
const CloudConfig$json = {
'1': 'CloudConfig',
'2': [
{'1': 'id', '3': 1, '4': 1, '5': 9, '10': 'id'},
{'1': 'secret', '3': 2, '4': 1, '5': 9, '10': 'secret'},
{'1': 'app_address', '3': 3, '4': 1, '5': 9, '10': 'appAddress'},
],
};

/// Descriptor for `CloudConfig`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List cloudConfigDescriptor = $convert.base64Decode(
'CgtDbG91ZENvbmZpZxIOCgJpZBgBIAEoCVICaWQSFgoGc2VjcmV0GAIgASgJUgZzZWNyZXQSHw'
'oLYXBwX2FkZHJlc3MYAyABKAlSCmFwcEFkZHJlc3M=');

4 changes: 4 additions & 0 deletions lib/src/viam_sdk.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import './app/app.dart';
import './app/data.dart';
import './app/provisioning.dart';
import './gen/app/v1/app.pbgrpc.dart';
import './robot/client.dart';
import './viam_sdk_impl.dart';
Expand All @@ -21,6 +22,9 @@ abstract class Viam {
/// A client to communicate with Viam's data and data sync services
DataClient get dataClient;

/// A client to communicate with Viam's data and data sync services
ProvisioningClient get provisioningClient;

/// Get a [RobotClient] connected to the provided [Robot]
Future<RobotClient> getRobotClient(Robot robot);
}
Loading

0 comments on commit 9a37a9b

Please sign in to comment.