Skip to content
Open
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
45 changes: 44 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
7 changes: 5 additions & 2 deletions azure_storage.info.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Azure Storage Integration
type: module
description: 'Integrates Azure Storage with Drupal'
core: 8.x
package: azure
core_version_requirement: ^8.8.3 || ^9
package: Azure
configure: azure_storage.settings_form
dependencies:
- key:key
24 changes: 2 additions & 22 deletions azure_storage.install
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href=":settings">Azure Storage File System module settings page</a>.', [
':settings' => Url::fromRoute('azure_storage.admin_settings')->toString(),
]),
];
}
if ($phase === 'runtime') {

if (ini_get('allow_url_fopen')) {
$requirements['azure_storage_allow_url_fopen'] = [
Expand Down Expand Up @@ -159,4 +139,4 @@ function azure_storage_install() {
\Drupal::database()->query("ALTER TABLE {azure_storage_file} ADD PRIMARY KEY (uri)");
break;
}
}
}
4 changes: 2 additions & 2 deletions azure_storage.links.menu.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions azure_storage.links.task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
azure_storage.settings_form:
title: 'Settings'
route_name: azure_storage.settings_form
base_route: azure_storage.settings_form
2 changes: 2 additions & 0 deletions azure_storage.permissions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
administer azure storage:
title: 'Administer Azure Storage configuration'
7 changes: 3 additions & 4 deletions azure_storage.routing.yml
Original file line number Diff line number Diff line change
@@ -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

7 changes: 7 additions & 0 deletions azure_storage.services.yml
Original file line number Diff line number Diff line change
@@ -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']
30 changes: 16 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
7 changes: 6 additions & 1 deletion config/install/azure_storage.settings.yml
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
azure_storage:
protocol: 'https'
account_name: ''
test_account_key: ''
live_account_key: ''
mode: 'test'
endpoint_suffix: ''
39 changes: 39 additions & 0 deletions src/AzureStorage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Drupal\azure_storage;

/**
* Class AzureStorage.
*
* @package Drupal\azure_storage
*/
final class AzureStorage {

/**
* Gets the Azure Storage Account key value.
*
* @param null $key_id
* Optional custom key module key id.
*
* @return string|null
* The key value if found or NULL.
*/
public static function getAccountKey($key_id = NULL) {
$settings = \Drupal::config('azure_storage.settings');
if ($key_id === NULL) {
$mode = $settings->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;
}

}
82 changes: 82 additions & 0 deletions src/AzureStorageClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace Drupal\azure_storage;

use Drupal\Core\Config\ConfigFactoryInterface;
use MicrosoftAzure\Storage\Queue\QueueRestProxy;
use Psr\Log\LoggerInterface;

/**
* Class AzureStorageClient.
*
* @package Drupal\azure_storage
*/
class AzureStorageClient implements AzureStorageClientInterface {

/**
* The Azure Storage settings.
*
* @var \Drupal\Core\Config\Config
*/
protected $config;

/**
* Logger service.
*
* @var \Drupal\Core\Logger\LoggerChannelInterface
*/
protected $logger;

/**
* Azure Queue client.
*
* @var \MicrosoftAzure\Storage\Queue\Internal\IQueue
*/
protected $queueClient;

/**
* AzureStorageClient constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* A configuration factory instance.
* @param \Psr\Log\LoggerInterface $logger
* A logger instance.
*/
public function __construct(ConfigFactoryInterface $config_factory, LoggerInterface $logger) {
$this->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";
}

}
44 changes: 44 additions & 0 deletions src/AzureStorageClientInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Drupal\azure_storage;

/**
* Interface AzureStorageClientInterface.
*
* @package Drupal\azure_storage
*/
interface AzureStorageClientInterface {

/**
* Set a storage queue service.
*
* When no connection string is given, one will be looked up from config.
*
* @param string $connection_string
* Optional Azure connection string.
*
* @return $this
* AzureClient.
*/
public function setStorageQueueService($connection_string = NULL);

/**
* Get the storage queue service.
*
* @return \MicrosoftAzure\Storage\Queue\Internal\IQueue
* Azure Queue Service.
*/
public function getStorageQueueService();

/**
* Get a storage queue connection string.
*
* @param array $params
* Optional parameters with fallback.
*
* @return string
* Connection string.
*/
public function getStorageQueueConnectionString(array $params = []) : string;

}
Loading