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

generate provision command #535

Merged
merged 1 commit into from
Mar 15, 2024
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
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
Loading