public ApiClient CreateNewSandboxClient(string sandboxName, SandboxOptions sandboxOptions, User user)
        {
            if (user.ApiClients.Count >= _maximumSandboxesPerUser)
            {
                var message = $"The maximum of {_maximumSandboxesPerUser} sandboxes for user id {user.UserId} has been reached!";
                message += " To configure please update the 'MaximumSandboxesPerUser' app setting in the web.config.";
                _log.Error(message);
                throw new ArgumentOutOfRangeException(message);
            }

            var client = SetupDefaultSandboxClient(sandboxName, sandboxOptions, user);

            ProvisionSandbox(client);

            var leaIds = _templateDatabaseLeaQuery.GetLocalEducationAgencyIds(client.Key);

            _defaultApplicationCreator.AddLeaIdsToApplication(leaIds, client.Application.ApplicationId);

            return(client);
        }
Ejemplo n.º 2
0
        public void UpdateClientWithLEAIdsFromPopulatedSandbox()
        {
            foreach (var user in _settings.Users)
            {
                var clientProfile = _clientAppRepo.GetUser(user.Email);

                // look through all the sandboxes that are populated so we can get the lea ids from the created sandbox.
                // note our current template process has the populated data with lea's installed in it.
                foreach (var apiClient in clientProfile.ApiClients)
                {
                    var leaIds = _templateDatabaseLeaQuery.GetLocalEducationAgencyIds(apiClient.Key).ToList();

                    _applicationCreator.AddLeaIdsToApplication(leaIds, apiClient.Application.ApplicationId);
                }
            }
        }
Ejemplo n.º 3
0
        public void Execute()
        {
            // we are pulling command line arguments therefore we are going directly to the configuration object
            var _configurationFilePath = _configurationRoot.GetValue <string>("configurationFilePath");
            var _environmentFilePath   = _configurationRoot.GetValue <string>("environmentFilePath");

            var postmanEnvironment = new PostmanEnvironment();

            _clientAppRepo.Reset();

            if (!string.IsNullOrEmpty(_configurationFilePath))
            {
                _logger.Debug($"configurationPath = {_configurationFilePath}");

                if (!File.Exists(_configurationFilePath))
                {
                    throw new Exception($"Configuration file {_configurationFilePath} does not exists.");
                }

                _testHarnessConfiguration =
                    JsonConvert.DeserializeObject <TestHarnessConfiguration>(File.ReadAllText(_configurationFilePath));
            }
            else
            {
                _testHarnessConfiguration.Vendors = CreateDefaultVendor();
            }

            foreach (var vendor in _testHarnessConfiguration.Vendors)
            {
                var user = _clientAppRepo.GetUser(vendor.Email) ??
                           _clientAppRepo.CreateUser(
                    new User
                {
                    FullName = vendor.VendorName,
                    Email    = vendor.Email,
                    Vendor   = _clientAppRepo.CreateOrGetVendor(
                        vendor.Email, vendor.VendorName, vendor.NamespacePrefixes)
                });

                foreach (var app in vendor.Applications)
                {
                    var application = _clientAppRepo.CreateApplicationForVendor(
                        user.Vendor.VendorId, app.ApplicationName, app.ClaimSetName);

                    var leaIds = app.ApiClients.SelectMany(s => s.LocalEducationOrganizations).Distinct().ToList();

                    _defaultApplicationCreator.AddLeaIdsToApplication(leaIds, application.ApplicationId);

                    foreach (var client in app.ApiClients)
                    {
                        var key = !string.IsNullOrEmpty(client.Key)
                            ? client.Key
                            : GetGuid();

                        var secret = !string.IsNullOrEmpty(client.Secret)
                            ? client.Secret
                            : GetGuid();

                        var apiClient = _clientAppRepo.CreateApiClient(user.UserId, client.ApiClientName, key, secret);

                        postmanEnvironment.Values.Add(
                            new ValueItem
                        {
                            Enabled = true,
                            Value   = key,
                            Key     = "ApiKey_" + client.ApiClientName
                        });

                        postmanEnvironment.Values.Add(
                            new ValueItem
                        {
                            Enabled = true,
                            Value   = secret,
                            Key     = "ApiSecret_" + client.ApiClientName
                        });

                        _clientAppRepo.AddLeaIdsToApiClient(
                            user.UserId, apiClient.ApiClientId, client.LocalEducationOrganizations,
                            application.ApplicationId);

                        postmanEnvironment.Values.Add(
                            new ValueItem
                        {
                            Enabled = true,
                            Value   = client.LocalEducationOrganizations,
                            Key     = client.ApiClientName + "LeaId"
                        });
                    }

                    if (app.Profiles != null)
                    {
                        _clientAppRepo.AddProfilesToApplication(app.Profiles, application.ApplicationId);
                    }
                }
            }

            CreateEnvironmentFile();

            void CreateEnvironmentFile()
            {
                if (!string.IsNullOrEmpty(_environmentFilePath) && new DirectoryInfo(_environmentFilePath).Exists)
                {
                    postmanEnvironment.Values.Add(
                        new ValueItem
                    {
                        Enabled = true,
                        Value   = _configuration.GetValue <string>("Urls") ?? "http://*****:*****@ed-fi.org",
                    VendorName   = "Test Admin",
                    Applications = new List <Application> {
                        application
                    },
                    NamespacePrefixes = new List <string>
                    {
                        "uri://ed-fi.org",
                        "uri://gbisd.edu",
                        "uri://tpdm.ed-fi.org"
                    }
                };

                return(new List <Vendor> {
                    vendor
                });
            }

            string GetGuid()
            {
                return(Guid.NewGuid().ToString("N").Substring(0, 20));
            }
        }