Skip to content

feat(storage): multi bucket get properties api #5577

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
merged 23 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
13d6723
updating storage_outputs class for multi-bucket support
Sep 17, 2024
c5c0438
seperated bucket out into its own class instead of using a map
Sep 17, 2024
f22dd48
made bucket_output class a proper output class like the others in amp…
Sep 18, 2024
cc6c55b
Update auth.dart
ekjotmultani Sep 18, 2024
b6f8719
added doc comments and changed name of bucket class
Sep 18, 2024
66ad860
Merge branch 'storagewereoutput-update' of https://github.com/aws-amp…
Sep 18, 2024
3fc0ce9
Delete devtools_options.yaml
ekjotmultani Sep 18, 2024
9114206
added trailing commas to pass ci test
Sep 18, 2024
a17b602
Merge branch 'storage-output-update' of https://github.com/aws-amplif…
Sep 18, 2024
e7906c7
ran dart format on two failing files
Sep 18, 2024
6055a80
feat(core): add storage bucket type (#5478)
NikaHsn Sep 20, 2024
24089ae
Merge pull request #5476 from aws-amplify/storage-output-update
ekjotmultani Sep 23, 2024
d01d0df
updated resource.ts and backend.ts for multiple buckets in our infra-…
Sep 24, 2024
47c1371
updated resource.ts and backend.ts for multiple buckets in our infra-…
Sep 24, 2024
0d4e492
Merge pull request #5492 from aws-amplify/multi-bucket-infra-update
ekjotmultani Sep 24, 2024
d68bb03
feat(storage): update s3 storage service to support multiple s3 clien…
NikaHsn Sep 25, 2024
3eafd51
feat(storage): update uploadData API to accept optional storage bucke…
NikaHsn Oct 14, 2024
1becb6f
added bucket option to getProperties api
ekjotmultani Oct 18, 2024
3d717dd
added integration tests
ekjotmultani Oct 19, 2024
3a13b3d
removed the use of specific s3 bucket names and regions, moved testin…
ekjotmultani Oct 21, 2024
58ead62
added unauthiorized path test
ekjotmultani Oct 21, 2024
7de725c
Update packages/amplify_core/lib/src/types/storage/get_properties_opt…
ekjotmultani Oct 21, 2024
3bea1dc
Merge branch 'multi-bucket' into feat/multi-bucket-get-properties-api
ekjotmultani Oct 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class StorageCategory extends AmplifyCategory<StoragePluginInterface> {
data: data,
onProgress: onProgress,
options: options,
bucket: bucket,
),
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'package:aws_common/aws_common.dart';
import 'package:amplify_core/amplify_core.dart';

/// {@template amplify_core.storage.get_properties_options}
/// Configurable options for `Amplify.Storage.getProperties`.
Expand All @@ -14,20 +14,25 @@ class StorageGetPropertiesOptions
/// {@macro amplify_core.storage.get_properties_options}
const StorageGetPropertiesOptions({
this.pluginOptions,
this.bucket,
});

/// {@macro amplify_core.storage.download_get_properties_plugin_options}
final StorageGetPropertiesPluginOptions? pluginOptions;

/// Optionally specify which bucket to retrieve
final StorageBucket? bucket;

@override
List<Object?> get props => [pluginOptions];
List<Object?> get props => [pluginOptions, bucket];

@override
String get runtimeTypeName => 'StorageGetPropertiesOptions';

@override
Map<String, Object?> toJson() => {
'pluginOptions': pluginOptions?.toJson(),
'bucket': bucket,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,119 @@ void main() {
expect(result.storageItem.size, data.length);
});
});
group('multibucket config', () {
final mainBucket =
StorageBucket.fromOutputs('Storage Integ Test main bucket');
final secondaryBucket =
StorageBucket.fromOutputs('Storage Integ Test secondary bucket');
setUpAll(() async {
await configure(amplifyEnvironments['main']!);
addTearDownPath(StoragePath.fromString(path));
await Amplify.Storage.uploadData(
data: StorageDataPayload.bytes(data),
path: StoragePath.fromString(path),
options: const StorageUploadDataOptions(metadata: metadata),
bucket: mainBucket,
).result;
await Amplify.Storage.uploadData(
data: StorageDataPayload.bytes(data),
path: StoragePath.fromString(path),
options: const StorageUploadDataOptions(metadata: metadata),
bucket: secondaryBucket,
).result;
});

testWidgets('String StoragePath', (_) async {
final result = await Amplify.Storage.getProperties(
path: StoragePath.fromString(path),
options: StorageGetPropertiesOptions(
bucket: mainBucket,
),
).result;
expect(result.storageItem.path, path);
expect(result.storageItem.metadata, metadata);
expect(result.storageItem.eTag, isNotNull);
expect(result.storageItem.size, data.length);

final resultSecondaryBucket = await Amplify.Storage.getProperties(
path: StoragePath.fromString(path),
options: StorageGetPropertiesOptions(
bucket: secondaryBucket,
),
).result;
expect(resultSecondaryBucket.storageItem.path, path);
expect(resultSecondaryBucket.storageItem.metadata, metadata);
expect(resultSecondaryBucket.storageItem.eTag, isNotNull);
expect(resultSecondaryBucket.storageItem.size, data.length);
});

testWidgets('with identity ID', (_) async {
final userIdentityId = await signInNewUser();
final name = 'get-properties-with-identity-id-${uuid()}';
final data = 'with identity ID'.codeUnits;
final expectedResolvedPath = 'private/$userIdentityId/$name';
addTearDownPath(StoragePath.fromString(expectedResolvedPath));
await Amplify.Storage.uploadData(
data: StorageDataPayload.bytes(data),
path: StoragePath.fromString(expectedResolvedPath),
options: const StorageUploadDataOptions(metadata: metadata),
bucket: secondaryBucket,
).result;
final result = await Amplify.Storage.getProperties(
path: StoragePath.fromIdentityId(
((identityId) => 'private/$identityId/$name'),
),
options: StorageGetPropertiesOptions(
bucket: secondaryBucket,
),
).result;
expect(result.storageItem.path, expectedResolvedPath);
expect(result.storageItem.metadata, metadata);
expect(result.storageItem.eTag, isNotNull);
expect(result.storageItem.size, data.length);
});

testWidgets('not existent path', (_) async {
// we expect StorageNotFoundException here since there is no data uploaded to either bucket on this path
await expectLater(
() => Amplify.Storage.getProperties(
path: const StoragePath.fromString('public/not-existent-path'),
options: StorageGetPropertiesOptions(
bucket: mainBucket,
),
).result,
throwsA(isA<StorageNotFoundException>()),
);
await expectLater(
() => Amplify.Storage.getProperties(
path: const StoragePath.fromString('public/not-existent-path'),
options: StorageGetPropertiesOptions(
bucket: secondaryBucket,
),
).result,
throwsA(isA<StorageNotFoundException>()),
);
});
testWidgets('unauthorized path', (_) async {
await expectLater(
() => Amplify.Storage.getProperties(
path: const StoragePath.fromString('unauthorized/path'),
options: StorageGetPropertiesOptions(
bucket: mainBucket,
),
).result,
throwsA(isA<StorageAccessDeniedException>()),
);
await expectLater(
() => Amplify.Storage.getProperties(
path: const StoragePath.fromString('unauthorized/path'),
options: StorageGetPropertiesOptions(
bucket: secondaryBucket,
),
).result,
throwsA(isA<StorageAccessDeniedException>()),
);
});
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class AmplifyStorageS3Dart extends StoragePluginInterface

final s3Options = StorageGetPropertiesOptions(
pluginOptions: s3PluginOptions,
bucket: options?.bucket,
);

return S3GetPropertiesOperation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,12 @@ class StorageS3Service {
required StorageGetPropertiesOptions options,
}) async {
final resolvedPath = await _pathResolver.resolvePath(path: path);

final s3ClientInfo = getS3ClientInfo(storageBucket: options.bucket);
return S3GetPropertiesResult(
storageItem: S3Item.fromHeadObjectOutput(
await headObject(
s3client: _defaultS3Client,
bucket: _storageOutputs.bucketName,
bucket: s3ClientInfo.bucketName,
key: resolvedPath,
),
path: resolvedPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ void main() {
() async {
const testOptions = StorageGetPropertiesOptions(
pluginOptions: S3GetPropertiesPluginOptions(),
bucket: StorageBucket.fromBucketInfo(
BucketInfo(bucketName: 'unit-test-bucket', region: 'us-east-2'),
),
);

when(
Expand Down
Loading