forked from googleapis/google-cloud-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDns.java
More file actions
544 lines (473 loc) · 19 KB
/
Dns.java
File metadata and controls
544 lines (473 loc) · 19 KB
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
/*
* Copyright 2016 Google Inc. All Rights Reserved.
*
* 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.gcloud.dns;
import com.google.common.base.Joiner;
import com.google.common.collect.Sets;
import com.google.gcloud.Page;
import com.google.gcloud.Service;
import com.google.gcloud.dns.spi.DnsRpc;
import java.io.Serializable;
import java.util.Set;
/**
* An interface for the Google Cloud DNS service.
*
* @see <a href="https://cloud.google.com/dns/docs">Google Cloud DNS</a>
*/
public interface Dns extends Service<DnsOptions> {
/**
* The fields of a project.
*
* <p>These values can be used to specify the fields to include in a partial response when calling
* {@link Dns#getProject(ProjectOption...)}. Project ID is always returned, even if not
* specified.
*/
enum ProjectField {
PROJECT_ID("id"),
PROJECT_NUMBER("number"),
QUOTA("quota");
private final String selector;
ProjectField(String selector) {
this.selector = selector;
}
String selector() {
return selector;
}
static String selector(ProjectField... fields) {
Set<String> fieldStrings = Sets.newHashSetWithExpectedSize(fields.length + 1);
fieldStrings.add(PROJECT_ID.selector());
for (ProjectField field : fields) {
fieldStrings.add(field.selector());
}
return Joiner.on(',').join(fieldStrings);
}
}
/**
* The fields of a zone.
*
* <p>These values can be used to specify the fields to include in a partial response when calling
* {@link Dns#getZone(String, ZoneOption...)}. The name is always returned, even if not
* specified.
*/
enum ZoneField {
CREATION_TIME("creationTime"),
DESCRIPTION("description"),
DNS_NAME("dnsName"),
ZONE_ID("id"),
NAME("name"),
NAME_SERVER_SET("nameServerSet"),
NAME_SERVERS("nameServers");
private final String selector;
ZoneField(String selector) {
this.selector = selector;
}
String selector() {
return selector;
}
static String selector(ZoneField... fields) {
Set<String> fieldStrings = Sets.newHashSetWithExpectedSize(fields.length + 1);
fieldStrings.add(NAME.selector());
for (ZoneField field : fields) {
fieldStrings.add(field.selector());
}
return Joiner.on(',').join(fieldStrings);
}
}
/**
* The fields of a DNS record.
*
* <p>These values can be used to specify the fields to include in a partial response when calling
* {@link Dns#listDnsRecords(String, DnsRecordListOption...)}. The name and type are always
* returned even if not selected.
*/
enum DnsRecordField {
DNS_RECORDS("rrdatas"),
NAME("name"),
TTL("ttl"),
TYPE("type");
private final String selector;
DnsRecordField(String selector) {
this.selector = selector;
}
String selector() {
return selector;
}
static String selector(DnsRecordField... fields) {
Set<String> fieldStrings = Sets.newHashSetWithExpectedSize(fields.length + 1);
fieldStrings.add(NAME.selector());
fieldStrings.add(TYPE.selector());
for (DnsRecordField field : fields) {
fieldStrings.add(field.selector());
}
return Joiner.on(',').join(fieldStrings);
}
}
/**
* The fields of a change request.
*
* <p>These values can be used to specify the fields to include in a partial response when calling
* {@link Dns#applyChangeRequest(String, ChangeRequest, ChangeRequestOption...)} The ID is always
* returned even if not selected.
*/
enum ChangeRequestField {
ID("id"),
START_TIME("startTime"),
STATUS("status"),
ADDITIONS("additions"),
DELETIONS("deletions");
private final String selector;
ChangeRequestField(String selector) {
this.selector = selector;
}
String selector() {
return selector;
}
static String selector(ChangeRequestField... fields) {
Set<String> fieldStrings = Sets.newHashSetWithExpectedSize(fields.length + 1);
fieldStrings.add(ID.selector());
for (ChangeRequestField field : fields) {
fieldStrings.add(field.selector());
}
return Joiner.on(',').join(fieldStrings);
}
}
/**
* The sorting order for listing.
*/
enum SortingOrder {
DESCENDING, ASCENDING;
public String selector() {
return name().toLowerCase();
}
}
/**
* Class that for specifying DNS record options.
*/
class DnsRecordListOption extends AbstractOption implements Serializable {
private static final long serialVersionUID = 1009627025381096098L;
DnsRecordListOption(DnsRpc.Option option, Object value) {
super(option, value);
}
/**
* Returns an option to specify the DNS record's fields to be returned by the RPC call.
*
* <p>If this option is not provided all record fields are returned. {@code
* DnsRecordField.fields} can be used to specify only the fields of interest. The name of the
* DNS record always returned, even if not specified. {@link DnsRecordField} provides a list of
* fields that can be used.
*/
public static DnsRecordListOption fields(DnsRecordField... fields) {
StringBuilder builder = new StringBuilder();
builder.append("nextPageToken,rrsets(").append(DnsRecordField.selector(fields)).append(')');
return new DnsRecordListOption(DnsRpc.Option.FIELDS, builder.toString());
}
/**
* Returns an option to specify a page token.
*
* <p>The page token (returned from a previous call to list) indicates from where listing should
* continue.
*/
public static DnsRecordListOption pageToken(String pageToken) {
return new DnsRecordListOption(DnsRpc.Option.PAGE_TOKEN, pageToken);
}
/**
* The maximum number of DNS records to return per RPC.
*
* <p>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 DnsRecordListOption pageSize(int pageSize) {
return new DnsRecordListOption(DnsRpc.Option.PAGE_SIZE, pageSize);
}
/**
* Restricts the list to only DNS records with this fully qualified domain name.
*/
public static DnsRecordListOption dnsName(String dnsName) {
return new DnsRecordListOption(DnsRpc.Option.NAME, dnsName);
}
/**
* Restricts the list to return only records of this type. If present, {@link
* Dns.DnsRecordListOption#dnsName(String)} must also be present.
*/
public static DnsRecordListOption type(DnsRecord.Type type) {
return new DnsRecordListOption(DnsRpc.Option.DNS_TYPE, type.name());
}
}
/**
* Class for specifying zone field options.
*/
class ZoneOption extends AbstractOption implements Serializable {
private static final long serialVersionUID = -8065564464895945037L;
ZoneOption(DnsRpc.Option option, Object value) {
super(option, value);
}
/**
* Returns an option to specify the zones's fields to be returned by the RPC call.
*
* <p>If this option is not provided all zone fields are returned. {@code ZoneOption.fields} can
* be used to specify only the fields of interest. Zone ID is always returned, even if not
* specified. {@link ZoneField} provides a list of fields that can be used.
*/
public static ZoneOption fields(ZoneField... fields) {
return new ZoneOption(DnsRpc.Option.FIELDS, ZoneField.selector(fields));
}
}
/**
* Class for specifying zone listing options.
*/
class ZoneListOption extends AbstractOption implements Serializable {
private static final long serialVersionUID = -2830645032124504717L;
ZoneListOption(DnsRpc.Option option, Object value) {
super(option, value);
}
/**
* Returns an option to specify the zones's fields to be returned by the RPC call.
*
* <p>If this option is not provided all zone fields are returned. {@code ZoneOption.fields} can
* be used to specify only the fields of interest. Zone ID is always returned, even if not
* specified. {@link ZoneField} provides a list of fields that can be used.
*/
public static ZoneListOption fields(ZoneField... fields) {
StringBuilder builder = new StringBuilder();
builder.append("nextPageToken,managedZones(").append(ZoneField.selector(fields)).append(')');
return new ZoneListOption(DnsRpc.Option.FIELDS, builder.toString());
}
/**
* Returns an option to specify a page token.
*
* <p>The page token (returned from a previous call to list) indicates from where listing should
* continue.
*/
public static ZoneListOption pageToken(String pageToken) {
return new ZoneListOption(DnsRpc.Option.PAGE_TOKEN, pageToken);
}
/**
* Restricts the list to only zone with this fully qualified domain name.
*/
public static ZoneListOption dnsName(String dnsName) {
StringBuilder builder = new StringBuilder();
return new ZoneListOption(DnsRpc.Option.DNS_NAME, dnsName);
}
/**
* The maximum number of zones to return per RPC.
*
* <p>The server can return fewer zones 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 ZoneListOption pageSize(int pageSize) {
return new ZoneListOption(DnsRpc.Option.PAGE_SIZE, pageSize);
}
}
/**
* Class for specifying project options.
*/
class ProjectOption extends AbstractOption implements Serializable {
private static final long serialVersionUID = 6817937338218847748L;
ProjectOption(DnsRpc.Option option, Object value) {
super(option, value);
}
/**
* Returns an option to specify the project's fields to be returned by the RPC call.
*
* <p>If this option is not provided all project fields are returned. {@code
* ProjectOption.fields} can be used to specify only the fields of interest. Project ID is
* always returned, even if not specified. {@link ProjectField} provides a list of fields that
* can be used.
*/
public static ProjectOption fields(ProjectField... fields) {
return new ProjectOption(DnsRpc.Option.FIELDS, ProjectField.selector(fields));
}
}
/**
* Class for specifying change request field options.
*/
class ChangeRequestOption extends AbstractOption implements Serializable {
private static final long serialVersionUID = 1067273695061077782L;
ChangeRequestOption(DnsRpc.Option option, Object value) {
super(option, value);
}
/**
* Returns an option to specify which fields of {@link ChangeRequest} should be returned by the
* service.
*
* <p>If this option is not provided all change request fields are returned. {@code
* ChangeRequestOption.fields} can be used to specify only the fields of interest. The ID of the
* change request is always returned, even if not specified. {@link ChangeRequestField} provides
* a list of fields that can be used.
*/
public static ChangeRequestOption fields(ChangeRequestField... fields) {
return new ChangeRequestOption(
DnsRpc.Option.FIELDS,
ChangeRequestField.selector(fields)
);
}
}
/**
* Class for specifying change request listing options.
*/
class ChangeRequestListOption extends AbstractOption implements Serializable {
private static final long serialVersionUID = -900209143895376089L;
ChangeRequestListOption(DnsRpc.Option option, Object value) {
super(option, value);
}
/**
* Returns an option to specify which fields of{@link ChangeRequest} should be returned by the
* service.
*
* <p>If this option is not provided all change request fields are returned. {@code
* ChangeRequestOption.fields} can be used to specify only the fields of interest. The ID of the
* change request is always returned, even if not specified. {@link ChangeRequestField} provides
* a list of fields that can be used.
*/
public static ChangeRequestListOption fields(ChangeRequestField... fields) {
StringBuilder builder = new StringBuilder();
builder.append("nextPageToken,changes(").append(ChangeRequestField.selector(fields))
.append(')');
return new ChangeRequestListOption(DnsRpc.Option.FIELDS, builder.toString());
}
/**
* Returns an option to specify a page token.
*
* <p>The page token (returned from a previous call to list) indicates from where listing should
* continue.
*/
public static ChangeRequestListOption pageToken(String pageToken) {
return new ChangeRequestListOption(DnsRpc.Option.PAGE_TOKEN, pageToken);
}
/**
* The maximum number of change requests to return per RPC.
*
* <p>The server can return fewer change requests 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 ChangeRequestListOption pageSize(int pageSize) {
return new ChangeRequestListOption(DnsRpc.Option.PAGE_SIZE, pageSize);
}
/**
* Returns an option to specify whether the the change requests should be listed in ascending
* (most-recent last) or descending (most-recent first) order with respect to when the change
* request was accepted by the server. If this option is not provided, the listing order is
* undefined.
*/
public static ChangeRequestListOption sortOrder(SortingOrder order) {
return new ChangeRequestListOption(DnsRpc.Option.SORTING_ORDER, order.selector());
}
}
/**
* Creates a new zone.
*
* <p>Returns {@link Zone} object representing the new zone's information. In addition to the
* name, dns name and description (supplied by the user within the {@code zoneInfo} parameter),
* the returned object can include the following read-only fields supplied by the server: creation
* time, id, and list of name servers. The returned fields can be optionally restricted by
* specifying {@link ZoneOption}s.
*
* @throws DnsException upon failure
* @see <a href="https://cloud.google.com/dns/api/v1/managedZones/create">Cloud DNS Managed Zones:
* create</a>
*/
Zone create(ZoneInfo zoneInfo, ZoneOption... options);
/**
* Returns the zone by the specified zone name. Returns {@code null} if the zone is not found. The
* returned fields can be optionally restricted by specifying {@link ZoneOption}s.
*
* @throws DnsException upon failure
* @see <a href="https://cloud.google.com/dns/api/v1/managedZones/get">Cloud DNS Managed Zones:
* get</a>
*/
Zone getZone(String zoneName, ZoneOption... options);
/**
* Lists the zones inside the project.
*
* <p>This method returns zones in an unspecified order. New zones do not necessarily appear at
* the end of the list. Use {@link ZoneListOption} to restrict the listing to a domain name, set
* page size, and set page token.
*
* @return a page of zones
* @throws DnsException upon failure
* @see <a href="https://cloud.google.com/dns/api/v1/managedZones/list">Cloud DNS Managed Zones:
* list</a>
*/
Page<Zone> listZones(ZoneListOption... options);
/**
* Deletes an existing zone identified by name. Returns {@code true} if the zone was successfully
* deleted and {@code false} otherwise.
*
* @return {@code true} if zone was found and deleted and {@code false} otherwise
* @throws DnsException upon failure
* @see <a href="https://cloud.google.com/dns/api/v1/managedZones/delete">Cloud DNS Managed Zones:
* delete</a>
*/
boolean delete(String zoneName); // delete does not admit any options
/**
* Lists the DNS records in the zone identified by name.
*
* <p>The fields to be returned, page size and page tokens can be specified using {@link
* DnsRecordListOption}s.
*
* @throws DnsException upon failure or if the zone cannot be found
* @see <a href="https://cloud.google.com/dns/api/v1/resourceRecordSets/list">Cloud DNS
* ResourceRecordSets: list</a>
*/
Page<DnsRecord> listDnsRecords(String zoneName, DnsRecordListOption... options);
/**
* Retrieves the information about the current project. The returned fields can be optionally
* restricted by specifying {@link ProjectOption}s.
*
* @throws DnsException upon failure
* @see <a href="https://cloud.google.com/dns/api/v1/projects/get">Cloud DNS Projects: get</a>
*/
ProjectInfo getProject(ProjectOption... fields);
/**
* Submits a change request for the specified zone. The returned object contains the following
* read-only fields supplied by the server: id, start time and status. time, id, and list of name
* servers. The fields to be returned can be selected by {@link ChangeRequestOption}s.
*
* @return the new {@link ChangeRequest}
* @throws DnsException upon failure if zone is not found
* @see <a href="https://cloud.google.com/dns/api/v1/changes/create">Cloud DNS Changes: create</a>
*/
ChangeRequest applyChangeRequest(String zoneName, ChangeRequest changeRequest,
ChangeRequestOption... options);
/**
* Retrieves updated information about a change request previously submitted for a zone identified
* by ID. Returns {@code null} if the request cannot be found and throws an exception if the zone
* does not exist. The fields to be returned using can be specified using {@link
* ChangeRequestOption}s.
*
* @throws DnsException upon failure or if the zone cannot be found
* @see <a href="https://cloud.google.com/dns/api/v1/changes/get">Cloud DNS Chages: get</a>
*/
ChangeRequest getChangeRequest(String zoneName, String changeRequestId,
ChangeRequestOption... options);
/**
* Lists the change requests for the zone identified by name that were submitted to the service.
*
* <p>The sorting order for changes (based on when they were received by the server), fields to be
* returned, page size and page token can be specified using {@link ChangeRequestListOption}s.
*
* @return A page of change requests
* @throws DnsException upon failure or if the zone cannot be found
* @see <a href="https://cloud.google.com/dns/api/v1/changes/list">Cloud DNS Chages: list</a>
*/
Page<ChangeRequest> listChangeRequests(String zoneName, ChangeRequestListOption... options);
/**
* Initiates a new empty batch ready to be populated with service calls, which will use this
* {@code Dns} instance when submitted for processing to Google Cloud DNS.
*/
DnsBatch batch();
void submitBatch(DnsBatch batch);
}