-
Notifications
You must be signed in to change notification settings - Fork 251
CLDSRV754: add GetBucketLogging and PutBucketLogging endpoints #5966
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bert-e
merged 3 commits into
development/9.1
from
improvement/CLDSRV-754-bucket-put-get-logging
Oct 16, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const { standardMetadataValidateBucket } = require('../metadata/metadataUtils'); | ||
const { checkExpectedBucketOwner } = require('./apiUtils/authorization/bucketOwner'); | ||
const monitoring = require('../utilities/monitoringHandler'); | ||
const { waterfall } = require('async'); | ||
|
||
const BucketLoggingStatusNotFoundBody = '<?xml version="1.0" encoding="UTF-8"?>\n' + | ||
'<BucketLoggingStatus xmlns="http://doc.s3.amazonaws.com/2006-03-01" />'; | ||
|
||
function bucketGetLogging(authInfo, request, log, callback) { | ||
log.debug('processing request', { method: 'bucketGetLogging' }); | ||
|
||
const bucketName = request.bucketName; | ||
const metadataValParams = { | ||
authInfo, | ||
bucketName, | ||
requestType: request.apiMethods || 'bucketGetLogging', | ||
request, | ||
}; | ||
|
||
return waterfall([ | ||
next => standardMetadataValidateBucket(metadataValParams, request.actionImplicitDenies, log, (err, bucket) => { | ||
if (err) { | ||
return next(err); | ||
} | ||
|
||
return next(null, bucket); | ||
}), | ||
(bucket, next) => checkExpectedBucketOwner(request.headers, bucket, log, err => { | ||
if (err) { | ||
return next(err); | ||
} | ||
|
||
return next(null, bucket); | ||
}), | ||
(bucket, next) => { | ||
const bucketLoggingStatus = bucket.getBucketLoggingStatus(); | ||
if (!bucketLoggingStatus) { | ||
return next(null, BucketLoggingStatusNotFoundBody); | ||
} | ||
|
||
return next(null, bucketLoggingStatus.toXML()); | ||
} | ||
], (err, body) => { | ||
if (err) { | ||
log.trace('error processing request', { error: err, method: 'bucketGetLogging' }); | ||
monitoring.promMetrics('GET', bucketName, err.code, 'bucketGetLogging'); | ||
return callback(err); | ||
} | ||
|
||
monitoring.promMetrics('GET', bucketName, '200', 'bucketGetLogging'); | ||
return callback(null, body); | ||
}); | ||
} | ||
|
||
module.exports = bucketGetLogging; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
const { waterfall } = require('async'); | ||
const { standardMetadataValidateBucket } = require('../metadata/metadataUtils'); | ||
const { checkExpectedBucketOwner } = require('./apiUtils/authorization/bucketOwner'); | ||
const BucketLoggingStatus = require('arsenal').models.BucketLoggingStatus; | ||
const metadata = require('../metadata/wrapper'); | ||
const monitoring = require('../utilities/monitoringHandler'); | ||
const { errorInstances } = require('arsenal'); | ||
|
||
function bucketPutLogging(authInfo, request, log, callback) { | ||
log.debug('processing request', { method: 'bucketPutLogging' }); | ||
|
||
const bucketName = request.bucketName; | ||
const parsed = BucketLoggingStatus.fromXML(request.post); | ||
if (parsed.error) { | ||
log.trace('error processing request', { error: parsed.error, method: 'bucketPutLogging' }); | ||
monitoring.promMetrics('PUT', bucketName, parsed.error.arsenalError, 'bucketPutLogging'); | ||
return callback(parsed.error.arsenalError); | ||
} | ||
|
||
const metadataValParams = { | ||
authInfo, | ||
bucketName, | ||
requestType: request.apiMethods || 'bucketPutLogging', | ||
request, | ||
}; | ||
|
||
return waterfall([ | ||
next => standardMetadataValidateBucket(metadataValParams, request.actionImplicitDenies, log, (err, bucket) => { | ||
if (err) { | ||
return next(err); | ||
} | ||
|
||
return next(null, bucket); | ||
}), | ||
(bucket, next) => { | ||
const loggingEnabled = parsed.res.getLoggingEnabled(); | ||
if (!loggingEnabled) { | ||
return next(null, bucket); | ||
} | ||
|
||
return metadata.getBucket(loggingEnabled.TargetBucket, log, err => { | ||
if (err) { | ||
return next(errorInstances.InvalidTargetBucketForLogging.customizeDescription(err.description)); | ||
} | ||
|
||
return next(null, bucket); | ||
}); | ||
}, | ||
(bucket, next) => checkExpectedBucketOwner(request.headers, bucket, log, err => { | ||
if (err) { | ||
return next(err); | ||
} | ||
|
||
return next(null, bucket); | ||
}), | ||
(bucket, next) => { | ||
bucket.setBucketLoggingStatus(parsed.res); | ||
return metadata.updateBucket(bucket.getName(), bucket, log, err => { | ||
if (err) { | ||
return next(err); | ||
} | ||
|
||
return next(); | ||
}); | ||
}, | ||
], err => { | ||
if (err) { | ||
log.trace('error processing request', { error: err, method: 'bucketPutLogging' }); | ||
monitoring.promMetrics('PUT', bucketName, err.code, 'bucketPutLogging'); | ||
return callback(err); | ||
} | ||
|
||
monitoring.promMetrics('PUT', bucketName, '200', 'bucketPutLogging'); | ||
return callback(); | ||
}); | ||
} | ||
|
||
module.exports = bucketPutLogging; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
tests/functional/aws-node-sdk/test/bucket/getBucketLogging.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
const assert = require('assert'); | ||
|
||
const withV4 = require('../support/withV4'); | ||
const BucketUtility = require('../../lib/utility/bucket-util'); | ||
|
||
const bucketName = 'testgetloggingbucket'; | ||
const targetBucket = 'testloggingtargetbucket'; | ||
|
||
const validLoggingConfig = { | ||
LoggingEnabled: { | ||
TargetBucket: targetBucket, | ||
TargetPrefix: 'logs/', | ||
}, | ||
}; | ||
|
||
describe('GET bucket logging', () => { | ||
withV4(sigCfg => { | ||
const bucketUtil = new BucketUtility('default', sigCfg); | ||
const s3 = bucketUtil.s3; | ||
|
||
afterEach(done => { | ||
process.stdout.write('Deleting buckets\n'); | ||
bucketUtil.deleteOne(bucketName).then(() => bucketUtil.deleteOne(targetBucket)).then(() => done()) | ||
.catch(err => { | ||
if (err && err.code !== 'NoSuchBucket') { | ||
return done(err); | ||
} | ||
return done(); | ||
}); | ||
}); | ||
|
||
describe('without existing bucket', () => { | ||
it('should return NoSuchBucket', done => { | ||
s3.getBucketLogging({ Bucket: bucketName }, err => { | ||
assert(err); | ||
assert.strictEqual(err.code, 'NoSuchBucket'); | ||
assert.strictEqual(err.statusCode, 404); | ||
return done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('on bucket without logging configuration', () => { | ||
before(done => { | ||
process.stdout.write('Creating bucket without logging\n'); | ||
s3.createBucket({ Bucket: bucketName }, err => { | ||
if (err) { | ||
process.stdout.write('error creating bucket', err); | ||
return done(err); | ||
} | ||
return done(); | ||
}); | ||
}); | ||
|
||
it('should return empty BucketLoggingStatus', done => { | ||
s3.getBucketLogging({ Bucket: bucketName }, (err, data) => { | ||
assert.strictEqual(err, null, | ||
`Found unexpected err ${err}`); | ||
// When no logging is configured, AWS returns empty object | ||
assert(data); | ||
assert.strictEqual(Object.keys(data).length, 0, 'Expected data to have no keys'); | ||
return done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('with existing logging configuration', () => { | ||
before(done => { | ||
process.stdout.write('Creating buckets and setting logging\n'); | ||
return s3.createBucket({ Bucket: bucketName }, err => { | ||
if (err) { | ||
return done(err); | ||
} | ||
return s3.createBucket({ Bucket: targetBucket }, err => { | ||
if (err) { | ||
return done(err); | ||
} | ||
return s3.putBucketLogging({ | ||
Bucket: bucketName, | ||
BucketLoggingStatus: validLoggingConfig, | ||
}, done); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should return bucket logging configuration successfully', done => { | ||
s3.getBucketLogging({ Bucket: bucketName }, (err, data) => { | ||
assert.strictEqual(err, null, | ||
`Found unexpected err ${err}`); | ||
assert(data.LoggingEnabled); | ||
assert.strictEqual(data.LoggingEnabled.TargetBucket, | ||
targetBucket); | ||
assert.strictEqual(data.LoggingEnabled.TargetPrefix, 'logs/'); | ||
return done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we check if the target bucket exists? Do you know if AWS returns an error if it does not exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An error occurred (InvalidTargetBucketForLogging) when calling the PutBucketLogging operation: The target bucket for logging does not exist
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added a check and functional tests