/** * Constructs a new ResourceRecord object. Callers should use the setter or fluent setter (with...) methods to * initialize any additional object members. * * @param value * The current or new DNS record value, not to exceed 4,000 characters. In the case of a <code>DELETE</code> * action, if the current value does not match the actual value, an error is returned. For descriptions about * how to format <code>Value</code> for different record types, see <a * href="http://docs.aws.amazon.com/Route53/latest/DeveloperGuide/ResourceRecordTypes.html">Supported DNS * Resource Record Types</a> in the <i>Amazon Route 53 Developer Guide</i>.</p> * <p> * You can specify more than one value for all record types except <code>CNAME</code> and <code>SOA</code>. * </p> * <note> * <p> * If you're creating an alias resource record set, omit <code>Value</code>. * </p> */ public ResourceRecord(String value) { setValue(value); }
public ResourceRecord unmarshall(StaxUnmarshallerContext context) throws Exception { ResourceRecord resourceRecord = new ResourceRecord(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 1; while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) return resourceRecord; if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("Value", targetDepth)) { resourceRecord.setValue(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return resourceRecord; } } } }
private boolean createResourceRecordSet(ResourceRecordSetWithHostedZone rrs) throws InterruptedException { rrs.getResourceRecordSet().setResourceRecords(Arrays.asList(new ResourceRecord(registrationHostname))); Change change = new Change(ChangeAction.UPSERT, rrs.getResourceRecordSet()); if (executeChangeWithRetry(change, rrs.getHostedZone())) { Thread.sleep(1000); // check change not overwritten ResourceRecordSet resourceRecordSet = getResourceRecordSet(rrs.getResourceRecordSet().getName(), rrs.getHostedZone()); return resourceRecordSet.getResourceRecords().equals(rrs.getResourceRecordSet().getResourceRecords()); } return false; }
if(target.equals(record.getValue())) .withType(RRType.CNAME) .withTTL(300L) .withResourceRecords(new ResourceRecord() .withValue(target)
private boolean createResourceRecordSet(ResourceRecordSetWithHostedZone rrs) throws InterruptedException { rrs.getResourceRecordSet().setResourceRecords(Arrays.asList(new ResourceRecord(registrationHostname))); Change change = new Change(ChangeAction.UPSERT, rrs.getResourceRecordSet()); if (executeChangeWithRetry(change, rrs.getHostedZone())) { Thread.sleep(1000); // check change not overwritten ResourceRecordSet resourceRecordSet = getResourceRecordSet(rrs.getResourceRecordSet().getName(), rrs.getHostedZone()); return resourceRecordSet.getResourceRecords().equals(rrs.getResourceRecordSet().getResourceRecords()); } return false; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof ResourceRecord == false) return false; ResourceRecord other = (ResourceRecord) obj; if (other.getValue() == null ^ this.getValue() == null) return false; if (other.getValue() != null && other.getValue().equals(this.getValue()) == false) return false; return true; }
@TaskAction public void changeResourceRecordSets() { // to enable conventionMappings feature String hostedZoneId = getHostedZoneId(); String rrsName = getRrsName(); String resourceRecord = getResourceRecord(); AmazonRoute53PluginExtension ext = getProject().getExtensions().getByType(AmazonRoute53PluginExtension.class); AmazonRoute53 route53 = ext.getClient(); route53.changeResourceRecordSets(new ChangeResourceRecordSetsRequest() .withHostedZoneId(hostedZoneId) .withChangeBatch(new ChangeBatch() .withChanges(new Change(ChangeAction.CREATE, new ResourceRecordSet(rrsName, RRType.CNAME) .withResourceRecords(new ResourceRecord(resourceRecord)))))); getLogger().info("change {} requested", hostedZoneId); } }
setValue(value); return this;
/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. * * @return A string representation of this object. * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getValue() != null) sb.append("Value: ").append(getValue()); sb.append("}"); return sb.toString(); }
ResourceRecord resourceRecord = new ResourceRecord(address);
private void unbindFromDomain(String domain) throws InterruptedException { ResourceRecordSetWithHostedZone resourceRecordSetWithHostedZone = getResourceRecordSetWithHostedZone(domain); if (hasValue(resourceRecordSetWithHostedZone, registrationHostname)) { resourceRecordSetWithHostedZone.getResourceRecordSet().getResourceRecords().get(0).setValue(NULL_DOMAIN); executeChangeWithRetry(new Change(ChangeAction.UPSERT, resourceRecordSetWithHostedZone.getResourceRecordSet()), resourceRecordSetWithHostedZone.getHostedZone()); } }
private boolean hasValue(ResourceRecordSetWithHostedZone resourceRecordSetWithHostedZone, String ip) { if (resourceRecordSetWithHostedZone != null && resourceRecordSetWithHostedZone.getResourceRecordSet() != null) { for (ResourceRecord rr : resourceRecordSetWithHostedZone.getResourceRecordSet().getResourceRecords()) { if (ip.equals(rr.getValue())) { return true; } } } return false; }
private void unbindFromDomain(String domain) throws InterruptedException { ResourceRecordSetWithHostedZone resourceRecordSetWithHostedZone = getResourceRecordSetWithHostedZone(domain); if (hasValue(resourceRecordSetWithHostedZone, registrationHostname)) { resourceRecordSetWithHostedZone.getResourceRecordSet().getResourceRecords().get(0).setValue(NULL_DOMAIN); executeChangeWithRetry(new Change(ChangeAction.UPSERT, resourceRecordSetWithHostedZone.getResourceRecordSet()), resourceRecordSetWithHostedZone.getHostedZone()); } }
private void doBind() throws InterruptedException { List<ResourceRecordSetWithHostedZone> freeDomains = new ArrayList<>(); List<String> domains = getDeclaredDomains(); for(String domain : domains) { ResourceRecordSetWithHostedZone rrs = getResourceRecordSetWithHostedZone(domain); if (rrs != null) { if (rrs.getResourceRecordSet() == null) { ResourceRecordSet resourceRecordSet = new ResourceRecordSet(); resourceRecordSet.setName(domain); resourceRecordSet.setType(RRType.CNAME); resourceRecordSet.setTTL(serverConfig.getRoute53DomainTTL()); freeDomains.add(new ResourceRecordSetWithHostedZone(rrs.getHostedZone(), resourceRecordSet)); } else if (NULL_DOMAIN.equals(rrs.getResourceRecordSet().getResourceRecords().get(0).getValue())) { freeDomains.add(rrs); } // already registered if (hasValue(rrs, registrationHostname)) { return; } } } for(ResourceRecordSetWithHostedZone rrs : freeDomains) { if (createResourceRecordSet(rrs)) { logger.info("Bind {} to {}" , registrationHostname, rrs.getResourceRecordSet().getName()); return; } } logger.warn("Unable to find free domain in {}", domains); }
private boolean hasValue(ResourceRecordSetWithHostedZone resourceRecordSetWithHostedZone, String ip) { if (resourceRecordSetWithHostedZone != null && resourceRecordSetWithHostedZone.getResourceRecordSet() != null) { for (ResourceRecord rr : resourceRecordSetWithHostedZone.getResourceRecordSet().getResourceRecords()) { if (ip.equals(rr.getValue())) { return true; } } } return false; }
ObjectNode toJson(ResourceRecordSet rs) { ObjectNode n = mapper.createObjectNode(); n.put("aws_ttl", rs.getTTL()); n.put("aws_type", rs.getType()); n.put("aws_name", rs.getName()); n.put("id", rs.getType() + "_" + rs.getName()); ArrayNode an = mapper.createArrayNode(); n.set("aws_resourceRecords", an); for (ResourceRecord rr : rs.getResourceRecords()) { an.add(rr.getValue()); } return n; }
private void doBind() throws InterruptedException { List<ResourceRecordSetWithHostedZone> freeDomains = new ArrayList<>(); List<String> domains = getDeclaredDomains(); for(String domain : domains) { ResourceRecordSetWithHostedZone rrs = getResourceRecordSetWithHostedZone(domain); if (rrs != null) { if (rrs.getResourceRecordSet() == null) { ResourceRecordSet resourceRecordSet = new ResourceRecordSet(); resourceRecordSet.setName(domain); resourceRecordSet.setType(RRType.CNAME); resourceRecordSet.setTTL(serverConfig.getRoute53DomainTTL()); freeDomains.add(new ResourceRecordSetWithHostedZone(rrs.getHostedZone(), resourceRecordSet)); } else if (NULL_DOMAIN.equals(rrs.getResourceRecordSet().getResourceRecords().get(0).getValue())) { freeDomains.add(rrs); } // already registered if (hasValue(rrs, registrationHostname)) { return; } } } for(ResourceRecordSetWithHostedZone rrs : freeDomains) { if (createResourceRecordSet(rrs)) { logger.info("Bind {} to {}" , registrationHostname, rrs.getResourceRecordSet().getName()); return; } } logger.warn("Unable to find free domain in {}", domains); }