Skip to content

Commit 5187637

Browse files
authored
feat: expose apis of resourcemanager folders (googleapis#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
1 parent 345a057 commit 5187637

File tree

10 files changed

+1807
-44
lines changed

10 files changed

+1807
-44
lines changed

java-resourcemanager/clirr-ignored-differences.xml

+60
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,69 @@
66
<method>java.util.Map testOrgPermissions(java.lang.String, java.util.List)</method>
77
<differenceType>7012</differenceType>
88
</difference>
9+
<difference>
10+
<className>com/google/cloud/resourcemanager/ResourceManager</className>
11+
<method>void clearOrgPolicy(java.lang.String, com.google.cloud.resourcemanager.OrgPolicyInfo)</method>
12+
<differenceType>7012</differenceType>
13+
</difference>
14+
<difference>
15+
<className>com/google/cloud/resourcemanager/ResourceManager</className>
16+
<method>com.google.cloud.resourcemanager.OrgPolicyInfo getEffectiveOrgPolicy(java.lang.String, java.lang.String)</method>
17+
<differenceType>7012</differenceType>
18+
</difference>
19+
<difference>
20+
<className>com/google/cloud/resourcemanager/ResourceManager</className>
21+
<method>com.google.cloud.resourcemanager.OrgPolicyInfo getOrgPolicy(java.lang.String, java.lang.String)</method>
22+
<differenceType>7012</differenceType>
23+
</difference>
24+
<difference>
25+
<className>com/google/cloud/resourcemanager/ResourceManager</className>
26+
<method>com.google.api.gax.paging.Page listAvailableOrgPolicyConstraints(java.lang.String, com.google.cloud.resourcemanager.ResourceManager$ListOption[])</method>
27+
<differenceType>7012</differenceType>
28+
</difference>
29+
<difference>
30+
<className>com/google/cloud/resourcemanager/ResourceManager</className>
31+
<method>com.google.api.gax.paging.Page listOrgPolicies(java.lang.String, com.google.cloud.resourcemanager.ResourceManager$ListOption[])</method>
32+
<differenceType>7012</differenceType>
33+
</difference>
34+
<difference>
35+
<className>com/google/cloud/resourcemanager/ResourceManager</className>
36+
<method>com.google.cloud.resourcemanager.OrgPolicyInfo replaceOrgPolicy(java.lang.String, com.google.cloud.resourcemanager.OrgPolicyInfo)</method>
37+
<differenceType>7012</differenceType>
38+
</difference>
939
<difference>
1040
<className>com/google/cloud/resourcemanager/spi/v1beta1/ResourceManagerRpc</className>
1141
<method>java.util.Map testOrgPermissions(java.lang.String, java.util.List)</method>
1242
<differenceType>7012</differenceType>
1343
</difference>
44+
<difference>
45+
<className>com/google/cloud/resourcemanager/spi/v1beta1/ResourceManagerRpc</className>
46+
<method>void clearOrgPolicy(java.lang.String, com.google.api.services.cloudresourcemanager.model.OrgPolicy)</method>
47+
<differenceType>7012</differenceType>
48+
</difference>
49+
<difference>
50+
<className>com/google/cloud/resourcemanager/spi/v1beta1/ResourceManagerRpc</className>
51+
<method>com.google.api.services.cloudresourcemanager.model.OrgPolicy getEffectiveOrgPolicy(java.lang.String, java.lang.String)</method>
52+
<differenceType>7012</differenceType>
53+
</difference>
54+
<difference>
55+
<className>com/google/cloud/resourcemanager/spi/v1beta1/ResourceManagerRpc</className>
56+
<method>com.google.api.services.cloudresourcemanager.model.OrgPolicy getOrgPolicy(java.lang.String, java.lang.String)</method>
57+
<differenceType>7012</differenceType>
58+
</difference>
59+
<difference>
60+
<className>com/google/cloud/resourcemanager/spi/v1beta1/ResourceManagerRpc</className>
61+
<method>com.google.cloud.resourcemanager.spi.v1beta1.ResourceManagerRpc$ListResult listAvailableOrgPolicyConstraints(java.lang.String, java.util.Map)</method>
62+
<differenceType>7012</differenceType>
63+
</difference>
64+
<difference>
65+
<className>com/google/cloud/resourcemanager/spi/v1beta1/ResourceManagerRpc</className>
66+
<method>com.google.cloud.resourcemanager.spi.v1beta1.ResourceManagerRpc$ListResult listOrgPolicies(java.lang.String, java.util.Map)</method>
67+
<differenceType>7012</differenceType>
68+
</difference>
69+
<difference>
70+
<className>com/google/cloud/resourcemanager/spi/v1beta1/ResourceManagerRpc</className>
71+
<method>com.google.api.services.cloudresourcemanager.model.OrgPolicy replaceOrgPolicy(java.lang.String, com.google.api.services.cloudresourcemanager.model.OrgPolicy)</method>
72+
<differenceType>7012</differenceType>
73+
</difference>
1474
</differences>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,293 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.cloud.resourcemanager;
17+
18+
import com.google.api.services.cloudresourcemanager.model.BooleanConstraint;
19+
import com.google.api.services.cloudresourcemanager.model.Constraint;
20+
import com.google.api.services.cloudresourcemanager.model.ListConstraint;
21+
import com.google.common.base.Function;
22+
import com.google.common.base.MoreObjects;
23+
import java.util.Objects;
24+
25+
/**
26+
* A Google Cloud Resource Manager constraint metadata object.
27+
*
28+
* @see <a
29+
* href="https://cloud.google.com/resource-manager/reference/rest/v1/ListAvailableOrgPolicyConstraintsResponse#Constraint">Constraint</a>
30+
*/
31+
public class ConstraintInfo {
32+
33+
static final Function<Constraint, ConstraintInfo> FROM_PROTOBUF_FUNCTION =
34+
new Function<Constraint, ConstraintInfo>() {
35+
@Override
36+
public ConstraintInfo apply(Constraint protobuf) {
37+
return ConstraintInfo.fromProtobuf(protobuf);
38+
}
39+
};
40+
static final Function<ConstraintInfo, Constraint> TO_PROTOBUF_FUNCTION =
41+
new Function<ConstraintInfo, Constraint>() {
42+
@Override
43+
public Constraint apply(ConstraintInfo constraintInfo) {
44+
return constraintInfo.toProtobuf();
45+
}
46+
};
47+
48+
private BooleanConstraint booleanConstraint;
49+
private String constraintDefault;
50+
private String description;
51+
private String displayName;
52+
private Constraints constraints;
53+
private String name;
54+
private Integer version;
55+
56+
/**
57+
* A Constraint that allows or disallows a list of string values, which are configured by an
58+
* Organization's policy administrator with a Policy.
59+
*/
60+
static class Constraints {
61+
62+
private final String suggestedValue;
63+
private final Boolean supportsUnder;
64+
65+
Constraints(String suggestedValue, Boolean supportsUnder) {
66+
this.suggestedValue = suggestedValue;
67+
this.supportsUnder = supportsUnder;
68+
}
69+
70+
/**
71+
* The Google Cloud Console tries to default to a configuration that matches the value specified
72+
* in this Constraint.
73+
*/
74+
String getSuggestedValue() {
75+
return suggestedValue;
76+
}
77+
78+
/**
79+
* Indicates whether subtrees of Cloud Resource Manager resource hierarchy can be used in
80+
* Policy.allowed_values and Policy.denied_values.
81+
*/
82+
Boolean getSupportsUnder() {
83+
return supportsUnder;
84+
}
85+
86+
@Override
87+
public String toString() {
88+
return MoreObjects.toStringHelper(this)
89+
.add("suggestedValue", getSuggestedValue())
90+
.add("supportsUnder", getSupportsUnder())
91+
.toString();
92+
}
93+
94+
@Override
95+
public int hashCode() {
96+
return Objects.hash(suggestedValue, supportsUnder);
97+
}
98+
99+
@Override
100+
public boolean equals(Object o) {
101+
if (this == o) {
102+
return true;
103+
}
104+
if (o == null || getClass() != o.getClass()) {
105+
return false;
106+
}
107+
Constraints that = (Constraints) o;
108+
return Objects.equals(suggestedValue, that.suggestedValue)
109+
&& Objects.equals(supportsUnder, that.supportsUnder);
110+
}
111+
112+
ListConstraint toProtobuf() {
113+
return new ListConstraint().setSuggestedValue(suggestedValue).setSupportsUnder(supportsUnder);
114+
}
115+
116+
static Constraints fromProtobuf(ListConstraint listConstraint) {
117+
return new Constraints(listConstraint.getSuggestedValue(), listConstraint.getSupportsUnder());
118+
}
119+
}
120+
121+
/** Builder for {@code ConstraintInfo}. */
122+
static class Builder {
123+
private BooleanConstraint booleanConstraint;
124+
private String constraintDefault;
125+
private String description;
126+
private String displayName;
127+
private Constraints constraints;
128+
private String name;
129+
private Integer version;
130+
131+
Builder(String name) {
132+
this.name = name;
133+
}
134+
135+
Builder(ConstraintInfo info) {
136+
this.booleanConstraint = info.booleanConstraint;
137+
this.constraintDefault = info.constraintDefault;
138+
this.description = info.description;
139+
this.displayName = info.displayName;
140+
this.constraints = info.constraints;
141+
this.name = info.name;
142+
this.version = info.version;
143+
}
144+
145+
Builder setBooleanConstraint(BooleanConstraint booleanConstraint) {
146+
this.booleanConstraint = booleanConstraint;
147+
return this;
148+
}
149+
150+
Builder setConstraintDefault(String constraintDefault) {
151+
this.constraintDefault = constraintDefault;
152+
return this;
153+
}
154+
155+
Builder setDescription(String description) {
156+
this.description = description;
157+
return this;
158+
}
159+
160+
Builder setDisplayName(String displayName) {
161+
this.displayName = displayName;
162+
return this;
163+
}
164+
165+
Builder setConstraints(Constraints constraints) {
166+
this.constraints = constraints;
167+
return this;
168+
}
169+
170+
Builder setName(String name) {
171+
this.name = name;
172+
return this;
173+
}
174+
175+
Builder setVersion(Integer version) {
176+
this.version = version;
177+
return this;
178+
}
179+
180+
ConstraintInfo build() {
181+
return new ConstraintInfo(this);
182+
}
183+
}
184+
185+
ConstraintInfo(Builder builder) {
186+
this.booleanConstraint = builder.booleanConstraint;
187+
this.constraintDefault = builder.constraintDefault;
188+
this.description = builder.description;
189+
this.displayName = builder.displayName;
190+
this.constraints = builder.constraints;
191+
this.name = builder.name;
192+
this.version = builder.version;
193+
}
194+
195+
/** Returns the boolean constraint to check whether the constraint is enforced or not. */
196+
public BooleanConstraint getBooleanConstraint() {
197+
return booleanConstraint;
198+
}
199+
200+
/** Returns the default behavior of the constraint. */
201+
public String getConstraintDefault() {
202+
return constraintDefault;
203+
}
204+
205+
/** Returns the detailed description of the constraint. */
206+
public String getDescription() {
207+
return description;
208+
}
209+
210+
/** Returns the human readable name of the constraint. */
211+
public String getDisplayName() {
212+
return displayName;
213+
}
214+
215+
/** Returns the listConstraintInfo. */
216+
public Constraints getConstraints() {
217+
return constraints;
218+
}
219+
220+
/** Returns the globally unique name of the constraint. */
221+
public String getName() {
222+
return name;
223+
}
224+
225+
/** Returns the version of the Constraint. Default version is 0. */
226+
public Integer getVersion() {
227+
return version;
228+
}
229+
230+
@Override
231+
public boolean equals(Object o) {
232+
if (this == o) {
233+
return true;
234+
}
235+
if (o == null || getClass() != o.getClass()) {
236+
return false;
237+
}
238+
ConstraintInfo that = (ConstraintInfo) o;
239+
return Objects.equals(booleanConstraint, that.booleanConstraint)
240+
&& Objects.equals(constraintDefault, that.constraintDefault)
241+
&& Objects.equals(description, that.description)
242+
&& Objects.equals(displayName, that.displayName)
243+
&& Objects.equals(constraints, that.constraints)
244+
&& Objects.equals(name, that.name)
245+
&& Objects.equals(version, that.version);
246+
}
247+
248+
@Override
249+
public int hashCode() {
250+
return Objects.hash(
251+
booleanConstraint, constraintDefault, description, displayName, constraints, name, version);
252+
}
253+
254+
/** Returns a builder for the {@link ConstraintInfo} object. */
255+
public static Builder newBuilder(String name) {
256+
return new Builder(name);
257+
}
258+
259+
/** Returns a builder for the {@link ConstraintInfo} object. */
260+
public Builder toBuilder() {
261+
return new Builder(this);
262+
}
263+
264+
Constraint toProtobuf() {
265+
Constraint constraintProto = new Constraint();
266+
constraintProto.setBooleanConstraint(booleanConstraint);
267+
constraintProto.setConstraintDefault(constraintDefault);
268+
constraintProto.setDescription(description);
269+
constraintProto.setDisplayName(displayName);
270+
if (constraints != null) {
271+
constraintProto.setListConstraint(constraints.toProtobuf());
272+
}
273+
constraintProto.setName(name);
274+
constraintProto.setVersion(version);
275+
return constraintProto;
276+
}
277+
278+
static ConstraintInfo fromProtobuf(Constraint constraintProtobuf) {
279+
Builder builder = newBuilder(constraintProtobuf.getName());
280+
builder.setBooleanConstraint(constraintProtobuf.getBooleanConstraint());
281+
builder.setConstraintDefault(constraintProtobuf.getConstraintDefault());
282+
builder.setDescription(constraintProtobuf.getDescription());
283+
builder.setDisplayName(constraintProtobuf.getDisplayName());
284+
if (constraintProtobuf.getListConstraint() != null) {
285+
builder.setConstraints(Constraints.fromProtobuf(constraintProtobuf.getListConstraint()));
286+
}
287+
if (constraintProtobuf.getName() != null && !constraintProtobuf.getName().equals("Unnamed")) {
288+
builder.setName(constraintProtobuf.getName());
289+
}
290+
builder.setVersion(constraintProtobuf.getVersion());
291+
return builder.build();
292+
}
293+
}

0 commit comments

Comments
 (0)