public Task <OrganizationCMS> FindOrganizationCMSByTypeAndAccountName(ConfigurationManagementService type, string accountName)
 {
     return(_context.OrganizationCMSs.FirstOrDefaultAsync(x => x.Type == type &&
                                                          x.AccountName.Equals(accountName, StringComparison.InvariantCultureIgnoreCase) &&
                                                          x.Status == EntityStatus.Active &&
                                                          x.Organization.Status == EntityStatus.Active));
 }
Esempio n. 2
0
        public async void CanDeleteConfiguration()
        {
            DbContextOptions <AsyncInnDbContext> options = new DbContextOptionsBuilder <AsyncInnDbContext>().UseInMemoryDatabase("DeleteConfiguration").Options;

            using (AsyncInnDbContext context = new AsyncInnDbContext(options))
            {
                // Arrange
                Room room = new Room();
                room.ID           = 1;
                room.Name         = "test";
                room.Layout       = Layout.OneBedroom;
                room.AmenityCount = 5;

                //Act
                ConfigurationManagementService roomServ = new ConfigurationManagementService(context);

                await roomServ.CreateConfiguration(room);

                roomServ.DeleteConfiguration(room.ID);

                var result = context.Rooms.FirstOrDefault(r => r.ID == room.ID);
                //Assert
                Assert.Null(result);
            }
        }
        public async Task <IActionResult> GetProjectServiceTemplates([FromQuery(Name = "gitProviderType")] ConfigurationManagementService gitProviderType,
                                                                     [FromQuery(Name = "cloudProviderType")] CloudProviderService cloudProviderType,
                                                                     [FromQuery(Name = "pipeType")] PipeType pipeType)
        {
            var serviceTemplates = await _projectServiceTemplateQueryService.GetProjectServiceTemplates(gitProviderType, cloudProviderType, pipeType);

            return(this.Ok(serviceTemplates));
        }
        public async Task <IActionResult> GetAccounts(string cmsProvider)
        {
            ConfigurationManagementService cmsValue = (ConfigurationManagementService)Enum.Parse(typeof(ConfigurationManagementService), cmsProvider);

            var accounts = await _cmsExternalQueryService.GetAccounts(cmsValue);

            return(this.Ok(accounts));
        }
        public OrganizationCMS GetConfigurationManagementServiceByType(ConfigurationManagementService type)
        {
            if (this.ConfigurationManagementServices == null)
            {
                this.ConfigurationManagementServices = new List <OrganizationCMS>();
            }

            return(this.ConfigurationManagementServices.FirstOrDefault(x => x.Type == type));
        }
Esempio n. 6
0
        public Project ImportProject(Guid organizationId, string organizationExternalId, string name, string description, ProjectType projectType,
                                     Guid organizationCMSId, Guid?organizationCPSId, Guid?projectTemplateId, string agentPoolId, ProjectVisibility projectVisibility,
                                     CloudProviderService cloudProviderService, ConfigurationManagementService configurationManagementService)
        {
            var newProject = CreateProject(organizationId, organizationExternalId, name, description, projectType, organizationCMSId, organizationCPSId, projectTemplateId, agentPoolId, projectVisibility, cloudProviderService, configurationManagementService);

            newProject.IsImported = true;

            return(newProject);
        }
Esempio n. 7
0
 public void AddCredential(ConfigurationManagementService cmsType, bool needCredentials, string accessId, string accessSecret, string accessToken)
 {
     if (needCredentials)
     {
         this.Credential = ProjectServiceTemplateCredential.Factory.Create(cmsType, accessId, accessSecret, accessToken, this.CreatedBy);
     }
     else
     {
         this.Credential = ProjectServiceTemplateCredential.Factory.Create(cmsType, this.CreatedBy);
     }
 }
Esempio n. 8
0
            public static ProjectServiceTemplateCredential Create(ConfigurationManagementService CMSType,
                                                                  string accessId,
                                                                  string accessSecret,
                                                                  string accessToken,
                                                                  string createdBy)
            {
                var entity = new ProjectServiceTemplateCredential()
                {
                    CMSType      = CMSType,
                    AccessId     = accessId,
                    AccessSecret = accessSecret,
                    AccessToken  = accessToken,
                    CreatedBy    = createdBy,
                    Status       = EntityStatus.Active
                };

                var validationResult = new DataValidatorManager <ProjectServiceTemplateCredential>().Build().Validate(entity);

                if (!validationResult.IsValid)
                {
                    throw new ApplicationException(validationResult.Errors);
                }

                if (CMSType == ConfigurationManagementService.VSTS)
                {
                    if (string.IsNullOrEmpty(accessId))
                    {
                        throw new ApplicationException("Access Id is required");
                    }

                    if (string.IsNullOrEmpty(accessSecret))
                    {
                        throw new ApplicationException("Access Secret is required");
                    }
                }

                if (CMSType == ConfigurationManagementService.GitHub)
                {
                    if (string.IsNullOrEmpty(accessId))
                    {
                        throw new ApplicationException("Access Id is required");
                    }

                    if (string.IsNullOrEmpty(accessToken))
                    {
                        throw new ApplicationException("Access Token is required");
                    }
                }

                return(entity);
            }
Esempio n. 9
0
        public async Task <ProjectServiceTemplateListRp> GetProjectServiceTemplates(ConfigurationManagementService gitProviderType, CloudProviderService cloudProviderType, PipeType pipeType)
        {
            var serviceTemplates = await _projectServiceTemplateRepository.GetProjectServiceTemplates(gitProviderType, cloudProviderType, pipeType);

            ProjectServiceTemplateListRp list = new ProjectServiceTemplateListRp
            {
                Items = serviceTemplates.Select(x => new ProjectServiceTemplateListItemRp()
                {
                    ProjectServiceTemplateId = x.ProjectServiceTemplateId,
                    Name        = x.Name,
                    Description = x.Description
                }).ToList()
            };

            return(list);
        }
Esempio n. 10
0
        public async Task <CMSProjectListRp> GetAccounts(ConfigurationManagementService type)
        {
            var cmsAuthCredential = this._cmsCredentialService(type).GetToken();
            var cmsAccounts       = await _cmsQueryService(type).GetAccounts(cmsAuthCredential);

            CMSProjectListRp list = new CMSProjectListRp();

            if (cmsAccounts != null && cmsAccounts.Items != null)
            {
                list.Items = cmsAccounts.Items.Select(c => new CMSProjectListItemRp {
                    AccountId = c.AccountId, Name = c.Name, Description = c.Description
                }).ToList();
            }


            return(list);
        }
Esempio n. 11
0
            public static ProjectServiceTemplateCredential Create(ConfigurationManagementService CMSType, string createdBy)
            {
                var entity = new ProjectServiceTemplateCredential()
                {
                    CMSType   = CMSType,
                    CreatedBy = createdBy,
                    Status    = EntityStatus.Active
                };

                var validationResult = new DataValidatorManager <ProjectServiceTemplateCredential>().Build().Validate(entity);

                if (!validationResult.IsValid)
                {
                    throw new ApplicationException(validationResult.Errors);
                }

                return(entity);
            }
Esempio n. 12
0
            public static ProjectServiceTemplate Create(string name,
                                                        ConfigurationManagementService serviceCMSType,
                                                        CloudProviderService serviceCPSType,
                                                        string description,
                                                        string url,
                                                        string logo,
                                                        PipeType pipeType,
                                                        TemplateType templateType,
                                                        TemplateAccess templateAccess,
                                                        bool needCredentials,
                                                        Guid programmingLanguageId,
                                                        string framework,
                                                        string createdBy)
            {
                var entity = new ProjectServiceTemplate()
                {
                    Name                  = name,
                    ServiceCMSType        = serviceCMSType,
                    ServiceCPSType        = serviceCPSType,
                    Description           = description,
                    Url                   = url,
                    Logo                  = logo,
                    PipeType              = pipeType,
                    TemplateType          = templateType,
                    TemplateAccess        = templateAccess,
                    NeedCredentials       = needCredentials,
                    ProgrammingLanguageId = programmingLanguageId,
                    Framework             = framework,
                    CreatedBy             = createdBy
                };

                var validationResult = new DataValidatorManager <ProjectServiceTemplate>().Build().Validate(entity);

                if (!validationResult.IsValid)
                {
                    throw new ApplicationException(validationResult.Errors);
                }

                return(entity);
            }
            public static OrganizationCMS Create(string name,
                                                 ConfigurationManagementService type,
                                                 CMSConnectionType connectionType,
                                                 string accountId,
                                                 string accountName,
                                                 string accessId,
                                                 string accessSecret,
                                                 string accessToken,
                                                 string createdBy)
            {
                var entity = new OrganizationCMS()
                {
                    Name           = name,
                    Type           = type,
                    ConnectionType = connectionType,
                    AccountId      = accountId,
                    AccountName    = accountName,
                    AccessId       = accessId,
                    AccessSecret   = accessSecret,
                    AccessToken    = accessToken,
                    CreatedBy      = createdBy,
                    Status         = EntityStatus.Active
                };

                var validationResult = new DataValidatorManager <OrganizationCMS>().Build().Validate(entity);

                if (!validationResult.IsValid)
                {
                    throw new ApplicationException(validationResult.Errors);
                }

                if ((type == ConfigurationManagementService.VSTS ||
                     type == ConfigurationManagementService.Bitbucket) && string.IsNullOrEmpty(accessSecret))
                {
                    throw new ApplicationException("Access Secret is required");
                }

                return(entity);
            }
Esempio n. 14
0
        public ProjectServiceTemplate AddProjectTemplateService(Guid organizationId, string name, ConfigurationManagementService serviceCMSType,
                                                                CloudProviderService serviceCPSType, string description, string url, string logo,
                                                                PipeType pipeType, TemplateType templateType, TemplateAccess templateAccess,
                                                                bool needCredentials,
                                                                Guid programmingLanguageId, string framework, ConfigurationManagementService cmsType, string accessId, string accessSecret, string accessToken,
                                                                List <ProjectServiceTemplateParameter> parameters)
        {
            Organization organization = FindOrganizationById(organizationId);

            if (organization == null)
            {
                throw new ApplicationException($"The organization with id {organizationId} does not exists");
            }

            var newOrganizationProjectServiceTemplate = ProjectServiceTemplate.Factory.Create(name, serviceCMSType, serviceCPSType, description, url, logo, pipeType, templateType, templateAccess, needCredentials, programmingLanguageId, framework, this.Id);

            newOrganizationProjectServiceTemplate.AddCredential(cmsType, needCredentials, accessId, accessSecret, accessToken);

            newOrganizationProjectServiceTemplate.AddParameters(parameters);
            newOrganizationProjectServiceTemplate.AddOrganization(organizationId);

            return(newOrganizationProjectServiceTemplate);
        }
 public async Task <List <ProjectServiceTemplate> > GetProjectServiceTemplates(ConfigurationManagementService gitProviderType, CloudProviderService cloudProviderType, PipeType pipeType)
 {
     return(await _context.ProjectServiceTemplates.Where(x => x.ServiceCPSType == cloudProviderType &&
                                                         x.PipeType == pipeType &&
                                                         x.TemplateType == Domain.Models.Enums.TemplateType.Standard &&
                                                         x.TemplateAccess == Domain.Models.Enums.TemplateAccess.System &&
                                                         x.Status == EntityStatus.Active).ToListAsync());
 }
Esempio n. 16
0
            public static Project Create(string organizationExternalId, string name, string description,
                                         ProjectType projectType, Guid organizationCMSId, Guid?organizationCPSId, Guid?projectTemplateId, string agentPoolId,
                                         ProjectVisibility projectVisibility, CloudProviderService cloudProviderService, ConfigurationManagementService configurationManagementService, string createdBy)
            {
                var entity = new Project()
                {
                    Name                   = name,
                    InternalName           = name.Replace(".", "").Replace("_", ""),
                    OrganizationExternalId = organizationExternalId,
                    Description            = description,
                    ProjectType            = projectType,
                    OrganizationCMSId      = organizationCMSId,
                    OrganizationCPSId      = organizationCPSId,
                    ProjectTemplateId      = projectTemplateId,
                    AgentPoolId            = agentPoolId,
                    ProjectVisibility      = projectVisibility,
                    OwnerId                = createdBy,
                    CreatedBy              = createdBy
                };

                var validationResult = new DataValidatorManager <Project>().Build().Validate(entity);

                if (!validationResult.IsValid)
                {
                    throw new ApplicationException(validationResult.Errors);
                }

                entity.GrantUserAccess(createdBy, PipelineRole.ProjectAdmin);

                //add activities
                entity.AddActivity(nameof(DomainConstants.Activities.PRCRBA), DomainConstants.Activities.PRCRBA);
                if (cloudProviderService == CloudProviderService.AWS)
                {
                    entity.AddActivity(nameof(DomainConstants.Activities.PREXBA), DomainConstants.Activities.PREXBA);
                }
                else if (cloudProviderService == CloudProviderService.Azure)
                {
                    entity.AddActivity(nameof(DomainConstants.Activities.PREXBO), DomainConstants.Activities.PREXBO);
                }

                if (configurationManagementService == ConfigurationManagementService.GitLab)
                {
                    entity.AddActivity(nameof(DomainConstants.Activities.PREXGL), DomainConstants.Activities.PREXGL);
                }

                entity.AddActivity(nameof(DomainConstants.Activities.PRCLEP), DomainConstants.Activities.PRCLEP);
                entity.AddActivity(nameof(DomainConstants.Activities.PRGTEP), DomainConstants.Activities.PRGTEP);
                entity.AddActivity(nameof(DomainConstants.Activities.PRACBA), DomainConstants.Activities.PRACBA);
                if (projectTemplateId.HasValue)
                {
                    entity.AddActivity(nameof(DomainConstants.Activities.PRSTPT), DomainConstants.Activities.PRSTPT);
                }

                return(entity);
            }
Esempio n. 17
0
        public void AddConfigurationManagementService(Guid organizationId, string name, ConfigurationManagementService type, CMSConnectionType connectionType, string accountId, string accountName, string accessId, string accessSecret, string accessToken)
        {
            Organization organization = FindOrganizationById(organizationId);

            if (organization == null)
            {
                throw new ApplicationException($"The organization with id {organizationId} does not exists");
            }

            var newOrganizationCMS = OrganizationCMS.Factory.Create(name, type, connectionType, accountId, accountName, accessId, accessSecret, accessToken, this.Id);

            organization.AddConfigurationManagementService(newOrganizationCMS);
        }
Esempio n. 18
0
        public Project CreateProject(Guid organizationId, string organizationExternalId, string name, string description, ProjectType projectType,
                                     Guid organizationCMSId, Guid?organizationCPSId, Guid?projectTemplateId, string agentPoolId,
                                     ProjectVisibility projectVisibility, CloudProviderService cloudProviderService, ConfigurationManagementService configurationManagementService)
        {
            Organization organization = FindOrganizationById(organizationId);

            if (organization == null)
            {
                throw new ApplicationException($"The organization with id {organizationId} does not exists");
            }

            Project newProject = Project.Factory.Create(organizationExternalId, name, description, projectType, organizationCMSId, organizationCPSId,
                                                        projectTemplateId, agentPoolId, projectVisibility, cloudProviderService, configurationManagementService, this.Id);

            ProjectEnvironment developmentProjectEnvironment = ProjectEnvironment.Factory.Create(DomainConstants.Environments.Development, "Environment for development and some tests", EnvironmentType.Root, false, false, 1, this.Id);

            developmentProjectEnvironment.Activate();

            newProject.AddEnvironment(developmentProjectEnvironment);

            ProjectEnvironment productionProjectEnvironment = ProjectEnvironment.Factory.Create(DomainConstants.Environments.Production, "Environment for production", EnvironmentType.Fact, true, false, 2, this.Id);

            productionProjectEnvironment.Activate();

            newProject.AddEnvironment(productionProjectEnvironment);

            organization.AddProject(newProject);

            return(newProject);
        }