-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* In this commit I refactor BackblazePhotoImporter to enable unit testing (see next commit) * Add a test file for BackblazePhotosImporter and update the gradle file with new dependencies In this commit I added a test file for BackblazePhotosImporter and updated the gradle file with new dependencies required to run it. * Refactor BackblazeVideosImporter to enable unit testing Commit is corresponding to the one for the photos importer but this time we're changing the constructor of the video importer. The unit tests are added in the next commit * Add a test file for BackblazeVideosImporter In this commit I'm adding a file with unit tests for the video importer * Adding BaseBackblazeS3ClientFactory to enable unit testing on the client The following two commits refacor BackblazeDataTransferClient for facilitating BackblazeDataTransferClient unit testing. In this one I'm adding interface for client factory and adding a base class * Refactor BackblazeDataTransferClient and BackblazeDataTransferClientFactory to make use of BaseBackblazeS3ClientFactory In this commit I refactor BackblazeDataTransferClient and BackblazeDataTransferClientFactory to make use of BaseBackblazeS3ClientFactory * Add BackblazeDataTransferClientTest In the last commit I implement BackblazeDataTransferClientTest * Remove unused variable from BackblazeDataTransferClient Co-authored-by: William Morland <[email protected]>
- Loading branch information
Showing
12 changed files
with
669 additions
and
40 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
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
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
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
23 changes: 23 additions & 0 deletions
23
.../java/org/datatransferproject/datatransfer/backblaze/common/BackblazeS3ClientFactory.java
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,23 @@ | ||
/* | ||
* Copyright 2021 The Data Transfer Project Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.datatransferproject.datatransfer.backblaze.common; | ||
|
||
import software.amazon.awssdk.services.s3.S3Client; | ||
|
||
public interface BackblazeS3ClientFactory { | ||
S3Client createS3Client(String accessKey, String secretKey, String region); | ||
} |
45 changes: 45 additions & 0 deletions
45
...a/org/datatransferproject/datatransfer/backblaze/common/BaseBackblazeS3ClientFactory.java
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,45 @@ | ||
/* | ||
* Copyright 2021 The Data Transfer Project Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.datatransferproject.datatransfer.backblaze.common; | ||
|
||
import java.net.URI; | ||
import software.amazon.awssdk.auth.credentials.AwsSessionCredentials; | ||
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; | ||
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; | ||
import software.amazon.awssdk.regions.Region; | ||
import software.amazon.awssdk.services.s3.S3Client; | ||
|
||
public class BaseBackblazeS3ClientFactory implements BackblazeS3ClientFactory { | ||
private static final String S3_ENDPOINT_FORMAT_STRING = "https://s3.%s.backblazeb2.com"; | ||
|
||
public S3Client createS3Client(String accessKey, String secretKey, String region) { | ||
AwsSessionCredentials awsCreds = AwsSessionCredentials.create(accessKey, secretKey, ""); | ||
|
||
ClientOverrideConfiguration clientOverrideConfiguration = | ||
ClientOverrideConfiguration.builder().putHeader("User-Agent", "Facebook-DTP").build(); | ||
|
||
// Use any AWS region for the client, the Backblaze API does not care about it | ||
Region awsRegion = Region.US_EAST_1; | ||
|
||
return S3Client.builder() | ||
.credentialsProvider(StaticCredentialsProvider.create(awsCreds)) | ||
.overrideConfiguration(clientOverrideConfiguration) | ||
.endpointOverride(URI.create(String.format(S3_ENDPOINT_FORMAT_STRING, region))) | ||
.region(awsRegion) | ||
.build(); | ||
} | ||
} |
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
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
Oops, something went wrong.