This library contains utils that can be used to integrate with the Redhat Openshift cloud plattform of the Federal Office of Information Technology, Systems and Telecommunication FOITT.
Additionally, it offers some general helpers
IEmailServicebased on MailKit- Serilog Formatter for optimal integration with Splunk in the FOITT
- An
HtmlNormalizerthat can streamline HTML by removing styles, images, tags and more based on what is configured inHtmlNormalizerOptions. - Some converters
The latest NuGet package is published at https://www.nuget.org/packages/Swiss.FCh.Utils.
Use IServiceCollection.AddEmailService() to register the Swiss.FCh.Utils.Services.IEmailService in your DI container.
A configuration section like the following must be present in your app settings.
{
"EmailService": {
"Host": "my_smtp_server",
"Port": "my_smtp_port"
}
}Sending an e-mail could then be implemented as follows.
var message = new Email
{
From = new EmailAddress { Address = "from@example.com", Name = "From" },
To = [new EmailAddress {Address = "to@example.com", Name = "To"}],
Subject = "Test Subject",
TextMessage = "Hello World"
};
await service.Send(message);In your appsettings.json, configure Serilog as follows.
"Serilog": {
"WriteTo": [
{
"Name": "Console",
"Args": {
"formatter": "Swiss.FCh.Utils.Logging.SerilogFormatter, Swiss.FCh.Utils"
}
}
]
}- Use
IHostApplicationBuilder.AddRhosConfigurations("YOUR_STAGE")to read environment configurations. - Add PGSQL DB secrets like this:
IHostApplicationBuilder.AddRhosPostgresConfiguration("YOUR_STAGE", "path-to-your/pg-database-credentials.json") - Add S3 secrets like this:
IHostApplicationBuilder.AddRhosS3Configuration("YOUR_STAGE", "path-to-your/s3-credentials.json")
Use IServiceCollection.AddHtmlNormalizer() to register the Swiss.FCh.Utils.Services.IHtmlNormalizer in your DI container.
Then call Swiss.FCh.Utils.Services.IHtmlNormalizer.Normalize("your HTML", new HtmlNormalizerOptions { ... }).
The HtmlNormalizerOptions allow you to configure the following:
RemoveClassesremoves all classes from the HTML (e.g.<div class="my-class">will result in<div>).RemoveStylesremoves all styles from the HTML (e.g.<div style="display: block">will result in<div>).RemoveImagesremoves all<img>tags from the HTML.RemoveEmptyAnchorsremoves all<a>tags with nohref(it will keep the content of the<a>tag as content of its parent).RemoveSpansremoves all<span>tags and adds their content to its parent. This is only applied, ifRemoveStyles,ReplaceItalicWithEmphasisandReplaceBoldWithStrongare enabled.ReplaceItalicWithEmphasisreplaces<i>with<em>.ReplaceBoldWithStrongreplaces<b>with<strong>.
See: https://github.com/swiss/fch-urils/blob/main/CONTRIBUTING.md
See: https://github.com/swiss/fch-utils/blob/main/SECURITY.md
To publish a new version of the NuGet package, proceed as follows.
- apply and push your changes
- define and describe the new version in
CHANGELOG.md - push the corresponding label with
git tag vx.x.xandgit push origin vx.x.x - go to GitHub -> Actions -> 'Build and Publish to NuGet.org' and trigger a run while specifying the correct GIT label