Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ScopeVariables to tenant variables #874

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,7 @@ Octopus.Client.Editors.Async
Task<TenantVariablesEditor> Load()
Task<TenantVariablesEditor> Save()
Octopus.Client.Editors.Async.TenantVariablesEditor SetLibraryVariableValue(Octopus.Client.Model.LibraryVariableSetResource, String, Octopus.Client.Model.PropertyValueResource)
Octopus.Client.Editors.Async.TenantVariablesEditor SetLibraryVariableValue(Octopus.Client.Model.LibraryVariableSetResource, String, Octopus.Client.Model.PropertyValueResource, String[])
Octopus.Client.Editors.Async.TenantVariablesEditor SetProjectVariableValue(Octopus.Client.Model.ProjectResource, Octopus.Client.Model.EnvironmentResource, String, Octopus.Client.Model.PropertyValueResource)
}
class UsernamePasswordAccountEditor
Expand Down Expand Up @@ -2448,6 +2449,13 @@ Octopus.Client.Model
.ctor()
Octopus.Client.Model.TResource Resource { get; set; }
}
class CommonVariableValueResource
{
.ctor()
String[] Scope { get; set; }
String TemplateId { get; set; }
Octopus.Client.Model.PropertyValueResource Value { get; set; }
}
CommunicationStyle
{
None = 0
Expand Down Expand Up @@ -3587,10 +3595,12 @@ Octopus.Client.Model
String LibraryVariableSetId { get; }
String LibraryVariableSetName { get; set; }
Octopus.Client.Extensibility.LinkCollection Links { get; set; }
List<CommonVariableValueResource> ScopedVariables { get; set; }
List<ActionTemplateParameterResource> Templates { get; set; }
Dictionary<String, PropertyValueResource> Variables { get; set; }
Octopus.Client.Model.PropertyValueResource GetVariableValue(String)
void SetVariableValue(String, Octopus.Client.Model.PropertyValueResource)
void SetVariableValue(String, Octopus.Client.Model.PropertyValueResource, String[])
Boolean TryGetVariableValue(String, Octopus.Client.Model.PropertyValueResource&)
}
class LibraryVariableSetProjectUsage
Expand Down Expand Up @@ -5765,6 +5775,7 @@ Octopus.Client.Model
Octopus.Client.Model.PropertyValueResource GetLibraryVariableValue(Octopus.Client.Model.LibraryVariableSetResource, String)
Octopus.Client.Model.PropertyValueResource GetProjectVariableValue(Octopus.Client.Model.ProjectResource, Octopus.Client.Model.EnvironmentResource, String)
void SetLibraryVariableValue(Octopus.Client.Model.LibraryVariableSetResource, String, Octopus.Client.Model.PropertyValueResource)
void SetLibraryVariableValue(Octopus.Client.Model.LibraryVariableSetResource, String, Octopus.Client.Model.PropertyValueResource, String[])
void SetProjectVariableValue(Octopus.Client.Model.ProjectResource, Octopus.Client.Model.EnvironmentResource, String, Octopus.Client.Model.PropertyValueResource)
Boolean TryGetLibraryVariableValue(Octopus.Client.Model.LibraryVariableSetResource, String, Octopus.Client.Model.PropertyValueResource&)
Boolean TryGetProjectVariableValue(Octopus.Client.Model.ProjectResource, Octopus.Client.Model.EnvironmentResource, String, Octopus.Client.Model.PropertyValueResource&)
Expand All @@ -5774,10 +5785,12 @@ Octopus.Client.Model
String LibraryVariableSetId { get; }
String LibraryVariableSetName { get; set; }
Octopus.Client.Extensibility.LinkCollection Links { get; set; }
List<CommonVariableValueResource> ScopedVariables { get; set; }
List<ActionTemplateParameterResource> Templates { get; set; }
Dictionary<String, PropertyValueResource> Variables { get; set; }
Octopus.Client.Model.PropertyValueResource GetVariableValue(String)
void SetVariableValue(String, Octopus.Client.Model.PropertyValueResource)
void SetVariableValue(String, Octopus.Client.Model.PropertyValueResource, String[])
Boolean TryGetVariableValue(String, Octopus.Client.Model.PropertyValueResource&)
}
class Project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,7 @@ Octopus.Client.Editors.Async
Task<TenantVariablesEditor> Load()
Task<TenantVariablesEditor> Save()
Octopus.Client.Editors.Async.TenantVariablesEditor SetLibraryVariableValue(Octopus.Client.Model.LibraryVariableSetResource, String, Octopus.Client.Model.PropertyValueResource)
Octopus.Client.Editors.Async.TenantVariablesEditor SetLibraryVariableValue(Octopus.Client.Model.LibraryVariableSetResource, String, Octopus.Client.Model.PropertyValueResource, String[])
Octopus.Client.Editors.Async.TenantVariablesEditor SetProjectVariableValue(Octopus.Client.Model.ProjectResource, Octopus.Client.Model.EnvironmentResource, String, Octopus.Client.Model.PropertyValueResource)
}
class UsernamePasswordAccountEditor
Expand Down Expand Up @@ -2465,6 +2466,13 @@ Octopus.Client.Model
.ctor()
Octopus.Client.Model.TResource Resource { get; set; }
}
class CommonVariableValueResource
{
.ctor()
String[] Scope { get; set; }
String TemplateId { get; set; }
Octopus.Client.Model.PropertyValueResource Value { get; set; }
}
CommunicationStyle
{
None = 0
Expand Down Expand Up @@ -3604,10 +3612,12 @@ Octopus.Client.Model
String LibraryVariableSetId { get; }
String LibraryVariableSetName { get; set; }
Octopus.Client.Extensibility.LinkCollection Links { get; set; }
List<CommonVariableValueResource> ScopedVariables { get; set; }
List<ActionTemplateParameterResource> Templates { get; set; }
Dictionary<String, PropertyValueResource> Variables { get; set; }
Octopus.Client.Model.PropertyValueResource GetVariableValue(String)
void SetVariableValue(String, Octopus.Client.Model.PropertyValueResource)
void SetVariableValue(String, Octopus.Client.Model.PropertyValueResource, String[])
Boolean TryGetVariableValue(String, Octopus.Client.Model.PropertyValueResource&)
}
class LibraryVariableSetProjectUsage
Expand Down Expand Up @@ -5786,6 +5796,7 @@ Octopus.Client.Model
Octopus.Client.Model.PropertyValueResource GetLibraryVariableValue(Octopus.Client.Model.LibraryVariableSetResource, String)
Octopus.Client.Model.PropertyValueResource GetProjectVariableValue(Octopus.Client.Model.ProjectResource, Octopus.Client.Model.EnvironmentResource, String)
void SetLibraryVariableValue(Octopus.Client.Model.LibraryVariableSetResource, String, Octopus.Client.Model.PropertyValueResource)
void SetLibraryVariableValue(Octopus.Client.Model.LibraryVariableSetResource, String, Octopus.Client.Model.PropertyValueResource, String[])
void SetProjectVariableValue(Octopus.Client.Model.ProjectResource, Octopus.Client.Model.EnvironmentResource, String, Octopus.Client.Model.PropertyValueResource)
Boolean TryGetLibraryVariableValue(Octopus.Client.Model.LibraryVariableSetResource, String, Octopus.Client.Model.PropertyValueResource&)
Boolean TryGetProjectVariableValue(Octopus.Client.Model.ProjectResource, Octopus.Client.Model.EnvironmentResource, String, Octopus.Client.Model.PropertyValueResource&)
Expand All @@ -5795,10 +5806,12 @@ Octopus.Client.Model
String LibraryVariableSetId { get; }
String LibraryVariableSetName { get; set; }
Octopus.Client.Extensibility.LinkCollection Links { get; set; }
List<CommonVariableValueResource> ScopedVariables { get; set; }
List<ActionTemplateParameterResource> Templates { get; set; }
Dictionary<String, PropertyValueResource> Variables { get; set; }
Octopus.Client.Model.PropertyValueResource GetVariableValue(String)
void SetVariableValue(String, Octopus.Client.Model.PropertyValueResource)
void SetVariableValue(String, Octopus.Client.Model.PropertyValueResource, String[])
Boolean TryGetVariableValue(String, Octopus.Client.Model.PropertyValueResource&)
}
class Project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,12 @@ public TenantVariablesEditor SetLibraryVariableValue(
Instance.SetLibraryVariableValue(libraryVariableSetResource, templateName, value);
return this;
}

public TenantVariablesEditor SetLibraryVariableValue(LibraryVariableSetResource libraryVariableSetResource,
string templateName, PropertyValueResource value, string[] scope)
{
Instance.SetLibraryVariableValue(libraryVariableSetResource, templateName, value, scope);
return this;
}
}
}
10 changes: 10 additions & 0 deletions source/Octopus.Server.Client/Model/CommonVariableValueResource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Octopus.Client.Model;

public class CommonVariableValueResource
{
public string TemplateId { get; set; }

public PropertyValueResource Value { get; set; }

public string[] Scope { get; set; }
}
38 changes: 38 additions & 0 deletions source/Octopus.Server.Client/Model/TenantVariableResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ public void SetLibraryVariableValue(
libraryVariables.SetVariableValue(templateName, value);
}

public void SetLibraryVariableValue(LibraryVariableSetResource libraryVariableSetResource, string templateName,
PropertyValueResource value, string[] scope)
{
if (!LibraryVariables.TryGetValue(libraryVariableSetResource.Id, out var libraryVariables))
{
throw new ArgumentException("Supplied library variable set is not connected", nameof(libraryVariableSetResource));
}

libraryVariables.SetVariableValue(templateName, value, scope);
}

public class Project
{
public Project(string projectId)
Expand Down Expand Up @@ -168,6 +179,8 @@ public Library(string libraryVariableSetId)

public Dictionary<string, PropertyValueResource> Variables { get; set; } = new Dictionary<string, PropertyValueResource>();

public List<CommonVariableValueResource> ScopedVariables { get; set; } = [];

public LinkCollection Links { get; set; }

public bool TryGetVariableValue(string templateName, out PropertyValueResource value)
Expand Down Expand Up @@ -203,6 +216,31 @@ public void SetVariableValue(string templateName, PropertyValueResource value)

Variables[templateId] = value;
}

public void SetVariableValue(string templateName, PropertyValueResource value, string[] scope)
{
var templateId = Templates.SingleOrDefault(t => t.Name == templateName)?.Id;
if (templateId is null)
{
throw new ArgumentException($"No project variable template with name '{templateName}'");
}

var existingVariable = ScopedVariables
.Where(v => string.Equals(v.TemplateId, templateId, StringComparison.OrdinalIgnoreCase))
.FirstOrDefault(v => scope.All(s => v.Scope.Contains(s, StringComparer.OrdinalIgnoreCase)));
if (existingVariable is not null)
{
existingVariable.Value = value;
return;
}

ScopedVariables.Add(new CommonVariableValueResource
{
TemplateId = templateId,
Value = value,
Scope = scope
});
}
}

public string SpaceId { get; set; }
Expand Down
Loading