Skip to content
This repository has been archived by the owner on Sep 16, 2023. It is now read-only.

Commit

Permalink
feat!: setIamPolicy now accepts ResourceName instead of ResourceName …
Browse files Browse the repository at this point in the history
…subtypes (#21)

* [CHANGE ME] Re-generated  to pick up changes in the API or client library generator.

* fix: allow Iam breaking changes

Co-authored-by: Jeff Ching <chingor@google.com>
  • Loading branch information
yoshi-automation and chingor13 committed Dec 21, 2019
1 parent fff06a9 commit d90614c
Show file tree
Hide file tree
Showing 45 changed files with 1,766 additions and 1,137 deletions.
1 change: 1 addition & 0 deletions .github/release-please.yml
@@ -1 +1,2 @@
releaseType: java-yoshi
bumpMinorPreMajor: true
14 changes: 10 additions & 4 deletions .kokoro/build.sh
Expand Up @@ -27,6 +27,7 @@ echo ${JOB_TYPE}
mvn install -B -V \
-DskipTests=true \
-Dclirr.skip=true \
-Denforcer.skip=true \
-Dmaven.javadoc.skip=true \
-Dgcloud.download.skip=true \
-T 1C
Expand All @@ -38,7 +39,7 @@ fi

case ${JOB_TYPE} in
test)
mvn test -B -Dclirr.skip=true
mvn test -B -Dclirr.skip=true -Denforcer.skip=true
bash ${KOKORO_GFILE_DIR}/codecov.sh
bash .kokoro/coerce_logs.sh
;;
Expand All @@ -49,12 +50,17 @@ javadoc)
mvn javadoc:javadoc javadoc:test-javadoc
;;
integration)
mvn -B ${INTEGRATION_TEST_ARGS} -DtrimStackTrace=false -Dclirr.skip=true -fae verify
mvn -B ${INTEGRATION_TEST_ARGS} \
-DtrimStackTrace=false \
-Dclirr.skip=true \
-Denforcer.skip=true \
-fae \
verify
bash .kokoro/coerce_logs.sh
;;
clirr)
mvn -B clirr:check
mvn -B -Denforcer.skip=true clirr:check
;;
*)
;;
esac
esac
6 changes: 5 additions & 1 deletion .kokoro/dependencies.sh
Expand Up @@ -23,5 +23,9 @@ echo $JOB_TYPE

export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=128m"

mvn install -DskipTests=true -B -V
# this should run maven enforcer
mvn install -B -V \
-DskipTests=true \
-Dclirr.skip=true

mvn -B dependency:analyze -DfailOnWarning=true
2 changes: 1 addition & 1 deletion .kokoro/release/publish_javadoc.sh
Expand Up @@ -33,7 +33,7 @@ python3 -m pip install gcp-docuploader
# compile all packages
mvn clean install -B -DskipTests=true

NAME=cloudiot
NAME=google-cloud-iot
VERSION=$(grep ${NAME}: versions.txt | cut -d: -f3)

# build the docs
Expand Down
11 changes: 11 additions & 0 deletions google-cloud-iot/clirr-ignored-differences.xml
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- see http://www.mojohaus.org/clirr-maven-plugin/examples/ignored-differences.html -->
<differences>
<!-- TODO: remove after 0.117.0 release -->
<difference>
<differenceType>7005</differenceType>
<className>com/google/cloud/iot/v1/DeviceManagerClient</className>
<method>* *Iam*(com.google.cloud.iot.v1.RegistryName*)</method>
<to>* *Iam*(com.google.api.resourcenames.ResourceName*)</to>
</difference>
</differences>

Large diffs are not rendered by default.

Expand Up @@ -523,13 +523,6 @@ public static class Builder extends StubSettings.Builder<DeviceManagerStubSettin
Lists.<StatusCode.Code>newArrayList(
StatusCode.Code.DEADLINE_EXCEEDED, StatusCode.Code.UNAVAILABLE)));
definitions.put("non_idempotent", ImmutableSet.copyOf(Lists.<StatusCode.Code>newArrayList()));
definitions.put(
"rate_limited_aware",
ImmutableSet.copyOf(
Lists.<StatusCode.Code>newArrayList(
StatusCode.Code.DEADLINE_EXCEEDED,
StatusCode.Code.RESOURCE_EXHAUSTED,
StatusCode.Code.UNAVAILABLE)));
RETRYABLE_CODE_DEFINITIONS = definitions.build();
}

Expand All @@ -546,20 +539,9 @@ public static class Builder extends StubSettings.Builder<DeviceManagerStubSettin
.setInitialRpcTimeout(Duration.ofMillis(20000L))
.setRpcTimeoutMultiplier(1.0)
.setMaxRpcTimeout(Duration.ofMillis(20000L))
.setTotalTimeout(Duration.ofMillis(120000L))
.setTotalTimeout(Duration.ofMillis(600000L))
.build();
definitions.put("default", settings);
settings =
RetrySettings.newBuilder()
.setInitialRetryDelay(Duration.ofMillis(1000L))
.setRetryDelayMultiplier(1.3)
.setMaxRetryDelay(Duration.ofMillis(60000L))
.setInitialRpcTimeout(Duration.ofMillis(20000L))
.setRpcTimeoutMultiplier(1.0)
.setMaxRpcTimeout(Duration.ofMillis(20000L))
.setTotalTimeout(Duration.ofMillis(120000L))
.build();
definitions.put("rate_limited_aware", settings);
RETRY_PARAM_DEFINITIONS = definitions.build();
}

Expand Down Expand Up @@ -662,7 +644,7 @@ private static Builder initDefaults(Builder builder) {

builder
.deleteDeviceRegistrySettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

builder
Expand All @@ -687,7 +669,7 @@ private static Builder initDefaults(Builder builder) {

builder
.deleteDeviceSettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

builder
Expand All @@ -697,8 +679,8 @@ private static Builder initDefaults(Builder builder) {

builder
.modifyCloudToDeviceConfigSettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("rate_limited_aware"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("rate_limited_aware"));
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

builder
.listDeviceConfigVersionsSettings()
Expand Down Expand Up @@ -727,8 +709,8 @@ private static Builder initDefaults(Builder builder) {

builder
.sendCommandToDeviceSettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("rate_limited_aware"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("rate_limited_aware"));
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

builder
.bindDeviceToGatewaySettings()
Expand Down
Expand Up @@ -25,6 +25,7 @@
import com.google.api.gax.grpc.testing.MockServiceHelper;
import com.google.api.gax.rpc.ApiClientHeaderProvider;
import com.google.api.gax.rpc.InvalidArgumentException;
import com.google.api.resourcenames.ResourceName;
import com.google.common.collect.Lists;
import com.google.iam.v1.GetIamPolicyRequest;
import com.google.iam.v1.Policy;
Expand All @@ -42,6 +43,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
Expand All @@ -60,7 +62,8 @@ public class DeviceManagerClientTest {
public static void startStaticServer() {
mockDeviceManager = new MockDeviceManager();
serviceHelper =
new MockServiceHelper("in-process-1", Arrays.<MockGrpcService>asList(mockDeviceManager));
new MockServiceHelper(
UUID.randomUUID().toString(), Arrays.<MockGrpcService>asList(mockDeviceManager));
serviceHelper.start();
}

Expand Down Expand Up @@ -666,7 +669,7 @@ public void setIamPolicyTest() {
Policy expectedResponse = Policy.newBuilder().setVersion(version).setEtag(etag).build();
mockDeviceManager.addResponse(expectedResponse);

RegistryName resource = RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]");
ResourceName resource = DeviceName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]", "[DEVICE]");
Policy policy = Policy.newBuilder().build();

Policy actualResponse = client.setIamPolicy(resource, policy);
Expand All @@ -691,7 +694,7 @@ public void setIamPolicyExceptionTest() throws Exception {
mockDeviceManager.addException(exception);

try {
RegistryName resource = RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]");
ResourceName resource = DeviceName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]", "[DEVICE]");
Policy policy = Policy.newBuilder().build();

client.setIamPolicy(resource, policy);
Expand All @@ -709,7 +712,7 @@ public void getIamPolicyTest() {
Policy expectedResponse = Policy.newBuilder().setVersion(version).setEtag(etag).build();
mockDeviceManager.addResponse(expectedResponse);

RegistryName resource = RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]");
ResourceName resource = DeviceName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]", "[DEVICE]");

Policy actualResponse = client.getIamPolicy(resource);
Assert.assertEquals(expectedResponse, actualResponse);
Expand All @@ -732,7 +735,7 @@ public void getIamPolicyExceptionTest() throws Exception {
mockDeviceManager.addException(exception);

try {
RegistryName resource = RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]");
ResourceName resource = DeviceName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]", "[DEVICE]");

client.getIamPolicy(resource);
Assert.fail("No exception raised");
Expand All @@ -747,7 +750,7 @@ public void testIamPermissionsTest() {
TestIamPermissionsResponse expectedResponse = TestIamPermissionsResponse.newBuilder().build();
mockDeviceManager.addResponse(expectedResponse);

RegistryName resource = RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]");
ResourceName resource = DeviceName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]", "[DEVICE]");
List<String> permissions = new ArrayList<>();

TestIamPermissionsResponse actualResponse = client.testIamPermissions(resource, permissions);
Expand All @@ -772,7 +775,7 @@ public void testIamPermissionsExceptionTest() throws Exception {
mockDeviceManager.addException(exception);

try {
RegistryName resource = RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]");
ResourceName resource = DeviceName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]", "[DEVICE]");
List<String> permissions = new ArrayList<>();

client.testIamPermissions(resource, permissions);
Expand All @@ -788,6 +791,47 @@ public void sendCommandToDeviceTest() {
SendCommandToDeviceResponse expectedResponse = SendCommandToDeviceResponse.newBuilder().build();
mockDeviceManager.addResponse(expectedResponse);

DeviceName name = DeviceName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]", "[DEVICE]");
ByteString binaryData = ByteString.copyFromUtf8("40");

SendCommandToDeviceResponse actualResponse = client.sendCommandToDevice(name, binaryData);
Assert.assertEquals(expectedResponse, actualResponse);

List<AbstractMessage> actualRequests = mockDeviceManager.getRequests();
Assert.assertEquals(1, actualRequests.size());
SendCommandToDeviceRequest actualRequest = (SendCommandToDeviceRequest) actualRequests.get(0);

Assert.assertEquals(name, DeviceName.parse(actualRequest.getName()));
Assert.assertEquals(binaryData, actualRequest.getBinaryData());
Assert.assertTrue(
channelProvider.isHeaderSent(
ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}

@Test
@SuppressWarnings("all")
public void sendCommandToDeviceExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockDeviceManager.addException(exception);

try {
DeviceName name = DeviceName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]", "[DEVICE]");
ByteString binaryData = ByteString.copyFromUtf8("40");

client.sendCommandToDevice(name, binaryData);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception
}
}

@Test
@SuppressWarnings("all")
public void sendCommandToDeviceTest2() {
SendCommandToDeviceResponse expectedResponse = SendCommandToDeviceResponse.newBuilder().build();
mockDeviceManager.addResponse(expectedResponse);

DeviceName name = DeviceName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]", "[DEVICE]");
ByteString binaryData = ByteString.copyFromUtf8("40");
String subfolder = "subfolder153561774";
Expand All @@ -811,7 +855,7 @@ public void sendCommandToDeviceTest() {

@Test
@SuppressWarnings("all")
public void sendCommandToDeviceExceptionTest() throws Exception {
public void sendCommandToDeviceExceptionTest2() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockDeviceManager.addException(exception);

Expand Down

0 comments on commit d90614c

Please sign in to comment.