diff --git a/README.md b/README.md index c451b81..0cde730 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,45 @@ -# azure_storage +CONTENTS OF THIS FILE +--------------------- + + * Introduction + * Requirements + * Maintainers + + +INTRODUCTION +------------ + This project provides an easy integration with Microsoft Azure Storage services (blobs, tables and queues).. + + * For a full description of the module, visit the project page: + https://www.drupal.org/project/azure_storage + * To submit bug reports and feature suggestions or to track changes, use + the issue tracker on Drupal.org: + https://www.drupal.org/project/issues/azure_storage + + +REQUIREMENTS +------------ + +This module requires the following outside of Drupal core: + + * Key - https://www.drupal.org/project/key + + +INSTALLATION +------------ + + * Install the module as you would normally install a contributed + Drupal module. Visit [Installing Drupal 8 Modules](https://www.drupal.org/node/1897420) for further + information. + + +MAINTAINERS +----------- + + * Janak Singh (dakku) - https://www.drupal.org/u/dakku + * Sang Lostrie (baikho) - https://www.drupal.org/u/baikho + +### Supporting organizations: + + * [Access](https://www.drupal.org/access) - Development and maintenance diff --git a/azure_storage.info.yml b/azure_storage.info.yml index 73a0712..3108965 100644 --- a/azure_storage.info.yml +++ b/azure_storage.info.yml @@ -1,5 +1,8 @@ name: Azure Storage Integration type: module description: 'Integrates Azure Storage with Drupal' -core: 8.x -package: azure \ No newline at end of file +core_version_requirement: ^8.8.3 || ^9 +package: Azure +configure: azure_storage.settings_form +dependencies: + - key:key diff --git a/azure_storage.install b/azure_storage.install index 311cf2e..25e35a7 100644 --- a/azure_storage.install +++ b/azure_storage.install @@ -13,27 +13,7 @@ use Drupal\Core\Url; */ function azure_storage_requirements($phase) { $requirements = []; - if ($phase == 'install') { - if (!class_exists('\Aws\Azure Storage\Azure StorageClient')) { - $requirements['azure_storage_library'] = [ - 'description' => t('azure_storage require Azure Storage library.'), - 'severity' => REQUIREMENT_ERROR, - ]; - } - } - if ($phase == 'runtime') { - $azure_storage_config = \Drupal::config('azure_storage.settings'); - $access_key = $azure_storage_config->get('access_key'); - $secret_key = $azure_storage_config->get('secret_key'); - if (!($access_key && $secret_key)) { - $requirements['azure_storage'] = [ - 'title' => t('Azure Storage File System'), - 'severity' => REQUIREMENT_ERROR, - 'description' => t('Azure Storage File System access key or secret key is not set and it is required for some functionalities to work. Please set it up at the Azure Storage File System module settings page.', [ - ':settings' => Url::fromRoute('azure_storage.admin_settings')->toString(), - ]), - ]; - } + if ($phase === 'runtime') { if (ini_get('allow_url_fopen')) { $requirements['azure_storage_allow_url_fopen'] = [ @@ -159,4 +139,4 @@ function azure_storage_install() { \Drupal::database()->query("ALTER TABLE {azure_storage_file} ADD PRIMARY KEY (uri)"); break; } -} \ No newline at end of file +} diff --git a/azure_storage.links.menu.yml b/azure_storage.links.menu.yml index e4247f6..e4acda0 100644 --- a/azure_storage.links.menu.yml +++ b/azure_storage.links.menu.yml @@ -1,5 +1,5 @@ azure_storage.settings_form: - title: 'Azure Storage Settings' + title: 'Azure Storage' route_name: azure_storage.settings_form description: 'Configure Azure Storage Settings' - parent: system.admin_config_system + parent: system.admin_config_services diff --git a/azure_storage.links.task.yml b/azure_storage.links.task.yml new file mode 100644 index 0000000..2d22301 --- /dev/null +++ b/azure_storage.links.task.yml @@ -0,0 +1,4 @@ +azure_storage.settings_form: + title: 'Settings' + route_name: azure_storage.settings_form + base_route: azure_storage.settings_form diff --git a/azure_storage.permissions.yml b/azure_storage.permissions.yml new file mode 100644 index 0000000..6ba12c8 --- /dev/null +++ b/azure_storage.permissions.yml @@ -0,0 +1,2 @@ +administer azure storage: + title: 'Administer Azure Storage configuration' diff --git a/azure_storage.routing.yml b/azure_storage.routing.yml index 784ab25..6da2961 100644 --- a/azure_storage.routing.yml +++ b/azure_storage.routing.yml @@ -1,10 +1,9 @@ azure_storage.settings_form: - path: '/admin/config/azure_storage/settings' + path: '/admin/config/services/azure-storage' defaults: _form: '\Drupal\azure_storage\Form\SettingsForm' - _title: 'Azure Storage Settings Form' + _title: 'Azure Storage Settings' requirements: - _permission: 'access administration pages' + _permission: 'administer azure storage' options: _admin_route: TRUE - diff --git a/azure_storage.services.yml b/azure_storage.services.yml new file mode 100644 index 0000000..863c270 --- /dev/null +++ b/azure_storage.services.yml @@ -0,0 +1,7 @@ +services: + logger.channel.azure_storage: + parent: logger.channel_base + arguments: ['azure_storage'] + azure_storage.client: + class: '\Drupal\azure_storage\AzureStorageClient' + arguments: ['@config.factory', '@logger.channel.azure_storage'] diff --git a/composer.json b/composer.json index 12d2f53..eafdbef 100644 --- a/composer.json +++ b/composer.json @@ -1,16 +1,18 @@ { - "name": "drupal/azure_storage", - "type": "drupal-module", - "description": "Azure Storage Integration", - "keywords": ["Drupal"], - "license": "GPL-2.0+", - "homepage": "https://www.drupal.org/project/azure_storage", - "minimum-stability": "dev", - "support": { - "issues": "https://www.drupal.org/project/issues/azure_storage", - "source": "http://cgit.drupalcode.org/azure_storage" - }, - "require": { - "microsoft/azure-storage": "*" - } + "name": "drupal/azure_storage", + "type": "drupal-module", + "description": "Azure Storage Integration", + "keywords": [ + "Drupal" + ], + "license": "GPL-2.0+", + "homepage": "https://www.drupal.org/project/azure_storage", + "support": { + "issues": "https://www.drupal.org/project/issues/azure_storage", + "source": "http://cgit.drupalcode.org/azure_storage" + }, + "require": { + "microsoft/azure-storage-queue": "^1.3", + "microsoft/azure-storage-common": "^1.5" + } } diff --git a/config/install/azure_storage.settings.yml b/config/install/azure_storage.settings.yml index 1c7ea79..8f4b34c 100644 --- a/config/install/azure_storage.settings.yml +++ b/config/install/azure_storage.settings.yml @@ -1 +1,6 @@ -azure_storage: +protocol: 'https' +account_name: '' +test_account_key: '' +live_account_key: '' +mode: 'test' +endpoint_suffix: '' diff --git a/src/AzureStorage.php b/src/AzureStorage.php new file mode 100644 index 0000000..96458ee --- /dev/null +++ b/src/AzureStorage.php @@ -0,0 +1,39 @@ +get('mode') ?? 'test'; + $config_key = $mode . '_account_key'; + $key_id = $settings->get($config_key); + } + if ($key_id) { + /** @var \Drupal\key\KeyRepositoryInterface $key_repository */ + $key_repository = \Drupal::service('key.repository'); + $key_entity = $key_repository->getKey($key_id); + if ($key_entity) { + return $key_entity->getKeyValue(); + } + } + return NULL; + } + +} diff --git a/src/AzureStorageClient.php b/src/AzureStorageClient.php index e69de29..fe57f06 100644 --- a/src/AzureStorageClient.php +++ b/src/AzureStorageClient.php @@ -0,0 +1,82 @@ +config = $config_factory->get('azure_storage.settings'); + $this->logger = $logger; + } + + /** + * {@inheritdoc} + */ + public function setStorageQueueService($connection_string = NULL) { + if ($connection_string === NULL) { + $connection_string = $this->getStorageQueueConnectionString(); + } + $this->queueClient = QueueRestProxy::createQueueService($connection_string); + return $this; + } + + /** + * {@inheritdoc} + */ + public function getStorageQueueService() { + if ($this->queueClient === NULL) { + $this->setStorageQueueService(); + } + return $this->queueClient; + } + + /** + * {@inheritdoc} + */ + public function getStorageQueueConnectionString(array $params = []) : string { + $protocol = $params['protocol'] ?? $this->config->get('protocol'); + $account_name = $params['account_name'] ?? $this->config->get('account_name'); + $account_key = $params['account_key'] ?? AzureStorage::getAccountKey(); + $endpoint_suffix = $params['endpoint_suffix'] ?? $this->config->get('endpoint_suffix'); + return "DefaultEndpointsProtocol=$protocol;AccountName=$account_name;AccountKey=$account_key;EndpointSuffix=$endpoint_suffix"; + } + +} diff --git a/src/AzureStorageClientInterface.php b/src/AzureStorageClientInterface.php new file mode 100644 index 0000000..8b48106 --- /dev/null +++ b/src/AzureStorageClientInterface.php @@ -0,0 +1,44 @@ + TRUE, ]; - $form['account_key'] = [ - '#type' => 'textfield', - '#title' => $this->t('Account Key'), + $form['test_account_key'] = [ + '#type' => 'key_select', + '#title' => $this->t('Account Key (test)'), + '#description' => $this->t('The Account Key for Azure Storage'), + '#default_value' => $config->get('test_account_key'), + '#required' => TRUE, + ]; + + $form['live_account_key'] = [ + '#type' => 'key_select', + '#title' => $this->t('Account Key (live)'), '#description' => $this->t('The Account Key for Azure Storage'), - '#default_value' => $config->get('account_key'), + '#default_value' => $config->get('live_account_key'), '#required' => TRUE, ]; + $form['mode'] = [ + '#type' => 'radios', + '#title' => $this->t('Mode'), + '#options' => [ + 'test' => $this->t('Test'), + 'live' => $this->t('Live'), + ], + '#default_value' => $config->get('mode'), + ]; + + $form['endpoint_suffix'] = [ + '#type' => 'textfield', + '#title' => $this->t('Endpoint Suffix'), + '#description' => $this->t('The Endpoint Suffix for Azure Storage'), + '#default_value' => $config->get('endpoint_suffix'), + ]; + return parent::buildForm($form, $form_state); } @@ -72,7 +97,10 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $this->config('azure_storage.settings') ->set('protocol', $form_state->getValue('protocol')) ->set('account_name', $form_state->getValue('account_name')) - ->set('account_key', $form_state->getValue('account_key')) + ->set('test_account_key', $form_state->getValue('test_account_key')) + ->set('live_account_key', $form_state->getValue('live_account_key')) + ->set('mode', $form_state->getValue('mode')) + ->set('endpoint_suffix', $form_state->getValue('endpoint_suffix')) ->save(); }