-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1726 from danskernesdigitalebibliotek/DDFBRA-138-…
…create-task-for-fetching-graphql-credentials DDFBRA-138 - Create task for fetching UUID of the graphql_consumer
- Loading branch information
Showing
4 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* DPL consumers module. | ||
*/ | ||
|
||
/** | ||
* Get consumer by Client ID. | ||
* | ||
* @return string | ||
* The consumer UUID. | ||
* | ||
* @throws \Exception | ||
*/ | ||
function dpl_consumers_get_consumer_uuid(string $client_id): string { | ||
try { | ||
$consumer = \Drupal::entityTypeManager() | ||
->getStorage('consumer') | ||
->loadByProperties(['client_id' => $client_id]); | ||
|
||
// We assume that there is only one consumer with the given client ID | ||
// as it is used an as unique identifier (machine name). | ||
if (!empty($consumer)) { | ||
$consumer = reset($consumer); | ||
|
||
return $consumer->uuid() ?? throw new \Exception('UUID not found.'); | ||
} | ||
else { | ||
throw new \Exception('Consumer not found.'); | ||
} | ||
} | ||
catch (\Exception $e) { | ||
throw new \Exception($e->getMessage()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
services: | ||
dpl_consumer.commands: | ||
class: \Drupal\dpl_consumers\Commands\DplConsumersCommands | ||
tags: | ||
- { name: drush.command } |
26 changes: 26 additions & 0 deletions
26
web/modules/custom/dpl_consumers/src/Commands/DplConsumersCommands.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\dpl_consumers\Commands; | ||
|
||
use Drupal\dpl_consumers\DplGraphqlConsumersConstants; | ||
use Drush\Commands\DrushCommands; | ||
|
||
/** | ||
* Drush commands for DPL consumers. | ||
*/ | ||
final class DplConsumersCommands extends DrushCommands { | ||
|
||
/** | ||
* Function is used for printing out the consumer credentials to the console. | ||
* | ||
* @command dpl_consumers:consumer-credentials | ||
*/ | ||
public function getConsumerCredentials(): void { | ||
$graphql_consumer_client_id = DplGraphqlConsumersConstants::GRAPHQL_CONSUMER_CLIENT_ID; | ||
$consumer_uuid = dpl_consumers_get_consumer_uuid($graphql_consumer_client_id); | ||
$this->output()->writeln('Consumer UUID: ' . $consumer_uuid); | ||
} | ||
|
||
} |