Skip to content

Commit 6056fac

Browse files
authored
Merge pull request #138 from OctopusDeploy/enf0rc3-bft/will/remove-dependendy-on-octopus-data
Removed dependency on Octopus.Data and updated it to use Octopus.Server.MessageContracts
2 parents 5091af3 + 23db53d commit 6056fac

23 files changed

+479
-23
lines changed

source/Tests/RealLifeScenario/Entities/DeploymentAction.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System;
22
using Newtonsoft.Json;
3-
using Octopus.Data.Model;
4-
using Octopus.Server.Extensibility.HostServices.Model;
53

64
namespace Tests.RealLifeScenario.Entities
75
{

source/Tests/RealLifeScenario/Entities/DeploymentActionExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using Octopus.Server.Extensibility.HostServices.Model;
32

43
namespace Tests.RealLifeScenario.Entities
54
{
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
using Octopus.TinyTypes;
3+
4+
namespace Tests.RealLifeScenario.Entities
5+
{
6+
/// <summary>
7+
/// Copied subset of class from server.
8+
/// </summary>
9+
public class DeploymentEnvironmentId : PrefixedNumericStringTinyType
10+
{
11+
internal DeploymentEnvironmentId(string value) : base(value, "Environments-")
12+
{
13+
}
14+
}
15+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
using Octopus.TinyTypes;
3+
4+
namespace Tests.RealLifeScenario.Entities
5+
{
6+
/// <summary>
7+
/// Copied subset of class from server.
8+
/// </summary>
9+
public class FeedIdOrName : CaseInsensitiveStringTinyType
10+
{
11+
internal FeedIdOrName(string value) : base(value)
12+
{
13+
}
14+
}
15+
16+
public static class FeedIdOrNameExtensionMethods
17+
{
18+
[return: NotNullIfNotNull("value")]
19+
public static FeedIdOrName? ToFeedIdOrName(this string? value) => value is null ? null : new FeedIdOrName(value);
20+
}
21+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Tests.RealLifeScenario.Entities
2+
{
3+
/// <summary>
4+
/// Copied from server.
5+
/// </summary>
6+
public enum GuidedFailureMode
7+
{
8+
EnvironmentDefault,
9+
Off,
10+
On
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Tests.RealLifeScenario.Entities
2+
{
3+
/// <summary>
4+
/// Copied from server.
5+
/// </summary>
6+
public enum PackageAcquisitionLocation
7+
{
8+
Server,
9+
ExecutionTarget,
10+
NotAcquired
11+
}
12+
}
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Newtonsoft.Json;
4+
using Octopus.Ocl.Converters;
5+
6+
namespace Tests.RealLifeScenario.Entities
7+
{
8+
/// <summary>
9+
/// Copied a subset from server, but it still has Id for serialization purposes, even if it doesn't have the IId interface.
10+
/// Excluded convenience methods.
11+
/// </summary>
12+
/// <summary>
13+
/// Represents a reference from a deployment-process (specifically an action or action-template) to a package.
14+
/// May be named or un-named.
15+
/// </summary>
16+
/// <history>
17+
/// Prior to Octopus 2018.8, deployment actions could have at most a single package-reference. This was
18+
/// captured as properties on the action (Octopus.Action.Package.PackageId, Octopus.Action.Package.FeedId, etc).
19+
/// In 2018.8, we introduced support for actions with multiple packages (initially script steps and kubernetes step).
20+
/// Storing collections of nested objects in the property-bag gets very messy, so package-references were moved into
21+
/// their own class
22+
/// and collection on the deployment actions.
23+
/// </history>
24+
public class PackageReference
25+
{
26+
/// <summary>
27+
/// Constructs a named package-reference.
28+
/// </summary>
29+
/// <param name="name">The package-reference name.</param>
30+
/// <param name="packageId">The package ID or a variable-expression</param>
31+
/// <param name="feedIdOrName">The feed ID or a variable-expression</param>
32+
/// <param name="acquisitionLocation">The location the package should be acquired</param>
33+
public PackageReference(string? name, string packageId, FeedIdOrName feedIdOrName, PackageAcquisitionLocation acquisitionLocation)
34+
: this(name, packageId, feedIdOrName, acquisitionLocation.ToString())
35+
{
36+
}
37+
38+
/// <summary>
39+
/// Constructs a named package-reference.
40+
/// </summary>
41+
/// <param name="name">The package-reference name.</param>
42+
/// <param name="packageId">The package ID or a variable-expression</param>
43+
/// <param name="feedIdOrName">The feed ID or a variable-expression</param>
44+
/// <param name="acquisitionLocation">The location the package should be acquired.
45+
/// May be one <see cref="PackageAcquisitionLocation" /> or a variable-expression.</param>
46+
public PackageReference(string? name, string packageId, FeedIdOrName feedIdOrName, string acquisitionLocation)
47+
: this(
48+
null,
49+
name,
50+
packageId,
51+
feedIdOrName,
52+
acquisitionLocation)
53+
{
54+
}
55+
56+
/// <summary>
57+
/// For JSON deserialization only
58+
/// </summary>
59+
[JsonConstructor]
60+
public PackageReference(string? id,
61+
string? name,
62+
string packageId,
63+
FeedIdOrName feedIdOrName,
64+
string acquisitionLocation)
65+
: this()
66+
{
67+
if (!string.IsNullOrEmpty(id)) Id = id;
68+
69+
PackageId = packageId;
70+
FeedIdOrName = feedIdOrName;
71+
AcquisitionLocation = acquisitionLocation;
72+
Name = name ?? string.Empty;
73+
}
74+
75+
/// <summary>
76+
/// Constructs a primary package (an un-named package reference)
77+
/// </summary>
78+
public PackageReference(string packageId, FeedIdOrName feedIdOrName, PackageAcquisitionLocation acquisitionLocation)
79+
: this(null, packageId, feedIdOrName, acquisitionLocation)
80+
{
81+
}
82+
83+
/// <summary>
84+
/// Constructs a primary package (an un-named package reference)
85+
/// </summary>
86+
public PackageReference(string packageId, FeedIdOrName feedIdOrName, string acquisitionLocation)
87+
: this(null, packageId, feedIdOrName, acquisitionLocation)
88+
{
89+
}
90+
91+
/// <summary>
92+
/// Constructs a primary package (an un-named package reference)
93+
/// </summary>
94+
public PackageReference(string packageId, FeedIdOrName feedIdOrName)
95+
: this(packageId, feedIdOrName, PackageAcquisitionLocation.Server)
96+
{
97+
}
98+
99+
/// <summary>
100+
/// In the scenario where we are migrating from 2.6 instances, we set the ID of the package-reference
101+
/// to the same ID as the deployment-action.
102+
/// This was the least-bad option that let the migrator do its thing when migrating project
103+
/// release-creation-strategy and versioning-strategy.
104+
/// </summary>
105+
public PackageReference(string id) : this()
106+
{
107+
if (!string.IsNullOrEmpty(id)) Id = id;
108+
}
109+
110+
public PackageReference()
111+
{
112+
Id = Guid.NewGuid().ToString();
113+
Properties = new Dictionary<string, string>();
114+
FeedIdOrName = "feeds-builtin".ToFeedIdOrName();
115+
}
116+
117+
public string Id { get; }
118+
119+
/// <summary>
120+
/// An name for the package-reference.
121+
/// This may be empty.
122+
/// This is used to discriminate the package-references. Package ID isn't suitable because an action may potentially
123+
/// have multiple references to the same package ID (e.g. if you wanted to use different versions of the same package).
124+
/// Also, the package ID may be a variable-expression.
125+
/// </summary>
126+
public string Name { get; set; } = string.Empty;
127+
128+
/// <summary>
129+
/// Package ID or a variable-expression
130+
/// </summary>
131+
public string PackageId { get; set; } = string.Empty;
132+
133+
/// <summary>
134+
/// Feed ID, name or a variable-expression
135+
/// </summary>
136+
[JsonProperty("FeedId")] // This is named FeedId for backward-compatibility as we don't yet want to change the underlying database JSON/schema.
137+
[OclName("feed")]
138+
public FeedIdOrName FeedIdOrName { get; set; }
139+
140+
/// <summary>
141+
/// The package-acquisition location.
142+
/// One of <see cref="PackageAcquisitionLocation" /> or a variable-expression
143+
/// </summary>
144+
public string AcquisitionLocation { get; set; } = string.Empty;
145+
146+
/// <summary>
147+
/// Specific version to use for this package. If not specified, package can be
148+
/// selected at release creation or runbook run time.
149+
/// </summary>
150+
public string? Version { get; set; }
151+
152+
/// <summary>
153+
/// This reference identifier is populated when a step package step contains a package reference
154+
/// It allows us to correlate the reference within the step package inputs to this Server package reference
155+
/// </summary>
156+
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
157+
public string? StepPackageInputsReferenceId { get; set; }
158+
159+
/// <summary>
160+
/// This should never be null for new objects but there are a small number of customers with
161+
/// older databases that may have it as null.
162+
/// </summary>
163+
[JsonProperty(ObjectCreationHandling = ObjectCreationHandling.Reuse)]
164+
public IDictionary<string, string>? Properties { get; private set; }
165+
166+
[JsonIgnore]
167+
public bool IsPrimaryPackage => Name == "";
168+
}
169+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
5+
namespace Tests.RealLifeScenario.Entities
6+
{
7+
/// <summary>
8+
/// This is a copy from Octopus.Server.MessageContracts.PackageReferenceCollectionResource, with a subset of properties.
9+
/// </summary>
10+
public class PackageReferenceCollection : ICollection<PackageReference>
11+
{
12+
readonly Dictionary<string, PackageReference> idMap = new(StringComparer.OrdinalIgnoreCase);
13+
14+
readonly Dictionary<string, PackageReference> nameMap = new(StringComparer.OrdinalIgnoreCase);
15+
16+
public PackageReferenceCollection()
17+
{
18+
}
19+
20+
public PackageReferenceCollection(IEnumerable<PackageReference> packages)
21+
{
22+
foreach (var package in packages) Add(package);
23+
}
24+
25+
public PackageReference? PrimaryPackage => nameMap.ContainsKey("") ? nameMap[""] : null;
26+
27+
public bool HasPrimaryPackage => PrimaryPackage != null;
28+
29+
public int Count => nameMap.Count;
30+
31+
public bool IsReadOnly => false;
32+
33+
public void Add(PackageReference item)
34+
{
35+
if (item == null)
36+
{
37+
throw new ArgumentNullException(nameof(item));
38+
}
39+
40+
if (nameMap.ContainsKey(item.Name))
41+
{
42+
throw new ArgumentException($"A package reference with the name '{item.Name}' already exists");
43+
}
44+
45+
if (idMap.ContainsKey(item.Id))
46+
{
47+
throw new ArgumentException($"A package reference with the ID '{item.Id}' already exists");
48+
}
49+
50+
nameMap.Add(item.Name, item);
51+
idMap.Add(item.Id, item);
52+
}
53+
54+
public bool Contains(PackageReference item) => idMap.ContainsKey(item.Id);
55+
56+
public void CopyTo(PackageReference[] array, int arrayIndex)
57+
{
58+
nameMap.Values.CopyTo(array, arrayIndex);
59+
}
60+
61+
public bool Remove(PackageReference item)
62+
{
63+
nameMap.Remove(item.Name);
64+
return idMap.Remove(item.Id);
65+
}
66+
67+
public void Clear()
68+
{
69+
idMap.Clear();
70+
nameMap.Clear();
71+
}
72+
73+
public IEnumerator<PackageReference> GetEnumerator() => nameMap.Values.GetEnumerator();
74+
75+
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
76+
}
77+
}

source/Tests/RealLifeScenario/Entities/PropertiesDictionary.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using Octopus.Server.Extensibility.HostServices.Model;
54

65
namespace Tests.RealLifeScenario.Entities
76
{

0 commit comments

Comments
 (0)