-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nika Hassani
committed
Sep 17, 2024
1 parent
51d01c4
commit 3ef6f7e
Showing
6 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
packages/amplify_core/lib/src/types/exception/storage/invalid_storage_bucket_exception.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
part of '../amplify_exception.dart'; | ||
|
||
/// {@template amplify_core.storage.invalid_storage_bucket_exception} | ||
/// Exception thrown when the [StorageBucket] is invalid. | ||
/// {@endtemplate} | ||
class InvalidStorageBucketException extends StorageException { | ||
const InvalidStorageBucketException( | ||
super.message, { | ||
super.recoverySuggestion, | ||
super.underlyingException, | ||
}); | ||
|
||
@override | ||
String get runtimeTypeName => 'InvalidStorageBucketException'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/// {@template amplify_core.storage.bucket_info} | ||
/// Presents a storage bucket information. | ||
/// {@endtemplate} | ||
class BucketInfo { | ||
/// {@macro amplify_core.storage.bucket_info} | ||
const BucketInfo({required this.bucketName, required this.region}); | ||
final String bucketName; | ||
final String region; | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/amplify_core/lib/src/types/storage/storage_bucket.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import 'package:amplify_core/src/config/amplify_outputs/storage/storage_outputs.dart'; | ||
import 'package:amplify_core/src/types/storage/bucket_info.dart'; | ||
import 'package:amplify_core/src/types/storage/storage_bucket_from_outputs.dart'; | ||
import 'package:meta/meta.dart'; | ||
|
||
/// Presents a storage bucket. | ||
class StorageBucket { | ||
/// Creates a [StorageBucket] from [BucketInfo]. | ||
const StorageBucket.fromBucketInfo(this._info); | ||
|
||
/// Creates a [StorageBucket] defined by the [name] in AmplifyOutputs file. | ||
factory StorageBucket.fromOutputs(String name) => | ||
StorageBucketFromOutputs(name); | ||
|
||
final BucketInfo _info; | ||
|
||
@internal | ||
BucketInfo resolveBucketInfo(StorageOutputs? storageOutputs) => _info; | ||
} |
31 changes: 31 additions & 0 deletions
31
packages/amplify_core/lib/src/types/storage/storage_bucket_from_outputs.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import 'package:amplify_core/amplify_core.dart'; | ||
import 'package:amplify_core/src/config/amplify_outputs/storage/storage_outputs.dart'; | ||
import 'package:meta/meta.dart'; | ||
|
||
/// {@template amplify_core.storage.storage_bucket_from_outputs} | ||
/// Creates a [StorageBucket] defined by the name in AmplifyOutputs file. | ||
/// {@endtemplate} | ||
@internal | ||
class StorageBucketFromOutputs implements StorageBucket { | ||
/// {@macro amplify_core.storage.storage_bucket_from_outputs} | ||
const StorageBucketFromOutputs(this._name); | ||
|
||
final String _name; | ||
|
||
@override | ||
BucketInfo resolveBucketInfo(StorageOutputs? storageOutputs) { | ||
assert( | ||
storageOutputs != null, | ||
const InvalidStorageBucketException( | ||
'Amplify Storage is not configured.', | ||
recoverySuggestion: | ||
'Make sure storage exists in the Amplify Outputs file.', | ||
), | ||
); | ||
// TODO(nikahsn): fix after adding buckets to StorageOutputs. | ||
return BucketInfo( | ||
bucketName: _name, | ||
region: storageOutputs!.awsRegion, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters