implement DELETE, fix GET
This commit is contained in:
parent
7d97e8d4bb
commit
eed5063b2d
52
lib/index.js
52
lib/index.js
|
@ -32,7 +32,7 @@ module.exports.create = function(config) {
|
|||
},
|
||||
|
||||
set: function(data) {
|
||||
// console.log('Add Key Auth URL', data);
|
||||
console.log('Add Key Auth URL');
|
||||
var ch = data.challenge;
|
||||
|
||||
var signed = aws4.sign({
|
||||
|
@ -62,7 +62,7 @@ module.exports.create = function(config) {
|
|||
// console.log(resp.statusCode);
|
||||
if (200 !== resp.statusCode) {
|
||||
console.error(resp.statusCode);
|
||||
console.error(resp.body);
|
||||
// console.error(resp.body);
|
||||
throw new Error('Could not PUT.');
|
||||
}
|
||||
return true;
|
||||
|
@ -73,7 +73,7 @@ module.exports.create = function(config) {
|
|||
});
|
||||
},
|
||||
get: function(data) {
|
||||
// console.log('List Key Auth URL', data);
|
||||
console.log('List Key Auth URL');
|
||||
|
||||
var ch = data.challenge;
|
||||
|
||||
|
@ -97,17 +97,17 @@ module.exports.create = function(config) {
|
|||
url: 'http://' + signed.host + signed.path,
|
||||
headers: { 'Content-Type': 'text/plain;charset=UTF-8' }
|
||||
}).then(function(resp) {
|
||||
// console.log(resp.statusCode);
|
||||
if (200 !== resp.statusCode) {
|
||||
console.error(resp.statusCode);
|
||||
console.error(resp.body);
|
||||
throw new Error('Could not GET');
|
||||
}
|
||||
|
||||
if (200 === resp.statusCode) {
|
||||
return {
|
||||
keyAuthorization: resp.body
|
||||
};
|
||||
|
||||
}else if (404 === resp.statusCode){
|
||||
return null;
|
||||
}
|
||||
// wrong sign returns 403
|
||||
console.error(resp.statusCode);
|
||||
// console.error(resp.body);
|
||||
throw new Error('Could not GET');
|
||||
})
|
||||
.catch(function(err) {
|
||||
throw err;
|
||||
|
@ -117,9 +117,37 @@ module.exports.create = function(config) {
|
|||
},
|
||||
|
||||
remove: function(data) {
|
||||
// console.log('Remove Key Auth URL', data);
|
||||
console.log('Remove Key Auth URL');
|
||||
var ch = data.challenge;
|
||||
|
||||
var signed = aws4.sign({
|
||||
host: awsHost,
|
||||
service: 's3',
|
||||
region: awsRegion,
|
||||
path: '/' + awsBucket + '/' + ch.identifier.value + '/' + ch.token,
|
||||
method: 'DELETE',
|
||||
signQuery: true
|
||||
},
|
||||
AWSCredentials
|
||||
);
|
||||
console.log(signed);
|
||||
return request({
|
||||
// debug: true,
|
||||
method: 'DELETE',
|
||||
url: 'http://' + signed.host + signed.path
|
||||
}).then(function(resp) {
|
||||
// console.log(resp.statusCode);
|
||||
if (204 !== resp.statusCode) {
|
||||
console.error(resp.statusCode);
|
||||
console.error(resp.body);
|
||||
throw new Error('Could not DELETE.');
|
||||
}
|
||||
return true;
|
||||
})
|
||||
.catch(function(err) {
|
||||
throw err;
|
||||
// return null;
|
||||
});
|
||||
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue