Skip to content

Commit

Permalink
feat: Added empty-stream struct replication
Browse files Browse the repository at this point in the history
  • Loading branch information
jruaux committed Jun 26, 2024
1 parent f9ec9e8 commit 7477892
Show file tree
Hide file tree
Showing 26 changed files with 338 additions and 225 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ subprojects { subproj ->

configurations {
all*.exclude module: 'spring-boot-starter-logging'
all*.exclude module: 'commons-logging'
}

bootJar {
Expand Down
9 changes: 3 additions & 6 deletions connectors/riot-file/riot-file.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,14 @@
* limitations under the License.
*/
dependencies {
api group: 'info.picocli', name: 'picocli', version: picocliVersion
implementation group: 'info.picocli', name: 'picocli', version: picocliVersion
annotationProcessor group: 'info.picocli', name: 'picocli-codegen', version: picocliVersion
implementation 'org.springframework.batch:spring-batch-infrastructure'
implementation group: 'com.redis', name: 'spring-batch-resource', version: springBatchRedisVersion
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml'
implementation 'org.springframework:spring-oxm'
implementation group: 'org.springframework.cloud', name: 'spring-cloud-aws-context', version: awsVersion
implementation group: 'org.springframework.cloud', name: 'spring-cloud-aws-autoconfigure', version: awsVersion
implementation(group: 'org.springframework.cloud', name: 'spring-cloud-gcp-starter-storage', version: gcpVersion) {
exclude group: 'javax.annotation', module: 'javax.annotation-api'
}
implementation group: 'io.awspring.cloud', name: 'spring-cloud-aws-starter-s3', version: awsVersion
implementation group: 'com.google.cloud', name: 'spring-cloud-gcp-starter-storage', version: gcpVersion
testImplementation group: 'com.redis', name: 'spring-batch-redis-test', version: springBatchRedisVersion
}

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.redis.riot.file;

import java.net.URI;

import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

import io.awspring.cloud.s3.InMemoryBufferingS3OutputStreamProvider;
import io.awspring.cloud.s3.Location;
import io.awspring.cloud.s3.PropertiesS3ObjectContentTypeResolver;
import io.awspring.cloud.s3.S3Resource;
import picocli.CommandLine.ArgGroup;
import picocli.CommandLine.Option;
import software.amazon.awssdk.auth.credentials.AnonymousCredentialsProvider;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.S3ClientBuilder;

public class AwsArgs {

@ArgGroup(exclusive = false)
private AwsCredentialsArgs credentialsArgs;

@Option(names = "--s3-region", description = "Region to use for the AWS client (e.g. us-west-1).", paramLabel = "<name>")
private Region region;

@Option(names = "--s3-endpoint", description = "Service endpoint with which the AWS client should communicate (e.g. https://sns.us-west-1.amazonaws.com).", paramLabel = "<url>")
private URI endpoint;

public static boolean isSimpleStorageResource(String location) {
Assert.notNull(location, "Location must not be null");
return location.toLowerCase().startsWith(Location.S3_PROTOCOL_PREFIX);
}

public Resource resource(String location) {
S3ClientBuilder clientBuilder = S3Client.builder();
if (region != null) {
clientBuilder.region(region);
}
if (endpoint != null) {
clientBuilder.endpointOverride(endpoint);
}
clientBuilder.credentialsProvider(credentialsProvider());
S3Client client = clientBuilder.build();
InMemoryBufferingS3OutputStreamProvider outputStreamProvider = new InMemoryBufferingS3OutputStreamProvider(
client, new PropertiesS3ObjectContentTypeResolver());
return S3Resource.create(location, client, outputStreamProvider);
}

private AwsCredentialsProvider credentialsProvider() {
if (credentialsArgs != null && StringUtils.hasText(credentialsArgs.getAccessKey())
&& StringUtils.hasText(credentialsArgs.getSecretKey())) {
AwsBasicCredentials credentials = AwsBasicCredentials.create(credentialsArgs.getAccessKey(),
credentialsArgs.getSecretKey());
return StaticCredentialsProvider.create(credentials);
}
return AnonymousCredentialsProvider.create();
}

public AwsCredentialsArgs getCredentialsArgs() {
return credentialsArgs;
}

public void setCredentialsArgs(AwsCredentialsArgs args) {
this.credentialsArgs = args;
}

public Region getRegion() {
return region;
}

public void setRegion(Region region) {
this.region = region;
}

public URI getEndpoint() {
return endpoint;
}

public void setEndpoint(URI endpoint) {
this.endpoint = endpoint;
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
package com.redis.riot.file;

import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;

import picocli.CommandLine.Option;

public class AmazonS3CredentialsArgs {
public class AwsCredentialsArgs {

@Option(names = "--s3-access", required = true, description = "AWS access key.", paramLabel = "<key>")
private String accessKey;

@Option(names = "--s3-secret", required = true, arity = "0..1", interactive = true, description = "AWS secret key.", paramLabel = "<key>")
private String secretKey;

public AWSCredentialsProvider credentials() {
BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
return new AWSStaticCredentialsProvider(credentials);
}

public String getAccessKey() {
return accessKey;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class FileArgs {
public static final char DEFAULT_QUOTE_CHARACTER = '"';

@ArgGroup(exclusive = false)
private AmazonS3Args amazonS3Args = new AmazonS3Args();
private AwsArgs amazonS3Args = new AwsArgs();

@ArgGroup(exclusive = false)
private GoogleStorageArgs googleStorageArgs = new GoogleStorageArgs();
Expand Down Expand Up @@ -51,7 +51,7 @@ public FileType fileType(Resource resource) {
}

public Resource resource(String location) throws IOException {
if (AmazonS3Args.isSimpleStorageResource(location)) {
if (AwsArgs.isSimpleStorageResource(location)) {
return amazonS3Args.resource(location);
}
if (GoogleStorageArgs.isGoogleStorageResource(location)) {
Expand Down Expand Up @@ -91,11 +91,11 @@ public void setGoogleStorageArgs(GoogleStorageArgs args) {
this.googleStorageArgs = args;
}

public AmazonS3Args getAmazonS3Args() {
public AwsArgs getAmazonS3Args() {
return amazonS3Args;
}

public void setAmazonS3Args(AmazonS3Args args) {
public void setAmazonS3Args(AwsArgs args) {
this.amazonS3Args = args;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import org.springframework.core.io.Resource;
import org.springframework.util.ResourceUtils;

import picocli.CommandLine;
import software.amazon.awssdk.regions.Region;

public abstract class FileUtils {

public static final Pattern EXTENSION_PATTERN = Pattern.compile("(?i)\\.(?<extension>\\w+)(?:\\.(?<gz>gz))?$");
Expand Down Expand Up @@ -88,7 +91,7 @@ public static boolean isStdin(String file) {
}

public static boolean isFile(String file) {
return !AmazonS3Args.isSimpleStorageResource(file) && !GoogleStorageArgs.isGoogleStorageResource(file)
return !AwsArgs.isSimpleStorageResource(file) && !GoogleStorageArgs.isGoogleStorageResource(file)
&& !ResourceUtils.isUrl(file) && !isStdin(file);
}

Expand All @@ -109,4 +112,8 @@ public static List<Path> expand(Path path) {
}
}

public static void registerConverters(CommandLine commandLine) {
commandLine.registerConverter(Region.class, Region::of);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
import java.io.OutputStream;
import java.util.zip.GZIPOutputStream;

import org.springframework.cloud.gcp.core.GcpScope;
import org.springframework.core.io.Resource;
import org.springframework.core.io.WritableResource;
import org.springframework.util.Assert;

import com.google.cloud.spring.core.GcpScope;

import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
import java.nio.file.Files;
import java.util.Base64;

import org.springframework.cloud.gcp.autoconfigure.storage.GcpStorageAutoConfiguration;
import org.springframework.cloud.gcp.core.GcpScope;
import org.springframework.cloud.gcp.core.UserAgentHeaderProvider;
import org.springframework.cloud.gcp.storage.GoogleStorageResource;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;

import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.ServiceOptions;
import com.google.cloud.spring.autoconfigure.storage.GcpStorageAutoConfiguration;
import com.google.cloud.spring.core.GcpScope;
import com.google.cloud.spring.core.UserAgentHeaderProvider;
import com.google.cloud.spring.storage.GoogleStorageResource;
import com.google.cloud.storage.StorageOptions;

import picocli.CommandLine.Option;
Expand Down
Loading

0 comments on commit 7477892

Please sign in to comment.