Skip to content

Commit 5b92339

Browse files
committed
Split s3Extended into per-command files under src/commands
Issue: CLDSRVCLT-10
1 parent d46894c commit 5b92339

File tree

14 files changed

+727
-658
lines changed

14 files changed

+727
-658
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
import { S3Client, S3ClientConfig } from '@aws-sdk/client-s3';
3-
import { ListObjectsV2ExtendedCommand } from '@scality/cloudserverclient/clients/s3Extended';
3+
import { ListObjectsV2ExtendedCommand } from '@scality/cloudserverclient/commands/s3Extended';
44

55
const config: S3ClientConfig = {
66
endpoint: 'http://localhost:8000',

src/clients/s3Extended.ts

Lines changed: 0 additions & 219 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import {
2+
GetObjectAttributesCommand,
3+
GetObjectAttributesCommandInput,
4+
GetObjectAttributesCommandOutput,
5+
ObjectAttributes,
6+
} from '@aws-sdk/client-s3';
7+
import {
8+
overrideObjectAttributesHeaderMiddleware,
9+
captureResponseBodyMiddleware,
10+
parseUserMetadataMiddleware,
11+
} from './utils';
12+
13+
export interface GetObjectAttributesExtendedInput extends Omit<GetObjectAttributesCommandInput, 'ObjectAttributes'> {
14+
ObjectAttributes: (ObjectAttributes | `x-amz-meta-${string}`)[];
15+
}
16+
17+
export interface GetObjectAttributesExtendedOutput extends GetObjectAttributesCommandOutput {
18+
[key: `x-amz-meta-${string}`]: string;
19+
}
20+
21+
export class GetObjectAttributesExtendedCommand extends GetObjectAttributesCommand {
22+
constructor(input: GetObjectAttributesExtendedInput) {
23+
super(input as GetObjectAttributesCommandInput);
24+
25+
const captured = { xml: '' };
26+
27+
this.middlewareStack.add(
28+
overrideObjectAttributesHeaderMiddleware('x-amz-object-attributes', input.ObjectAttributes), {
29+
step: 'build',
30+
name: 'overrideObjectAttributesHeader',
31+
});
32+
33+
this.middlewareStack.add(captureResponseBodyMiddleware(captured), {
34+
step: 'deserialize',
35+
name: 'captureResponseBody',
36+
priority: 'low', // runs before SDK deserializer
37+
});
38+
39+
this.middlewareStack.add(parseUserMetadataMiddleware(captured), {
40+
step: 'deserialize',
41+
name: 'parseUserMetadata',
42+
priority: 'high', // runs after SDK deserializer
43+
});
44+
}
45+
}

src/commands/s3Extended/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from './listObjects';
2+
export * from './listObjectsV2';
3+
export * from './listObjectVersions';
4+
export * from './getObjectAttributes';
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { ListObjectVersionsCommand, ListObjectVersionsCommandInput } from '@aws-sdk/client-s3';
2+
import { extendCommandWithExtraParametersMiddleware } from './utils';
3+
4+
export interface ListObjectVersionsExtendedInput extends ListObjectVersionsCommandInput {
5+
Query: string;
6+
}
7+
8+
export class ListObjectVersionsExtendedCommand extends ListObjectVersionsCommand {
9+
constructor(input: ListObjectVersionsExtendedInput) {
10+
super(input);
11+
12+
this.middlewareStack.add(
13+
extendCommandWithExtraParametersMiddleware(input.Query),
14+
{ step: 'build', name: 'extendCommandWithExtraParameters' }
15+
);
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { ListObjectsCommand, ListObjectsCommandInput } from '@aws-sdk/client-s3';
2+
import { extendCommandWithExtraParametersMiddleware } from './utils';
3+
4+
export interface ListObjectsExtendedInput extends ListObjectsCommandInput {
5+
Query: string;
6+
}
7+
8+
export class ListObjectsExtendedCommand extends ListObjectsCommand {
9+
constructor(input: ListObjectsExtendedInput) {
10+
super(input);
11+
12+
this.middlewareStack.add(
13+
extendCommandWithExtraParametersMiddleware(input.Query),
14+
{ step: 'build', name: 'extendCommandWithExtraParameters' }
15+
);
16+
}
17+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import {
2+
ListObjectsV2Command,
3+
ListObjectsV2CommandInput,
4+
ListObjectsV2CommandOutput,
5+
OptionalObjectAttributes,
6+
_Object,
7+
} from '@aws-sdk/client-s3';
8+
import {
9+
extendCommandWithExtraParametersMiddleware,
10+
overrideObjectAttributesHeaderMiddleware,
11+
captureResponseBodyMiddleware,
12+
parseListObjectsUserMetadataMiddleware,
13+
} from './utils';
14+
15+
export interface ListObjectsV2ExtendedInput extends ListObjectsV2CommandInput {
16+
Query?: string;
17+
ObjectAttributes?: (OptionalObjectAttributes | `x-amz-meta-${string}`)[];
18+
}
19+
20+
export interface ListObjectsV2ExtendedContentEntry extends _Object {
21+
[key: `x-amz-meta-${string}`]: string;
22+
}
23+
24+
export interface ListObjectsV2ExtendedOutput extends ListObjectsV2CommandOutput {
25+
Contents?: ListObjectsV2ExtendedContentEntry[];
26+
}
27+
28+
export class ListObjectsV2ExtendedCommand extends ListObjectsV2Command {
29+
constructor(input: ListObjectsV2ExtendedInput) {
30+
super(input);
31+
32+
this.middlewareStack.add(
33+
extendCommandWithExtraParametersMiddleware(input.Query),
34+
{ step: 'build', name: 'extendCommandWithExtraParameters' }
35+
);
36+
37+
if (input.ObjectAttributes?.length) {
38+
const captured = { xml: '' };
39+
40+
this.middlewareStack.add(
41+
overrideObjectAttributesHeaderMiddleware(
42+
'x-amz-optional-object-attributes', input.ObjectAttributes), {
43+
step: 'build',
44+
name: 'overrideObjectAttributesHeader',
45+
});
46+
47+
this.middlewareStack.add(captureResponseBodyMiddleware(captured), {
48+
step: 'deserialize',
49+
name: 'captureResponseBody',
50+
priority: 'low',
51+
});
52+
53+
this.middlewareStack.add(parseListObjectsUserMetadataMiddleware(captured), {
54+
step: 'deserialize',
55+
name: 'parseUserMetadata',
56+
priority: 'high',
57+
});
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)