public DeploymentValidationResult ValidateDeployment(DeployProject project, DeployComponent component, DeployEnvironment environment)
		{
			var returnValue = new DeploymentValidationResult();
			DeployEnvironmentConfiguration environmentConfiguration;
			List<DeployStep> deploymentStepList;
			if(component.UseConfigurationGroup)
			{
				environmentConfiguration = environment.TryGetConfigurationItem(component.ConfigurationId);
				var configuration = project.GetConfiguration(component.ConfigurationId);
				deploymentStepList = configuration.DeploymentStepList;;
			}
			else
			{
				environmentConfiguration = environment.TryGetComponentItem(component.Id);
				deploymentStepList = component.DeploymentStepList;
			}
			if(environmentConfiguration != null)
			{
				foreach(var deploymentStep in deploymentStepList)
				{
					var taskDefinition = _taskFactory.CreateTaskDefinition(deploymentStep.TaskTypeName, deploymentStep.TaskOptionsJson);
					var validationItem = this.ValidateTaskDefinition(taskDefinition, environmentConfiguration);
					returnValue.AddResult(deploymentStep, validationItem);
				}
			}
			return returnValue;
		}
        private void AssertCreatedEnvironment(DeployEnvironment result, DeployProject project, string environmentName, List<DeployEnvironmentConfiguration> environmentComponentList, List<DeployEnvironmentConfiguration> environmentConfigurationList, IProjectRepository sut)
        {
            Assert.IsNotNull(result);
            Assert.IsNotNullOrEmpty(result.Id);
            Assert.AreEqual(project.Id, result.ProjectId);
            Assert.AreEqual(environmentName, result.EnvironmentName);
            AssertHelpers.AssertCreatedBaseDto(result, this.UserName);
            
            environmentComponentList = environmentComponentList ?? new List<DeployEnvironmentConfiguration>();
            Assert.AreEqual(environmentComponentList.Count(), result.ComponentList.Count);
            foreach(var item in environmentComponentList)
            {
                var createdItem = result.ComponentList.SingleOrDefault(i=>i.ParentId == item.ParentId);
                AssertCreatedEnvironmentConfiguration(item, createdItem, project, result, EnumDeployStepParentType.Component);
            }
            environmentConfigurationList = environmentConfigurationList ?? new List<DeployEnvironmentConfiguration>();
            Assert.AreEqual(environmentConfigurationList.Count(), result.ConfigurationList.Count);
            foreach (var item in environmentConfigurationList)
            {
                var createdItem = result.ConfigurationList.SingleOrDefault(i => i.ParentId == item.ParentId);
                AssertCreatedEnvironmentConfiguration(item, createdItem, project, result, EnumDeployStepParentType.Configuration);
            }

            var dbItem = sut.GetEnvironment(result.Id, result.ProjectId);
            AssertEnvironment(result, dbItem);

            var dbProject = sut.GetProject(project.Id);
            var dbProjectEnvironment = dbProject.EnvironmentList.SingleOrDefault(i => i.Id == result.Id);
            Assert.IsNotNull(dbProjectEnvironment);
            AssertEnvironment(result, dbProjectEnvironment);
        }
Пример #3
0
		public object Post(DeployProject project)
		{
			if(string.IsNullOrEmpty(project.Id))
			{
				return _projectManager.CreateProject(project.ProjectName, project.UsesSharedComponentConfiguration);
			}
			else 
			{
				return _projectManager.UpdateProject(project.Id, project.ProjectName, project.UsesSharedComponentConfiguration);
			}
		}
Пример #4
0
		public object Get(DeployProject request)
		{
			if(request != null && !string.IsNullOrEmpty(request.Id))
			{
                var project = _projectManager.GetProject(request.Id);				
                return _parameterMasker.Mask(project);
			}
			else 
			{
				var projectList = _projectManager.GetProjectList();
                return _parameterMasker.Mask(projectList);
			}
		}
Пример #5
0
 public DeployProject Mask(DeployProject project)
 {
     if(project == null)
     {
         return null;
     }
     var newProject = AutoMapper.Mapper.Map(project, new DeployProject());
     if(project.EnvironmentList != null)
     {
         newProject.EnvironmentList = this.Mask(project, project.EnvironmentList).ToList();
     }
     return newProject;
 }
			public void CanCreateProject()
			{
				var repository = new Mock<IProjectRepository>();
				IProjectManager sut = new ProjectManager(repository.Object, new Mock<IDeployTaskFactory>().Object);
				var project = new DeployProject
				{
					ProjectName = Guid.NewGuid().ToString(),
					Id = Guid.NewGuid().ToString(),
					UsesSharedComponentConfiguration = false
				};
				repository.Setup(i=>i.CreateProject(project.ProjectName, project.UsesSharedComponentConfiguration)).Returns(project);
				DeployProject result = sut.CreateProject(project.ProjectName, project.UsesSharedComponentConfiguration);
				Assert.AreEqual(project, result);
				repository.Verify(i => i.CreateProject(project.ProjectName, project.UsesSharedComponentConfiguration), Times.Once());
			}
Пример #7
0
 public IEnumerable<DeployEnvironment> Mask(DeployProject project, IEnumerable<DeployEnvironment> environmentList)
 {
     if(environmentList == null)
     {
         return null;
     }
     if (project == null)
     {
         throw new ArgumentNullException("Missing project");
     }
     var newEnvironmentList = new List<DeployEnvironment>();
     foreach(var environment in environmentList)
     {
         var newEnvironment = this.Mask(project, environment);
         newEnvironmentList.Add(newEnvironment);
     }
     return newEnvironmentList;
 }
Пример #8
0
 public DeployEnvironment Mask(DeployProject project, DeployEnvironment environment)
 {
     if(environment == null)
     {
         return null;
     }
     if (project == null)
     {
         throw new ArgumentNullException("Missing project");
     }
     var newEnvironment = AutoMapper.Mapper.Map(environment, new DeployEnvironment());
     if (environment.ConfigurationList != null)
     {
         newEnvironment.ConfigurationList = this.Mask(project, environment.ConfigurationList).ToList();
     }
     if(environment.ComponentList != null)
     {
         newEnvironment.ComponentList = this.Mask(project, environment.ComponentList).ToList();
     }
     return newEnvironment;
 }
		private DeployProjectRolePermissions ValidatePermissions(DeployProjectRolePermissions permissions, string projectRoleId, DeployProject project)
		{
			permissions = permissions ?? new DeployProjectRolePermissions();

			permissions.RequestDeployPermissionList = permissions.RequestDeployPermissionList ?? new List<DeployProjectRoleEnvironmentPermission>();
			this.ValidateEnvironmentPermissions(permissions.RequestDeployPermissionList, projectRoleId, project);

			permissions.ApproveRejectDeployPermissionList = permissions.ApproveRejectDeployPermissionList ?? new List<DeployProjectRoleEnvironmentPermission>();
			this.ValidateEnvironmentPermissions(permissions.ApproveRejectDeployPermissionList, projectRoleId, project);

			permissions.RunDeploymentPermissionList = permissions.RunDeploymentPermissionList ?? new List<DeployProjectRoleEnvironmentPermission>();
			this.ValidateEnvironmentPermissions(permissions.RunDeploymentPermissionList, projectRoleId, project);

			permissions.EditEnvironmentPermissionList = permissions.EditEnvironmentPermissionList ?? new List<DeployProjectRoleEnvironmentPermission>();
			this.ValidateEnvironmentPermissions(permissions.EditEnvironmentPermissionList, projectRoleId, project);

			permissions.EditEnvironmentPermissionsPermissionList = permissions.EditEnvironmentPermissionsPermissionList ?? new List<DeployProjectRoleEnvironmentPermission>();
			this.ValidateEnvironmentPermissions(permissions.EditEnvironmentPermissionsPermissionList, projectRoleId, project);

			return permissions;
		}
		private void ValidateEnvironmentPermissions(List<DeployProjectRoleEnvironmentPermission> permissionList, string projectRoleId, DeployProject project)
		{
			var itemsToDelete = new List<DeployProjectRoleEnvironmentPermission>();
			foreach(var item in permissionList)
			{
				var environment = project.EnvironmentList.FirstOrDefault(i=>i.Id == item.EnvironmentId);
				if(environment == null)
				{
					itemsToDelete.Add(item);
				}
				else 
				{
					item.EnvironmentName = environment.EnvironmentName;
				}
			}
			foreach(var item in itemsToDelete)
			{
				permissionList.Remove(item);
			}
			foreach(var environment in project.EnvironmentList)
			{
				var item = permissionList.FirstOrDefault(i=>i.EnvironmentId == environment.Id);
				if(item == null)
				{
					item = new DeployProjectRoleEnvironmentPermission
					{
						EnvironmentId = environment.Id,
						EnvironmentName = environment.EnvironmentName,
                        //ProjectId = project.Id,
                        //ProjectRoleId = projectRoleId,
						Access = EnumPermissionAccess.Grant
					};
					permissionList.Add(item);
				}
			}
			
		}
		public void SendBuildPublishedNotification(DeployProject project, DeployBuild build)
		{
		}
		private DeployProjectRole ValidateRole(DeployProjectRole role, DeployProject project)
		{
			role.Permissions = this.ValidatePermissions(role.Permissions, role.Id, project);
			role.ProjectName = project.ProjectName;
			return role;
		}
Пример #13
0
		public void SendBuildPublishedNotification(DeployProject project, DeployBuild build)
		{
			var emailAddresseList = GetNotificationEmailAddresses(project.Id, i=>i.BuildPublished);
			if(emailAddresseList != null && emailAddresseList.Count > 0)
			{
				var dataObject = new
				{
					Project = project,
					Build = build,
					ViewBuildUrl = _urlGenerator.ViewBuildUrl(build.Id)
				};
				var template = _razorTemplateRepository.GetTemplate("BuildPublishEmail", _notificationResourceViews.BuildPublishEmailView);
				_emailQueue.QueueMessage("New Build Published", emailAddresseList, dataObject, template.ViewData);
			}
		}
		private DeployProjectRole CreateEveryoneRole(DeployProject project)
		{
			var role = new DeployProjectRole
			{
				Id = "Everyone",
				ProjectId = project.Id,
				ProjectName = project.ProjectName,
				RoleName = "Everyone",
				EveryoneRoleIndicator = true
			};
			role.Permissions = this.ValidatePermissions(role.Permissions, role.Id, project);
			role.Permissions.EditComponentConfigurationAccess = EnumPermissionAccess.Grant;
			role.Permissions.CreateEnvironmentAccess = EnumPermissionAccess.Grant;
			role.Permissions.EditProjectPermissionsAccess = EnumPermissionAccess.Grant;
			foreach (var item in role.Permissions.RequestDeployPermissionList)
			{
				item.Access = EnumPermissionAccess.Grant;
			}
			foreach(var item in role.Permissions.RunDeploymentPermissionList)
			{
				item.Access = EnumPermissionAccess.Grant;
			}
			foreach(var item in role.Permissions.ApproveRejectDeployPermissionList)
			{
				item.Access = EnumPermissionAccess.Grant;
			}
			foreach(var item in role.Permissions.EditEnvironmentPermissionList)
			{
				item.Access = EnumPermissionAccess.Grant;
			}
			foreach(var item in role.Permissions.EditEnvironmentPermissionsPermissionList)
			{
				item.Access = EnumPermissionAccess.Grant;
			}
			return role;
		}
Пример #15
0
 public DeployEnvironmentConfiguration Unmask(DeployProject project, DeployEnvironmentConfiguration environmentConfiguration, DeployEnvironment originalEnvironment)
 {
     if(environmentConfiguration == null)
     {
         return null;
     }
     if(project == null)
     {
         throw new ArgumentNullException("Missing project");
     }
     var newEnvironmentConfiguration = AutoMapper.Mapper.Map(environmentConfiguration, new DeployEnvironmentConfiguration());
     if (string.IsNullOrEmpty(environmentConfiguration.Id))
     {
         //New item being created, don't need to unmask
         return newEnvironmentConfiguration;
     }
     DeployEnvironmentConfiguration originalEnviromentConfiguration;
     switch(environmentConfiguration.ParentType)
     {
         case EnumDeployStepParentType.Configuration:
             originalEnviromentConfiguration = originalEnvironment.ConfigurationList.FirstOrDefault(i => i.ParentType == environmentConfiguration.ParentType && i.ParentId == environmentConfiguration.ParentId);
             break;
         case EnumDeployStepParentType.Component:
             originalEnviromentConfiguration = originalEnvironment.ComponentList.FirstOrDefault(i => i.ParentType == environmentConfiguration.ParentType && i.ParentId == environmentConfiguration.ParentId);
             break;
         default:
             throw new UnknownEnumValueException(environmentConfiguration.ParentType);
     }
     if(originalEnviromentConfiguration != null)
     {
         List<DeployStep> deploymentStepList = new List<DeployStep>();
         switch (newEnvironmentConfiguration.ParentType)
         {
             case EnumDeployStepParentType.Component:
                 var component = project.ComponentList.FirstOrDefault(i => i.Id == newEnvironmentConfiguration.ParentId);
                 if (component != null)
                 {
                     deploymentStepList = component.DeploymentStepList;
                 }
                 break;
             case EnumDeployStepParentType.Configuration:
                 var configuration = project.ConfigurationList.FirstOrDefault(i => i.Id == newEnvironmentConfiguration.ParentId);
                 if (configuration != null)
                 {
                     deploymentStepList = configuration.DeploymentStepList;
                 }
                 break;
             default:
                 throw new UnknownEnumValueException(newEnvironmentConfiguration.ParentType);
         }
         var definition = _deploymentValidator.GetComponentConfigurationDefinition(deploymentStepList);
         if (definition.EnvironmentTaskParameterList != null)
         {
             foreach (var parameterDefinition in definition.EnvironmentTaskParameterList.Where(i => i.Sensitive))
             {
                 if (newEnvironmentConfiguration.ConfigurationValueList.ContainsKey(parameterDefinition.FieldName)
                         && originalEnviromentConfiguration.ConfigurationValueList.ContainsKey(parameterDefinition.FieldName))
                 {
                     if(newEnvironmentConfiguration.ConfigurationValueList[parameterDefinition.FieldName] == this.MaskValue)
                     {
                         newEnvironmentConfiguration.ConfigurationValueList[parameterDefinition.FieldName] = originalEnviromentConfiguration.ConfigurationValueList[parameterDefinition.FieldName];
                     }
                 }
             }
         }
         if (definition.MachineTaskParameterList != null && newEnvironmentConfiguration.MachineList != null && originalEnviromentConfiguration.MachineList != null) 
         {
             foreach (var parameterDefinition in definition.MachineTaskParameterList.Where(i => i.Sensitive))
             {
                 foreach(var newMachineConfiguration in newEnvironmentConfiguration.MachineList)
                 {
                     var originalMachineConfiguration = originalEnviromentConfiguration.MachineList.FirstOrDefault(i=>i.Id == newMachineConfiguration.Id);
                     if(originalMachineConfiguration != null)
                     {
                         if(newMachineConfiguration.ConfigurationValueList.ContainsKey(parameterDefinition.FieldName)
                                 && originalMachineConfiguration.ConfigurationValueList.ContainsKey(parameterDefinition.FieldName))
                         {
                             if (newMachineConfiguration.ConfigurationValueList[parameterDefinition.FieldName] == this.MaskValue)
                             {
                                 newMachineConfiguration.ConfigurationValueList[parameterDefinition.FieldName] = originalMachineConfiguration.ConfigurationValueList[parameterDefinition.FieldName];
                             }
                         }
                     }
                 }
             }
         }
     }
     return newEnvironmentConfiguration;
 }
        private void AssertCreatedEnvironmentConfiguration(DeployEnvironmentConfiguration sourceItem, DeployEnvironmentConfiguration createdItem, DeployProject project, DeployEnvironment environment, EnumDeployStepParentType parentType)
        {
            Assert.IsNotNull(createdItem);
            AssertHelpers.AssertCreatedBaseDto(createdItem, this.UserName);
            Assert.AreEqual(project.Id, createdItem.ProjectId);
            Assert.AreEqual(sourceItem.ParentId, createdItem.ParentId);
            Assert.AreEqual(parentType, createdItem.ParentType);
            Assert.AreEqual(sourceItem.DeployCredentialsId, createdItem.DeployCredentialsId);

            AssertHelpers.AssertDictionary(sourceItem.ConfigurationValueList, createdItem.ConfigurationValueList);
            Assert.AreEqual(sourceItem.MachineList.Count, createdItem.MachineList.Count);
            foreach(var sourceMachine in sourceItem.MachineList)
            {
                var createdMachine = createdItem.MachineList.SingleOrDefault(i=>i.MachineName == sourceMachine.MachineName);
                Assert.IsNotNull(createdMachine);
                AssertHelpers.AssertCreatedBaseDto(createdMachine, this.UserName);
                Assert.AreEqual(project.Id, createdMachine.ProjectId);
                Assert.AreEqual(environment.Id, createdMachine.EnvironmentId);
                Assert.AreEqual(environment.EnvironmentName, createdMachine.EnvironmentName);
                Assert.AreEqual(sourceItem.Id, createdMachine.ParentId);
                AssertHelpers.AssertDictionary(sourceMachine.ConfigurationValueList, createdMachine.ConfigurationValueList);
            }
        }
				private void SetPermission(DeployProject project, DeployEnvironment environment, List<DeployProjectRoleEnvironmentPermission> list, EnumPermissionAccess access)
				{
					foreach(var x in project.EnvironmentList)
					{
						var item = list.FirstOrDefault(i=>i.EnvironmentId == x.Id);
						if(item == null)
						{
							item = new DeployProjectRoleEnvironmentPermission
							{
                                //Id = this.Fixture.Create<string>(),
                                //ProjectId = project.Id,
								EnvironmentId = x.Id,
								EnvironmentName = x.CreatedByUserName
							};
							list.Add(item);
						}
					}
					list.First(i=>i.EnvironmentId == environment.Id).Access = access;
				}
Пример #18
0
 public IEnumerable<DeployEnvironmentConfiguration> Mask(DeployProject project, IEnumerable<DeployEnvironmentConfiguration> environmentConfigurationList)
 {
     if (environmentConfigurationList == null)
     {
         return null;
     }
     if (project == null)
     {
         throw new ArgumentNullException("Missing project");
     }
     var newConfigurationList = new List<DeployEnvironmentConfiguration>();
     foreach(var configuration in environmentConfigurationList)
     {
         var newConfiguration = this.Mask(project, configuration);
         newConfigurationList.Add(newConfiguration);
     }
     return newConfigurationList;
 }
 private void LoadProjectChildren(DeployProject project)
 {
     project.BranchList = GetBranchList(project.Id).ToList();
     project.ConfigurationList = GetConfigurationList(project.Id);
     project.ComponentList = GetComponentList(project.Id);
     project.EnvironmentList = GetEnvironmentList(project.Id);
 }
			public void CanRetrieveProjectByID()
			{
				var repository = new Mock<IProjectRepository>();
				var project = new DeployProject
				{
					ProjectName = Guid.NewGuid().ToString(),
					Id = Guid.NewGuid().ToString()
				};
				repository.Setup(i=>i.GetProject(project.Id)).Returns(project);
                IProjectManager sut = new ProjectManager(repository.Object, new Mock<IDeployTaskFactory>().Object);
				DeployProject result = sut.GetProject(project.Id);
				Assert.AreEqual(project, result);
				repository.Verify(i=>i.GetProject(project.Id), Times.Once());
			}
			public void CanUpdateDeploymentStep()
			{
				string projectId = Guid.NewGuid().ToString();
				string componentId = Guid.NewGuid().ToString();
				string deploymentStepId = Guid.NewGuid().ToString();
				string stepName = Guid.NewGuid().ToString();
				string taskTypeName = typeof(TestTaskType).ToString();
				string taskOptionsJson = Guid.NewGuid().ToString();
				var projectRepository = new Mock<IProjectRepository>();
				var project = new DeployProject
				{
					Id = projectId,
					ComponentList = new List<DeployComponent>(),
					UsesSharedComponentConfiguration = false
				};
				projectRepository.Setup(i=>i.GetProject(projectId)).Returns(project);
				projectRepository.Setup(i => i.UpdateComponentDeploymentStep(deploymentStepId, project.Id, componentId, stepName, taskTypeName, taskOptionsJson, null, null))
									.Returns(new DeployStep
									{
										Id = deploymentStepId,
										StepName = stepName,
										TaskTypeName = taskTypeName,
										TaskOptionsJson = Guid.NewGuid().ToString(),
										ParentId = componentId,
										ProjectId = projectId,
										SharedDeploymentStepId = Guid.NewGuid().ToString(),
									});
                IProjectManager sut = new ProjectManager(projectRepository.Object, new Mock<IDeployTaskFactory>().Object);

				var result = sut.UpdateComponentDeploymentStep(deploymentStepId, projectId, componentId, stepName, taskTypeName, taskOptionsJson);

				Assert.IsNotNull(result);
				Assert.AreEqual(stepName, result.StepName);

				projectRepository.Verify(i => i.UpdateComponentDeploymentStep(deploymentStepId, project.Id, componentId, stepName, taskTypeName, taskOptionsJson,null, null), Times.Once());
			}
			public void MissingTaskOptions_CreatesTaskOptions()
			{
                //var project = new DeployProject
                //{
                //    ProjectName = Guid.NewGuid().ToString(),
                //    Id = Guid.NewGuid().ToString(),
                //    UsesSharedComponentConfiguration = false
                //};
                //string componentId = Guid.NewGuid().ToString();
                //string stepName = Guid.NewGuid().ToString();
                //string taskTypeName = typeof(TestTaskType).ToString();
                //string taskOptionsJson = null;
                //var projectRepository = new Mock<IProjectRepository>();
                //projectRepository.Setup(i => i.GetProject(project.Id)).Returns(project);
                //var deployTaskFactory = new Mock<IDeployTaskFactory>();
                //deployTaskFactory.Setup(i=>i.CreateTaskDefinition(taskTypeName, It.IsAny<string>())).Returns(new TestTaskType() { DeployTaskOptions = new object() });
                //IProjectManager sut = new ProjectManager(projectRepository.Object, deployTaskFactory.Object);
                
                //var result = sut.CreateComponentDeploymentStep(project.Id, componentId, stepName, taskTypeName, taskOptionsJson);

                //Assert.IsNotNull(result);
                //Assert.AreEqual(stepName, result.StepName);
                //projectRepository.Verify(i => i.CreateComponentDeploymentStep(project.Id, componentId, stepName, taskTypeName, It.IsAny<string>(), null), Times.Once());

                string projectId = Guid.NewGuid().ToString();
                string componentId = Guid.NewGuid().ToString();
                string stepName = Guid.NewGuid().ToString();
                string taskTypeName = typeof(TestTaskType).ToString();
                string taskOptionsJson = null;
                var projectRepository = new Mock<IProjectRepository>();
                var project = new DeployProject
                {
                    Id = projectId,
                    ComponentList = new List<DeployComponent>(),
                    UsesSharedComponentConfiguration = false
                };
                projectRepository.Setup(i => i.GetProject(projectId))
                                    .Returns(project);
                projectRepository.Setup(i => i.CreateComponentDeploymentStep(project.Id, componentId, stepName, taskTypeName, It.IsAny<string>(), null))
                                    .Returns(new DeployStep
                                    {
                                        Id = Guid.NewGuid().ToString(),
                                        StepName = stepName,
                                        TaskTypeName = taskTypeName,
                                        TaskOptionsJson = taskOptionsJson,
                                        ProjectId = projectId,
                                        ParentId = componentId,
                                        SharedDeploymentStepId = Guid.NewGuid().ToString()
                                    });
                var deployTaskFactory = new Mock<IDeployTaskFactory>();
                deployTaskFactory.Setup(i=>i.CreateTaskDefinition(taskTypeName, It.IsAny<string>())).Returns(new TestTaskType() { DeployTaskOptions = new object() });
                IProjectManager sut = new ProjectManager(projectRepository.Object, deployTaskFactory.Object);

                var result = sut.CreateComponentDeploymentStep(projectId, componentId, stepName, taskTypeName, taskOptionsJson);

                Assert.IsNotNull(result);
                Assert.AreEqual(stepName, result.StepName);
                projectRepository.Verify(i => i.CreateComponentDeploymentStep(project.Id, componentId, stepName, taskTypeName, It.IsAny<string>(), null), Times.Once());
            }
			public void BadId_ThrowsError()
			{
				var repository = new Mock<IProjectRepository>();
				var project = new DeployProject
				{
					ProjectName = Guid.NewGuid().ToString(),
					Id = Guid.NewGuid().ToString()
				};
				repository.Setup(i => i.GetProject(project.Id)).Returns((DeployProject)null);
                IProjectManager sut = new ProjectManager(repository.Object, new Mock<IDeployTaskFactory>().Object);
				Assert.Throws<KeyNotFoundException>(delegate { sut.GetProject(project.Id); });
				repository.Verify(i => i.GetProject(It.IsAny<string>()), Times.Once());
			}
				public DeployProjectRole AddRoleAssignment(DeployProject project, DeployEnvironment environment, 
							EnumPermissionAccess createEnvironmentAccess=EnumPermissionAccess.None,
							EnumPermissionAccess editComponentConfigurationAccess=EnumPermissionAccess.None, 
							EnumPermissionAccess editProjectPermissionsAccess=EnumPermissionAccess.None,
							EnumPermissionAccess approveRejectDeployAccess=EnumPermissionAccess.None, 
							EnumPermissionAccess requestDeploymentAccess=EnumPermissionAccess.None,
							EnumPermissionAccess runDeploymentmentAccess=EnumPermissionAccess.None,
							EnumPermissionAccess editEnvironmentAccess=EnumPermissionAccess.None,
							EnumPermissionAccess editEnvironmentPermissionsAccess = EnumPermissionAccess.None)
				{
					string roleId = this.Fixture.Create<string>();
					var role = new DeployProjectRole
					{
						Id = roleId,
						ProjectId = project.Id,
						RoleName = this.Fixture.Create<string>("RoleName"),
						Assignments = new DeployProjectRoleAssignments
						{
							UserNameList = new List<string> { this.UserName }
						},
						EveryoneRoleIndicator = false
					};
					role.Permissions.EditComponentConfigurationAccess = editComponentConfigurationAccess;
					role.Permissions.CreateEnvironmentAccess = createEnvironmentAccess;
					role.Permissions.EditProjectPermissionsAccess = editProjectPermissionsAccess;
					this.SetPermission(project, environment, role.Permissions.ApproveRejectDeployPermissionList, approveRejectDeployAccess);
					this.SetPermission(project, environment, role.Permissions.RequestDeployPermissionList, requestDeploymentAccess);
					this.SetPermission(project, environment, role.Permissions.RunDeploymentPermissionList, runDeploymentmentAccess);
					this.SetPermission(project, environment, role.Permissions.EditEnvironmentPermissionList, editEnvironmentAccess);
					this.SetPermission(project, environment, role.Permissions.EditEnvironmentPermissionsPermissionList, editEnvironmentPermissionsAccess);

					this.DeployProjectRoleList.Add(role);

					return role;
				}
Пример #25
0
		public void Delete(DeployProject project) 
		{
			_projectManager.DeleteProject(project.Id);
		}
        public DeployProject CreateProject(string projectName, bool usesSharedComponentConfiguration)
        {
            if(string.IsNullOrEmpty(projectName))
            {
                throw new ArgumentNullException("Missing project name");
            }
            var project = new DeployProject
            {
                Id = Guid.NewGuid().ToString(),
                ProjectName = projectName,
                UsesSharedComponentConfiguration = usesSharedComponentConfiguration,
                CreatedByUserName = _userIdentity.UserName,
                CreatedDateTimeUtc = DateTime.UtcNow,
                UpdatedByUserName = _userIdentity.UserName,
                UpdatedDateTimeUtc = DateTime.UtcNow
            };

            using(var db = _sqlConnectionInfo.GetDB())
            {
                var sql = PetaPoco.Sql.Builder
                    .Append("INSERT INTO DeployProject (ID, ProjectName, UsesSharedComponentConfiguration, CreatedByUserName, CreatedDateTimeUtc, UpdatedByUserName, UpdatedDateTimeUtc)")
                    .Append("VALUES (@Id, @ProjectName, @UsesSharedComponentConfiguration, @CreatedByUserName, @CreatedDateTimeUtc, @UpdatedByUserName, @UpdatedDateTimeUtc)", project);
                db.Execute(sql);
            }
            return project;
        }
Пример #27
0
 public DeployEnvironmentConfiguration Mask(DeployProject project, DeployEnvironmentConfiguration environmentConfiguration)
 {
     if(environmentConfiguration == null)
     {
         return null;
     }
     if (project == null)
     {
         throw new ArgumentNullException("Missing project");
     }
     var newEnvironmentConfiguration = AutoMapper.Mapper.Map(environmentConfiguration, new DeployEnvironmentConfiguration());
     if (newEnvironmentConfiguration.ConfigurationValueList != null && newEnvironmentConfiguration.ConfigurationValueList.Any())
     {
         List<DeployStep> deploymentStepList = new List<DeployStep>();
         switch (newEnvironmentConfiguration.ParentType)
         {
             case EnumDeployStepParentType.Component:
                 var component = project.ComponentList.FirstOrDefault(i => i.Id == newEnvironmentConfiguration.ParentId);
                 if(component != null)
                 {
                     deploymentStepList = component.DeploymentStepList;
                 }
                 break;
             case EnumDeployStepParentType.Configuration:
                 var configuration = project.ConfigurationList.FirstOrDefault(i => i.Id == newEnvironmentConfiguration.ParentId);
                 if(configuration != null)
                 {
                     deploymentStepList = configuration.DeploymentStepList;
                 }
                 break;
         }
         var definition = _deploymentValidator.GetComponentConfigurationDefinition(deploymentStepList);
         if(definition.EnvironmentTaskParameterList != null)
         {
             foreach(var parameterDefinition in definition.EnvironmentTaskParameterList.Where(i=>i.Sensitive))
             {
                 if (newEnvironmentConfiguration.ConfigurationValueList.ContainsKey(parameterDefinition.FieldName))
                 {
                     newEnvironmentConfiguration.ConfigurationValueList[parameterDefinition.FieldName] = this.MaskValue;
                 }
             }
         }
         if(definition.MachineTaskParameterList != null && newEnvironmentConfiguration.MachineList != null)
         {
             foreach (var parameterDefinition in definition.MachineTaskParameterList.Where(i => i.Sensitive))
             {
                 foreach(var newMachineConfiguration in newEnvironmentConfiguration.MachineList)
                 {
                     if (newMachineConfiguration.ConfigurationValueList.ContainsKey(parameterDefinition.FieldName))
                     {
                         newMachineConfiguration.ConfigurationValueList[parameterDefinition.FieldName] = this.MaskValue;
                     }
                 }
             }
         }
     }
     return newEnvironmentConfiguration;
 }