Example #1
0
        /// <summary>
        /// The entry point method.
        /// </summary>
        /// <param name="args">The arguments.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        public static async Task Main(string[] args)
        {
            IHostBuilder builder = Host.CreateDefaultBuilder();

            builder.ConfigureServices((ctx, services) =>
            {
                services.AddJsonNetSerializerSettingsProvider();
                services.AddJsonNetPropertyBag();
                services.AddJsonNetCultureInfoConverter();
                services.AddJsonNetDateTimeOffsetToIso8601AndUnixTimeConverter();
                services.AddSingleton <JsonConverter>(new StringEnumConverter(true));

                var msiTokenSourceOptions = new LegacyAzureServiceTokenProviderOptions
                {
                    AzureServicesAuthConnectionString = ctx.Configuration["AzureServicesAuthConnectionString"],
                };

                services.AddServiceIdentityAzureTokenCredentialSourceFromLegacyConnectionString(msiTokenSourceOptions);
                services.AddMicrosoftRestAdapterForServiceIdentityAccessTokenSource();

                var tenancyClientOptions = new TenancyClientOptions
                {
                    TenancyServiceBaseUri          = new Uri(ctx.Configuration["TenancyClient:TenancyServiceBaseUri"]),
                    ResourceIdForMsiAuthentication = ctx.Configuration["TenancyClient:ResourceIdForMsiAuthentication"],
                };

                services.AddSingleton(tenancyClientOptions);

                services.AddTenantProviderServiceClient();
            });

            await builder.RunCommandLineApplicationAsync <TenancyCliCommand>(args).ConfigureAwait(false);
        }
Example #2
0
        /// <summary>
        /// Adds services required by the command line application to the service collection.
        /// </summary>
        /// <param name="services">The service collection to add to.</param>
        /// <param name="config">The <see cref="IConfiguration"/>.</param>
        /// <returns>The service collection, for chaining.</returns>
        public static IServiceCollection AddMarainServices(this IServiceCollection services, IConfiguration config)
        {
            services.AddLogging(config => config.AddConsole());

            services.AddJsonNetSerializerSettingsProvider();
            services.AddJsonNetPropertyBag();
            services.AddJsonNetCultureInfoConverter();
            services.AddJsonNetDateTimeOffsetToIso8601AndUnixTimeConverter();
            services.AddSingleton <JsonConverter>(new StringEnumConverter(true));

            var msiTokenSourceOptions = new AzureManagedIdentityTokenSourceOptions
            {
                AzureServicesAuthConnectionString = config["AzureServicesAuthConnectionString"],
            };

            services.AddAzureManagedIdentityBasedTokenSource(msiTokenSourceOptions);

            TenancyClientOptions tenancyClientOptions = config.GetSection("TenancyClient").Get <TenancyClientOptions>();

            services.AddSingleton(tenancyClientOptions);
            services.AddTenantProviderServiceClient();

            services.AddMarainTenantManagement();

            return(services);
        }
        public static void PerFeatureContainerSetup(FeatureContext featureContext)
        {
            ContainerBindings.ConfigureServices(
                featureContext,
                services =>
            {
                var configBuilder = new ConfigurationBuilder();
                configBuilder.AddConfigurationForTest("appsettings.json");
                IConfigurationRoot config = configBuilder.Build();
                services.AddSingleton <IConfiguration>(config);

                services.AddLogging();
                services.AddOpenApiJsonSerializerSettings();

                // Tenancy service client.
                services.AddSingleton(sp =>
                {
                    TenancyClientOptions tenancyConfiguration = sp.GetRequiredService <IConfiguration>().GetSection("TenancyClient").Get <TenancyClientOptions>();

                    if (tenancyConfiguration?.TenancyServiceBaseUri == default)
                    {
                        throw new InvalidOperationException("Could not find a configuration value for TenancyClient:TenancyServiceBaseUri");
                    }

                    return(tenancyConfiguration);
                });

                // Disable response caching here so that it doesn't affect the TransientTenantManager.
                services.AddTenantProviderServiceClient(false);

                // Token source, to provide authentication when accessing external services.
                services.AddAzureManagedIdentityBasedTokenSource(
                    sp => new AzureManagedIdentityTokenSourceOptions
                {
                    AzureServicesAuthConnectionString = sp.GetRequiredService <IConfiguration>()["AzureServicesAuthConnectionString"],
                });

                // Marain tenancy management, required to create transient client/service tenants.
                services.AddMarainTenantManagement();

                // Add the tenanted table store for notifications so we can clear up our own mess after the test.
                services.AddTenantedAzureTableUserNotificationStore(
                    sp => new TenantCloudTableFactoryOptions
                {
                    AzureServicesAuthConnectionString = sp.GetRequiredService <IConfiguration>()["AzureServicesAuthConnectionString"],
                });

                // Add the tenanted blob store for the notification tempalte store so we can clear up our own mess after the test.
                services.AddTenantedAzureBlobTemplateStore(
                    sp => new TenantCloudBlobContainerFactoryOptions
                {
                    AzureServicesAuthConnectionString = sp.GetRequiredService <IConfiguration>()["AzureServicesAuthConnectionString"],
                });

                services.RegisterCoreUserNotificationsContentTypes();

                services.EnsureDateTimeOffsetConverterNotPresent();
            });
        }
        /// <summary>
        /// Configures common services required by both management and delivery channel APIs.
        /// </summary>
        /// <param name="services">The service collection.</param>
        /// <returns>The service collection, to enable chaining.</returns>
        public static IServiceCollection AddCommonUserNotificationsApiServices(
            this IServiceCollection services)
        {
            // Monitoring - for better AppInsights integration
            services.AddApplicationInsightsInstrumentationTelemetry();

            services.AddOpenApiJsonSerializerSettings();

            // Marain services integration, allowing shorthand calls to get and validate the current tenant in operation implementations.
            services.AddMarainServiceConfiguration();
            services.AddMarainServicesTenancy();

            // Tenancy service client.
            services.AddSingleton(sp =>
            {
                TenancyClientOptions tenancyConfiguration = sp.GetRequiredService <IConfiguration>().GetSection("TenancyClient").Get <TenancyClientOptions>();

                if (tenancyConfiguration?.TenancyServiceBaseUri == default)
                {
                    throw new OpenApiServiceMismatchException("Could not find a configuration value for TenancyClient:TenancyServiceBaseUri");
                }

                return(tenancyConfiguration);
            });

            services.AddTenantProviderServiceClient();

            // Operations control client
            services.AddOperationsControlClient(
                sp =>
            {
                MarainOperationsControlClientOptions operationsConfiguration =
                    sp.GetRequiredService <IConfiguration>().GetSection("Operations").Get <MarainOperationsControlClientOptions>();

                if (operationsConfiguration?.OperationsControlServiceBaseUri == default)
                {
                    throw new OpenApiServiceMismatchException("Could not find a configuration value for Operations:OperationsControlServiceBaseUri");
                }

                return(operationsConfiguration);
            });

            // Token source, to provide authentication when accessing external services.
            services.AddAzureManagedIdentityBasedTokenSource(
                sp => new AzureManagedIdentityTokenSourceOptions
            {
                AzureServicesAuthConnectionString = sp.GetRequiredService <IConfiguration>()["AzureServicesAuthConnectionString"],
            });

            // Notification storage
            services.AddTenantedAzureTableUserNotificationStore(
                sp => new TenantCloudTableFactoryOptions
            {
                AzureServicesAuthConnectionString = sp.GetRequiredService <IConfiguration>()["AzureServicesAuthConnectionString"],
            });

            return(services);
        }
Example #5
0
        public static void PerFeatureContainerSetup(FeatureContext featureContext)
        {
            ContainerBindings.ConfigureServices(
                featureContext,
                services =>
            {
                var configBuilder = new ConfigurationBuilder();
                configBuilder.AddConfigurationForTest("appsettings.json");
                IConfigurationRoot config = configBuilder.Build();
                services.AddSingleton <IConfiguration>(config);

                services.AddLogging(x => x.AddConsole());

                services.AddJsonNetSerializerSettingsProvider();
                services.AddJsonNetPropertyBag();
                services.AddJsonNetCultureInfoConverter();
                services.AddJsonNetDateTimeOffsetToIso8601AndUnixTimeConverter();
                services.AddSingleton <JsonConverter>(new StringEnumConverter(new CamelCaseNamingStrategy()));

                // Tenancy service client.
                TenancyClientOptions tenancyConfiguration = config.GetSection("TenancyClient").Get <TenancyClientOptions>();

                if (tenancyConfiguration?.TenancyServiceBaseUri is null)
                {
                    throw new InvalidOperationException("Could not find a configuration value for TenancyClient:TenancyServiceBaseUri");
                }

                services.AddSingleton(tenancyConfiguration);

                // Disable tenant caching - necessary because we create/update tenants as part of setup.
                services.AddTenantProviderServiceClient(false);

                // Token source, to provide authentication when accessing external services.
                string azureServicesAuthConnectionString = config["AzureServicesAuthConnectionString"];
                services.AddServiceIdentityAzureTokenCredentialSourceFromLegacyConnectionString(azureServicesAuthConnectionString);
                services.AddMicrosoftRestAdapterForServiceIdentityAccessTokenSource();

                // Marain tenancy management, required to create transient client/service tenants.
                services.AddMarainTenantManagement();
            });
        }
Example #6
0
        public static void SetupFeature(FeatureContext featureContext)
        {
            ContainerBindings.ConfigureServices(
                featureContext,
                services =>
            {
                IConfigurationBuilder configurationBuilder = new ConfigurationBuilder()
                                                             .AddEnvironmentVariables()
                                                             .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

                IConfiguration root = configurationBuilder.Build();

                services.AddSingleton(root);
                services.AddJsonNetSerializerSettingsProvider();
                services.AddJsonNetPropertyBag();
                services.AddJsonNetCultureInfoConverter();
                services.AddJsonNetDateTimeOffsetToIso8601AndUnixTimeConverter();
                services.AddSingleton <JsonConverter>(new StringEnumConverter(new CamelCaseNamingStrategy()));

                string azureServicesAuthConnectionString = root["AzureServicesAuthConnectionString"];
                services.AddServiceIdentityAzureTokenCredentialSourceFromLegacyConnectionString(azureServicesAuthConnectionString);
                services.AddMicrosoftRestAdapterForServiceIdentityAccessTokenSource();

                services.AddSingleton(sp => sp.GetRequiredService <IConfiguration>().GetSection("TenancyClient").Get <TenancyClientOptions>());

                TenancyClientOptions tenancyClientConfiguration = root.GetSection("TenancyClient").Get <TenancyClientOptions>();
                services.AddSingleton(tenancyClientConfiguration);
                services.AddTenantProviderServiceClient();

                services.AddTenantedClaimsStoreOnAzureBlobStorage();
                services.AddTenantedClaimsApiWithOpenApiActionResultHosting(root);

                services.AddClaimsClient(_ =>
                {
                    return(new ClaimsClientOptions
                    {
                        BaseUri = new Uri($"http://localhost:{FunctionBindings.ClaimsHostPort}"),
                    });
                });
            });
        }