2020-11-10 17:00:00 +00:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
importScripts('/static/static/wasm/wasm_exec.js')
|
|
|
|
|
|
|
|
if (!WebAssembly.instantiate) {
|
|
|
|
self.postMessage(new Error('web assembly is not supported'));
|
|
|
|
}
|
|
|
|
|
|
|
|
const go = new Go();
|
|
|
|
const instantiateStreaming = WebAssembly.instantiateStreaming || async function (resp, importObject) {
|
|
|
|
const response = await resp;
|
|
|
|
const source = await response.arrayBuffer();
|
|
|
|
|
|
|
|
return await WebAssembly.instantiate(source, importObject);
|
|
|
|
};
|
|
|
|
const response = fetch('/static/static/wasm/access.wasm');
|
2020-12-15 18:48:34 +00:00
|
|
|
instantiateStreaming(response, go.importObject).then(result => {
|
|
|
|
go.run(result.instance)
|
|
|
|
self.postMessage('configured');
|
|
|
|
}).catch(err => self.postMessage(new Error(err.message)));
|
2020-11-10 17:00:00 +00:00
|
|
|
|
|
|
|
self.onmessage = function (event) {
|
2020-11-17 20:22:14 +00:00
|
|
|
const data = event.data;
|
2020-11-16 20:06:41 +00:00
|
|
|
let result;
|
2020-11-18 20:12:59 +00:00
|
|
|
let apiKey;
|
2020-11-17 20:22:14 +00:00
|
|
|
switch (data.type) {
|
2020-11-10 17:00:00 +00:00
|
|
|
case 'GenerateAccess':
|
2020-11-18 20:12:59 +00:00
|
|
|
apiKey = data.apiKey;
|
|
|
|
const passphrase = data.passphrase;
|
|
|
|
const projectID = data.projectID;
|
2020-12-23 04:24:37 +00:00
|
|
|
const nodeURL = data.satelliteNodeURL;
|
2020-11-18 20:12:59 +00:00
|
|
|
|
|
|
|
result = self.generateAccessGrant(nodeURL, apiKey, passphrase, projectID);
|
2020-11-16 20:06:41 +00:00
|
|
|
|
|
|
|
self.postMessage(result);
|
|
|
|
break;
|
|
|
|
case 'SetPermission':
|
2020-11-17 20:22:14 +00:00
|
|
|
const isDownload = data.isDownload;
|
|
|
|
const isUpload = data.isUpload;
|
|
|
|
const isList = data.isList;
|
|
|
|
const isDelete = data.isDelete;
|
|
|
|
const buckets = data.buckets;
|
2020-11-24 20:51:36 +00:00
|
|
|
const notBefore = data.notBefore;
|
|
|
|
const notAfter = data.notAfter;
|
2020-11-18 20:12:59 +00:00
|
|
|
apiKey = data.apiKey;
|
2020-11-17 20:22:14 +00:00
|
|
|
|
|
|
|
let permission = self.newPermission().value;
|
|
|
|
|
|
|
|
permission.AllowDownload = isDownload;
|
|
|
|
permission.AllowUpload = isUpload;
|
|
|
|
permission.AllowDelete = isDelete;
|
|
|
|
permission.AllowList = isList;
|
2020-11-24 20:51:36 +00:00
|
|
|
permission.NotBefore = notBefore;
|
|
|
|
permission.NotAfter = notAfter;
|
2020-11-17 20:22:14 +00:00
|
|
|
|
|
|
|
result = self.setAPIKeyPermission(apiKey, buckets, permission);
|
2020-11-10 17:00:00 +00:00
|
|
|
|
|
|
|
self.postMessage(result);
|
|
|
|
break;
|
2021-02-15 13:06:47 +00:00
|
|
|
case 'Stop':
|
|
|
|
self.close();
|
|
|
|
break;
|
2020-11-10 17:00:00 +00:00
|
|
|
default:
|
|
|
|
self.postMessage(new Error('provided message event type is not supported'));
|
|
|
|
}
|
|
|
|
};
|