public List <OrganizationCMS> GetConfigurationManagementServices(CMSConnectionType connectionType)
        {
            if (this.ConfigurationManagementServices == null)
            {
                this.ConfigurationManagementServices = new List <OrganizationCMS>();
            }

            return(this.ConfigurationManagementServices.Where(x => x.ConnectionType == connectionType).ToList());
        }
            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);
            }
        public async Task <IActionResult> GetOrganizationConfigurationManagementServices(Guid organizationId, [FromQuery(Name = "type")] CMSConnectionType connectionType)
        {
            var configurationManagementServices = await _organizationCMSQueryService.GetOrganizationConfigurationManagementServices(organizationId, connectionType);

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

            return(this.Ok(configurationManagementServices));
        }
Esempio n. 4
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. 5
0
        public async Task <OrganizationCMSListRp> GetOrganizationConfigurationManagementServices(Guid organizationId, CMSConnectionType connectionType)
        {
            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);
            }

            PipelineRole role = user.GetRoleInOrganization(organizationId);

            OrganizationCMSListRp list = new OrganizationCMSListRp();

            List <OrganizationCMS> configurationManagementServices = organization.GetConfigurationManagementServices(connectionType);

            if (configurationManagementServices != null)
            {
                list.Items = configurationManagementServices.Select(x => new OrganizationCMSListItemRp()
                {
                    OrganizationCMSId = x.OrganizationCMSId,
                    Name         = x.Name,
                    Type         = x.Type,
                    AccountId    = role == PipelineRole.OrganizationAdmin ? _dataProtectorService.Unprotect(x.AccountId) : DomainConstants.Obfuscator.Default,
                    AccountName  = role == PipelineRole.OrganizationAdmin ? _dataProtectorService.Unprotect(x.AccountName) : DomainConstants.Obfuscator.Default,
                    AccessId     = role == PipelineRole.OrganizationAdmin ? _dataProtectorService.Unprotect(x.AccessId) : DomainConstants.Obfuscator.Default,
                    AccessSecret = role == PipelineRole.OrganizationAdmin ? _dataProtectorService.Unprotect(x.AccessSecret) : DomainConstants.Obfuscator.Default,
                    AccessToken  = role == PipelineRole.OrganizationAdmin ? _dataProtectorService.Unprotect(x.AccessToken) : DomainConstants.Obfuscator.Default
                }).ToList();
            }

            return(list);
        }