Skip to content

Commit

Permalink
FOLIO: Improve json_log_file behavior/documentation (vufind-org#3348)
Browse files Browse the repository at this point in the history
Co-authored-by: Demian Katz <demian.katz@villanova.edu>
  • Loading branch information
fgleixner and demiankatz authored Jan 25, 2024
1 parent 8fe33c2 commit e749d9a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
8 changes: 5 additions & 3 deletions config/vufind/Folio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ tenant = diku
; (the default), it will only log POSTs to reduce noise.
debug_get_requests = false
; Set this to a file path writeable by VuFind to capture API inputs and outputs in
; JSON format suitable for use in test classes. This feature will only work when
; VuFind is in development mode. Be sure to sanitize the collected data and remove
; any real/sensitive data before including it in tests!
; JSON format suitable for use in test classes. Be sure to sanitize the collected
; data and remove any real/sensitive data before including it in tests!
; ATTENTION: This feature will only work when VuFind is in development mode. See
; https://vufind.org/wiki/development:troubleshooting#turn_on_development_mode
; for instructions on enabling development mode.
;json_log_file = "/usr/local/vufind/local/cache/folio.json"

; If set to true, the driver will use the legacy /authn/login method instead of the
Expand Down
31 changes: 16 additions & 15 deletions module/VuFind/src/VuFind/ILS/Driver/AbstractAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,23 +183,24 @@ public function makeRequest(
}
if ($jsonLog = ($this->config['API']['json_log_file'] ?? false)) {
if (APPLICATION_ENV !== 'development') {
throw new \Exception(
'SECURITY: json_log_file enabled outside of development mode'
$this->logError(
'SECURITY: json_log_file enabled outside of development mode; disabling feature.'
);
} else {
$body = $response->getBody();
$jsonBody = @json_decode($body);
$json = file_exists($jsonLog)
? json_decode(file_get_contents($jsonLog)) : [];
$json[] = [
'expectedMethod' => $method,
'expectedPath' => $path,
'expectedParams' => $params,
'body' => $jsonBody ? $jsonBody : $body,
'bodyType' => $jsonBody ? 'json' : 'string',
'code' => $code,
];
file_put_contents($jsonLog, json_encode($json));
}
$body = $response->getBody();
$jsonBody = @json_decode($body);
$json = file_exists($jsonLog)
? json_decode(file_get_contents($jsonLog)) : [];
$json[] = [
'expectedMethod' => $method,
'expectedPath' => $path,
'expectedParams' => $params,
'body' => $jsonBody ? $jsonBody : $body,
'bodyType' => $jsonBody ? 'json' : 'string',
'code' => $code,
];
file_put_contents($jsonLog, json_encode($json));
}
return $response;
}
Expand Down

0 comments on commit e749d9a

Please sign in to comment.