public async Task <CPSCloudResourceSummaryModel> GetProjectFeatureServiceCloudSummary(Guid organizationId, Guid projectId, Guid featureId, Guid serviceId)
        {
            string loggedUserId = _identityService.GetUserId();

            DomainModels.User user = await _userRepository.GetUser(loggedUserId);

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

                return(null);
            }

            DomainModels.Project project = user.FindProjectById(projectId);
            if (project == null)
            {
                await _domainManagerService.AddNotFound($"The project with id {projectId} does not exists.");

                return(null);
            }

            DomainModels.ProjectFeature feature = project.GetFeatureById(featureId);
            if (feature == null)
            {
                await _domainManagerService.AddNotFound($"The project feature with id {featureId} does not exists.");

                return(null);
            }

            DomainModels.ProjectFeatureService featureService = feature.GetFeatureServiceById(serviceId);
            if (featureService == null)
            {
                await _domainManagerService.AddNotFound($"The project feature pipe with id {serviceId} does not exists.");

                return(null);
            }

            var environments = new List <string>()
            {
                DomainConstants.Environments.Development
            };

            CPSAuthCredentialModel authCredentials = new CPSAuthCredentialModel();

            authCredentials.AccessId        = _dataProtectorService.Unprotect(project.OrganizationCPS.AccessId);
            authCredentials.AccessName      = _dataProtectorService.Unprotect(project.OrganizationCPS.AccessName);
            authCredentials.AccessSecret    = _dataProtectorService.Unprotect(project.OrganizationCPS.AccessSecret);
            authCredentials.AccessRegion    = _dataProtectorService.Unprotect(project.OrganizationCPS.AccessRegion);
            authCredentials.AccessAppId     = _dataProtectorService.Unprotect(project.OrganizationCPS.AccessAppId);
            authCredentials.AccessAppSecret = _dataProtectorService.Unprotect(project.OrganizationCPS.AccessAppSecret);
            authCredentials.AccessDirectory = _dataProtectorService.Unprotect(project.OrganizationCPS.AccessDirectory);

            var summary = await _cpsQueryService(project.OrganizationCPS.Type).GetSummary(organization.Name, project.Name, featureService.ProjectService.Name, environments, feature.Name, authCredentials);

            return(summary);
        }
        public async Task <CPSCloudResourceEnvironmentSummaryModel> GetEnvironmentSummary(string organization, string project, string service, string environmentName, string feature, CPSAuthCredentialModel authCredential)
        {
            CPSCloudResourceEnvironmentSummaryModel summaryEnvironmentModel = new CPSCloudResourceEnvironmentSummaryModel();

            try
            {
                var serviceCreds = await ApplicationTokenProvider.LoginSilentAsync(authCredential.AccessDirectory, authCredential.AccessAppId, authCredential.AccessAppSecret);

                ResourceManagementClient resourceManagementClient = new ResourceManagementClient(serviceCreds);
                resourceManagementClient.SubscriptionId = authCredential.AccessId;

                string resourceGroupName = $"{organization}{project}{service}{environmentName}{feature}".ToLower();
                try
                {
                    var resourceGroupResponse = resourceManagementClient.ResourceGroups.Get(resourceGroupName);
                    if (resourceGroupResponse != null)
                    {
                        summaryEnvironmentModel      = new CPSCloudResourceEnvironmentSummaryModel();
                        summaryEnvironmentModel.Name = environmentName;

                        var deployments = resourceManagementClient.Deployments.ListByResourceGroup(resourceGroupName, new Microsoft.Rest.Azure.OData.ODataQuery <Microsoft.Azure.Management.ResourceManager.Models.DeploymentExtendedFilter>()
                        {
                            Top = 1, OrderBy = "Name desc"
                        });
                        DeploymentExtended deployment = null;
                        foreach (var item in deployments)
                        {
                            deployment = item;
                            break;
                        }

                        var statusModel = AzureHelper.GetStatusModel(deployment.Properties.ProvisioningState);
                        summaryEnvironmentModel.StatusCode = statusModel.StatusCode;
                        summaryEnvironmentModel.StatusName = statusModel.StatusName;

                        if (deployment != null && deployment.Properties.Outputs != null)
                        {
                            var outPuts = JObject.Parse(JsonConvert.SerializeObject(deployment.Properties.Outputs));
                            foreach (var output in outPuts)
                            {
                                string key = output.Key.First().ToString().ToUpper() + output.Key.Substring(1);
                                summaryEnvironmentModel.AddProperty(key, output.Value["value"].ToString());
                            }
                        }

                        var resources = resourceManagementClient.Resources.ListByResourceGroup(resourceGroupName);

                        if (resources != null && resources.Any())
                        {
                            foreach (var item in resources)
                            {
                                if (!string.IsNullOrEmpty(item.Kind))
                                {
                                    summaryEnvironmentModel.AddResource(item.Type, item.Id, item.Name, statusModel.StatusName);
                                }
                            }
                        }
                    }
                    else
                    {
                        summaryEnvironmentModel            = new CPSCloudResourceEnvironmentSummaryModel();
                        summaryEnvironmentModel.Name       = environmentName;
                        summaryEnvironmentModel.StatusCode = PipelineEnvironmentStatusEnumModel.Pending.ToString();
                        summaryEnvironmentModel.StatusName = PipelineEnvironmentStatusEnumModel.Pending.GetDescription();
                    }
                }
                catch (System.Exception ex)
                {
                    summaryEnvironmentModel            = new CPSCloudResourceEnvironmentSummaryModel();
                    summaryEnvironmentModel.Name       = environmentName;
                    summaryEnvironmentModel.StatusCode = PipelineEnvironmentStatusEnumModel.Pending.ToString();
                    summaryEnvironmentModel.StatusName = PipelineEnvironmentStatusEnumModel.Pending.GetDescription();
                }
            }
            catch (System.Exception)
            {
            }

            return(summaryEnvironmentModel);
        }
        public async Task <CPSCloudResourceSummaryModel> GetSummary(string organization, string project, string service, List <string> environments, string feature, CPSAuthCredentialModel authCredential)
        {
            CPSCloudResourceSummaryModel summaryModel = new CPSCloudResourceSummaryModel();

            try
            {
                var serviceCreds = await ApplicationTokenProvider.LoginSilentAsync(authCredential.AccessDirectory, authCredential.AccessAppId, authCredential.AccessAppSecret);

                ResourceManagementClient resourceManagementClient = new ResourceManagementClient(serviceCreds);
                resourceManagementClient.SubscriptionId = authCredential.AccessId;

                foreach (var environmentName in environments)
                {
                    string resourceGroupName = $"{organization}{project}{service}{environmentName}{feature}".ToLower();
                    try
                    {
                        var resourceGroupResponse = resourceManagementClient.ResourceGroups.Get(resourceGroupName);
                        if (resourceGroupResponse != null)
                        {
                            var environment = summaryModel.AddEnvironment(environmentName, resourceGroupResponse.Properties.ProvisioningState);
                            var deployments = resourceManagementClient.Deployments.ListByResourceGroup(resourceGroupName, new Microsoft.Rest.Azure.OData.ODataQuery <Microsoft.Azure.Management.ResourceManager.Models.DeploymentExtendedFilter>()
                            {
                                Top = 1, OrderBy = "Name desc"
                            });
                            DeploymentExtended deployment = null;
                            foreach (var item in deployments)
                            {
                                deployment = item;
                                break;
                            }
                            if (deployment != null && deployment.Properties.Outputs != null)
                            {
                                var outPuts = JObject.Parse(JsonConvert.SerializeObject(deployment.Properties.Outputs));
                                foreach (var output in outPuts)
                                {
                                    string key = output.Key.First().ToString().ToUpper() + output.Key.Substring(1);
                                    environment.AddProperty(key, output.Value["value"].ToString());
                                }
                            }
                        }
                        else
                        {
                            summaryModel.AddEnvironment(environmentName, "NO_DEPLOYED_YET");
                        }
                    }
                    catch (System.Exception ex)
                    {
                        summaryModel.AddEnvironment(environmentName, "NO_DEPLOYED_YET");
                    }
                }
            }
            catch (System.Exception)
            {
            }

            return(summaryModel);
        }
コード例 #4
0
        public async Task <ProjectEnvironmentListRp> GetProjectEnvironments(Guid organizationId, Guid projectId)
        {
            string loggedUserId = _identityService.GetUserId();

            DomainModels.User user = await _userRepository.GetUser(loggedUserId);

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

                return(null);
            }

            DomainModels.Project project = user.FindProjectById(projectId);
            if (project == null)
            {
                await _domainManagerService.AddNotFound($"The project with id {projectId} does not exists.");

                return(null);
            }

            ProjectEnvironmentListRp list = new ProjectEnvironmentListRp();

            if (project.Environments != null)
            {
                list.Items = project.Environments.Select(x => new ProjectEnvironmentListItemRp()
                {
                    ProjectEnvironmentId = x.ProjectEnvironmentId,
                    Name        = x.Name,
                    Description = x.Description,
                    Type        = x.Type,
                    Status      = x.Status,
                    Rank        = x.Rank
                }).OrderBy(x => x.Rank).ToList();


                var services = project.Services.Select(x => new
                {
                    ProjectServiceId = x.ProjectServiceId,
                    Name             = x.Name
                }).ToList();

                CPSAuthCredentialModel authCredentials = new CPSAuthCredentialModel();
                authCredentials.AccessId        = _dataProtectorService.Unprotect(project.OrganizationCPS.AccessId);
                authCredentials.AccessName      = _dataProtectorService.Unprotect(project.OrganizationCPS.AccessName);
                authCredentials.AccessSecret    = _dataProtectorService.Unprotect(project.OrganizationCPS.AccessSecret);
                authCredentials.AccessRegion    = _dataProtectorService.Unprotect(project.OrganizationCPS.AccessRegion);
                authCredentials.AccessAppId     = _dataProtectorService.Unprotect(project.OrganizationCPS.AccessAppId);
                authCredentials.AccessAppSecret = _dataProtectorService.Unprotect(project.OrganizationCPS.AccessAppSecret);
                authCredentials.AccessDirectory = _dataProtectorService.Unprotect(project.OrganizationCPS.AccessDirectory);

                if (services != null && services.Any())
                {
                    foreach (var env in list.Items)
                    {
                        var projectServiceEnvironments    = new ProjectServiceEnvironmentListRp();
                        var projectServiceEnvironmentList = new ConcurrentBag <ProjectServiceEnvironmentListItemRp>();

                        await services.ForEachAsync(5, async service =>
                        {
                            var projectServiceEnvironmentListItem     = new ProjectServiceEnvironmentListItemRp();
                            projectServiceEnvironmentListItem.Name    = service.Name;
                            projectServiceEnvironmentListItem.Summary = await _cpsQueryService(project.OrganizationCPS.Type).GetEnvironmentSummary(organization.Name, project.Name, service.Name, env.Name, "Root", authCredentials);
                            projectServiceEnvironmentList.Add(projectServiceEnvironmentListItem);
                        });

                        projectServiceEnvironments.Items = projectServiceEnvironmentList.ToList();

                        env.Services = projectServiceEnvironments;
                    }
                }
            }

            return(list);
        }
コード例 #5
0
        public async Task <CPSCloudResourceSummaryModel> GetSummary(string organization, string project, string service, List <string> environments, string feature, CPSAuthCredentialModel authCredential)
        {
            CPSCloudResourceSummaryModel summaryModel = new CPSCloudResourceSummaryModel();

            try
            {
                AmazonCloudFormationClient client = new AmazonCloudFormationClient(authCredential.AccessId, authCredential.AccessSecret, Amazon.RegionEndpoint.GetBySystemName(authCredential.AccessRegion));

                foreach (var environmentName in environments)
                {
                    string stackName = $"{organization}{project}{service}{environmentName}{feature}".ToLower();
                    try
                    {
                        var stacksResponse = await client.DescribeStacksAsync(new DescribeStacksRequest()
                        {
                            StackName = stackName
                        });

                        if (stacksResponse.HttpStatusCode == System.Net.HttpStatusCode.OK)
                        {
                            var stack = stacksResponse.Stacks.FirstOrDefault();
                            if (stack != null)
                            {
                                var environment = summaryModel.AddEnvironment(environmentName, stack.StackStatus.Value);
                                if (stack.Outputs != null)
                                {
                                    foreach (var output in stack.Outputs)
                                    {
                                        string key = output.OutputKey.First().ToString().ToUpper() + output.OutputKey.Substring(1);
                                        environment.AddProperty(key, output.OutputValue);
                                    }
                                }
                            }
                            else
                            {
                                summaryModel.AddEnvironment(environmentName, "NO_DEPLOYED_YET");
                            }
                        }
                    }
                    catch (System.Exception ex)
                    {
                        summaryModel.AddEnvironment(environmentName, "NO_DEPLOYED_YET");
                    }
                }
            }
            catch (System.Exception)
            {
            }

            return(summaryModel);
        }
コード例 #6
0
        public async Task <CPSCloudResourceEnvironmentSummaryModel> GetEnvironmentSummary(string organization, string project, string service, string environmentName, string feature, CPSAuthCredentialModel authCredential)
        {
            CPSCloudResourceEnvironmentSummaryModel summaryEnvironmentModel = new CPSCloudResourceEnvironmentSummaryModel();

            try
            {
                AmazonCloudFormationClient client = new AmazonCloudFormationClient(authCredential.AccessId, authCredential.AccessSecret, Amazon.RegionEndpoint.GetBySystemName(authCredential.AccessRegion));

                string stackName = $"{organization}{project}{service}{environmentName}{feature}".ToLower();
                try
                {
                    var stacksResponse = await client.DescribeStacksAsync(new DescribeStacksRequest()
                    {
                        StackName = stackName
                    });

                    if (stacksResponse.HttpStatusCode == System.Net.HttpStatusCode.OK)
                    {
                        var stack = stacksResponse.Stacks.FirstOrDefault();
                        if (stack != null)
                        {
                            summaryEnvironmentModel      = new CPSCloudResourceEnvironmentSummaryModel();
                            summaryEnvironmentModel.Name = environmentName;

                            var statusModel = AWSHelper.GetStatusModel(stack.StackStatus.Value);
                            summaryEnvironmentModel.StatusCode = statusModel.StatusCode;
                            summaryEnvironmentModel.StatusName = statusModel.StatusName;

                            if (stack.Outputs != null)
                            {
                                foreach (var output in stack.Outputs)
                                {
                                    string key = output.OutputKey.First().ToString().ToUpper() + output.OutputKey.Substring(1);
                                    summaryEnvironmentModel.AddProperty(key, output.OutputValue);
                                }
                            }

                            var resources = await client.DescribeStackResourcesAsync(new DescribeStackResourcesRequest { StackName = stackName });

                            if (resources != null && resources.StackResources != null && resources.StackResources.Any())
                            {
                                foreach (var item in resources.StackResources)
                                {
                                    if (!string.IsNullOrEmpty(item.ResourceType))
                                    {
                                        summaryEnvironmentModel.AddResource(item.ResourceType, item.PhysicalResourceId, item.LogicalResourceId, item.ResourceStatusReason);
                                    }
                                }
                            }
                        }
                        else
                        {
                            summaryEnvironmentModel            = new CPSCloudResourceEnvironmentSummaryModel();
                            summaryEnvironmentModel.Name       = environmentName;
                            summaryEnvironmentModel.StatusCode = PipelineEnvironmentStatusEnumModel.Pending.ToString();
                            summaryEnvironmentModel.StatusName = PipelineEnvironmentStatusEnumModel.Pending.GetDescription();
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    summaryEnvironmentModel            = new CPSCloudResourceEnvironmentSummaryModel();
                    summaryEnvironmentModel.Name       = environmentName;
                    summaryEnvironmentModel.StatusCode = PipelineEnvironmentStatusEnumModel.Pending.ToString();
                    summaryEnvironmentModel.StatusName = PipelineEnvironmentStatusEnumModel.Pending.GetDescription();
                }
            }
            catch (System.Exception)
            {
            }

            return(summaryEnvironmentModel);
        }
        public async Task <ProjectFeatureServiceEnvironmentListRp> GetFeatureProjectServiceEnvironments(Guid organizationId, Guid projectId, Guid featureId, Guid serviceId)
        {
            string loggedUserId = _identityService.GetUserId();

            DomainModels.User user = await _userRepository.GetUser(loggedUserId);

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

                return(null);
            }

            DomainModels.Project project = user.FindProjectById(projectId);
            if (project == null)
            {
                await _domainManagerService.AddNotFound($"The project with id {projectId} does not exists.");

                return(null);
            }

            DomainModels.ProjectFeature projectFeature = project.GetFeatureById(featureId);
            if (projectFeature == null)
            {
                await _domainManagerService.AddNotFound($"The project feature with id {featureId} does not exists.");

                return(null);
            }

            DomainModels.ProjectFeatureService projectFeatureService = projectFeature.GetFeatureServiceById(serviceId);
            if (projectFeatureService == null)
            {
                await _domainManagerService.AddNotFound($"The feature service with id {serviceId} does not exists.");

                return(null);
            }

            ProjectFeatureServiceEnvironmentListRp list = new ProjectFeatureServiceEnvironmentListRp();

            CPSAuthCredentialModel authCredentials = new CPSAuthCredentialModel();

            authCredentials.AccessId        = _dataProtectorService.Unprotect(project.OrganizationCPS.AccessId);
            authCredentials.AccessName      = _dataProtectorService.Unprotect(project.OrganizationCPS.AccessName);
            authCredentials.AccessSecret    = _dataProtectorService.Unprotect(project.OrganizationCPS.AccessSecret);
            authCredentials.AccessRegion    = _dataProtectorService.Unprotect(project.OrganizationCPS.AccessRegion);
            authCredentials.AccessAppId     = _dataProtectorService.Unprotect(project.OrganizationCPS.AccessAppId);
            authCredentials.AccessAppSecret = _dataProtectorService.Unprotect(project.OrganizationCPS.AccessAppSecret);
            authCredentials.AccessDirectory = _dataProtectorService.Unprotect(project.OrganizationCPS.AccessDirectory);

            if (projectFeatureService.Environments != null)
            {
                List <ProjectFeatureServiceEnvironmentListItemRp> projectFeatureServiceEnvironmentList = new List <ProjectFeatureServiceEnvironmentListItemRp>();
                var environments = projectFeatureService.Environments.OrderBy(x => x.ProjectFeatureEnvironment.Rank);
                foreach (var item in environments)
                {
                    var projectServiceEnvironmentListItem = new ProjectFeatureServiceEnvironmentListItemRp();
                    projectServiceEnvironmentListItem.ProjectFeatureServiceEnvironmentId = item.ProjectFeatureServiceEnvironmentId;
                    projectServiceEnvironmentListItem.Name    = item.ProjectFeatureEnvironment.Name;
                    projectServiceEnvironmentListItem.Status  = item.Status;
                    projectServiceEnvironmentListItem.Summary = await _cpsQueryService(project.OrganizationCPS.Type).GetEnvironmentSummary(organization.Name, project.Name, projectFeatureService.ProjectService.Name, item.ProjectFeatureEnvironment.Name, projectFeature.Name, authCredentials);

                    projectServiceEnvironmentListItem.Variables = item.Variables.Select(p => new ProjectFeatureServiceEnvironmentVariableListItemRp()
                    {
                        Name  = p.Name,
                        Value = p.Value
                    }).ToList();
                    projectFeatureServiceEnvironmentList.Add(projectServiceEnvironmentListItem);
                }
                list.Items = projectFeatureServiceEnvironmentList;
            }

            return(list);
        }