Skip to content

Commit

Permalink
Merge pull request #535 from WildernessLabs/bug/provision-id
Browse files Browse the repository at this point in the history
generate provision command
  • Loading branch information
adrianstevens authored Mar 15, 2024
2 parents b41a8fc + d3f3577 commit 68db664
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,48 @@ public class DeviceProvisionCommand : BaseDeviceCommand<DeviceProvisionCommand>
[CommandOption("id", 'i', Description = "The unique ID/serial number of the device to provision. If not provided, it will be queried from the configured device.", IsRequired = false)]
public string? SerialNumber { get; set; }

[CommandOption("gen-command", Description = "Generate a provisioning command for the configured device", IsRequired = false)]
public bool GenerateProvisionCommand { get; set; }

public DeviceProvisionCommand(UserService userService, DeviceService deviceService, MeadowConnectionManager connectionManager, ILoggerFactory loggerFactory)
: base(connectionManager, loggerFactory)
{
_deviceService = deviceService;
_userService = userService;
}

private async ValueTask OutputProvisionCommand()
{
var device = await GetCurrentDevice();

var info = await device.GetDeviceInfo(CancellationToken);

Logger?.LogInformation(Strings.RequestingDevicePublicKey);

var publicKey = await device.GetPublicKey(CancellationToken);
publicKey = publicKey.Replace("\r", string.Empty).Replace("\n", string.Empty);
var provisioningID = !string.IsNullOrWhiteSpace(info?.ProcessorId) ? info.ProcessorId : info?.SerialNumber;

var command = "meadow device provision";
if (!string.IsNullOrWhiteSpace(OrgId))
{
command += $" -o {OrgId}";
}
command += $" -id \"{provisioningID}\" -k \"{publicKey}\"";
Logger?.LogInformation($"Provisioning command is:");
Logger?.LogInformation(command);
}

protected override async ValueTask ExecuteCommand()
{
if (GenerateProvisionCommand)
{
Logger?.LogInformation("Generating a device provisioning command...");

await OutputProvisionCommand();
return;
}

UserOrg? org;

try
Expand Down
6 changes: 5 additions & 1 deletion Source/v2/Meadow.Cli/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,11 @@
},
"Device provision": {
"commandName": "Project",
"commandLineArgs": "device provision"
"commandLineArgs": "device provision -o christacke6612"
},
"Device provision command": {
"commandName": "Project",
"commandLineArgs": "device provision --gen-command"
},
"Device provision other": {
"commandName": "Project",
Expand Down

0 comments on commit 68db664

Please sign in to comment.