Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions compose.override.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:-""}'
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ helfi_hakuvahti.settings:
type: config_object
label: 'Helfi hakuvahti settings'
mapping:
api_key:
type: string
base_url:
type: string
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions public/modules/custom/helfi_hakuvahti/src/Hakuvahti.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
1 change: 1 addition & 0 deletions public/sites/default/all.settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading