Skip to content
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
9 changes: 1 addition & 8 deletions example/viam_robot_example_app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,7 @@ API_KEY_ID=<API KEY ID>
API_KEY=<API KEY>
```

or using location secrets (deprecated, please prefer using API keys!):

```
ROBOT_LOCATION=<ROBOT_LOCATION_URI>
LOCATION_SECRET=<ROBOT_LOCATION_SECRET>
```

Both these fields can be obtained from your robot's `Code Sample` tab on [app.viam.com](https://app.viam.com).
These fields can be obtained from your robot's `Code Sample` tab on [app.viam.com](https://app.viam.com).

## Run

Expand Down
5 changes: 2 additions & 3 deletions lib/src/robot/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ class RobotClientOptions {
..credentials = Credentials.apiKey(apiKey)
..authEntity = apiKeyID;

/// Convenience initializer for creating options with a robot location secret
RobotClientOptions.withLocationSecret(String locationSecret)
: dialOptions = DialOptions()..credentials = Credentials.locationSecret(locationSecret);
/// Convenience initializer for creating options with a robot secret
RobotClientOptions.withRobotSecret(String robotSecret) : dialOptions = DialOptions()..credentials = Credentials.robotSecret(robotSecret);
}

/// {@category Viam SDK}
Expand Down
6 changes: 3 additions & 3 deletions lib/src/rpc/dial.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,16 @@ class DialOptions {
/// {@category Viam SDK}
/// The credentials used for connecting to the robot
class Credentials {
/// The type of credential, e.g. 'robot-location-secret', 'api-key'
/// The type of credential, e.g. 'robot-secret', 'api-key'
final String type;

/// The payload of the credential
final String payload;

const Credentials(this.type, this.payload);

/// Convenience initializer for creating credentials of type 'robot-location-secret' with the provided payload.
const Credentials.locationSecret(this.payload) : type = 'robot-location-secret';
/// Convenience initializer for creating credentials of type 'robot-secret' with the provided payload.
const Credentials.robotSecret(this.payload) : type = 'robot-secret';

/// Convenience initializer for creating credentials of type 'api-key' with the provided key as payload.
const Credentials.apiKey(this.payload) : type = 'api-key';
Expand Down
4 changes: 1 addition & 3 deletions lib/src/viam_sdk_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,8 @@ class ViamImpl implements Viam {

@override
Future<RobotClient> getRobotClient(Robot robot) async {
final location = await appClient.getLocation(robot.location);
final secret = location.auth.secrets.firstWhere((element) => element.state == SharedSecret_State.STATE_ENABLED);
final parts = await appClient.listRobotParts(robot.id);
final part = parts.firstWhere((element) => element.mainPart);
return RobotClient.atAddress(part.fqdn, RobotClientOptions.withLocationSecret(secret.secret));
return RobotClient.atAddress(part.fqdn, RobotClientOptions.withRobotSecret(part.secret));
}
}