Skip to content

Commit 7daa044

Browse files
authored
chore(aws-storage-s3): add plugin-specific options (#897)
* fix(aws-storage-s3): add plugin-specific options * minor fixup * add object method overrides
1 parent 6c63739 commit 7daa044

14 files changed

+944
-95
lines changed

aws-storage-s3/src/main/java/com/amplifyframework/storage/s3/AWSS3StoragePlugin.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import com.amplifyframework.storage.s3.operation.AWSS3StorageListOperation;
4646
import com.amplifyframework.storage.s3.operation.AWSS3StorageRemoveOperation;
4747
import com.amplifyframework.storage.s3.operation.AWSS3StorageUploadFileOperation;
48+
import com.amplifyframework.storage.s3.options.AWSS3StorageUploadFileOptions;
4849
import com.amplifyframework.storage.s3.request.AWSS3StorageDownloadFileRequest;
4950
import com.amplifyframework.storage.s3.request.AWSS3StorageGetPresignedUrlRequest;
5051
import com.amplifyframework.storage.s3.request.AWSS3StorageListRequest;
@@ -314,7 +315,9 @@ public StorageUploadFileOperation<?> uploadFile(
314315
: defaultAccessLevel,
315316
options.getTargetIdentityId(),
316317
options.getContentType(),
317-
options.getServerSideEncryption(),
318+
options instanceof AWSS3StorageUploadFileOptions
319+
? ((AWSS3StorageUploadFileOptions) options).getServerSideEncryption()
320+
: ServerSideEncryption.NONE,
318321
options.getMetadata()
319322
);
320323

core/src/main/java/com/amplifyframework/storage/StorageServerSideEncryption.java renamed to aws-storage-s3/src/main/java/com/amplifyframework/storage/s3/ServerSideEncryption.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
* permissions and limitations under the License.
1414
*/
1515

16-
package com.amplifyframework.storage;
16+
package com.amplifyframework.storage.s3;
1717

1818
/**
19-
* Represents storage server side encryption method type.
19+
* Represents server side encryption method types that are supported by AWS S3.
2020
*/
21-
public enum StorageServerSideEncryption {
21+
public enum ServerSideEncryption {
2222
/**
2323
* AES256 encryption.
2424
*/
@@ -36,7 +36,7 @@ public enum StorageServerSideEncryption {
3636

3737
private final String name;
3838

39-
StorageServerSideEncryption(String name) {
39+
ServerSideEncryption(String name) {
4040
this.name = name;
4141
}
4242

aws-storage-s3/src/main/java/com/amplifyframework/storage/s3/operation/AWSS3StorageUploadFileOperation.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
import com.amplifyframework.hub.HubEvent;
2525
import com.amplifyframework.storage.StorageChannelEventName;
2626
import com.amplifyframework.storage.StorageException;
27-
import com.amplifyframework.storage.StorageServerSideEncryption;
2827
import com.amplifyframework.storage.operation.StorageUploadFileOperation;
2928
import com.amplifyframework.storage.result.StorageTransferProgress;
3029
import com.amplifyframework.storage.result.StorageUploadFileResult;
3130
import com.amplifyframework.storage.s3.CognitoAuthProvider;
31+
import com.amplifyframework.storage.s3.ServerSideEncryption;
3232
import com.amplifyframework.storage.s3.request.AWSS3StorageUploadFileRequest;
3333
import com.amplifyframework.storage.s3.service.StorageService;
3434
import com.amplifyframework.storage.s3.utils.S3Keys;
@@ -111,8 +111,8 @@ public void start() {
111111
objectMetadata.setUserMetadata(getRequest().getMetadata());
112112
objectMetadata.setContentType(getRequest().getContentType());
113113

114-
StorageServerSideEncryption storageServerSideEncryption = getRequest().getServerSideEncryption();
115-
if (!StorageServerSideEncryption.NONE.equals(storageServerSideEncryption)) {
114+
ServerSideEncryption storageServerSideEncryption = getRequest().getServerSideEncryption();
115+
if (!ServerSideEncryption.NONE.equals(storageServerSideEncryption)) {
116116
objectMetadata.setSSEAlgorithm(storageServerSideEncryption.getName());
117117
}
118118

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package com.amplifyframework.storage.s3.options;
17+
18+
import androidx.annotation.NonNull;
19+
import androidx.core.util.ObjectsCompat;
20+
21+
import com.amplifyframework.storage.options.StorageDownloadFileOptions;
22+
23+
/**
24+
* Options to specify attributes of object download operation from an AWS S3 bucket.
25+
*/
26+
public final class AWSS3StorageDownloadFileOptions extends StorageDownloadFileOptions {
27+
28+
private AWSS3StorageDownloadFileOptions(final Builder builder) {
29+
super(builder);
30+
}
31+
32+
/**
33+
* Factory method to create a new instance of the
34+
* {@link Builder}. The builder can be
35+
* used to configure properties and then construct a new immutable
36+
* instance of the storage options that are specific to AWS S3.
37+
* @return An instance of the {@link Builder}
38+
*/
39+
@NonNull
40+
public static Builder builder() {
41+
return new Builder();
42+
}
43+
44+
/**
45+
* Factory method to create builder which is configured to prepare
46+
* object instances with the same field values as the provided
47+
* options. This can be used as a starting ground to create a
48+
* new clone of the provided options, which shares some common
49+
* configuration.
50+
* @param options Options to populate into a new builder configuration
51+
* @return A Builder instance that has been configured using the
52+
* values in the provided options
53+
*/
54+
@NonNull
55+
public static Builder from(@NonNull final AWSS3StorageDownloadFileOptions options) {
56+
return builder()
57+
.accessLevel(options.getAccessLevel())
58+
.targetIdentityId(options.getTargetIdentityId());
59+
}
60+
61+
/**
62+
* Constructs a default instance of the {@link AWSS3StorageDownloadFileOptions}.
63+
* @return default instance of AWSS3StorageDownloadFileOptions
64+
*/
65+
@NonNull
66+
public static AWSS3StorageDownloadFileOptions defaultInstance() {
67+
return builder().build();
68+
}
69+
70+
@Override
71+
public boolean equals(Object obj) {
72+
if (this == obj) {
73+
return true;
74+
} else if (!(obj instanceof AWSS3StorageDownloadFileOptions)) {
75+
return false;
76+
} else {
77+
AWSS3StorageDownloadFileOptions that = (AWSS3StorageDownloadFileOptions) obj;
78+
return ObjectsCompat.equals(getAccessLevel(), that.getAccessLevel()) &&
79+
ObjectsCompat.equals(getTargetIdentityId(), that.getTargetIdentityId());
80+
}
81+
}
82+
83+
@Override
84+
public int hashCode() {
85+
return ObjectsCompat.hash(
86+
getAccessLevel(),
87+
getTargetIdentityId()
88+
);
89+
}
90+
91+
@NonNull
92+
@Override
93+
public String toString() {
94+
return "AWSS3StorageDownloadFileOptions {" +
95+
"accessLevel=" + getAccessLevel() +
96+
", targetIdentityId=" + getTargetIdentityId() +
97+
'}';
98+
}
99+
100+
/**
101+
* A utility that can be used to configure and construct immutable
102+
* instances of the {@link AWSS3StorageDownloadFileOptions}, by chaining
103+
* fluent configuration method calls.
104+
*/
105+
public static final class Builder extends StorageDownloadFileOptions.Builder<Builder> {
106+
@Override
107+
@NonNull
108+
public AWSS3StorageDownloadFileOptions build() {
109+
return new AWSS3StorageDownloadFileOptions(this);
110+
}
111+
}
112+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package com.amplifyframework.storage.s3.options;
17+
18+
import android.annotation.SuppressLint;
19+
import androidx.annotation.NonNull;
20+
import androidx.core.util.ObjectsCompat;
21+
22+
import com.amplifyframework.storage.options.StorageGetUrlOptions;
23+
24+
/**
25+
* Options to specify attributes of presigned URL generation from an AWS S3 bucket.
26+
*/
27+
public final class AWSS3StorageGetPresignedUrlOptions extends StorageGetUrlOptions {
28+
29+
private AWSS3StorageGetPresignedUrlOptions(final Builder builder) {
30+
super(builder);
31+
}
32+
33+
/**
34+
* Returns a new Builder instance that can be used to configure
35+
* and build a new immutable instance of AWSS3StorageGetPresignedUrlOptions.
36+
* @return a new builder instance
37+
*/
38+
@SuppressLint("SyntheticAccessor")
39+
@NonNull
40+
public static Builder builder() {
41+
return new Builder();
42+
}
43+
44+
/**
45+
* Factory method to create builder which is configured to prepare
46+
* object instances with the same field values as the provided
47+
* options. This can be used as a starting ground to create a
48+
* new clone of the provided options, which shares some common
49+
* configuration.
50+
* @param options Options to populate into a new builder configuration
51+
* @return A Builder instance that has been configured using the
52+
* values in the provided options
53+
*/
54+
@NonNull
55+
public static Builder from(@NonNull AWSS3StorageGetPresignedUrlOptions options) {
56+
return builder()
57+
.accessLevel(options.getAccessLevel())
58+
.targetIdentityId(options.getTargetIdentityId())
59+
.expires(options.getExpires());
60+
}
61+
62+
/**
63+
* Constructs a default instance of the {@link StorageGetUrlOptions}.
64+
* @return default instance of StorageGetUrlOptions
65+
*/
66+
@NonNull
67+
public static AWSS3StorageGetPresignedUrlOptions defaultInstance() {
68+
return builder().build();
69+
}
70+
71+
@Override
72+
public boolean equals(Object obj) {
73+
if (this == obj) {
74+
return true;
75+
} else if (!(obj instanceof AWSS3StorageGetPresignedUrlOptions)) {
76+
return false;
77+
} else {
78+
AWSS3StorageGetPresignedUrlOptions that = (AWSS3StorageGetPresignedUrlOptions) obj;
79+
return ObjectsCompat.equals(getAccessLevel(), that.getAccessLevel()) &&
80+
ObjectsCompat.equals(getTargetIdentityId(), that.getTargetIdentityId()) &&
81+
ObjectsCompat.equals(getExpires(), that.getExpires());
82+
}
83+
}
84+
85+
@Override
86+
public int hashCode() {
87+
return ObjectsCompat.hash(
88+
getAccessLevel(),
89+
getTargetIdentityId(),
90+
getExpires()
91+
);
92+
}
93+
94+
@NonNull
95+
@Override
96+
public String toString() {
97+
return "AWSS3StorageGetPresignedUrlOptions {" +
98+
"accessLevel=" + getAccessLevel() +
99+
", targetIdentityId=" + getTargetIdentityId() +
100+
", expires=" + getExpires() +
101+
'}';
102+
}
103+
104+
/**
105+
* A utility that can be used to configure and construct immutable
106+
* instances of the {@link AWSS3StorageGetPresignedUrlOptions}, by chaining
107+
* fluent configuration method calls.
108+
*/
109+
public static final class Builder extends StorageGetUrlOptions.Builder<Builder> {
110+
@Override
111+
@NonNull
112+
public AWSS3StorageGetPresignedUrlOptions build() {
113+
return new AWSS3StorageGetPresignedUrlOptions(this);
114+
}
115+
}
116+
}

0 commit comments

Comments
 (0)