Skip to content

Commit 376fcab

Browse files
author
Ádám Hóka
committed
Add Azure Blob Storage support
Signed-off-by: Adam Hoka <hoka.adam@nexogen.hu>
1 parent 12ab900 commit 376fcab

8 files changed

Lines changed: 60 additions & 6 deletions

File tree

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ There are some config settings you need to change in the files below.
212212
| `HMD_MINIO_ENDPOINT` | `minio.example.org` | Address of your Minio endpoint/instance |
213213
| `HMD_MINIO_PORT` | `9000` | Port that is used for your Minio instance |
214214
| `HMD_MINIO_SECURE` | `true` | If set to `true` HTTPS is used for Minio |
215+
| `HMD_AZURE_CONNECTION_STRING` | no example | Azure Blob Storage connection string |
216+
| `HMD_AZURE_CONTAINER` | no example | Azure Blob Storage container name (automatically created if non existent) |
215217
| `HMD_HSTS_ENABLE` | ` true` | set to enable [HSTS](https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security) if HTTPS is also enabled (default is ` true`) |
216218
| `HMD_HSTS_INCLUDE_SUBDOMAINS` | `true` | set to include subdomains in HSTS (default is `true`) |
217219
| `HMD_HSTS_MAX_AGE` | `31536000` | max duration in seconds to tell clients to keep HSTS status (default is a year) |
@@ -261,7 +263,7 @@ There are some config settings you need to change in the files below.
261263
| `documentMaxLength` | `100000` | note max length |
262264
| `email` | `true` or `false` | set to allow email signin |
263265
| `allowEmailRegister` | `true` or `false` | set to allow email register (only applied when email is set, default is `true`. Note `bin/manage_users` might help you if registration is `false`.) |
264-
| `imageUploadType` | `imgur`(default), `s3`, `minio` or `filesystem` | Where to upload image
266+
| `imageUploadType` | `imgur`(default), `s3`, `minio`, `azure` or `filesystem` | Where to upload image
265267
| `minio` | `{ "accessKey": "YOUR_MINIO_ACCESS_KEY", "secretKey": "YOUR_MINIO_SECRET_KEY", "endpoint": "YOUR_MINIO_HOST", port: 9000, secure: true }` | When `imageUploadType` is set to `minio`, you need to set this key. Also checkout our [Minio Image Upload Guide](docs/guides/minio-image-upload.md) |
266268
| `s3` | `{ "accessKeyId": "YOUR_S3_ACCESS_KEY_ID", "secretAccessKey": "YOUR_S3_ACCESS_KEY", "region": "YOUR_S3_REGION" }` | When `imageuploadtype` be set to `s3`, you would also need to setup this key, check our [S3 Image Upload Guide](docs/guides/s3-image-upload.md) |
267269
| `s3bucket` | `YOUR_S3_BUCKET_NAME` | bucket name when `imageUploadType` is set to `s3` or `minio` |
@@ -271,7 +273,7 @@ There are some config settings you need to change in the files below.
271273
| service | settings location | description |
272274
| ------- | --------- | ----------- |
273275
| facebook, twitter, github, gitlab, mattermost, dropbox, google, ldap, saml | environment variables or `config.json` | for signin |
274-
| imgur, s3, minio | environment variables or `config.json` | for image upload |
276+
| imgur, s3, minio, azure | environment variables or `config.json` | for image upload |
275277
| dropbox(`dropbox/appKey`) | `config.json` | for export and import |
276278

277279
## Third-party integration OAuth callback URLs

config.json.example

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@
114114
"secretAccessKey": "change this",
115115
"region": "change this"
116116
},
117-
"s3bucket": "change this"
117+
"s3bucket": "change this",
118+
"azure":
119+
{
120+
"connectionString": "change this",
121+
"container": "change this"
122+
}
118123
}
119124
}

lib/config/default.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ module.exports = {
5656
heartbeatTimeout: 10000,
5757
// document
5858
documentMaxLength: 100000,
59-
// image upload setting, available options are imgur/s3/filesystem
59+
// image upload setting, available options are imgur/s3/filesystem/azure
6060
imageUploadType: 'filesystem',
6161
imgur: {
6262
clientID: undefined
@@ -74,6 +74,10 @@ module.exports = {
7474
port: 9000
7575
},
7676
s3bucket: undefined,
77+
azure: {
78+
connectionString: undefined,
79+
container: undefined
80+
},
7781
// authentication
7882
facebook: {
7983
clientID: undefined,

lib/config/dockerSecret.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ if (fs.existsSync(basePath)) {
2222
accessKeyId: getSecret('s3_acccessKeyId'),
2323
secretAccessKey: getSecret('s3_secretAccessKey')
2424
},
25+
azure: {
26+
connectionString: getSecret('azure_connectionString')
27+
},
2528
facebook: {
2629
clientID: getSecret('facebook_clientID'),
2730
clientSecret: getSecret('facebook_clientSecret')

lib/config/environment.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ module.exports = {
4545
port: toIntegerConfig(process.env.HMD_MINIO_PORT)
4646
},
4747
s3bucket: process.env.HMD_S3_BUCKET,
48+
azure: {
49+
connectionString: process.env.HMD_AZURE_CONNECTION_STRING,
50+
container: process.env.HMD_AZURE_CONTAINER
51+
},
4852
facebook: {
4953
clientID: process.env.HMD_FACEBOOK_CLIENTID,
5054
clientSecret: process.env.HMD_FACEBOOK_CLIENTSECRET

lib/config/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ if (config.sessionSecret === 'secret') {
127127
}
128128

129129
// Validate upload upload providers
130-
if (['filesystem', 's3', 'minio', 'imgur'].indexOf(config.imageUploadType) === -1) {
131-
logger.error('"imageuploadtype" is not correctly set. Please use "filesystem", "s3", "minio" or "imgur". Defaulting to "imgur"')
130+
if (['filesystem', 's3', 'minio', 'imgur', 'azure'].indexOf(config.imageUploadType) === -1) {
131+
logger.error('"imageuploadtype" is not correctly set. Please use "filesystem", "s3", "minio", "azure" or "imgur". Defaulting to "imgur"')
132132
config.imageUploadType = 'imgur'
133133
}
134134

lib/web/imageRouter/azure.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict'
2+
const path = require('path')
3+
4+
const config = require('../../config')
5+
const logger = require('../../logger')
6+
7+
const azure = require('azure-storage')
8+
9+
exports.uploadImage = function (imagePath, callback) {
10+
if (!imagePath || typeof imagePath !== 'string') {
11+
callback(new Error('Image path is missing or wrong'), null)
12+
return
13+
}
14+
15+
if (!callback || typeof callback !== 'function') {
16+
logger.error('Callback has to be a function')
17+
return
18+
}
19+
20+
var azureBlobService = azure.createBlobService(config.azure.connectionString)
21+
22+
azureBlobService.createContainerIfNotExists(config.azure.container, { publicAccessLevel: 'blob' }, function (err, result, response) {
23+
if (err) {
24+
callback(new Error(err.message), null)
25+
} else {
26+
azureBlobService.createBlockBlobFromLocalFile(config.azure.container, path.basename(imagePath), imagePath, function (err, result, response) {
27+
if (err) {
28+
callback(new Error(err.message), null)
29+
} else {
30+
callback(null, azureBlobService.getUrl(config.azure.container, result.name))
31+
}
32+
})
33+
}
34+
})
35+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"async": "^2.1.4",
2020
"aws-sdk": "^2.7.20",
2121
"base64url": "^3.0.0",
22+
"azure-storage": "^2.7.0",
2223
"blueimp-md5": "^2.6.0",
2324
"body-parser": "^1.15.2",
2425
"bootstrap": "^3.3.7",

0 commit comments

Comments
 (0)