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

Handle graphql consumers for both BNF and Go #1891

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
8 changes: 6 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
COMPOSE_PROJECT_NAME=dapple-cms
COMPOSER_MEMORY_LIMIT=-1

# GraphQL Consumer environment variables used for local development
GRAPHQL_CONSUMER_SECRET=some-secret
# GraphQL Consumer secrets and user passwords
BNF_GRAPHQL_CONSUMER_SECRET=dUOAxbWr72cnigpkZXN1SuyuXfeHxZb5
BNF_GRAPHQL_CONSUMER_USER_PASSWORD=dUOAxbWr72cnigpkZXN1SuyuXfeHxZb5

GO_GRAPHQL_CONSUMER_SECRET=GVOzhK8BogbZHrEzXW0W5HYFtScQrABt
GO_GRAPHQL_CONSUMER_USER_PASSWORD=oA8mqZFxmFubREH77T3qeApeoUxoNS7Y

#OPENID_CLIENT_ID=some-client-id
#OPENID_CLIENT_SECRET=some-client-secret
Expand Down
4 changes: 0 additions & 4 deletions .lagoon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@ tasks:

drush user:create patron --password="$PR_DRUPAL_PWD"
drush user:role:add 'patron' patron

drush user:create $GRAPHQL_USER_NAME --password="$GRAPHQL_USER_PASSWORD"
drush user:role:add 'external_system' $GRAPHQL_USER_NAME
drush user:role:add 'graphql_consumer' $GRAPHQL_USER_NAME
else
echo "Test users already exist. Skipping creation..."
fi
Expand Down
4 changes: 0 additions & 4 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,6 @@ tasks:
- task dev:cli -- drush user:create patron --password="test"
- task dev:cli -- drush user:role:add 'patron' patron

- task dev:cli -- drush user:create graphql_consumer --password="test"
- task dev:cli -- drush user:role:add 'external_system' graphql_consumer
- task dev:cli -- drush user:role:add 'graphql_consumer' graphql_consumer

dev:import-profile-translations:
desc: Import our custom profile translations. This is done automatically on deploy.
cmds:
Expand Down
3 changes: 2 additions & 1 deletion config/sync/administerusersbyrole.settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ roles:
mediator: safe
patron: unsafe
external_system: safe
graphql_consumer: unsafe
bnf_graphql_client: unsafe
go_graphql_client: unsafe
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
uuid: b74f9f26-2491-4676-831b-8bf9e1db2924
langcode: da
status: true
dependencies:
config:
- user.role.bnf_graphql_client
module:
- user
id: user_add_role_action.bnf_graphql_client
label: 'Add the BNF GraphQL Client role to the selected user(s)'
type: user
plugin: user_add_role_action
configuration:
rid: bnf_graphql_client
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
uuid: 5b4da83f-bde0-4d1a-afd0-62b5a758379e
langcode: da
status: true
dependencies:
config:
- user.role.go_graphql_client
module:
- user
id: user_add_role_action.go_graphql_client
label: 'Add the GO GraphQL Client role to the selected user(s)'
type: user
plugin: user_add_role_action
configuration:
rid: go_graphql_client

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
uuid: 64ba08c0-435a-4e68-b9db-ad5e36751432
langcode: da
status: true
dependencies:
config:
- user.role.bnf_graphql_client
module:
- user
id: user_remove_role_action.bnf_graphql_client
label: 'Remove the BNF GraphQL Client role from the selected user(s)'
type: user
plugin: user_remove_role_action
configuration:
rid: bnf_graphql_client
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
uuid: c8fe6acb-1517-47b9-abb1-b6e66472bf54
langcode: da
status: true
dependencies:
config:
- user.role.go_graphql_client
module:
- user
id: user_remove_role_action.go_graphql_client
label: 'Remove the GO GraphQL Client role from the selected user(s)'
type: user
plugin: user_remove_role_action
configuration:
rid: go_graphql_client

This file was deleted.

12 changes: 12 additions & 0 deletions config/sync/user.role.bnf_graphql_client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
uuid: acb9efe1-c340-4abb-a4a6-c7acb96e41b3
langcode: da
status: true
dependencies:
module:
- graphql
id: bnf_graphql_client
label: 'BNF GraphQL Client'
weight: 9
is_admin: null
permissions:
- 'execute graphql_compose_server arbitrary graphql requests'
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
uuid: 2844cde3-5ba7-4a93-958a-70da917913a7
langcode: en
uuid: 0f907e2f-f8c2-4979-85f4-bf9ab822603b
langcode: da
status: true
dependencies:
module:
- graphql
id: graphql_consumer
label: 'GraphQl consumer'
weight: 8
id: go_graphql_client
label: 'GO GraphQL Client'
weight: 10
is_admin: null
permissions:
- 'execute graphql_compose_server arbitrary graphql requests'
95 changes: 0 additions & 95 deletions web/modules/custom/dpl_consumers/dpl_consumers.crud.php

This file was deleted.

31 changes: 25 additions & 6 deletions web/modules/custom/dpl_consumers/dpl_consumers.deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

declare(strict_types=1);

require_once __DIR__ . '/dpl_consumers.crud.php';

/**
* Run consumer creation on deploy.
*
Expand All @@ -22,8 +20,29 @@
* as we don't want to create duplicates.
*/
function dpl_consumers_deploy_10001(): void {
dpl_consumers_delete_user();
dpl_consumers_delete_consumer();
dpl_consumers_create_user();
dpl_consumers_create_consumer();
// Noop. We don't need to do anything here.
// Since we have changed our minds.
// @see dpl_consumers_deploy_10002().
}

/**
* Expand the users, roles, consumers so they can handle both BNF and GO.
*
* So we delete previous entities and create new ones.
*/
function dpl_consumers_deploy_10002(): void {
/** @var \Drupal\dpl_consumers\Services\ConsumerHandler $consumer_handler */
$consumer_handler = \Drupal::service('dpl_consumers.consumer_handler');

// Delete consume and users that we want to handle differently.
// We want to create consumers and consumer users
// specifically for the two known consumers (BNF and Go) and connected users.
$consumer_handler->getConsumer('graphql_consumer')->delete();
$consumer_handler->getConsumerUser('GraphQL Consumer')->delete();
$consumer_handler->getConsumerUser('graphql_consumer')->delete();

// Create new consumers (BNF and Go) and their users and roles.
foreach (dpl_consumers_known_consumers_settings() as $consumer) {
$consumer_handler->create($consumer['consumer'], $consumer['user'], $consumer['role']);
}
}
24 changes: 21 additions & 3 deletions web/modules/custom/dpl_consumers/dpl_consumers.install
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,30 @@

declare(strict_types=1);

require_once __DIR__ . '/dpl_consumers.crud.php';
use Drupal\dpl_consumers\Consumer;
use Drupal\dpl_consumers\ConsumerUser;

/**
* Implements hook_uninstall().
*/
function dpl_consumers_uninstall(): void {
dpl_consumers_delete_user();
dpl_consumers_delete_consumer();
// Delete consumers (BNF and Go) and their users.
// Roles are handled by config.
/** @var \Drupal\dpl_consumers\Services\ConsumerHandler $consumer_handler */
$consumer_handler = \Drupal::service('dpl_consumers.consumer_handler');

$consumers = [
[
'consumer' => new Consumer('bnf_graphql', \Drupal::entityTypeManager()),
'user' => new ConsumerUser('bnf_graphql', \Drupal::entityTypeManager()),
],
[
'consumer' => new Consumer('go_graphql', \Drupal::entityTypeManager()),
'user' => new ConsumerUser('go_graphql', \Drupal::entityTypeManager()),
],
];

foreach ($consumers as $consumer) {
$consumer_handler->delete($consumer['consumer'], $consumer['user']);
}
}
Loading
Loading