use of com.google.cloud.billing.v1.ProjectBillingInfo in project terra-resource-buffer by DataBiosphere.
the class SetBillingInfoStep method doStep.
@Override
public StepResult doStep(FlightContext flightContext) {
// Skip if billing account is not set.
if (gcpProjectConfig.getBillingAccount() == null || gcpProjectConfig.getBillingAccount().isEmpty()) {
return StepResult.getStepResultSuccess();
}
String projectId = flightContext.getWorkingMap().get(GOOGLE_PROJECT_ID, String.class);
ProjectBillingInfo setBilling = ProjectBillingInfo.newBuilder().setBillingAccountName("billingAccounts/" + gcpProjectConfig.getBillingAccount()).build();
billingCow.updateProjectBillingInfo(projectIdToName(projectId), setBilling);
return StepResult.getStepResultSuccess();
}
use of com.google.cloud.billing.v1.ProjectBillingInfo in project terra-cloud-resource-lib by DataBiosphere.
the class CloudBillingUtils method setDefaultProjectBilling.
/**
* Sets the projects billing account with the default billing used for test.
*/
public static void setDefaultProjectBilling(String projectId) throws Exception {
ProjectBillingInfo setBilling = ProjectBillingInfo.newBuilder().setBillingAccountName(BILLING_ACCOUNT_NAME).build();
getBillingClientCow().updateProjectBillingInfo("projects/" + projectId, setBilling);
// Sleep for 1s to make sure billing is ready.
Thread.sleep(1000);
}
use of com.google.cloud.billing.v1.ProjectBillingInfo in project java-billing by googleapis.
the class CloudBillingClientTest method listProjectBillingInfoTest2.
@Test
public void listProjectBillingInfoTest2() throws Exception {
ProjectBillingInfo responsesElement = ProjectBillingInfo.newBuilder().build();
ListProjectBillingInfoResponse expectedResponse = ListProjectBillingInfoResponse.newBuilder().setNextPageToken("").addAllProjectBillingInfo(Arrays.asList(responsesElement)).build();
mockCloudBilling.addResponse(expectedResponse);
String name = "name3373707";
ListProjectBillingInfoPagedResponse pagedListResponse = client.listProjectBillingInfo(name);
List<ProjectBillingInfo> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getProjectBillingInfoList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockCloudBilling.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListProjectBillingInfoRequest actualRequest = ((ListProjectBillingInfoRequest) actualRequests.get(0));
Assert.assertEquals(name, actualRequest.getName());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.billing.v1.ProjectBillingInfo in project java-billing by googleapis.
the class CloudBillingClientTest method listProjectBillingInfoTest.
@Test
public void listProjectBillingInfoTest() throws Exception {
ProjectBillingInfo responsesElement = ProjectBillingInfo.newBuilder().build();
ListProjectBillingInfoResponse expectedResponse = ListProjectBillingInfoResponse.newBuilder().setNextPageToken("").addAllProjectBillingInfo(Arrays.asList(responsesElement)).build();
mockCloudBilling.addResponse(expectedResponse);
BillingAccountName name = BillingAccountName.of("[BILLING_ACCOUNT]");
ListProjectBillingInfoPagedResponse pagedListResponse = client.listProjectBillingInfo(name);
List<ProjectBillingInfo> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getProjectBillingInfoList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockCloudBilling.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListProjectBillingInfoRequest actualRequest = ((ListProjectBillingInfoRequest) actualRequests.get(0));
Assert.assertEquals(name.toString(), actualRequest.getName());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.billing.v1.ProjectBillingInfo in project terra-workspace-manager by DataBiosphere.
the class SetProjectBillingStep method doStep.
@Override
public StepResult doStep(FlightContext flightContext) {
String projectId = flightContext.getWorkingMap().get(WorkspaceFlightMapKeys.GCP_PROJECT_ID, String.class);
String billingAccountId = flightContext.getWorkingMap().get(WorkspaceFlightMapKeys.BILLING_ACCOUNT_ID, String.class);
ProjectBillingInfo setBilling = ProjectBillingInfo.newBuilder().setBillingAccountName("billingAccounts/" + billingAccountId).build();
billingClient.updateProjectBillingInfo("projects/" + projectId, setBilling);
return StepResult.getStepResultSuccess();
}
Aggregations