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

Merge Changes for 1.3.0.0 Release #345

Merged
merged 29 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6a4c8e6
New attempt to fix DeveloperLevel.
CartBlanche Jul 6, 2023
1ab47e2
add metadata param for package publish
lamebrain Jul 20, 2023
fefaa62
Create package with / path separator always (#300)
Redth Jul 24, 2023
72c2f1f
update publish endpoint
lamebrain Jul 26, 2023
f047957
move config name to const
lamebrain Jul 26, 2023
f8d3d96
Merge pull request #331 from WildernessLabs/publish_metadata
lamebrain Jul 27, 2023
ab9c5b3
Bump to 1.2.0.0
CartBlanche Jul 26, 2023
6a26941
Force flash erase if Version is 'Unknown'
CartBlanche Aug 5, 2023
08b704b
Fix for #332
CartBlanche Aug 5, 2023
5451119
update login redirect
lamebrain Aug 11, 2023
7a3123e
Merge pull request #340 from WildernessLabs/user_redirect
lamebrain Aug 16, 2023
03b6785
Add ability to publish commands to devices via Meadow.Cloud
stevenkuhn Aug 17, 2023
91b6206
Merge pull request #341 from WildernessLabs/cloud-command-publish
stevenkuhn Aug 18, 2023
f5f6c09
package_v2
lamebrain Aug 19, 2023
fee4093
clean up
lamebrain Aug 19, 2023
329a9b8
clean up more
lamebrain Aug 19, 2023
f2b7044
send os version on package upload
lamebrain Aug 21, 2023
0075fdb
add Glob package to other proj files
lamebrain Aug 21, 2023
e65cc13
Support Old and new LibUsbDotNet nugets. (#338)
CartBlanche Aug 24, 2023
933e93c
Merge branch 'develop' into package_v2
lamebrain Aug 24, 2023
7bf211a
Add ability to publish commands by device ID via Meadow.Cloud
stevenkuhn Aug 21, 2023
e757a44
clean up
lamebrain Aug 24, 2023
6e138cd
add Glob ref to classic
lamebrain Aug 24, 2023
663fe46
Merge pull request #343 from WildernessLabs/cloud-command-publish
stevenkuhn Aug 24, 2023
08af471
Merge pull request #342 from WildernessLabs/package_v2
lamebrain Aug 24, 2023
60c79dd
add friendly name arg
lamebrain Aug 24, 2023
329e4de
Merge pull request #344 from WildernessLabs/friendly_name
lamebrain Aug 24, 2023
5c55399
Merge branch 'main' into develop
lamebrain Aug 24, 2023
6fba84f
fix missed merges
lamebrain Aug 24, 2023
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
22 changes: 17 additions & 5 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Meadow.CLI
env:
CLI_RELEASE_VERSION: 1.2.0.0
IDE_TOOLS_RELEASE_VERSION: 1.2.0
MEADOW_OS_VERSION: 1.2.0.0
CLI_RELEASE_VERSION: 1.3.0.0
IDE_TOOLS_RELEASE_VERSION: 1.3.0
MEADOW_OS_VERSION: 1.3.0.0
VS_MAC_2019_VERSION: 8.10
VS_MAC_2022_VERSION: 17.5

Expand Down Expand Up @@ -62,10 +62,22 @@ jobs:
- name: Add MSBuild to Path
uses: microsoft/[email protected]

- name: Restore dependencies
- name: Restore Classic dependencies
run: dotnet restore main/MeadowCLI.Classic.sln /p:Configuration=Release

- name: Build Classic CLI
run: dotnet build main/MeadowCLI.Classic.sln /p:Configuration=Release

- name: Upload nuget Artifacts for internal testing
uses: actions/upload-artifact@v2
with:
name: Meadow.CLI.Classic.nuget.${{ ENV.CLI_RELEASE_VERSION }}
path: 'main\Meadow.CLI.Classic\bin\Release\*.nupkg'

- name: Restore normal dependencies
run: dotnet restore main/MeadowCLI.sln /p:Configuration=Release

- name: Build
- name: Build normal CLI
run: dotnet build main/MeadowCLI.sln /p:Configuration=Release

- name: Upload nuget Artifacts for internal testing
Expand Down
14 changes: 6 additions & 8 deletions Meadow.CLI.Core/CloudServices/CloudServiceBase.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
using Meadow.CLI.Core.Exceptions;
using Meadow.CLI.Core.Identity;
using System;
using System.Collections.Generic;
using System.Net.Http.Headers;
using System.Net.Http;
using System.Text;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;

namespace Meadow.CLI.Core.CloudServices
{
public abstract class CloudServiceBase
{
IdentityManager _identityManager;
readonly IdentityManager _identityManager;

protected CloudServiceBase(IdentityManager identityManager)
{
_identityManager = identityManager;
}

protected async Task<HttpClient> AuthenticatedHttpClient()
protected async Task<HttpClient> GetAuthenticatedHttpClient(CancellationToken cancellationToken = default)
{
var authToken = await _identityManager.GetAccessToken();
var authToken = await _identityManager.GetAccessToken(cancellationToken);
if (string.IsNullOrEmpty(authToken))
{
throw new MeadowCloudAuthException();
}

HttpClient client = new HttpClient();
HttpClient client = new();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authToken);

return client;
Expand Down
27 changes: 6 additions & 21 deletions Meadow.CLI.Core/CloudServices/CollectionService.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
using System;
using Meadow.CLI.Core.CloudServices.Messages;
using Meadow.CLI.Core.Identity;
using Microsoft.Extensions.Configuration;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Meadow.CLI.Core.CloudServices.Messages;
using Meadow.CLI.Core.DeviceManagement.Tools;
using Meadow.CLI.Core.Exceptions;
using Meadow.CLI.Core.Identity;
using Microsoft.Extensions.Configuration;

namespace Meadow.CLI.Core.CloudServices;

public class CollectionService : CloudServiceBase
{
IConfiguration _config;
IdentityManager _identityManager;
readonly IConfiguration _config;

public CollectionService(IConfiguration config, IdentityManager identityManager) : base(identityManager)
{
_config = config;
_identityManager = identityManager;
}

public async Task<List<Collection>> GetOrgCollections(string orgId, string host, CancellationToken cancellationToken)
Expand All @@ -32,16 +24,9 @@ public async Task<List<Collection>> GetOrgCollections(string orgId, string host,
host = _config[Constants.MEADOW_CLOUD_HOST_CONFIG_NAME];
}

var authToken = await _identityManager.GetAccessToken(cancellationToken).ConfigureAwait(false);
if (string.IsNullOrEmpty(authToken))
{
throw new MeadowCloudAuthException();
}

HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authToken);
var httpClient = await GetAuthenticatedHttpClient(cancellationToken);

var result = await httpClient.GetStringAsync($"{host}/api/orgs/{orgId}/collections");
return JsonSerializer.Deserialize<List<Collection>>(result);
return JsonSerializer.Deserialize<List<Collection>>(result) ?? new List<Collection>();
}
}
86 changes: 86 additions & 0 deletions Meadow.CLI.Core/CloudServices/CommandService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using Meadow.CLI.Core.Exceptions;
using Meadow.CLI.Core.Identity;
using Microsoft.Extensions.Configuration;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;

namespace Meadow.CLI.Core.CloudServices
{
public class CommandService : CloudServiceBase
{
readonly IConfiguration _config;
readonly IdentityManager _identityManager;

public CommandService(IConfiguration config, IdentityManager identityManager) : base(identityManager)
{
_config = config;
_identityManager = identityManager;
}

public async Task PublishCommandForCollection(
string collectionId,
string commandName,
JsonDocument? arguments = null,
int qualityOfService = 0,
string? host = null,
CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(host))
{
host = _config[Constants.MEADOW_CLOUD_HOST_CONFIG_NAME];
}

var httpClient = await GetAuthenticatedHttpClient(cancellationToken);

var payload = new
{
commandName,
args = arguments,
qos = qualityOfService
};
var content = new StringContent(JsonSerializer.Serialize(payload), Encoding.UTF8, "application/json");
var response = await httpClient.PostAsync($"{host}/api/collections/{collectionId}/commands", content, cancellationToken);

if (!response.IsSuccessStatusCode)
{
var message = await response.Content.ReadAsStringAsync();
throw new MeadowCloudException(message);
}
}

public async Task PublishCommandForDevices(
string[] deviceIds,
string commandName,
JsonDocument? arguments = null,
int qualityOfService = 0,
string? host = null,
CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(host))
{
host = _config[Constants.MEADOW_CLOUD_HOST_CONFIG_NAME];
}

var httpClient = await GetAuthenticatedHttpClient(cancellationToken);

var payload = new
{
deviceIds,
commandName,
args = arguments,
qos = qualityOfService
};
var content = new StringContent(JsonSerializer.Serialize(payload), Encoding.UTF8, "application/json");
var response = await httpClient.PostAsync($"{host}/api/devices/commands", content, cancellationToken);

if (!response.IsSuccessStatusCode)
{
var message = await response.Content.ReadAsStringAsync();
throw new MeadowCloudException(message);
}
}
}
}
23 changes: 11 additions & 12 deletions Meadow.CLI.Core/CloudServices/DeviceService.cs
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
using System;
using Meadow.CLI.Core.Identity;
using Microsoft.Extensions.Configuration;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Meadow.CLI.Core.Exceptions;
using Meadow.CLI.Core.Identity;
using Microsoft.Extensions.Configuration;

namespace Meadow.CLI.Core.CloudServices
{
public class DeviceService : CloudServiceBase
{
IConfiguration _config;
readonly IConfiguration _config;

public DeviceService(IConfiguration config, IdentityManager identityManager) : base(identityManager)
{
_config = config;
}

public async Task<(bool isSuccess, string message)> AddDevice(string orgId, string id, string publicKey, string collectionId, string host)
public async Task<(bool isSuccess, string message)> AddDevice(string orgId, string id, string publicKey, string collectionId, string name, string host, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(host))
{
host = _config[Constants.MEADOW_CLOUD_HOST_CONFIG_NAME];
}

var httpClient = await AuthenticatedHttpClient();
var httpClient = await GetAuthenticatedHttpClient(cancellationToken);

dynamic payload = new
{
orgId,
id,
publicKey,
collectionId
collectionId,
name
};

var json = JsonSerializer.Serialize<dynamic>(payload);

var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await httpClient.PostAsync($"{host}/api/devices", content);

var response = await httpClient.PostAsync($"{host}/api/devices", content, cancellationToken);

if (response.IsSuccessStatusCode)
{
return (response.IsSuccessStatusCode, string.Empty);
Expand All @@ -50,7 +50,6 @@ public DeviceService(IConfiguration config, IdentityManager identityManager) : b
var message = await response.Content.ReadAsStringAsync();
return (false, message);
}

}
}
}
10 changes: 10 additions & 0 deletions Meadow.CLI.Core/CloudServices/Messages/User.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Meadow.CLI.Core.CloudServices.Messages;

public class User
{
public string Id { get; set; }

Check warning on line 5 in Meadow.CLI.Core/CloudServices/Messages/User.cs

View workflow job for this annotation

GitHub Actions / Build Mac 2022 Extension

Non-nullable property 'Id' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 5 in Meadow.CLI.Core/CloudServices/Messages/User.cs

View workflow job for this annotation

GitHub Actions / Build Mac 2019 Extension

Non-nullable property 'Id' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public string Email { get; set; }

Check warning on line 6 in Meadow.CLI.Core/CloudServices/Messages/User.cs

View workflow job for this annotation

GitHub Actions / Build Mac 2022 Extension

Non-nullable property 'Email' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 6 in Meadow.CLI.Core/CloudServices/Messages/User.cs

View workflow job for this annotation

GitHub Actions / Build Mac 2019 Extension

Non-nullable property 'Email' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public string FirstName { get; set; }

Check warning on line 7 in Meadow.CLI.Core/CloudServices/Messages/User.cs

View workflow job for this annotation

GitHub Actions / Build Mac 2022 Extension

Non-nullable property 'FirstName' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 7 in Meadow.CLI.Core/CloudServices/Messages/User.cs

View workflow job for this annotation

GitHub Actions / Build Mac 2019 Extension

Non-nullable property 'FirstName' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public string LastName { get; set; }

Check warning on line 8 in Meadow.CLI.Core/CloudServices/Messages/User.cs

View workflow job for this annotation

GitHub Actions / Build Mac 2019 Extension

Non-nullable property 'LastName' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public string FullName { get; set; }
}
Loading
Loading