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.PublicAccessBlockConfiguration;

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

@Override
public PublicAccessBlockConfiguration getPayload() {
return super.getPayload();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public final class AwsS3SchemaProvider implements QuerySchemaProvider {
@Override
public Set<? extends DataFetcher<?>> resolveSchemaObjects(ConfigurationProvider configurationProvider) {
return Set.of(
BucketDataFetcher.INSTANCE
BucketDataFetcher.INSTANCE,
PublicAccessBlockConfigurationFetcher.INSTANCE
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ public List<AwsBucket> fetch(DataFetchContext context) {
List<AwsBucket> list = new ArrayList<>();
for ( AwsConnectorConfig.Account account : accounts ) {
for ( Region region : account.getRegions() ) {
S3ClientBuilder ec2ClientBuilder = S3Client.builder()
S3ClientBuilder s3ClientBuilder = S3Client.builder()
.region( region )
.credentialsProvider( account.getCredentialsProvider() );
if ( sdkHttpClient != null ) {
ec2ClientBuilder.httpClient( sdkHttpClient );
s3ClientBuilder.httpClient( sdkHttpClient );
}
try (S3Client client = ec2ClientBuilder.build()) {
try (S3Client client = s3ClientBuilder.build()) {
for ( Bucket bucket : client.listBuckets().buckets() ) {
list.add( new AwsBucket(
account.getAccountId(),
Expand All @@ -61,7 +61,7 @@ public List<AwsBucket> fetch(DataFetchContext context) {
return list;
}
catch (RuntimeException e) {
throw new DataFetcherException( "Could not fetch bucket list", e );
throw new DataFetcherException( "Could not fetch public access block configuration list", e );
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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 java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

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

public static final PublicAccessBlockConfigurationFetcher INSTANCE = new PublicAccessBlockConfigurationFetcher();

private PublicAccessBlockConfigurationFetcher() {
}

@Override
public List<AwsPublicAccessBlockConfiguration> fetch(DataFetchContext context) {
try {
List<AwsConnectorConfig.Account> accounts = AwsConnectorConfig.ACCOUNT.getAll( context );
SdkHttpClient sdkHttpClient = AwsConnectorConfig.HTTP_CLIENT.find( context );
List<AwsPublicAccessBlockConfiguration> 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 publicAccessBlockResponse = client.getPublicAccessBlock(r->r.bucket( bucket.name() ));
var publicAccessBlockConfiguration = publicAccessBlockResponse.publicAccessBlockConfiguration();
list.add( new AwsPublicAccessBlockConfiguration(
account.getAccountId(),
region.id(),
bucket.name(),
publicAccessBlockConfiguration
) );
}
}
}
}
return list;
}
catch (RuntimeException e) {
throw new DataFetcherException( "Could not fetch public access block configuration list", e );
}
}

@Override
public DataFormat getDataFormat() {
return DataFormats.componentMethodConvention( AwsPublicAccessBlockConfiguration.class, AwsConventionContext.INSTANCE );
}
}
9 changes: 9 additions & 0 deletions examples/app/src/main/java/com/blazebit/query/app/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.blazebit.query.connector.aws.rds.AwsDBInstance;
import com.blazebit.query.connector.aws.route53.AwsHealthCheck;
import com.blazebit.query.connector.aws.route53.AwsHostedZone;
import com.blazebit.query.connector.aws.s3.AwsPublicAccessBlockConfiguration;
import com.blazebit.query.connector.aws.s3.AwsBucket;
import com.blazebit.query.connector.azure.graph.AzureGraphAlert;
import com.blazebit.query.connector.azure.graph.AzureGraphApplication;
Expand Down Expand Up @@ -261,6 +262,8 @@ public static void main(String[] args) throws Exception {
queryContextBuilder.registerSchemaObjectAlias( AwsHealthCheck.class, "AwsHealthCheck" );
// S3
queryContextBuilder.registerSchemaObjectAlias( AwsBucket.class, "AwsBucket" );
queryContextBuilder.registerSchemaObjectAlias( AwsPublicAccessBlockConfiguration.class, "AwsPublicAccessBlockConfiguration" );


// Gitlab
queryContextBuilder.registerSchemaObjectAlias( Project.class, "GitlabProject" );
Expand Down Expand Up @@ -482,6 +485,12 @@ private static void testAws(QuerySession session) {
List<Object[]> awsBucketResult = awsBucketQuery.getResultList();
System.out.println("AwsBuckets");
print(awsBucketResult);

TypedQuery<Object[]> awsPublicAccessBlockConfigurationQuery = session.createQuery(
"select f.* from AwsPublicAccessBlockConfiguration f" );
List<Object[]> awsPublicAccessBlockConfigurationResult = awsPublicAccessBlockConfigurationQuery.getResultList();
System.out.println("AwsPublicAccessBlockConfiguration");
print(awsPublicAccessBlockConfigurationResult);
}

private static void testGitlab(QuerySession session) {
Expand Down