-
Notifications
You must be signed in to change notification settings - Fork 1
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
Admin CLI for sending announcements to all identities #1031
Admin CLI for sending announcements to all identities #1031
Conversation
<ItemGroup> | ||
<None Remove="appsettings.json" /> | ||
<Content Include="appsettings.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</Content> | ||
</ItemGroup> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be necessary. As far as I know, appsettings.json files are copied by default. At least that's how it works in the other projects (e.g. ConsumerApi)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll check that
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</Content> | ||
</ItemGroup> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should add the following lines (it's done like this in all the other application .csproj
's):
<Target Name="PreBuild" BeforeTargets="Build" Condition="$(Configuration) == Debug">
<Delete Files="$(ProjectDir)appsettings.override.json" />
<Copy SourceFiles="..\..\..\..\appsettings.override.json" DestinationFolder="$(ProjectDir)" UseHardlinksIfPossible="true" />
</Target>
And I just noticed that I forgot one major thing: since so far the Admin CLI only used two parameters (DB provider and DB connection string), I didn't feel the need to add the full configuration stuff). But now that we need a lot more than that, we should add configuration as we do it in the other projects, like in the ConsumerApi. See
backbone/Applications/ConsumerApi/src/Program.cs
Lines 219 to 236 in 019ea5b
static void LoadConfiguration(WebApplicationBuilder webApplicationBuilder, string[] strings) | |
{ | |
webApplicationBuilder.Configuration.Sources.Clear(); | |
var env = webApplicationBuilder.Environment; | |
webApplicationBuilder.Configuration | |
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false) | |
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: false) | |
.AddJsonFile("appsettings.override.json", optional: true, reloadOnChange: true); | |
if (env.IsDevelopment()) | |
{ | |
var appAssembly = Assembly.Load(new AssemblyName(env.ApplicationName)); | |
webApplicationBuilder.Configuration.AddUserSecrets(appAssembly, optional: true); | |
} | |
webApplicationBuilder.Configuration.AddEnvironmentVariables(); | |
webApplicationBuilder.Configuration.AddCommandLine(strings); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add that
var severity = new Option<string?>("--severity") | ||
{ | ||
IsRequired = true, | ||
Description = "The severity of the announcement." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be good to add a list of possible values to the description of this option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add that suggestion
{ | ||
var severity = severityInput switch | ||
{ | ||
_ when string.IsNullOrWhiteSpace(severityInput) => AnnouncementSeverity.Low, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't we agree on removing the default value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. Will be removed.
|
||
if (input == null || !input.Trim().Equals("x", StringComparison.CurrentCultureIgnoreCase)) continue; | ||
|
||
input = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if I'm missing something, but to me it looks as if with this line you always return null
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah looks little wired. That term is not required and gets removed (input == null ||
if (texts.Count == 0) | ||
{ | ||
Console.WriteLine(@"No texts provided. Exiting..."); | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not necessary to do this check. This is already done by the MediatR command validator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see no good reson why not do an early exit, before the MeditR validator gets called, but ok I can remove that check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I usually don't like duplicating the validation logic. More places where you have to remember to change things if you want to.
But yeah, on the other hand I'm also a friend of early returns. Debatable. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding these settings into appsettings.json
is not good. The appsettings.json
file is only meant for default values that make sense in any environment. But a rabbitmq event bus for example doesn't fulfill this criteria.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll adopt it as it's done in AdminApi
var configuration = new ConfigurationBuilder() | ||
.SetBasePath(Directory.GetCurrentDirectory()) | ||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) | ||
.Build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be replaced with what I wrote in one of my first comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
# Ensure the appsettings.json file is copied to the correct location | ||
COPY appsettings.json /app/appsettings.json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, and BTW it doesn't work :-(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's see if it works once you're done with the other configuration related changes
|
||
namespace Backbone.AdminCli.Configuration; | ||
|
||
public class DevicesCliConfiguration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public class DevicesCliConfiguration | |
public class DevicesConfiguration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can rename it.
Pull request was closed
Readiness checklist