Initial commit
This commit is contained in:
commit
57148a56fa
15 changed files with 1418 additions and 0 deletions
67
checker/rule.go
Normal file
67
checker/rule.go
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
// This file is part of the happyDomain (R) project.
|
||||
// Copyright (c) 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 (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
sdk "git.happydns.org/checker-sdk-go/checker"
|
||||
)
|
||||
|
||||
// Rule returns the delegation check rule.
|
||||
func Rule() sdk.CheckRule {
|
||||
return &delegationRule{}
|
||||
}
|
||||
|
||||
type delegationRule struct{}
|
||||
|
||||
func (r *delegationRule) Name() string { return "delegation_check" }
|
||||
|
||||
func (r *delegationRule) Description() string {
|
||||
return "Verifies a DNS delegation against its parent zone and the delegated name servers"
|
||||
}
|
||||
|
||||
func (r *delegationRule) ValidateOptions(opts sdk.CheckerOptions) error {
|
||||
if v, ok := opts["minNameServers"]; ok {
|
||||
f, ok := v.(float64)
|
||||
if !ok {
|
||||
return fmt.Errorf("minNameServers must be a number")
|
||||
}
|
||||
if f < 1 {
|
||||
return fmt.Errorf("minNameServers must be >= 1")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *delegationRule) Evaluate(ctx context.Context, obs sdk.ObservationGetter, opts sdk.CheckerOptions) sdk.CheckState {
|
||||
var data DelegationData
|
||||
if err := obs.Get(ctx, ObservationKeyDelegation, &data); err != nil {
|
||||
return sdk.CheckState{
|
||||
Status: sdk.StatusError,
|
||||
Message: fmt.Sprintf("Failed to get delegation data: %v", err),
|
||||
Code: "delegation_error",
|
||||
}
|
||||
}
|
||||
return Evaluate(&data)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue