Search in sources :

Example 1 with AwsAccessRole

use of com.google.cloud.bigquery.connection.v1.AwsAccessRole in project java-bigqueryconnection by googleapis.

the class CreateAwsConnectionIT method testCreateAwsConnection.

@Test
public void testCreateAwsConnection() throws IOException {
    String iamRoleId = String.format("arn:aws:iam::%s:role/%s", AWS_ACCOUNT_ID, AWS_ROLE_ID);
    AwsAccessRole awsRole = AwsAccessRole.newBuilder().setIamRoleId(iamRoleId).build();
    AwsProperties awsProperties = AwsProperties.newBuilder().setAccessRole(awsRole).build();
    Connection connection = Connection.newBuilder().setAws(awsProperties).build();
    CreateAwsConnection.createAwsConnection(PROJECT_ID, LOCATION, connectionId, connection);
    assertThat(bout.toString()).contains("Aws connection created successfully :");
}
Also used : AwsAccessRole(com.google.cloud.bigquery.connection.v1.AwsAccessRole) AwsProperties(com.google.cloud.bigquery.connection.v1.AwsProperties) Connection(com.google.cloud.bigquery.connection.v1.Connection) Test(org.junit.Test)

Example 2 with AwsAccessRole

use of com.google.cloud.bigquery.connection.v1.AwsAccessRole in project java-bigqueryconnection by googleapis.

the class CreateAwsConnection method createAwsConnection.

public static void createAwsConnection(String projectId, String location, String connectionId, Connection connection) throws IOException {
    try (ConnectionServiceClient client = ConnectionServiceClient.create()) {
        LocationName parent = LocationName.of(projectId, location);
        CreateConnectionRequest request = CreateConnectionRequest.newBuilder().setParent(parent.toString()).setConnection(connection).setConnectionId(connectionId).build();
        Connection response = client.createConnection(request);
        AwsAccessRole role = response.getAws().getAccessRole();
        System.out.println("Aws connection created successfully : Aws userId :" + role.getIamRoleId() + " Aws externalId :" + role.getIdentity());
    }
}
Also used : ConnectionServiceClient(com.google.cloud.bigqueryconnection.v1.ConnectionServiceClient) AwsAccessRole(com.google.cloud.bigquery.connection.v1.AwsAccessRole) Connection(com.google.cloud.bigquery.connection.v1.Connection) CreateConnectionRequest(com.google.cloud.bigquery.connection.v1.CreateConnectionRequest) LocationName(com.google.cloud.bigquery.connection.v1.LocationName)

Aggregations

AwsAccessRole (com.google.cloud.bigquery.connection.v1.AwsAccessRole)2 Connection (com.google.cloud.bigquery.connection.v1.Connection)2 AwsProperties (com.google.cloud.bigquery.connection.v1.AwsProperties)1 CreateConnectionRequest (com.google.cloud.bigquery.connection.v1.CreateConnectionRequest)1 LocationName (com.google.cloud.bigquery.connection.v1.LocationName)1 ConnectionServiceClient (com.google.cloud.bigqueryconnection.v1.ConnectionServiceClient)1 Test (org.junit.Test)1