public static IServiceCollection AddAutomationAuth(this IServiceCollection services, IConfiguration authenticationSection, IConfiguration authorizationSection) { var authorizationOptions = authorizationSection.Get <GitAutomation.Auth.AuthorizationOptions>(); foreach (var plugin in authorizationOptions.Types.Select(PluginActivator.GetPluginOrNull <IRegisterPrincipalValidation>)) { plugin?.RegisterPrincipalValidation(services, authorizationSection); } var authBuilder = services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => { options.Events = new CookieAuthenticationEvents { OnValidatePrincipal = async(context) => { var principalValidation = context.HttpContext.RequestServices.GetServices <IPrincipalValidation>(); var currentPrincipal = context.Principal; foreach (var entry in principalValidation) { currentPrincipal = await entry.OnValidatePrincipal(context.HttpContext, currentPrincipal); if (currentPrincipal == null) { context.RejectPrincipal(); break; } } if (currentPrincipal != null) { context.ReplacePrincipal(currentPrincipal); } } }; }); var authenticationOptions = authenticationSection.Get <AuthenticationOptions>(); services.Configure <AuthenticationOptions>(authenticationSection); PluginActivator.GetPlugin <IRegisterAuthentication>( typeName: authenticationOptions.Type, errorMessage: $"Unknown git service api registry: {authenticationOptions.Type}. Specify a .Net type.`" ).RegisterAuthentication(services, authBuilder, authenticationSection); services.AddAuthorization(options => { options.AddGitAutomationPolicies(); }); return(services); }
public static IServiceCollection AddGitUtilities(this IServiceCollection services, IConfiguration persistenceConfiguration, IConfiguration repositoryConfiguration, IConfiguration appConfiguration) { services.AddSingleton <IRepositoryMediator, RepositoryMediator>(); services.AddSingleton <GitAutomation.Processes.IReactiveProcessFactory, GitAutomation.Processes.ReactiveProcessFactory>(); services.AddSingleton <IRepositoryOrchestration, RepositoryOrchestration>(); services.AddSingleton <IOrchestrationActions, OrchestrationActions>(); services.AddSingleton <IRepositoryStateDriver, RepositoryStateDriver>(); services.AddSingleton <IRemoteRepositoryState, RemoteRepositoryState>(); services.AddSingleton <ILocalRepositoryState, LocalRepositoryState>(); services.AddSingleton <IGitCli>(sp => sp.GetRequiredService <ILocalRepositoryState>().Cli); services.AddSingleton <Func <HttpClient> >(() => new HttpClient()); services.AddTransient <GitAutomation.Orchestration.Actions.IntegrateBranchesOrchestration>(); services.AddSingleton <GitAutomation.Work.IUnitOfWorkFactory, GitAutomation.Work.UnitOfWorkFactory>(); services.AddSingleton <IBranchSettingsNotifiers, BranchSettingsNotifiers>(); services.AddSingleton(appConfiguration.Get <AppOptions>() ?? new AppOptions()); var persistenceOptions = persistenceConfiguration.Get <PersistenceOptions>(); PluginActivator.GetPlugin <IRegisterBranchSettings>( typeName: persistenceOptions.Type, errorMessage: $"Unknown persistence registry: {persistenceOptions.Type}. Specify a .Net type." ).RegisterBranchSettings(services, persistenceConfiguration); var repositoryOptions = repositoryConfiguration.Get <GitRepositoryOptions>(); PluginActivator.GetPlugin <IRegisterGitServiceApi>( typeName: repositoryOptions.ApiType, errorMessage: $"Unknown git service api registry: {repositoryOptions.ApiType}. Specify a .Net type, such as `{typeof(RegisterMemory).FullName}`" ).RegisterGitServiceApi(services, repositoryConfiguration); services.AddIntegrationNamingConvention(repositoryOptions); services.AddTransient <NormalMergeStrategy>(); services.AddTransient <MergeNextIterationMergeStrategy>(); services.AddTransient <ForceFreshMergeStrategy>(); services.AddTransient <IMergeStrategyManager, MergeStrategyManager>(); return(services); }