diff --git a/compose.override.yaml b/compose.override.yaml index 9cb94e91..b23e4d55 100644 --- a/compose.override.yaml +++ b/compose.override.yaml @@ -2,7 +2,5 @@ services: app: environment: HAKUVAHTI_URL: 'http://hakuvahti:3000' - HELBIT_CLIENT_ID: '${HELBIT_CLIENT_ID:-""}' -networks: - hakuvahti-network: - external: true + HAKUVAHTI_API_KEY: '123' + HELBIT_CLIENT_ID: '${HELBIT_CLIENT_ID:-""}' \ No newline at end of file diff --git a/public/modules/custom/helfi_hakuvahti/config/schema/helfi_hakuvahti.schema.yml b/public/modules/custom/helfi_hakuvahti/config/schema/helfi_hakuvahti.schema.yml index 793353ae..67b7f516 100644 --- a/public/modules/custom/helfi_hakuvahti/config/schema/helfi_hakuvahti.schema.yml +++ b/public/modules/custom/helfi_hakuvahti/config/schema/helfi_hakuvahti.schema.yml @@ -16,5 +16,7 @@ helfi_hakuvahti.settings: type: config_object label: 'Helfi hakuvahti settings' mapping: + api_key: + type: string base_url: type: string diff --git a/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php b/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php index 5cd82e4a..d14478e0 100644 --- a/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php +++ b/public/modules/custom/helfi_hakuvahti/src/Controller/HelfiHakuvahtiSubscribeController.php @@ -61,7 +61,7 @@ public function post(Request $request): JsonResponse { catch (\InvalidArgumentException | \JsonException $e) { // The frontend should not send invalid requests. $this->logger?->error('Hakuvahti initial subscription failed: ' . $e->getMessage()); - return new JsonResponse(['success' => FALSE, 'error' => $e->getMessage()], Response::HTTP_BAD_REQUEST); + return new JsonResponse(['success' => FALSE, 'error' => 'Error while handling the request.'], Response::HTTP_BAD_REQUEST); } // Allows other modules to alter the request. diff --git a/public/modules/custom/helfi_hakuvahti/src/Hakuvahti.php b/public/modules/custom/helfi_hakuvahti/src/Hakuvahti.php index bf4d2db1..0f5afc6c 100644 --- a/public/modules/custom/helfi_hakuvahti/src/Hakuvahti.php +++ b/public/modules/custom/helfi_hakuvahti/src/Hakuvahti.php @@ -51,19 +51,19 @@ public function unsubscribe(string $hash, string $subscription): void { * @throws \Drupal\helfi_hakuvahti\HakuvahtiException */ private function makeRequest(string $method, string $url, array $options = []): ResponseInterface { - if (!$baseUrl = $this->configFactory->get('helfi_hakuvahti.settings')->get('base_url')) { + $settings = $this->configFactory->get('helfi_hakuvahti.settings'); + if (!$baseUrl = $settings->get('base_url')) { throw new HakuvahtiException('Hakuvahti base url is not configured.'); } - // @todo hakuvahti has no use for Drupal tokens https://github.com/City-of-Helsinki/helfi-hakuvahti/blob/main/src/plugins/token.ts#L19. - // Maybe this value could be kind of api-key, so - // that only allowed services can talk to hakuvahti? - $token = '123'; + $apiKey = $settings->get('api_key'); try { return $this->client->request($method, "$baseUrl$url", NestedArray::mergeDeep([ RequestOptions::HEADERS => [ - 'token' => $token, + 'Authorization' => "api-key $apiKey", + // @todo remove this when we have fully migrated to new Hakuvahti. + 'token' => '123', ], RequestOptions::TIMEOUT => 5, ], $options)); diff --git a/public/sites/default/all.settings.php b/public/sites/default/all.settings.php index f4b29488..9751ce0e 100644 --- a/public/sites/default/all.settings.php +++ b/public/sites/default/all.settings.php @@ -21,6 +21,7 @@ ]; } +$config['helfi_hakuvahti.settings']['api_key'] = getenv('HAKUVAHTI_API_KEY'); $config['helfi_hakuvahti.settings']['base_url'] = getenv('HAKUVAHTI_URL'); // Elastic proxy URL.