use of software.amazon.awssdk.crt.s3.S3Client in project aws-java-nio-spi-for-s3 by awslabs.
the class S3ClientStore method clientForRegion.
private S3Client clientForRegion(String regionString) {
// It may be useful to further cache clients for regions although at some point clients for buckets may need to be
// specialized beyond just region end points.
Region region = regionString.equals("") ? Region.US_EAST_1 : Region.of(regionString);
logger.debug("bucket region is: '{}'", region.id());
return S3Client.builder().region(region).overrideConfiguration(conf -> conf.retryPolicy(builder -> builder.retryCondition(retryCondition).backoffStrategy(backoffStrategy))).build();
}
use of software.amazon.awssdk.crt.s3.S3Client in project aws-codeguru-cli by aws.
the class ArtifactAdapterTest method test_zipAndUpload_happyCaseBuildDir.
@Test
public void test_zipAndUpload_happyCaseBuildDir() throws Exception {
val tempDir = Files.createTempDirectory("test_zipAndUpload_happyCaseGitFilesOnly");
val bucketName = "some-bucket";
// only include files from the util dir.
val repoDir = Paths.get("./test-data/fake-repo");
val buildArtifacts = repoDir.resolve("build-dir/lib");
val config = Configuration.builder().s3Client(s3client).interactiveMode(false).build();
Answer<Object> answer = invocationOnMock -> {
Path filePath = invocationOnMock.getArgument(1);
if (!filePath.toString().contains("analysis-bin")) {
// only look at the artifacts.
return null;
}
Assertions.assertTrue(filePath.toFile().isFile());
try (val zipFile = new ZipFile(filePath.toFile())) {
val entries = zipFile.entries();
int count = 0;
while (entries.hasMoreElements()) {
val s = entries.nextElement().getName();
Assertions.assertTrue(s.endsWith("included.txt"));
// count the files that are not in the git folder.
count++;
}
Assertions.assertEquals(1, count);
}
return null;
};
doAnswer(answer).when(s3client).putObject(any(PutObjectRequest.class), any(Path.class));
val metaData = ArtifactAdapter.zipAndUpload(config, tempDir, repoDir, Arrays.asList(repoDir), Arrays.asList(buildArtifacts), bucketName);
Assertions.assertNotNull(metaData.getBuildKey());
Assertions.assertNotNull(metaData.getSourceKey());
}
use of software.amazon.awssdk.crt.s3.S3Client in project aws-codeguru-cli by aws.
the class ArtifactAdapterTest method test_zipAndUpload_happyCaseGitFilesOnly.
@Test
public void test_zipAndUpload_happyCaseGitFilesOnly() throws Exception {
val repoDir = Paths.get("./test-data/two-commits").toRealPath();
val tempDir = Files.createTempDirectory("test_zipAndUpload_happyCaseGitFilesOnly");
val bucketName = "some-bucket";
// only include files from the util dir.
final List<Path> buildDirs = Collections.emptyList();
val mockTerminal = new MockTextTerminal();
// answer No to the question if only files under version control should be scanned.
mockTerminal.getInputs().add("y");
val config = Configuration.builder().s3Client(s3client).interactiveMode(true).textIO(new TextIO(mockTerminal)).versionedFiles(Arrays.asList(repoDir.resolve("test.txt"))).build();
Answer<Object> answer = invocationOnMock -> {
Path filePath = invocationOnMock.getArgument(1);
Assertions.assertTrue(filePath.toFile().isFile());
try (val zipFile = new ZipFile(filePath.toFile())) {
val entries = zipFile.entries();
int count = 0;
while (entries.hasMoreElements()) {
val s = entries.nextElement().getName();
val original = repoDir.resolve(s).toFile();
Assertions.assertTrue(original.isFile(), "Not a valid file: " + original);
Assertions.assertFalse(s.startsWith(".."));
if (!s.startsWith("git/")) {
// count the files that are not in the git folder.
count++;
}
}
Assertions.assertEquals(1, count, "Unexpected number of files in zip.");
}
return null;
};
doAnswer(answer).when(s3client).putObject(any(PutObjectRequest.class), any(Path.class));
val metaData = ArtifactAdapter.zipAndUpload(config, tempDir, repoDir, Arrays.asList(repoDir), buildDirs, bucketName);
Assertions.assertNull(metaData.getBuildKey());
Assertions.assertNotNull(metaData.getSourceKey());
}
use of software.amazon.awssdk.crt.s3.S3Client in project aws-codeguru-cli by aws.
the class ArtifactAdapterTest method test_zipAndUpload_happyCaseSourceOnly.
@Test
public void test_zipAndUpload_happyCaseSourceOnly() throws Exception {
val repoDir = Paths.get("./");
// skip the test if the test container stripped to the top level .git folder
Assumptions.assumeTrue(repoDir.resolve(".git").toFile().isDirectory());
val tempDir = Files.createTempDirectory("test_zipAndUpload_happyCase");
val bucketName = "some-bucket";
val sourceDirs = Arrays.asList(Paths.get("src"));
final List<Path> buildDirs = Collections.emptyList();
val config = Configuration.builder().s3Client(s3client).build();
Answer<Object> answer = invocationOnMock -> {
Path filePath = invocationOnMock.getArgument(1);
Assertions.assertTrue(filePath.toFile().isFile());
try (val zipFile = new ZipFile(filePath.toFile())) {
val entries = zipFile.entries();
while (entries.hasMoreElements()) {
val s = entries.nextElement().getName();
val original = repoDir.resolve(s).toFile();
Assertions.assertTrue(original.isFile(), "Not a valid file: " + original);
Assertions.assertFalse(s.startsWith(".."));
}
}
return null;
};
doAnswer(answer).when(s3client).putObject(any(PutObjectRequest.class), any(Path.class));
val metaData = ArtifactAdapter.zipAndUpload(config, tempDir, repoDir, sourceDirs, buildDirs, bucketName);
Assertions.assertNull(metaData.getBuildKey());
Assertions.assertNotNull(metaData.getSourceKey());
}
use of software.amazon.awssdk.crt.s3.S3Client in project beam by apache.
the class S3WritableByteChannelTest method writeFromOptions.
private void writeFromOptions(S3Options options, boolean writeReadOnlyBuffer) throws IOException {
S3Client mockS3Client = mock(S3Client.class, withSettings().defaultAnswer(RETURNS_SMART_NULLS));
S3ResourceId path = S3ResourceId.fromUri("s3://bucket/dir/file");
Supplier channel = () -> new S3WritableByteChannel(mockS3Client, path, "text/plain", S3FileSystemConfiguration.fromS3Options(options));
write(mockS3Client, channel, path, options.getSSEAlgorithm(), toMd5(options.getSSECustomerKey()), options.getSSEKMSKeyId(), options.getS3UploadBufferSizeBytes(), options.getBucketKeyEnabled(), writeReadOnlyBuffer);
}
Aggregations