
com.blazebit.query.connector.gcp.iam.RoleDataFetcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of blaze-query-connector-google-gcp-iam Show documentation
Show all versions of blaze-query-connector-google-gcp-iam Show documentation
A multi-platform querying library
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright Blazebit
*/
package com.blazebit.query.connector.gcp.iam;
import com.blazebit.query.connector.base.DataFormats;
import com.blazebit.query.connector.gcp.base.GcpConnectorConfig;
import com.blazebit.query.connector.gcp.base.GcpConventionContext;
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 com.google.api.gax.core.CredentialsProvider;
import com.google.api.gax.rpc.PermissionDeniedException;
import com.google.cloud.iam.admin.v1.IAMClient;
import com.google.cloud.iam.admin.v1.IAMSettings;
import com.google.iam.admin.v1.ListRolesRequest;
import com.google.iam.admin.v1.Role;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* @author Christian Beikov
* @since 1.0.0
*/
public class RoleDataFetcher implements DataFetcher, Serializable {
public static final RoleDataFetcher INSTANCE = new RoleDataFetcher();
private RoleDataFetcher() {
}
@Override
public List fetch(DataFetchContext context) {
try {
List credentialsProviders = GcpConnectorConfig.GCP_CREDENTIALS_PROVIDER.getAll( context );
List list = new ArrayList<>();
for ( CredentialsProvider credentialsProvider : credentialsProviders ) {
final IAMSettings settings = IAMSettings.newBuilder()
.setCredentialsProvider(credentialsProvider)
.build();
try (IAMClient client = IAMClient.create( settings )) {
try {
final ListRolesRequest request = ListRolesRequest.newBuilder()
// .setName("970024905535")
// .setAddress(newAddressName)
// .setRegion(REGION)
.build();
final IAMClient.ListRolesPagedResponse response = client.listRoles( request );
for ( Role instance : response.iterateAll() ) {
list.add( instance );
}
}
catch (PermissionDeniedException e) {
if ( "SERVICE_DISABLED".equals( e.getErrorDetails().getErrorInfo().getReason() ) ) {
// Ignore this exception, since there are no resources
continue;
}
throw e;
}
}
}
return list;
}
catch (IOException e) {
throw new DataFetcherException( "Could not fetch role list", e );
}
}
@Override
public DataFormat getDataFormat() {
return DataFormats.beansConvention( Role.class, GcpConventionContext.INSTANCE );
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy