• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 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 
17 package com.google.cloud.dns;
18 
19 import com.google.api.gax.paging.Page;
20 import com.google.cloud.FieldSelector;
21 import com.google.cloud.FieldSelector.Helper;
22 import com.google.cloud.Service;
23 import com.google.cloud.dns.spi.v1.DnsRpc;
24 import com.google.common.collect.ImmutableList;
25 import java.util.List;
26 
27 /**
28  * An interface for the Google Cloud DNS service.
29  *
30  * @see <a href="https://cloud.google.com/dns/docs">Google Cloud DNS</a>
31  */
32 public interface Dns extends Service<DnsOptions> {
33 
34   /**
35    * The fields of a project.
36    *
37    * <p>These values can be used to specify the fields to include in a partial response when calling
38    * {@link Dns#getProject(ProjectOption...)}. Project ID is always returned, even if not specified.
39    */
40   enum ProjectField implements FieldSelector {
41     PROJECT_ID("id"),
42     PROJECT_NUMBER("number"),
43     QUOTA("quota");
44 
45     static final List<? extends FieldSelector> REQUIRED_FIELDS = ImmutableList.of(PROJECT_ID);
46 
47     private final String selector;
48 
ProjectField(String selector)49     ProjectField(String selector) {
50       this.selector = selector;
51     }
52 
53     @Override
getSelector()54     public String getSelector() {
55       return selector;
56     }
57   }
58 
59   /**
60    * The fields of a zone.
61    *
62    * <p>These values can be used to specify the fields to include in a partial response when calling
63    * {@link Dns#getZone(String, ZoneOption...)}. The name is always returned, even if not specified.
64    */
65   enum ZoneField implements FieldSelector {
66     CREATION_TIME("creationTime"),
67     DESCRIPTION("description"),
68     DNS_NAME("dnsName"),
69     ZONE_ID("id"),
70     NAME("name"),
71     NAME_SERVER_SET("nameServerSet"),
72     NAME_SERVERS("nameServers"),
73     DNSSEC("dnssecConfig"),
74     LABELS("labels");
75 
76     static final List<? extends FieldSelector> REQUIRED_FIELDS = ImmutableList.of(NAME);
77 
78     private final String selector;
79 
ZoneField(String selector)80     ZoneField(String selector) {
81       this.selector = selector;
82     }
83 
84     @Override
getSelector()85     public String getSelector() {
86       return selector;
87     }
88   }
89 
90   /**
91    * The fields of a record set.
92    *
93    * <p>These values can be used to specify the fields to include in a partial response when calling
94    * {@link Dns#listRecordSets(String, RecordSetListOption...)}. The name and type are always
95    * returned even if not selected.
96    */
97   enum RecordSetField implements FieldSelector {
98     DNS_RECORDS("rrdatas"),
99     NAME("name"),
100     TTL("ttl"),
101     TYPE("type");
102 
103     static final List<? extends FieldSelector> REQUIRED_FIELDS = ImmutableList.of(NAME, TYPE);
104 
105     private final String selector;
106 
RecordSetField(String selector)107     RecordSetField(String selector) {
108       this.selector = selector;
109     }
110 
111     @Override
getSelector()112     public String getSelector() {
113       return selector;
114     }
115   }
116 
117   /**
118    * The fields of a change request.
119    *
120    * <p>These values can be used to specify the fields to include in a partial response when calling
121    * {@link Dns#applyChangeRequest(String, ChangeRequestInfo, ChangeRequestOption...)} The ID is
122    * always returned even if not selected.
123    */
124   enum ChangeRequestField implements FieldSelector {
125     ID("id"),
126     START_TIME("startTime"),
127     STATUS("status"),
128     ADDITIONS("additions"),
129     DELETIONS("deletions");
130 
131     static final List<? extends FieldSelector> REQUIRED_FIELDS = ImmutableList.of(ID);
132 
133     private final String selector;
134 
ChangeRequestField(String selector)135     ChangeRequestField(String selector) {
136       this.selector = selector;
137     }
138 
139     @Override
getSelector()140     public String getSelector() {
141       return selector;
142     }
143   }
144 
145   /** The sorting order for listing. */
146   enum SortingOrder {
147     DESCENDING,
148     ASCENDING;
149 
selector()150     public String selector() {
151       return name().toLowerCase();
152     }
153   }
154 
155   /** Class for specifying record set listing options. */
156   class RecordSetListOption extends Option {
157 
158     private static final long serialVersionUID = 1009627025381096098L;
159 
RecordSetListOption(DnsRpc.Option option, Object value)160     RecordSetListOption(DnsRpc.Option option, Object value) {
161       super(option, value);
162     }
163 
164     /**
165      * Returns an option to specify the record set's fields to be returned by the RPC call.
166      *
167      * <p>If this option is not provided all record fields are returned. {@code
168      * RecordSetField.fields} can be used to specify only the fields of interest. The name of the
169      * record set in always returned, even if not specified. {@link RecordSetField} provides a list
170      * of fields that can be used.
171      */
fields(RecordSetField... fields)172     public static RecordSetListOption fields(RecordSetField... fields) {
173       return new RecordSetListOption(
174           DnsRpc.Option.FIELDS,
175           Helper.listSelector("rrsets", RecordSetField.REQUIRED_FIELDS, fields));
176     }
177 
178     /**
179      * Returns an option to specify a page token.
180      *
181      * <p>The page token (returned from a previous call to list) indicates from where listing should
182      * continue.
183      */
pageToken(String pageToken)184     public static RecordSetListOption pageToken(String pageToken) {
185       return new RecordSetListOption(DnsRpc.Option.PAGE_TOKEN, pageToken);
186     }
187 
188     /**
189      * The maximum number of record sets to return per RPC.
190      *
191      * <p>The server can return fewer record sets than requested. When there are more results than
192      * the page size, the server will return a page token that can be used to fetch other results.
193      */
pageSize(int pageSize)194     public static RecordSetListOption pageSize(int pageSize) {
195       return new RecordSetListOption(DnsRpc.Option.PAGE_SIZE, pageSize);
196     }
197 
198     /** Restricts the list to only record sets with this fully qualified domain name. */
dnsName(String dnsName)199     public static RecordSetListOption dnsName(String dnsName) {
200       return new RecordSetListOption(DnsRpc.Option.NAME, dnsName);
201     }
202 
203     /**
204      * Restricts the list to return only record sets of this type. If present, {@link
205      * RecordSetListOption#dnsName(String)} must also be present.
206      */
type(RecordSet.Type type)207     public static RecordSetListOption type(RecordSet.Type type) {
208       return new RecordSetListOption(DnsRpc.Option.DNS_TYPE, type.name());
209     }
210   }
211 
212   /** Class for specifying zone field options. */
213   class ZoneOption extends Option {
214 
215     private static final long serialVersionUID = -8065564464895945037L;
216 
ZoneOption(DnsRpc.Option option, Object value)217     ZoneOption(DnsRpc.Option option, Object value) {
218       super(option, value);
219     }
220 
221     /**
222      * Returns an option to specify the zones's fields to be returned by the RPC call.
223      *
224      * <p>If this option is not provided all zone fields are returned. {@code ZoneOption.fields} can
225      * be used to specify only the fields of interest. Zone ID is always returned, even if not
226      * specified. {@link ZoneField} provides a list of fields that can be used.
227      */
fields(ZoneField... fields)228     public static ZoneOption fields(ZoneField... fields) {
229       return new ZoneOption(
230           DnsRpc.Option.FIELDS, Helper.selector(ZoneField.REQUIRED_FIELDS, fields));
231     }
232   }
233 
234   /** Class for specifying zone listing options. */
235   class ZoneListOption extends Option {
236 
237     private static final long serialVersionUID = -2830645032124504717L;
238 
ZoneListOption(DnsRpc.Option option, Object value)239     ZoneListOption(DnsRpc.Option option, Object value) {
240       super(option, value);
241     }
242 
243     /**
244      * Returns an option to specify the zones's fields to be returned by the RPC call.
245      *
246      * <p>If this option is not provided all zone fields are returned. {@code ZoneOption.fields} can
247      * be used to specify only the fields of interest. Zone ID is always returned, even if not
248      * specified. {@link ZoneField} provides a list of fields that can be used.
249      */
fields(ZoneField... fields)250     public static ZoneListOption fields(ZoneField... fields) {
251       return new ZoneListOption(
252           DnsRpc.Option.FIELDS,
253           Helper.listSelector("managedZones", ZoneField.REQUIRED_FIELDS, fields));
254     }
255 
256     /**
257      * Returns an option to specify a page token.
258      *
259      * <p>The page token (returned from a previous call to list) indicates from where listing should
260      * continue.
261      */
pageToken(String pageToken)262     public static ZoneListOption pageToken(String pageToken) {
263       return new ZoneListOption(DnsRpc.Option.PAGE_TOKEN, pageToken);
264     }
265 
266     /** Restricts the list to only zone with this fully qualified domain name. */
dnsName(String dnsName)267     public static ZoneListOption dnsName(String dnsName) {
268       return new ZoneListOption(DnsRpc.Option.DNS_NAME, dnsName);
269     }
270 
271     /**
272      * The maximum number of zones to return per RPC.
273      *
274      * <p>The server can return fewer zones than requested. When there are more results than the
275      * page size, the server will return a page token that can be used to fetch other results.
276      */
pageSize(int pageSize)277     public static ZoneListOption pageSize(int pageSize) {
278       return new ZoneListOption(DnsRpc.Option.PAGE_SIZE, pageSize);
279     }
280   }
281 
282   /** Class for specifying project options. */
283   class ProjectOption extends Option {
284 
285     private static final long serialVersionUID = 6817937338218847748L;
286 
ProjectOption(DnsRpc.Option option, Object value)287     ProjectOption(DnsRpc.Option option, Object value) {
288       super(option, value);
289     }
290 
291     /**
292      * Returns an option to specify the project's fields to be returned by the RPC call.
293      *
294      * <p>If this option is not provided all project fields are returned. {@code
295      * ProjectOption.fields} can be used to specify only the fields of interest. Project ID is
296      * always returned, even if not specified. {@link ProjectField} provides a list of fields that
297      * can be used.
298      */
fields(ProjectField... fields)299     public static ProjectOption fields(ProjectField... fields) {
300       return new ProjectOption(
301           DnsRpc.Option.FIELDS, Helper.selector(ProjectField.REQUIRED_FIELDS, fields));
302     }
303   }
304 
305   /** Class for specifying change request field options. */
306   class ChangeRequestOption extends Option {
307 
308     private static final long serialVersionUID = 1067273695061077782L;
309 
ChangeRequestOption(DnsRpc.Option option, Object value)310     ChangeRequestOption(DnsRpc.Option option, Object value) {
311       super(option, value);
312     }
313 
314     /**
315      * Returns an option to specify which fields of {@link ChangeRequest} should be returned by the
316      * service.
317      *
318      * <p>If this option is not provided all change request fields are returned. {@code
319      * ChangeRequestOption.fields} can be used to specify only the fields of interest. The ID of the
320      * change request is always returned, even if not specified. {@link ChangeRequestField} provides
321      * a list of fields that can be used.
322      */
fields(ChangeRequestField... fields)323     public static ChangeRequestOption fields(ChangeRequestField... fields) {
324       return new ChangeRequestOption(
325           DnsRpc.Option.FIELDS, Helper.selector(ChangeRequestField.REQUIRED_FIELDS, fields));
326     }
327   }
328 
329   /** Class for specifying change request listing options. */
330   class ChangeRequestListOption extends Option {
331 
332     private static final long serialVersionUID = -900209143895376089L;
333 
ChangeRequestListOption(DnsRpc.Option option, Object value)334     ChangeRequestListOption(DnsRpc.Option option, Object value) {
335       super(option, value);
336     }
337 
338     /**
339      * Returns an option to specify which fields of{@link ChangeRequest} should be returned by the
340      * service.
341      *
342      * <p>If this option is not provided all change request fields are returned. {@code
343      * ChangeRequestOption.fields} can be used to specify only the fields of interest. The ID of the
344      * change request is always returned, even if not specified. {@link ChangeRequestField} provides
345      * a list of fields that can be used.
346      */
fields(ChangeRequestField... fields)347     public static ChangeRequestListOption fields(ChangeRequestField... fields) {
348       return new ChangeRequestListOption(
349           DnsRpc.Option.FIELDS,
350           Helper.listSelector("changes", ChangeRequestField.REQUIRED_FIELDS, fields));
351     }
352 
353     /**
354      * Returns an option to specify a page token.
355      *
356      * <p>The page token (returned from a previous call to list) indicates from where listing should
357      * continue.
358      */
pageToken(String pageToken)359     public static ChangeRequestListOption pageToken(String pageToken) {
360       return new ChangeRequestListOption(DnsRpc.Option.PAGE_TOKEN, pageToken);
361     }
362 
363     /**
364      * The maximum number of change requests to return per RPC.
365      *
366      * <p>The server can return fewer change requests than requested. When there are more results
367      * than the page size, the server will return a page token that can be used to fetch other
368      * results.
369      */
pageSize(int pageSize)370     public static ChangeRequestListOption pageSize(int pageSize) {
371       return new ChangeRequestListOption(DnsRpc.Option.PAGE_SIZE, pageSize);
372     }
373 
374     /**
375      * Returns an option to specify whether the the change requests should be listed in ascending
376      * (most-recent last) or descending (most-recent first) order with respect to when the change
377      * request was accepted by the server. If this option is not provided, the listing order is
378      * undefined.
379      */
sortOrder(SortingOrder order)380     public static ChangeRequestListOption sortOrder(SortingOrder order) {
381       return new ChangeRequestListOption(DnsRpc.Option.SORTING_ORDER, order.selector());
382     }
383   }
384 
385   /**
386    * Creates a new zone.
387    *
388    * <p>Returns {@link Zone} object representing the new zone's information. In addition to the
389    * name, dns name and description (supplied by the user within the {@code zoneInfo} parameter),
390    * the returned object can include the following read-only fields supplied by the server: creation
391    * time, id, and list of name servers. The returned fields can be optionally restricted by
392    * specifying {@link ZoneOption}s.
393    *
394    * @throws DnsException upon failure
395    * @see <a href="https://cloud.google.com/dns/api/v1/managedZones/create">Cloud DNS Managed Zones:
396    *     create</a>
397    */
create(ZoneInfo zoneInfo, ZoneOption... options)398   Zone create(ZoneInfo zoneInfo, ZoneOption... options);
399 
400   /**
401    * Returns the zone by the specified zone name. Returns {@code null} if the zone is not found. The
402    * returned fields can be optionally restricted by specifying {@link ZoneOption}s.
403    *
404    * @throws DnsException upon failure
405    * @see <a href="https://cloud.google.com/dns/api/v1/managedZones/get">Cloud DNS Managed Zones:
406    *     get</a>
407    */
getZone(String zoneName, ZoneOption... options)408   Zone getZone(String zoneName, ZoneOption... options);
409 
410   /**
411    * Lists the zones inside the project.
412    *
413    * <p>This method returns zones in an unspecified order. New zones do not necessarily appear at
414    * the end of the list. Use {@link ZoneListOption} to restrict the listing to a domain name, set
415    * page size, and set page token.
416    *
417    * @return a page of zones
418    * @throws DnsException upon failure
419    * @see <a href="https://cloud.google.com/dns/api/v1/managedZones/list">Cloud DNS Managed Zones:
420    *     list</a>
421    */
listZones(ZoneListOption... options)422   Page<Zone> listZones(ZoneListOption... options);
423 
424   /**
425    * Deletes an existing zone identified by name. Returns {@code true} if the zone was successfully
426    * deleted and {@code false} otherwise.
427    *
428    * @return {@code true} if zone was found and deleted and {@code false} otherwise
429    * @throws DnsException upon failure
430    * @see <a href="https://cloud.google.com/dns/api/v1/managedZones/delete">Cloud DNS Managed Zones:
431    *     delete</a>
432    */
delete(String zoneName)433   boolean delete(String zoneName); // delete does not admit any options
434 
435   /**
436    * Lists the record sets in the zone identified by name.
437    *
438    * <p>The fields to be returned, page size and page tokens can be specified using {@link
439    * RecordSetListOption}s.
440    *
441    * @throws DnsException upon failure or if the zone cannot be found
442    * @see <a href="https://cloud.google.com/dns/api/v1/resourceRecordSets/list">Cloud DNS
443    *     ResourceRecordSets: list</a>
444    */
listRecordSets(String zoneName, RecordSetListOption... options)445   Page<RecordSet> listRecordSets(String zoneName, RecordSetListOption... options);
446 
447   /**
448    * Retrieves the information about the current project. The returned fields can be optionally
449    * restricted by specifying {@link ProjectOption}s.
450    *
451    * @throws DnsException upon failure
452    * @see <a href="https://cloud.google.com/dns/api/v1/projects/get">Cloud DNS Projects: get</a>
453    */
getProject(ProjectOption... fields)454   ProjectInfo getProject(ProjectOption... fields);
455 
456   /**
457    * Submits a change request for the specified zone. The returned object contains the following
458    * read-only fields supplied by the server: id, start time and status. time, id, and list of name
459    * servers. The fields to be returned can be selected by {@link ChangeRequestOption}s.
460    *
461    * @return the new {@link ChangeRequest}
462    * @throws DnsException upon failure or if zone is not found
463    * @see <a href="https://cloud.google.com/dns/api/v1/changes/create">Cloud DNS Changes: create</a>
464    */
applyChangeRequest( String zoneName, ChangeRequestInfo changeRequest, ChangeRequestOption... options)465   ChangeRequest applyChangeRequest(
466       String zoneName, ChangeRequestInfo changeRequest, ChangeRequestOption... options);
467 
468   /**
469    * Retrieves updated information about a change request previously submitted for a zone identified
470    * by ID. Returns {@code null} if the request cannot be found and throws an exception if the zone
471    * does not exist. The fields to be returned using can be specified using {@link
472    * ChangeRequestOption}s.
473    *
474    * @throws DnsException upon failure or if the zone cannot be found
475    * @see <a href="https://cloud.google.com/dns/api/v1/changes/get">Cloud DNS Chages: get</a>
476    */
getChangeRequest( String zoneName, String changeRequestId, ChangeRequestOption... options)477   ChangeRequest getChangeRequest(
478       String zoneName, String changeRequestId, ChangeRequestOption... options);
479 
480   /**
481    * Lists the change requests for the zone identified by name that were submitted to the service.
482    *
483    * <p>The sorting order for changes (based on when they were received by the server), fields to be
484    * returned, page size and page token can be specified using {@link ChangeRequestListOption}s.
485    *
486    * @return A page of change requests
487    * @throws DnsException upon failure or if the zone cannot be found
488    * @see <a href="https://cloud.google.com/dns/api/v1/changes/list">Cloud DNS Chages: list</a>
489    */
listChangeRequests(String zoneName, ChangeRequestListOption... options)490   Page<ChangeRequest> listChangeRequests(String zoneName, ChangeRequestListOption... options);
491 
492   /** Creates a new empty batch for grouping multiple service calls in one underlying RPC call. */
batch()493   DnsBatch batch();
494 }
495