-
Notifications
You must be signed in to change notification settings - Fork 20
ARSN-528: add BucketLoggingStatus to BucketInfo model #2538
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 4 commits into
development/8.2
from
improvement/ARSN-528-add-bucketloggingstatus-model
Oct 14, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
74d6a45
ARSN-528: add BucketLoggingStatus to BucketInfo model
leif-scality cf9faaf
ARSN-528: bump BucketInfo modelVersion
leif-scality 6e35a3f
ARSN-528: add bucketPutLogging and bucketGetLogging route to lib/s3ro…
leif-scality 5f15fcb
ARSN-528: add GetBucketLogging and PutBucketLogging to lib/policyEval…
leif-scality 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
BourgoisMickael marked this conversation as resolved.
Show resolved
Hide resolved
|
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,193 @@ | ||
import { parseString } from 'xml2js'; | ||
import errors, { ArsenalError, errorInstances } from '../errors'; | ||
|
||
/** BucketLoggingStatus constants, not documented by AWS but found via testing */ | ||
const TARGET_BUCKET_MIN_LENGTH = 3; | ||
const TARGET_BUCKET_MAX_LENGTH = 255; | ||
const TARGET_PREFIX_MAX_LENGTH = 800; | ||
|
||
/** | ||
* Format of xml request: | ||
* https://docs.aws.amazon.com/AmazonS3/latest/API/API_LoggingEnabled.html | ||
* https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutBucketLogging.html | ||
* | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<BucketLoggingStatus xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> | ||
<LoggingEnabled> | ||
<TargetBucket>string</TargetBucket> | ||
<TargetGrants> | ||
<Grant> | ||
<Grantee> | ||
<DisplayName>string</DisplayName> | ||
<EmailAddress>string</EmailAddress> | ||
<ID>string</ID> | ||
<xsi:type>string</xsi:type> | ||
<URI>string</URI> | ||
</Grantee> | ||
<Permission>string</Permission> | ||
</Grant> | ||
</TargetGrants> | ||
<TargetObjectKeyFormat> | ||
<PartitionedPrefix> | ||
<PartitionDateSource>string</PartitionDateSource> | ||
</PartitionedPrefix> | ||
<SimplePrefix> | ||
</SimplePrefix> | ||
</TargetObjectKeyFormat> | ||
<TargetPrefix>string</TargetPrefix> | ||
</LoggingEnabled> | ||
</BucketLoggingStatus> | ||
*/ | ||
|
||
export type LoggingEnabled = { | ||
TargetBucket: string; | ||
TargetPrefix: string; | ||
BourgoisMickael marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// TargetGrants and TargetObjectKeyFormat are not implemented. | ||
}; | ||
|
||
export default class BucketLoggingStatus { | ||
private _loggingEnabled?: LoggingEnabled; | ||
|
||
constructor(loggingEnabled?: LoggingEnabled) { | ||
this._loggingEnabled = loggingEnabled; | ||
} | ||
|
||
getLoggingEnabled(): LoggingEnabled | undefined { | ||
return this._loggingEnabled; | ||
} | ||
|
||
toXML(): string { | ||
let loggingEnabledXML = ""; | ||
if (this._loggingEnabled) { | ||
loggingEnabledXML = `<LoggingEnabled> | ||
<TargetBucket>${this._loggingEnabled.TargetBucket}</TargetBucket> | ||
<TargetPrefix>${this._loggingEnabled.TargetPrefix}</TargetPrefix> | ||
</LoggingEnabled> | ||
`; | ||
} | ||
|
||
return `<?xml version="1.0" encoding="UTF-8"?> | ||
<BucketLoggingStatus xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> | ||
${loggingEnabledXML} | ||
</BucketLoggingStatus> | ||
`; | ||
} | ||
|
||
static fromXML( | ||
data: string, | ||
): { error?: { arsenalError: ArsenalError, details: any }; res?: BucketLoggingStatus; } { | ||
let parsed, parseError; | ||
|
||
try { | ||
parseString(data, (err: any, res: any) => { | ||
parseError = err; | ||
parsed = res; | ||
}); | ||
|
||
if (parseError) { | ||
return { | ||
error: { arsenalError: errors.MalformedXML, details: parseError }, | ||
}; | ||
} | ||
} catch (err) { | ||
return { | ||
error: { arsenalError: errors.MalformedXML, details: err }, | ||
}; | ||
} | ||
|
||
if (!parsed) { | ||
return { | ||
error: { arsenalError: errors.MalformedXML, details: 'request xml is undefined or empty' }, | ||
}; | ||
} | ||
|
||
if (!parsed.BucketLoggingStatus) { | ||
return { | ||
error: { arsenalError: errors.MalformedXML, details: 'missing BucketLoggingStatus root' }, | ||
}; | ||
} | ||
|
||
let loggingEnabled: LoggingEnabled | undefined = undefined; | ||
if (parsed.BucketLoggingStatus.LoggingEnabled) { | ||
const loggingEnabledData = parsed.BucketLoggingStatus.LoggingEnabled[0]; | ||
|
||
if ( | ||
!Object.prototype.hasOwnProperty.call(loggingEnabledData, 'TargetBucket') || | ||
loggingEnabledData.TargetBucket === null || | ||
loggingEnabledData.TargetBucket === undefined | ||
) { | ||
return { | ||
error: { | ||
arsenalError: errors.MalformedXML, | ||
details: 'missing TargetBucket field in LoggingEnabled', | ||
}, | ||
}; | ||
} else if (loggingEnabledData.TargetBucket[0].length < TARGET_BUCKET_MIN_LENGTH) { | ||
return { | ||
error: { | ||
arsenalError: errors.InvalidBucketName, | ||
details: `TargetBucket field length < ${TARGET_BUCKET_MIN_LENGTH}`, | ||
}, | ||
}; | ||
} else if (loggingEnabledData.TargetBucket[0].length > TARGET_BUCKET_MAX_LENGTH) { | ||
return { | ||
error: { | ||
arsenalError: errors.InvalidBucketName, | ||
details: `TargetBucket field length > ${TARGET_BUCKET_MAX_LENGTH}`, | ||
}, | ||
}; | ||
} | ||
|
||
if ( | ||
!Object.prototype.hasOwnProperty.call(loggingEnabledData, 'TargetPrefix') || | ||
loggingEnabledData.TargetPrefix === null || | ||
loggingEnabledData.TargetPrefix === undefined | ||
) { | ||
return { | ||
error: { | ||
arsenalError: errors.MalformedXML, | ||
details: 'missing TargetPrefix field in LoggingEnabled', | ||
}, | ||
}; | ||
} else if (loggingEnabledData.TargetPrefix[0].length > TARGET_PREFIX_MAX_LENGTH) { | ||
return { | ||
error: { | ||
arsenalError: errorInstances.InvalidArgument | ||
.customizeDescription(`Field exceeds ${TARGET_PREFIX_MAX_LENGTH} bytes`) | ||
.addMetadataEntry('invalidArguments', | ||
[{ ArgumentName: 'TargetPrefix', ArgumentValue: loggingEnabledData.TargetPrefix[0] }]), | ||
details: `TargetPrefix field length > ${TARGET_PREFIX_MAX_LENGTH}`, | ||
}, | ||
}; | ||
} | ||
|
||
if (loggingEnabledData.TargetGrants) { | ||
return { | ||
error: { | ||
arsenalError: errors.NotImplemented, | ||
details: 'TargetGrants field in LoggingEnabled is not implemented', | ||
}, | ||
}; | ||
} | ||
|
||
if (loggingEnabledData.TargetObjectKeyFormat) { | ||
return { | ||
error: { | ||
arsenalError: errors.NotImplemented, | ||
details: 'TargetObjectKeyFormat field in LoggingEnabled is not implemented', | ||
}, | ||
}; | ||
} | ||
|
||
loggingEnabled = { | ||
TargetBucket: loggingEnabledData.TargetBucket[0], | ||
TargetPrefix: loggingEnabledData.TargetPrefix[0], | ||
}; | ||
} | ||
|
||
return { | ||
error: undefined, | ||
res: new BucketLoggingStatus(loggingEnabled), | ||
}; | ||
} | ||
}; |
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
BourgoisMickael marked this conversation as resolved.
Show resolved
Hide resolved
|
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
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.
Uh oh!
There was an error while loading. Please reload this page.