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

Formatting: fixes 3331 - removes nuspec from microservice runtime (#3368) #3370

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 8 additions & 8 deletions cli/cli/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public App()

private static LogConfigData ConfigureLogging(App app, Func<LoggerConfiguration, ILogger> configureLogger = null)
{

var tempFile = Path.Combine(Path.GetTempPath(), "beamCliLog.txt");
var shouldUseTempFile = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("BEAM_CLI_NO_FILE_LOG"));
try
Expand Down Expand Up @@ -148,7 +148,7 @@ private void ConfigureServices(IDependencyBuilder services)
services.AddSingleton<IDataReporterService, DataReporterService>();
services.AddSingleton<ServerService>();
services.AddSingleton<AppLifecycle>();

OpenApiRegistration.RegisterOpenApis(services);

_serviceConfigurator?.Invoke(services);
Expand All @@ -158,7 +158,7 @@ private void ConfigureServices(IDependencyBuilder services)
Action<IDependencyBuilder> serviceConfigurator = null,
Action<IDependencyBuilder> commandConfigurator = null,
Func<LoggerConfiguration, ILogger> configureLogger = null,
LogConfigData prebuiltLogger=null
LogConfigData prebuiltLogger = null
)
{
if (IsBuilt)
Expand Down Expand Up @@ -321,7 +321,7 @@ private void ConfigureServices(IDependencyBuilder services)


// content commands

Commands.AddRootCommand<ContentCommand>();
Commands.AddSubCommandWithHandler<ContentPullCommand, ContentPullCommandArgs, ContentCommand>();
Commands.AddSubCommandWithHandler<ContentStatusCommand, ContentStatusCommandArgs, ContentCommand>();
Expand Down Expand Up @@ -431,7 +431,7 @@ protected virtual Parser GetProgram()
});

var commandLineBuilder = new CommandLineBuilder(root);

// this middleware is responsible for catching parse errors and putting them on the data-out raw channel
commandLineBuilder.AddMiddleware((ctx, next) =>
{
Expand All @@ -445,7 +445,7 @@ protected virtual Parser GetProgram()
var appContext = provider.GetService<IAppContext>();
var reporter = provider.GetService<IDataReporterService>();
var isPiping = appContext.UsePipeOutput || appContext.ShowRawOutput;

if (!isPiping)
{
// we aren't using raw output, so this middleware has nothing to do.
Expand All @@ -457,9 +457,9 @@ protected virtual Parser GetProgram()
reporter.Exception(ex, ctx.ExitCode, ctx.BindingContext.ParseResult.Diagram());
// don't call the next task, because we have "handled" the error by posting it to the error channel
return Task.CompletedTask;

}, MiddlewareOrder.ErrorReporting);

commandLineBuilder.AddMiddleware(consoleContext =>
{
// create a scope for the execution of the command
Expand Down
2 changes: 1 addition & 1 deletion cli/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ In most cases, this is as trivial as renaming the type inside the microservice t
- Microservices install with current CLI version
- Standalone Microservices no longer have a `LoadEnvironmentVariables` method, and connection strings are handled in the existing `Prepare` method.
- `beam project generate-env` command writes a blank `.env` file and returns connection strings over STDOUT instead.
- Generating microservice clients for Unreal now outputs them to a Plugin called `[ProjectName]MicroserviceClients` instead of placing it in some existing module. Update flow:
- Generating microservice clients for Unreal now outputs them to a Plugin called `[ProjectName]MicroserviceClients` instead of placing it in some existing module. Update flow:
- Delete your microservice client files in the various `AutoGen` folders where they used to live.
- Do a clean rebuild of your microservice solution to re-run the generation.
- Add `[ProjectName]MicroserviceClients.AddMicroserviceClient(Module)` to all your `Build.cs` files of modules in which you want to use the clients.
Expand Down
2 changes: 1 addition & 1 deletion cli/cli/CommandContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public override async Task Handle(TArgs args)

var reporter = args.Provider.GetService<IDataReporterService>();
reporter.Report(_channel.ChannelName, result);

if (AutoLogOutput)
{
LogResult(result);
Expand Down
12 changes: 6 additions & 6 deletions cli/cli/Commands/CliServerCommand/RequestCliCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class RequestCliCommandArgs : CommandArgs

public class RequestCliCommandOutput
{

}

public class RequestCliCommand : StreamCommand<RequestCliCommandArgs, RequestCliCommandOutput>
Expand All @@ -39,14 +39,14 @@ public override void Configure()
public override async Task Handle(RequestCliCommandArgs args)
{
var client = new HttpClient();

var req = new HttpRequestMessage(HttpMethod.Post, $"http://127.0.0.1:{args.port}/execute");

var json = JsonConvert.SerializeObject(new ServerRequest() { commandLine = args.commandLine });

req.Content = new StringContent(json, Encoding.UTF8, "application/json");


try
{
Log.Information("sending request " + json);
Expand All @@ -60,14 +60,14 @@ public override async Task Handle(RequestCliCommandArgs args)
{
Log.Debug("waiting for next chunk of data...");
var line = await reader.ReadLineAsync();

if (string.IsNullOrEmpty(line)) continue; // TODO: what if the message contains a \n character?
line = line.Replace("\u200b", ""); // remove life-cycle zero-width character

if (!line.StartsWith("data: ")) continue;

var lineJson = line.Substring("data: ".Length); // remove the Server-Side-Event notation

Log.Information("received, " + lineJson);

}
Expand Down
6 changes: 3 additions & 3 deletions cli/cli/Commands/CliServerCommand/ServeCliCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public override void Configure()
new Argument<string>("owner", () => "cli",
"The owner of the server is used to identify the server later with the /info endpoint"),
(args, owner) => args.owner = owner);

var portOption = new Option<int>("--port", () => 8342, "The port the local server will bind to");
portOption.AddAlias("-p");
AddOption(portOption, (args, port) => args.port = port);
Expand All @@ -47,7 +47,7 @@ public override void Configure()
"When true, if the given --port is not available, it will be incremented until an available port is discovered");
incPortOption.AddAlias("-i");
AddOption(incPortOption, (args, inc) => args.incPortUntilSuccess = inc);

var timerOption = new Option<int>("--self-destruct-seconds", () => 0,
"The number of seconds the server will stay alive without receiving any traffic. A value of zero means there is no self destruct timer");
timerOption.AddAlias("-d");
Expand All @@ -59,7 +59,7 @@ public override async Task Handle(ServeCliCommandArgs args)
{
args.logData = _logData;
var server = args.Provider.GetService<ServerService>();

await server.RunServer(args, data =>
{
this.SendResults(new ServeCliCommandOutput
Expand Down
218 changes: 109 additions & 109 deletions cli/cli/Commands/Content/ContentBulkEditCommand.cs
Original file line number Diff line number Diff line change
@@ -1,109 +1,109 @@
using cli.Services.Content;
using System.CommandLine;
using System.Text.Json;

namespace cli.Content;

public class ContentBulkEditCommand : AppCommand<ContentBulkEditCommandArgs>, IEmptyResult
{
private static readonly Option<string[]> CONTENT_ID_OPTION = new("--content-ids", Array.Empty<string>, "An array of existing content ids");

private static readonly Option<string[]> CONTENT_PROPERTIES_ID_OPTION =
new("--content-properties", Array.Empty<string>, "An array, parallel to the --content-ids, that contain the escaped properties json for each content");

private ContentService _contentService;

public ContentBulkEditCommand() : base("bulk-edit", "Saves a serialized content properties JSON-blob into a manifest")
{
}

public override void Configure()
{
AddOption(ContentCommand.MANIFESTS_FILTER_OPTION, (args, s) => args.ManifestIds = s);
AddOption(CONTENT_ID_OPTION, (args, s) => args.ContentIds = s);
AddOption(CONTENT_PROPERTIES_ID_OPTION, (args, s) => args.ContentProperties = s);
}

public override async Task Handle(ContentBulkEditCommandArgs args)
{
_contentService = args.ContentService;

// Ensure Manifest Ids is correct
if (args.ManifestIds.Length == 0)
args.ManifestIds = new[] { "global" };
else if (args.ManifestIds.Length > 1)
throw new CliException("Must pass a single Manifest Id per-command invocation.", 6, true);

var manifestId = args.ManifestIds[0];

// Tries to load the local content --- this command does not work unless the manifest is already known.
var localCache = _contentService.GetLocalCache(manifestId);

// Invalid args
if (args.ContentIds.Length != args.ContentProperties.Length)
throw new CliException("Content Ids and Content Properties have different lengths. Please provide parallel arrays for these options.", 2, true);

var updatedDocuments = new List<ContentDocument>(args.ContentIds.Length);
var notFoundIds = new List<string>(args.ContentIds.Length);
var invalidProperties = new List<(int idx, string id, string errMsg)>(args.ContentIds.Length);
for (int i = 0; i < args.ContentIds.Length; i++)
{
string id = args.ContentIds[i];
string properties = args.ContentProperties[i];

// This command does not create new content objects; so, we check if the given id already exists before proceeding.
if (localCache.GetContent(id) == null)
{
notFoundIds.Add(id);
continue;
}

// Check if the property JSON is valid
JsonElement? propertiesJson;
try
{
propertiesJson = JsonSerializer.Deserialize<JsonElement>(properties);
}
catch (Exception e)
{
invalidProperties.Add((i, id, e.Message));
continue;
}

var contentToAdd = new ContentDocument() { id = id, properties = propertiesJson, };
updatedDocuments.Add(contentToAdd);
}

// If we the given ids are non-existent, we notify the user.
if (notFoundIds.Count > 0)
{
var err = $"Content Id provided was not found in the given manifest. IDs={string.Join(",", notFoundIds)}";
throw new CliException(err, 3, true);
}

// If we failed to parse any of the JSON, we notify the user.
if (invalidProperties.Count > 0)
{
var err = $"Failed to parse Content Properties. Parsing Errors:\n{string.Join("\n", invalidProperties.Select(ip => $"[{ip.idx}] {ip.id} -> {ip.errMsg}"))}";
throw new CliException(err, 4, true);
}

// Save the actual updated content
try
{
var updateTasks = updatedDocuments.Select(d => localCache.UpdateContent(d));
await Task.WhenAll(updateTasks);
}
catch (Exception e)
{
var err = $"Failed to save Content. Errors:{e.Message}";
throw new CliException(err, 5, true);
}
}
}

public class ContentBulkEditCommandArgs : ContentCommandArgs
{
public string[] ContentIds;
public string[] ContentProperties;
}
using cli.Services.Content;
using System.CommandLine;
using System.Text.Json;
namespace cli.Content;
public class ContentBulkEditCommand : AppCommand<ContentBulkEditCommandArgs>, IEmptyResult
{
private static readonly Option<string[]> CONTENT_ID_OPTION = new("--content-ids", Array.Empty<string>, "An array of existing content ids");
private static readonly Option<string[]> CONTENT_PROPERTIES_ID_OPTION =
new("--content-properties", Array.Empty<string>, "An array, parallel to the --content-ids, that contain the escaped properties json for each content");
private ContentService _contentService;
public ContentBulkEditCommand() : base("bulk-edit", "Saves a serialized content properties JSON-blob into a manifest")
{
}
public override void Configure()
{
AddOption(ContentCommand.MANIFESTS_FILTER_OPTION, (args, s) => args.ManifestIds = s);
AddOption(CONTENT_ID_OPTION, (args, s) => args.ContentIds = s);
AddOption(CONTENT_PROPERTIES_ID_OPTION, (args, s) => args.ContentProperties = s);
}
public override async Task Handle(ContentBulkEditCommandArgs args)
{
_contentService = args.ContentService;
// Ensure Manifest Ids is correct
if (args.ManifestIds.Length == 0)
args.ManifestIds = new[] { "global" };
else if (args.ManifestIds.Length > 1)
throw new CliException("Must pass a single Manifest Id per-command invocation.", 6, true);
var manifestId = args.ManifestIds[0];
// Tries to load the local content --- this command does not work unless the manifest is already known.
var localCache = _contentService.GetLocalCache(manifestId);
// Invalid args
if (args.ContentIds.Length != args.ContentProperties.Length)
throw new CliException("Content Ids and Content Properties have different lengths. Please provide parallel arrays for these options.", 2, true);
var updatedDocuments = new List<ContentDocument>(args.ContentIds.Length);
var notFoundIds = new List<string>(args.ContentIds.Length);
var invalidProperties = new List<(int idx, string id, string errMsg)>(args.ContentIds.Length);
for (int i = 0; i < args.ContentIds.Length; i++)
{
string id = args.ContentIds[i];
string properties = args.ContentProperties[i];
// This command does not create new content objects; so, we check if the given id already exists before proceeding.
if (localCache.GetContent(id) == null)
{
notFoundIds.Add(id);
continue;
}
// Check if the property JSON is valid
JsonElement? propertiesJson;
try
{
propertiesJson = JsonSerializer.Deserialize<JsonElement>(properties);
}
catch (Exception e)
{
invalidProperties.Add((i, id, e.Message));
continue;
}
var contentToAdd = new ContentDocument() { id = id, properties = propertiesJson, };
updatedDocuments.Add(contentToAdd);
}
// If we the given ids are non-existent, we notify the user.
if (notFoundIds.Count > 0)
{
var err = $"Content Id provided was not found in the given manifest. IDs={string.Join(",", notFoundIds)}";
throw new CliException(err, 3, true);
}
// If we failed to parse any of the JSON, we notify the user.
if (invalidProperties.Count > 0)
{
var err = $"Failed to parse Content Properties. Parsing Errors:\n{string.Join("\n", invalidProperties.Select(ip => $"[{ip.idx}] {ip.id} -> {ip.errMsg}"))}";
throw new CliException(err, 4, true);
}
// Save the actual updated content
try
{
var updateTasks = updatedDocuments.Select(d => localCache.UpdateContent(d));
await Task.WhenAll(updateTasks);
}
catch (Exception e)
{
var err = $"Failed to save Content. Errors:{e.Message}";
throw new CliException(err, 5, true);
}
}
}
public class ContentBulkEditCommandArgs : ContentCommandArgs
{
public string[] ContentIds;
public string[] ContentProperties;
}
2 changes: 1 addition & 1 deletion cli/cli/Commands/Content/ContentCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class ContentCommand : CommandGroup
{
public static readonly Option<string[]> MANIFESTS_FILTER_OPTION =
new("--manifest-ids", Array.Empty<string>, "Inform a subset of ','-separated manifest ids for which to return data. By default, will return all manifests");


public ContentCommand() : base("content", "Open content folder in file explorer")
{
Expand Down