Initial commit
This commit is contained in:
commit
957997a01c
16 changed files with 956 additions and 0 deletions
67
checker/abstract.go
Normal file
67
checker/abstract.go
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
// This file is part of the happyDomain (R) project.
|
||||
// Copyright (c) 2020-2026 happyDomain
|
||||
// Authors: Pierre-Olivier Mercier, et al.
|
||||
//
|
||||
// This program is offered under a commercial and under the AGPL license.
|
||||
// For commercial licensing, contact us at <contact@happydomain.org>.
|
||||
//
|
||||
// For AGPL licensing:
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package checker
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
// Service type identifiers as exposed by happyDomain core.
|
||||
const (
|
||||
serviceTypeOrigin = "abstract.Origin"
|
||||
serviceTypeNSOnlyOrigin = "abstract.NSOnlyOrigin"
|
||||
)
|
||||
|
||||
// originPayload is a minimal local copy of services/abstract.Origin keeping
|
||||
// only the field this checker reads. The JSON tag matches the upstream wire
|
||||
// format ("ns").
|
||||
type originPayload struct {
|
||||
NameServers []*dns.NS `json:"ns"`
|
||||
}
|
||||
|
||||
// nsOnlyOriginPayload is a minimal local copy of
|
||||
// services/abstract.NSOnlyOrigin keeping only the field this checker reads.
|
||||
type nsOnlyOriginPayload struct {
|
||||
NameServers []*dns.NS `json:"ns"`
|
||||
}
|
||||
|
||||
// nsFromService extracts the list of NS records from an Origin or
|
||||
// NSOnlyOrigin service payload.
|
||||
func nsFromService(svc *serviceMessage) []*dns.NS {
|
||||
switch svc.Type {
|
||||
case serviceTypeOrigin:
|
||||
var o originPayload
|
||||
if err := json.Unmarshal(svc.Service, &o); err != nil {
|
||||
return nil
|
||||
}
|
||||
return o.NameServers
|
||||
case serviceTypeNSOnlyOrigin:
|
||||
var o nsOnlyOriginPayload
|
||||
if err := json.Unmarshal(svc.Service, &o); err != nil {
|
||||
return nil
|
||||
}
|
||||
return o.NameServers
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue