|
|
@ -5,10 +5,12 @@ import ( |
|
|
|
"path/filepath" |
|
|
|
"path/filepath" |
|
|
|
|
|
|
|
|
|
|
|
"darvaza.org/resolver" |
|
|
|
"darvaza.org/resolver" |
|
|
|
|
|
|
|
"darvaza.org/slog" |
|
|
|
|
|
|
|
"darvaza.org/slog/handlers/discard" |
|
|
|
"github.com/hack-pad/hackpadfs/os" |
|
|
|
"github.com/hack-pad/hackpadfs/os" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// A ScanOption preconfigures the Zones before scanning
|
|
|
|
// A ScanOption pre-configures the Zones before scanning
|
|
|
|
type ScanOption func(*Zones, *ScanOptions) error |
|
|
|
type ScanOption func(*Zones, *ScanOptions) error |
|
|
|
|
|
|
|
|
|
|
|
// ScanOptions contains flags used by the initial scan
|
|
|
|
// ScanOptions contains flags used by the initial scan
|
|
|
@ -17,6 +19,10 @@ type ScanOptions struct { |
|
|
|
// pre-populate Machine.PublicAddresses during the
|
|
|
|
// pre-populate Machine.PublicAddresses during the
|
|
|
|
// initial scan
|
|
|
|
// initial scan
|
|
|
|
DontResolvePublicAddresses bool |
|
|
|
DontResolvePublicAddresses bool |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Logger specifies the logger to be used. otherwise
|
|
|
|
|
|
|
|
// the scanner will be mute
|
|
|
|
|
|
|
|
slog.Logger |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ResolvePublicAddresses instructs the scanner to use
|
|
|
|
// ResolvePublicAddresses instructs the scanner to use
|
|
|
@ -55,6 +61,18 @@ func WithResolver(h resolver.Resolver) ScanOption { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// WithLogger specifies what to use for logging
|
|
|
|
|
|
|
|
func WithLogger(log slog.Logger) ScanOption { |
|
|
|
|
|
|
|
return func(m *Zones, opt *ScanOptions) error { |
|
|
|
|
|
|
|
if log == nil { |
|
|
|
|
|
|
|
log = discard.New() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
opt.Logger = log |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (m *Zones) setDefaults(opt *ScanOptions) error { |
|
|
|
func (m *Zones) setDefaults(opt *ScanOptions) error { |
|
|
|
if m.resolver == nil { |
|
|
|
if m.resolver == nil { |
|
|
|
h := resolver.NewCloudflareLookuper() |
|
|
|
h := resolver.NewCloudflareLookuper() |
|
|
@ -64,6 +82,12 @@ func (m *Zones) setDefaults(opt *ScanOptions) error { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if opt.Logger == nil { |
|
|
|
|
|
|
|
if err := WithLogger(nil)(m, opt); err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|