Make the CLI configurable #1

Closed
mokhtar wants to merge 11 commits from proper-config into master
2 changed files with 25 additions and 25 deletions
Showing only changes of commit 8ee3d3ce75 - Show all commits

View File

@ -15,7 +15,7 @@ type hardcodedRecord struct {
SRV *dns.SRV
}
var records = map[string]hardcodedRecord{
var hardcodedRecords = map[string]hardcodedRecord{
// additional records I set up to host emails, feel free to change or remove them for your own needs
"local-ip.sh.": {
TXT: []string{"v=spf1 include:capsulecorp.dev ~all"},

View File

@ -31,9 +31,9 @@ func (xip *Xip) SetTXTRecord(fqdn string, value string) {
return
}
if rootRecords, ok := records[fqdn]; ok {
if rootRecords, ok := hardcodedRecords[fqdn]; ok {
rootRecords.TXT = []string{value}
records[fmt.Sprintf("_acme-challenge.%s.", config.Domain)] = rootRecords
hardcodedRecords[fmt.Sprintf("_acme-challenge.%s.", config.Domain)] = rootRecords
}
}
@ -45,18 +45,18 @@ func (xip *Xip) UnsetTXTRecord(fqdn string) {
return
}
if rootRecords, ok := records[fqdn]; ok {
if rootRecords, ok := hardcodedRecords[fqdn]; ok {
rootRecords.TXT = []string{}
records[fmt.Sprintf("_acme-challenge.%s.", config.Domain)] = rootRecords
hardcodedRecords[fmt.Sprintf("_acme-challenge.%s.", config.Domain)] = rootRecords
}
}
func (xip *Xip) fqdnToA(fqdn string) []*dns.A {
normalizedFqdn := strings.ToLower(fqdn)
if records[normalizedFqdn].A != nil {
if hardcodedRecords[normalizedFqdn].A != nil {
var aRecords []*dns.A
for _, record := range records[normalizedFqdn].A {
for _, record := range hardcodedRecords[normalizedFqdn].A {
aRecords = append(aRecords, &dns.A{
Hdr: dns.RR_Header{
Ttl: uint32((time.Minute * 5).Seconds()),
@ -117,12 +117,12 @@ func (xip *Xip) handleA(question dns.Question, message *dns.Msg) {
func (xip *Xip) handleAAAA(question dns.Question, message *dns.Msg) {
fqdn := question.Name
normalizedFqdn := strings.ToLower(fqdn)
if records[normalizedFqdn].AAAA == nil {
if hardcodedRecords[normalizedFqdn].AAAA == nil {
xip.answerWithAuthority(question, message)
return
}
for _, record := range records[normalizedFqdn].AAAA {
for _, record := range hardcodedRecords[normalizedFqdn].AAAA {
message.Answer = append(message.Answer, &dns.AAAA{
Hdr: dns.RR_Header{
Ttl: uint32((time.Minute * 5).Seconds()),
@ -172,12 +172,12 @@ func chunkBy(str string, chunkSize int) (chunks []string) {
func (xip *Xip) handleTXT(question dns.Question, message *dns.Msg) {
fqdn := question.Name
normalizedFqdn := strings.ToLower(fqdn)
if records[normalizedFqdn].TXT == nil {
if hardcodedRecords[normalizedFqdn].TXT == nil {
xip.answerWithAuthority(question, message)
return
}
for _, record := range records[normalizedFqdn].TXT {
for _, record := range hardcodedRecords[normalizedFqdn].TXT {
message.Answer = append(message.Answer, &dns.TXT{
Hdr: dns.RR_Header{
Ttl: uint32((time.Minute * 5).Seconds()),
@ -193,12 +193,12 @@ func (xip *Xip) handleTXT(question dns.Question, message *dns.Msg) {
func (xip *Xip) handleMX(question dns.Question, message *dns.Msg) {
fqdn := question.Name
normalizedFqdn := strings.ToLower(fqdn)
if records[normalizedFqdn].MX == nil {
if hardcodedRecords[normalizedFqdn].MX == nil {
xip.answerWithAuthority(question, message)
return
}
for _, record := range records[normalizedFqdn].MX {
for _, record := range hardcodedRecords[normalizedFqdn].MX {
message.Answer = append(message.Answer, &dns.MX{
Hdr: dns.RR_Header{
Ttl: uint32((time.Minute * 5).Seconds()),
@ -215,12 +215,12 @@ func (xip *Xip) handleMX(question dns.Question, message *dns.Msg) {
func (xip *Xip) handleCNAME(question dns.Question, message *dns.Msg) {
fqdn := question.Name
normalizedFqdn := strings.ToLower(fqdn)
if records[normalizedFqdn].CNAME == nil {
if hardcodedRecords[normalizedFqdn].CNAME == nil {
xip.answerWithAuthority(question, message)
return
}
for _, record := range records[normalizedFqdn].CNAME {
for _, record := range hardcodedRecords[normalizedFqdn].CNAME {
message.Answer = append(message.Answer, &dns.CNAME{
Hdr: dns.RR_Header{
Ttl: uint32((time.Minute * 5).Seconds()),
@ -236,7 +236,7 @@ func (xip *Xip) handleCNAME(question dns.Question, message *dns.Msg) {
func (xip *Xip) handleSRV(question dns.Question, message *dns.Msg) {
fqdn := question.Name
normalizedFqdn := strings.ToLower(fqdn)
if records[normalizedFqdn].SRV == nil {
if hardcodedRecords[normalizedFqdn].SRV == nil {
xip.answerWithAuthority(question, message)
return
}
@ -248,10 +248,10 @@ func (xip *Xip) handleSRV(question dns.Question, message *dns.Msg) {
Rrtype: dns.TypeSRV,
Class: dns.ClassINET,
},
Priority: records[normalizedFqdn].SRV.Priority,
Weight: records[normalizedFqdn].SRV.Weight,
Port: records[normalizedFqdn].SRV.Port,
Target: records[normalizedFqdn].SRV.Target,
Priority: hardcodedRecords[normalizedFqdn].SRV.Priority,
Weight: hardcodedRecords[normalizedFqdn].SRV.Weight,
Port: hardcodedRecords[normalizedFqdn].SRV.Port,
Target: hardcodedRecords[normalizedFqdn].SRV.Target,
})
}
@ -373,17 +373,17 @@ func (xip *Xip) initHardcodedRecords() {
ip := net.ParseIP(ns)
rootDomainARecords = append(rootDomainARecords, ip)
entry := records[name]
entry.A = append(records[name].A, ip)
records[name] = entry
entry := hardcodedRecords[name]
entry.A = append(hardcodedRecords[name].A, ip)
hardcodedRecords[name] = entry
xip.nameServers = append(xip.nameServers, name)
}
records[fmt.Sprintf("%s.", config.Domain)] = hardcodedRecord{A: rootDomainARecords}
hardcodedRecords[fmt.Sprintf("%s.", config.Domain)] = hardcodedRecord{A: rootDomainARecords}
// will be filled in later when requesting the wildcard certificate
records[fmt.Sprintf("_acme-challenge.%s.", config.Domain)] = hardcodedRecord{TXT: []string{}}
hardcodedRecords[fmt.Sprintf("_acme-challenge.%s.", config.Domain)] = hardcodedRecord{TXT: []string{}}
}
func NewXip() (xip *Xip) {