From 51876371e0be10ed7531127d04cfca0ee4b410ca Mon Sep 17 00:00:00 2001
From: Ajit Thakor <49403056+athakor@users.noreply.github.com>
Date: Mon, 13 Apr 2020 22:30:27 +0530
Subject: [PATCH] feat: expose apis of resourcemanager folders (#99)
* feat: expose folders apis
* feat: change the position of serialVersionUID
* feat: modified code as well add system test for constraint and org policy
* feat: add more checks to fix code coverage
* feat: simplified the code as per the existing design
* feat: fix the review changes as well as simplified the code
* feat: add mockito tests instead of easymock
* feat: review changes fixes
* feat: fix review changes
* feat: fix review changes
* feat: fix all the testcases
* feat: fix review changes
* feat: address feedback
* feat: address feedback
---
.../clirr-ignored-differences.xml | 60 +++
.../cloud/resourcemanager/ConstraintInfo.java | 293 +++++++++++++
.../cloud/resourcemanager/OrgPolicyInfo.java | 388 ++++++++++++++++++
.../resourcemanager/ResourceManager.java | 98 +++++
.../resourcemanager/ResourceManagerImpl.java | 201 +++++++++
.../spi/v1beta1/HttpResourceManagerRpc.java | 101 +++++
.../spi/v1beta1/ResourceManagerRpc.java | 77 ++++
.../resourcemanager/ConstraintInfoTest.java | 119 ++++++
.../resourcemanager/OrgPolicyInfoTest.java | 137 +++++++
.../ResourceManagerImplTest.java | 377 +++++++++++++++--
10 files changed, 1807 insertions(+), 44 deletions(-)
create mode 100644 java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ConstraintInfo.java
create mode 100644 java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/OrgPolicyInfo.java
create mode 100644 java-resourcemanager/src/test/java/com/google/cloud/resourcemanager/ConstraintInfoTest.java
create mode 100644 java-resourcemanager/src/test/java/com/google/cloud/resourcemanager/OrgPolicyInfoTest.java
diff --git a/java-resourcemanager/clirr-ignored-differences.xml b/java-resourcemanager/clirr-ignored-differences.xml
index da1f3c38fdb9..242668404296 100644
--- a/java-resourcemanager/clirr-ignored-differences.xml
+++ b/java-resourcemanager/clirr-ignored-differences.xml
@@ -6,9 +6,69 @@
java.util.Map testOrgPermissions(java.lang.String, java.util.List)7012
+
+ com/google/cloud/resourcemanager/ResourceManager
+ void clearOrgPolicy(java.lang.String, com.google.cloud.resourcemanager.OrgPolicyInfo)
+ 7012
+
+
+ com/google/cloud/resourcemanager/ResourceManager
+ com.google.cloud.resourcemanager.OrgPolicyInfo getEffectiveOrgPolicy(java.lang.String, java.lang.String)
+ 7012
+
+
+ com/google/cloud/resourcemanager/ResourceManager
+ com.google.cloud.resourcemanager.OrgPolicyInfo getOrgPolicy(java.lang.String, java.lang.String)
+ 7012
+
+
+ com/google/cloud/resourcemanager/ResourceManager
+ com.google.api.gax.paging.Page listAvailableOrgPolicyConstraints(java.lang.String, com.google.cloud.resourcemanager.ResourceManager$ListOption[])
+ 7012
+
+
+ com/google/cloud/resourcemanager/ResourceManager
+ com.google.api.gax.paging.Page listOrgPolicies(java.lang.String, com.google.cloud.resourcemanager.ResourceManager$ListOption[])
+ 7012
+
+
+ com/google/cloud/resourcemanager/ResourceManager
+ com.google.cloud.resourcemanager.OrgPolicyInfo replaceOrgPolicy(java.lang.String, com.google.cloud.resourcemanager.OrgPolicyInfo)
+ 7012
+ com/google/cloud/resourcemanager/spi/v1beta1/ResourceManagerRpcjava.util.Map testOrgPermissions(java.lang.String, java.util.List)7012
+
+ com/google/cloud/resourcemanager/spi/v1beta1/ResourceManagerRpc
+ void clearOrgPolicy(java.lang.String, com.google.api.services.cloudresourcemanager.model.OrgPolicy)
+ 7012
+
+
+ com/google/cloud/resourcemanager/spi/v1beta1/ResourceManagerRpc
+ com.google.api.services.cloudresourcemanager.model.OrgPolicy getEffectiveOrgPolicy(java.lang.String, java.lang.String)
+ 7012
+
+
+ com/google/cloud/resourcemanager/spi/v1beta1/ResourceManagerRpc
+ com.google.api.services.cloudresourcemanager.model.OrgPolicy getOrgPolicy(java.lang.String, java.lang.String)
+ 7012
+
+
+ com/google/cloud/resourcemanager/spi/v1beta1/ResourceManagerRpc
+ com.google.cloud.resourcemanager.spi.v1beta1.ResourceManagerRpc$ListResult listAvailableOrgPolicyConstraints(java.lang.String, java.util.Map)
+ 7012
+
+
+ com/google/cloud/resourcemanager/spi/v1beta1/ResourceManagerRpc
+ com.google.cloud.resourcemanager.spi.v1beta1.ResourceManagerRpc$ListResult listOrgPolicies(java.lang.String, java.util.Map)
+ 7012
+
+
+ com/google/cloud/resourcemanager/spi/v1beta1/ResourceManagerRpc
+ com.google.api.services.cloudresourcemanager.model.OrgPolicy replaceOrgPolicy(java.lang.String, com.google.api.services.cloudresourcemanager.model.OrgPolicy)
+ 7012
+
diff --git a/java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ConstraintInfo.java b/java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ConstraintInfo.java
new file mode 100644
index 000000000000..b6ddc915e14b
--- /dev/null
+++ b/java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ConstraintInfo.java
@@ -0,0 +1,293 @@
+/*
+ * Copyright 2020 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.google.cloud.resourcemanager;
+
+import com.google.api.services.cloudresourcemanager.model.BooleanConstraint;
+import com.google.api.services.cloudresourcemanager.model.Constraint;
+import com.google.api.services.cloudresourcemanager.model.ListConstraint;
+import com.google.common.base.Function;
+import com.google.common.base.MoreObjects;
+import java.util.Objects;
+
+/**
+ * A Google Cloud Resource Manager constraint metadata object.
+ *
+ * @see Constraint
+ */
+public class ConstraintInfo {
+
+ static final Function FROM_PROTOBUF_FUNCTION =
+ new Function() {
+ @Override
+ public ConstraintInfo apply(Constraint protobuf) {
+ return ConstraintInfo.fromProtobuf(protobuf);
+ }
+ };
+ static final Function TO_PROTOBUF_FUNCTION =
+ new Function() {
+ @Override
+ public Constraint apply(ConstraintInfo constraintInfo) {
+ return constraintInfo.toProtobuf();
+ }
+ };
+
+ private BooleanConstraint booleanConstraint;
+ private String constraintDefault;
+ private String description;
+ private String displayName;
+ private Constraints constraints;
+ private String name;
+ private Integer version;
+
+ /**
+ * A Constraint that allows or disallows a list of string values, which are configured by an
+ * Organization's policy administrator with a Policy.
+ */
+ static class Constraints {
+
+ private final String suggestedValue;
+ private final Boolean supportsUnder;
+
+ Constraints(String suggestedValue, Boolean supportsUnder) {
+ this.suggestedValue = suggestedValue;
+ this.supportsUnder = supportsUnder;
+ }
+
+ /**
+ * The Google Cloud Console tries to default to a configuration that matches the value specified
+ * in this Constraint.
+ */
+ String getSuggestedValue() {
+ return suggestedValue;
+ }
+
+ /**
+ * Indicates whether subtrees of Cloud Resource Manager resource hierarchy can be used in
+ * Policy.allowed_values and Policy.denied_values.
+ */
+ Boolean getSupportsUnder() {
+ return supportsUnder;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("suggestedValue", getSuggestedValue())
+ .add("supportsUnder", getSupportsUnder())
+ .toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(suggestedValue, supportsUnder);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ Constraints that = (Constraints) o;
+ return Objects.equals(suggestedValue, that.suggestedValue)
+ && Objects.equals(supportsUnder, that.supportsUnder);
+ }
+
+ ListConstraint toProtobuf() {
+ return new ListConstraint().setSuggestedValue(suggestedValue).setSupportsUnder(supportsUnder);
+ }
+
+ static Constraints fromProtobuf(ListConstraint listConstraint) {
+ return new Constraints(listConstraint.getSuggestedValue(), listConstraint.getSupportsUnder());
+ }
+ }
+
+ /** Builder for {@code ConstraintInfo}. */
+ static class Builder {
+ private BooleanConstraint booleanConstraint;
+ private String constraintDefault;
+ private String description;
+ private String displayName;
+ private Constraints constraints;
+ private String name;
+ private Integer version;
+
+ Builder(String name) {
+ this.name = name;
+ }
+
+ Builder(ConstraintInfo info) {
+ this.booleanConstraint = info.booleanConstraint;
+ this.constraintDefault = info.constraintDefault;
+ this.description = info.description;
+ this.displayName = info.displayName;
+ this.constraints = info.constraints;
+ this.name = info.name;
+ this.version = info.version;
+ }
+
+ Builder setBooleanConstraint(BooleanConstraint booleanConstraint) {
+ this.booleanConstraint = booleanConstraint;
+ return this;
+ }
+
+ Builder setConstraintDefault(String constraintDefault) {
+ this.constraintDefault = constraintDefault;
+ return this;
+ }
+
+ Builder setDescription(String description) {
+ this.description = description;
+ return this;
+ }
+
+ Builder setDisplayName(String displayName) {
+ this.displayName = displayName;
+ return this;
+ }
+
+ Builder setConstraints(Constraints constraints) {
+ this.constraints = constraints;
+ return this;
+ }
+
+ Builder setName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ Builder setVersion(Integer version) {
+ this.version = version;
+ return this;
+ }
+
+ ConstraintInfo build() {
+ return new ConstraintInfo(this);
+ }
+ }
+
+ ConstraintInfo(Builder builder) {
+ this.booleanConstraint = builder.booleanConstraint;
+ this.constraintDefault = builder.constraintDefault;
+ this.description = builder.description;
+ this.displayName = builder.displayName;
+ this.constraints = builder.constraints;
+ this.name = builder.name;
+ this.version = builder.version;
+ }
+
+ /** Returns the boolean constraint to check whether the constraint is enforced or not. */
+ public BooleanConstraint getBooleanConstraint() {
+ return booleanConstraint;
+ }
+
+ /** Returns the default behavior of the constraint. */
+ public String getConstraintDefault() {
+ return constraintDefault;
+ }
+
+ /** Returns the detailed description of the constraint. */
+ public String getDescription() {
+ return description;
+ }
+
+ /** Returns the human readable name of the constraint. */
+ public String getDisplayName() {
+ return displayName;
+ }
+
+ /** Returns the listConstraintInfo. */
+ public Constraints getConstraints() {
+ return constraints;
+ }
+
+ /** Returns the globally unique name of the constraint. */
+ public String getName() {
+ return name;
+ }
+
+ /** Returns the version of the Constraint. Default version is 0. */
+ public Integer getVersion() {
+ return version;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ ConstraintInfo that = (ConstraintInfo) o;
+ return Objects.equals(booleanConstraint, that.booleanConstraint)
+ && Objects.equals(constraintDefault, that.constraintDefault)
+ && Objects.equals(description, that.description)
+ && Objects.equals(displayName, that.displayName)
+ && Objects.equals(constraints, that.constraints)
+ && Objects.equals(name, that.name)
+ && Objects.equals(version, that.version);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(
+ booleanConstraint, constraintDefault, description, displayName, constraints, name, version);
+ }
+
+ /** Returns a builder for the {@link ConstraintInfo} object. */
+ public static Builder newBuilder(String name) {
+ return new Builder(name);
+ }
+
+ /** Returns a builder for the {@link ConstraintInfo} object. */
+ public Builder toBuilder() {
+ return new Builder(this);
+ }
+
+ Constraint toProtobuf() {
+ Constraint constraintProto = new Constraint();
+ constraintProto.setBooleanConstraint(booleanConstraint);
+ constraintProto.setConstraintDefault(constraintDefault);
+ constraintProto.setDescription(description);
+ constraintProto.setDisplayName(displayName);
+ if (constraints != null) {
+ constraintProto.setListConstraint(constraints.toProtobuf());
+ }
+ constraintProto.setName(name);
+ constraintProto.setVersion(version);
+ return constraintProto;
+ }
+
+ static ConstraintInfo fromProtobuf(Constraint constraintProtobuf) {
+ Builder builder = newBuilder(constraintProtobuf.getName());
+ builder.setBooleanConstraint(constraintProtobuf.getBooleanConstraint());
+ builder.setConstraintDefault(constraintProtobuf.getConstraintDefault());
+ builder.setDescription(constraintProtobuf.getDescription());
+ builder.setDisplayName(constraintProtobuf.getDisplayName());
+ if (constraintProtobuf.getListConstraint() != null) {
+ builder.setConstraints(Constraints.fromProtobuf(constraintProtobuf.getListConstraint()));
+ }
+ if (constraintProtobuf.getName() != null && !constraintProtobuf.getName().equals("Unnamed")) {
+ builder.setName(constraintProtobuf.getName());
+ }
+ builder.setVersion(constraintProtobuf.getVersion());
+ return builder.build();
+ }
+}
diff --git a/java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/OrgPolicyInfo.java b/java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/OrgPolicyInfo.java
new file mode 100644
index 000000000000..55dc20015cdf
--- /dev/null
+++ b/java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/OrgPolicyInfo.java
@@ -0,0 +1,388 @@
+/*
+ * Copyright 2020 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.google.cloud.resourcemanager;
+
+import com.google.api.services.cloudresourcemanager.model.BooleanPolicy;
+import com.google.api.services.cloudresourcemanager.model.ListPolicy;
+import com.google.api.services.cloudresourcemanager.model.OrgPolicy;
+import com.google.api.services.cloudresourcemanager.model.RestoreDefault;
+import com.google.common.base.Function;
+import com.google.common.base.MoreObjects;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * A Google Cloud Resource Manager organization policy metadata object.
+ *
+ *
Defines a Cloud Organization Policy which specifies constraints for configurations of Cloud
+ * Platform resources.
+ */
+public class OrgPolicyInfo {
+
+ static final Function FROM_PROTOBUF_FUNCTION =
+ new Function() {
+ @Override
+ public OrgPolicyInfo apply(OrgPolicy protobuf) {
+ return OrgPolicyInfo.fromProtobuf(protobuf);
+ }
+ };
+ static final Function TO_PROTOBUF_FUNCTION =
+ new Function() {
+ @Override
+ public OrgPolicy apply(OrgPolicyInfo orgPolicyInfo) {
+ return orgPolicyInfo.toProtobuf();
+ }
+ };
+
+ private BoolPolicy boolPolicy;
+ private String constraint;
+ private String etag;
+ private Policies policies;
+ private RestoreDefault restoreDefault;
+ private String updateTime;
+ private Integer version;
+
+ /** Used For boolean Constraints, whether to enforce the Constraint or not. */
+ static class BoolPolicy {
+
+ private final Boolean enforce;
+
+ BoolPolicy(Boolean enforce) {
+ this.enforce = enforce;
+ }
+
+ public boolean getEnforce() {
+ return enforce;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this).add("enforce", getEnforce()).toString();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ BoolPolicy that = (BoolPolicy) o;
+ return Objects.equals(enforce, that.enforce);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(enforce);
+ }
+
+ BooleanPolicy toProtobuf() {
+ return new BooleanPolicy().setEnforced(enforce);
+ }
+
+ static BoolPolicy fromProtobuf(BooleanPolicy booleanPolicy) {
+ return new BoolPolicy(booleanPolicy.getEnforced());
+ }
+ }
+
+ /**
+ * The organization ListPolicy object.
+ *
+ *
ListPolicy can define specific values and subtrees of Cloud Resource Manager resource
+ * hierarchy (Organizations, Folders, Projects) that are allowed or denied by setting the
+ * allowedValues and deniedValues fields. This is achieved by using the under: and optional is:
+ * prefixes. The under: prefix denotes resource subtree values. The is: prefix is used to denote
+ * specific values, and is required only if the value contains a ":". Values prefixed with "is:"
+ * are treated the same as values with no prefix. Ancestry subtrees must be in one of the
+ * following formats: - "projects/", e.g. "projects/tokyo-rain-123" - "folders/", e.g.
+ * "folders/1234" - "organizations/", e.g. "organizations/1234" The supportsUnder field of the
+ * associated Constraint defines whether ancestry prefixes can be used. You can set allowedValues
+ * and deniedValues in the same Policy if allValues is ALL_VALUES_UNSPECIFIED. ALLOW or DENY are
+ * used to allow or deny all values. If allValues is set to either ALLOW or DENY, allowedValues
+ * and deniedValues must be unset.
+ */
+ static class Policies {
+
+ private final String allValues;
+ private final List allowedValues;
+ private final List deniedValues;
+ private final Boolean inheritFromParent;
+ private final String suggestedValue;
+
+ Policies(
+ String allValues,
+ List allowedValues,
+ List deniedValues,
+ Boolean inheritFromParent,
+ String suggestedValue) {
+ this.allValues = allValues;
+ this.allowedValues = allowedValues;
+ this.deniedValues = deniedValues;
+ this.inheritFromParent = inheritFromParent;
+ this.suggestedValue = suggestedValue;
+ }
+
+ /** Returns all the Values state of this policy. */
+ String getAllValues() {
+ return allValues;
+ }
+
+ /** Returns the list of allowed values of this resource */
+ List getAllowedValues() {
+ return allowedValues;
+ }
+
+ /** Returns the list of denied values of this resource. */
+ List getDeniedValues() {
+ return deniedValues;
+ }
+
+ /** Returns the inheritance behavior for this Policy */
+ Boolean getInheritFromParent() {
+ return inheritFromParent;
+ }
+
+ /** Returns the suggested value of this policy. */
+ String getSuggestedValue() {
+ return suggestedValue;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("allValues", getAllValues())
+ .add("allowedValues", getAllowedValues())
+ .add("deniedValues", getDeniedValues())
+ .add("inheritFromParent", getInheritFromParent())
+ .add("suggestedValue", getSuggestedValue())
+ .toString();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ Policies policies = (Policies) o;
+ return Objects.equals(allValues, policies.allValues)
+ && Objects.equals(allowedValues, policies.allowedValues)
+ && Objects.equals(deniedValues, policies.deniedValues)
+ && Objects.equals(inheritFromParent, policies.inheritFromParent)
+ && Objects.equals(suggestedValue, policies.suggestedValue);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(
+ allValues, allowedValues, deniedValues, inheritFromParent, suggestedValue);
+ }
+
+ ListPolicy toProtobuf() {
+ return new ListPolicy()
+ .setAllValues(allValues)
+ .setAllowedValues(allowedValues)
+ .setDeniedValues(deniedValues)
+ .setInheritFromParent(inheritFromParent)
+ .setSuggestedValue(suggestedValue);
+ }
+
+ static Policies fromProtobuf(ListPolicy listPolicy) {
+ return new Policies(
+ listPolicy.getAllValues(),
+ listPolicy.getAllowedValues(),
+ listPolicy.getDeniedValues(),
+ listPolicy.getInheritFromParent(),
+ listPolicy.getSuggestedValue());
+ }
+ }
+
+ /** Builder for {@code OrganizationPolicyInfo}. */
+ static class Builder {
+ private BoolPolicy boolPolicy;
+ private String constraint;
+ private String etag;
+ private Policies policies;
+ private RestoreDefault restoreDefault;
+ private String updateTime;
+ private Integer version;
+
+ Builder() {}
+
+ Builder(OrgPolicyInfo info) {
+ this.boolPolicy = info.boolPolicy;
+ this.constraint = info.constraint;
+ this.etag = info.etag;
+ this.policies = info.policies;
+ this.restoreDefault = info.restoreDefault;
+ this.updateTime = info.updateTime;
+ this.version = info.version;
+ }
+
+ Builder setBoolPolicy(BoolPolicy boolPolicy) {
+ this.boolPolicy = boolPolicy;
+ return this;
+ }
+
+ Builder setConstraint(String constraint) {
+ this.constraint = constraint;
+ return this;
+ }
+
+ Builder setEtag(String etag) {
+ this.etag = etag;
+ return this;
+ }
+
+ Builder setListPolicy(Policies policies) {
+ this.policies = policies;
+ return this;
+ }
+
+ Builder setRestoreDefault(RestoreDefault restoreDefault) {
+ this.restoreDefault = restoreDefault;
+ return this;
+ }
+
+ Builder setUpdateTime(String updateTime) {
+ this.updateTime = updateTime;
+ return this;
+ }
+
+ Builder setVersion(Integer version) {
+ this.version = version;
+ return this;
+ }
+
+ OrgPolicyInfo build() {
+ return new OrgPolicyInfo(this);
+ }
+ }
+
+ OrgPolicyInfo(Builder builder) {
+ this.boolPolicy = builder.boolPolicy;
+ this.constraint = builder.constraint;
+ this.etag = builder.etag;
+ this.policies = builder.policies;
+ this.restoreDefault = builder.restoreDefault;
+ this.updateTime = builder.updateTime;
+ this.version = builder.version;
+ }
+
+ /** Returns the boolean constraint to check whether the constraint is enforced or not. */
+ public BoolPolicy getBoolPolicy() {
+ return boolPolicy;
+ }
+
+ /** Returns the name of the Constraint. */
+ public String getConstraint() {
+ return constraint;
+ }
+
+ /** Returns the etag value of policy. */
+ public String getEtag() {
+ return etag;
+ }
+
+ /** Return the policies. */
+ public Policies getPolicies() {
+ return policies;
+ }
+
+ /** Restores the default behavior of the constraint. */
+ public RestoreDefault getRestoreDefault() {
+ return restoreDefault;
+ }
+
+ /** Returns the updated timestamp of policy. */
+ public String getUpdateTime() {
+ return updateTime;
+ }
+
+ /** Returns the version of the Policy, Default version is 0. */
+ public Integer getVersion() {
+ return version;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ OrgPolicyInfo policyInfo = (OrgPolicyInfo) o;
+ return Objects.equals(boolPolicy, policyInfo.boolPolicy)
+ && Objects.equals(constraint, policyInfo.constraint)
+ && Objects.equals(etag, policyInfo.etag)
+ && Objects.equals(policies, policyInfo.policies)
+ && Objects.equals(restoreDefault, policyInfo.restoreDefault)
+ && Objects.equals(updateTime, policyInfo.updateTime)
+ && Objects.equals(version, policyInfo.version);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(
+ boolPolicy, constraint, etag, policies, restoreDefault, updateTime, version);
+ }
+
+ /** Returns a builder for the {@link OrgPolicyInfo} object. */
+ public static Builder newBuilder() {
+ return new Builder();
+ }
+
+ /** Returns a builder for the {@link OrgPolicyInfo} object. */
+ public Builder toBuilder() {
+ return new Builder(this);
+ }
+
+ OrgPolicy toProtobuf() {
+ OrgPolicy orgPolicyProto = new OrgPolicy();
+ if (boolPolicy != null) {
+ orgPolicyProto.setBooleanPolicy(boolPolicy.toProtobuf());
+ }
+ orgPolicyProto.setConstraint(constraint);
+ if (policies != null) {
+ orgPolicyProto.setListPolicy(policies.toProtobuf());
+ }
+ orgPolicyProto.setRestoreDefault(restoreDefault);
+ orgPolicyProto.setEtag(etag);
+ orgPolicyProto.setUpdateTime(updateTime);
+ orgPolicyProto.setVersion(version);
+ return orgPolicyProto;
+ }
+
+ static OrgPolicyInfo fromProtobuf(OrgPolicy orgPolicyProtobuf) {
+ Builder builder = newBuilder();
+ if (orgPolicyProtobuf.getBooleanPolicy() != null) {
+ builder.setBoolPolicy(BoolPolicy.fromProtobuf(orgPolicyProtobuf.getBooleanPolicy()));
+ }
+ builder.setConstraint(orgPolicyProtobuf.getConstraint());
+ if (orgPolicyProtobuf.getListPolicy() != null) {
+ builder.setListPolicy(Policies.fromProtobuf(orgPolicyProtobuf.getListPolicy()));
+ }
+ builder.setRestoreDefault(orgPolicyProtobuf.getRestoreDefault());
+ builder.setEtag(orgPolicyProtobuf.getEtag());
+ builder.setUpdateTime(orgPolicyProtobuf.getUpdateTime());
+ builder.setVersion(orgPolicyProtobuf.getVersion());
+ return builder.build();
+ }
+}
diff --git a/java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ResourceManager.java b/java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ResourceManager.java
index b2a46edf09dd..873db0513eb1 100644
--- a/java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ResourceManager.java
+++ b/java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ResourceManager.java
@@ -339,6 +339,33 @@ public static ProjectListOption fields(ProjectField... fields) {
*/
List testPermissions(String projectId, List permissions);
+ /** Class for specifying project list options. */
+ class ListOption extends Option {
+
+ private ListOption(ResourceManagerRpc.Option option, Object value) {
+ super(option, value);
+ }
+
+ /**
+ * Returns an option to specify a page token.
+ *
+ *
The page token (returned from a previous call to list) indicates from where listing should
+ * continue.
+ */
+ public static ListOption pageToken(String pageToken) {
+ return new ListOption(ResourceManagerRpc.Option.PAGE_TOKEN, pageToken);
+ }
+
+ /**
+ * The maximum number of records to return per RPC.
+ *
+ *
The server can return fewer records than requested. When there are more results than the
+ * page size, the server will return a page token that can be used to fetch other results.
+ */
+ public static ListOption pageSize(int pageSize) {
+ return new ListOption(ResourceManagerRpc.Option.PAGE_SIZE, pageSize);
+ }
+ }
/**
* Returns the permissions and their results representing whether the caller has the permissions
* on the specified Organization.
@@ -354,4 +381,75 @@ public static ProjectListOption fields(ProjectField... fields) {
* Resource Manager testIamPermissions
*/
Map testOrgPermissions(String resource, List permissions);
+
+ /**
+ * Clears a Policy from a resource.
+ *
+ * @throws ResourceManagerException upon failure
+ * @see Resource
+ * Manager clearOrgPolicy
+ */
+ void clearOrgPolicy(String resource, OrgPolicyInfo orgPolicy);
+
+ /**
+ * Gets the effective Policy on a resource.
+ *
+ *
This is the result of merging Policies in the resource hierarchy. The returned Policy will
+ * not have an etag set because it is a computed Policy across multiple resources. Subtrees of
+ * Resource Manager resource hierarchy with 'under:' prefix are not expanded.
+ *
+ * @throws ResourceManagerException upon failure
+ * @see Resource
+ * Manager getEffectiveOrgPolicy
+ */
+ OrgPolicyInfo getEffectiveOrgPolicy(String resource, String constraint);
+
+ /**
+ * Gets the Policy on a resource.
+ *
+ *
If no Policy is set on the resource, a Policy is returned with default values including
+ * POLICY_TYPE_NOT_SET for the policy_type one of. The etag value can be used with
+ * projects.setOrgPolicy() to create or update a Policy during read-modify-write.
+ *
+ * @throws ResourceManagerException upon failure
+ * @see Resource
+ * Manager getOrgPolicy
+ */
+ OrgPolicyInfo getOrgPolicy(String resource, String constraint);
+
+ /**
+ * Lists the Constraints that could be applied on the specified resource.
+ *
+ * @throws ResourceManagerException upon failure
+ * @see Resource
+ * Manager listAvailableOrgPolicyConstraints
+ */
+ Page listAvailableOrgPolicyConstraints(String resource, ListOption... options);
+
+ /**
+ * Lists the Policies set for a particular resource.
+ *
+ * @throws ResourceManagerException upon failure
+ * @see Resource
+ * Manager listOrgPolicies
+ */
+ Page listOrgPolicies(String resource, ListOption... options);
+
+ /**
+ * Updates the specified Policy on the resource. Creates a new Policy for that Constraint on the
+ * resource if one does not exist.
+ *
+ *