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(storage): Add support to define the S3 Storage Class #2862

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion aws-storage-s3/api/aws-storage-s3.api
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ public final class com/amplifyframework/storage/s3/options/AWSS3StorageUploadFil
public fun equals (Ljava/lang/Object;)Z
public static fun from (Lcom/amplifyframework/storage/s3/options/AWSS3StorageUploadFileOptions;)Lcom/amplifyframework/storage/s3/options/AWSS3StorageUploadFileOptions$Builder;
public fun getServerSideEncryption ()Lcom/amplifyframework/storage/s3/ServerSideEncryption;
public fun getStorageClass ()Laws/sdk/kotlin/services/s3/model/StorageClass;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
public fun useAccelerateEndpoint ()Z
Expand All @@ -253,6 +254,7 @@ public final class com/amplifyframework/storage/s3/options/AWSS3StorageUploadFil
public fun build ()Lcom/amplifyframework/storage/s3/options/AWSS3StorageUploadFileOptions;
public fun serverSideEncryption (Lcom/amplifyframework/storage/s3/ServerSideEncryption;)Lcom/amplifyframework/storage/s3/options/AWSS3StorageUploadFileOptions$Builder;
public fun setUseAccelerateEndpoint (Z)Lcom/amplifyframework/storage/s3/options/AWSS3StorageUploadFileOptions$Builder;
public fun storageClass (Laws/sdk/kotlin/services/s3/model/StorageClass;)Lcom/amplifyframework/storage/s3/options/AWSS3StorageUploadFileOptions$Builder;
}

public final class com/amplifyframework/storage/s3/options/AWSS3StorageUploadInputStreamOptions : com/amplifyframework/storage/options/StorageUploadInputStreamOptions {
Expand All @@ -261,6 +263,7 @@ public final class com/amplifyframework/storage/s3/options/AWSS3StorageUploadInp
public fun equals (Ljava/lang/Object;)Z
public static fun from (Lcom/amplifyframework/storage/s3/options/AWSS3StorageUploadInputStreamOptions;)Lcom/amplifyframework/storage/s3/options/AWSS3StorageUploadInputStreamOptions$Builder;
public fun getServerSideEncryption ()Lcom/amplifyframework/storage/s3/ServerSideEncryption;
public fun getStorageClass ()Laws/sdk/kotlin/services/s3/model/StorageClass;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
public fun useAccelerateEndpoint ()Z
Expand All @@ -272,6 +275,7 @@ public final class com/amplifyframework/storage/s3/options/AWSS3StorageUploadInp
public fun build ()Lcom/amplifyframework/storage/s3/options/AWSS3StorageUploadInputStreamOptions;
public fun serverSideEncryption (Lcom/amplifyframework/storage/s3/ServerSideEncryption;)Lcom/amplifyframework/storage/s3/options/AWSS3StorageUploadInputStreamOptions$Builder;
public fun setUseAccelerateEndpoint (Z)Lcom/amplifyframework/storage/s3/options/AWSS3StorageUploadInputStreamOptions$Builder;
public fun storageClass (Laws/sdk/kotlin/services/s3/model/StorageClass;)Lcom/amplifyframework/storage/s3/options/AWSS3StorageUploadInputStreamOptions$Builder;
}

public final class com/amplifyframework/storage/s3/request/AWSS3StorageDownloadFileRequest {
Expand Down Expand Up @@ -314,13 +318,14 @@ public final class com/amplifyframework/storage/s3/request/AWSS3StorageRemoveReq
}

public final class com/amplifyframework/storage/s3/request/AWSS3StorageUploadRequest {
public fun <init> (Ljava/lang/String;Ljava/lang/Object;Lcom/amplifyframework/storage/StorageAccessLevel;Ljava/lang/String;Ljava/lang/String;Lcom/amplifyframework/storage/s3/ServerSideEncryption;Ljava/util/Map;Z)V
public fun <init> (Ljava/lang/String;Ljava/lang/Object;Lcom/amplifyframework/storage/StorageAccessLevel;Ljava/lang/String;Ljava/lang/String;Lcom/amplifyframework/storage/s3/ServerSideEncryption;Laws/sdk/kotlin/services/s3/model/StorageClass;Ljava/util/Map;Z)V
public fun getAccessLevel ()Lcom/amplifyframework/storage/StorageAccessLevel;
public fun getContentType ()Ljava/lang/String;
public fun getKey ()Ljava/lang/String;
public fun getLocal ()Ljava/lang/Object;
public fun getMetadata ()Ljava/util/Map;
public fun getServerSideEncryption ()Lcom/amplifyframework/storage/s3/ServerSideEncryption;
public fun getStorageClass ()Laws/sdk/kotlin/services/s3/model/StorageClass;
public fun getTargetIdentityId ()Ljava/lang/String;
public fun useAccelerateEndpoint ()Z
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
import java.util.concurrent.TimeUnit;

import aws.sdk.kotlin.services.s3.S3Client;
import aws.sdk.kotlin.services.s3.model.StorageClass;

/**
* A plugin for the storage category which uses S3 as a storage
Expand Down Expand Up @@ -579,6 +580,9 @@ public StorageUploadFileOperation<?> uploadFile(
options instanceof AWSS3StorageUploadFileOptions
? ((AWSS3StorageUploadFileOptions) options).getServerSideEncryption()
: ServerSideEncryption.NONE,
options instanceof AWSS3StorageUploadFileOptions
? ((AWSS3StorageUploadFileOptions) options).getStorageClass()
: StorageClass.Standard.INSTANCE,
options.getMetadata(),
useAccelerateEndpoint
);
Expand Down Expand Up @@ -617,6 +621,9 @@ public StorageUploadFileOperation<?> uploadFile(
options instanceof AWSS3StorageUploadFileOptions
? ((AWSS3StorageUploadFileOptions) options).getServerSideEncryption()
: ServerSideEncryption.NONE,
options instanceof AWSS3StorageUploadFileOptions
? ((AWSS3StorageUploadFileOptions) options).getStorageClass()
: StorageClass.Standard.INSTANCE,
options.getMetadata(),
useAccelerateEndpoint
);
Expand Down Expand Up @@ -707,6 +714,9 @@ public StorageUploadInputStreamOperation<?> uploadInputStream(
options instanceof AWSS3StorageUploadInputStreamOptions
? ((AWSS3StorageUploadInputStreamOptions) options).getServerSideEncryption()
: ServerSideEncryption.NONE,
options instanceof AWSS3StorageUploadInputStreamOptions
? ((AWSS3StorageUploadInputStreamOptions) options).getStorageClass()
: StorageClass.Standard.INSTANCE,
options.getMetadata(),
useAccelerateEndpoint
);
Expand Down Expand Up @@ -745,6 +755,9 @@ public StorageUploadInputStreamOperation<?> uploadInputStream(
options instanceof AWSS3StorageUploadInputStreamOptions
? ((AWSS3StorageUploadInputStreamOptions) options).getServerSideEncryption()
: ServerSideEncryption.NONE,
options instanceof AWSS3StorageUploadInputStreamOptions
? ((AWSS3StorageUploadInputStreamOptions) options).getStorageClass()
: StorageClass.Standard.INSTANCE,
options.getMetadata(),
useAccelerateEndpoint
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ internal class AWSS3StoragePathUploadFileOperation internal constructor(
objectMetadata.metaData[ObjectMetadata.SERVER_SIDE_ENCRYPTION] =
storageServerSideEncryption.getName()
}
objectMetadata.metaData[ObjectMetadata.STORAGE_CLASS] = uploadRequest.storageClass.value
transferObserver = storageService.uploadFile(
transferId,
serviceKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package com.amplifyframework.storage.s3.operation

import aws.sdk.kotlin.services.s3.model.StorageClass
import com.amplifyframework.auth.AuthCredentialsProvider
import com.amplifyframework.core.Amplify
import com.amplifyframework.core.Consumer
Expand Down Expand Up @@ -110,6 +111,7 @@ internal class AWSS3StoragePathUploadInputStreamOperation internal constructor(
objectMetadata.metaData[ObjectMetadata.SERVER_SIDE_ENCRYPTION] =
storageServerSideEncryption.getName()
}
objectMetadata.metaData[ObjectMetadata.STORAGE_CLASS] = request.storageClass.value
transferObserver = storageService.uploadInputStream(
transferId,
serviceKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class AWSS3StorageUploadFileOperation @JvmOverloads internal constructor(
objectMetadata.metaData[ObjectMetadata.SERVER_SIDE_ENCRYPTION] =
storageServerSideEncryption.getName()
}
objectMetadata.metaData[ObjectMetadata.STORAGE_CLASS] = uploadRequest.storageClass.value
transferObserver = storageService.uploadFile(
transferId,
serviceKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class AWSS3StorageUploadInputStreamOperation @JvmOverloads internal constructor(
objectMetadata.metaData[ObjectMetadata.SERVER_SIDE_ENCRYPTION] =
storageServerSideEncryption.getName()
}
objectMetadata.metaData[ObjectMetadata.STORAGE_CLASS] = uploadRequest.storageClass.value
transferObserver = storageService.uploadInputStream(
transferId,
serviceKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,20 @@

import java.util.Objects;

import aws.sdk.kotlin.services.s3.model.StorageClass;

/**
* Options to specify attributes of object upload operation to an AWS S3 bucket.
*/
public final class AWSS3StorageUploadFileOptions extends StorageUploadFileOptions {
private final ServerSideEncryption serverSideEncryption;
private final StorageClass storageClass;
private final boolean useAccelerationMode;

private AWSS3StorageUploadFileOptions(final Builder builder) {
super(builder);
this.serverSideEncryption = builder.getServerSideEncryption();
this.storageClass = builder.getStorageClass();
this.useAccelerationMode = builder.useAccelerateEndpoint;
}

Expand All @@ -45,6 +49,15 @@ public ServerSideEncryption getServerSideEncryption() {
return serverSideEncryption;
}

/**
* Storage class.
* @return Storage class
*/
@NonNull
public StorageClass getStorageClass() {
return storageClass;
}

/**
* Factory method to create a new instance of the
* {@link Builder}. The builder can be
Expand Down Expand Up @@ -75,6 +88,7 @@ public static Builder from(@NonNull final AWSS3StorageUploadFileOptions options)
.targetIdentityId(options.getTargetIdentityId())
.contentType(options.getContentType())
.serverSideEncryption(options.getServerSideEncryption())
.storageClass(options.getStorageClass())
.metadata(options.getMetadata());
}

Expand Down Expand Up @@ -109,6 +123,7 @@ public boolean equals(Object obj) {
ObjectsCompat.equals(getTargetIdentityId(), that.getTargetIdentityId()) &&
ObjectsCompat.equals(getContentType(), that.getContentType()) &&
ObjectsCompat.equals(getServerSideEncryption(), that.getServerSideEncryption()) &&
ObjectsCompat.equals(getStorageClass(), that.getStorageClass()) &&
ObjectsCompat.equals(getMetadata(), that.getMetadata());
}
}
Expand All @@ -121,6 +136,7 @@ public int hashCode() {
getTargetIdentityId(),
getContentType(),
getServerSideEncryption(),
getStorageClass(),
getMetadata()
);
}
Expand All @@ -134,6 +150,7 @@ public String toString() {
", targetIdentityId=" + getTargetIdentityId() +
", contentType=" + getContentType() +
", serverSideEncryption=" + getServerSideEncryption().getName() +
", storageClass=" + getStorageClass() +
", metadata=" + getMetadata() +
'}';
}
Expand All @@ -145,11 +162,13 @@ public String toString() {
*/
public static final class Builder extends StorageUploadFileOptions.Builder<Builder> {
private ServerSideEncryption serverSideEncryption;
private StorageClass storageClass;
private boolean useAccelerateEndpoint;

private Builder() {
super();
this.serverSideEncryption = ServerSideEncryption.NONE;
this.storageClass = StorageClass.Standard.INSTANCE;
}

/**
Expand All @@ -173,11 +192,27 @@ public Builder serverSideEncryption(@NonNull ServerSideEncryption serverSideEncr
return this;
}

/**
* Configures the storage class for a new AWSS3StorageUploadFileOptions instance.
* @param storageClass storage class
* @return Current Builder instance for fluent chaining
*/
@NonNull
public Builder storageClass(@NonNull StorageClass storageClass) {
this.storageClass = Objects.requireNonNull(storageClass);
return this;
}

@NonNull
ServerSideEncryption getServerSideEncryption() {
return serverSideEncryption;
}

@NonNull
StorageClass getStorageClass() {
return storageClass;
}

@Override
@NonNull
public AWSS3StorageUploadFileOptions build() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,20 @@

import java.util.Objects;

import aws.sdk.kotlin.services.s3.model.StorageClass;

/**
* Options to specify attributes of object upload operation to an AWS S3 bucket.
*/
public final class AWSS3StorageUploadInputStreamOptions extends StorageUploadInputStreamOptions {
private final ServerSideEncryption serverSideEncryption;
private final StorageClass storageClass;
private final boolean useAccelerationMode;

private AWSS3StorageUploadInputStreamOptions(final Builder builder) {
super(builder);
this.serverSideEncryption = builder.serverSideEncryption;
this.storageClass = builder.storageClass;
this.useAccelerationMode = builder.useAccelerateEndpoint;
}

Expand All @@ -45,6 +49,15 @@ public ServerSideEncryption getServerSideEncryption() {
return serverSideEncryption;
}

/**
* Storage class.
* @return Storage class
*/
@NonNull
public StorageClass getStorageClass() {
return storageClass;
}

/**
* Factory method to create a new instance of the
* {@link Builder}. The builder can be
Expand Down Expand Up @@ -75,6 +88,7 @@ public static Builder from(@NonNull final AWSS3StorageUploadInputStreamOptions o
.targetIdentityId(options.getTargetIdentityId())
.contentType(options.getContentType())
.serverSideEncryption(options.getServerSideEncryption())
.storageClass(options.getStorageClass())
.metadata(options.getMetadata());
}

Expand Down Expand Up @@ -109,6 +123,7 @@ public boolean equals(Object obj) {
ObjectsCompat.equals(getTargetIdentityId(), that.getTargetIdentityId()) &&
ObjectsCompat.equals(getContentType(), that.getContentType()) &&
ObjectsCompat.equals(getServerSideEncryption(), that.getServerSideEncryption()) &&
ObjectsCompat.equals(getStorageClass(), that.getStorageClass()) &&
ObjectsCompat.equals(getMetadata(), that.getMetadata());
}
}
Expand All @@ -121,6 +136,7 @@ public int hashCode() {
getTargetIdentityId(),
getContentType(),
getServerSideEncryption(),
getStorageClass(),
getMetadata()
);
}
Expand All @@ -134,6 +150,7 @@ public String toString() {
", targetIdentityId=" + getTargetIdentityId() +
", contentType=" + getContentType() +
", serverSideEncryption=" + getServerSideEncryption().getName() +
", storageClass=" + getStorageClass() +
", metadata=" + getMetadata() +
'}';
}
Expand All @@ -145,11 +162,13 @@ public String toString() {
*/
public static final class Builder extends StorageUploadInputStreamOptions.Builder<Builder> {
private ServerSideEncryption serverSideEncryption;
private StorageClass storageClass;
private boolean useAccelerateEndpoint;

private Builder() {
super();
this.serverSideEncryption = ServerSideEncryption.NONE;
this.storageClass = StorageClass.Standard.INSTANCE;
}

/**
Expand All @@ -173,6 +192,17 @@ public Builder serverSideEncryption(@NonNull ServerSideEncryption serverSideEncr
return this;
}

/**
* Configures the storage class for a new AWSS3StorageUploadInputStreamOptions instance.
* @param storageClass storage class
* @return Current Builder instance for fluent chaining
*/
@NonNull
public Builder storageClass(@NonNull StorageClass storageClass) {
this.storageClass = Objects.requireNonNull(storageClass);
return this;
}

@Override
@NonNull
public AWSS3StorageUploadInputStreamOptions build() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package com.amplifyframework.storage.s3.request

import aws.sdk.kotlin.services.s3.model.StorageClass
import com.amplifyframework.storage.StoragePath
import com.amplifyframework.storage.s3.ServerSideEncryption

Expand All @@ -26,6 +27,7 @@ internal data class AWSS3StoragePathUploadRequest<L>(
val local: L,
val contentType: String?,
val serverSideEncryption: ServerSideEncryption,
val storageClass: StorageClass,
val metadata: Map<String, String>,
val useAccelerateEndpoint: Boolean
)
Loading