Skip to content

Commit b92dac5

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

15 files changed

+751
-654
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
import { S3Client, S3ClientConfig } from '@aws-sdk/client-s3';
3+
import { GetObjectAttributesExtendedCommand } from '@scality/cloudserverclient/commands/s3Extended';
4+
5+
const config: S3ClientConfig = {
6+
endpoint: 'http://localhost:8000',
7+
credentials: {
8+
accessKeyId: 'accessKey1',
9+
secretAccessKey: 'verySecretKey1',
10+
},
11+
region: 'us-east-1',
12+
};
13+
14+
const client = new S3Client(config);
15+
16+
const response = await client.send(
17+
new GetObjectAttributesExtendedCommand({
18+
Bucket: 'aBucketName',
19+
Key: 'anObjectKey',
20+
ObjectAttributes: ['ETag', 'ObjectSize', 'x-amz-meta-*'],
21+
}),
22+
);
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 & 217 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import {
2+
GetObjectAttributesCommand,
3+
GetObjectAttributesCommandInput,
4+
GetObjectAttributesCommandOutput,
5+
} from '@aws-sdk/client-s3';
6+
import {
7+
overrideObjectAttributesHeaderMiddleware,
8+
captureResponseBodyMiddleware,
9+
parseUserMetadataMiddleware,
10+
} from './utils';
11+
12+
export interface GetObjectAttributesExtendedInput extends Omit<GetObjectAttributesCommandInput, 'ObjectAttributes'> {
13+
ObjectAttributes: string[];
14+
}
15+
16+
export interface GetObjectAttributesExtendedOutput extends GetObjectAttributesCommandOutput {
17+
[key: `x-amz-meta-${string}`]: string;
18+
}
19+
20+
export class GetObjectAttributesExtendedCommand extends GetObjectAttributesCommand {
21+
constructor(input: GetObjectAttributesExtendedInput) {
22+
super(input as GetObjectAttributesCommandInput);
23+
24+
const captured = { xml: '' };
25+
26+
this.middlewareStack.add(overrideObjectAttributesHeaderMiddleware('x-amz-object-attributes', input.ObjectAttributes), {
27+
step: 'build',
28+
name: 'overrideObjectAttributesHeader',
29+
});
30+
31+
this.middlewareStack.add(captureResponseBodyMiddleware(captured), {
32+
step: 'deserialize',
33+
name: 'captureResponseBody',
34+
priority: 'low', // runs before SDK deserializer
35+
});
36+
37+
this.middlewareStack.add(parseUserMetadataMiddleware(captured), {
38+
step: 'deserialize',
39+
name: 'parseUserMetadata',
40+
priority: 'high', // runs after SDK deserializer
41+
});
42+
}
43+
}

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

0 commit comments

Comments
 (0)