From 4a67c4e864520b76959c4da18f94f4b3d6e8c14c Mon Sep 17 00:00:00 2001 From: MytsV Date: Mon, 21 Oct 2024 20:03:06 +0300 Subject: [PATCH] Make rule activity configurable with an environmental variable --- .env.development.local.template | 1 + .../core/port/secondary/env-config-gateway-output-port.ts | 5 +++++ src/lib/infrastructure/gateway/env-config-gateway.ts | 6 ++++++ .../gateway/rule-gateway/endpoints/create-rule-endpoint.ts | 2 +- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.env.development.local.template b/.env.development.local.template index c1ba5363b..3a4b71000 100644 --- a/.env.development.local.template +++ b/.env.development.local.template @@ -17,6 +17,7 @@ NODE_TLS_REJECT_UNAUTHORIZED=0 [gateway] RUCIO_AUTH_HOST=https://rucio-devmaany.cern.ch:443 RUCIO_HOST=https://rucio-devmaany.cern.ch:443 +RULE_ACTIVITY=User Subscriptions PARAMS_ENCODING_ENABLED=false [oidc] diff --git a/src/lib/core/port/secondary/env-config-gateway-output-port.ts b/src/lib/core/port/secondary/env-config-gateway-output-port.ts index 9974fc92d..bb844f8df 100644 --- a/src/lib/core/port/secondary/env-config-gateway-output-port.ts +++ b/src/lib/core/port/secondary/env-config-gateway-output-port.ts @@ -61,6 +61,11 @@ export default interface EnvConfigGatewayOutputPort { */ projectURL(): Promise; + /** + * @returns the rule activity string + */ + ruleActivity(): Promise; + /** * @returns whether the query parameters should get URI encoded */ diff --git a/src/lib/infrastructure/gateway/env-config-gateway.ts b/src/lib/infrastructure/gateway/env-config-gateway.ts index d3f6c0638..1c897c8cd 100644 --- a/src/lib/infrastructure/gateway/env-config-gateway.ts +++ b/src/lib/infrastructure/gateway/env-config-gateway.ts @@ -154,6 +154,12 @@ class EnvConfigGateway implements EnvConfigGatewayOutputPort { return Promise.resolve(true); } + async ruleActivity(): Promise { + const value = await this.get('RULE_ACTIVITY'); + // Return a default value if the environmental variable is not specified + return value ?? 'User Subscriptions'; + } + async get(key: string, required: boolean = false): Promise { let value = process.env[key]; if (value !== undefined) { diff --git a/src/lib/infrastructure/gateway/rule-gateway/endpoints/create-rule-endpoint.ts b/src/lib/infrastructure/gateway/rule-gateway/endpoints/create-rule-endpoint.ts index 19e247fcb..00808210f 100644 --- a/src/lib/infrastructure/gateway/rule-gateway/endpoints/create-rule-endpoint.ts +++ b/src/lib/infrastructure/gateway/rule-gateway/endpoints/create-rule-endpoint.ts @@ -14,7 +14,7 @@ export default class CreateRuleEndpoint extends BaseEndpoint { const rucioHost = await this.envConfigGateway.rucioHost(); const endpoint = `${rucioHost}/rules/`; - this.params.activity = 'User Subscriptions'; + this.params.activity = await this.envConfigGateway.ruleActivity(); const request: HTTPRequest = { method: 'POST',