Giter Club home page Giter Club logo

kros.aspnetcore's Introduction

kros.aspnetcore's People

Contributors

akiuu avatar bakosk avatar burgyn avatar csleead avatar jurajknutelsky avatar kubinko avatar kumecky avatar lukassefcik avatar majco333 avatar marek011 avatar michalau avatar mikado3780 avatar ml13 avatar mluh avatar motycak avatar ondrix avatar satano avatar slashersvk avatar urbanox avatar vojtechrojicek avatar wosciatko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

kros.aspnetcore's Issues

Swagger UI do not generate proper URL from appsettings.json

Library name and version

  • Kros.AspNetCore 1.0

Description

Link on SwaggerUI contain href="about:blank" attribute instead of href="someValidUrlFromAppSettings"

Steps To Reproduce

  1. Copy lines from repo readme
  2. Run App
  3. Go to domain/swagger
  4. Click to link

Expected behavior

Open proper web address from appsetings

Actual behavior

Open blank page

Bug in AddCustomOriginsCorsPolicy extension

Library name and version

  • Kros.AspNetCore 1.1.2

Steps To Reproduce

By default in appsettings.json exists "AllowedHosts": "*"
After this settings app failed with error:

Object reference not set to an instance of an ojbect.

Add BaseStartup class and use it for appsettings

  • Sharing appsettings.json...
  • Add to dotnet Template
  • Add to BestPractices project

For sharing this code:

var builder = new ConfigurationBuilder()
                .SetBasePath(env.ContentRootPath)
                .AddJsonFile("appsettings.json")
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
                .AddJsonFile($"appsettings.local.json", optional: true)
                .AddEnvironmentVariables();

Allow add multiple RequestsAssemblies in AddPipelineBehaviorsForRequest mediatR extension

It would be nice to allow add multiple request assemblies when configuring pipeline behavior for mediatR.
If command are in multiple asssemblies, it looks like:

.AddPipelineBehaviorsForRequest<ICompanySubResourceCommand>(config =>
{
    config.RequestsAssembly = Assembly.GetEntryAssembly();
})
.AddPipelineBehaviorsForRequest<ICompanySubResourceCommand>(config =>
{
    config.RequestsAssembly = typeof(CopyInvoiceCommand).Assembly;
})

Nicer version would be like

.AddPipelineBehaviorsForRequest<ICompanySubResourceCommand>(config =>
{
    config.RequestsAssemblies.Add(Assembly.GetEntryAssembly());
    config.RequestsAssemblies.Add(typeof(CopyInvoiceCommand).Assembly);
})

Expand cache in GatewayAuthorizationMiddleware

Is your feature request related to a problem? Please describe

Aktalne sa cache-uje podla jwt tokenu a path z requestu.
Ak to nie je v cache, tak sa vola autorizacna sluzba, ktora do claimov vlozi connection id.
Avsak ak sa connection id zmeni (uzivatel urobil refresh, alebo pouziva aplikaciu v 2 taboch),
tak v claimoch sa nezmeni connection id a nasledne sa preposialaju cez signalR spravy so zlym connection id.

Describe the solution you'd like

Ak request obsahuje hlavicku connection id, tak do cache pridat zaznam aj s connection id/

Additional context

Add any other context or screenshots about the feature request here.

Create new nuget project "Kros.Swagger.Extensions"

  • Add nuget "Swashbuckle.AspNetCore"
  • Add support for configure "Title", "Version" and XML comments
  • Fix problem with duplicite schemas. Use this code:

services.ConfigureSwaggerGen(options => { options.CustomSchemaIds(x => x.FullName); // https://wegotcode.com/microsoft/swagger-fix-for-dotnetcore/ });

WIP: Define topic prefix for MassTransit

General info

Nowadays it is not possible to distinguish messages from multiple environments on single service bus. Also every developer needs own service bus for testing purposes.

Solution

Support definition of message prefix in application configuration, i.e appsettings.json:

...
"AzureServiceBus": {
    "ConnectionString": "",
    "TokenTimeToLive": 60,
    "MessagePrefix": "Staging", // <=== this 
    "Endpoints": {
...

Created topic address where services can subscribe will be:
{ServiceBusAdress}/{Prefix}-{Namespace/MessageName}

Prefix can be used to specify environment (dev, test, staging, ...) or also developer (Majo, Gabo...).
Both sides, publisher and subscriber, only need to set prefix in configuration and everything should work.

Extension for IS health checks

Add extension for adding health checks for identity server.

public static class HealthChecksBuilderExtensions
   {
       public static IHealthChecksBuilder AddIdentityServerHealthChecks(this IHealthChecksBuilder healthChecksBuilder, IConfiguration configuration)
       {
           var identityServerOptions = configuration.GetSection("IdentityServerHandlers").Get<IdentityServerOptions[]>().ToList();
           foreach (var option in identityServerOptions)
           {
               healthChecksBuilder.AddUrlGroup(
                   new Uri(option.AuthorityUrl),
                   name: $" IdentityServer handler for scheme {option.AuthenticationScheme}",
                   tags: new string[] { "url" });
           }

           return healthChecksBuilder;
       }
   }

Configure appsettings.local.json in Program.CreateHostBuilder

Is your feature request related to a problem? Please describe

For using Azure app configuration need connection string to azure portal.
I need use similar code:

Host.CreateDefaultBuilder(args)    
    .ConfigureWebHostDefaults(webBuilder =>
    {                    
        webBuilder.ConfigureAppConfiguration((hostingContext, config) =>
        {                        
            var settings = config.Build();                        
            config.AddAzureAppConfiguration(options => {
                options.Connect(settings["ConnectionStrings:AppConfig"])
                    .UseFeatureFlags();
            });
        })
        .UseStartup<Startup>();
    });

File appsettings.local.json is loading in startup, but I need access in Program.CreateHostBuilder.
Appsettings.json contains only

 "ConnectionStrings": {   
    "AppConfig": ""
  }

During loading CreateHostBuilder is throw exception System.ArgumentNullException: 'Value cannot be null. (Parameter 'connectionString')', because is empty in appsetting.json.

Describe the solution you'd like

Move

config.AddJsonFile("appsettings.local.json", optional: true);

into Program.CreateHostBuilder. as extension.

Support loading configuration from key vault secrets

We do not want to have secret configuration values in appsettings.json, not even if they are set there during deployment pipeline. We should load secrets directly from key vault as configuration values.

Implementation

Adding key vault as configuration source must be simple as calling AddAzureKeyVault() method in program start:

// Minimal API
builder.Configuration.AddAzureKeyVault();

// Program.cs
public static IHostBuilder CreateWebHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureAppConfiguration(configBuilder =>
        {
            configBuilder.AddAzureKeyVault();
        });

By default configuration is loaded from KeyVault section in appsettings.json, but can be tewaked in delegate parameter of AddAzureKeyVault(options).

Configuration

"KeyVault": {
  "Name": "key-vault-name",
  "Prefixes": [ "prefix1", "prefix2" ],
  "IdentityClientId": "13cd1e37-1351-4d76-889a-9eae0fbd3c76",
  "ReloadInterval": "00:05:00"
}
  • Name: Key vault name. If set, key vault configuration source is added to configuration builder. Then secrets from that key vault are loaded into configuration. If the name is not set, nothing is done.
  • Prefixes: List of prefixes, which limits secrets which are loaded. If present, only secrets with these prefixes will be loaded. In no prefix is set, all secrets are loaded. Prefixes here are set without trailing dash (-), but secret names must contain it. For example if prefix is lorem, secrets which name starts with lorem- are loaded.
  • IdentityClientId: GUID of the user assigned managed identity, which will be used to connect to key vault. If not set, system assigned identity will be used.
  • ReloadInterval: Timespan for polling key vault for changes. If not set, reloading will be disabled.

Name of the key vault secret can not containt dot (.), nor colon (:), so double dash (--) must be used for hierarchical configuration values. For example secret with name ConnectionStrings--DefaultConnection will be used as configuration value for:

"ConnectionStrings": {
  "DefaultConnection": ""
}

If some prefix is present, the name of the secret will be prefix-ConnectionStrings--DefaultConnection.

If needed... Extensions for Health checks

Add extensions for health checks:

  • proxy support
  • json output support
  • add tests

Notes:
Report and writer
Tests

public static class UrisHealthCheckBuilderExtensions
{
///


/// Add a health check for single uri.
///

/// The .
/// The uri to check.
/// The health check name. Optional. If null the type name 'uri-group' will be used for the name.
///
/// The that should be reported when the health check fails. If null then
/// the default status of will be reported.
///
/// A list of tags that can be used to filter sets of health checks.
/// The proxy for http request. Optional
/// The .
public static IHealthChecksBuilder AddUrlGroup(this IHealthChecksBuilder builder, Uri uri, string name, Uri proxy,
HealthStatus? failureStatus = null, IEnumerable tags = null)
{
if (proxy == null)
{
builder.Services.AddHttpClient("HealthCheck");
}
else
{
builder.Services
.AddHttpClient("HealthCheck")
.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler()
{
Proxy = new WebProxy(proxy)
});
}

        var options = new UriHealthCheckOptions();
        options.AddUri(uri);

        var registrationName = name;
        return builder.Add(new HealthCheckRegistration(
            registrationName,
            sp => CreateHealthCheck(sp, registrationName, options),
            failureStatus,
            tags));
    }

    private static UriHealthCheck CreateHealthCheck(IServiceProvider sp, string name, UriHealthCheckOptions options)
    {
        var httpClientFactory = sp.GetRequiredService<IHttpClientFactory>();
        return new UriHealthCheck(options, () => httpClientFactory.CreateClient("HealthCheck"));
    }
}

Support for reading Azure feature flags with Azure app configration

During reading Azure app configuration

ConfigurationBuilderExtenstions.AddAzureAppConfiguration

is possible read also feature flags, using this code:

 options
   .Select("_", LabelFilter.Null)
   .Select("_", hostingContext.HostingEnvironment.EnvironmentName)
   .UseFeatureFlags();```

Add support for .NET Core 3.0

As ASP.NET Core 3.0 has been released a couple of weeks ago, it would be nice if this solution targeted also .NET Core 3.0. I propose multi-platform targeting, so ASP.NET Core 2.2 apps would be still supported.

Projects in need of targeting .NET Core 3.0:

  • Kros.AspNetCore
  • Kros.MassTransit.AzureServiceBus
  • Kros.MediatR.Extensions

Projects in need of package upgrade so they would support .NET Core 3.0:

  • Kros.ApplicationInsights.Extensions
  • Kros.Swagger.Extensions

Cannot forget about multi-targeting for test projects:

  • Kros.AspNetCore.Tests
  • Kros.MediatR.Extensions.Tests

Dependency Injection runtime error in MassTransit and .NET Core 3.0.

Library name and version

  • Kros.MassTransit.AzureServiceBus 1.0.0-alpha.2

Description

In some cases when using Kros.MassTransit.AzureServiceBus package to configure Azure Service Bus consumers in ASP.NET Core 3.0 app, application fails during startup with following error:
System.TypeLoadException: 'Method 'RegisterExecuteActivity' on type 'MassTransit.ExtensionsDependencyInjectionIntegration.Configuration.Registration.DependencyInjectionContainerRegistrar' from assembly 'MassTransit.ExtensionsDependencyInjectionIntegration, Version=5.5.6.0, Culture=neutral, PublicKeyToken=b8e0e9f2f1e657fa' tried to implicitly implement an interface method with weaker type parameter constraints.'

Steps To Reproduce

So far unknown. For some configuration it works, for some not.

Expected behavior

Application should start without any errors and ASB should be working.

Actual behavior

Application fails upon startup.

New Application Insight property for route pattern

Logging new application insight property for route pattern.
Now is logging full url, with all ids (DELETE/Companies/789/BankAccounts/123).
New property should log pattern (DELETE/Companies/{CompanyId}/BankAccounts/{BankAccountId})

Machine to machine authorization

Is your feature request related to a problem? Please describe

To be able to authorize a request from another API/Azure function as ‘grant_type: client_credentials’

Describe the solution you'd like

Another API/ Azure function will request an access token from IS based on given credentials (client_id, client_secret, grant_type). This token will then allow the foreign API to make requests of our API, which will be authorized against IS.

Additional context

We need to send a request from the azure function to the search service, where the user access token no longer exists (we do not want to hold it internally)

Add default development settings functionality

Add:

  • key vault extension (adds azure key vault to iconfigurationbuilder)
  • add machine name or guid to azure service bus endpoint (it should be possible to have endpoint names in development settings with placeholder for machine name or guid which should be replaced with actual development machine name or guid when running application)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.