From 4986d42c735c1119176e30ff1e83441ed916b1ed Mon Sep 17 00:00:00 2001 From: Awilum Date: Fri, 21 Feb 2020 22:50:38 +0300 Subject: [PATCH] feat(admin-plugin): update installation process with new delivery registry token --- .../admin/app/Controllers/UsersController.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/site/plugins/admin/app/Controllers/UsersController.php b/site/plugins/admin/app/Controllers/UsersController.php index c6e07b4c..cc3b02e1 100644 --- a/site/plugins/admin/app/Controllers/UsersController.php +++ b/site/plugins/admin/app/Controllers/UsersController.php @@ -187,12 +187,36 @@ class UsersController extends Controller ], 'yaml') ); + // Create default registry delivery token + $api_delivery_registry_token = bin2hex(random_bytes(16)); + $api_delivery_registry_token_dir_path = PATH['tokens'] . '/delivery/registry/' . $api_delivery_registry_token; + $api_delivery_registry_token_file_path = $api_delivery_registry_token_dir_path . '/token.yaml'; + + if (! Filesystem::has($api_delivery_registry_token_dir_path)) Filesystem::createDir($api_delivery_registry_token_dir_path); + + Filesystem::write( + $api_delivery_registry_token_file_path, + $this->parser->encode([ + 'title' => 'Default', + 'icon' => 'fas fa-archive', + 'limit_calls' => (int) 0, + 'calls' => (int) 0, + 'state' => 'enabled', + 'uuid' => $uuid, + 'created_by' => $uuid, + 'created_at' => $time, + 'updated_by' => $uuid, + 'updated_at' => $time, + ], 'yaml') + ); + // Set Default API's tokens $custom_flextype_settings_file_path = PATH['config']['site'] . '/settings.yaml'; $custom_flextype_settings_file_data = $this->parser->decode(Filesystem::read($custom_flextype_settings_file_path), 'yaml'); $custom_flextype_settings_file_data['api']['images']['default_token'] = $api_delivery_images_token; $custom_flextype_settings_file_data['api']['entries']['default_token'] = $api_delivery_entries_token; + $custom_flextype_settings_file_data['api']['registry']['default_token'] = $api_delivery_registry_token; Filesystem::write($custom_flextype_settings_file_path, $this->parser->encode($custom_flextype_settings_file_data, 'yaml'));