Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DDFBRA-138 - Create task for fetching UUID of the graphql_consumer #1726

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,11 @@ tasks:
cmds:
- cmd: task dev:cli -- drush default-content:export-module dpl_example_content

dev:go:graphql-credentials:
desc: Get the GraphQL consumer credentials
cmds:
- cmd: task dev:cli -- drush dpl_consumers:consumer-credentials

ci:reset:
desc: Create CI setup in a clean state
cmds:
Expand Down
36 changes: 36 additions & 0 deletions web/modules/custom/dpl_consumers/dpl_consumers.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
Dresse marked this conversation as resolved.
Show resolved Hide resolved

/**
* @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);
Dresse marked this conversation as resolved.
Show resolved Hide resolved

return $consumer->uuid() ?? throw new \Exception('UUID not found.');
}
else {
throw new \Exception('Consumer not found.');
}
}
catch (\Exception $e) {
throw new \Exception($e->getMessage());
}
}
5 changes: 5 additions & 0 deletions web/modules/custom/dpl_consumers/drush.services.yml
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 }
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);
}

}
Loading