Skip to content

Commit

Permalink
rename s3PluginConfig to storageOutputs
Browse files Browse the repository at this point in the history
  • Loading branch information
Nika Hassani committed Jun 19, 2024
1 parent 6639f78 commit e62a64a
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class AmplifyStorageS3Dart extends StoragePluginInterface

/// The [StorageOutputs] of the [AmplifyStorageS3Dart] plugin.
@protected
late final StorageOutputs s3pluginConfig;
late final StorageOutputs storageOutputs;

late S3PathResolver _pathResolver;

Expand All @@ -65,12 +65,10 @@ class AmplifyStorageS3Dart extends StoragePluginInterface
AmplifyOutputs? config,
required AmplifyAuthProviderRepository authProviderRepo,
}) async {
final s3PluginConfig = config?.storage;

if (s3PluginConfig == null) {
if (config?.storage == null) {
throw ConfigurationError('No Storage S3 plugin config detected.');
}
s3pluginConfig = s3PluginConfig;
storageOutputs = config!.storage!;

final identityProvider = authProviderRepo
.getAuthProvider(APIAuthorizationType.userPools.authProviderToken);
Expand Down Expand Up @@ -109,7 +107,7 @@ class AmplifyStorageS3Dart extends StoragePluginInterface
..addInstance<StorageS3Service>(
StorageS3Service(
credentialsProvider: credentialsProvider,
s3PluginConfig: s3PluginConfig,
storageOutputs: storageOutputs,
pathResolver: _pathResolver,
logger: logger,
dependencyManager: dependencies,
Expand Down Expand Up @@ -263,7 +261,7 @@ class AmplifyStorageS3Dart extends StoragePluginInterface
path: path,
localFile: localFile,
options: options,
s3pluginConfig: s3pluginConfig,
storageOutputs: storageOutputs,
storageS3Service: storageS3Service,
appPathProvider: _appPathProvider,
onProgress: onProgress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ S3DownloadFileOperation downloadFile({
required StoragePath path,
required AWSFile localFile,
required StorageDownloadFileOptions options,
required StorageOutputs s3pluginConfig,
required StorageOutputs storageOutputs,
required StorageS3Service storageS3Service,
required AppPathProvider appPathProvider,
void Function(S3TransferProgress)? onProgress,
Expand All @@ -30,7 +30,7 @@ S3DownloadFileOperation downloadFile({
path: path,
localFile: localFile,
options: options,
s3pluginConfig: s3pluginConfig,
storageOutputs: storageOutputs,
storageS3Service: storageS3Service,
),
// In Web the download process is managed by the browser so the operation
Expand All @@ -45,7 +45,7 @@ Future<S3DownloadFileResult> _downloadFromUrl({
required StoragePath path,
required AWSFile localFile,
required StorageDownloadFileOptions options,
required StorageOutputs s3pluginConfig,
required StorageOutputs storageOutputs,
required StorageS3Service storageS3Service,
}) async {
final s3PluginOptions = options.pluginOptions as S3DownloadFilePluginOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ S3DownloadFileOperation downloadFile({
required StoragePath path,
required AWSFile localFile,
required StorageDownloadFileOptions options,
required StorageOutputs s3pluginConfig,
required StorageOutputs storageOutputs,
required StorageS3Service storageS3Service,
required AppPathProvider appPathProvider,
void Function(S3TransferProgress)? onProgress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ S3DownloadFileOperation downloadFile({
required StoragePath path,
required AWSFile localFile,
required StorageDownloadFileOptions options,
required StorageOutputs s3pluginConfig,
required StorageOutputs storageOutputs,
required StorageS3Service storageS3Service,
required AppPathProvider appPathProvider,
void Function(S3TransferProgress)? onProgress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ const testDateTimeNowOverride = #_testDateTimeNowOverride;
class StorageS3Service {
/// {@macro amplify_storage_s3.storage_s3_service}
factory StorageS3Service({
required StorageOutputs s3PluginConfig,
required StorageOutputs storageOutputs,
required S3PathResolver pathResolver,
required AWSIamAmplifyAuthProvider credentialsProvider,
required AWSLogger logger,
required DependencyManager dependencyManager,
}) {
final usePathStyle = s3PluginConfig.bucketName.contains('.');
final usePathStyle = storageOutputs.bucketName.contains('.');

if (usePathStyle) {
logger.warn(
Expand All @@ -56,7 +56,7 @@ class StorageS3Service {
);

return StorageS3Service._(
s3PluginConfig: s3PluginConfig,
storageOutputs: storageOutputs,
s3ClientConfig: s3ClientConfig,
pathResolver: pathResolver,
credentialsProvider: credentialsProvider,
Expand All @@ -66,18 +66,18 @@ class StorageS3Service {
}

StorageS3Service._({
required StorageOutputs s3PluginConfig,
required StorageOutputs storageOutputs,
required smithy_aws.S3ClientConfig s3ClientConfig,
required S3PathResolver pathResolver,
required AWSIamAmplifyAuthProvider credentialsProvider,
required AWSLogger logger,
required DependencyManager dependencyManager,
}) : _s3PluginConfig = s3PluginConfig,
}) : _storageOutptus = storageOutputs,
_defaultS3ClientConfig = s3ClientConfig,
// dependencyManager.get() => S3Client is used for unit tests
_defaultS3Client = dependencyManager.get() ??
s3.S3Client(
region: s3PluginConfig.awsRegion,
region: storageOutputs.awsRegion,
credentialsProvider: credentialsProvider,
s3ClientConfig: s3ClientConfig,
client: AmplifyHttpClient(dependencyManager)
Expand All @@ -96,7 +96,7 @@ class StorageS3Service {
static final _defaultS3SignerConfiguration =
sigv4.S3ServiceConfiguration(signPayload: false);

final StorageOutputs _s3PluginConfig;
final StorageOutputs _storageOutptus;
final smithy_aws.S3ClientConfig _defaultS3ClientConfig;
final s3.S3Client _defaultS3Client;
final S3PathResolver _pathResolver;
Expand All @@ -106,7 +106,7 @@ class StorageS3Service {
final DateTime _serviceStartingTime;

sigv4.AWSCredentialScope get _signerScope => sigv4.AWSCredentialScope(
region: _s3PluginConfig.awsRegion,
region: _storageOutptus.awsRegion,
service: AWSService.s3,
);

Expand Down Expand Up @@ -134,7 +134,7 @@ class StorageS3Service {
if (!s3PluginOptions.listAll) {
final request = s3.ListObjectsV2Request.build((builder) {
builder
..bucket = _s3PluginConfig.bucketName
..bucket = _storageOutptus.bucketName
..prefix = resolvedPath
..maxKeys = options.pageSize
..continuationToken = options.nextToken
Expand All @@ -161,7 +161,7 @@ class StorageS3Service {
try {
final request = s3.ListObjectsV2Request.build((builder) {
builder
..bucket = _s3PluginConfig.bucketName
..bucket = _storageOutptus.bucketName
..prefix = resolvedPath
..delimiter = s3PluginOptions.excludeSubPaths
? s3PluginOptions.delimiter
Expand Down Expand Up @@ -207,7 +207,7 @@ class StorageS3Service {
storageItem: S3Item.fromHeadObjectOutput(
await headObject(
s3client: _defaultS3Client,
bucket: _s3PluginConfig.bucketName,
bucket: _storageOutptus.bucketName,
key: resolvedPath,
),
path: resolvedPath,
Expand Down Expand Up @@ -244,14 +244,14 @@ class StorageS3Service {

var resolvedPath = await _pathResolver.resolvePath(path: path);
var host =
'${_s3PluginConfig.bucketName}.${_getS3EndpointHost(region: _s3PluginConfig.awsRegion)}';
'${_storageOutptus.bucketName}.${_getS3EndpointHost(region: _storageOutptus.awsRegion)}';
if (_defaultS3ClientConfig.usePathStyle) {
host = host.replaceFirst('${_s3PluginConfig.bucketName}.', '');
resolvedPath = '${_s3PluginConfig.bucketName}/$resolvedPath';
host = host.replaceFirst('${_storageOutptus.bucketName}.', '');
resolvedPath = '${_storageOutptus.bucketName}/$resolvedPath';
} else if (s3PluginOptions.useAccelerateEndpoint) {
// https: //docs.aws.amazon.com/AmazonS3/latest/userguide/transfer-acceleration-getting-started.html
host = host
.replaceFirst(RegExp('${_s3PluginConfig.awsRegion}\\.'), '')
.replaceFirst(RegExp('${_storageOutptus.awsRegion}\\.'), '')
.replaceFirst(RegExp(r'\.s3\.'), '.s3-accelerate.');
}

Expand Down Expand Up @@ -297,7 +297,7 @@ class StorageS3Service {
final downloadDataTask = S3DownloadTask(
s3Client: _defaultS3Client,
defaultS3ClientConfig: _defaultS3ClientConfig,
bucket: _s3PluginConfig.bucketName,
bucket: _storageOutptus.bucketName,
path: path,
options: options,
pathResolver: _pathResolver,
Expand Down Expand Up @@ -328,7 +328,7 @@ class StorageS3Service {
dataPayload,
s3Client: _defaultS3Client,
defaultS3ClientConfig: _defaultS3ClientConfig,
bucket: _s3PluginConfig.bucketName,
bucket: _storageOutptus.bucketName,
path: path,
options: options,
pathResolver: _pathResolver,
Expand Down Expand Up @@ -367,7 +367,7 @@ class StorageS3Service {
localFile,
s3Client: _defaultS3Client,
defaultS3ClientConfig: _defaultS3ClientConfig,
bucket: _s3PluginConfig.bucketName,
bucket: _storageOutptus.bucketName,
path: path,
options: uploadDataOptions,
pathResolver: _pathResolver,
Expand Down Expand Up @@ -407,8 +407,8 @@ class StorageS3Service {

final copyRequest = s3.CopyObjectRequest.build((builder) {
builder
..bucket = _s3PluginConfig.bucketName
..copySource = '${_s3PluginConfig.bucketName}/$sourcePath'
..bucket = _storageOutptus.bucketName
..copySource = '${_storageOutptus.bucketName}/$sourcePath'
..key = destinationPath
..metadataDirective = s3.MetadataDirective.copy;
});
Expand All @@ -427,7 +427,7 @@ class StorageS3Service {
? S3Item.fromHeadObjectOutput(
await headObject(
s3client: _defaultS3Client,
bucket: _s3PluginConfig.bucketName,
bucket: _storageOutptus.bucketName,
key: destinationPath,
),
path: destinationPath,
Expand All @@ -451,7 +451,7 @@ class StorageS3Service {

await _deleteObject(
s3client: _defaultS3Client,
bucket: _s3PluginConfig.bucketName,
bucket: _storageOutptus.bucketName,
key: resolvedPath,
);

Expand Down Expand Up @@ -491,7 +491,7 @@ class StorageS3Service {
);
final request = s3.DeleteObjectsRequest.build((builder) {
builder
..bucket = _s3PluginConfig.bucketName
..bucket = _storageOutptus.bucketName
// force to use sha256 instead of md5
..checksumAlgorithm = s3.ChecksumAlgorithm.sha256
..delete = s3.Delete.build((builder) {
Expand Down Expand Up @@ -598,7 +598,7 @@ class StorageS3Service {
for (final record in records) {
final request = s3.AbortMultipartUploadRequest.build((builder) {
builder
..bucket = _s3PluginConfig.bucketName
..bucket = _storageOutptus.bucketName
..key = record.objectKey
..uploadId = record.uploadId;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void main() {
group('downloadFile() html implementation', () {
late StorageS3Service storageS3Service;
const testKey = 'upload-key.text';
const testS3pluginConfig = StorageOutputs(
const testStorageOutputs = StorageOutputs(
bucketName: 'fake-bucket',
awsRegion: 'west-2',
);
Expand Down Expand Up @@ -91,7 +91,7 @@ void main() {
path: const StoragePath.fromString('public/$testKey'),
localFile: AWSFile.fromPath('file_name.jpg'),
options: const StorageDownloadFileOptions(),
s3pluginConfig: testS3pluginConfig,
storageOutputs: testStorageOutputs,
storageS3Service: storageS3Service,
appPathProvider: const DummyPathProvider(),
);
Expand Down Expand Up @@ -130,7 +130,7 @@ void main() {
),
localFile: AWSFile.fromPath('download.jpg'),
options: options,
s3pluginConfig: testS3pluginConfig,
storageOutputs: testStorageOutputs,
storageS3Service: storageS3Service,
appPathProvider: const DummyPathProvider(),
).result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void main() {
late FutureOr<void> Function() onDone;
const appPathProvider = S3DartAppPathProvider();
final testDestinationPath = path.join(Directory.current.path, 'test.txt');
const testS3pluginConfig = StorageOutputs(
const testStorageOutputs = StorageOutputs(
bucketName: 'fake-bucket',
awsRegion: 'west-2',
);
Expand Down Expand Up @@ -84,7 +84,7 @@ void main() {
),
localFile: AWSFile.fromPath(testDestinationPath),
options: options,
s3pluginConfig: testS3pluginConfig,
storageOutputs: testStorageOutputs,
storageS3Service: storageS3Service,
appPathProvider: appPathProvider,
onProgress: (progress) {
Expand Down Expand Up @@ -168,7 +168,7 @@ void main() {
options: const StorageDownloadFileOptions(
pluginOptions: S3DownloadFilePluginOptions(),
),
s3pluginConfig: testS3pluginConfig,
storageOutputs: testStorageOutputs,
storageS3Service: storageS3Service,
appPathProvider: appPathProvider,
onProgress: (progress) {
Expand Down Expand Up @@ -200,7 +200,7 @@ void main() {
options: const StorageDownloadFileOptions(
pluginOptions: S3DownloadFilePluginOptions(),
),
s3pluginConfig: testS3pluginConfig,
storageOutputs: testStorageOutputs,
storageS3Service: storageS3Service,
appPathProvider: appPathProvider,
onProgress: (progress) {
Expand Down Expand Up @@ -238,7 +238,7 @@ void main() {
options: const StorageDownloadFileOptions(
pluginOptions: S3DownloadFilePluginOptions(),
),
s3pluginConfig: testS3pluginConfig,
storageOutputs: testStorageOutputs,
storageS3Service: storageS3Service,
appPathProvider: appPathProvider,
onProgress: (progress) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void main() {
group('StorageS3Service', () {
const testBucket = 'bucket1';
const testRegion = 'west-2';
const s3PluginConfig =
const storageOutputs =
StorageOutputs(bucketName: testBucket, awsRegion: testRegion);

final pathResolver = TestPathResolver();
Expand All @@ -44,7 +44,7 @@ void main() {
..addInstance<S3Client>(s3Client)
..addInstance<AWSSigV4Signer>(awsSigV4Signer);
storageS3Service = StorageS3Service(
s3PluginConfig: s3PluginConfig,
storageOutputs: storageOutputs,
pathResolver: pathResolver,
credentialsProvider: TestIamAuthProvider(),
logger: logger,
Expand All @@ -54,7 +54,7 @@ void main() {

test('log a warning when should use path style URLs', () {
StorageS3Service(
s3PluginConfig: const StorageOutputs(
storageOutputs: const StorageOutputs(
bucketName: 'bucket.name.has.dots.com',
awsRegion: 'us-west-2',
),
Expand Down Expand Up @@ -771,7 +771,7 @@ void main() {
late StorageS3Service pathStyleStorageS3Service;
const pathStyleBucket = 'bucket.name.has.dots.com';
const pathStyleRegion = 'west-2';
const pathStyleS3PluginConfig = StorageOutputs(
const pathStyleStorageOutputs = StorageOutputs(
bucketName: pathStyleBucket,
awsRegion: pathStyleRegion,
);
Expand All @@ -787,7 +787,7 @@ void main() {
..addInstance<S3Client>(MockS3Client())
..addInstance<AWSSigV4Signer>(pathStyleAwsSigV4Signer);
pathStyleStorageS3Service = StorageS3Service(
s3PluginConfig: pathStyleS3PluginConfig,
storageOutputs: pathStyleStorageOutputs,
pathResolver: pathResolver,
credentialsProvider: TestIamAuthProvider(),
logger: MockAWSLogger(),
Expand Down Expand Up @@ -831,7 +831,7 @@ void main() {
.having(
(o) => o.host,
'host',
's3.${pathStyleS3PluginConfig.awsRegion}.amazonaws.com',
's3.${pathStyleStorageOutputs.awsRegion}.amazonaws.com',
)
.having(
(o) => o.path,
Expand Down

0 comments on commit e62a64a

Please sign in to comment.