Skip to content

Commit

Permalink
fix: refresh WHOIS for new domains
Browse files Browse the repository at this point in the history
  • Loading branch information
nwesterhausen committed Apr 9, 2024
1 parent 8489933 commit bc3df7a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
4 changes: 3 additions & 1 deletion configuration/whois-cache.configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@ func (w *WhoisCacheStorage) Add(fqdn string) {
LastUpdated: time.Time{},
}

// Perform the whois query
// Perform the whois query for the new domain
newEntry.Refresh()

// Add the entry to the list
w.FileContents.Entries = append(w.FileContents.Entries, newEntry)
// Flush the cache to disk
w.Flush()
}

func (w *WhoisCacheStorage) Refresh() {
Expand Down
8 changes: 4 additions & 4 deletions service/domain.service.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (s *ServicesDomain) CreateDomain(domain configuration.Domain) (int, error)
}
}
// This should never happen.. but just in case return -1 and an error
return -1, errors.New("Failed to add domain")
return -1, errors.New("failed to add domain")
}

func (s *ServicesDomain) GetDomain(fqdn string) (configuration.Domain, error) {
Expand All @@ -33,7 +33,7 @@ func (s *ServicesDomain) GetDomain(fqdn string) (configuration.Domain, error) {
return d, nil
}
}
return configuration.Domain{}, errors.New("Domain not found")
return configuration.Domain{}, errors.New("domain not found")
}

func (s *ServicesDomain) GetDomains() ([]configuration.Domain, error) {
Expand All @@ -52,7 +52,7 @@ func (s *ServicesDomain) UpdateDomain(domain configuration.Domain) error {
}
}
// This should never happen.. but just in case return an error
return errors.New("Failed to update domain")
return errors.New("failed to update domain")
}

func (s *ServicesDomain) DeleteDomain(fqdn string) error {
Expand All @@ -65,7 +65,7 @@ func (s *ServicesDomain) DeleteDomain(fqdn string) error {
// Return nil to indicate success (we can confirm the domain was deleted by checking the list)
for _, d := range s.store.DomainFile.Domains {
if d.FQDN == fqdn {
return errors.New("Failed to delete domain")
return errors.New("failed to delete domain")
}
}
return nil
Expand Down
11 changes: 10 additions & 1 deletion service/whois.service.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@ func (s *ServicesWhois) GetWhois(fqdn string) (configuration.WhoisCache, error)
}
log.Println("🙅 WHOIS entry cache miss for", fqdn)

return configuration.WhoisCache{}, errors.New("WHOIS entry not found")
// Since we cache missed, let's try to fetch the WHOIS entry instead
s.store.Add(fqdn)
// Try to get the entry again
for _, entry := range s.store.FileContents.Entries {
if entry.FQDN == fqdn {
return entry, nil
}
}

return configuration.WhoisCache{}, errors.New("entry missing")
}

func (s *ServicesWhois) MarkAlertSent(fqdn string, alert configuration.Alert) bool {
Expand Down

0 comments on commit bc3df7a

Please sign in to comment.