Skip to content
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

feat(core): update storage outputs class for multi-bucket support #5476

Open
wants to merge 10 commits into
base: multi-bucket
Choose a base branch
from
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'package:amplify_core/amplify_core.dart';

part 'bucket_output.g.dart';

@zAmplifyOutputsSerializable
class BucketOutput
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class BucketOutput
class BucketOutputs

with AWSEquatable<BucketOutput>, AWSSerializable, AWSDebuggable{

const BucketOutput({required this.name, required this.bucketName, required this.awsRegion});

factory BucketOutput.fromJson(Map<String, Object?> json) =>
_$BucketOutputFromJson(json);

final String name;

final String bucketName;

final String awsRegion;

@override
List<Object?> get props => [
name,
bucketName,
awsRegion,
];

@override
String get runtimeTypeName => 'BucketOutput';

@override
Object? toJson() {
return _$BucketOutputToJson(this);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import 'package:amplify_core/amplify_core.dart';
import 'package:amplify_core/src/config/amplify_outputs/storage/bucket_output.dart';

part 'storage_outputs.g.dart';

Expand All @@ -12,7 +13,8 @@ part 'storage_outputs.g.dart';
class StorageOutputs
with AWSEquatable<StorageOutputs>, AWSSerializable, AWSDebuggable {
/// {@macro amplify_core.amplify_outputs.storage_outputs}
const StorageOutputs({required this.awsRegion, required this.bucketName});
const StorageOutputs({required this.awsRegion, required this.bucketName, this.buckets});


factory StorageOutputs.fromJson(Map<String, Object?> json) =>
_$StorageOutputsFromJson(json);
Expand All @@ -23,8 +25,11 @@ class StorageOutputs
/// The Amazon S3 bucket name.
final String bucketName;

/// The list of buckets if there are multiple buckets for the project
final List<BucketOutput>? buckets;

@override
List<Object?> get props => [awsRegion, bucketName];
List<Object?> get props => [awsRegion, bucketName, buckets];

@override
String get runtimeTypeName => 'StorageOutputs';
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: I see the test data has been updated, but are the tests written in a way that validate the new functionality too? Do they need to be updated?

Copy link
Author

@ekjotmultani ekjotmultani Sep 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good question, since multiple buckets are optional, I think we should validate that it works when only one bucket is supplied too. I'll check this out

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've verified that the test does work properly when only a single bucket is supplied and that the test itself actually validates the new function for multi-bucket support

Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,26 @@ const amplifyoutputs = '''{
]
},
"storage": {
"aws_region": "oem dks",
"bucket_name": "dolor et esse"
},
"aws_region": "us-east-2",
"bucket_name": "amplifyTeamDrive-one-stora-testbucketgen2bucket0b8c-9ggcfqfunkjr",
"buckets": [
{
"name": "amplifyTeamDrive-one",
"bucket_name": "amplifyTeamDrive-one-stora-testbucketgen2bucket0b8c-9ggcfqfunkjr",
"aws_region": "us-east-2"
},
{
"name": "amplifyTeamDrive-two",
"bucket_name": "amplifyTeamDrive-two-stora-testbucketgen2bucket0b8c-2",
"aws_region": "us-east-2"
},
{
"name": "amplifyTeamDrive-three",
"bucket_name": "amplifyTeamDrive-three-stora-testbucketgen2bucket0b8c-3",
"aws_region": "us-east-2"
}
]
},
"version": "1"
}
''';
Loading