prysm-pulse/testing/middleware/builder/options.go
Nishant Das aef22bf54e
Add In Support For Builder in E2E (#12343)
* fix it up

* add gaz

* add changes in

* finally runs

* fix it

* add progress

* add capella support

* save progress

* remove debug logs

* cleanup

* remove log

* fix flag

* remove unused lock

* gaz

* change

* fix

* lint

* james review

---------

Co-authored-by: james-prysm <90280386+james-prysm@users.noreply.github.com>
2023-05-11 11:10:29 -05:00

80 lines
1.6 KiB
Go

package builder
import (
"net/url"
"os"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
type config struct {
builderPort int
builderHost string
destinationUrl *url.URL
logger *logrus.Logger
secret string
}
type Option func(p *Builder) error
// WithHost sets the proxy server host.
func WithHost(host string) Option {
return func(p *Builder) error {
p.cfg.builderHost = host
return nil
}
}
// WithPort sets the proxy server port.
func WithPort(port int) Option {
return func(p *Builder) error {
p.cfg.builderPort = port
return nil
}
}
// WithDestinationAddress sets the forwarding address requests will be sent to.
func WithDestinationAddress(addr string) Option {
return func(p *Builder) error {
if addr == "" {
return errors.New("must provide a destination address for builder")
}
u, err := url.Parse(addr)
if err != nil {
return errors.Wrapf(err, "could not parse URL for destination address: %s", addr)
}
p.cfg.destinationUrl = u
return nil
}
}
// WithJwtSecret adds in support for jwt authenticated
// connections for our proxy.
func WithJwtSecret(secret string) Option {
return func(p *Builder) error {
p.cfg.secret = secret
return nil
}
}
// WithLogger sets a custom logger for the proxy.
func WithLogger(l *logrus.Logger) Option {
return func(p *Builder) error {
p.cfg.logger = l
return nil
}
}
// WithLogFile specifies a log file to write
// the proxies output to.
func WithLogFile(f *os.File) Option {
return func(p *Builder) error {
if p.cfg.logger == nil {
return errors.New("nil logger provided")
}
p.cfg.logger.SetOutput(f)
return nil
}
}