-
Notifications
You must be signed in to change notification settings - Fork 0
/
DynamicValue.js
68 lines (58 loc) · 1.55 KB
/
DynamicValue.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const API = require("./NSLookupIO/API.js")
class GetDNSRecord {
static identifier = "com.astzweig.GetDNSRecord"
static title = "Get DNS record"
static inputs = [
InputField("domain", "Domain to lookup", "String"),
InputField("recordType", "DNS record type to lookup", "Select", {
"choices": {
"a": "A",
"aaaa": "AAAA",
"cname": "CNAME",
"txt": "TXT",
"ns": "NS",
"mx": "MX",
"soa": "SOA"
}
})
]
title(context) {
return `Get value of DNS record of ${this.domain}`;
}
text(context) {
return this.value;
}
evaluate(context) {
try {
this.#validateInputValues()
} catch(errorMessage) {
return errorMessage
}
try {
let records = this.#getDNSRecordsFromAPI()
this.value = records.getValueForRecordType(this.recordType)
} catch(errorMessage) {
console.error(errorMessage)
return `Could not get IP address of ${this.domain}`
}
return this.value;
}
#validateInputValues() {
this.#checkDomain()
this.#checkRecordType()
}
#checkDomain() {
const parts = this.domain.split('.')
if (parts.length < 2) throw `${this.domain} has no top level domain`
if (parts[1].length < 2) throw `Top level domain of ${this.domain} is too short`
}
#checkRecordType() {
if (!this.recordType) throw `Please select a record type to retrieve for ${this.domain}`
}
#getDNSRecordsFromAPI() {
let api = new API(this.domain)
api.sendRequest()
return api
}
}
module.exports = GetDNSRecord