-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
261 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
Source/v2/Meadow.Cli/Commands/Current/Cloud/Package/CloudPackageListCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using CliFx.Attributes; | ||
using Meadow.Cloud; | ||
using Meadow.Cloud.Identity; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Meadow.CLI.Commands.DeviceManagement; | ||
|
||
[Command("cloud package list", Description = "Lists all Meadow Packages (MPAK)")] | ||
public class CloudPackageListCommand : BaseCloudCommand<CloudPackageListCommand> | ||
{ | ||
private PackageService _packageService; | ||
|
||
[CommandOption("orgId", 'o', Description = "Optional organization ID", IsRequired = false)] | ||
public string? OrgId { get; set; } | ||
|
||
[CommandOption("host", Description = "Optionally set a host (default is https://www.meadowcloud.co)", IsRequired = false)] | ||
public string Host { get; set; } | ||
|
||
public CloudPackageListCommand( | ||
IdentityManager identityManager, | ||
UserService userService, | ||
DeviceService deviceService, | ||
CollectionService collectionService, | ||
PackageService packageService, | ||
ILoggerFactory? loggerFactory) | ||
: base(identityManager, userService, deviceService, collectionService, loggerFactory) | ||
{ | ||
_packageService = packageService; | ||
} | ||
|
||
protected override async ValueTask ExecuteCommand(CancellationToken? cancellationToken) | ||
{ | ||
if (Host == null) Host = DefaultHost; | ||
var org = await ValidateOrg(Host, OrgId, cancellationToken); | ||
|
||
if (org == null) return; | ||
|
||
var packages = await _packageService.GetOrgPackages(org.Id, Host, cancellationToken); | ||
|
||
if (packages == null || packages.Count == 0) | ||
{ | ||
Logger?.LogInformation("No packages found."); | ||
} | ||
else | ||
{ | ||
Logger?.LogInformation("packages:"); | ||
foreach (var package in packages) | ||
{ | ||
Logger?.LogInformation($" {package.Id} | {package.Name}"); | ||
} | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
Source/v2/Meadow.Cli/Commands/Current/Cloud/Package/CloudPackagePublishCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using CliFx.Attributes; | ||
using Meadow.Cloud; | ||
using Meadow.Cloud.Identity; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Meadow.CLI.Commands.DeviceManagement; | ||
|
||
[Command("cloud package publish", Description = "Publishes a Meadow Package (MPAK)")] | ||
public class CloudPackagePublishCommand : BaseCloudCommand<CloudPackagePublishCommand> | ||
{ | ||
private PackageService _packageService; | ||
|
||
[CommandParameter(0, Name = "PackageID", Description = "ID of the package to publish", IsRequired = true)] | ||
public string PackageId { get; init; } | ||
|
||
[CommandOption("collectionId", 'c', Description = "The target collection for publishing", IsRequired = true)] | ||
public string CollectionId { get; set; } | ||
|
||
[CommandOption("metadata", 'm', Description = "Pass through metadata", IsRequired = false)] | ||
public string Metadata { get; set; } | ||
|
||
[CommandOption("host", Description = "Optionally set a host (default is https://www.meadowcloud.co)", IsRequired = false)] | ||
public string Host { get; set; } | ||
|
||
public CloudPackagePublishCommand( | ||
IdentityManager identityManager, | ||
UserService userService, | ||
DeviceService deviceService, | ||
CollectionService collectionService, | ||
PackageService packageService, | ||
ILoggerFactory? loggerFactory) | ||
: base(identityManager, userService, deviceService, collectionService, loggerFactory) | ||
{ | ||
_packageService = packageService; | ||
} | ||
|
||
protected override async ValueTask ExecuteCommand(CancellationToken? cancellationToken) | ||
{ | ||
if (Host == null) Host = DefaultHost; | ||
|
||
try | ||
{ | ||
Logger?.LogInformation($"Publishing package {PackageId} to collection {CollectionId}..."); | ||
|
||
await _packageService.PublishPackage(PackageId, CollectionId, Metadata, Host, cancellationToken); | ||
Logger?.LogInformation("Publish successful."); | ||
} | ||
catch (MeadowCloudException mex) | ||
{ | ||
Logger?.LogError($"Publish failed: {mex.Message}"); | ||
} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
Source/v2/Meadow.Cli/Commands/Current/Cloud/Package/CloudPackageUploadCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using CliFx.Attributes; | ||
using Meadow.Cloud; | ||
using Meadow.Cloud.Identity; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Meadow.CLI.Commands.DeviceManagement; | ||
|
||
[Command("cloud package upload", Description = "Upload a Meadow Package (MPAK) to Meadow.Cloud")] | ||
public class CloudPackageUploadCommand : BaseCloudCommand<CloudPackageUploadCommand> | ||
{ | ||
[CommandParameter(0, Name = "MpakPath", Description = "The full path of the mpak file", IsRequired = true)] | ||
public string MpakPath { get; init; } | ||
|
||
[CommandOption("orgId", 'o', Description = "OrgId to upload to", IsRequired = false)] | ||
public string? OrgId { get; set; } | ||
|
||
[CommandOption("description", 'd', Description = "Description of the package", IsRequired = false)] | ||
public string? Description { get; set; } | ||
|
||
[CommandOption("host", Description = "Optionally set a host (default is https://www.meadowcloud.co)", IsRequired = false)] | ||
public string? Host { get; set; } | ||
|
||
private PackageService _packageService; | ||
|
||
public CloudPackageUploadCommand( | ||
IdentityManager identityManager, | ||
UserService userService, | ||
DeviceService deviceService, | ||
CollectionService collectionService, | ||
PackageService packageService, | ||
ILoggerFactory? loggerFactory) | ||
: base(identityManager, userService, deviceService, collectionService, loggerFactory) | ||
{ | ||
_packageService = packageService; | ||
} | ||
|
||
protected override async ValueTask ExecuteCommand(CancellationToken? cancellationToken) | ||
{ | ||
if (!File.Exists(MpakPath)) | ||
{ | ||
Logger?.LogError($"Package {MpakPath} does not exist"); | ||
return; | ||
} | ||
|
||
if (Host == null) Host = DefaultHost; | ||
var org = await ValidateOrg(Host, OrgId, cancellationToken); | ||
|
||
if (org == null) return; | ||
|
||
try | ||
{ | ||
Logger?.LogInformation($"Uploading package {Path.GetFileName(MpakPath)}..."); | ||
|
||
var package = await _packageService.UploadPackage(MpakPath, org.Id, Description, Host, cancellationToken); | ||
Logger?.LogInformation($"Upload complete. Package Id: {package.Id}"); | ||
} | ||
catch (MeadowCloudException mex) | ||
{ | ||
Logger?.LogError($"Upload failed: {mex.Message}"); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.