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): update storage API options to include bucket #2896

Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,8 @@ public StorageGetUrlOperation<?> getUrl(
AWSS3StorageService storageService = defaultStorageService;
try {
storageService = getStorageService(options.getBucket());
} catch (InvalidStorageBucketException exception) {
onError.accept(
new StorageException(
"Unable to find bucket from name in Amplify Outputs.",
exception,
"Ensure the bucket name used is available in Amplify Outputs.")
);
} catch (StorageException exception) {
onError.accept(exception);
}

AWSS3StorageGetPresignedUrlOperation operation =
Expand Down Expand Up @@ -409,13 +404,8 @@ public StorageGetUrlOperation<?> getUrl(
AWSS3StorageService storageService = defaultStorageService;
try {
storageService = getStorageService(options.getBucket());
} catch (InvalidStorageBucketException exception) {
onError.accept(
new StorageException(
"Unable to find bucket from name in Amplify Outputs.",
exception,
"Ensure the bucket name used is available in Amplify Outputs.")
);
} catch (StorageException exception) {
onError.accept(exception);
}

AWSS3StoragePathGetPresignedUrlOperation operation =
Expand Down Expand Up @@ -505,8 +495,15 @@ public StorageDownloadFileOperation<?> downloadFile(
useAccelerateEndpoint
);

AWSS3StorageService storageService = defaultStorageService;
try {
storageService = getStorageService(options.getBucket());
} catch (StorageException exception) {
onError.accept(exception);
}

AWSS3StorageDownloadFileOperation operation = new AWSS3StorageDownloadFileOperation(
defaultStorageService,
storageService,
executorService,
authCredentialsProvider,
request,
Expand Down Expand Up @@ -540,9 +537,16 @@ public StorageDownloadFileOperation<?> downloadFile(
useAccelerateEndpoint
);

AWSS3StorageService storageService = defaultStorageService;
try {
storageService = getStorageService(options.getBucket());
} catch (StorageException exception) {
onError.accept(exception);
}

AWSS3StoragePathDownloadFileOperation operation = new AWSS3StoragePathDownloadFileOperation(
request,
defaultStorageService,
storageService,
executorService,
authCredentialsProvider,
onProgress,
Expand Down Expand Up @@ -632,8 +636,15 @@ public StorageUploadFileOperation<?> uploadFile(
useAccelerateEndpoint
);

AWSS3StorageService storageService = defaultStorageService;
try {
storageService = getStorageService(options.getBucket());
} catch (StorageException exception) {
onError.accept(exception);
}

AWSS3StorageUploadFileOperation operation = new AWSS3StorageUploadFileOperation(
defaultStorageService,
storageService,
executorService,
authCredentialsProvider,
request,
Expand Down Expand Up @@ -670,9 +681,16 @@ public StorageUploadFileOperation<?> uploadFile(
useAccelerateEndpoint
);

AWSS3StorageService storageService = defaultStorageService;
try {
storageService = getStorageService(options.getBucket());
} catch (StorageException exception) {
onError.accept(exception);
}

AWSS3StoragePathUploadFileOperation operation = new AWSS3StoragePathUploadFileOperation(
request,
defaultStorageService,
storageService,
executorService,
authCredentialsProvider,
onProgress,
Expand Down Expand Up @@ -760,8 +778,15 @@ public StorageUploadInputStreamOperation<?> uploadInputStream(
useAccelerateEndpoint
);

AWSS3StorageService storageService = defaultStorageService;
try {
storageService = getStorageService(options.getBucket());
} catch (StorageException exception) {
onError.accept(exception);
}

AWSS3StorageUploadInputStreamOperation operation = new AWSS3StorageUploadInputStreamOperation(
defaultStorageService,
storageService,
executorService,
authCredentialsProvider,
awsS3StoragePluginConfiguration,
Expand Down Expand Up @@ -798,10 +823,17 @@ public StorageUploadInputStreamOperation<?> uploadInputStream(
useAccelerateEndpoint
);

AWSS3StorageService storageService = defaultStorageService;
try {
storageService = getStorageService(options.getBucket());
} catch (StorageException exception) {
onError.accept(exception);
}

AWSS3StoragePathUploadInputStreamOperation operation =
new AWSS3StoragePathUploadInputStreamOperation(
request,
defaultStorageService,
storageService,
executorService,
authCredentialsProvider,
onProgress,
Expand Down Expand Up @@ -851,9 +883,16 @@ public StorageRemoveOperation<?> remove(
options.getTargetIdentityId()
);

AWSS3StorageService storageService = defaultStorageService;
try {
storageService = getStorageService(options.getBucket());
} catch (StorageException exception) {
onError.accept(exception);
}

AWSS3StorageRemoveOperation operation =
new AWSS3StorageRemoveOperation(
defaultStorageService,
storageService,
executorService,
authCredentialsProvider,
request,
Expand All @@ -876,9 +915,16 @@ public StorageRemoveOperation<?> remove(
) {
AWSS3StoragePathRemoveRequest request = new AWSS3StoragePathRemoveRequest(path);

AWSS3StorageService storageService = defaultStorageService;
try {
storageService = getStorageService(options.getBucket());
} catch (StorageException exception) {
onError.accept(exception);
}

AWSS3StoragePathRemoveOperation operation =
new AWSS3StoragePathRemoveOperation(
defaultStorageService,
storageService,
executorService,
authCredentialsProvider,
request,
Expand Down Expand Up @@ -1053,15 +1099,18 @@ public StorageListOperation<?> list(
@SuppressLint("UnsafeOptInUsageError")
@VisibleForTesting
@NonNull
AWSS3StorageService getStorageService(@Nullable StorageBucket bucket) throws InvalidStorageBucketException {
AWSS3StorageService getStorageService(@Nullable StorageBucket bucket) throws StorageException {
if (bucket == null) {
return defaultStorageService;
}

if (bucket instanceof OutputsStorageBucket) {
AWSS3StorageService service = getAWSS3StorageService((OutputsStorageBucket) bucket);
if (service == null) {
throw new InvalidStorageBucketException();
throw new StorageException(
"Unable to find bucket from name in Amplify Outputs.",
new InvalidStorageBucketException(),
"Ensure the bucket name used is available in Amplify Outputs.");
} else {
return service;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ public static Builder builder() {
@SuppressWarnings("deprecation")
public static Builder from(@NonNull final AWSS3StorageDownloadFileOptions options) {
return builder()
.accessLevel(options.getAccessLevel())
.targetIdentityId(options.getTargetIdentityId())
.setUseAccelerateEndpoint(options.useAccelerateEndpoint());
.accessLevel(options.getAccessLevel())
.targetIdentityId(options.getTargetIdentityId())
.setUseAccelerateEndpoint(options.useAccelerateEndpoint())
.bucket(options.getBucket());
}

/**
Expand Down Expand Up @@ -90,7 +91,8 @@ public boolean equals(Object obj) {
} else {
AWSS3StorageDownloadFileOptions that = (AWSS3StorageDownloadFileOptions) obj;
return ObjectsCompat.equals(getAccessLevel(), that.getAccessLevel()) &&
ObjectsCompat.equals(getTargetIdentityId(), that.getTargetIdentityId());
ObjectsCompat.equals(getTargetIdentityId(), that.getTargetIdentityId()) &&
ObjectsCompat.equals(getBucket(), that.getBucket());
}
}

Expand All @@ -99,7 +101,8 @@ public boolean equals(Object obj) {
public int hashCode() {
return ObjectsCompat.hash(
getAccessLevel(),
getTargetIdentityId()
getTargetIdentityId(),
getBucket()
);
}

Expand All @@ -111,6 +114,7 @@ public String toString() {
"accessLevel=" + getAccessLevel() +
", targetIdentityId=" + getTargetIdentityId() +
", useAccelerationMode=" + useAccelerateEndpoint() +
", bucket=" + getBucket() +
'}';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ public static Builder builder() {
@SuppressWarnings("deprecation")
public static Builder from(@NonNull final AWSS3StorageListOptions options) {
return builder()
.accessLevel(options.getAccessLevel())
.targetIdentityId(options.getTargetIdentityId());
.accessLevel(options.getAccessLevel())
.targetIdentityId(options.getTargetIdentityId())
.bucket(options.getBucket());
}

/**
Expand All @@ -78,7 +79,8 @@ public boolean equals(Object obj) {
} else {
AWSS3StorageListOptions that = (AWSS3StorageListOptions) obj;
return ObjectsCompat.equals(getAccessLevel(), that.getAccessLevel()) &&
ObjectsCompat.equals(getTargetIdentityId(), that.getTargetIdentityId());
ObjectsCompat.equals(getTargetIdentityId(), that.getTargetIdentityId()) &&
ObjectsCompat.equals(getBucket(), that.getBucket());
}
}

Expand All @@ -87,7 +89,8 @@ public boolean equals(Object obj) {
public int hashCode() {
return ObjectsCompat.hash(
getAccessLevel(),
getTargetIdentityId()
getTargetIdentityId(),
getBucket()
);
}

Expand All @@ -98,6 +101,7 @@ public String toString() {
return "AWSS3StorageListOptions {" +
"accessLevel=" + getAccessLevel() +
", targetIdentityId=" + getTargetIdentityId() +
", bucket=" + getBucket() +
'}';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ public static Builder builder() {
@SuppressWarnings("deprecation")
public static Builder from(@NonNull final AWSS3StorageRemoveOptions options) {
return builder()
.accessLevel(options.getAccessLevel())
.targetIdentityId(options.getTargetIdentityId());
.accessLevel(options.getAccessLevel())
.targetIdentityId(options.getTargetIdentityId())
.bucket(options.getBucket());
}

/**
Expand All @@ -79,7 +80,8 @@ public boolean equals(Object obj) {
} else {
AWSS3StorageRemoveOptions that = (AWSS3StorageRemoveOptions) obj;
return ObjectsCompat.equals(getAccessLevel(), that.getAccessLevel()) &&
ObjectsCompat.equals(getTargetIdentityId(), that.getTargetIdentityId());
ObjectsCompat.equals(getTargetIdentityId(), that.getTargetIdentityId()) &&
ObjectsCompat.equals(getBucket(), that.getBucket());
}
}

Expand All @@ -88,7 +90,8 @@ public boolean equals(Object obj) {
public int hashCode() {
return ObjectsCompat.hash(
getAccessLevel(),
getTargetIdentityId()
getTargetIdentityId(),
getBucket()
);
}

Expand All @@ -99,6 +102,7 @@ public String toString() {
return "AWSS3StorageRemoveOptions {" +
"accessLevel=" + getAccessLevel() +
", targetIdentityId=" + getTargetIdentityId() +
", bucket=" + getBucket() +
'}';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ public static Builder builder() {
@SuppressWarnings("deprecation")
public static Builder from(@NonNull final AWSS3StorageUploadFileOptions options) {
return builder()
.accessLevel(options.getAccessLevel())
.targetIdentityId(options.getTargetIdentityId())
.contentType(options.getContentType())
.serverSideEncryption(options.getServerSideEncryption())
.metadata(options.getMetadata());
.accessLevel(options.getAccessLevel())
.targetIdentityId(options.getTargetIdentityId())
.contentType(options.getContentType())
.serverSideEncryption(options.getServerSideEncryption())
.metadata(options.getMetadata())
.bucket(options.getBucket());
}

/**
Expand Down Expand Up @@ -109,7 +110,8 @@ public boolean equals(Object obj) {
ObjectsCompat.equals(getTargetIdentityId(), that.getTargetIdentityId()) &&
ObjectsCompat.equals(getContentType(), that.getContentType()) &&
ObjectsCompat.equals(getServerSideEncryption(), that.getServerSideEncryption()) &&
ObjectsCompat.equals(getMetadata(), that.getMetadata());
ObjectsCompat.equals(getMetadata(), that.getMetadata()) &&
ObjectsCompat.equals(getBucket(), that.getBucket());
}
}

Expand All @@ -121,7 +123,8 @@ public int hashCode() {
getTargetIdentityId(),
getContentType(),
getServerSideEncryption(),
getMetadata()
getMetadata(),
getBucket()
);
}

Expand All @@ -135,6 +138,7 @@ public String toString() {
", contentType=" + getContentType() +
", serverSideEncryption=" + getServerSideEncryption().getName() +
", metadata=" + getMetadata() +
", bucket=" + getBucket() +
'}';
}

Expand Down
Loading