This repository was archived by the owner on Oct 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathConstraintInfo.java
295 lines (256 loc) · 9.06 KB
/
ConstraintInfo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/*
* 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 <a
* href="https://cloud.google.com/resource-manager/reference/rest/v1/ListAvailableOrgPolicyConstraintsResponse#Constraint">Constraint</a>
* @deprecated v3 GAPIC client of ResourceManager is now available
*/
@Deprecated
public class ConstraintInfo {
static final Function<Constraint, ConstraintInfo> FROM_PROTOBUF_FUNCTION =
new Function<Constraint, ConstraintInfo>() {
@Override
public ConstraintInfo apply(Constraint protobuf) {
return ConstraintInfo.fromProtobuf(protobuf);
}
};
static final Function<ConstraintInfo, Constraint> TO_PROTOBUF_FUNCTION =
new Function<ConstraintInfo, Constraint>() {
@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();
}
}