Skip to content

Commit

Permalink
Merge pull request kubernetes#489 from anvithks/restore-fix
Browse files Browse the repository at this point in the history
Fixed object restore issue. Added appropriate messages while archiving object.
  • Loading branch information
skdwriting authored Dec 22, 2020
2 parents e707ae2 + 4c21cf5 commit b00541a
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 21 deletions.
72 changes: 60 additions & 12 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,35 @@ export class AppComponent implements OnInit, AfterViewInit {
uploadNum = 0;
self.progressValue = 0;
} else {
let errMessage = {
header: '',
content: ''
};
self.showPrompt = false;
uploadNum = 0;
self.progressValue = 0;
window['isUpload'] = false;
self.msg.error("Upload failed. The network may be unstable. Please try again later.");
let x2js = new X2JS();
let jsonObj = x2js.xml_str2json(xhr.responseText);
if(jsonObj.Error && jsonObj.Error.Code){
errMessage['header'] = jsonObj.Error.Code;
errMessage['content'] = jsonObj.Error.Message;
} else{
errMessage.content="Upload failed. The network may be unstable. Please try again later.";
}

if(requestOptions.headers['X-Amz-Storage-Class']){
self.msg.error("File ["+ selectFile.name +"] could not be archived.");
errMessage.content+=". File ["+ selectFile.name +"] could not be archived."
self.msg.error(errMessage);
if (cb) {
cb();
}
} else{
errMessage.content+=". File ["+ selectFile.name +"] could not be uploaded."
self.msg.error(errMessage);
if (cb) {
cb();
}
}
}
};
Expand All @@ -428,15 +450,35 @@ export class AppComponent implements OnInit, AfterViewInit {
window['singleUpload'](selectFile, bucketId, options, uploadUrl, cb);
uploadNum++;
}else{
this.showPrompt = false;
let errMessage = {
header: '',
content: ''
};
self.showPrompt = false;
uploadNum = 0;
self.progressValue = 0;
window['isUpload'] = false;
this.msg.error("Upload failed. The network may be unstable. Please try again later.");
if(requestOptions.headers['X-Amz-Storage-Class']){
self.msg.error("File ["+ selectFile.name +"] could not be archived." + err);
let x2js = new X2JS();
let jsonObj = x2js.xml_str2json(xhr.responseText);
if(jsonObj.Error && jsonObj.Error.Code){
errMessage['header'] = jsonObj.Error.Code;
errMessage['content'] = jsonObj.Error.Message;
} else{
errMessage.content="Upload failed. The network may be unstable. Please try again later.";
}
if (cb) {
cb();

if(requestOptions.headers['X-Amz-Storage-Class']){
errMessage.content+=". File ["+ selectFile.name +"] could not be archived."
self.msg.error(errMessage);
if (cb) {
cb();
}
} else{
errMessage.content+=". File ["+ selectFile.name +"] could not be uploaded."
self.msg.error(errMessage);
if (cb) {
cb();
}
}
}
}
Expand Down Expand Up @@ -696,15 +738,16 @@ export class AppComponent implements OnInit, AfterViewInit {
method: method,
path: canonicalUri,
service: service ? service : 's3',
region: region ? region : 'ap-south-1',
region: region ? region : 'us-east-1',
body: body ? body : '',
headers: {
'X-Auth-Token': localStorage['auth-token'],
'Content-Type': headers && headers['Content-Type'] ? headers['Content-Type'] : 'application/xml'
'X-Auth-Token': localStorage['auth-token']
}

}

if(region){
requestOptions['region'] = region;
}
/******
ToDo:
Currently we are checking for the known headers in our API requests and adding them to the signature generation.
Expand All @@ -728,6 +771,11 @@ export class AppComponent implements OnInit, AfterViewInit {
if(headers && headers['X-Amz-Content-Sha256'] == 'UNSIGNED-PAYLOAD'){
requestOptions.headers['X-Amz-Content-Sha256'] = 'UNSIGNED-PAYLOAD';
}

if(headers && headers['Content-Type']){
requestOptions.headers['Content-Type'] = headers['Content-Type'];
}

aws4.sign(requestOptions, {
secretAccessKey: this.SignatureKey['secretAccessKey'],
accessKeyId: this.SignatureKey['AccessKey']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
</div>
</div>
<div style="padding: 20px 0;">
<label>Do you want to Archive this object?</label>
<label>Archive object?</label>
<p-inputSwitch [(ngModel)]="enableArchival" onLabel="Yes" offLabel="No"></p-inputSwitch>
</div>
<form *ngIf="enableArchival" [grid]="{label: 'ui-g-3', content:'ui-g-20'}" [formGroup]="uploadForm" [errorMessage]="errorMessage">
Expand Down
15 changes: 9 additions & 6 deletions src/app/business/block/bucket-detail/bucket-detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,28 +460,31 @@ export class BucketDetailComponent implements OnInit {
let params = {
"days" : value.days,
"tier" : value.tier
}
};
window['getAkSkList'](()=>{
let requestMethod = "POST";
let url = '/' + this.bucketId + '/' + this.selectFileName + '?restore';
let requestOptions: any;
let options: any = {};
let contentHeaders = {
'Content-Type' : 'application/json',
'X-Amz-Content-Sha256': 'UNSIGNED-PAYLOAD'
};
requestOptions = window['getSignatureKey'](requestMethod, url, '', '', '', '', '', '', contentHeaders);

options['headers'] = new Headers();

requestOptions = window['getSignatureKey'](requestMethod, url, '', '', '', params);

options = this.BucketService.getSignatureOptions(requestOptions, options);

this.BucketService.restoreObject(this.bucketId, this.selectFileName, params, options).subscribe((res)=>{
this.BucketService.restoreObject(this.bucketId + '/' + this.selectFileName, params, options).subscribe((res)=>{
this.restoreDisplay = false;
this.restoreObjectForm.reset({
"days" : 1
});
this.msgs = [];
this.msgs.push({severity: 'success', summary: 'Success', detail: 'Object has been retrieved successfully.'});
this.msgs.push({severity: 'success', summary: 'Success', detail: 'Object restoration has been initiated successfully. Object will be available for download shortly.'});
},
(error)=>{
console.log("Object could not be retrieved.", error);
this.restoreDisplay = false;
this.restoreObjectForm.reset({
"days" : 1
Expand Down
4 changes: 2 additions & 2 deletions src/app/business/block/buckets.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ export class BucketService {
}

//Restore Object
restoreObject(bucketName, objectName, param?, options?){
let url = this.url + bucketName + "/" + objectName + "?restore"
restoreObject(name, param?, options?){
let url = this.url + name + "?restore"
return this.http.post(url, param, options);
}

Expand Down

0 comments on commit b00541a

Please sign in to comment.