From f433f7e39e4790948f0527e1a8e4622f516e8516 Mon Sep 17 00:00:00 2001 From: Mike Decker Date: Mon, 22 Apr 2024 09:12:27 -0700 Subject: [PATCH] Add configurable workgroup api timeout and increase it --- config/install/stanford_samlauth.settings.yml | 1 + config/schema/stanford_samlauth.schema.yml | 3 +++ src/Service/WorkgroupApi.php | 3 ++- stanford_samlauth.install | 10 ++++++++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/config/install/stanford_samlauth.settings.yml b/config/install/stanford_samlauth.settings.yml index 9bf1d00..9a8c8d4 100644 --- a/config/install/stanford_samlauth.settings.yml +++ b/config/install/stanford_samlauth.settings.yml @@ -11,4 +11,5 @@ role_mapping: workgroup_api: cert: '' key: '' + timeout: 30 mapping: {} diff --git a/config/schema/stanford_samlauth.schema.yml b/config/schema/stanford_samlauth.schema.yml index b02ad1a..d817ba1 100644 --- a/config/schema/stanford_samlauth.schema.yml +++ b/config/schema/stanford_samlauth.schema.yml @@ -64,6 +64,9 @@ stanford_samlauth.settings: key: type: string label: Path to Workgroup API Key file + timeout: + type: integer + label: API Request timeout limit reevaluate: type: string label: Reevaluation rule diff --git a/src/Service/WorkgroupApi.php b/src/Service/WorkgroupApi.php index 0786ec2..c992374 100644 --- a/src/Service/WorkgroupApi.php +++ b/src/Service/WorkgroupApi.php @@ -159,11 +159,12 @@ public function isSunetValid(string $sunet): bool { * API response or false if fails. */ protected function callApi(string $workgroup = NULL, string $sunet = NULL): ?array { + $config = $this->configFactory->get('stanford_samlauth.settings'); $options = [ 'cert' => $this->getCert(), 'ssl_key' => $this->getKey(), 'verify' => TRUE, - 'timeout' => 5, + 'timeout' => $config->get('role_mapping.workgroup_api.timeout') ?: 30, 'query' => [ 'type' => $workgroup ? 'workgroup' : 'user', 'id' => $workgroup ?: $sunet, diff --git a/stanford_samlauth.install b/stanford_samlauth.install index 57db61d..2224843 100644 --- a/stanford_samlauth.install +++ b/stanford_samlauth.install @@ -113,3 +113,13 @@ function stanford_samlauth_install() { ->set('match_noredirect_pages', "/jsonapi\r\n/jsonapi/*\r\n/subrequests") ->save(); } + +/** + * Add request timeout config value. + */ +function stanford_samlauth_update_1001() { + \Drupal::configFactory() + ->getEditable('stanford_samlauth.settings') + ->set('role_mapping.workgroup_api.timeout', 30) + ->save(); +}