public async Task <IActionResult> GetProjectServiceTemplateInternals([FromQuery(Name = "programmingLanguageId")] Guid programmingLanguageId,
                                                                             [FromQuery(Name = "cloudProviderType")] CloudProviderService cloudProviderType)
        {
            var serviceTemplates = await _projectServiceTemplateQueryService.GetProjectServiceTemplateInternals(programmingLanguageId, cloudProviderType);

            return(this.Ok(serviceTemplates));
        }
Пример #2
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);
        }
        public async Task <IActionResult> GetOrganizationProjectServiceTemplates(Guid organizationId,
                                                                                 [FromQuery(Name = "cloudProviderType")] CloudProviderService cloudProviderType,
                                                                                 [FromQuery(Name = "pipeType")] PipeType pipeType)
        {
            if (!ModelState.IsValid)
            {
                return(this.BadRequest(ModelState));
            }

            var templates = await _organizationProjectServiceTemplateQueryService.GetOrganizationProjectServiceTemplates(organizationId, cloudProviderType, pipeType);

            if (_domainManagerService.HasNotFounds())
            {
                return(this.NotFound(_domainManagerService.GetForbidden()));
            }

            if (_domainManagerService.HasForbidden())
            {
                return(this.Forbidden(_domainManagerService.GetForbidden()));
            }

            if (_domainManagerService.HasConflicts())
            {
                return(this.Conflict(_domainManagerService.GetConflicts()));
            }

            return(this.Ok(templates));
        }
        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 OrganizationCPS GetCloudProviderServiceByType(CloudProviderService type)
        {
            if (this.CloudProviderServices == null)
            {
                this.CloudProviderServices = new List <OrganizationCPS>();
            }

            return(this.CloudProviderServices.FirstOrDefault(x => x.Type == type));
        }
Пример #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);
        }
Пример #7
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);
            }
        public List <ProjectServiceTemplate> GetProjectServiceTemplates(CloudProviderService cloudProviderType, PipeType pipeType)
        {
            if (this.ProjectServiceTemplates == null)
            {
                this.ProjectServiceTemplates = new List <OrganizationProjectServiceTemplate>();
            }

            var projectServiceTemplates = this.ProjectServiceTemplates.Select(x => x.ProjectServiceTemplate);

            if (projectServiceTemplates == null)
            {
                return(null);
            }

            return(projectServiceTemplates.Where(x => x.ServiceCPSType == cloudProviderType && x.PipeType == pipeType).ToList());
        }
Пример #9
0
        public async Task <ProjectTemplateListRp> GetProjectTemplates(CloudProviderService cloudProviderType)
        {
            var projectTemplates = await _projectTemplateRepository.GetProjectTemplates(cloudProviderType);

            ProjectTemplateListRp list = new ProjectTemplateListRp
            {
                Items = projectTemplates.Select(x => new ProjectTemplateListItemRp()
                {
                    ProjectTemplateId = x.ProjectTemplateId,
                    Name        = x.Name,
                    Description = x.Description,
                    Logo        = x.Logo
                }).ToList()
            };

            return(list);
        }
Пример #10
0
        public void AddCloudProviderService(Guid organizationId, string name,
                                            CloudProviderService type,
                                            string accessId,
                                            string accessName,
                                            string accessSecret,
                                            string accessAppId,
                                            string accessAppSecret,
                                            string accessDirectory,
                                            string accessRegion)
        {
            Organization organization = FindOrganizationById(organizationId);

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

            var newOrganizationCPS = OrganizationCPS.Factory.Create(name, type, accessId, accessName, accessSecret, accessAppId, accessAppSecret, accessDirectory, accessRegion, this.Id);

            organization.AddCloudProviderService(newOrganizationCPS);
        }
Пример #11
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);
            }
Пример #12
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);
        }
Пример #13
0
        public async Task <ProjectServiceTemplateListRp> GetProjectServiceTemplateInternals(Guid programmingLanguageId, CloudProviderService cloudProviderType)
        {
            var serviceTemplates = await _projectServiceTemplateRepository.GetProjectServiceTemplateInternals(programmingLanguageId, cloudProviderType);

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

            return(list);
        }
Пример #14
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);
        }
 public async Task <List <ProjectTemplate> > GetProjectTemplates(CloudProviderService cloudProviderType)
 {
     return(await _context.ProjectTemplates.Where(x => x.CloudProviderType == cloudProviderType &&
                                                  x.Status == EntityStatus.Active).ToListAsync());
 }
 public async Task <List <ProjectServiceTemplate> > GetProjectServiceTemplateInternals(Guid programmingLanguageId, CloudProviderService cloudProviderType)
 {
     return(await _context.ProjectServiceTemplates.Where(x => x.ProgrammingLanguageId == programmingLanguageId &&
                                                         x.ServiceCPSType == cloudProviderType &&
                                                         x.TemplateType == Domain.Models.Enums.TemplateType.Internal &&
                                                         x.Status == EntityStatus.Active).ToListAsync());
 }
 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());
 }
Пример #18
0
        public async Task <OrganizationProjectServiceTemplateListRp> GetOrganizationProjectServiceTemplates(Guid organizationId, CloudProviderService cloudProviderType, PipeType pipeType)
        {
            var loggedUserId = _identityService.GetUserId();

            User user = await _userRepository.GetUser(loggedUserId);

            Organization organization = user.FindOrganizationById(organizationId);

            if (organization == null)
            {
                await _domainManagerService.AddNotFound($"The organzation with id {organizationId} does not exists.");

                return(null);
            }

            var systemTemplates = await _projectServiceTemplateRepository.GetProjectServiceTemplates(ConfigurationManagementService.VSTS, cloudProviderType, pipeType);

            OrganizationProjectServiceTemplateListRp list = new OrganizationProjectServiceTemplateListRp
            {
                Items = systemTemplates.Select(x => new OrganizationProjectServiceTemplateListItemRp()
                {
                    ProjectServiceTemplateId = x.ProjectServiceTemplateId,
                    Name                    = x.Name,
                    Description             = x.Description,
                    Access                  = x.TemplateAccess,
                    ProgrammingLanguageName = x.ProgrammingLanguage.Name,
                    Framework               = x.Framework,
                    Status                  = x.Status,
                    Logo                    = x.Logo
                }).ToList()
            };

            if (cloudProviderType == CloudProviderService.None)
            {
                var organizationAWSTemplates   = organization.GetProjectServiceTemplates(CloudProviderService.AWS, pipeType);
                var organizationAzureTemplates = organization.GetProjectServiceTemplates(CloudProviderService.Azure, pipeType);

                foreach (var item in organizationAWSTemplates)
                {
                    list.Items.Add(new OrganizationProjectServiceTemplateListItemRp()
                    {
                        ProjectServiceTemplateId = item.ProjectServiceTemplateId,
                        Name                    = item.Name,
                        Description             = item.Description,
                        Access                  = item.TemplateAccess,
                        ProgrammingLanguageName = item.ProgrammingLanguage.Name,
                        Framework               = item.Framework,
                        Status                  = item.Status
                    });
                }

                foreach (var item in organizationAzureTemplates)
                {
                    list.Items.Add(new OrganizationProjectServiceTemplateListItemRp()
                    {
                        ProjectServiceTemplateId = item.ProjectServiceTemplateId,
                        Name                    = item.Name,
                        Description             = item.Description,
                        Access                  = item.TemplateAccess,
                        ProgrammingLanguageName = item.ProgrammingLanguage.Name,
                        Framework               = item.Framework,
                        Status                  = item.Status
                    });
                }
            }
            else
            {
                var organizationTemplates = organization.GetProjectServiceTemplates(cloudProviderType, pipeType);
                foreach (var item in organizationTemplates)
                {
                    list.Items.Add(new OrganizationProjectServiceTemplateListItemRp()
                    {
                        ProjectServiceTemplateId = item.ProjectServiceTemplateId,
                        Name                    = item.Name,
                        Description             = item.Description,
                        Access                  = item.TemplateAccess,
                        ProgrammingLanguageName = item.ProgrammingLanguage.Name,
                        Framework               = item.Framework,
                        Status                  = item.Status
                    });
                }
            }


            return(list);
        }
            public static OrganizationCPS Create(string name, CloudProviderService type,
                                                 string accessId,
                                                 string accessName,
                                                 string accessSecret,
                                                 string accessAppId,
                                                 string accessAppSecret,
                                                 string accessDirectory,
                                                 string accessRegion,
                                                 string createdBy)
            {
                var entity = new OrganizationCPS()
                {
                    Name            = name,
                    Type            = type,
                    AccessId        = accessId,
                    AccessName      = accessName,
                    AccessSecret    = accessSecret,
                    AccessAppId     = accessAppId,
                    AccessAppSecret = accessAppSecret,
                    AccessDirectory = accessDirectory,
                    AccessRegion    = accessRegion,
                    CreatedBy       = createdBy,
                    Status          = EntityStatus.Active
                };

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

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

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

                if (type == CloudProviderService.Azure)
                {
                    if (string.IsNullOrEmpty(accessName))
                    {
                        throw new ApplicationException("Subscription Name is required");
                    }

                    if (string.IsNullOrEmpty(accessAppId))
                    {
                        throw new ApplicationException("Application Id is required");
                    }

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

                    if (string.IsNullOrEmpty(accessDirectory))
                    {
                        throw new ApplicationException("Directory is required");
                    }
                }

                return(entity);
            }
        public async Task <IActionResult> GetProjectTemplates([FromQuery(Name = "cloudProviderType")] CloudProviderService cloudProviderType)
        {
            var projectTemplates = await _projectTemplateQueryService.GetProjectTemplates(cloudProviderType);

            return(this.Ok(projectTemplates));
        }