public function ApigeeEdgeManagementCliService::isValidEdgeCredentials in Apigee Edge 8
Validate the Apigee Edge org connection settings.
Parameters
\Symfony\Component\Console\Style\StyleInterface $io: The IO interface of the CLI tool calling the method.
callable $t: The translation function akin to t().
string $org: The Edge org to connect to.
string $email: The email of an Edge user with org admin role to make Edge API calls.
string $password: The password of an Edge user email to make Edge API calls.
string $base_url: The base url of the Edge API.
Return value
bool Return true if the Edge API can be called, false if it cannot.
1 call to ApigeeEdgeManagementCliService::isValidEdgeCredentials()
- ApigeeEdgeManagementCliService::createEdgeRoleForDrupal in src/
Command/ Util/ ApigeeEdgeManagementCliService.php - Create role in Apigee Edge for Drupal to use for Edge connection.
File
- src/
Command/ Util/ ApigeeEdgeManagementCliService.php, line 253
Class
- ApigeeEdgeManagementCliService
- Defines an interface for Edge connection classes.
Namespace
Drupal\apigee_edge\Command\UtilCode
public function isValidEdgeCredentials(StyleInterface $io, callable $t, string $org, string $email, string $password, string $base_url) {
$url = $base_url . '/o/' . $org;
try {
$response = $this->httpClient
->get($url, [
'auth' => [
$email,
$password,
],
'headers' => [
'Accept' => 'application/json',
],
]);
} catch (TransferException $exception) {
$this
->handleHttpClientExceptions($exception, $io, $t, $url, $org, $email);
return FALSE;
}
// Make sure a response is returned.
$raw_body = (string) $response
->getBody();
if (empty($raw_body)) {
$io
->error($t('Response to :url returned empty. HTTP !response_code !response_reason', [
':url' => $url,
'!response_code' => $response
->getStatusCode(),
'!response_reason' => json_last_error_msg(),
]));
return FALSE;
}
$body = json_decode($raw_body);
if (JSON_ERROR_NONE !== json_last_error()) {
$io
->error($t('Unable to parse response from GET :url into JSON: !error ', [
':url' => $url,
'!error' => json_last_error_msg(),
]));
return FALSE;
}
if (!isset($body->name)) {
$io
->error($t('The response from GET :url did not contain valid org data.', [
':url' => $url,
]));
return FALSE;
}
else {
$io
->success($t('Connected to Edge org :org.', [
':org' => $body->name,
]));
}
return TRUE;
}