Compare commits

...

2 Commits

Author SHA1 Message Date
Dora Korpar fdaa86e1d3 [squash] apis 2019-06-18 17:02:07 -07:00
Dora Korpar 9c690507e7 ft: S3C-1976 bucket policies 2019-06-14 16:33:34 -07:00
5 changed files with 180 additions and 1 deletions

View File

@ -86,7 +86,6 @@ const constants = {
'logging',
'metrics',
'notification',
'policy',
'requestPayment',
'restore',
'torrent',

View File

@ -4,6 +4,7 @@ const bucketDelete = require('./bucketDelete');
const bucketDeleteCors = require('./bucketDeleteCors');
const bucketDeleteWebsite = require('./bucketDeleteWebsite');
const bucketDeleteLifecycle = require('./bucketDeleteLifecycle');
const bucketDeletePolicy = require('./bucketDeletePolicy');
const bucketGet = require('./bucketGet');
const bucketGetACL = require('./bucketGetACL');
const bucketGetCors = require('./bucketGetCors');
@ -11,6 +12,7 @@ const bucketGetVersioning = require('./bucketGetVersioning');
const bucketGetWebsite = require('./bucketGetWebsite');
const bucketGetLocation = require('./bucketGetLocation');
const bucketGetLifecycle = require('./bucketGetLifecycle');
const bucketGetPolicy = require('./bucketGetPolicy');
const bucketHead = require('./bucketHead');
const { bucketPut } = require('./bucketPut');
const bucketPutACL = require('./bucketPutACL');
@ -19,6 +21,7 @@ const bucketPutVersioning = require('./bucketPutVersioning');
const bucketPutWebsite = require('./bucketPutWebsite');
const bucketPutReplication = require('./bucketPutReplication');
const bucketPutLifecycle = require('./bucketPutLifecycle');
const bucketPutPolicy = require('./bucketPutPolicy');
const bucketGetReplication = require('./bucketGetReplication');
const bucketDeleteReplication = require('./bucketDeleteReplication');
const corsPreflight = require('./corsPreflight');
@ -183,6 +186,9 @@ const api = {
bucketPutLifecycle,
bucketGetLifecycle,
bucketDeleteLifecycle,
bucketPutPolicy,
bucketGetPolicy,
bucketDeletePolicy,
corsPreflight,
completeMultipartUpload,
initiateMultipartUpload,

View File

@ -0,0 +1,56 @@
const metadata = require('../metadata/wrapper');
const { metadataValidateBucket } = require('../metadata/metadataUtils');
const { pushMetric } = require('../utapi/utilities');
const collectCorsHeaders = require('../utilities/collectCorsHeaders');
/**
* bucketDeletePolicy - Delete the bucket policy
* @param {AuthInfo} authInfo - Instance of AuthInfo class with requester's info
* @param {object} request - http request object
* @param {object} log - Werelogs logger
* @param {function} callback - callback to server
* @return {undefined}
*/
function bucketDeletePolicy(authInfo, request, log, callback) {
log.debug('processing request', { method: 'bucketDeletePolicy' });
const { bucketName, headers, method } = request;
const metadataValParams = {
authInfo,
bucketName,
requestType: 'bucketOwnerAction',
};
return metadataValidateBucket(metadataValParams, log, (err, bucket) => {
const corsHeaders = collectCorsHeaders(headers.origin, method, bucket);
if (err) {
log.debug('error processing request', {
error: err,
method: 'bucketDeletePolicy',
});
return callback(err, corsHeaders);
}
if (!bucket.getBucketPolicy()) {
log.trace('no existing bucket policy', {
method: 'bucketDeletePolicy',
});
pushMetric('deleteBucketPolicy', log, {
authInfo,
bucket: bucketName,
});
return callback(null, corsHeaders);
}
log.trace('deleting bucket policy in metadata');
bucket.setBucketPolicy(null);
return metadata.updateBucket(bucketName, bucket, log, err => {
if (err) {
return callback(err, corsHeaders);
}
pushMetric('deleteBucketPolicy', log, {
authInfo,
bucket: bucketName,
});
return callback(null, corsHeaders);
});
});
}
module.exports = bucketDeletePolicy;

View File

@ -0,0 +1,49 @@
const { errors } = require('arsenal');
const { metadataValidateBucket } = require('../metadata/metadataUtils');
const { pushMetric } = require('../utapi/utilities');
const collectCorsHeaders = require('../utilities/collectCorsHeaders');
/**
* bucketGetLifecycle - Get the bucket lifecycle configuration
* @param {AuthInfo} authInfo - Instance of AuthInfo class with requester's info
* @param {object} request - http request object
* @param {object} log - Werelogs logger
* @param {function} callback - callback to server
* @return {undefined}
*/
function bucketGetLifecycle(authInfo, request, log, callback) {
log.debug('processing request', { method: 'bucketGetPolicy' });
const { bucketName, headers, method } = request;
const metadataValParams = {
authInfo,
bucketName,
requestType: 'bucketOwnerAction',
};
return metadataValidateBucket(metadataValParams, log, (err, bucket) => {
const corsHeaders = collectCorsHeaders(headers.origin, method, bucket);
if (err) {
log.debug('error processing request', {
error: err,
method: 'bucketGetPolicy',
});
return callback(err, null, corsHeaders);
}
const bucketPolicy = bucket.getBucketPolicy();
if (!bucketPolicy) {
log.debug('error processing request', {
error: errors.NoSuchBucketPolicy,
method: 'bucketGetLifecycle',
});
return callback(errors.NoSuchLifecycleConfiguration, null,
corsHeaders);
}
pushMetric('getBucketPolicy', log, {
authInfo,
bucket: bucketName,
});
return callback(null, bucketPolicy, corsHeaders);
});
}
module.exports = bucketGetLifecycle;

View File

@ -0,0 +1,69 @@
const async = require('async');
// const { BucketPolicy } = require('arsenal').models;
const parseXML = require('../utilities/parseXML');
const collectCorsHeaders = require('../utilities/collectCorsHeaders');
const metadata = require('../metadata/wrapper');
const { metadataValidateBucket } = require('../metadata/metadataUtils');
const { pushMetric } = require('../utapi/utilities');
/**
* bucketPutPolicy - create or update a bucket policy
* @param {AuthInfo} authInfo - Instance of AuthInfo class with requester's info
* @param {object} request - http request object
* @param {object} log - Werelogs logger
* @param {function} callback - callback to server
* @return {undefined}
*/
function bucketPutPolicy(authInfo, request, log, callback) {
log.debug('processing request', { method: 'bucketPutPolicy' });
const { bucketName } = request;
const metadataValParams = {
authInfo,
bucketName,
requestType: 'bucketOwnerAction',
};
const policyJSON = JSON.parse(request.post);
return async.waterfall([
next => parseXML(request.post, log, next),
(parsedXml, next) => {
const bucketPolicy = new BucketPolicy(parsedXml);
// if there was an error getting bucket policy,
// returned configObj will contain 'error' key
process.nextTick(() => {
const configObj = bucketPolicy.getbucketPolicy();
return next(configObj.error || null, configObj);
});
},
(bucketPolicy, next) => metadataValidateBucket(metadataValParams, log,
(err, bucket) => {
if (err) {
return next(err, bucket);
}
return next(null, bucket, bucketPolicy);
}),
(bucket, bucketPolicy, next) => {
bucket.setBucketPolicy(bucketPolicy);
metadata.updateBucket(bucket.getName(), bucket, log,
err => next(err, bucket));
},
], (err, bucket) => {
const corsHeaders = collectCorsHeaders(request.headers.origin,
request.method, bucket);
if (err) {
log.trace('error processing request',
{ error: err, method: 'bucketPutPolicy' });
return callback(err, corsHeaders);
}
pushMetric('putBucketPolicy', log, {
authInfo,
bucket: bucketName,
});
return callback(null, corsHeaders);
});
}
module.exports = bucketPutPolicy;