Skip to content

Commit 9c60c8c

Browse files
committed
feat(Storage): Adding StorageBucket (#3812)
1 parent cb80b91 commit 9c60c8c

12 files changed

+1491
-89
lines changed

Amplify/Categories/Storage/Operation/Request/StorageDownloadDataRequest.swift

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ public extension StorageDownloadDataRequest {
6464
@available(*, deprecated, message: "Use `path` in Storage API instead of `Options`")
6565
public let targetIdentityId: String?
6666

67+
/// A Storage Bucket that contains the object to download. Defaults to `nil`, in which case the default one will be used.
68+
///
69+
/// - Tag: StorageDownloadDataRequest.bucket
70+
public let bucket: (any StorageBucket)?
71+
6772
/// Extra plugin specific options, only used in special circumstances when the existing options do not provide
6873
/// a way to utilize the underlying storage system's functionality. See plugin documentation for expected
6974
/// key/values
@@ -90,20 +95,28 @@ public extension StorageDownloadDataRequest {
9095

9196
///
9297
/// - Tag: StorageDownloadDataRequestOptions.init
93-
@available(*, deprecated, message: "Use init(pluginOptions)")
94-
public init(accessLevel: StorageAccessLevel = .guest,
95-
targetIdentityId: String? = nil,
96-
pluginOptions: Any? = nil) {
98+
@available(*, deprecated, message: "Use init(bucket:pluginOptions)")
99+
public init(
100+
accessLevel: StorageAccessLevel = .guest,
101+
targetIdentityId: String? = nil,
102+
bucket: (any StorageBucket)? = nil,
103+
pluginOptions: Any? = nil
104+
) {
97105
self.accessLevel = accessLevel
98106
self.targetIdentityId = targetIdentityId
107+
self.bucket = bucket
99108
self.pluginOptions = pluginOptions
100109
}
101110

102111
///
103112
/// - Tag: StorageDownloadDataRequestOptions.init
104-
public init(pluginOptions: Any? = nil) {
113+
public init(
114+
bucket: (any StorageBucket)? = nil,
115+
pluginOptions: Any? = nil
116+
) {
105117
self.accessLevel = .guest
106118
self.targetIdentityId = nil
119+
self.bucket = bucket
107120
self.pluginOptions = pluginOptions
108121
}
109122
}

Amplify/Categories/Storage/Operation/Request/StorageDownloadFileRequest.swift

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ public extension StorageDownloadFileRequest {
7171
@available(*, deprecated, message: "Use `path` in Storage API instead of `Options`")
7272
public let targetIdentityId: String?
7373

74+
/// A Storage Bucket that contains the object to download. Defaults to `nil`, in which case the default one will be used.
75+
///
76+
/// - Tag: StorageDownloadDataRequest.bucket
77+
public let bucket: (any StorageBucket)?
78+
7479
/// Extra plugin specific options, only used in special circumstances when the existing options do not provide
7580
/// a way to utilize the underlying storage system's functionality. See plugin documentation for expected
7681
/// key/values
@@ -79,20 +84,27 @@ public extension StorageDownloadFileRequest {
7984
public let pluginOptions: Any?
8085

8186
/// - Tag: StorageDownloadFileRequestOptions.init
82-
@available(*, deprecated, message: "Use init(pluginOptions)")
83-
public init(accessLevel: StorageAccessLevel = .guest,
84-
targetIdentityId: String? = nil,
85-
pluginOptions: Any? = nil) {
87+
@available(*, deprecated, message: "Use init(bucket:pluginOptions)")
88+
public init(
89+
accessLevel: StorageAccessLevel = .guest,
90+
targetIdentityId: String? = nil,
91+
bucket: (any StorageBucket)? = nil,
92+
pluginOptions: Any? = nil
93+
) {
8694
self.accessLevel = accessLevel
8795
self.targetIdentityId = targetIdentityId
96+
self.bucket = bucket
8897
self.pluginOptions = pluginOptions
8998
}
9099

91100
/// - Tag: StorageDownloadFileRequestOptions.init
92-
@available(*, deprecated, message: "Use init(pluginOptions)")
93-
public init(pluginOptions: Any? = nil) {
101+
public init(
102+
bucket: (any StorageBucket)? = nil,
103+
pluginOptions: Any? = nil
104+
) {
94105
self.accessLevel = .guest
95106
self.targetIdentityId = nil
107+
self.bucket = bucket
96108
self.pluginOptions = pluginOptions
97109
}
98110
}

Amplify/Categories/Storage/Operation/Request/StorageGetURLRequest.swift

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ public extension StorageGetURLRequest {
7373
/// - Tag: StorageGetURLRequest.Options.expires
7474
public let expires: Int
7575

76+
/// A Storage Bucket that contains the object. Defaults to `nil`, in which case the default one will be used.
77+
///
78+
/// - Tag: StorageDownloadDataRequest.bucket
79+
public let bucket: (any StorageBucket)?
80+
7681
/// Extra plugin specific options, only used in special circumstances when the existing options do
7782
/// not provide a way to utilize the underlying storage system's functionality. See plugin
7883
/// documentation or
@@ -83,21 +88,29 @@ public extension StorageGetURLRequest {
8388
public let pluginOptions: Any?
8489

8590
/// - Tag: StorageGetURLRequest.Options.init
86-
@available(*, deprecated, message: "Use init(expires:pluginOptions)")
87-
public init(accessLevel: StorageAccessLevel = .guest,
88-
targetIdentityId: String? = nil,
89-
expires: Int = Options.defaultExpireInSeconds,
90-
pluginOptions: Any? = nil) {
91+
@available(*, deprecated, message: "Use init(expires:bucket:pluginOptions)")
92+
public init(
93+
accessLevel: StorageAccessLevel = .guest,
94+
targetIdentityId: String? = nil,
95+
expires: Int = Options.defaultExpireInSeconds,
96+
bucket: (any StorageBucket)? = nil,
97+
pluginOptions: Any? = nil
98+
) {
9199
self.accessLevel = accessLevel
92100
self.targetIdentityId = targetIdentityId
93101
self.expires = expires
102+
self.bucket = bucket
94103
self.pluginOptions = pluginOptions
95104
}
96105

97106
/// - Tag: StorageGetURLRequest.Options.init
98-
public init(expires: Int = Options.defaultExpireInSeconds,
99-
pluginOptions: Any? = nil) {
107+
public init(
108+
expires: Int = Options.defaultExpireInSeconds,
109+
bucket: (any StorageBucket)? = nil,
110+
pluginOptions: Any? = nil
111+
) {
100112
self.expires = expires
113+
self.bucket = bucket
101114
self.pluginOptions = pluginOptions
102115
self.accessLevel = .guest
103116
self.targetIdentityId = nil

Amplify/Categories/Storage/Operation/Request/StorageListRequest.swift

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ public extension StorageListRequest {
7878
/// - Tag: StorageListRequestOptions.pageSize
7979
public let pageSize: UInt
8080

81+
/// A Storage Bucket that contains the objects to list. Defaults to `nil`, in which case the default one will be used.
82+
///
83+
/// - Tag: StorageDownloadDataRequest.bucket
84+
public let bucket: (any StorageBucket)?
85+
8186
/// Opaque string indicating the page offset at which to resume a listing. This is usually a copy of
8287
/// the value from [StorageListResult.nextToken](x-source-tag://StorageListResult.nextToken).
8388
///
@@ -96,18 +101,22 @@ public extension StorageListRequest {
96101
public let pluginOptions: Any?
97102

98103
/// - Tag: StorageListRequestOptions.init
99-
public init(accessLevel: StorageAccessLevel = .guest,
100-
targetIdentityId: String? = nil,
101-
path: String? = nil,
102-
subpathStrategy: SubpathStrategy = .include,
103-
pageSize: UInt = 1000,
104-
nextToken: String? = nil,
105-
pluginOptions: Any? = nil) {
104+
public init(
105+
accessLevel: StorageAccessLevel = .guest,
106+
targetIdentityId: String? = nil,
107+
path: String? = nil,
108+
subpathStrategy: SubpathStrategy = .include,
109+
pageSize: UInt = 1000,
110+
bucket: (any StorageBucket)? = nil,
111+
nextToken: String? = nil,
112+
pluginOptions: Any? = nil
113+
) {
106114
self.accessLevel = accessLevel
107115
self.targetIdentityId = targetIdentityId
108116
self.path = path
109117
self.subpathStrategy = subpathStrategy
110118
self.pageSize = pageSize
119+
self.bucket = bucket
111120
self.nextToken = nextToken
112121
self.pluginOptions = pluginOptions
113122
}

Amplify/Categories/Storage/Operation/Request/StorageRemoveRequest.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ public extension StorageRemoveRequest {
5656
@available(*, deprecated, message: "Use `path` in Storage API instead of `Options`")
5757
public let accessLevel: StorageAccessLevel
5858

59+
/// A Storage Bucket that contains the object to remove. Defaults to `nil`, in which case the default one will be used.
60+
///
61+
/// - Tag: StorageDownloadDataRequest.bucket
62+
public let bucket: (any StorageBucket)?
63+
5964
/// Extra plugin specific options, only used in special circumstances when the existing options do not provide
6065
/// a way to utilize the underlying storage system's functionality. See plugin documentation for expected
6166
/// key/values
@@ -64,9 +69,13 @@ public extension StorageRemoveRequest {
6469
public let pluginOptions: Any?
6570

6671
/// - Tag: StorageRemoveRequestOptions.init
67-
public init(accessLevel: StorageAccessLevel = .guest,
68-
pluginOptions: Any? = nil) {
72+
public init(
73+
accessLevel: StorageAccessLevel = .guest,
74+
bucket: (any StorageBucket)? = nil,
75+
pluginOptions: Any? = nil
76+
) {
6977
self.accessLevel = accessLevel
78+
self.bucket = bucket
7079
self.pluginOptions = pluginOptions
7180
}
7281
}

Amplify/Categories/Storage/Operation/Request/StorageUploadDataRequest.swift

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ public extension StorageUploadDataRequest {
7575
/// - Tag: StorageUploadDataRequestOptions.metadata
7676
public let metadata: [String: String]?
7777

78+
/// A specific Storage Bucket to upload the data. Defaults to `nil`, in which case the default one will be used.
79+
///
80+
/// - Tag: StorageDownloadDataRequest.bucket
81+
public let bucket: (any StorageBucket)?
82+
7883
/// The standard MIME type describing the format of the object to store
7984
///
8085
/// - Tag: StorageUploadDataRequestOptions.contentType
@@ -88,28 +93,34 @@ public extension StorageUploadDataRequest {
8893
public let pluginOptions: Any?
8994

9095
/// - Tag: StorageUploadDataRequestOptions.init
91-
@available(*, deprecated, message: "Use init(metadata:contentType:options)")
92-
public init(accessLevel: StorageAccessLevel = .guest,
93-
targetIdentityId: String? = nil,
94-
metadata: [String: String]? = nil,
95-
contentType: String? = nil,
96-
pluginOptions: Any? = nil
96+
@available(*, deprecated, message: "Use init(metadata:bucket:contentType:options)")
97+
public init(
98+
accessLevel: StorageAccessLevel = .guest,
99+
targetIdentityId: String? = nil,
100+
metadata: [String: String]? = nil,
101+
bucket: (any StorageBucket)? = nil,
102+
contentType: String? = nil,
103+
pluginOptions: Any? = nil
97104
) {
98105
self.accessLevel = accessLevel
99106
self.targetIdentityId = targetIdentityId
100107
self.metadata = metadata
108+
self.bucket = bucket
101109
self.contentType = contentType
102110
self.pluginOptions = pluginOptions
103111
}
104112

105113
/// - Tag: StorageUploadDataRequestOptions.init
106-
public init(metadata: [String: String]? = nil,
107-
contentType: String? = nil,
108-
pluginOptions: Any? = nil
114+
public init(
115+
metadata: [String: String]? = nil,
116+
bucket: (any StorageBucket)? = nil,
117+
contentType: String? = nil,
118+
pluginOptions: Any? = nil
109119
) {
110120
self.accessLevel = .guest
111121
self.targetIdentityId = nil
112122
self.metadata = metadata
123+
self.bucket = bucket
113124
self.contentType = contentType
114125
self.pluginOptions = pluginOptions
115126
}

Amplify/Categories/Storage/Operation/Request/StorageUploadFileRequest.swift

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ public extension StorageUploadFileRequest {
7272
/// - Tag: StorageUploadFileRequestOptions.metadata
7373
public let metadata: [String: String]?
7474

75+
/// A specific Storage Bucket to upload the file. Defaults to `nil`, in which case the default one will be used.
76+
///
77+
/// - Tag: StorageUploadFileRequestOptions.bucket
78+
public let bucket: (any StorageBucket)?
79+
7580
/// The standard MIME type describing the format of the object to store
7681
///
7782
/// - Tag: StorageUploadFileRequestOptions.contentType
@@ -85,28 +90,34 @@ public extension StorageUploadFileRequest {
8590
public let pluginOptions: Any?
8691

8792
/// - Tag: StorageUploadFileRequestOptions.init
88-
@available(*, deprecated, message: "Use init(metadata:contentType:pluginOptions)")
89-
public init(accessLevel: StorageAccessLevel = .guest,
90-
targetIdentityId: String? = nil,
91-
metadata: [String: String]? = nil,
92-
contentType: String? = nil,
93-
pluginOptions: Any? = nil
93+
@available(*, deprecated, message: "Use init(metadata:bucket:contentType:pluginOptions)")
94+
public init(
95+
accessLevel: StorageAccessLevel = .guest,
96+
targetIdentityId: String? = nil,
97+
metadata: [String: String]? = nil,
98+
bucket: (any StorageBucket)? = nil,
99+
contentType: String? = nil,
100+
pluginOptions: Any? = nil
94101
) {
95102
self.accessLevel = accessLevel
96103
self.targetIdentityId = targetIdentityId
97104
self.metadata = metadata
105+
self.bucket = bucket
98106
self.contentType = contentType
99107
self.pluginOptions = pluginOptions
100108
}
101109

102110
/// - Tag: StorageUploadFileRequestOptions.init
103-
public init(metadata: [String: String]? = nil,
104-
contentType: String? = nil,
105-
pluginOptions: Any? = nil
111+
public init(
112+
metadata: [String: String]? = nil,
113+
bucket: (any StorageBucket)? = nil,
114+
contentType: String? = nil,
115+
pluginOptions: Any? = nil
106116
) {
107117
self.accessLevel = .guest
108118
self.targetIdentityId = nil
109119
self.metadata = metadata
120+
self.bucket = bucket
110121
self.contentType = contentType
111122
self.pluginOptions = pluginOptions
112123
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//
2+
// Copyright Amazon.com Inc. or its affiliates.
3+
// All Rights Reserved.
4+
//
5+
// SPDX-License-Identifier: Apache-2.0
6+
//
7+
8+
import Foundation
9+
10+
/// Protocol that represents a Storage bucket.
11+
///
12+
/// - Tag: StorageBucket
13+
public protocol StorageBucket { }
14+
15+
/// Represents information about a Storage bucket
16+
///
17+
/// - Tag: BucketInfo
18+
public struct BucketInfo: Hashable {
19+
20+
/// The name of the bucket
21+
/// - Tag: BucketInfo.bucketName
22+
public let bucketName: String
23+
24+
/// The region of the bucket
25+
/// - Tag: BucketInfo.region
26+
public let region: String
27+
28+
public init(bucketName: String, region: String) {
29+
self.bucketName = bucketName
30+
self.region = region
31+
}
32+
}
33+
34+
public extension StorageBucket where Self == OutputsStorageBucket {
35+
36+
/// References a `StorageBucket` in the AmplifyOutputs file using the given name.
37+
///
38+
/// - Parameter name: The name of the bucket
39+
static func fromOutputs(name: String) -> Self {
40+
return OutputsStorageBucket(name: name)
41+
}
42+
}
43+
44+
public extension StorageBucket where Self == ResolvedStorageBucket {
45+
/// References a `StorageBucket` using the data from the given `BucketInfo`.
46+
///
47+
/// - Parameter bucketInfo: A `BucketInfo` instance
48+
static func fromBucketInfo(_ bucketInfo: BucketInfo) -> Self {
49+
return ResolvedStorageBucket(bucketInfo: bucketInfo)
50+
}
51+
}
52+
53+
54+
/// Conforms to `StorageBucket`. Represents a Storage Bucket defined by a name in the AmplifyOutputs file.
55+
///
56+
/// - Tag: OutputsStorageBucket
57+
public struct OutputsStorageBucket: StorageBucket {
58+
public let name: String
59+
}
60+
61+
/// Conforms to `StorageBucket`. Represents a Storage Bucket defined by a name and a region defined in `BucketInfo`.
62+
///
63+
/// - Tag: ResolvedStorageBucket
64+
public struct ResolvedStorageBucket: StorageBucket {
65+
public let bucketInfo: BucketInfo
66+
}

api-dump/AWSDataStorePlugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8205,7 +8205,7 @@
82058205
"-module",
82068206
"AWSDataStorePlugin",
82078207
"-o",
8208-
"\/var\/folders\/4d\/0gnh84wj53j7wyk695q0tc_80000gn\/T\/tmp.BZQxGLOyZz\/AWSDataStorePlugin.json",
8208+
"\/var\/folders\/m_\/cksx93ys47x4621g0zbw_m4m0000gn\/T\/tmp.xrcnJX8DBh\/AWSDataStorePlugin.json",
82098209
"-I",
82108210
".build\/debug",
82118211
"-sdk-version",

0 commit comments

Comments
 (0)