public async Task UpdateVariableSet(VariableSet varSet) { var id = varSet.Id; if (varSet.IdType == VariableSet.VariableIdTypes.Library) { id = (await client.Repository.LibraryVariableSets.Get(id)).VariableSetId; } var set = await client.Repository.VariableSets.Get(id); foreach (var variable in varSet.Variables) { var scope = new ScopeSpecification(); if (variable.EnvironmentIds.Any()) { scope.Add(ScopeField.Environment, new ScopeValue(variable.EnvironmentIds)); } if (variable.TargetIds.Any()) { scope.Add(ScopeField.Machine, new ScopeValue(variable.TargetIds)); } if (variable.RoleIds.Any()) { scope.Add(ScopeField.Role, new ScopeValue(variable.RoleIds)); } set.AddOrUpdateVariableValue(variable.Key, variable.Value, scope); } await client.Repository.VariableSets.Modify(set); }
public async Task UpdateVars(List <SecretVariable> vars, string libraryName, IEnumerable <string> environments, IEnumerable <string> roles, bool apply) { var lib = await _octopusRepository.ValidateLibrary(libraryName).ConfigureAwait(false); var set = await _octopusRepository.VariableSets.Get(lib.VariableSetId).ConfigureAwait(false); var scope = new ScopeSpecification(); foreach (var environment in environments) { var enviro = await _octopusRepository.ValidateEnvironment(environment).ConfigureAwait(false); if (scope.ContainsKey(ScopeField.Environment)) { scope[ScopeField.Environment].Add(enviro.Id); } else { scope.Add(ScopeField.Environment, new ScopeValue(enviro.Id)); } } await _octopusRepository.ValidateRoles(roles).ConfigureAwait(false); scope.Add(ScopeField.Role, new ScopeValue(roles)); foreach (var variable in vars) { set.AddOrUpdateVariableValue(variable.Name, variable.Value, scope, variable.IsSecret); } if (apply) { await _octopusRepository.VariableSets.Modify(set).ConfigureAwait(false); } }
private static ScopeSpecification CreateScope(ScopeSpecification scopeSpec, CopyScopeValue copyAction = null) { var spec = new ScopeSpecification(); foreach (var scope in scopeSpec) { if (scope.Key != ScopeField.Action) spec.Add(scope.Key, new ScopeValue(scope.Value)); else if (copyAction != null) spec.Add(scope.Key, copyAction(scope)); } return spec; }
private static ScopeSpecification CreateScopeSpesification(OctoVariable variable, VariableSetResource variableSet) { var scopeSpecifiaciton = new ScopeSpecification(); variable.Scopes.ForEach(scope => { ScopeField scopeName = FindScopeName(scope); List <ReferenceDataItem> referenceDataItems = FindScopeValue(scopeName, variableSet); List <string> scopeValues = referenceDataItems.Join(scope.Values, refDataItem => refDataItem.Name, selectedScope => selectedScope, (item, s) => item.Id) .ToList(); if (!scopeValues.Any()) { throw new CakeException($"({string.Join(",", scope.Values)}) value(s) can not be found on ({scope.Name}) scope."); } var value = new ScopeValue(scopeValues.First(), scopeValues.Skip(1).ToArray()); scopeSpecifiaciton.Add(scopeName, value); }); return(scopeSpecifiaciton); }
private static ScopeSpecification CreateScope(ScopeSpecification scopeSpec, CopyScopeValue copyAction = null) { var spec = new ScopeSpecification(); foreach (var scope in scopeSpec) { if (scope.Key != ScopeField.Action) { spec.Add(scope.Key, new ScopeValue(scope.Value)); } else if (copyAction != null) { spec.Add(scope.Key, copyAction(scope)); } } return(spec); }
public static ScopeSpecification UpdateWith(this ScopeSpecification resource, IReadOnlyDictionary <VariableScopeType, IEnumerable <ElementReference> > model, IOctopusRepository repository, DeploymentProcessResource deploymentProcess, ProjectResource project) { resource.Clear(); foreach (var kv in model) { resource.Add((ScopeField)kv.Key, new ScopeValue(kv.Value.Select(reference => ResolveId(kv.Key, reference, repository, deploymentProcess, project)))); } return(resource); }