Skip to content

Commit

Permalink
Merge pull request #358 from Netflix/adrian.revert-zone.ttl
Browse files Browse the repository at this point in the history
Reverts Zone.ttl
  • Loading branch information
adriancole committed Mar 30, 2015
2 parents 7be881b + 4ccab85 commit 31b1842
Show file tree
Hide file tree
Showing 24 changed files with 86 additions and 227 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
### Version 4.5
* Adds `Zone.email()`, `Zone.ttl()` and `Zone.builder()`
* Adds email and ttl to CLI zone list output
* Adds `Zone.email()` and displays it in CLI zone list output
* Adds `ZoneApi.iterateByName()` to support lookups
* Adds `-n` parameter to CLI zone list
* Deprecates `Zone.idOrName()` as `Zone.id()` cannot be null
Expand Down
2 changes: 1 addition & 1 deletion cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ If you just want to fool around, you can use the `mock` provider.
```bash
# first column is the zone id, which isn't always its name!
$ denominator -p mock zone list
denominator.io. denominator.io. admin.denominator.io. 86400
denominator.io. denominator.io. admin.denominator.io.
$ denominator -p mock -z denominator.io. record list
denominator.io. SOA 3600 ns1.denominator.io. admin.denominator.io. 1 3600 600 604800 60
denominator.io. NS 86400 ns1.denominator.io.
Expand Down
3 changes: 1 addition & 2 deletions cli/src/main/java/denominator/cli/Denominator.java
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,7 @@ public Iterator<String> doRun(final DNSApiManager mgr) {
return Iterators.transform(zones, new Function<Zone, String>() {
@Override
public String apply(Zone input) {
return format("%-24s %-36s %-36s %d", input.id(), input.name(), input.email(),
input.ttl());
return format("%-24s %-36s %s", input.id(), input.name(), input.email());
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion cli/src/test/java/denominator/cli/DenominatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void listsAllProvidersWithCredentials() {
@Test // denominator -p mock zone list
public void testZoneList() {
assertThat(new ZoneList().doRun(mgr)).containsExactly(
"denominator.io. denominator.io. admin.denominator.io. 86400"
"denominator.io. denominator.io. admin.denominator.io."
);
}

Expand Down
55 changes: 2 additions & 53 deletions clouddns/src/main/java/denominator/clouddns/CloudDNSZoneApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
import javax.inject.Inject;

import denominator.clouddns.RackspaceApis.CloudDNS;
import denominator.clouddns.RackspaceApis.ListWithNext;
import denominator.model.Zone;

import static denominator.common.Util.singletonIterator;

class CloudDNSZoneApi implements denominator.ZoneApi {

private final CloudDNS api;
Expand All @@ -21,59 +18,11 @@ class CloudDNSZoneApi implements denominator.ZoneApi {

@Override
public Iterator<Zone> iterator() {
return new ZipWithDomain(api.domains());
return api.domains().iterator();
}

@Override
public Iterator<Zone> iterateByName(String name) {
ListWithNext<Zone> zones = api.domainsByName(name);
if (zones.isEmpty()) {
return singletonIterator(null);
}
return singletonIterator(zipWithDomain(zones.get(0)));
}

/**
* CloudDNS only exposes a domain's ttl in the show api.
*/
private Zone zipWithDomain(Zone next) {
int ttl = api.domain(next.id()).ttl();
return Zone.builder()
.name(next.name())
.id(next.id())
.email(next.email())
.ttl(ttl).build();
}

class ZipWithDomain implements Iterator<Zone> {

ListWithNext<Zone> list;
int i = 0;
int length;

ZipWithDomain(ListWithNext<Zone> list) {
this.list = list;
this.length = list.size();
}

@Override
public boolean hasNext() {
while (i == length && list.next != null) {
list = api.domains(list.next);
length = list.size();
i = 0;
}
return i < length;
}

@Override
public Zone next() {
return zipWithDomain(list.get(i++));
}

@Override
public void remove() {
throw new UnsupportedOperationException();
}
return api.domainsByName(name).iterator();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,20 @@ protected String jsonKey() {
}

protected Zone build(JsonReader reader) throws IOException {
Zone.Builder result = new Zone.Builder();
String name = null, id = null, email = null;
while (reader.hasNext()) {
String nextName = reader.nextName();
if (nextName.equals("name")) {
result.name(reader.nextString());
name = reader.nextString();
} else if (nextName.equals("id")) {
result.id(reader.nextString());
id = reader.nextString();
} else if (nextName.equals("emailAddress")) {
result.email(reader.nextString());
} else if (nextName.equals("ttl")) {
result.ttl(reader.nextInt());
email = reader.nextString();
} else {
reader.skipValue();
}
}
return result.build();
return Zone.create(name, id, email);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ interface CloudDNS {
@RequestLine("GET /domains?name={name}")
ListWithNext<Zone> domainsByName(@Param("name") String name);

@RequestLine("GET")
ListWithNext<Zone> domains(URI href);

@RequestLine("GET /domains")
ListWithNext<Zone> domains();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import static denominator.assertj.ModelAssertions.assertThat;
import static denominator.clouddns.RackspaceApisTest.domainId;
import static junit.framework.Assert.assertFalse;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;

public class CloudDNSResourceRecordSetApiMockTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import denominator.model.Zone;

import static denominator.assertj.ModelAssertions.assertThat;
import static denominator.clouddns.RackspaceApisTest.domainResponse;
import static denominator.clouddns.RackspaceApisTest.domainsResponse;

public class CloudDNSZoneApiMockTest {
Expand All @@ -21,19 +20,15 @@ public class CloudDNSZoneApiMockTest {
public void iteratorWhenPresent() throws Exception {
server.enqueueAuthResponse();
server.enqueue(new MockResponse().setBody(domainsResponse));
server.enqueue(new MockResponse().setBody(domainResponse));

ZoneApi api = server.connect().api().zones();

assertThat(api.iterator()).containsExactly(
Zone.builder().name("denominator.io").id("1234").email("admin@denominator.io").ttl(3600)
.build()
Zone.create("denominator.io", "1234", "admin@denominator.io")
);

server.assertAuthRequest();
server.assertRequest().hasPath("/v1.0/123123/domains");
server.assertRequest()
.hasPath("/v1.0/123123/domains/1234?showRecords=false&showSubdomains=false");
}

@Test
Expand All @@ -52,19 +47,15 @@ public void iteratorWhenAbsent() throws Exception {
public void iteratorByNameWhenPresent() throws Exception {
server.enqueueAuthResponse();
server.enqueue(new MockResponse().setBody(domainsResponse));
server.enqueue(new MockResponse().setBody(domainResponse));

ZoneApi api = server.connect().api().zones();

assertThat(api.iterateByName("denominator.io")).containsExactly(
Zone.builder().name("denominator.io").id("1234").email("admin@denominator.io").ttl(3600)
.build()
Zone.create("denominator.io", "1234", "admin@denominator.io")
);

server.assertAuthRequest();
server.assertRequest().hasPath("/v1.0/123123/domains?name=denominator.io");
server.assertRequest()
.hasPath("/v1.0/123123/domains/1234?showRecords=false&showSubdomains=false");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ public void domainsByNamePresent() throws Exception {
server.enqueue(new MockResponse().setBody(domainsResponse));

assertThat(mockApi().domainsByName("denominator.io")).containsExactly(
Zone.builder().name("denominator.io").id("1234").email("admin@denominator.io").ttl(86400)
.build()
Zone.create("denominator.io", "1234", "admin@denominator.io")
);

server.assertAuthRequest();
Expand Down Expand Up @@ -280,9 +279,6 @@ public Credentials get() {
static String
domainsResponse =
"{\"domains\":[{\"name\":\"denominator.io\",\"id\":1234,\"accountId\":123123,\"emailAddress\":\"admin@denominator.io\",\"updated\":\"2013-09-02T19:46:56.000+0000\",\"created\":\"2013-09-02T19:45:51.000+0000\"}],\"totalEntries\":1}";
static String
domainResponse =
"{\"name\":\"denominator.io\",\"id\":1234,\"accountId\":123123,\"ttl\": 3600,\"emailAddress\":\"admin@denominator.io\"}";
// NOTE records are allowed to be out of order by type
static String
recordsResponse =
Expand Down
6 changes: 1 addition & 5 deletions core/src/main/java/denominator/mock/MockZoneApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@ public Zone next() {
checkState(soa.hasNext(), "SOA record for zone %s was not present", name);

SOAData soaData = (SOAData) soa.next().records().get(0);
return Zone.builder()
.name(name)
.id(name)
.ttl(soaData.minimum())
.email(soaData.rname()).build();
return Zone.create(name, name, soaData.rname());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public void testImplicitDynamicCredentialsUpdate() {
DNSApiManager mgr = create(new DynamicCredentialsProvider());
ZoneApi zones = mgr.api().zones();
assertThat(zones.iterator())
.containsExactly(Zone.builder().name("acme").email("coyote").build());
.containsExactly(Zone.create("acme", "wily", "coyote"));
assertThat(zones.iterator())
.containsExactly(Zone.builder().name("acme").email("runner").build());
.containsExactly(Zone.create("acme", "road", "runner"));

// now, if the supplier doesn't supply a set of credentials, we should
// get a correct message
Expand Down Expand Up @@ -118,7 +118,7 @@ public Iterator<Zone> iterator() {
CustomerUsernamePassword cup = creds.get();
// normally, the credentials object would be used to invoke a remote
// command. in this case, we don't and say we did :)
return asList(Zone.builder().name(cup.customer).email(cup.password).build()).iterator();
return asList(Zone.create(cup.customer, cup.username, cup.password)).iterator();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,20 @@ protected String jsonKey() {
}

protected Zone build(JsonReader reader) throws IOException {
Zone.Builder result = new Zone.Builder();
String name = null, id = null, email = null;
while (reader.hasNext()) {
String nextName = reader.nextName();
if (nextName.equals("name")) {
result.name(reader.nextString());
name = reader.nextString();
} else if (nextName.equals("id")) {
result.id(reader.nextString());
id = reader.nextString();
} else if (nextName.equals("email")) {
result.email(reader.nextString());
} else if (nextName.equals("ttl")) {
result.ttl(reader.nextInt());
email = reader.nextString();
} else {
reader.skipValue();
}
}
return result.build();
return Zone.create(name, id, email);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ public void domainsPresent() throws Exception {
server.enqueue(new MockResponse().setBody(domainsResponse));

assertThat(mockApi().domains()).containsExactly(
Zone.builder().name("denominator.io.").id(domainId).email("admin@denominator.io").ttl(3600)
.build()
Zone.create("denominator.io.", domainId, "admin@denominator.io")
);

server.assertAuthRequest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public void iteratorWhenPresent() throws Exception {
ZoneApi api = server.connect().api().zones();

assertThat(api.iterator()).containsExactly(
Zone.builder().name("denominator.io.").id(domainId).email("admin@denominator.io").ttl(3600)
.build()
Zone.create("denominator.io.", domainId, "admin@denominator.io")
);

server.assertAuthRequest();
Expand All @@ -53,8 +52,7 @@ public void iteratorByNameWhenPresent() throws Exception {
ZoneApi api = server.connect().api().zones();

assertThat(api.iterateByName("denominator.io.")).containsExactly(
Zone.builder().name("denominator.io.").id(domainId).email("admin@denominator.io").ttl(3600)
.build()
Zone.create("denominator.io.", domainId, "admin@denominator.io")
);

server.assertAuthRequest();
Expand Down
6 changes: 1 addition & 5 deletions dynect/src/main/java/denominator/dynect/DynECTZoneApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ private Zone fromSOA(String name) {
checkState(soa.hasNext(), "SOA record for zone %s was not present", name);

SOAData soaData = (SOAData) soa.next().records().get(0);
return Zone.builder()
.name(name)
.id(name)
.ttl(soaData.minimum())
.email(soaData.rname()).build();
return Zone.create(name, name, soaData.rname());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public void iteratorWhenPresent() throws Exception {
ZoneApi api = server.connect().api().zones();

assertThat(api.iterator()).containsExactly(
Zone.builder().name("denominator.io").id("denominator.io").email("fake@denominator.io.")
.ttl(1800).build()
Zone.create("denominator.io", "denominator.io","fake@denominator.io.")
);

server.assertSessionRequest();
Expand Down Expand Up @@ -59,8 +58,7 @@ public void iteratorByNameWhenPresent() throws Exception {
ZoneApi api = server.connect().api().zones();

assertThat(api.iterateByName("denominator.io.")).containsExactly(
Zone.builder().name("denominator.io.").id("denominator.io.").email("fake@denominator.io.")
.ttl(1800).build()
Zone.create("denominator.io.", "denominator.io.", "fake@denominator.io.")
);

server.assertSessionRequest();
Expand Down
Loading

0 comments on commit 31b1842

Please sign in to comment.