Пример #1
0
        public async Task Execute(string odsInstanceName, CloudOdsClaimSet claimSet, ApiMode apiMode)
        {
            var odsSqlConfiguration = await _odsSecretConfigurationProvider.GetSqlConfiguration();

            var cloudOdsInstance = await _getCloudOdsInstanceQuery.Execute(odsInstanceName);

            var firstTimeSetupConfiguration = await GetFirstTimeSetupConfiguration(cloudOdsInstance, claimSet, odsSqlConfiguration);

            SetupAndRuntimeConfigurations(firstTimeSetupConfiguration);

            if (apiMode.SupportsSingleInstance)
            {
                var defaultOdsInstance = new OdsInstanceRegistration
                {
                    Name        = odsInstanceName,
                    Description = "Default single ods instance"
                };
                await _odsInstanceFirstTimeSetupService.CompleteSetup(defaultOdsInstance, claimSet, apiMode);
            }

            CreateClaimSetForAdminApp(firstTimeSetupConfiguration.ClaimSet);

            ApplyAdditionalClaimSetModifications();

            await _usersContext.SaveChangesAsync();

            await _securityContext.SaveChangesAsync();

            await _restartAppServicesCommand.Execute(new CloudOdsApiOperationContext(cloudOdsInstance));
        }
Пример #2
0
        public async Task <bool> Execute(string odsInstanceName, CloudOdsClaimSet claimSet, ApiMode apiMode)
        {
            ExtraDatabaseInitializationAction?.Invoke();
            var restartRequired = false;

            if (apiMode.SupportsSingleInstance)
            {
                var defaultOdsInstance = new OdsInstanceRegistration
                {
                    Name         = odsInstanceName,
                    DatabaseName = _instanceService.DatabaseName(0, apiMode),
                    Description  = "Default single ods instance"
                };
                await _firstTimeSetupService.CompleteSetup(defaultOdsInstance, claimSet, apiMode);
            }

            if (!_claimSetCheckService.RequiredClaimSetsExist())
            {
                CreateClaimSetForAdminApp(claimSet);

                ApplyAdditionalClaimSetModifications();

                restartRequired = true;
            }

            await _usersContext.SaveChangesAsync();

            await _securityContext.SaveChangesAsync();

            return(restartRequired);
        }
        public async Task <int> Execute(IRegisterOdsInstanceModel instance, ApiMode mode, string userId, CloudOdsClaimSet cloudOdsClaimSet = null)
        {
            var instanceName = instance.NumericSuffix.Value.ToString();

            var newInstance = new OdsInstanceRegistration
            {
                Name         = instanceName,
                DatabaseName = _inferInstanceService.DatabaseName(instance.NumericSuffix.Value, mode),
                Description  = instance.Description
            };
            await _odsInstanceFirstTimeSetupService.CompleteSetup(newInstance, cloudOdsClaimSet, mode);

            await _identity.UserOdsInstanceRegistrations.AddAsync(
                new UserOdsInstanceRegistration
            {
                OdsInstanceRegistrationId = newInstance.Id,
                UserId = userId
            });

            await _identity.SaveChangesAsync();

            if (mode == ApiMode.YearSpecific)
            {
                _setCurrentSchoolYear.Execute(instanceName, mode, (short)instance.NumericSuffix.Value);
            }

            return(newInstance.Id);
        }
        public async Task CompleteSetup(OdsInstanceRegistration odsInstanceRegistration, CloudOdsClaimSet claimSet,
                                        ApiMode apiMode)
        {
            await AddOdsInstanceRegistration(odsInstanceRegistration);
            await CreateAndSaveApiKeyAndSecret(odsInstanceRegistration, claimSet, apiMode);

            _reportViewsSetUp.CreateReportViews(odsInstanceRegistration.Name, apiMode);
            _firstTimeSetupService.EnsureAdminDatabaseInitialized();
            await _usersContext.SaveChangesAsync();
        }
        private async Task CreateAndSaveApiKeyAndSecret(OdsInstanceRegistration odsInstanceRegistration, CloudOdsClaimSet claimSet, ApiMode mode)
        {
            var secretConfiguration = new OdsSecretConfiguration();

            var applicationCreateResult = await _firstTimeSetupService.CreateAdminAppInAdminDatabase(claimSet.ClaimSetName, odsInstanceRegistration.Name,
                                                                                                     ConfigurationManager.AppSettings["AwsCurrentVersion"], mode);

            secretConfiguration.ProductionApiKeyAndSecret = applicationCreateResult.ProductionKeyAndSecret;

            await _odsSecretConfigurationProvider.SetSecretConfiguration(secretConfiguration, odsInstanceRegistration.Id);
        }
Пример #6
0
        private static bool TryQueryInstanceRegistration(out OdsInstanceRegistration instanceRegistration)
        {
            OdsInstanceRegistration singleInstanceLookup;

            using (var dbContext = new AdminAppDbContext())
            {
                singleInstanceLookup = dbContext.OdsInstanceRegistrations.FirstOrDefault(x =>
                                                                                         x.Name.Equals(CloudOdsAdminAppSettings.Instance.OdsInstanceName,
                                                                                                       StringComparison.InvariantCultureIgnoreCase));
            }
            instanceRegistration = singleInstanceLookup;
            return(singleInstanceLookup != null);
        }
Пример #7
0
        public static OdsInstanceRegistration SetupOdsInstanceRegistration(string instanceName)
        {
            var testInstance = new OdsInstanceRegistration
            {
                Name        = instanceName,
                Description = Sample("Description")
            };

            Save(testInstance);

            SetupOdsInstanceSecretConfigurations(new List <OdsInstanceRegistration> {
                testInstance
            });

            return(testInstance);
        }
Пример #8
0
        private OdsInstanceRegistration CreateOdsInstanceRegistration(string instanceName)
        {
            OdsInstanceRegistration createdOdsInstanceRegistration = null;

            Scoped <AdminAppDbContext>(database =>
            {
                database.OdsInstanceRegistrations.Add(new OdsInstanceRegistration {
                    Name = instanceName
                });
                database.SaveChanges();

                createdOdsInstanceRegistration =
                    database.OdsInstanceRegistrations.FirstOrDefault(x => x.Name == instanceName);
            });

            return(createdOdsInstanceRegistration);
        }
        public void ShouldNotDeregisterIfOdsInstanceDoesNotExist()
        {
            var testInstanceNotInSystem = new OdsInstanceRegistration
            {
                Id          = 1,
                Description = "Test Description",
                Name        = "EdFi_Ods_1234"
            };

            var deregisterModel = new DeregisterOdsInstanceModel
            {
                OdsInstanceId = testInstanceNotInSystem.Id,
                Name          = testInstanceNotInSystem.Name,
                Description   = testInstanceNotInSystem.Description
            };

            var validator = new DeregisterOdsInstanceModelValidator(SetupContext);

            validator.ShouldNotValidate(deregisterModel, "The instance you are trying to deregister does not exist in the database.");
        }
Пример #10
0
        public async Task Execute(string odsInstanceName, CloudOdsClaimSet claimSet, ApiMode apiMode)
        {
            ExtraDatabaseInitializationAction?.Invoke();

            if (apiMode.SupportsSingleInstance)
            {
                var defaultOdsInstance = new OdsInstanceRegistration
                {
                    Name        = odsInstanceName,
                    Description = "Default single ods instance"
                };
                await _firstTimeSetupService.CompleteSetup(defaultOdsInstance, claimSet, apiMode);
            }

            CreateClaimSetForAdminApp(claimSet);

            ApplyAdditionalClaimSetModifications();

            await _usersContext.SaveChangesAsync();

            await _securityContext.SaveChangesAsync();
        }
        public async Task <int> Execute(IRegisterOdsInstanceModel instance, ApiMode mode, string userId, CloudOdsClaimSet cloudOdsClaimSet = null)
        {
            var instanceName = InferInstanceDatabaseName(instance.NumericSuffix.Value, mode);

            var newInstance = new OdsInstanceRegistration
            {
                Name        = instanceName,
                Description = instance.Description
            };
            await _odsInstanceFirstTimeSetupService.CompleteSetup(newInstance, cloudOdsClaimSet, mode);

            _identity.UserOdsInstanceRegistrations.Add(
                new UserOdsInstanceRegistration
            {
                OdsInstanceRegistrationId = newInstance.Id,
                UserId = userId
            });

            _identity.SaveChanges();

            return(newInstance.Id);
        }
        public void ShouldNotEditIfInstancesDoesNotExist()
        {
            var existingUser = SetupUsers(1).Single();

            var testInstanceInSystem = SetupOdsInstanceRegistrations(1).Single();

            var testInstanceNotInSystem = new OdsInstanceRegistration
            {
                Name        = $"TestInstance{Guid.NewGuid():N}",
                Description = "Test Description"
            };

            var updateModel = new EditOdsInstanceRegistrationForUserModel
            {
                UserId = existingUser.Id,
                OdsInstanceRegistrations = new List <OdsInstanceRegistrationSelection>
                {
                    new OdsInstanceRegistrationSelection
                    {
                        Name = testInstanceInSystem.Name,
                        OdsInstanceRegistrationId = testInstanceInSystem.Id,
                        Selected = true
                    },
                    new OdsInstanceRegistrationSelection
                    {
                        Name = testInstanceNotInSystem.Name,
                        OdsInstanceRegistrationId = testInstanceNotInSystem.Id,
                        Selected = true
                    }
                }
            };

            Scoped <EditOdsInstanceRegistrationForUserModelValidator>(validator =>
            {
                var validationResults = validator.Validate(updateModel);
                validationResults.IsValid.ShouldBe(false);
                validationResults.Errors.Select(x => x.ErrorMessage).ShouldContain("A selected instance does not exist in the database.");
            });
        }
        private bool TryQueryInstanceRegistration(string userId, string unsafeInstanceId, out OdsInstanceRegistration instanceRegistration)
        {
            if (int.TryParse(unsafeInstanceId, out var safeInstanceId))
            {
                var isAuthorized = IsUserAuthorizedForInstance(safeInstanceId, userId);

                var instanceLookup = _adminAppDbContext.OdsInstanceRegistrations.Find(safeInstanceId);

                if (isAuthorized && instanceLookup != null)
                {
                    instanceRegistration = instanceLookup;
                    return(true);
                }
            }

            instanceRegistration = null;
            return(false);
        }
 private async Task AddOdsInstanceRegistration(OdsInstanceRegistration odsInstanceRegistration)
 {
     _database.OdsInstanceRegistrations.Add(odsInstanceRegistration);
     await _database.SaveChangesAsync();
 }