Skip to content

Commit

Permalink
Add auth to config for gme blob. Fixes #1645 (#1838)
Browse files Browse the repository at this point in the history
* Add auth to config for gme blob. Fixes #1645

* Only ask for access token if not running in the browser
  • Loading branch information
brollb authored Aug 5, 2020
1 parent 5f2753f commit 263474f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/common/storage/backends/gme/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ define([
BlobClient
) {

const GMEStorage = function(/*name, logger*/) {
const GMEStorage = function(id, name, logger, config={}) {
StorageClient.apply(this, arguments);
const params = this.getBlobClientParams();
params.apiToken = config.apiToken;
this.blobClient = new BlobClient(params);
};

Expand Down
25 changes: 25 additions & 0 deletions src/common/storage/backends/gme/metadata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*global define*/
define([
'deepforge/gmeConfig',
], function(
config,
) {
const metadata = {
name: 'WebGME Blob Storage',
configStructure: []
};


if (config.authentication.enable) {
metadata.configStructure.push({
name: 'apiToken',
displayName: 'Access Token',
value: '',
valueType: 'string',
readOnly: false,
isAuth: true,
isRequiredForBrowser: false,
});
}
return metadata;
});
4 changes: 0 additions & 4 deletions src/common/storage/backends/gme/metadata.json

This file was deleted.

4 changes: 2 additions & 2 deletions src/common/storage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ define([
'module',
'./backends/StorageBackend',
'text!deepforge/storage/backends/sciserver-files/metadata.json',
'text!deepforge/storage/backends/gme/metadata.json',
'deepforge/storage/backends/gme/metadata',
'text!deepforge/storage/backends/s3/metadata.json'
],function(
module,
Expand All @@ -15,7 +15,7 @@ define([
const Storage = {};
const StorageMetadata = {};
StorageMetadata['sciserver-files'] = JSON.parse(sciserverFiles);
StorageMetadata['gme'] = JSON.parse(gme);
StorageMetadata['gme'] = gme;
StorageMetadata['s3'] = JSON.parse(s3);
const STORAGE_BACKENDS = Object.keys(StorageMetadata);

Expand Down
14 changes: 11 additions & 3 deletions src/common/viz/StorageHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ define([
) {
const StorageHelpers = {};

StorageHelpers.getAuthenticationConfig = async function (dataInfo) {
StorageHelpers.getAuthenticationConfig = async function (dataInfo, runInBrowser=false) {
const {backend} = dataInfo;
const metadata = Storage.getStorageMetadata(backend);
metadata.configStructure = metadata.configStructure
.filter(option => option.isAuth);
.filter(option => {
if (option.isAuth) {
const isRequiredForBrowser = option.isRequiredForBrowser !== false;
const isNodeJs = !runInBrowser;
return isNodeJs || isRequiredForBrowser;
}
return false;
});

if (metadata.configStructure.length) {
const configDialog = new ConfigDialog();
const title = `Authenticate with ${metadata.name}`;
Expand All @@ -26,7 +34,7 @@ define([
};

StorageHelpers.download = async function (dataInfo, dataName='data') {
const config = await StorageHelpers.getAuthenticationConfig(dataInfo);
const config = await StorageHelpers.getAuthenticationConfig(dataInfo, true);
const storageAdapter = await Storage.getClient(dataInfo.backend, null, config);
const storageName = Storage.getStorageMetadata(dataInfo.backend).name;

Expand Down

0 comments on commit 263474f

Please sign in to comment.