private function KeyEntityFormEnhancer::createDebugText in Apigee Edge 8
Creates debug text if there was an error during form validation.
Parameters
\Exception $exception: The thrown exception during form validation.
\Drupal\key\KeyInterface $key: The used key during form validation.
Return value
string The debug text to be displayed.
1 call to KeyEntityFormEnhancer::createDebugText()
- KeyEntityFormEnhancer::validateForm in src/
KeyEntityFormEnhancer.php - Additional validation handler for Apigee Edge authentication key forms.
File
- src/
KeyEntityFormEnhancer.php, line 618
Class
- KeyEntityFormEnhancer
- Enhances Apigee Edge related Key entity add/edit forms.
Namespace
Drupal\apigee_edgeCode
private function createDebugText(\Exception $exception, KeyInterface $key) : string {
$key_type = $key
->getKeyType();
$credentials = [];
$keys = [
'auth_type' => $key_type instanceof EdgeKeyTypeInterface ? $key_type
->getAuthenticationType($key) : 'invalid credentials',
'key_provider' => get_class($key
->getKeyProvider()),
];
if ($key_type instanceof EdgeKeyTypeInterface) {
$credentials = [
'endpoint' => $key_type
->getEndpoint($key),
'organization' => $key_type
->getOrganization($key),
];
if ($key_type
->getInstanceType($key) != EdgeKeyTypeInterface::INSTANCE_TYPE_HYBRID) {
$credentials['username'] = $key_type
->getUsername($key);
}
if ($key_type
->getAuthenticationType($key) === EdgeKeyTypeInterface::EDGE_AUTH_TYPE_OAUTH) {
$credentials['authorization_server'] = $key_type
->getAuthorizationServer($key);
$credentials['client_id'] = $key_type
->getClientId($key);
$credentials['client_secret'] = $key_type
->getClientSecret($key) === Oauth::DEFAULT_CLIENT_SECRET ? Oauth::DEFAULT_CLIENT_SECRET : '***client-secret***';
}
}
// Sanitize exception text.
$exception_text = preg_replace([
'/(.*refresh_token=)([^\\&\\r\\n]+)(.*)/',
'/(.*mfa_token=)([^\\&\\r\\n]+)(.*)/',
'/(.*password=)([^\\&\\r\\n]+)(.*)/',
'/(Authorization: (Basic|Bearer) ).*/',
], [
'$1***refresh-token***$3',
'$1***mfa-token***$3',
'$1***password***$3',
'$1***credentials***',
], (string) $exception);
// Filter out any private values from config.
$client_config = array_filter($this->configFactory
->get('apigee_edge.client')
->get(), static function ($key) {
return !is_string($key) || $key[0] !== '_';
}, ARRAY_FILTER_USE_KEY);
return json_encode($credentials, JSON_PRETTY_PRINT) . PHP_EOL . json_encode($keys, JSON_PRETTY_PRINT) . PHP_EOL . json_encode($client_config, JSON_PRETTY_PRINT) . PHP_EOL . $exception_text;
}