Пример #1
0
        private void Initialize()
        {
            var token = authorization.GetToken().Result;

            Container.Instance.feedRepo = AzureCosmosDocRepository.CreateAzureCosmosDocRepository("FeedCollection", token).Result;
            Container.Instance.userRepo = AzureCosmosDocRepository.CreateAzureCosmosDocRepository("UserCollection", token).Result;
        }
Пример #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger <Startup> logger)
        {
            // Enable middleware to serve generated Swagger as a JSON endpoint.
            app.UseSwagger();

            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
            // specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "API V1");
                //c.RoutePrefix = string.Empty;
            });

            logger.LogInformation($"Application: {env?.ApplicationName} Environment: {env.EnvironmentName}");
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();
            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            // Create Azure resources

            // Connect to the Azure Cosmos
            DocumentClient client = new DocumentClient(
                new Uri(Configuration.GetSection("CosmosDb")["EndPoint"]),
                GetSecret(Configuration.GetSection("CosmosDb")["Key"]).Result);

            PartyFindsApi.core.Container.Instance.listingsRepo =
                AzureCosmosDocRepository.CreateAzureCosmosDocRepository("Listings", client).Result;
            PartyFindsApi.core.Container.Instance.messageRepo =
                AzureCosmosDocRepository.CreateAzureCosmosDocRepository("Messages", client).Result;
            PartyFindsApi.core.Container.Instance.notificationsRepo =
                AzureCosmosDocRepository.CreateAzureCosmosDocRepository("Notifications", client).Result;
            PartyFindsApi.core.Container.Instance.userRepo =
                AzureCosmosDocRepository.CreateAzureCosmosDocRepository("Users", client).Result;

            // TODO: Old code based on Token. Migrate to KeyVault or managed identity
            //var token = GetToken().Result;
            //core.Container.Instance.listingsRepo = AzureCosmosDocRepository.CreateAzureCosmosDocRepository("Listings", token).Result;

            // Blob Container
            string endpointSuffix = Configuration.GetValue <string>("Storage:EndpointSuffix");

            if (!string.IsNullOrEmpty(endpointSuffix))
            {
                endpointSuffix = $";EndpointSuffix={endpointSuffix}";
            }

            BlobServiceClient blobServiceClient = new BlobServiceClient
                                                      ($"DefaultEndpointsProtocol=http;" +
                                                      $"AccountName={Configuration.GetValue<string>("Storage:AccountName")};" +
                                                      $"AccountKey={GetSecret(Configuration.GetValue<string>("Storage:Key")).Result};" +
                                                      $"{endpointSuffix};BlobEndpoint={Configuration.GetValue<string>("Storage:BlobEndpoint")};");

            core.Container.Instance.uploadsContainer = blobServiceClient.GetBlobContainerClient("uploads");
            core.Container.Instance.uploadsContainer.CreateIfNotExists();
        }