web/satellite: create access grant: get restricted api key from web worker

WHAT:
get new api key with restrictions from web worker

WHY:
apply restrictions

Change-Id: I5747c9ede0c508b29f635a07895738715bd54621
This commit is contained in:
VitaliiShpital 2020-11-17 22:22:14 +02:00 committed by Vitalii Shpital
parent c22ae05bbe
commit 005b089c01
4 changed files with 58 additions and 33 deletions

View File

@ -37,6 +37,8 @@ export default class SortAccessGrantsHeader extends Vue {
@Prop({default: () => new Promise(() => false)}) @Prop({default: () => new Promise(() => false)})
private readonly onHeaderClickCallback: OnHeaderClickCallback; private readonly onHeaderClickCallback: OnHeaderClickCallback;
public AccessGrantsOrderBy = AccessGrantsOrderBy;
public sortBy: AccessGrantsOrderBy = AccessGrantsOrderBy.NAME; public sortBy: AccessGrantsOrderBy = AccessGrantsOrderBy.NAME;
public sortDirection: SortDirection = SortDirection.ASCENDING; public sortDirection: SortDirection = SortDirection.ASCENDING;

View File

@ -64,26 +64,12 @@ export default class BucketsSelection extends Vue {
return this.storedBucketNames.length.toString(); return this.storedBucketNames.length.toString();
} }
/**
* Returns selected bucket names from store or all bucket names.
*/
public get selectedBucketNames(): string[] {
return this.storedBucketNames.length ? this.storedBucketNames : this.allBucketNames;
}
/** /**
* Returns stored selected bucket names. * Returns stored selected bucket names.
*/ */
public get storedBucketNames(): string[] { private get storedBucketNames(): string[] {
return this.$store.state.accessGrantsModule.selectedBucketNames; return this.$store.state.accessGrantsModule.selectedBucketNames;
} }
/**
* Returns all bucket names.
*/
public get allBucketNames(): string[] {
return this.$store.state.bucketUsageModule.allBucketNames;
}
} }
</script> </script>

View File

@ -11,12 +11,12 @@
<div class="permissions__content"> <div class="permissions__content">
<div class="permissions__content__left"> <div class="permissions__content__left">
<div class="permissions__content__left__item"> <div class="permissions__content__left__item">
<input type="checkbox" id="read" name="read" v-model="isRead" :checked="isRead"> <input type="checkbox" id="download" name="download" v-model="isDownload" :checked="isDownload">
<label class="permissions__content__left__item__label" for="read">Read</label> <label class="permissions__content__left__item__label" for="download">Download</label>
</div> </div>
<div class="permissions__content__left__item"> <div class="permissions__content__left__item">
<input type="checkbox" id="write" name="write" v-model="isWrite" :checked="isWrite"> <input type="checkbox" id="upload" name="upload" v-model="isUpload" :checked="isUpload">
<label class="permissions__content__left__item__label" for="write">Write</label> <label class="permissions__content__left__item__label" for="upload">Upload</label>
</div> </div>
<div class="permissions__content__left__item"> <div class="permissions__content__left__item">
<input type="checkbox" id="list" name="list" v-model="isList" :checked="isList"> <input type="checkbox" id="list" name="list" v-model="isList" :checked="isList">
@ -40,7 +40,7 @@
<div class="permissions__content__right__bucket-bullets"> <div class="permissions__content__right__bucket-bullets">
<div <div
class="permissions__content__right__bucket-bullets__container" class="permissions__content__right__bucket-bullets__container"
v-for="(name, index) in selectedBucketNames" v-for="(name, index) in storedBucketNames"
:key="index" :key="index"
> >
<BucketNameBullet :name="name"/> <BucketNameBullet :name="name"/>
@ -90,8 +90,8 @@ export default class PermissionsStep extends Vue {
private restrictedKey: string = ''; private restrictedKey: string = '';
private worker: Worker; private worker: Worker;
public isRead: boolean = true; public isDownload: boolean = true;
public isWrite: boolean = true; public isUpload: boolean = true;
public isList: boolean = true; public isList: boolean = true;
public isDelete: boolean = true; public isDelete: boolean = true;
@ -156,16 +156,44 @@ export default class PermissionsStep extends Vue {
* Holds on continue in browser button click logic. * Holds on continue in browser button click logic.
*/ */
public onContinueInBrowserClick(): void { public onContinueInBrowserClick(): void {
// mock this.worker.postMessage({
return; 'type': 'SetPermission',
'isDownload': this.isDownload,
'isUpload': this.isUpload,
'isList': this.isList,
'isDelete': this.isDelete,
'buckets': this.selectedBucketNames,
'apiKey': this.key,
});
this.$router.push({
name: RouteConfig.AccessGrants.with(RouteConfig.CreateAccessGrant.with(RouteConfig.PassphraseStep)).name,
params: {
key: this.restrictedKey,
},
});
} }
/** /**
* Returns stored selected bucket names. * Returns stored selected bucket names.
*/ */
public get selectedBucketNames(): string[] { public get storedBucketNames(): string[] {
return this.$store.state.accessGrantsModule.selectedBucketNames; return this.$store.state.accessGrantsModule.selectedBucketNames;
} }
/**
* Returns selected bucket names from store or all bucket names.
*/
private get selectedBucketNames(): string[] {
return this.storedBucketNames.length ? this.storedBucketNames : this.allBucketNames;
}
/**
* Returns all bucket names.
*/
private get allBucketNames(): string[] {
return this.$store.state.bucketUsageModule.allBucketNames;
}
} }
</script> </script>

View File

@ -18,21 +18,30 @@ const response = fetch('/static/static/wasm/access.wasm');
instantiateStreaming(response, go.importObject).then(result => go.run(result.instance)).catch(err => self.postMessage(new Error(err.message))); instantiateStreaming(response, go.importObject).then(result => go.run(result.instance)).catch(err => self.postMessage(new Error(err.message)));
self.onmessage = function (event) { self.onmessage = function (event) {
const type = event.data.type; const data = event.data;
let result; let result;
switch (type) { switch (data.type) {
case 'GenerateAccess': case 'GenerateAccess':
result = self.generateAccessGrant(); result = self.generateAccessGrant();
self.postMessage(result);
break;
case 'NewPermission':
result = self.newPermission();
self.postMessage(result); self.postMessage(result);
break; break;
case 'SetPermission': case 'SetPermission':
result = self.setAPIKeyPermission(); const isDownload = data.isDownload;
const isUpload = data.isUpload;
const isList = data.isList;
const isDelete = data.isDelete;
const buckets = data.buckets;
const apiKey = data.apiKey;
let permission = self.newPermission().value;
permission.AllowDownload = isDownload;
permission.AllowUpload = isUpload;
permission.AllowDelete = isDelete;
permission.AllowList = isList;
result = self.setAPIKeyPermission(apiKey, buckets, permission);
self.postMessage(result); self.postMessage(result);
break; break;