mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 11:55:40 +01:00
Rename opts to cfg
This commit is contained in:
parent
0d17db0c59
commit
12ad7706e3
4 changed files with 62 additions and 64 deletions
|
|
@ -40,7 +40,7 @@ import (
|
|||
type topicMessages []Message
|
||||
|
||||
type processor struct {
|
||||
opts *options
|
||||
cfg *config
|
||||
validator csaf.RemoteValidator
|
||||
client util.Client
|
||||
unauthClient util.Client
|
||||
|
|
@ -165,17 +165,16 @@ func (m *topicMessages) hasErrors() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// newProcessor returns a processor structure after assigning the given options to the opts attribute
|
||||
// and initializing the "alreadyChecked" and "expr" fields.
|
||||
func newProcessor(opts *options) (*processor, error) {
|
||||
// newProcessor returns an initilaized processor.
|
||||
func newProcessor(cfg *config) (*processor, error) {
|
||||
|
||||
var validator csaf.RemoteValidator
|
||||
|
||||
if opts.RemoteValidator != "" {
|
||||
if cfg.RemoteValidator != "" {
|
||||
validatorOptions := csaf.RemoteValidatorOptions{
|
||||
URL: opts.RemoteValidator,
|
||||
Presets: opts.RemoteValidatorPresets,
|
||||
Cache: opts.RemoteValidatorCache,
|
||||
URL: cfg.RemoteValidator,
|
||||
Presets: cfg.RemoteValidatorPresets,
|
||||
Cache: cfg.RemoteValidatorCache,
|
||||
}
|
||||
var err error
|
||||
if validator, err = validatorOptions.Open(); err != nil {
|
||||
|
|
@ -185,10 +184,10 @@ func newProcessor(opts *options) (*processor, error) {
|
|||
}
|
||||
|
||||
return &processor{
|
||||
opts: opts,
|
||||
cfg: cfg,
|
||||
alreadyChecked: map[string]whereType{},
|
||||
expr: util.NewPathEval(),
|
||||
ageAccept: ageAccept(opts),
|
||||
ageAccept: ageAccept(cfg),
|
||||
validator: validator,
|
||||
labelChecker: labelChecker{
|
||||
advisories: map[csaf.TLPLabel]util.Set[string]{},
|
||||
|
|
@ -205,11 +204,11 @@ func (p *processor) close() {
|
|||
}
|
||||
}
|
||||
|
||||
func ageAccept(opts *options) func(time.Time) bool {
|
||||
if opts.Years == nil {
|
||||
func ageAccept(cfg *config) func(time.Time) bool {
|
||||
if cfg.Years == nil {
|
||||
return nil
|
||||
}
|
||||
good := time.Now().AddDate(-int(*opts.Years), 0, 0)
|
||||
good := time.Now().AddDate(-int(*cfg.Years), 0, 0)
|
||||
return func(t time.Time) bool {
|
||||
return !t.Before(good)
|
||||
}
|
||||
|
|
@ -431,12 +430,12 @@ func (p *processor) fullClient() util.Client {
|
|||
hClient.CheckRedirect = p.checkRedirect
|
||||
|
||||
var tlsConfig tls.Config
|
||||
if p.opts.Insecure {
|
||||
if p.cfg.Insecure {
|
||||
tlsConfig.InsecureSkipVerify = true
|
||||
}
|
||||
|
||||
if len(p.opts.clientCerts) != 0 {
|
||||
tlsConfig.Certificates = p.opts.clientCerts
|
||||
if len(p.cfg.clientCerts) != 0 {
|
||||
tlsConfig.Certificates = p.cfg.clientCerts
|
||||
}
|
||||
|
||||
hClient.Transport = &http.Transport{
|
||||
|
|
@ -446,23 +445,23 @@ func (p *processor) fullClient() util.Client {
|
|||
client := util.Client(&hClient)
|
||||
|
||||
// Add extra headers.
|
||||
if len(p.opts.ExtraHeader) > 0 {
|
||||
if len(p.cfg.ExtraHeader) > 0 {
|
||||
client = &util.HeaderClient{
|
||||
Client: client,
|
||||
Header: p.opts.ExtraHeader,
|
||||
Header: p.cfg.ExtraHeader,
|
||||
}
|
||||
}
|
||||
|
||||
// Add optional URL logging.
|
||||
if p.opts.Verbose {
|
||||
if p.cfg.Verbose {
|
||||
client = &util.LoggingClient{Client: client}
|
||||
}
|
||||
|
||||
// Add optional rate limiting.
|
||||
if p.opts.Rate != nil {
|
||||
if p.cfg.Rate != nil {
|
||||
client = &util.LimitingClient{
|
||||
Client: client,
|
||||
Limiter: rate.NewLimiter(rate.Limit(*p.opts.Rate), 1),
|
||||
Limiter: rate.NewLimiter(rate.Limit(*p.cfg.Rate), 1),
|
||||
}
|
||||
}
|
||||
return client
|
||||
|
|
@ -470,7 +469,7 @@ func (p *processor) fullClient() util.Client {
|
|||
|
||||
// basicClient returns a http Client w/o certs and headers.
|
||||
func (p *processor) basicClient() *http.Client {
|
||||
if p.opts.Insecure {
|
||||
if p.cfg.Insecure {
|
||||
tr := &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
}
|
||||
|
|
@ -500,7 +499,7 @@ func (p *processor) unauthorizedClient() util.Client {
|
|||
// usedAuthorizedClient tells if an authorized client is used
|
||||
// for downloading.
|
||||
func (p *processor) usedAuthorizedClient() bool {
|
||||
return p.opts.protectedAccess()
|
||||
return p.cfg.protectedAccess()
|
||||
}
|
||||
|
||||
// rolieFeedEntries loads the references to the advisory files for a given feed.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue