Beispiel #1
0
 public OcrController(UserManager <IdentityUser> userManager, ApplicationDbContext dbContext)
 {
     this.userManager = userManager;
     this.dbContext   = dbContext;
     _awsAccess       = dbContext.AwsAccesses.FirstOrDefault();
     this.InitializeAwsServices();
 }
Beispiel #2
0
        public void UpdateTokens_Should_Update_AwsAccessEntity()
        {
            // arrange
            var awsAccess = new AwsAccess {
                Token = "new token", AwsAccessKeyID = "new key", AwsSecreteAccessKey = "secret"
            };

            // act
            _adminController.UpdateTokens(awsAccess).GetAwaiter().GetResult();

            // asserts
            var entity = dbContext.AwsAccesses.FirstOrDefault(x => x.Id == 1);

            Assert.Equal(entity.Token, awsAccess.Token);
            Assert.Equal(entity.AwsSecreteAccessKey, awsAccess.AwsSecreteAccessKey);
            Assert.Equal(entity.AwsAccessKeyID, awsAccess.AwsAccessKeyID);
        }
Beispiel #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Configure default endpoint limit
            // This is the value used by AWS SDK, but by explicitly setting it here
            // we are hoping to work around a deadlock bug in .NET FX being encountered
            // See https://github.com/dotnet/corefx/issues/21796
            ServicePointManager.DefaultConnectionLimit = 50;

            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddDataProtection()
            .PersistKeysToDbContext <ApplicationDbContext>();

            services.AddDbContext <ApplicationDbContext>(options =>
                                                         //  options.UseInMemoryDatabase("AWS_OCR"));
                                                         options.UseSqlServer(
                                                             Configuration.GetConnectionString("DefaultConnection")));
            services.AddDefaultIdentity <IdentityUser>()
            .AddEntityFrameworkStores <ApplicationDbContext>();

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            var provider  = services.BuildServiceProvider();
            var dbContext = provider.GetService <ApplicationDbContext>();
            var awsAccess = dbContext.AwsAccesses.FirstOrDefault();

            if (awsAccess == null)
            {
                awsAccess = new AwsAccess
                {
                    AwsAccessKeyID      = Configuration.GetValue <string>("awsaccessKeyID", null),
                    AwsSecreteAccessKey = Configuration.GetValue <string>("awsSecreteAccessKey", null),
                    Region       = Configuration.GetValue <string>("awsRegion", null),
                    Token        = Configuration.GetValue <string>("awsToken", null),
                    S3BucketName = Configuration.GetValue <string>("s3BucketName", null),
                };
                dbContext.Add(awsAccess);
            }
            dbContext.SaveChanges();
        }
Beispiel #4
0
        public async Task <IActionResult> UpdateTokens(AwsAccess model)
        {
            var awsAccess = _dbContext.AwsAccesses.FirstOrDefault() ?? new AwsAccess();

            awsAccess.AwsAccessKeyID      = model.AwsAccessKeyID;
            awsAccess.AwsSecreteAccessKey = model.AwsSecreteAccessKey;
            awsAccess.Token = model.Token;

            if (awsAccess.Id != 0)
            {
                _dbContext.Update(awsAccess);
            }
            else
            {
                _dbContext.Add(awsAccess);
            }
            await _dbContext.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }