use of org.nhindirect.dns.tools.utils.Command in project nhin-d by DirectProject.
the class DNSRecordCommands method ensureSOA.
/**
* Adds an SOA records to the configuration service only if the record does not exist.
* @param args Contains the SOA record attributes.
*
* @since 1.0
*/
@Command(name = "Dns_SOA_Ensure", usage = ENSURE_SOA_USAGE)
public void ensureSOA(String[] args) {
DnsRecord record = fromRecord(parser.parseSOA(args));
if (!verifyIsUnique(record, false)) {
return;
}
addDNS(record);
}
use of org.nhindirect.dns.tools.utils.Command in project nhin-d by DirectProject.
the class DNSRecordCommands method match.
/**
* Looks up all records for a given domain and any sub domains.
* @param args The first entry in the array contains the domain name (required).
*
* @since 1.0
*/
@Command(name = "Dns_Match", usage = "Resolve all records for the given domain")
public void match(String[] args) {
String domain = StringArrayUtil.getRequiredValue(args, 0);
DnsRecord[] records = null;
Pattern pattern = Pattern.compile(domain);
ArrayList<DnsRecord> matchedRecords = new ArrayList<DnsRecord>();
try {
records = proxy.getDNSByType(Type.ANY);
} catch (Exception e) {
throw new RuntimeException("Error accessing configuration service: " + e.getMessage(), e);
}
if (records == null || records.length == 0) {
System.out.println("No records found");
return;
} else {
for (DnsRecord record : records) {
Matcher matcher = pattern.matcher(record.getName());
if (matcher.find()) {
matchedRecords.add(record);
}
}
}
if (matchedRecords.size() == 0) {
System.out.println("No records found");
return;
}
print(matchedRecords.toArray(new DnsRecord[matchedRecords.size()]));
}
use of org.nhindirect.dns.tools.utils.Command in project nhin-d by DirectProject.
the class DomainCommands method addDomain.
@Command(name = "AddDomain", usage = ADD_DOMAIN_USAGE)
public void addDomain(String[] args) {
final String domainName = StringArrayUtil.getRequiredValue(args, 0);
final String postmasterEmail = StringArrayUtil.getRequiredValue(args, 1);
try {
// make sure this domain name doesn't already exist
final Domain[] exDomain = proxy.listDomains(domainName, 1);
if (exDomain != null && exDomain.length > 0) {
System.out.println("The domain " + domainName + " already exists in the system");
return;
}
final Domain newDomain = new Domain();
newDomain.setDomainName(domainName);
newDomain.setPostMasterEmail(postmasterEmail);
newDomain.setStatus(EntityStatus.ENABLED);
proxy.addDomain(newDomain);
System.out.println("Domain " + domainName + " successfully added.");
} catch (Exception e) {
e.printStackTrace();
System.err.println("Failed to add new domain: " + e.getMessage());
}
}
use of org.nhindirect.dns.tools.utils.Command in project nhin-d by DirectProject.
the class PolicyCommands method listDomainPolicyGroups.
@Command(name = "ListDomainPolicyGroups", usage = LIST_DOMAIN_POLICY_GROUPS)
public void listDomainPolicyGroups(String[] args) {
final String domainName = StringArrayUtil.getRequiredValue(args, 0);
// make sure the domain exists
Domain[] domains;
try {
domains = proxy.getDomains(new String[] { domainName }, null);
if (domains == null || domains.length == 0) {
System.out.println("No domain with name " + domainName + " found");
return;
}
} catch (Exception e) {
System.out.println("Failed to lookup domain: " + e.getMessage());
return;
}
try {
final CertPolicyGroupDomainReltn[] reltns = proxy.getPolicyGroupsByDomain(domains[0].getId());
if (reltns == null || reltns.length == 0) {
System.out.println("Domain does not have any policy groups associated with it.");
return;
}
List<org.nhind.config.CertPolicyGroup> groups = new ArrayList<org.nhind.config.CertPolicyGroup>();
for (CertPolicyGroupDomainReltn reltn : reltns) groups.add(reltn.getCertPolicyGroup());
groupPrinter.printRecords(groups);
} catch (Exception e) {
System.out.println("Failed to lookup domain policy groups: " + e.getMessage());
return;
}
}
use of org.nhindirect.dns.tools.utils.Command in project nhin-d by DirectProject.
the class PolicyCommands method deletePolicyGroupFromDomain.
@Command(name = "DeletePolicyGroupFromDomain", usage = DELETE_GROUP_FROM_DOMAIN_USAGE)
public void deletePolicyGroupFromDomain(String[] args) {
// make sure the group exists
final String groupName = StringArrayUtil.getRequiredValue(args, 0);
final String domainName = StringArrayUtil.getRequiredValue(args, 1);
long policyGroupId = -1;
// make sure the domain exists
Domain[] domains;
try {
domains = proxy.getDomains(new String[] { domainName }, null);
if (domains == null || domains.length == 0) {
System.out.println("No domain with name " + domainName + " found");
return;
}
// make sure it's really associated
final CertPolicyGroupDomainReltn[] reltns = proxy.getPolicyGroupsByDomain(domains[0].getId());
if (reltns == null || reltns.length == 0) {
System.out.println("Policy group is not associated with domain.");
return;
} else {
for (org.nhind.config.CertPolicyGroupDomainReltn reltn : reltns) {
if (reltn.getCertPolicyGroup().getPolicyGroupName().compareToIgnoreCase(groupName) == 0) {
policyGroupId = reltn.getCertPolicyGroup().getId();
break;
}
}
if (policyGroupId == -1) {
System.out.println("Policy group is not associated with domain.");
return;
}
}
} catch (Exception e) {
System.out.println("Failed to lookup domain: " + e.getMessage());
return;
}
try {
proxy.disassociatePolicyGroupFromDomain(domains[0].getId(), policyGroupId);
System.out.println("Successfully delete policy group from domain.");
} catch (Exception e) {
System.out.println("Failed to delete policy group from domain: " + e.getMessage());
return;
}
}
Aggregations