1 | |
package org.kuali.maven.plugins.dnsme.mojo; |
2 | |
|
3 | |
import org.apache.maven.plugin.MojoExecutionException; |
4 | |
import org.apache.maven.plugin.MojoFailureException; |
5 | |
import org.kuali.maven.plugins.dnsme.DNSMEClient; |
6 | |
import org.kuali.maven.plugins.dnsme.beans.Domain; |
7 | |
import org.kuali.maven.plugins.dnsme.beans.Record; |
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | 0 | public class DeleteRecordMojo extends BaseDNSMEMojo { |
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
String domainName; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
String recordName; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
Integer recordId; |
38 | |
|
39 | |
@Override |
40 | |
public void performTasks(DNSMEClient client) throws MojoExecutionException, MojoFailureException { |
41 | 0 | Domain domain = client.getDomain(domainName); |
42 | 0 | Record record = getRecord(client, domain); |
43 | 0 | getLog().info("Deleting a record from '" + domainName + "'"); |
44 | 0 | getLog().info("[" + getLog(record) + "]"); |
45 | 0 | client.deleteRecord(domain, record.getId()); |
46 | 0 | } |
47 | |
|
48 | |
protected Record getRecord(DNSMEClient client, Domain domain) throws MojoExecutionException { |
49 | 0 | if (recordId != null) { |
50 | 0 | client.getRecord(domain, recordId); |
51 | |
} |
52 | 0 | if (recordName != null) { |
53 | 0 | return client.getRecord(domain, recordName); |
54 | |
} |
55 | 0 | throw new MojoExecutionException("Must supply a value for either recordName or recordId"); |
56 | |
} |
57 | |
|
58 | |
protected String getCompactLog(Record record) { |
59 | 0 | StringBuilder sb = new StringBuilder(); |
60 | 0 | sb.append(record.getName()); |
61 | 0 | sb.append("->" + record.getData()); |
62 | 0 | sb.append("," + record.getType()); |
63 | 0 | sb.append(",ttl=" + record.getTtl() + "s"); |
64 | 0 | return sb.toString(); |
65 | |
} |
66 | |
|
67 | |
protected String getLog(Record record) { |
68 | 0 | StringBuilder sb = new StringBuilder(); |
69 | 0 | sb.append(record.getId()); |
70 | 0 | sb.append("," + record.getName()); |
71 | 0 | sb.append("->" + record.getData()); |
72 | 0 | sb.append("," + record.getType()); |
73 | 0 | sb.append(",ttl=" + record.getTtl() + "s"); |
74 | 0 | sb.append(",gtd=" + record.getGtdLocation()); |
75 | 0 | return sb.toString(); |
76 | |
} |
77 | |
|
78 | |
} |