diff --git a/google-compute/gradle.properties b/google-compute/gradle.properties index 6f40b1bf..18aad4f6 100644 --- a/google-compute/gradle.properties +++ b/google-compute/gradle.properties @@ -1 +1 @@ -version = 0.7.0 +version = 0.8.0 diff --git a/google-compute/src/main/java/bio/terra/cloudres/google/compute/CloudComputeCow.java b/google-compute/src/main/java/bio/terra/cloudres/google/compute/CloudComputeCow.java index 041b1716..b17ce1fe 100644 --- a/google-compute/src/main/java/bio/terra/cloudres/google/compute/CloudComputeCow.java +++ b/google-compute/src/main/java/bio/terra/cloudres/google/compute/CloudComputeCow.java @@ -205,6 +205,69 @@ protected JsonObject serialize() { return result; } } + + /** See {@link Compute.Subnetworks#list(String, String)}. */ + public List list(String project, String region) throws IOException { + return new List(subnetworks.list(project, region)); + } + + /** See {@link Compute.Subnetworks.List}. */ + public class List extends AbstractRequestCow { + private final Compute.Subnetworks.List list; + + public List(Compute.Subnetworks.List list) { + super(CloudComputeOperation.GOOGLE_LIST_SUBNETWORK, clientConfig, operationAnnotator, list); + this.list = list; + } + + /** See {@link Compute.Subnetworks.List#setProject(String)}. */ + public List setProject(String project) { + this.list.setProject(project); + return this; + } + + /** See {@link Compute.Subnetworks.List#setRegion(String)}. */ + public List setRegion(String region) { + this.list.setRegion(region); + return this; + } + + /** See {@link Compute.Subnetworks.List#setFilter(String)}. */ + public List setFilter(String filter) { + this.list.setFilter(filter); + return this; + } + + /** See {@link Compute.Subnetworks.List#setMaxResults(Long)}. */ + public List setMaxResults(Long maxResults) { + this.list.setMaxResults(maxResults); + return this; + } + + /** See {@link Compute.Subnetworks.List#setOrderBy(String)}. */ + public List setOrderBy(String orderBy) { + this.list.setOrderBy(orderBy); + return this; + } + + /** See {@link Compute.Subnetworks.List#setPageToken(String)}. */ + public List setPageToken(String pageToken) { + this.list.setPageToken(pageToken); + return this; + } + + @Override + protected JsonObject serialize() { + JsonObject result = new JsonObject(); + result.addProperty("project_id", list.getProject()); + result.addProperty("region", list.getRegion()); + result.addProperty("filter", list.getFilter()); + result.addProperty("max_results", list.getMaxResults()); + result.addProperty("order_by", list.getOrderBy()); + result.addProperty("page_token", list.getPageToken()); + return result; + } + } } public Firewalls firewalls() { @@ -356,6 +419,42 @@ protected JsonObject serialize() { } } + public Zones zones() { + return new Zones(compute.zones()); + } + + /** See {@link Compute.Zones}. */ + public class Zones { + private final Compute.Zones zones; + + private Zones(Compute.Zones zones) { + this.zones = zones; + } + + /** See {@link Compute.Zones#get(String, String)}. */ + public Get get(String project, String zone) throws IOException { + return new Get(zones.get(project, zone)); + } + + /** See {@link Compute.Zones.Get}. */ + public class Get extends AbstractRequestCow { + private final Compute.Zones.Get get; + + private Get(Compute.Zones.Get get) { + super(CloudComputeOperation.GOOGLE_GET_ZONE, clientConfig, operationAnnotator, get); + this.get = get; + } + + @Override + protected JsonObject serialize() { + JsonObject result = new JsonObject(); + result.addProperty("project_id", get.getProject()); + result.addProperty("zone", get.getZone()); + return result; + } + } + } + /** * See {@link Compute#globalOperations()}. * diff --git a/google-compute/src/main/java/bio/terra/cloudres/google/compute/CloudComputeOperation.java b/google-compute/src/main/java/bio/terra/cloudres/google/compute/CloudComputeOperation.java index 0f1c7ebf..5235bd02 100644 --- a/google-compute/src/main/java/bio/terra/cloudres/google/compute/CloudComputeOperation.java +++ b/google-compute/src/main/java/bio/terra/cloudres/google/compute/CloudComputeOperation.java @@ -16,4 +16,6 @@ public enum CloudComputeOperation implements CloudOperation { GOOGLE_GET_NETWORK, GOOGLE_GET_ROUTE, GOOGLE_GET_SUBNETWORK, + GOOGLE_GET_ZONE, + GOOGLE_LIST_SUBNETWORK, } diff --git a/google-compute/src/test/java/bio/terra/cloudres/google/compute/CloudComputeCowTest.java b/google-compute/src/test/java/bio/terra/cloudres/google/compute/CloudComputeCowTest.java index 36e61793..bd172223 100644 --- a/google-compute/src/test/java/bio/terra/cloudres/google/compute/CloudComputeCowTest.java +++ b/google-compute/src/test/java/bio/terra/cloudres/google/compute/CloudComputeCowTest.java @@ -69,7 +69,7 @@ public void createAndGetAndDeleteNetwork() throws Exception { } @Test - public void createAndGetSubnetwork() throws Exception { + public void createAndGetAndListSubnetwork() throws Exception { String projectId = reusableProject.getProjectId(); String region = "us-west1"; String ipCidrRange = "10.130.0.0/20"; @@ -105,6 +105,9 @@ public void createAndGetSubnetwork() throws Exception { assertEquals(network.getSelfLink(), createdSubnet.getNetwork()); assertEquals(ipCidrRange, createdSubnet.getIpCidrRange()); assertEquals(regionName(projectId, region), createdSubnet.getRegion()); + + SubnetworkList subnetworkList = cloudComputeCow.subnetworks().list(projectId, region).execute(); + assertThat(subnetworkList.getItems().size(), Matchers.greaterThan(0)); } @Test @@ -166,6 +169,13 @@ public void createAndGetRoute() throws Exception { createdRoute.getNextHopGateway()); } + @Test + public void getZone() throws Exception { + Zone zone = + defaultCompute().zones().get(reusableProject.getProjectId(), "us-east1-b").execute(); + assertThat(zone.getRegion(), Matchers.containsString("us-east1")); + } + @Test public void networkInsertSerialize() throws Exception { Network network = new Network().setName("network-name"); @@ -218,6 +228,24 @@ public void subnetworkGetSerialize() throws Exception { get.serialize().toString()); } + @Test + public void subnetworkListSerialize() throws Exception { + CloudComputeCow.Subnetworks.List list = + defaultCompute() + .subnetworks() + .list("project-id", "us-west1") + .setFilter("my-filter") + .setMaxResults(42L) + .setOrderBy("order-by") + .setPageToken("page-token"); + + assertEquals( + "{\"project_id\":\"project-id\",\"region\":\"us-west1\"," + + "\"filter\":\"my-filter\",\"max_results\":42,\"order_by\":\"order-by\"," + + "\"page_token\":\"page-token\"}", + list.serialize().toString()); + } + @Test public void firewallInsertSerialize() throws Exception { Firewall firewall = new Firewall().setName("firewall-name"); @@ -268,6 +296,13 @@ public void routeGetSerialize() throws Exception { get.serialize().toString()); } + @Test + public void zoneGetSerialize() throws Exception { + CloudComputeCow.Zones.Get get = defaultCompute().zones().get("project-id", "us-east1-b"); + assertEquals( + "{\"project_id\":\"project-id\",\"zone\":\"us-east1-b\"}", get.serialize().toString()); + } + /** Create Project then set billing account, enable compute compute service */ private static Project createPreparedProject() throws Exception { Project project = ProjectUtils.executeCreateProject(); diff --git a/google-iam/gradle.properties b/google-iam/gradle.properties index e061323d..beefe9f0 100644 --- a/google-iam/gradle.properties +++ b/google-iam/gradle.properties @@ -1 +1 @@ -version = 0.6.0 +version = 0.6.1 diff --git a/google-iam/src/test/java/bio/terra/cloudres/google/iam/IamCowTest.java b/google-iam/src/test/java/bio/terra/cloudres/google/iam/IamCowTest.java index aa81fe2f..f2fdfbfe 100644 --- a/google-iam/src/test/java/bio/terra/cloudres/google/iam/IamCowTest.java +++ b/google-iam/src/test/java/bio/terra/cloudres/google/iam/IamCowTest.java @@ -21,12 +21,9 @@ import com.google.common.collect.ImmutableList; import java.io.IOException; import java.security.GeneralSecurityException; -import java.time.Duration; -import java.time.Instant; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.function.BooleanSupplier; import org.hamcrest.Matchers; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Tag; @@ -79,7 +76,6 @@ public void createAndGetAndListAndDeleteServiceAccount() throws Exception { serviceAccounts.delete(serviceAccountName).execute(); - GoogleJsonResponseException getAfterDelete = null; for (int retryNum = 0; retryNum < 20; retryNum++) { try { diff --git a/google-iam/src/test/java/bio/terra/cloudres/google/iam/ServiceAccountNameTest.java b/google-iam/src/test/java/bio/terra/cloudres/google/iam/ServiceAccountNameTest.java index b3e9427a..e11e42cb 100644 --- a/google-iam/src/test/java/bio/terra/cloudres/google/iam/ServiceAccountNameTest.java +++ b/google-iam/src/test/java/bio/terra/cloudres/google/iam/ServiceAccountNameTest.java @@ -1,30 +1,32 @@ package bio.terra.cloudres.google.iam; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; - import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + @Tag("unit") public class ServiceAccountNameTest { - @Test - public void name() { - String name = "projects/my-project/serviceAccounts/foo@bar.com"; - ServiceAccountName serviceAccountName = ServiceAccountName.fromNameFormat(name); + @Test + public void name() { + String name = "projects/my-project/serviceAccounts/foo@bar.com"; + ServiceAccountName serviceAccountName = ServiceAccountName.fromNameFormat(name); - assertEquals("my-project", serviceAccountName.projectId()); - assertEquals("foo@bar.com", serviceAccountName.email()); - assertEquals(name, serviceAccountName.formatName()); - } + assertEquals("my-project", serviceAccountName.projectId()); + assertEquals("foo@bar.com", serviceAccountName.email()); + assertEquals(name, serviceAccountName.formatName()); + } - @Test - public void invalidName() { - assertThrows(IllegalArgumentException.class, () -> ServiceAccountName.fromNameFormat("foo")); - } + @Test + public void invalidName() { + assertThrows(IllegalArgumentException.class, () -> ServiceAccountName.fromNameFormat("foo")); + } - @Test - public void emailAccountId() { - assertEquals("foo@my-project.iam.gserviceaccount.com", ServiceAccountName.emailFromAccountId("foo", "my-project")); - } + @Test + public void emailAccountId() { + assertEquals( + "foo@my-project.iam.gserviceaccount.com", + ServiceAccountName.emailFromAccountId("foo", "my-project")); + } }