-
Notifications
You must be signed in to change notification settings - Fork 195
Expand file tree
/
Copy pathMeilisearchResource.cs
More file actions
62 lines (51 loc) · 2.46 KB
/
Copy pathMeilisearchResource.cs
File metadata and controls
62 lines (51 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
namespace Aspire.Hosting.ApplicationModel;
/// <summary>
/// A resource that represents a Meilisearch
/// </summary>
public class MeilisearchResource : ContainerResource, IResourceWithConnectionString
{
internal const string PrimaryEndpointName = "http";
/// <param name="name">The name of the resource.</param>
/// <param name="masterKey">A parameter that contains the Meilisearch master key.</param>
public MeilisearchResource(string name, ParameterResource masterKey) : base(name)
{
ArgumentNullException.ThrowIfNull(masterKey);
MasterKeyParameter = masterKey;
}
private EndpointReference? _primaryEndpoint;
/// <summary>
/// Gets the primary endpoint for the Meilisearch. This endpoint is used for all API calls over HTTP.
/// </summary>
public EndpointReference PrimaryEndpoint => _primaryEndpoint ??= new(this, PrimaryEndpointName);
/// <summary>
/// Gets the host endpoint reference for this resource.
/// </summary>
public EndpointReferenceExpression Host => PrimaryEndpoint.Property(EndpointProperty.Host);
/// <summary>
/// Gets the port endpoint reference for this resource.
/// </summary>
public EndpointReferenceExpression Port => PrimaryEndpoint.Property(EndpointProperty.Port);
/// <summary>
/// Gets the parameter that contains the Meilisearch superuser password.
/// </summary>
public ParameterResource MasterKeyParameter { get; }
/// <summary>
/// Gets the connection string expression for the Meilisearch
/// </summary>
public ReferenceExpression ConnectionStringExpression =>
ReferenceExpression.Create($"Endpoint=http://{PrimaryEndpoint.Property(EndpointProperty.Host)}:{PrimaryEndpoint.Property(EndpointProperty.Port)};MasterKey={MasterKeyParameter}");
/// <summary>
/// Gets the connection URI expression for the Meilisearch server.
/// </summary>
/// <remarks>
/// Format: <c>http://{host}:{port}</c>.
/// </remarks>
public ReferenceExpression UriExpression => ReferenceExpression.Create($"http://{Host}:{Port}");
IEnumerable<KeyValuePair<string, ReferenceExpression>> IResourceWithConnectionString.GetConnectionProperties()
{
yield return new("Host", ReferenceExpression.Create($"{Host}"));
yield return new("Port", ReferenceExpression.Create($"{Port}"));
yield return new("MasterKey", ReferenceExpression.Create($"{MasterKeyParameter}"));
yield return new("Uri", UriExpression);
}
}