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) {
|
set: function(data) {
|
||||||
// console.log('Add Key Auth URL', data);
|
console.log('Add Key Auth URL');
|
||||||
var ch = data.challenge;
|
var ch = data.challenge;
|
||||||
|
|
||||||
var signed = aws4.sign({
|
var signed = aws4.sign({
|
||||||
@ -62,7 +62,7 @@ module.exports.create = function(config) {
|
|||||||
// console.log(resp.statusCode);
|
// console.log(resp.statusCode);
|
||||||
if (200 !== resp.statusCode) {
|
if (200 !== resp.statusCode) {
|
||||||
console.error(resp.statusCode);
|
console.error(resp.statusCode);
|
||||||
console.error(resp.body);
|
// console.error(resp.body);
|
||||||
throw new Error('Could not PUT.');
|
throw new Error('Could not PUT.');
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -73,7 +73,7 @@ module.exports.create = function(config) {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
get: function(data) {
|
get: function(data) {
|
||||||
// console.log('List Key Auth URL', data);
|
console.log('List Key Auth URL');
|
||||||
|
|
||||||
var ch = data.challenge;
|
var ch = data.challenge;
|
||||||
|
|
||||||
@ -97,17 +97,17 @@ module.exports.create = function(config) {
|
|||||||
url: 'http://' + signed.host + signed.path,
|
url: 'http://' + signed.host + signed.path,
|
||||||
headers: { 'Content-Type': 'text/plain;charset=UTF-8' }
|
headers: { 'Content-Type': 'text/plain;charset=UTF-8' }
|
||||||
}).then(function(resp) {
|
}).then(function(resp) {
|
||||||
// console.log(resp.statusCode);
|
if (200 === resp.statusCode) {
|
||||||
if (200 !== resp.statusCode) {
|
|
||||||
console.error(resp.statusCode);
|
|
||||||
console.error(resp.body);
|
|
||||||
throw new Error('Could not GET');
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
keyAuthorization: resp.body
|
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) {
|
.catch(function(err) {
|
||||||
throw err;
|
throw err;
|
||||||
@ -117,9 +117,37 @@ module.exports.create = function(config) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
remove: function(data) {
|
remove: function(data) {
|
||||||
// console.log('Remove Key Auth URL', data);
|
console.log('Remove Key Auth URL');
|
||||||
var ch = data.challenge;
|
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…
x
Reference in New Issue
Block a user