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); }
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 AssertEnvironment(DeployEnvironment expected, DeployEnvironment actual) { Assert.IsNotNull(actual); Assert.AreEqual(expected.ProjectId, actual.ProjectId); Assert.AreEqual(expected.EnvironmentName, actual.EnvironmentName); AssertHelpers.AssertBaseDto(expected, actual); AssertEnvironmentConfigurationList(expected.ComponentList, actual.ComponentList); AssertEnvironmentConfigurationList(expected.ConfigurationList, actual.ConfigurationList); }
public object Post(DeployEnvironment environment) { if (string.IsNullOrEmpty(environment.Id)) { return _projectManager.CreateEnvironment(environment.ProjectId, environment.EnvironmentName, environment.ComponentList, environment.ConfigurationList); } else { var project = _projectManager.GetProject(environment.ProjectId); var originalEnvironment = _projectManager.GetEnvironment(environment.Id, environment.ProjectId); var unmaskedEnvironment = _parameterMasker.Unmask(project, environment, originalEnvironment); return _projectManager.UpdateEnvironment(unmaskedEnvironment.Id, unmaskedEnvironment.ProjectId, unmaskedEnvironment.EnvironmentName, unmaskedEnvironment.ComponentList, unmaskedEnvironment.ConfigurationList); } }
public DeployState CreateDeployState(DeployBuild build, DeployProjectBranch branch, DeployEnvironment environment, DeployComponent component, IEnumerable<DeployMachine> machineList, string deployBatchRequestItemId) { if (build == null) { throw new ArgumentNullException("Missing build"); } if (branch == null) { throw new ArgumentNullException("Missing branch"); } if (component == null) { throw new ArgumentNullException("Missing component"); } if (environment == null) { throw new ArgumentNullException("Missing environment"); } if (machineList == null) { throw new ArgumentNullException("Missing machineList"); } if (deployBatchRequestItemId == null) { throw new ArgumentNullException("Missing deployBatchRequestItemId"); } var deployState = new DeployState { Id = Guid.NewGuid().ToString(), ProjectId = environment.ProjectId, Build = build, Branch = branch, Environment = environment, Component = component, MachineList = machineList.ToList(), Status = EnumDeployStatus.NotStarted, SubmittedDateTimeUtc = DateTime.UtcNow, DeployBatchRequestItemId = deployBatchRequestItemId, CreatedDateTimeUtc = DateTime.UtcNow, CreatedByUserName = _userIdentity.UserName, UpdatedDateTimeUtc = DateTime.UtcNow, UpdatedByUserName = _userIdentity.UserName }; _documentSession.StoreSaveEvict(deployState); return deployState; }
public object Get(DeployEnvironment request) { if(request == null || (string.IsNullOrEmpty(request.Id) && string.IsNullOrEmpty(request.ProjectId))) { throw new ArgumentNullException(); } var project = _projectManager.GetProject(request.ProjectId); if (!string.IsNullOrEmpty(request.Id)) { var environment = _projectManager.GetEnvironment(request.Id, request.ProjectId); return _parameterMasker.Mask(project, environment); } else { var environmentList = _projectManager.GetEnvironmentList(request.ProjectId); return _parameterMasker.Mask(project, environmentList); } }
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; }
public DeployState CreateDeployState(DeployBuild build, DeployProjectBranch branch, DeployEnvironment environment, DeployComponent component, IEnumerable<DeployMachine> machineList, string deployBatchRequestItemId) { var deployState = new DeployState { Id = Guid.NewGuid().ToString(), ProjectId = environment.ProjectId, Build = build, Branch = branch, Environment = environment, Component = component, MachineList = machineList.ToList(), Status = EnumDeployStatus.NotStarted, SubmittedDateTimeUtc = DateTime.UtcNow, DeployBatchRequestItemId = deployBatchRequestItemId, CreatedDateTimeUtc = DateTime.UtcNow, CreatedByUserName = _userIdentity.UserName, UpdatedDateTimeUtc = DateTime.UtcNow, UpdatedByUserName = _userIdentity.UserName }; _offlineDataProvider.SaveDeployState(deployState); return deployState; }
public void Delete(DeployEnvironment environment) { _projectManager.DeleteEnvironment(environment.Id, environment.ProjectId); }
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; }
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; }
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); } }
public DeployState CreateDeployState(DeployBuild build, DeployProjectBranch branch, DeployEnvironment environment, DeployComponent component, IEnumerable<DeployMachine> machineList, string deployBatchRequestItemId) { if (build == null) { throw new ArgumentNullException("Missing build"); } if (branch == null) { throw new ArgumentNullException("Missing branch"); } if (component == null) { throw new ArgumentNullException("Missing component"); } if (environment == null) { throw new ArgumentNullException("Missing environment"); } if (machineList == null) { throw new ArgumentNullException("Missing machineList"); } if (deployBatchRequestItemId == null) { throw new ArgumentNullException("Missing deployBatchRequestItemId"); } var sqlDeployState = new SqlDeployState { ID = Guid.NewGuid().ToString(), ProjectID = build.ProjectId, BranchID = branch.Id, BranchJson = branch.ToJson(), BuildID = build.Id, BuildJson = build.ToJson(), ComponentID = component.Id, ComponentJson = component.ToJson(), EnvironmentID = environment.Id, EnvironmentName = environment.EnvironmentName, EnvironmentJson = environment.ToJson(), DeployBatchRequestItemID = deployBatchRequestItemId, DeploymentCompleteDateTimeUtc = null, DeploymentStartedDateTimeUtc = null, ErrorDetails = null, SortableVersion = build.SortableVersion, EnumDeployStatusID = (int)EnumDeployStatus.NotStarted, CreatedByUserName = _userIdentity.UserName, CreatedDateTimeUtc = DateTime.UtcNow, UpdatedByUserName = _userIdentity.UserName, UpdatedDateTimeUtc = DateTime.UtcNow, SubmittedDateTimeUtc = DateTime.UtcNow }; var branchJson = branch.ToJson(); var buildJson = build.ToJson(); var componentJson = component.ToJson(); var environmentJson = environment.ToJson(); using(var db = _sqlConnectionInfo.GetDB()) { var deployStateSql = PetaPoco.Sql.Builder .Append("INSERT INTO DeployState (ID, DeployBatchRequestItemID, EnumDeployStatusID, ProjectID, BranchID, BuildID, EnvironmentID, EnvironmentName, ComponentID,") .Append("BranchJson, BuildJson, EnvironmentJson, ComponentJson, SubmittedDateTimeUtc, DeploymentStartedDateTimeUtc, DeploymentCompleteDateTimeUtc, ") .Append("ErrorDetails, SortableVersion, CreatedByUserName, CreatedDateTimeUtc, UpdatedByUserName, UpdatedDateTimeUtc)") .Append("VALUES (@ID, @DeployBatchRequestItemID, @EnumDeployStatusID, @ProjectID, @BranchID, @BuildID, @EnvironmentID, @EnvironmentName, @ComponentID,", sqlDeployState) .Append("@BranchJson, @BuildJson, @EnvironmentJson, @ComponentJson, @SubmittedDateTimeUtc, @DeploymentStartedDateTimeUtc, @DeploymentCompleteDateTimeUtc,", sqlDeployState) .Append("@ErrorDetails, @SortableVersion, @CreatedByUserName, @CreatedDateTimeUtc, @UpdatedByUserName, @UpdatedDateTimeUtc)", sqlDeployState); db.Execute(deployStateSql); foreach(var machine in machineList) { var sqlMachine = new SqlDeployStateMachine { ID = Guid.NewGuid().ToString(), DeployStateID = sqlDeployState.ID, MachineID = machine.Id, MachineName = machine.MachineName, MachineJson = machine.ToJson(), CreatedByUserName = _userIdentity.UserName, CreatedDateTimeUtc = DateTime.UtcNow, UpdatedByUserName = _userIdentity.UserName, UpdatedDateTimeUtc = DateTime.UtcNow }; var machineSql = PetaPoco.Sql.Builder .Append("INSERT INTO DeployStateMachine (ID, DeployStateID, MachineID, MachineName, MachineJson, CreatedByUserName, CreatedDateTimeUtc, UpdatedByUserName, UpdatedDateTimeUtc)") .Append("VALUES (@ID, @DeployStateID, @MachineID, @MachineName, @MachineJson, @CreatedByUserName, @CreatedDateTimeUtc, @UpdatedByUserName, @UpdatedDateTimeUtc)", sqlMachine); db.Execute(machineSql); } } return GetDeployState(sqlDeployState.ID); }
public DeployEnvironment CreateEnvironment(string projectId, string environmentName, IEnumerable<DeployEnvironmentConfiguration> componentList, IEnumerable<DeployEnvironmentConfiguration> configurationList) { if(string.IsNullOrEmpty(projectId)) { throw new ArgumentNullException("Missing project ID"); } if(string.IsNullOrEmpty(environmentName)) { throw new ArgumentNullException("Missing environment name"); } VerifyProjectExists(projectId); var item = new DeployEnvironment { Id = Guid.NewGuid().ToString(), ProjectId = projectId, EnvironmentName = environmentName, CreatedByUserName = _userIdentity.UserName, CreatedDateTimeUtc = DateTime.UtcNow, UpdatedByUserName = _userIdentity.UserName, UpdatedDateTimeUtc = DateTime.UtcNow, ComponentList = (componentList ?? new List<DeployEnvironmentConfiguration>()).ToList(), ConfigurationList = (configurationList ?? new List<DeployEnvironmentConfiguration>()).ToList() }; UpdateEnvironmentComponentList(item.ComponentList, item.Id, projectId, environmentName, EnumDeployStepParentType.Component); UpdateEnvironmentComponentList(item.ConfigurationList, item.Id, projectId, environmentName, EnumDeployStepParentType.Configuration); using (var db = _sqlConnectionInfo.GetDB()) { var sql = PetaPoco.Sql.Builder .Append("INSERT INTO DeployEnvironment (ID, DeployProjectID, EnvironmentName, CreatedDateTimeUtc, CreatedByUserName, UpdatedDateTimeUtc, UpdatedByUserName)") .Append("VALUES (@Id, @ProjectId, @EnvironmentName, @CreatedDateTimeUtc, @CreatedByUserName, @UpdatedDateTimeUtc, @UpdatedByUserName)", item); db.Execute(sql); } SaveEnvironmentConfigurationList(item.Id, item.ComponentList, EnumDeployStepParentType.Component); SaveEnvironmentConfigurationList(item.Id, item.ConfigurationList, EnumDeployStepParentType.Configuration); return item; }
private void LoadEnvironmentChildren(DeployEnvironment item) { item.ComponentList = GetEnvironmentConfigurationList(item.Id, EnumDeployStepParentType.Component); item.ConfigurationList = GetEnvironmentConfigurationList(item.Id, EnumDeployStepParentType.Configuration); }
public IEnumerable<DeployEnvironmentConfiguration> Unmask(DeployProject project, IEnumerable<DeployEnvironmentConfiguration> environmentConfigurationList, DeployEnvironment originalEnvironment) { 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.Unmask(project, configuration, originalEnvironment); newConfigurationList.Add(newConfiguration); } return newConfigurationList; }