Represents a collection of variables that is attached to a document.
Inheritance: Resource
		private void AddVariableSet(IDictionary<string, SortedSet<VariableResource>> variables, VariableSetResource variableSet, Dictionary<ScopeField, string> scopes)
		{
			var variableScopes = GetVariableScopes(variableSet, scopes);

			foreach (var variable in variableSet.Variables)
			{
				var variableName = variable.Name;

				if (variable.IsSensitive)
				{
					continue;
				}

				if (!variable.Scope.IsApplicableTo(variableScopes))
				{
					continue;
				}

				if (!variables.ContainsKey(variableName))
				{
					variables[variableName] = new SortedSet<VariableResource>(new VariableResourceScopeRankComparer());
				}
				variables[variableName].Add(variable);
			}
		}
Ejemplo n.º 2
0
        public void Init()
        {
            _ps = Utilities.CreatePowerShell(CmdletName, typeof(GetVariableSet));

            var octoRepo = Utilities.AddOctopusRepo(_ps.Runspace.SessionStateProxy.PSVariable);

            // Create a library variable set
            const string vsId = "/api/variables/variableset-LibraryVariableSets-1";
            var libraryResources = new List<LibraryVariableSetResource>
            {
                new LibraryVariableSetResource {Id = "LibraryVariableSets-1", Name = "Octopus"},
                new LibraryVariableSetResource {Id = "LibraryVariableSets-2", Name = "Deploy"},
                new LibraryVariableSetResource {Id = "LibraryVariableSets-3", Name = "Automation"}
            };

            octoRepo.Setup(o => o.LibraryVariableSets.FindAll()).Returns(libraryResources);

            // Create a variableset
            var variableRepo = new Mock<IVariableSetRepository>();
            var vsResource = new VariableSetResource
            {
                Variables = new List<VariableResource>
                {
                    new VariableResource {Name = "Octopus"},
                    new VariableResource {Name = "Deploy"},
                    new VariableResource {Name = "Automation"},
                }
            };
            variableRepo.Setup(v => v.Get(vsId)).Returns(vsResource);

            octoRepo.Setup(o => o.VariableSets).Returns(variableRepo.Object);
        }
Ejemplo n.º 3
0
        private VariableResource CreateVariable(string key, VariableSetResource variableSet)
        {
            var scope = new ScopeSpecification();
            scope.AddRange(VariableFilter.BuildScopeMap(variableSet.ScopeValues, _config.Filter));

            var v = new VariableResource
            {
                Name = key,
                Scope = scope
            };

            variableSet.Variables.Add(v);

            return v;
        }
Ejemplo n.º 4
0
        public void Init()
        {
            _ps = Utilities.CreatePowerShell(CmdletName, typeof(CopyStep));
            var octoRepo = Utilities.AddOctopusRepo(_ps.Runspace.SessionStateProxy.PSVariable);

            // Create project
            var project = new ProjectResource
            {
                Name = "Octopus",
                Description = "Test Source",
                DeploymentProcessId = "deploymentprocesses-1",
                VariableSetId = "variablesets-1",
            };

            // Create projects
            octoRepo.Setup(o => o.Projects.FindByName("Octopus")).Returns(project);
            octoRepo.Setup(o => o.Projects.FindByName("Gibberish")).Returns((ProjectResource)null);

            // Create deployment process
            var action = new DeploymentActionResource { Name = "NuGet", ActionType = "NuGet" };
            action.Environments.Add("environments-1");
            action.Properties.Add("Something", "Value");
            action.SensitiveProperties.Add("SomethingElse", "Secret");

            var step = new DeploymentStepResource { Id = "deploymentsteps-1", Name = "Website" };
            step.Actions.Add(action);

            _process = new DeploymentProcessResource();
            _process.Steps.Add(step);

            octoRepo.Setup(o => o.DeploymentProcesses.Get(It.IsIn(new[] { "deploymentprocesses-1" }))).Returns(_process);
            octoRepo.Setup(o => o.DeploymentProcesses.Get(It.IsIn(new[] { "deploymentprocesses-2" }))).Returns(new DeploymentProcessResource());

            // Create variable set
            var variable = new VariableResource { Name = "Name", Value = "Value" };
            variable.Scope.Add(ScopeField.Action, "DeploymentsActions-1");
            variable.Scope.Add(ScopeField.Environment, "Environments-1");

            var variableSet = new VariableSetResource();
            variableSet.Variables.Add(variable);

            octoRepo.Setup(o => o.VariableSets.Get(It.IsIn(new[] { "variablesets-1" }))).Returns(variableSet);
            octoRepo.Setup(o => o.VariableSets.Get(It.IsIn(new[] { "variablesets-2" }))).Returns(new VariableSetResource());
        }
		private Dictionary<ScopeField, ScopeValue> GetVariableScopes(VariableSetResource variableSet, Dictionary<ScopeField, string> scopes)
		{
			var variableScopes = new Dictionary<ScopeField, ScopeValue>();

			foreach (var scopeField in scopes.Keys)
			{
				var scopeValues = GetScopeValues(variableSet.ScopeValues, scopeField);
				var scopeValueName = scopes[scopeField];
				var scopeValue = scopeValues.FirstOrDefault(item => item.Name == scopeValueName);
				if (scopeValue == null)
				{
					continue;
				}

				variableScopes.Add(scopeField, new ScopeValue(scopeValue.Id));
			}

			return variableScopes;
		}
Ejemplo n.º 6
0
 protected void Modify(VariableSetResource variableSet)
 {
     _repo.VariableSets.Modify(variableSet);
 }
Ejemplo n.º 7
0
        IList<VariableResource> UpdateVariables(VariableSetResource variableSet, IDictionary<string, EnvironmentResource> environments, IDictionary<string, MachineResource> machines)
        {
            var variables = variableSet.Variables;

            foreach (var variable in variables)
            {
                if (variable.IsSensitive)
                {
                    Log.WarnFormat("'{0}' is a sensitive variable and it's value will be reset to a blank string, once the import has completed you will have to update it's value from the UI", variable.Name);
                    variable.Value = String.Empty;
                }
                foreach (var scopeValue in variable.Scope)
                {
                    switch (scopeValue.Key)
                    {
                        case ScopeField.Environment:
                            Log.Debug("Updating the Environment IDs of the Variables scope");
                            var oldEnvironmentIds = scopeValue.Value;
                            var newEnvironmentIds = new List<string>();
                            foreach (var oldEnvironmentId in oldEnvironmentIds)
                            {
                                newEnvironmentIds.Add(environments[oldEnvironmentId].Id);
                            }
                            scopeValue.Value.Clear();
                            scopeValue.Value.AddRange(newEnvironmentIds);
                            break;
                        case ScopeField.Machine:
                            Log.Debug("Updating the Machine IDs of the Variables scope");
                            var oldMachineIds = scopeValue.Value;
                            var newMachineIds = new List<string>();
                            foreach (var oldMachineId in oldMachineIds)
                            {
                                newMachineIds.Add(machines[oldMachineId].Id);
                            }
                            scopeValue.Value.Clear();
                            scopeValue.Value.AddRange(newMachineIds);
                            break;
                    }
                }
            }
            return variables;
        }
Ejemplo n.º 8
0
        void ImportVariableSets(VariableSetResource variableSet,
            ProjectResource importedProject,
            IDictionary<string, EnvironmentResource> environments,
            IDictionary<string, MachineResource> machines,
            IDictionary<ScopeField, List<ReferenceDataItem>> scopeValuesUsed)
        {
            Log.Debug("Importing the Projects Variable Set");
            var existingVariableSet = Repository.VariableSets.Get(importedProject.VariableSetId);

            var variables = UpdateVariables(variableSet, environments, machines);
            existingVariableSet.Variables.Clear();
            existingVariableSet.Variables.AddRange(variables);

            var scopeValues = UpdateScopeValues(environments, machines, scopeValuesUsed);
            existingVariableSet.ScopeValues.Actions.Clear();
            existingVariableSet.ScopeValues.Actions.AddRange(scopeValues.Actions);
            existingVariableSet.ScopeValues.Environments.Clear();
            existingVariableSet.ScopeValues.Environments.AddRange(scopeValues.Environments);
            existingVariableSet.ScopeValues.Machines.Clear();
            existingVariableSet.ScopeValues.Machines.AddRange(scopeValues.Machines);
            existingVariableSet.ScopeValues.Roles.Clear();
            existingVariableSet.ScopeValues.Roles.AddRange(scopeValues.Roles);
            existingVariableSet.ScopeValues.Machines.AddRange(scopeValues.Machines);

            Repository.VariableSets.Modify(existingVariableSet);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// BeginProcessing
        /// </summary>
        protected override void BeginProcessing()
        {
            _octopus = Session.RetrieveSession(this);

            var libraryVariableSet =
                _octopus.LibraryVariableSets.FindOne(
                    v => v.Name.Equals(VariableSet, StringComparison.InvariantCultureIgnoreCase));

            if (libraryVariableSet == null)
                throw new Exception(string.Format("Library variable set '{0}' was not found.", VariableSet));

            _variableSet = _octopus.VariableSets.Get(libraryVariableSet.Link("Variables"));
            WriteDebug("Found variable set" + _variableSet.Id);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// BeginProcessing
        /// </summary>
        protected override void BeginProcessing()
        {
            _octopus = Session.RetrieveSession(this);

            WriteDebug("Got connection");

            // Find the project that owns the variables we want to edit
            var project = _octopus.Projects.FindByName(Project);

            if (project == null)
            {
                const string msg = "Project '{0}' was not found.";
                throw new Exception(string.Format(msg, Project));
            }

            WriteDebug("Found project" + project.Id);

            // Get the variables for editing
            _variableSet = _octopus.VariableSets.Get(project.Link("Variables"));

            WriteDebug("Found variable set" + _variableSet.Id);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// BeginProcessing
        /// </summary>
        protected override void BeginProcessing()
        {
            _octopus = Session.RetrieveSession(this);

            // Find the project that owns the variables we want to edit
            var project = _octopus.Projects.FindByName(Project);

            if (project == null)
                throw new Exception(string.Format("Project '{0}' was not found.", Project));

            // Get the variables for editing
            _variableSet = _octopus.VariableSets.Get(project.Link("Variables"));
        }
 public static void UpdateVariablesVersion(string projectSlug, OctopusRepository octopusRepository,
     ProjectResource project, VariableSetResource varaibleResources)
 {
     var variables = octopusRepository.VariableSets.Get(project.VariableSetId);
     varaibleResources.Version = variables.Version;
 }
 public static void ImportVariables(OctopusRepository octopusRepository, ProjectResource createdProject,
     VariableSetResource variables)
 {
     variables.OwnerId = createdProject.Id;
     variables.Links["Self"] = string.Format("/api/variables/{0}", createdProject.VariableSetId);
     variables.Version = 0;
     octopusRepository.VariableSets.Modify(variables);
 }
Ejemplo n.º 14
0
        public void Init()
        {
            _ps = Utilities.CreatePowerShell(CmdletName, typeof (CopyProject));
            var octoRepo = Utilities.AddOctopusRepo(_ps.Runspace.SessionStateProxy.PSVariable);

            // Create a project group
            var groupResource = new ProjectGroupResource {Name = "Octopus", Id = "projectgroups-1"};
            octoRepo.Setup(o => o.ProjectGroups.FindByName("Octopus")).Returns(groupResource);
            octoRepo.Setup(o => o.ProjectGroups.FindByName("Gibberish")).Returns((ProjectGroupResource) null);

            // Create project
            var project = new ProjectResource
            {
                Name = "Source",
                Description = "Test Source",
                DeploymentProcessId = "deploymentprocesses-1",
                VariableSetId = "variablesets-1",
                DefaultToSkipIfAlreadyInstalled = true,
                IncludedLibraryVariableSetIds = new List<string> { "libraryvariablesets-1" },
                VersioningStrategy = new VersioningStrategyResource(),
                AutoCreateRelease = false,
                ReleaseCreationStrategy = new ReleaseCreationStrategyResource(),
                IsDisabled = false,
                LifecycleId = "lifecycle-1"
            };

            // Create projects
            _projects.Clear();
            _projects.Add(project);

            octoRepo.Setup(o => o.Projects.FindByName("Source")).Returns(project);
            octoRepo.Setup(o => o.Projects.FindByName("Gibberish")).Returns((ProjectResource) null);
            octoRepo.Setup(o => o.Projects.Create(It.IsAny<ProjectResource>())).Returns(
                delegate(ProjectResource p)
                {
                    p.VariableSetId = "variablesets-2";
                    p.DeploymentProcessId = "deploymentprocesses-2";
                    _projects.Add(p);
                    return p;
                }
            );

            // Create deployment process
            var action = new DeploymentActionResource {Name = "Action"};
            action.Environments.Add("environments-1");

            var step = new DeploymentStepResource { Id = "deploymentsteps-1", Name = "Database"};
            step.Actions.Add(action);

            var process = new DeploymentProcessResource();
            process.Steps.Add(step);

            octoRepo.Setup(o => o.DeploymentProcesses.Get(It.IsIn(new[] { "deploymentprocesses-1" }))).Returns(process);
            _copyProcess = new DeploymentProcessResource();
            octoRepo.Setup(o => o.DeploymentProcesses.Get(It.IsIn(new[] { "deploymentprocesses-2" }))).Returns(_copyProcess);

            // Create variable set
            var variable = new VariableResource { Name = "Name", Value = "Value" };
            variable.Scope.Add(ScopeField.Action, "deploymentsactions-1");
            variable.Scope.Add(ScopeField.Environment, "environments-1");

            var sourceVariables = new VariableSetResource();
            sourceVariables.Variables.Add(variable);

            octoRepo.Setup(o => o.VariableSets.Get(It.IsIn(new[] { "variablesets-1" }))).Returns(sourceVariables);
            _copyVariables = new VariableSetResource();
            octoRepo.Setup(o => o.VariableSets.Get(It.IsIn(new[] { "variablesets-2" }))).Returns(_copyVariables);
        }
Ejemplo n.º 15
0
 public void Modify(VariableSetResource variableSetResource)
 {
     _repository.VariableSets.Modify(variableSetResource);
 }