Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gcloud dns #559

Merged
merged 8 commits into from
Jan 22, 2016
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions gcloud-java-dns/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.gcloud</groupId>
<artifactId>gcloud-java-dns</artifactId>
<packaging>jar</packaging>
<name>GCloud Java DNS</name>
<description>
Java idiomatic client for Google Cloud DNS.
</description>
<parent>
<groupId>com.google.gcloud</groupId>
<artifactId>gcloud-java-pom</artifactId>
<version>0.1.3-SNAPSHOT</version>
</parent>
<properties>
<site.installationModule>gcloud-java-dns</site.installationModule>
</properties>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>gcloud-java-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-dns</artifactId>
<version>v1-rev7-1.21.0</version>
<scope>compile</scope>
<exclusions>
<exclusion>

This comment was marked as spam.

This comment was marked as spam.

<groupId>com.google.guava</groupId>
<artifactId>guava-jdk5</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>3.3</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
280 changes: 280 additions & 0 deletions gcloud-java-dns/src/main/java/com/google/gcloud/dns/DnsRecord.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
/*
* 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;

This comment was marked as spam.

This comment was marked as spam.


import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;

import java.io.Serializable;

This comment was marked as spam.

This comment was marked as spam.

import java.util.LinkedList;
import java.util.List;
import java.util.Objects;

/**
* A class that represents Google Cloud DNS record set.

This comment was marked as spam.

This comment was marked as spam.

*
* <p>A unit of data that will be returned by the DNS servers.

This comment was marked as spam.

This comment was marked as spam.

*
* @see <a href="https://cloud.google.com/dns/api/v1/resourceRecordSets">Google Cloud DNS
* documentation</a>
*/
public class DnsRecord implements Serializable {

private static final long serialVersionUID = 2016011914302204L;
private final String name;
private final List<String> rrdatas;
private final Integer ttl;
private final DnsRecordType type;
private final String zoneName;
private final Long zoneId;

private DnsRecord() {

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

this.name = null;
this.rrdatas = null;
this.ttl = null;
this.type = null;
this.zoneName = null;
this.zoneId = null;
}

DnsRecord(Builder builder) {
this.name = builder.name;
this.rrdatas = ImmutableList.copyOf(builder.rrdatas);
this.ttl = builder.ttl;
this.type = builder.type;
this.zoneName = builder.zoneName;
this.zoneId = builder.zoneId;
}

/**
* Enum for the DNS record types supported by Cloud DNS.
*
* <p>Google Cloud DNS currently supports records of type A, AAAA, CNAME, MX NAPTR, NS, PTR, SOA,
* SPF, SRV, TXT.
*
* @see <a href="https://cloud.google.com/dns/what-is-cloud-dns#supported_record_types">Cloud DNS
* supported record types</a>
*/
public enum DnsRecordType {

This comment was marked as spam.

This comment was marked as spam.

A,

This comment was marked as spam.

This comment was marked as spam.

AAAA,
CNAME,
MX,
NAPTR,
NS,
PTR,
SOA,
SPF,
SRV,
TXT
}

public static class Builder {

This comment was marked as spam.

This comment was marked as spam.


private List<String> rrdatas = new LinkedList<>();
private String name;
private Integer ttl;
private DnsRecordType type;
private String zoneName;
private Long zoneId;

private Builder() {

This comment was marked as spam.

This comment was marked as spam.

}

/**
* Creates a builder and pre-populates attributes with the values from the provided DnsRecord
* instance.
*/
public Builder(DnsRecord record) {

This comment was marked as spam.

This comment was marked as spam.

this.name = record.name;
this.ttl = record.ttl;
this.type = record.type;
this.zoneId = record.zoneId;
this.zoneName = record.zoneName;
this.rrdatas.addAll(record.rrdatas);
}

/**
* Adds a record to the record set. The records should be as defined in RFC 1035 (section 5) and
* RFC 1034 (section 3.6.1). Examples of records are available in Google DNS documentation.
*
* @see <a href="https://cloud.google.com/dns/what-is-cloud-dns#supported_record_types">Google
* DNS documentation </a>.
*/
public Builder add(String record) {

This comment was marked as spam.

This comment was marked as spam.

this.rrdatas.add(checkNotNull(record));
return this;
}

/**
* Sets name for this DNS record set. For example, www.example.com.
*/
public Builder name(String name) {
this.name = checkNotNull(name);
return this;
}

/**
* Sets the number of seconds that this record can be cached by resolvers. This number must be
* non-negative.
*
* @param ttl A non-negative number of seconds
*/
public Builder ttl(int ttl) {
checkArgument(ttl >= 0, "TTL cannot be negative. The supplied value was " + ttl + ".");

This comment was marked as spam.

This comment was marked as spam.

this.ttl = ttl;
return this;
}

/**
* The identifier of a supported record type, for example, A, AAAA, MX, TXT, and so on.
*/
public Builder type(DnsRecordType type) {
this.type = checkNotNull(type);
return this;
}

/**
* Builds the DNS record.
*/
public DnsRecord build() {
return new DnsRecord(this);
}

/**
* Sets references to the managed zone that this DNS record belongs to.
*
* todo(mderka): consider if this method is needed; may not be possible when listing records

This comment was marked as spam.

This comment was marked as spam.

*/
Builder managedZone(ManagedZoneInfo parent) {

This comment was marked as spam.

This comment was marked as spam.

checkNotNull(parent);
this.zoneId = parent.id();
this.zoneName = parent.name();
return this;
}

/**
* Sets name reference to the managed zone that this DNS record belongs to.
*/
Builder managedZone(String managedZoneName) {
this.zoneName = checkNotNull(managedZoneName);
return this;
}
}

/**
* Creates a builder pre-populated with the attribute values of this instance.
*/
public Builder toBuilder() {
return new Builder(this);
}

/**
* Creates an empty builder

This comment was marked as spam.

This comment was marked as spam.

*/
public static Builder builder() {

This comment was marked as spam.

This comment was marked as spam.

return new Builder();
}

/**
* Get the mandatory user assigned name of this DNS record.

This comment was marked as spam.

This comment was marked as spam.

*/
public String name() {
return name;
}

/**
* Returns a list of DNS record stored in this record set.
*/
public List<String> rrdatas() {

This comment was marked as spam.

This comment was marked as spam.

return rrdatas;
}

/**

This comment was marked as spam.

This comment was marked as spam.

* Returns the number of seconds that this DnsResource can be cached by resolvers. This number is
* provided by the user.
*/
public Integer ttl() {
return ttl;
}

/**
* Returns the type of this DNS record.
*/
public DnsRecordType type() {
return type;
}

/**
* Returns name of the managed zone that this record belongs to. The name of the managed zone is

This comment was marked as spam.

This comment was marked as spam.

* provided by the user when the managed zone is created. It is unique within a project. If this
* DNS record is not associated with a managed zone, this returns null.
*/
public String zoneName() {
return zoneName;
}

/**
* Returns id of the managed zone that this record belongs to.
*
* <p>The id of the managed zone is determined by the server when the managed zone is created. It
* is a read only value. If this DNS record is not associated with a managed zone, or if the id of
* the managed zone was not loaded from the cloud service, this returns null.
*/
public Long zoneId() {
return zoneId;
}

@Override
public int hashCode() {
return Objects.hash(name, rrdatas, ttl, type, zoneName, zoneId);
}

@Override
public boolean equals(Object obj) {
return (obj instanceof DnsRecord) && Objects.equals(this.toPb(), ((DnsRecord) obj).toPb())
&& this.zoneId().equals(((DnsRecord) obj).zoneId())
&& this.zoneName().equals(((DnsRecord) obj).zoneName());

}

com.google.api.services.dns.model.ResourceRecordSet toPb() {
com.google.api.services.dns.model.ResourceRecordSet pb =
new com.google.api.services.dns.model.ResourceRecordSet();

This comment was marked as spam.

This comment was marked as spam.

pb.setName(this.name());

This comment was marked as spam.

This comment was marked as spam.

pb.setRrdatas(this.rrdatas());
pb.setTtl(this.ttl());
pb.setType(this.type() == null ? null : this.type().name());

This comment was marked as spam.

This comment was marked as spam.

return pb;
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("name", name())

This comment was marked as spam.

This comment was marked as spam.

.add("rrdatas", rrdatas())
.add("ttl", ttl())
.add("type", type())
.add("zoneName", zoneName())
.add("zoneId", zoneId())
.toString();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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;

/**
* todo(mderka): Implement.
* todo(mderka): Add documentation.
*/
public class ManagedZoneInfo {

This comment was marked as spam.


private final String name;
private final Long id;

public String name() {
throw new UnsupportedOperationException("Not implemented yet.");
// todo(mderka): Implement
}

public Long id() {
return id;
// todo(mderka): Implement
}

private ManagedZoneInfo() {
name = null;
id = null;
throw new UnsupportedOperationException("Not implemented yet");
// todo(mderka): Implement
}

}
Loading