From 2dc6645e88ee7cd0eae948296da3394646864e8c Mon Sep 17 00:00:00 2001 From: Tanya Borisova Date: Tue, 18 Oct 2022 12:29:11 +0100 Subject: [PATCH 1/9] wip: pass in tre_url --- templates/shared_services/airlock_notifier/.env.sample | 1 + .../airlock_notifier/app/AirlockNotifier/workflow.json | 2 +- .../airlock_notifier/app/parameters.json | 4 ++++ .../shared_services/airlock_notifier/parameters.json | 6 ++++++ templates/shared_services/airlock_notifier/porter.yaml | 7 ++++++- .../airlock_notifier/template_schema.json | 10 +++++++++- .../airlock_notifier/terraform/airlock_notifier.tf | 1 + .../airlock_notifier/terraform/locals.tf | 1 + .../airlock_notifier/terraform/variables.tf | 5 +++++ 9 files changed, 34 insertions(+), 3 deletions(-) diff --git a/templates/shared_services/airlock_notifier/.env.sample b/templates/shared_services/airlock_notifier/.env.sample index 5ecb7a87c8..1de536c2a4 100644 --- a/templates/shared_services/airlock_notifier/.env.sample +++ b/templates/shared_services/airlock_notifier/.env.sample @@ -1,4 +1,5 @@ TRE_ID=__CHANGE_ME__ +TRE_URL=__CHANGE_ME__ SMTP_SERVER_ADDRESS="__CHANGE_ME__" SMTP_USERNAME="__CHANGE_ME__" SMTP_PASSWORD="__CHANGE_ME__" diff --git a/templates/shared_services/airlock_notifier/app/AirlockNotifier/workflow.json b/templates/shared_services/airlock_notifier/app/AirlockNotifier/workflow.json index 4752883022..9ffa5c475f 100644 --- a/templates/shared_services/airlock_notifier/app/AirlockNotifier/workflow.json +++ b/templates/shared_services/airlock_notifier/app/AirlockNotifier/workflow.json @@ -89,7 +89,7 @@ "Send_Email_with_SMTP": { "inputs": { "body": { - "Body": "

Airlock request id: @{body('Parse_JSON')?['data']?['request_id']}
\nWorkspace id: @{body('Parse_JSON')?['data']?['workspace_id']}

", + "Body": "

Airlock request id: @{body('Parse_JSON')?['data']?['request_id']}
\nWorkspace id: @{body('Parse_JSON')?['data']?['workspace_id']}
\nTRE URL: @parameters('tre_url')

", "From": "@parameters('smtp_from_email')", "Subject": "@variables('message')", "To": "@{join(variables('recipients'), ';')}" diff --git a/templates/shared_services/airlock_notifier/app/parameters.json b/templates/shared_services/airlock_notifier/app/parameters.json index 799fe2c93c..927ff4d134 100644 --- a/templates/shared_services/airlock_notifier/app/parameters.json +++ b/templates/shared_services/airlock_notifier/app/parameters.json @@ -2,5 +2,9 @@ "smtp_from_email": { "type": "String", "value": "@appsetting('smtp_from_email')" + }, + "tre_url": { + "type": "String", + "value": "@appsetting('tre_url')" } } diff --git a/templates/shared_services/airlock_notifier/parameters.json b/templates/shared_services/airlock_notifier/parameters.json index e4f6dc8d41..59261f21ec 100755 --- a/templates/shared_services/airlock_notifier/parameters.json +++ b/templates/shared_services/airlock_notifier/parameters.json @@ -10,6 +10,12 @@ "env": "TRE_ID" } }, + { + "name": "tre_url", + "source": { + "env": "TRE_URL" + } + }, { "name": "id", "source": { diff --git a/templates/shared_services/airlock_notifier/porter.yaml b/templates/shared_services/airlock_notifier/porter.yaml index aa122ab8a7..d08fde0eda 100644 --- a/templates/shared_services/airlock_notifier/porter.yaml +++ b/templates/shared_services/airlock_notifier/porter.yaml @@ -1,6 +1,6 @@ --- name: tre-shared-service-airlock-notifier -version: 0.2.0 +version: 0.2.102 description: "A shared service notifying on Airlock Operations" registry: azuretre dockerfile: Dockerfile.tmpl @@ -19,6 +19,9 @@ parameters: - name: tre_id type: string description: "The ID of the parent TRE instance e.g., mytre-dev-3142" + - name: tre_url + type: string + description: "The ID of the parent TRE instance e.g., mytre-dev-3142" - name: id type: string description: "Resource ID" @@ -63,6 +66,7 @@ install: vars: tre_id: "{{ bundle.parameters.tre_id }}" tre_resource_id: "{{ bundle.parameters.id }}" + tre_url: "{{ bundle.parameters.tre_url }}" smtp_server_address: "{{ bundle.parameters.smtp_server_address }}" smtp_username: "{{ bundle.parameters.smtp_username }}" smtp_password: "{{ bundle.parameters.smtp_password }}" @@ -113,6 +117,7 @@ uninstall: vars: tre_id: "{{ bundle.parameters.tre_id }}" tre_resource_id: "{{ bundle.parameters.id }}" + tre_url: "{{ bundle.parameters.tre_url }}" smtp_server_address: "{{ bundle.parameters.smtp_server_address }}" smtp_username: "{{ bundle.parameters.smtp_username }}" smtp_password: "{{ bundle.parameters.smtp_password }}" diff --git a/templates/shared_services/airlock_notifier/template_schema.json b/templates/shared_services/airlock_notifier/template_schema.json index ce4056ead6..cf26623e19 100644 --- a/templates/shared_services/airlock_notifier/template_schema.json +++ b/templates/shared_services/airlock_notifier/template_schema.json @@ -25,7 +25,8 @@ "type": "string", "title": "SMTP Password", "description": "SMTP Password", - "updateable": false + "updateable": false, + "sensitive": true }, "smtp_from_email": { "$id": "#/properties/smtp_from_email", @@ -33,6 +34,13 @@ "title": "SMTP From Email", "description": "SMTP From Email", "updateable": false + }, + "tre_url": { + "$id": "#/properties/tre_url", + "type": "string", + "title": "TRE URL", + "description": "If your TRE URL is different from ${TRE_ID}.${LOCATION}.cloudapp.azure.com, please enter it here", + "updateable": false } }, "pipeline": { diff --git a/templates/shared_services/airlock_notifier/terraform/airlock_notifier.tf b/templates/shared_services/airlock_notifier/terraform/airlock_notifier.tf index 3095e3a64e..3da61662e0 100644 --- a/templates/shared_services/airlock_notifier/terraform/airlock_notifier.tf +++ b/templates/shared_services/airlock_notifier/terraform/airlock_notifier.tf @@ -94,6 +94,7 @@ resource "azurerm_logic_app_standard" "logic_app" { "resource_group" = data.azurerm_resource_group.core.name "smtp_connection_runtime_url" = jsondecode(azurerm_resource_group_template_deployment.smtp_api_connection.output_content).connectionRuntimeUrl.value "smtp_from_email" = var.smtp_from_email + "tre_url" = try(var.tre_url, local.default_tre_url) "APPLICATIONINSIGHTS_CONNECTION_STRING" = data.azurerm_application_insights.core.connection_string } site_config { diff --git a/templates/shared_services/airlock_notifier/terraform/locals.tf b/templates/shared_services/airlock_notifier/terraform/locals.tf index d7a51e8435..032e5b2d43 100644 --- a/templates/shared_services/airlock_notifier/terraform/locals.tf +++ b/templates/shared_services/airlock_notifier/terraform/locals.tf @@ -9,4 +9,5 @@ locals { tre_id = var.tre_id tre_shared_service_id = var.tre_resource_id } + default_tre_url = "https://${var.tre_id}.${data.azurerm_resource_group.core.location}.cloudapp.com" } diff --git a/templates/shared_services/airlock_notifier/terraform/variables.tf b/templates/shared_services/airlock_notifier/terraform/variables.tf index 58ee2b894c..edebd3398e 100644 --- a/templates/shared_services/airlock_notifier/terraform/variables.tf +++ b/templates/shared_services/airlock_notifier/terraform/variables.tf @@ -8,6 +8,11 @@ variable "tre_resource_id" { description = "Resource ID" } +variable "tre_url" { + type = string + description = "TRE URL" +} + variable "smtp_server_address" { type = string } From 7a969ae1ca563bf2211c54bccfbe19eb157a86f1 Mon Sep 17 00:00:00 2001 From: Tanya Borisova Date: Tue, 18 Oct 2022 23:38:17 +0100 Subject: [PATCH 2/9] Use tre_url in the message --- .../airlock_notifier/app/AirlockNotifier/workflow.json | 2 +- templates/shared_services/airlock_notifier/porter.yaml | 5 +++-- .../airlock_notifier/terraform/airlock_notifier.tf | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/templates/shared_services/airlock_notifier/app/AirlockNotifier/workflow.json b/templates/shared_services/airlock_notifier/app/AirlockNotifier/workflow.json index 9ffa5c475f..7aac377311 100644 --- a/templates/shared_services/airlock_notifier/app/AirlockNotifier/workflow.json +++ b/templates/shared_services/airlock_notifier/app/AirlockNotifier/workflow.json @@ -89,7 +89,7 @@ "Send_Email_with_SMTP": { "inputs": { "body": { - "Body": "

Airlock request id: @{body('Parse_JSON')?['data']?['request_id']}
\nWorkspace id: @{body('Parse_JSON')?['data']?['workspace_id']}
\nTRE URL: @parameters('tre_url')

", + "Body": "View the request", "From": "@parameters('smtp_from_email')", "Subject": "@variables('message')", "To": "@{join(variables('recipients'), ';')}" diff --git a/templates/shared_services/airlock_notifier/porter.yaml b/templates/shared_services/airlock_notifier/porter.yaml index d08fde0eda..f963f66c7d 100644 --- a/templates/shared_services/airlock_notifier/porter.yaml +++ b/templates/shared_services/airlock_notifier/porter.yaml @@ -1,6 +1,6 @@ --- name: tre-shared-service-airlock-notifier -version: 0.2.102 +version: 0.2.109 description: "A shared service notifying on Airlock Operations" registry: azuretre dockerfile: Dockerfile.tmpl @@ -21,7 +21,8 @@ parameters: description: "The ID of the parent TRE instance e.g., mytre-dev-3142" - name: tre_url type: string - description: "The ID of the parent TRE instance e.g., mytre-dev-3142" + description: "The URL of the parent TRE instance, e.g. https://mytre-dev-3142.uksouth.cloudapp.com" + default: "" - name: id type: string description: "Resource ID" diff --git a/templates/shared_services/airlock_notifier/terraform/airlock_notifier.tf b/templates/shared_services/airlock_notifier/terraform/airlock_notifier.tf index efa798204c..2ff65c7b8a 100644 --- a/templates/shared_services/airlock_notifier/terraform/airlock_notifier.tf +++ b/templates/shared_services/airlock_notifier/terraform/airlock_notifier.tf @@ -94,7 +94,7 @@ resource "azurerm_logic_app_standard" "logic_app" { "resource_group" = data.azurerm_resource_group.core.name "smtp_connection_runtime_url" = jsondecode(azurerm_resource_group_template_deployment.smtp_api_connection.output_content).connectionRuntimeUrl.value "smtp_from_email" = var.smtp_from_email - "tre_url" = try(var.tre_url, local.default_tre_url) + "tre_url" = var.tre_url != "" ? var.tre_url : local.default_tre_url "APPLICATIONINSIGHTS_CONNECTION_STRING" = data.azurerm_application_insights.core.connection_string } site_config { From 9d7d992a4eb116fcfed9de39814d0c66344fa581 Mon Sep 17 00:00:00 2001 From: Tanya Borisova Date: Wed, 19 Oct 2022 10:28:40 +0100 Subject: [PATCH 3/9] Pass full Workspace ID in the notification event --- api_app/_version.py | 2 +- api_app/event_grid/event_sender.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api_app/_version.py b/api_app/_version.py index d3563f072c..3d187266f1 100644 --- a/api_app/_version.py +++ b/api_app/_version.py @@ -1 +1 @@ -__version__ = "0.4.54" +__version__ = "0.5.0" diff --git a/api_app/event_grid/event_sender.py b/api_app/event_grid/event_sender.py index b52de58bb7..81ffa61dca 100644 --- a/api_app/event_grid/event_sender.py +++ b/api_app/event_grid/event_sender.py @@ -28,14 +28,14 @@ async def send_status_changed_event(airlock_request: AirlockRequest, previous_st async def send_airlock_notification_event(airlock_request: AirlockRequest, emails: Dict): request_id = airlock_request.id status = airlock_request.status.value - short_workspace_id = airlock_request.workspaceId[-4:] + workspace_id = airlock_request.workspaceId snake_case_emails = {re.sub(r'(? Date: Wed, 19 Oct 2022 11:54:04 +0100 Subject: [PATCH 4/9] Last fixes --- templates/shared_services/airlock_notifier/porter.yaml | 2 +- templates/shared_services/airlock_notifier/terraform/locals.tf | 2 +- .../shared_services/airlock_notifier/terraform/variables.tf | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/templates/shared_services/airlock_notifier/porter.yaml b/templates/shared_services/airlock_notifier/porter.yaml index f963f66c7d..34949fc315 100644 --- a/templates/shared_services/airlock_notifier/porter.yaml +++ b/templates/shared_services/airlock_notifier/porter.yaml @@ -1,6 +1,6 @@ --- name: tre-shared-service-airlock-notifier -version: 0.2.109 +version: 0.2.2 description: "A shared service notifying on Airlock Operations" registry: azuretre dockerfile: Dockerfile.tmpl diff --git a/templates/shared_services/airlock_notifier/terraform/locals.tf b/templates/shared_services/airlock_notifier/terraform/locals.tf index 032e5b2d43..bcefd7f5d1 100644 --- a/templates/shared_services/airlock_notifier/terraform/locals.tf +++ b/templates/shared_services/airlock_notifier/terraform/locals.tf @@ -9,5 +9,5 @@ locals { tre_id = var.tre_id tre_shared_service_id = var.tre_resource_id } - default_tre_url = "https://${var.tre_id}.${data.azurerm_resource_group.core.location}.cloudapp.com" + default_tre_url = "https://${var.tre_id}.${data.azurerm_resource_group.core.location}.cloudapp.azure.com" } diff --git a/templates/shared_services/airlock_notifier/terraform/variables.tf b/templates/shared_services/airlock_notifier/terraform/variables.tf index edebd3398e..dc7355d30f 100644 --- a/templates/shared_services/airlock_notifier/terraform/variables.tf +++ b/templates/shared_services/airlock_notifier/terraform/variables.tf @@ -11,6 +11,7 @@ variable "tre_resource_id" { variable "tre_url" { type = string description = "TRE URL" + default = "" } variable "smtp_server_address" { From fc9530dc7327b357a37da423533eeb53e04ebc40 Mon Sep 17 00:00:00 2001 From: Tanya Borisova Date: Wed, 19 Oct 2022 12:16:53 +0100 Subject: [PATCH 5/9] fmt --- .../shared_services/airlock_notifier/terraform/variables.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/shared_services/airlock_notifier/terraform/variables.tf b/templates/shared_services/airlock_notifier/terraform/variables.tf index dc7355d30f..de9de1359c 100644 --- a/templates/shared_services/airlock_notifier/terraform/variables.tf +++ b/templates/shared_services/airlock_notifier/terraform/variables.tf @@ -9,9 +9,9 @@ variable "tre_resource_id" { } variable "tre_url" { - type = string + type = string description = "TRE URL" - default = "" + default = "" } variable "smtp_server_address" { From 506b939cf79ab5e20ffb66ec4a50989825560c2c Mon Sep 17 00:00:00 2001 From: Tanya Borisova Date: Wed, 19 Oct 2022 12:44:51 +0100 Subject: [PATCH 6/9] fix tests --- .../test_api/test_routes/test_airlock_resource_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api_app/tests_ma/test_api/test_routes/test_airlock_resource_helpers.py b/api_app/tests_ma/test_api/test_routes/test_airlock_resource_helpers.py index 73b4982f74..33c758b63b 100644 --- a/api_app/tests_ma/test_api/test_routes/test_airlock_resource_helpers.py +++ b/api_app/tests_ma/test_api/test_routes/test_airlock_resource_helpers.py @@ -54,7 +54,7 @@ def sample_status_changed_event(new_status="draft", previous_status=None): def sample_airlock_notification_event(status="draft"): status_changed_event = EventGridEvent( event_type="airlockNotification", - data=AirlockNotificationData(request_id=AIRLOCK_REQUEST_ID, event_type="status_changed", event_value=status, emails={"workspace_researcher": ["researcher@outlook.com"], "workspace_owner": ["owner@outlook.com"], "airlock_manager": ["manager@outlook.com"]}, workspace_id=WORKSPACE_ID[-4:]).__dict__, + data=AirlockNotificationData(request_id=AIRLOCK_REQUEST_ID, event_type="status_changed", event_value=status, emails={"workspace_researcher": ["researcher@outlook.com"], "workspace_owner": ["owner@outlook.com"], "airlock_manager": ["manager@outlook.com"]}, workspace_id=WORKSPACE_ID).__dict__, subject=f"{AIRLOCK_REQUEST_ID}/airlockNotification", data_version="2.0" ) From 64ed59c75bbb853fdf23b95ba51696660e6ff4e1 Mon Sep 17 00:00:00 2001 From: Tanya Borisova Date: Wed, 19 Oct 2022 22:39:50 +0100 Subject: [PATCH 7/9] Update URL pattern --- .../shared_services/airlock_notifier/template_schema.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/templates/shared_services/airlock_notifier/template_schema.json b/templates/shared_services/airlock_notifier/template_schema.json index cf26623e19..7e9d386249 100644 --- a/templates/shared_services/airlock_notifier/template_schema.json +++ b/templates/shared_services/airlock_notifier/template_schema.json @@ -40,7 +40,11 @@ "type": "string", "title": "TRE URL", "description": "If your TRE URL is different from ${TRE_ID}.${LOCATION}.cloudapp.azure.com, please enter it here", - "updateable": false + "updateable": false, + "pattern": "^(https:|http:|www\\.)\\S*", + "examples": [ + "https://mytre.westeurope.cloudapp.azure.com" + ] } }, "pipeline": { From 1072d3af3b3fec79878dbf5e57922e6af7419797 Mon Sep 17 00:00:00 2001 From: Tanya Borisova Date: Thu, 20 Oct 2022 09:08:06 +0100 Subject: [PATCH 8/9] try to fix linter --- .github/linters/.tflint.hcl | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/linters/.tflint.hcl b/.github/linters/.tflint.hcl index 359f6ac730..0852116fa7 100644 --- a/.github/linters/.tflint.hcl +++ b/.github/linters/.tflint.hcl @@ -5,8 +5,6 @@ config { plugin "azurerm" { enabled = true - version = "0.17.1" - source = "github.com/terraform-linters/tflint-ruleset-azurerm" } rule "terraform_unused_declarations" { From 7d1938f3b535e01af69c2c325147b6d344d4238a Mon Sep 17 00:00:00 2001 From: Tanya Borisova Date: Fri, 21 Oct 2022 09:55:03 +0100 Subject: [PATCH 9/9] fix accessing array item --- .../airlock_notifier/terraform/airlock_notifier.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/shared_services/airlock_notifier/terraform/airlock_notifier.tf b/templates/shared_services/airlock_notifier/terraform/airlock_notifier.tf index 2ff65c7b8a..db05ac8b29 100644 --- a/templates/shared_services/airlock_notifier/terraform/airlock_notifier.tf +++ b/templates/shared_services/airlock_notifier/terraform/airlock_notifier.tf @@ -119,10 +119,10 @@ resource "azurerm_resource_group_template_deployment" "smtp_api_connection_acces parameters_content = jsonencode({ "servicePrincipalId" = { - value = azurerm_logic_app_standard.logic_app.identity.0.principal_id + value = azurerm_logic_app_standard.logic_app.identity[0].principal_id }, "servicePrincipalTenantId" = { - value = azurerm_logic_app_standard.logic_app.identity.0.tenant_id + value = azurerm_logic_app_standard.logic_app.identity[0].tenant_id } })