-
Notifications
You must be signed in to change notification settings - Fork 0
Extend GetObjectAttributes and ListObjectsV2 with user metadata support #13
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
Open
maeldonn
wants to merge
5
commits into
development/1.0
Choose a base branch
from
improvement/CLDSRVCLT-10/user-metadata
base: development/1.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+729
−203
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1bba0e7
Extend basic command for GetObjectAttributes
maeldonn d46894c
Extend basic command for ListObjectV2
maeldonn 5b92339
Split s3Extended into per-command files under src/commands
maeldonn 4c958c7
Update cloudserver docker image version
maeldonn 5eaa299
Bump package.json to 1.0.5
maeldonn 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 |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "name": "@scality/cloudserverclient", | ||
| "version": "1.0.4", | ||
| "version": "1.0.5", | ||
| "engines": { | ||
| "node": ">=20" | ||
| }, | ||
|
|
||
This file was deleted.
Oops, something went wrong.
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,45 @@ | ||
| import { | ||
| GetObjectAttributesCommand, | ||
| GetObjectAttributesCommandInput, | ||
| GetObjectAttributesCommandOutput, | ||
| ObjectAttributes, | ||
| } from '@aws-sdk/client-s3'; | ||
| import { | ||
| overrideObjectAttributesHeaderMiddleware, | ||
| captureResponseBodyMiddleware, | ||
| parseUserMetadataMiddleware, | ||
| } from './utils'; | ||
|
|
||
| export interface GetObjectAttributesExtendedInput extends Omit<GetObjectAttributesCommandInput, 'ObjectAttributes'> { | ||
| ObjectAttributes: (ObjectAttributes | `x-amz-meta-${string}`)[]; | ||
| } | ||
|
|
||
| export interface GetObjectAttributesExtendedOutput extends GetObjectAttributesCommandOutput { | ||
| [key: `x-amz-meta-${string}`]: string; | ||
| } | ||
|
|
||
| export class GetObjectAttributesExtendedCommand extends GetObjectAttributesCommand { | ||
| constructor(input: GetObjectAttributesExtendedInput) { | ||
| super(input as GetObjectAttributesCommandInput); | ||
|
|
||
| const captured = { xml: '' }; | ||
|
|
||
| this.middlewareStack.add( | ||
| overrideObjectAttributesHeaderMiddleware('x-amz-object-attributes', input.ObjectAttributes), { | ||
| step: 'build', | ||
| name: 'overrideObjectAttributesHeader', | ||
| }); | ||
|
|
||
| this.middlewareStack.add(captureResponseBodyMiddleware(captured), { | ||
| step: 'deserialize', | ||
| name: 'captureResponseBody', | ||
| priority: 'low', // runs before SDK deserializer | ||
| }); | ||
|
|
||
| this.middlewareStack.add(parseUserMetadataMiddleware(captured), { | ||
| step: 'deserialize', | ||
| name: 'parseUserMetadata', | ||
| priority: 'high', // runs after SDK deserializer | ||
| }); | ||
| } | ||
| } |
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,4 @@ | ||
| export * from './listObjects'; | ||
| export * from './listObjectsV2'; | ||
| export * from './listObjectVersions'; | ||
| export * from './getObjectAttributes'; |
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,17 @@ | ||
| import { ListObjectVersionsCommand, ListObjectVersionsCommandInput } from '@aws-sdk/client-s3'; | ||
| import { extendCommandWithExtraParametersMiddleware } from './utils'; | ||
|
|
||
| export interface ListObjectVersionsExtendedInput extends ListObjectVersionsCommandInput { | ||
| Query: string; | ||
| } | ||
|
|
||
| export class ListObjectVersionsExtendedCommand extends ListObjectVersionsCommand { | ||
| constructor(input: ListObjectVersionsExtendedInput) { | ||
| super(input); | ||
|
|
||
| this.middlewareStack.add( | ||
| extendCommandWithExtraParametersMiddleware(input.Query), | ||
| { step: 'build', name: 'extendCommandWithExtraParameters' } | ||
| ); | ||
| } | ||
| } |
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,17 @@ | ||
| import { ListObjectsCommand, ListObjectsCommandInput } from '@aws-sdk/client-s3'; | ||
| import { extendCommandWithExtraParametersMiddleware } from './utils'; | ||
|
|
||
| export interface ListObjectsExtendedInput extends ListObjectsCommandInput { | ||
| Query: string; | ||
| } | ||
|
|
||
| export class ListObjectsExtendedCommand extends ListObjectsCommand { | ||
| constructor(input: ListObjectsExtendedInput) { | ||
| super(input); | ||
|
|
||
| this.middlewareStack.add( | ||
| extendCommandWithExtraParametersMiddleware(input.Query), | ||
| { step: 'build', name: 'extendCommandWithExtraParameters' } | ||
| ); | ||
| } | ||
| } |
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,60 @@ | ||
| import { | ||
| ListObjectsV2Command, | ||
| ListObjectsV2CommandInput, | ||
| ListObjectsV2CommandOutput, | ||
| OptionalObjectAttributes, | ||
| _Object, | ||
| } from '@aws-sdk/client-s3'; | ||
| import { | ||
| extendCommandWithExtraParametersMiddleware, | ||
| overrideObjectAttributesHeaderMiddleware, | ||
| captureResponseBodyMiddleware, | ||
| parseListObjectsUserMetadataMiddleware, | ||
| } from './utils'; | ||
|
|
||
| export interface ListObjectsV2ExtendedInput extends ListObjectsV2CommandInput { | ||
| Query?: string; | ||
| ObjectAttributes?: (OptionalObjectAttributes | `x-amz-meta-${string}`)[]; | ||
| } | ||
|
|
||
| export interface ListObjectsV2ExtendedContentEntry extends _Object { | ||
| [key: `x-amz-meta-${string}`]: string; | ||
| } | ||
|
|
||
| export interface ListObjectsV2ExtendedOutput extends ListObjectsV2CommandOutput { | ||
| Contents?: ListObjectsV2ExtendedContentEntry[]; | ||
| } | ||
|
|
||
| export class ListObjectsV2ExtendedCommand extends ListObjectsV2Command { | ||
| constructor(input: ListObjectsV2ExtendedInput) { | ||
| super(input); | ||
|
|
||
| this.middlewareStack.add( | ||
| extendCommandWithExtraParametersMiddleware(input.Query), | ||
| { step: 'build', name: 'extendCommandWithExtraParameters' } | ||
| ); | ||
|
|
||
| if (input.ObjectAttributes?.length) { | ||
| const captured = { xml: '' }; | ||
|
|
||
| this.middlewareStack.add( | ||
| overrideObjectAttributesHeaderMiddleware( | ||
| 'x-amz-optional-object-attributes', input.ObjectAttributes), { | ||
| step: 'build', | ||
| name: 'overrideObjectAttributesHeader', | ||
| }); | ||
|
|
||
| this.middlewareStack.add(captureResponseBodyMiddleware(captured), { | ||
| step: 'deserialize', | ||
| name: 'captureResponseBody', | ||
| priority: 'low', | ||
| }); | ||
|
|
||
| this.middlewareStack.add(parseListObjectsUserMetadataMiddleware(captured), { | ||
| step: 'deserialize', | ||
| name: 'parseUserMetadata', | ||
| priority: 'high', | ||
| }); | ||
| } | ||
| } | ||
| } |
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,87 @@ | ||
| import { Readable } from 'stream'; | ||
| import { streamCollector } from '@smithy/node-http-handler'; | ||
| import { XMLParser } from 'fast-xml-parser'; | ||
|
|
||
| export const USER_METADATA_PREFIX = 'x-amz-meta-'; | ||
|
|
||
|
|
||
| export function extendCommandWithExtraParametersMiddleware(query: string) { | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| return (next: any) => async (args: any) => { | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| const request = args.request as any; | ||
| if (request.query) { | ||
| request.query.search = query; | ||
| } else { | ||
| request.query = { search: query }; | ||
| } | ||
| return next(args); | ||
| }; | ||
| } | ||
|
|
||
|
|
||
| export function overrideObjectAttributesHeaderMiddleware(headerName: string, attributes: string[]) { | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| return (next: any) => async (args: any) => { | ||
| const request = args.request; | ||
| request.headers[headerName] = attributes.join(','); | ||
| return next(args); | ||
| }; | ||
| } | ||
|
|
||
| export function captureResponseBodyMiddleware(captured: { xml: string }) { | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| return (next: any) => async (args: any) => { | ||
| const { response } = await next(args); | ||
|
|
||
| if (response?.body) { | ||
| const collected = await streamCollector(response.body); | ||
| const buffer = Buffer.from(collected); | ||
| // eslint-disable-next-line no-param-reassign | ||
| captured.xml = buffer.toString('utf-8'); | ||
| // Re-create the body stream so the SDK deserializer can still consume it | ||
| response.body = Readable.from([buffer]); | ||
| } | ||
|
|
||
| return { response }; | ||
| }; | ||
| } | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| export function extractUserMetadata(source: Record<string, any>, target: Record<string, string>): void { | ||
| for (const [key, value] of Object.entries(source)) { | ||
| if (key.startsWith(USER_METADATA_PREFIX)) { | ||
| // eslint-disable-next-line no-param-reassign | ||
| target[key] = String(value); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export function parseUserMetadataMiddleware(captured: { xml: string }) { | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| return (next: any) => async (args: any) => { | ||
| const result = await next(args); | ||
| const parsed = new XMLParser().parse(captured.xml); | ||
| const response = parsed?.GetObjectAttributesResponse; | ||
| if (response) { | ||
| extractUserMetadata(response, result.output); | ||
| } | ||
| return result; | ||
| }; | ||
| } | ||
|
|
||
|
|
||
| export function parseListObjectsUserMetadataMiddleware(captured: { xml: string }) { | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| return (next: any) => async (args: any) => { | ||
| const result = await next(args); | ||
| const parsed = new XMLParser().parse(captured.xml); | ||
| const xmlContents = parsed?.ListBucketResult?.Contents; | ||
| if (result.output.Contents && xmlContents) { | ||
| for (let i = 0; i < result.output.Contents.length; i++) { | ||
| extractUserMetadata(xmlContents[i], result.output.Contents[i]); | ||
| } | ||
| } | ||
| return result; | ||
| }; | ||
| } | ||
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 |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| export * from './clients/backbeatRoutes'; | ||
| export * from './clients/bucketQuota'; | ||
| export * from './clients/proxyBackbeatApis'; | ||
| export * from './clients/s3Extended'; | ||
| export * from './commands/s3Extended'; | ||
| export { CloudserverClient, CloudserverClientConfig } from './clients/cloudserver'; | ||
| export * from './utils'; |
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.