1919import static com .google .common .base .Preconditions .checkNotNull ;
2020import static com .google .common .collect .Lists .transform ;
2121
22+ import com .google .api .client .util .Data ;
2223import com .google .api .services .dns .model .DnsKeySpec ;
2324import com .google .api .services .dns .model .ManagedZone ;
2425import com .google .api .services .dns .model .ManagedZoneDnsSecConfig ;
2728import com .google .common .collect .ImmutableList ;
2829import com .google .common .collect .ImmutableSet ;
2930import com .google .common .collect .Lists ;
31+ import com .google .common .collect .Maps ;
3032import java .io .Serializable ;
3133import java .math .BigInteger ;
3234import java .util .List ;
35+ import java .util .Map ;
3336import java .util .Objects ;
3437import java .util .Set ;
3538import org .threeten .bp .Instant ;
@@ -56,6 +59,7 @@ public class ZoneInfo implements Serializable {
5659 private final String nameServerSet ;
5760 private final List <String > nameServers ;
5861 private final DnsSecConfig dnsSecConfig ;
62+ private final Map <String , String > labels ;
5963
6064 /** This class represents the DNS key spec. */
6165 public static class KeySpec {
@@ -379,6 +383,11 @@ public Builder setDnsSecConfig(DnsSecConfig dnsSecConfig) {
379383 return this ;
380384 }
381385
386+ /** Sets the label of this zone. */
387+ public Builder setLabels (Map <String , String > labels ) {
388+ return this ;
389+ }
390+
382391 /** Builds the instance of {@code ZoneInfo} based on the information set by this builder. */
383392 public abstract ZoneInfo build ();
384393 }
@@ -392,6 +401,7 @@ static class BuilderImpl extends Builder {
392401 private String nameServerSet ;
393402 private List <String > nameServers ;
394403 private DnsSecConfig dnsSecConfig ;
404+ private Map <String , String > labels ;
395405
396406 private BuilderImpl (String name ) {
397407 this .name = checkNotNull (name );
@@ -409,6 +419,7 @@ private BuilderImpl(String name) {
409419 this .nameServers = ImmutableList .copyOf (info .nameServers );
410420 }
411421 this .dnsSecConfig = info .dnsSecConfig ;
422+ this .labels = info .labels ;
412423 }
413424
414425 @ Override
@@ -460,6 +471,23 @@ public Builder setDnsSecConfig(DnsSecConfig dnsSecConfig) {
460471 return this ;
461472 }
462473
474+ @ Override
475+ public Builder setLabels (Map <String , String > labels ) {
476+ if (labels != null ) {
477+ this .labels =
478+ Maps .transformValues (
479+ labels ,
480+ new Function <String , String >() {
481+ @ Override
482+ public String apply (String input ) {
483+ // replace null values with empty strings
484+ return input == null ? Data .<String >nullOf (String .class ) : input ;
485+ }
486+ });
487+ }
488+ return this ;
489+ }
490+
463491 @ Override
464492 public ZoneInfo build () {
465493 return new ZoneInfo (this );
@@ -476,6 +504,7 @@ public ZoneInfo build() {
476504 this .nameServers =
477505 builder .nameServers == null ? null : ImmutableList .copyOf (builder .nameServers );
478506 this .dnsSecConfig = builder .dnsSecConfig ;
507+ this .labels = builder .labels ;
479508 }
480509
481510 /**
@@ -523,6 +552,11 @@ public String getNameServerSet() {
523552 return nameServerSet ;
524553 }
525554
555+ /** Returns the labels for this zone. */
556+ public Map <String , String > getLabels () {
557+ return labels ;
558+ }
559+
526560 /**
527561 * The nameservers that the zone should be delegated to. This is defined by the Google DNS cloud.
528562 */
@@ -556,6 +590,9 @@ ManagedZone toPb() {
556590 if (this .dnsSecConfig != null ) {
557591 pb .setDnssecConfig (this .dnsSecConfig .toPb ());
558592 }
593+ if (this .getLabels () != null ) {
594+ pb .setLabels (labels );
595+ }
559596 return pb ;
560597 }
561598
@@ -583,6 +620,9 @@ static ZoneInfo fromPb(ManagedZone pb) {
583620 if (pb .getDnssecConfig () != null ) {
584621 builder .setDnsSecConfig (DnsSecConfig .fromPb (pb .getDnssecConfig ()));
585622 }
623+ if (pb .getLabels () != null ) {
624+ builder .setLabels (pb .getLabels ());
625+ }
586626 return builder .build ();
587627 }
588628
@@ -604,7 +644,8 @@ public int hashCode() {
604644 description ,
605645 nameServerSet ,
606646 nameServers ,
607- dnsSecConfig );
647+ dnsSecConfig ,
648+ labels );
608649 }
609650
610651 @ Override
@@ -618,6 +659,7 @@ public String toString() {
618659 .add ("nameServers" , getNameServers ())
619660 .add ("creationTimeMillis" , getCreationTimeMillis ())
620661 .add ("dnsSecConfig" , getDnsSecConfig ())
662+ .add ("labels" , getLabels ())
621663 .toString ();
622664 }
623665}
0 commit comments