From f935bb3fb5d8b2b74582af65a6b6d2ca0c07c944 Mon Sep 17 00:00:00 2001 From: Jeremy Foster Date: Thu, 28 Mar 2024 16:01:19 -0700 Subject: [PATCH] Fix Data Service email (#130) --- devops/kustomize/base/data-service/config-map.yaml | 1 + devops/kustomize/base/data-service/cron-job.yaml | 6 ++++++ .../kustomize/overlays/dev/data-service/kustomization.yaml | 5 ++++- .../kustomize/overlays/prod/data-service/kustomization.yaml | 3 +++ .../kustomize/overlays/test/data-service/kustomization.yaml | 5 ++++- src/data-service/Config/ServiceOptions.cs | 5 +++++ src/data-service/DataService.cs | 2 +- 7 files changed, 24 insertions(+), 3 deletions(-) diff --git a/devops/kustomize/base/data-service/config-map.yaml b/devops/kustomize/base/data-service/config-map.yaml index 2b07b658..3e39a0f8 100644 --- a/devops/kustomize/base/data-service/config-map.yaml +++ b/devops/kustomize/base/data-service/config-map.yaml @@ -15,6 +15,7 @@ metadata: created-by: jeremy.foster data: API_URL: http://api:8080 + ENVIRONMENT: "DEV" --- kind: ConfigMap apiVersion: v1 diff --git a/devops/kustomize/base/data-service/cron-job.yaml b/devops/kustomize/base/data-service/cron-job.yaml index b349ec08..731ed35a 100644 --- a/devops/kustomize/base/data-service/cron-job.yaml +++ b/devops/kustomize/base/data-service/cron-job.yaml @@ -84,6 +84,12 @@ spec: name: data-service key: API_URL + - name: Service__Environment + valueFrom: + configMapKeyRef: + name: data-service + key: ENVIRONMENT + - name: ServiceNow__ApiUrl valueFrom: secretKeyRef: diff --git a/devops/kustomize/overlays/dev/data-service/kustomization.yaml b/devops/kustomize/overlays/dev/data-service/kustomization.yaml index cde9c8e3..b48c892a 100644 --- a/devops/kustomize/overlays/dev/data-service/kustomization.yaml +++ b/devops/kustomize/overlays/dev/data-service/kustomization.yaml @@ -37,7 +37,10 @@ patches: value: https://ches-dev.api.gov.bc.ca/api/v1 - op: replace path: /data/FROM - value: (DEV) Hosting Service Dashboard + value: Hosting Service Dashboard - op: replace path: /data/TO value: jeremy.foster@fosol.ca + - op: replace + path: /data/ENVIRONMENT + value: DEV diff --git a/devops/kustomize/overlays/prod/data-service/kustomization.yaml b/devops/kustomize/overlays/prod/data-service/kustomization.yaml index 1e12d65e..cb79081d 100644 --- a/devops/kustomize/overlays/prod/data-service/kustomization.yaml +++ b/devops/kustomize/overlays/prod/data-service/kustomization.yaml @@ -41,3 +41,6 @@ patches: - op: replace path: /data/TO value: jeremy.foster@fosol.ca,michael.tessier@gov.bc.ca + - op: replace + path: /data/ENVIRONMENT + value: PROD diff --git a/devops/kustomize/overlays/test/data-service/kustomization.yaml b/devops/kustomize/overlays/test/data-service/kustomization.yaml index d735acaa..4f584f97 100644 --- a/devops/kustomize/overlays/test/data-service/kustomization.yaml +++ b/devops/kustomize/overlays/test/data-service/kustomization.yaml @@ -37,7 +37,10 @@ patches: value: https://ches-test.api.gov.bc.ca/api/v1 - op: replace path: /data/FROM - value: (TEST) Hosting Service Dashboard + value: Hosting Service Dashboard - op: replace path: /data/TO value: jeremy.foster@fosol.ca,michael.tessier@gov.bc.ca + - op: replace + path: /data/ENVIRONMENT + value: TEST diff --git a/src/data-service/Config/ServiceOptions.cs b/src/data-service/Config/ServiceOptions.cs index fda0ee87..7ef9ff7f 100644 --- a/src/data-service/Config/ServiceOptions.cs +++ b/src/data-service/Config/ServiceOptions.cs @@ -71,6 +71,11 @@ public class ServiceOptions /// public bool SendFailureEmail { get; set; } = true; + /// + /// get/set - Identify the environment this service is running in. + /// + public string Environment { get; set; } = ""; + /// /// get/set - Number of sequential failures that are allowed to occur before service stops (default = 3). /// diff --git a/src/data-service/DataService.cs b/src/data-service/DataService.cs index bcf55868..07d587e9 100644 --- a/src/data-service/DataService.cs +++ b/src/data-service/DataService.cs @@ -166,7 +166,7 @@ public async Task RunAsync() /// private async Task SendEmail(string subject, string body) { - var email = new EmailModel(this.ChesOptions.From, this.ChesOptions.OverrideTo.Split(","), subject, body); + var email = new EmailModel(this.ChesOptions.From, this.ChesOptions.OverrideTo.Split(","), $"{(!String.IsNullOrWhiteSpace(this.Options.Environment) ? $"({this.Options.Environment}) - " : "")}{subject}", body); await this.ChesService.SendEmailAsync(email); }