Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright Blazebit
*/
package com.blazebit.query.connector.aws.s3;

import com.blazebit.query.connector.aws.base.AwsWrapper;
import software.amazon.awssdk.services.s3.model.GetBucketVersioningResponse;

/**
* @author Donghwi Kim
* @since 1.0.0
*/
public class AwsBucketVersioning extends AwsWrapper<GetBucketVersioningResponse> {
public AwsBucketVersioning(String accountId, String region, String resourceId, GetBucketVersioningResponse payload) {
super( accountId, region, resourceId, payload );
}

@Override
public GetBucketVersioningResponse getPayload() {
return super.getPayload();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public Set<? extends DataFetcher<?>> resolveSchemaObjects(ConfigurationProvider
return Set.of(
BucketDataFetcher.INSTANCE,
BucketAclFetcher.INSTANCE,
BucketVersioningFetcher.INSTANCE,
BucketPolicyFetcher.INSTANCE,
LifecycleRuleFetcher.INSTANCE,
LoggingEnabledFetcher.INSTANCE,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright Blazebit
*/
package com.blazebit.query.connector.aws.s3;

import com.blazebit.query.connector.aws.base.AwsConnectorConfig;
import com.blazebit.query.connector.aws.base.AwsConventionContext;
import com.blazebit.query.connector.base.DataFormats;
import com.blazebit.query.spi.DataFetchContext;
import com.blazebit.query.spi.DataFetcher;
import com.blazebit.query.spi.DataFetcherException;
import com.blazebit.query.spi.DataFormat;
import software.amazon.awssdk.http.SdkHttpClient;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.S3ClientBuilder;
import software.amazon.awssdk.services.s3.model.Bucket;
import software.amazon.awssdk.services.s3.model.GetBucketVersioningRequest;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
* @author Donghwi Kim
* @since 1.0.0
*/
public class BucketVersioningFetcher implements DataFetcher<AwsBucketVersioning>, Serializable {

public static final BucketVersioningFetcher INSTANCE = new BucketVersioningFetcher();

private BucketVersioningFetcher() {
}

@Override
public List<AwsBucketVersioning> fetch(DataFetchContext context) {
try {
List<AwsConnectorConfig.Account> accounts = AwsConnectorConfig.ACCOUNT.getAll( context );
SdkHttpClient sdkHttpClient = AwsConnectorConfig.HTTP_CLIENT.find( context );
List<AwsBucketVersioning> list = new ArrayList<>();
for ( AwsConnectorConfig.Account account : accounts ) {
for ( Region region : account.getRegions() ) {
S3ClientBuilder s3ClientBuilder = S3Client.builder()
.region( region )
.credentialsProvider( account.getCredentialsProvider() );
if ( sdkHttpClient != null ) {
s3ClientBuilder.httpClient( sdkHttpClient );
}
try (S3Client client = s3ClientBuilder.build()) {
for ( Bucket bucket : client.listBuckets().buckets() ) {
var bucketVersioning = client.getBucketVersioning(
GetBucketVersioningRequest.builder().bucket( bucket.name() )
.build() );
list.add( new AwsBucketVersioning(
account.getAccountId(),
region.id(),
bucket.name(),
bucketVersioning
) );
}
}
}
}
return list;
}
catch (Exception e) {
throw new DataFetcherException( "Could not fetch bucket versioning list", e );
}
}

@Override
public DataFormat getDataFormat() {
return DataFormats.componentMethodConvention( AwsBucketVersioning.class, AwsConventionContext.INSTANCE );
}
}
10 changes: 9 additions & 1 deletion examples/app/src/main/java/com/blazebit/query/app/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.blazebit.query.connector.aws.route53.AwsHealthCheck;
import com.blazebit.query.connector.aws.route53.AwsHostedZone;
import com.blazebit.query.connector.aws.s3.AwsBucketAcl;
import com.blazebit.query.connector.aws.s3.AwsBucketVersioning;
import com.blazebit.query.connector.aws.s3.AwsBucketPolicy;
import com.blazebit.query.connector.aws.s3.AwsLoggingEnabled;
import com.blazebit.query.connector.aws.s3.AwsObjectLockConfiguration;
Expand Down Expand Up @@ -282,6 +283,7 @@ public static void main(String[] args) throws Exception {
// S3
queryContextBuilder.registerSchemaObjectAlias( AwsBucket.class, "AwsBucket" );
queryContextBuilder.registerSchemaObjectAlias( AwsBucketAcl.class, "AwsBucketAcl" );
queryContextBuilder.registerSchemaObjectAlias( AwsBucketVersioning.class, "AwsBucketVersioning" );
queryContextBuilder.registerSchemaObjectAlias( AwsBucketPolicy.class, "AwsBucketPolicy" );
queryContextBuilder.registerSchemaObjectAlias( AwsLifeCycleRule.class, "AwsLifeCycleRule" );
queryContextBuilder.registerSchemaObjectAlias( AwsLoggingEnabled.class, "AwsLoggingEnabled" );
Expand Down Expand Up @@ -552,7 +554,13 @@ private static void testAws(QuerySession session) {
System.out.println("AwsBucketAcl");
print(awsBucketAclResult);

TypedQuery<Object[]> awsBucketPolicyQuery = session.createQuery(
TypedQuery<Object[]> awsBucketVersioningQuery = session.createQuery(
"select f.* from AwsBucketVersioning f" );
List<Object[]> awsBucketVersioningResult = awsBucketVersioningQuery.getResultList();
System.out.println("AwsBucketVersioning");
print(awsBucketVersioningResult);

TypedQuery<Object[]> awsBucketPolicyQuery = session.createQuery(
"select f.* from AwsBucketPolicy f" );
List<Object[]> awsBucketPolicyResult = awsBucketPolicyQuery.getResultList();
System.out.println("AwsBucketPolicy");
Expand Down