-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetcher_options.go
More file actions
78 lines (68 loc) · 1.68 KB
/
fetcher_options.go
File metadata and controls
78 lines (68 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// SPDX-FileCopyrightText: 2025 Comcast Cable Communications Management, LLC
// SPDX-License-Identifier: Apache-2.0
package dnstxtjwt
import (
"fmt"
"net"
"time"
"github.com/lestrrat-go/jwx/v2/jwt"
)
type fetcherOptionFunc func(*Fetcher) error
func (f fetcherOptionFunc) apply(r *Fetcher) error {
return f(r)
}
// WithResolver sets the resolver to use for DNS queries. If the resolver
// is nil or this option is unset, the net.DefaultResolver is used.
func WithResolver(resolver Resolver) FetcherOption {
return fetcherOptionFunc(
func(r *Fetcher) error {
if resolver == nil {
resolver = net.DefaultResolver
}
r.resolver = resolver
return nil
},
)
}
// WithFQDN sets the FQDN to use for DNS queries.
func WithFQDN(fqdn string) FetcherOption {
return fetcherOptionFunc(
func(r *Fetcher) error {
r.fqdn = fqdn
return nil
},
)
}
// WithTimeout sets the timeout for DNS queries. Any timeout less than zero
// disable the timeout and wait indefinitely. The value of 0 sets the default.
// The default timeout is 30s.
func WithTimeout(timeout time.Duration) FetcherOption {
return fetcherOptionFunc(
func(r *Fetcher) error {
if timeout == 0 {
timeout = 30 * time.Second
}
r.timeout = timeout
return nil
},
)
}
// WithParseOptions sets the options to use for JWT parsing.
func WithParseOptions(opts ...jwt.ParseOption) FetcherOption {
return fetcherOptionFunc(
func(r *Fetcher) error {
r.opts = append(r.opts, opts...)
return nil
},
)
}
func validateOptions() FetcherOption {
return fetcherOptionFunc(
func(r *Fetcher) error {
if r.fqdn == "" {
return fmt.Errorf("%w fqdn must be set", ErrInvalidInput)
}
return nil
},
)
}