Skip to content

Commit

Permalink
[FEATURE] Fixes #199 and #201. Added SSE and Versioning feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
anvithks committed Nov 16, 2019
1 parent 11bb81e commit 3f4c559
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 9 deletions.
111 changes: 106 additions & 5 deletions src/app/business/block/buckets.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ export class BucketsComponent implements OnInit{
allBucketNameForCheck=[];
showCreateBucket = false;
akSkRouterLink = "/akSkManagement";
enableVersion: boolean;
enableEncryption = false;
sseTypes = [];
selectedSse = "SSE";
constructor(
public I18N: I18NService,
private router: Router,
Expand All @@ -92,7 +96,10 @@ export class BucketsComponent implements OnInit{
this.createBucketForm = this.fb.group({
"backend":["",{validators:[Validators.required], updateOn:'change'}],
"backend_type":["",{validators:[Validators.required], updateOn:'change'}],
"name":["",{validators:[Validators.required,Utils.isExisted(this.allBucketNameForCheck)], updateOn:'change'}]
"name":["",{validators:[Validators.required,Utils.isExisted(this.allBucketNameForCheck)], updateOn:'change'}],
"version": [false, { validators: [Validators.required], updateOn: 'change' }],
"encryption": [false, { validators: [Validators.required], updateOn: 'change' }],
"sse":["",{}],
});
this.migrationForm = this.fb.group({
"name": ['',{validators:[Validators.required], updateOn:'change'}],
Expand Down Expand Up @@ -131,6 +138,20 @@ export class BucketsComponent implements OnInit{
}];
this.allBackends = [];
this.getBuckets();
this.sseTypes = [
{
label: "SSE",
value: 'sse'
},
{
label: "SSE-C",
value: 'sse-c'
},
{
label: "SSE-KMS",
value: 'sse-kms'
},
]
}
showcalendar(){
this.selectTime = !this.selectTime;
Expand Down Expand Up @@ -190,6 +211,8 @@ export class BucketsComponent implements OnInit{
label:item.name,
value:item.name
});
item.encryptionEnabled = item.IsSSEEnabled=="true" ? true : false;
item.versionEnabled = item.IsVersioningEnabled=="true" ? true : false;
});
this.initBucket2backendAnd2Type();
});
Expand Down Expand Up @@ -327,7 +350,16 @@ export class BucketsComponent implements OnInit{
});
});
}

versionControl(){
let enableVersionValue = this.createBucketForm.get('version').value;

this.enableVersion = enableVersionValue ? true : false;
}
encryptionControl(){
let enableEncryptionValue = this.createBucketForm.get('encryption').value;

this.enableEncryption = enableEncryptionValue ? true : false;
}
creatBucket(){
if(!this.createBucketForm.valid){
for(let i in this.createBucketForm.controls){
Expand All @@ -338,7 +370,7 @@ export class BucketsComponent implements OnInit{
let param = {
name:this.createBucketForm.value.name,
backend_type:this.createBucketForm.value.backend_type,
backend:this.createBucketForm.value.backend,
backend:this.createBucketForm.value.backend
};
let xmlStr = `<CreateBucketConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">
<LocationConstraint>${this.createBucketForm.value.backend}</LocationConstraint>
Expand All @@ -352,14 +384,83 @@ export class BucketsComponent implements OnInit{
options.headers.set('Content-Type','application/xml');
this.BucketService.createBucket(this.createBucketForm.value.name,xmlStr,options).subscribe(()=>{
this.createBucketDisplay = false;
this.getBuckets();
/* Add the PUT Encryption Call here before fetching the updated list of Buckets */
if(this.enableEncryption){
this.bucketEncryption();
}
if(this.enableVersion){
this.bucketVersioning();
}
if(!this.enableEncryption && !this.enableVersion){
this.getBuckets();
}
/* Call the getBuckets call in the success of the encryption call */

});
})
})
}

bucketEncryption(){
let encryptStr = `<DefaultSSEConfiguration>
<SSE>
<enabled>true</enabled>
</SSE>
<SSE-KMS>
<enabled>false</enabled>
<DefaultKMSMasterKey>string</DefaultKMSMasterKey>
</SSE-KMS>
</DefaultSSEConfiguration>`
window['getAkSkList'](()=>{
let requestMethod = "PUT";
let url = this.BucketService.url+"/"+this.createBucketForm.value.name;
window['canonicalString'](requestMethod, url,()=>{
let options: any = {};
this.getSignature(options);
options.headers.set('Content-Type','application/xml');
this.BucketService.setEncryption(this.createBucketForm.value.name,encryptStr,options).subscribe(()=>{

if(this.enableVersion){
this.bucketVersioning();
this.enableVersion = false;
}
this.getBuckets();
});
});
})
}
bucketVersioning(){
window['getAkSkList'](()=>{
let requestMethod = "PUT";
let url = this.BucketService.url+"/"+this.createBucketForm.value.name;
window['canonicalString'](requestMethod, url,()=>{
let options: any = {};
this.getSignature(options);
options.headers.set('Content-Type','application/xml');
this.BucketService.setVersioning(this.createBucketForm.value.name,options).subscribe(()=>{

if(this.enableEncryption){
this.bucketEncryption();
this.enableEncryption=false;
}
this.getBuckets();
});
});
});
}
showCreateForm(){
this.createBucketDisplay = true;
this.createBucketForm.reset();
this.enableEncryption = false;
this.enableVersion = false;
this.createBucketForm.reset(
{
"backend":"",
"backend_type":"",
"name":"",
"version": false,
"encryption": false
}
);
this.createBucketForm.controls['name'].setValidators([Validators.required,Utils.isExisted(this.allBucketNameForCheck)]);
this.getTypes();
}
Expand Down
28 changes: 27 additions & 1 deletion src/app/business/block/buckets.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@
</p-column>
<p-column field="LocationConstraint" header="Default Backend" ></p-column>
<p-column field="createdAt" header="Created At"></p-column>
<p-column field="versionEnabled" header="Versioning Enabled">
<ng-template pTemplate="body" let-bucket="rowData">
<p *ngIf="bucket.versionEnabled">
<span class="version-text">Yes</span>
</p>
<p *ngIf="!bucket.versionEnabled">
<span class="version-text">No</span>
</p>
</ng-template>
</p-column>
<p-column field="encryptionEnabled" header="Encryption Enabled">
<ng-template pTemplate="body" let-bucket="rowData">
<p *ngIf="bucket.encryptionEnabled==true"><i class="fa fa-lock"></i> <span class="encryption-text">Yes</span><span class="encryption-type">AES256</span></p>
<p *ngIf="bucket.encryptionEnabled==false"><i class="fa fa-unlock"></i><span class="encryption-text">No</span></p>
</ng-template>
</p-column>
<p-column header="{{I18N.keyID['sds_block_volume_operation']}}" [style]="{'width': '335px'}">
<ng-template pTemplate="body" let-bucket="rowData" let-i="rowIndex">
<a (click)="configMigration(bucket)">Migrate</a>
Expand All @@ -35,7 +51,7 @@
</p-column>
</p-dataTable>

<p-dialog styleClass="create-bucket-dialog" header="Create Bucket" [(visible)]="createBucketDisplay" [width]="600" modal="modal" [height]="410">
<p-dialog styleClass="create-bucket-dialog" header="Create Bucket" [(visible)]="createBucketDisplay" [width]="900" modal="modal" [height]="700">
<form [grid]="{label: 'ui-g-3', content:'ui-g-20'}" [formGroup]="createBucketForm" [errorMessage]="errorMessage">
<form-item label="Name" [required]="true">
<input type="text" pInputText formControlName="name" />
Expand All @@ -48,6 +64,16 @@
<form-item label="Backend" [required]="true">
<p-dropdown [style]="{'min-width':'150px','width':'220px'}" placeholder="Please select" [options]="backendsOption" formControlName="backend"></p-dropdown>
</form-item>
<form-item label="Enable Versioning?" >
<p-inputSwitch formControlName="version" onLabel="Yes" offLabel="No" (onChange)="versionControl()"></p-inputSwitch>
</form-item>
<form-item label="Enable Encryption?" >
<p-inputSwitch formControlName="encryption" onLabel="Yes" offLabel="No" (onChange)="encryptionControl()"></p-inputSwitch>
</form-item>
<form-item label="Encryption Type">
<p-dropdown [style]="{'min-width':'150px','width':'220px'}" placeholder="Please select" [options]="sseTypes" [(disabled)]="!enableEncryption" [(ngModel)]='selectedSse' formControlName="sse"></p-dropdown>
</form-item>

</form>
<p-footer>
<button type="submit" class="ui-button-secondary" pButton (click)="creatBucket()" label="{{I18N.keyID['ok']}}"></button>
Expand Down
5 changes: 3 additions & 2 deletions src/app/business/block/buckets.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BucketsComponent } from './buckets.component';
import { RouterModule } from '@angular/router';
import { TabViewModule, ButtonModule } from '../../components/common/api';
import {DataTableModule, DropMenuModule, DialogModule, FormModule, InputTextModule, InputTextareaModule,
DropdownModule ,ConfirmationService,ConfirmDialogModule,CalendarModule,CheckboxModule} from '../../components/common/api';
DropdownModule ,ConfirmationService,ConfirmDialogModule,CalendarModule,CheckboxModule, InputSwitchModule} from '../../components/common/api';
import { ReactiveFormsModule, FormsModule } from '@angular/forms';
import { CommonModule } from '@angular/common';
import { HttpService } from './../../shared/service/Http.service';
Expand Down Expand Up @@ -31,7 +31,8 @@ import { MigrationService } from './../dataflow/migration.service';
ConfirmDialogModule,
RouterModule,
CalendarModule,
CheckboxModule
CheckboxModule,
InputSwitchModule
],
exports: [ BucketsComponent ],
providers: [
Expand Down
4 changes: 4 additions & 0 deletions src/app/business/block/buckets.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export class BucketService {
let url = this.url + '/' + id;
return this.http.get(url,options);
}
//Set Bucket Versioning
setVersioning(name,param?,options?) {
return this.http.put(this.url+"/"+name+"/?Versioning",param,options);
}

getBckends(): Observable<any> {
return this.http.get('v1beta/{project_id}/backend');
Expand Down
3 changes: 2 additions & 1 deletion src/assets/business/css/site.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1863,7 +1863,8 @@ a {
}
.create-bucket-dialog{
.ui-dialog-content{
height: 295px;
height: 550px;
padding-bottom: 0.6rem !important;
}
}

Expand Down

0 comments on commit 3f4c559

Please sign in to comment.