Skip to content

Commit

Permalink
tools/internal/parser: check TXT records (#2213)
Browse files Browse the repository at this point in the history
Supports checking a single PR, as well as re-verifying the entire PSL.
  • Loading branch information
danderson authored Oct 14, 2024
1 parent aeaf098 commit 3ea913a
Show file tree
Hide file tree
Showing 6 changed files with 1,220 additions and 8 deletions.
5 changes: 4 additions & 1 deletion tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ require (
github.com/natefinch/atomic v1.0.1
)

require github.com/google/go-querystring v1.1.0 // indirect
require (
github.com/creachadair/taskgroup v0.9.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
)
2 changes: 2 additions & 0 deletions tools/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ github.com/creachadair/flax v0.0.0-20240525192034-44db93b3a8ad h1:Fv6FRWgCJTHssl
github.com/creachadair/flax v0.0.0-20240525192034-44db93b3a8ad/go.mod h1:K8bFvn8hMdAljQkaKNc7I3os5Wk36JxkyCkfdZ7S8d4=
github.com/creachadair/mds v0.15.2 h1:es1qGKgRGSaztpvrSQcZ0B9I6NsHYJ1Sa9naD/3OfCM=
github.com/creachadair/mds v0.15.2/go.mod h1:4vrFYUzTXMJpMBU+OA292I6IUxKWCCfZkgXg+/kBZMo=
github.com/creachadair/taskgroup v0.9.0 h1:kzXSea5C7R5DtnKFBOTEW3hvmCkiVnRkODMVDMgSS6k=
github.com/creachadair/taskgroup v0.9.0/go.mod h1:+1hJc8zL1rQkxcMVqEYJ0UPGtwl6Iz1+fd4zcOLtt+A=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
Expand Down
51 changes: 51 additions & 0 deletions tools/internal/parser/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,54 @@ type ErrConflictingSuffixAndException struct {
func (e ErrConflictingSuffixAndException) Error() string {
return fmt.Sprintf("%s: suffix %s conflicts with exception in wildcard at %s", e.LocationString(), e.Domain, e.Wildcard.LocationString())
}

type ErrMissingTXTRecord struct {
Block
}

func (e ErrMissingTXTRecord) Error() string {
var name string
switch v := e.Block.(type) {
case *Suffix:
name = v.Domain.String()
case *Wildcard:
name = v.Domain.String()
default:
panic(fmt.Sprintf("unexpected block type %T in ErrInvalidTXTRecord", e.Block))
}
return fmt.Sprintf("%s: suffix %s has no TXT record", e.SrcRange().LocationString(), name)
}

type ErrTXTRecordMismatch struct {
Block
PR int
}

func (e ErrTXTRecordMismatch) Error() string {
switch v := e.Block.(type) {
case *Suffix:
return fmt.Sprintf("%s: suffix %s has a TXT record pointing to https://github.com/publicsuffix/list/pull/%d, but that PR does not change this suffix", e.SrcRange().LocationString(), v.Domain, e.PR)
case *Wildcard:
return fmt.Sprintf("%s: wildcard *.%s has a TXT record pointing to https://github.com/publicsuffix/list/pull/%d, but that PR does not change this wildcard", e.SrcRange().LocationString(), v.Domain, e.PR)
default:
panic(fmt.Sprintf("unexpected block type %T in ErrTXTRecordMismatch", e.Block))
}
}

type ErrTXTCheckFailure struct {
Block
Err error
}

func (e ErrTXTCheckFailure) Error() string {
var name string
switch v := e.Block.(type) {
case *Suffix:
name = v.Domain.String()
case *Wildcard:
name = v.Domain.String()
default:
panic(fmt.Sprintf("unexpected block type %T in ErrInvalidTXTRecord", e.Block))
}
return fmt.Sprintf("%s: error checking suffix %s: %v", e.SrcRange().LocationString(), name, e.Err)
}
Loading

0 comments on commit 3ea913a

Please sign in to comment.