Этот коммит содержится в:
nyaundi brian 2019-11-12 11:04:40 +03:00
родитель 7d97e8d4bb
Коммит eed5063b2d
1 изменённых файлов: 50 добавлений и 22 удалений

Просмотреть файл

@ -9,7 +9,7 @@ var defaults = {
awsSecretAccessKey: 'Tm3dNht5QMKxu7EU44ZLflDeE7sFbqQy3Q+XE+MY',
awsRegion: 'us-east-1',
awsBucket: 'hy8',
awsHost:'s3.switch.lxc'
awsHost: 's3.switch.lxc'
};
module.exports.create = function(config) {
@ -32,14 +32,14 @@ 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({
host: awsHost,
service: 's3',
region: awsRegion,
path: '/' + awsBucket + '/' + ch.identifier.value +'/'+ ch.token,
path: '/' + awsBucket + '/' + ch.identifier.value + '/' + ch.token,
headers: {
'Content-Type': 'text/plain;charset=UTF-8'
@ -54,7 +54,7 @@ module.exports.create = function(config) {
return request({
// debug: true,
method: 'PUT',
url: 'http://' +signed.host+ signed.path,
url: 'http://' + signed.host + signed.path,
headers: { 'Content-Type': 'text/plain;charset=UTF-8' },
body: ch.keyAuthorization
@ -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;
@ -81,7 +81,7 @@ module.exports.create = function(config) {
host: awsHost,
service: 's3',
region: awsRegion,
path: '/' + awsBucket + '/' + ch.identifier.value +'/'+ ch.token,
path: '/' + awsBucket + '/' + ch.identifier.value + '/' + ch.token,
headers: {
'Content-Type': 'text/plain;charset=UTF-8'
},
@ -94,33 +94,61 @@ module.exports.create = function(config) {
return request({
// debug: true,
method: 'GET',
url: 'http://' +signed.host+ signed.path,
url: 'http://' + signed.host + signed.path,
headers: { 'Content-Type': 'text/plain;charset=UTF-8' }
}).then(function(resp) {
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;
// return null;
});
},
remove: function(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 (200 !== resp.statusCode) {
if (204 !== resp.statusCode) {
console.error(resp.statusCode);
console.error(resp.body);
throw new Error('Could not GET');
throw new Error('Could not DELETE.');
}
return {
keyAuthorization: resp.body
};
return true;
})
.catch(function(err) {
throw err;
// return null;
});
},
remove: function(data) {
// console.log('Remove Key Auth URL', data);
var ch = data.challenge;
}
};
};