Skip to content

Commit a8cae54

Browse files
committed
fix(Solution): Fixed/renamed/added environment variables
Signed-off-by: Charles d'Avernas <[email protected]>
1 parent 5e6c4ec commit a8cae54

File tree

7 files changed

+46
-7
lines changed

7 files changed

+46
-7
lines changed

deployments/docker-compose/docker-compose.build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ services:
1414
SYNAPSE_DASHBOARD_SERVE: true
1515
SYNAPSE_API_AUTH_TOKEN_FILE: /app/tokens.yaml
1616
SYNAPSE_API_JWT_AUTHORITY: http://api:8080
17+
SYNAPSE_API_CLOUD_EVENTS_ENDPOINT: https://webhook.site/a4aff725-0711-48b2-a9d2-5d1b806d04d0
1718
volumes:
1819
- ./config/tokens.yaml:/app/tokens.yaml
1920
ports:
@@ -31,6 +32,7 @@ services:
3132
SYNAPSE_OPERATOR_NAME: operator-1
3233
SYNAPSE_RUNNER_API: http://api:8080
3334
SYNAPSE_RUNNER_LIFECYCLE_EVENTS: true
35+
SYNAPSE_RUNNER_CONTAINER_PLATFORM: docker
3436
DOCKER_HOST: unix:///var/run/docker.sock
3537
extra_hosts:
3638
- "host.docker.internal:host-gateway"

deployments/docker-compose/docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ services:
1212
SYNAPSE_DASHBOARD_SERVE: true
1313
SYNAPSE_API_AUTH_TOKEN_FILE: /app/tokens.yaml
1414
SYNAPSE_API_JWT_AUTHORITY: http://api:8080
15+
SYNAPSE_API_CLOUD_EVENTS_ENDPOINT: https://webhook.site/a4aff725-0711-48b2-a9d2-5d1b806d04d0
1516
volumes:
1617
- ./config/tokens.yaml:/app/tokens.yaml
1718
ports:
@@ -27,6 +28,7 @@ services:
2728
SYNAPSE_OPERATOR_NAME: operator-1
2829
SYNAPSE_RUNNER_API: http://api:8080
2930
SYNAPSE_RUNNER_LIFECYCLE_EVENTS: true
31+
SYNAPSE_RUNNER_CONTAINER_PLATFORM: docker
3032
DOCKER_HOST: unix:///var/run/docker.sock
3133
extra_hosts:
3234
- "host.docker.internal:host-gateway"

src/api/Synapse.Api.Application/Commands/Events/PublishCloudEventCommand.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,19 @@ public class PublishCloudEventCommandHandler(ILogger<PublishCloudEventCommandHan
4949
/// <inheritdoc/>
5050
public virtual async Task<IOperationResult> HandleAsync(PublishCloudEventCommand command, CancellationToken cancellationToken = default)
5151
{
52-
if (options.Value.Events?.Endpoint == null) return this.Ok();
52+
if (options.Value.CloudEvents.Endpoint == null)
53+
{
54+
logger.LogWarning("No endpoint configured for cloud events. Event will not be published.");
55+
return this.Ok();
56+
}
5357
var json = jsonSerializer.SerializeToText(command.CloudEvent);
5458
using var content = new StringContent(json, Encoding.UTF8, CloudEventContentType.Json);
55-
using var request = new HttpRequestMessage(HttpMethod.Post, options.Value.Events.Endpoint) { Content = content };
59+
using var request = new HttpRequestMessage(HttpMethod.Post, options.Value.CloudEvents.Endpoint) { Content = content };
5660
using var response = await httpClient.SendAsync(request, cancellationToken).ConfigureAwait(false);
5761
json = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
5862
if (!response.IsSuccessStatusCode)
5963
{
60-
logger.LogError("An error occurred while publishing the cloud event with id '{eventId}' to the configure endpoint '{endpoint}': {ex}", command.CloudEvent.Id, options.Value.Events.Endpoint, json);
64+
logger.LogError("An error occurred while publishing the cloud event with id '{eventId}' to the configure endpoint '{endpoint}': {ex}", command.CloudEvent.Id, options.Value.CloudEvents.Endpoint, json);
6165
response.EnsureSuccessStatusCode();
6266
}
6367
return this.Ok();

src/api/Synapse.Api.Application/Configuration/CloudEventOptions.cs renamed to src/api/Synapse.Api.Application/Configuration/ApiServerCloudEventOptions.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,23 @@ namespace Synapse.Api.Application.Configuration;
1818
/// <summary>
1919
/// Represents the options used to configure the Cloud Events published by the Synapse API server
2020
/// </summary>
21-
public class CloudEventOptions
21+
public class ApiServerCloudEventOptions
2222
{
2323

24+
/// <summary>
25+
/// Initializes a new <see cref="CloudEvent"/>
26+
/// </summary>
27+
/// <exception cref="Exception"></exception>
28+
public ApiServerCloudEventOptions()
29+
{
30+
var env = Environment.GetEnvironmentVariable(SynapseDefaults.EnvironmentVariables.Api.CloudEvents.Endpoint);
31+
if (!string.IsNullOrWhiteSpace(env))
32+
{
33+
if (!Uri.TryCreate(env, UriKind.Absolute, out var endpoint)) throw new Exception("The Cloud Events endpoint must be a valid absolute URI");
34+
this.Endpoint = endpoint;
35+
}
36+
}
37+
2438
/// <summary>
2539
/// Gets/sets the uri, if any, to which to publish <see cref="CloudEvent"/>s
2640
/// </summary>

src/api/Synapse.Api.Application/Configuration/ApiServerOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ public ApiServerOptions()
4141
/// <summary>
4242
/// Gets/sets the options used to configure the cloud events published by the Synapse API Server
4343
/// </summary>
44-
public virtual CloudEventOptions? Events { get; set; }
44+
public virtual ApiServerCloudEventOptions CloudEvents { get; set; } = new();
4545

4646
}

src/api/Synapse.Api.Server/appsettings.Development.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
}
1919
}
2020
},
21-
"Events": {
21+
"CloudEvents": {
2222
"Endpoint": "https://webhook.site/a4aff725-0711-48b2-a9d2-5d1b806d04d0"
2323
}
2424
}

src/core/Synapse.Core/SynapseDefaults.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,24 @@ public static class Oidc
456456

457457
}
458458

459+
/// <summary>
460+
/// Exposes constants about environment variables related to cloud events published by the API
461+
/// </summary>
462+
public static class CloudEvents
463+
{
464+
465+
/// <summary>
466+
/// Gets the prefix for all API related environment variables
467+
/// </summary>
468+
public const string Prefix = Api.Prefix + "CLOUD_EVENTS_";
469+
470+
/// <summary>
471+
/// Gets the absolute uri of the endpoint the API must publish cloud events to
472+
/// </summary>
473+
public const string Endpoint = Prefix + "ENDPOINT";
474+
475+
}
476+
459477
}
460478

461479
/// <summary>
@@ -544,7 +562,6 @@ public static class Runner
544562
/// </summary>
545563
public const string LifecycleEvents = Prefix + "LIFECYCLE_EVENTS";
546564

547-
548565
}
549566

550567
/// <summary>

0 commit comments

Comments
 (0)