Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some cleanups about host config #2490

Merged
merged 3 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/common/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,5 @@ func SetupGlobalLogger(c *cli.Context) {
log.Logger = log.With().Caller().Logger()
}

log.Log().Msgf("LogLevel = %s", zerolog.GlobalLevel().String())
log.Info().Msgf("LogLevel = %s", zerolog.GlobalLevel().String())
}
18 changes: 10 additions & 8 deletions cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ func run(c *cli.Context) error {
)
}

if _, err := url.Parse(c.String("server-host")); err != nil {
log.Fatal().Err(err).Msg("could not parse WOODPECKER_HOST")
}

if strings.Contains(c.String("server-host"), "://localhost") {
log.Warn().Msg(
"WOODPECKER_HOST should probably be publicly accessible (not localhost)",
Expand Down Expand Up @@ -136,7 +140,6 @@ func run(c *cli.Context) error {
server.Config.Services.Logs,
server.Config.Services.Pubsub,
_store,
server.Config.Server.Host,
)
proto.RegisterWoodpeckerServer(grpcServer, woodpeckerServer)

Expand Down Expand Up @@ -206,11 +209,9 @@ func run(c *cli.Context) error {

// http to https redirect
redirect := func(w http.ResponseWriter, req *http.Request) {
serverHost := server.Config.Server.Host
serverHost = strings.TrimPrefix(serverHost, "http://")
serverHost = strings.TrimPrefix(serverHost, "https://")
serverURL, _ := url.Parse(server.Config.Server.Host)
req.URL.Scheme = "https"
req.URL.Host = serverHost
req.URL.Host = serverURL.Host

w.Header().Set("Strict-Transport-Security", "max-age=31536000")

Expand Down Expand Up @@ -327,16 +328,17 @@ func setupEvilGlobals(c *cli.Context, v store.Store, f forge.Forge) {
server.Config.Server.Cert = c.String("server-cert")
server.Config.Server.Key = c.String("server-key")
server.Config.Server.AgentToken = c.String("agent-secret")
server.Config.Server.Host = c.String("server-host")
serverHost := c.String("server-host")
server.Config.Server.Host = serverHost
if c.IsSet("server-webhook-host") {
server.Config.Server.WebhookHost = c.String("server-webhook-host")
} else {
server.Config.Server.WebhookHost = c.String("server-host")
server.Config.Server.WebhookHost = serverHost
}
if c.IsSet("server-dev-oauth-host") {
server.Config.Server.OAuthHost = c.String("server-dev-oauth-host")
} else {
server.Config.Server.OAuthHost = c.String("server-host")
server.Config.Server.OAuthHost = serverHost
}
server.Config.Server.Port = c.String("server-addr")
server.Config.Server.PortTLS = c.String("server-addr-tls")
Expand Down
1 change: 0 additions & 1 deletion server/grpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ type RPC struct {
pubsub pubsub.Publisher
logger logging.Log
store store.Store
host string
pipelineTime *prometheus.GaugeVec
pipelineCount *prometheus.CounterVec
}
Expand Down
3 changes: 1 addition & 2 deletions server/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type WoodpeckerServer struct {
peer RPC
}

func NewWoodpeckerServer(forge forge.Forge, queue queue.Queue, logger logging.Log, pubsub pubsub.Publisher, store store.Store, host string) proto.WoodpeckerServer {
func NewWoodpeckerServer(forge forge.Forge, queue queue.Queue, logger logging.Log, pubsub pubsub.Publisher, store store.Store) proto.WoodpeckerServer {
pipelineTime := promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "woodpecker",
Name: "pipeline_time",
Expand All @@ -54,7 +54,6 @@ func NewWoodpeckerServer(forge forge.Forge, queue queue.Queue, logger logging.Lo
queue: queue,
pubsub: pubsub,
logger: logger,
host: host,
pipelineTime: pipelineTime,
pipelineCount: pipelineCount,
}
Expand Down