mirror of
https://github.com/jsiebens/ionscale.git
synced 2026-03-31 15:07:49 +01:00
chore: web listener to listener
This commit is contained in:
@@ -52,9 +52,9 @@ func configureCommand() *cobra.Command {
|
|||||||
command.RunE = func(command *cobra.Command, args []string) error {
|
command.RunE = func(command *cobra.Command, args []string) error {
|
||||||
c := &config.Config{}
|
c := &config.Config{}
|
||||||
|
|
||||||
c.WebListenAddr = "0.0.0.0:443"
|
c.ListenAddr = "0.0.0.0:443"
|
||||||
c.MetricsListenAddr = "127.0.0.1:9090"
|
c.MetricsListenAddr = "127.0.0.1:9090"
|
||||||
c.WebPublicAddr = fmt.Sprintf("%s:443", domain)
|
c.PublicAddr = fmt.Sprintf("%s:443", domain)
|
||||||
|
|
||||||
c.Keys = config.Keys{
|
c.Keys = config.Keys{
|
||||||
ControlKey: key.NewServerKey().String(),
|
ControlKey: key.NewServerKey().String(),
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ func LoadConfig(path string) (*Config, error) {
|
|||||||
|
|
||||||
func defaultConfig() *Config {
|
func defaultConfig() *Config {
|
||||||
return &Config{
|
return &Config{
|
||||||
WebListenAddr: ":8080",
|
ListenAddr: ":8080",
|
||||||
MetricsListenAddr: ":9091",
|
MetricsListenAddr: ":9091",
|
||||||
StunListenAddr: ":3478",
|
StunListenAddr: ":3478",
|
||||||
Database: Database{
|
Database: Database{
|
||||||
@@ -143,10 +143,10 @@ type ServerKeys struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
WebListenAddr string `yaml:"web_listen_addr,omitempty" env:"WEB_LISTEN_ADDR"`
|
ListenAddr string `yaml:"listen_addr,omitempty" env:"LISTEN_ADDR"`
|
||||||
StunListenAddr string `yaml:"stun_listen_addr,omitempty" env:"STUN_LISTEN_ADDR"`
|
StunListenAddr string `yaml:"stun_listen_addr,omitempty" env:"STUN_LISTEN_ADDR"`
|
||||||
MetricsListenAddr string `yaml:"metrics_listen_addr,omitempty" env:"METRICS_LISTEN_ADDR"`
|
MetricsListenAddr string `yaml:"metrics_listen_addr,omitempty" env:"METRICS_LISTEN_ADDR"`
|
||||||
WebPublicAddr string `yaml:"web_public_addr,omitempty" env:"WEB_PUBLIC_ADDR"`
|
PublicAddr string `yaml:"public_addr,omitempty" env:"PUBLIC_ADDR"`
|
||||||
StunPublicAddr string `yaml:"stun_public_addr,omitempty" env:"STUN_PUBLIC_ADDR"`
|
StunPublicAddr string `yaml:"stun_public_addr,omitempty" env:"STUN_PUBLIC_ADDR"`
|
||||||
Tls Tls `yaml:"tls,omitempty" envPrefix:"TLS_"`
|
Tls Tls `yaml:"tls,omitempty" envPrefix:"TLS_"`
|
||||||
PollNet PollNet `yaml:"poll_net,omitempty" envPrefix:"POLL_NET_"`
|
PollNet PollNet `yaml:"poll_net,omitempty" envPrefix:"POLL_NET_"`
|
||||||
@@ -157,7 +157,7 @@ type Config struct {
|
|||||||
DERP DERP `yaml:"derp,omitempty" envPrefix:"DERP_"`
|
DERP DERP `yaml:"derp,omitempty" envPrefix:"DERP_"`
|
||||||
Logging Logging `yaml:"logging,omitempty" envPrefix:"LOGGING_"`
|
Logging Logging `yaml:"logging,omitempty" envPrefix:"LOGGING_"`
|
||||||
|
|
||||||
WebPublicUrl *url.URL `yaml:"-"`
|
PublicUrl *url.URL `yaml:"-"`
|
||||||
|
|
||||||
stunHost string
|
stunHost string
|
||||||
stunPort int
|
stunPort int
|
||||||
@@ -242,12 +242,12 @@ type DERPServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) Validate() (*Config, error) {
|
func (c *Config) Validate() (*Config, error) {
|
||||||
publicWebUrl, webHost, webPort, err := validatePublicAddr(c.WebPublicAddr)
|
publicWebUrl, webHost, webPort, err := validatePublicAddr(c.PublicAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("web public addr: %w", err)
|
return nil, fmt.Errorf("web public addr: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.WebPublicUrl = publicWebUrl
|
c.PublicUrl = publicWebUrl
|
||||||
c.derpHost = webHost
|
c.derpHost = webHost
|
||||||
c.derpPort = webPort
|
c.derpPort = webPort
|
||||||
|
|
||||||
@@ -267,8 +267,8 @@ func (c *Config) Validate() (*Config, error) {
|
|||||||
func (c *Config) CreateUrl(format string, a ...interface{}) string {
|
func (c *Config) CreateUrl(format string, a ...interface{}) string {
|
||||||
path := fmt.Sprintf(format, a...)
|
path := fmt.Sprintf(format, a...)
|
||||||
u := url.URL{
|
u := url.URL{
|
||||||
Scheme: c.WebPublicUrl.Scheme,
|
Scheme: c.PublicUrl.Scheme,
|
||||||
Host: c.WebPublicUrl.Host,
|
Host: c.PublicUrl.Host,
|
||||||
Path: path,
|
Path: path,
|
||||||
}
|
}
|
||||||
return u.String()
|
return u.String()
|
||||||
|
|||||||
@@ -17,14 +17,14 @@ import (
|
|||||||
func NewIDTokenHandlers(machineKey key.MachinePublic, config *config.Config, repository domain.Repository) *IDTokenHandlers {
|
func NewIDTokenHandlers(machineKey key.MachinePublic, config *config.Config, repository domain.Repository) *IDTokenHandlers {
|
||||||
return &IDTokenHandlers{
|
return &IDTokenHandlers{
|
||||||
machineKey: machineKey,
|
machineKey: machineKey,
|
||||||
issuer: config.WebPublicUrl.String(),
|
issuer: config.PublicUrl.String(),
|
||||||
repository: repository,
|
repository: repository,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewOIDCConfigHandlers(config *config.Config, repository domain.Repository) *OIDCConfigHandlers {
|
func NewOIDCConfigHandlers(config *config.Config, repository domain.Repository) *OIDCConfigHandlers {
|
||||||
return &OIDCConfigHandlers{
|
return &OIDCConfigHandlers{
|
||||||
issuer: config.WebPublicUrl.String(),
|
issuer: config.PublicUrl.String(),
|
||||||
jwksUri: config.CreateUrl("/.well-known/jwks"),
|
jwksUri: config.CreateUrl("/.well-known/jwks"),
|
||||||
repository: repository,
|
repository: repository,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ func Start(ctx context.Context, c *config.Config) error {
|
|||||||
certmagic.Default.Storage = storage
|
certmagic.Default.Storage = storage
|
||||||
|
|
||||||
cfg := certmagic.NewDefault()
|
cfg := certmagic.NewDefault()
|
||||||
if err := cfg.ManageAsync(ctx, []string{c.WebPublicUrl.Hostname()}); err != nil {
|
if err := cfg.ManageAsync(ctx, []string{c.PublicUrl.Hostname()}); err != nil {
|
||||||
return logError(err)
|
return logError(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -226,8 +226,8 @@ func Start(ctx context.Context, c *config.Config) error {
|
|||||||
g.Go(func() error { return stunServer.Serve() })
|
g.Go(func() error { return stunServer.Serve() })
|
||||||
|
|
||||||
fields := []zap.Field{
|
fields := []zap.Field{
|
||||||
zap.String("url", c.WebPublicUrl.String()),
|
zap.String("url", c.PublicUrl.String()),
|
||||||
zap.String("addr", c.WebListenAddr),
|
zap.String("addr", c.ListenAddr),
|
||||||
zap.String("metrics_addr", c.MetricsListenAddr),
|
zap.String("metrics_addr", c.MetricsListenAddr),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,7 +238,7 @@ func Start(ctx context.Context, c *config.Config) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if c.Tls.AcmeEnabled {
|
if c.Tls.AcmeEnabled {
|
||||||
logger.Info("TLS is enabled with ACME", zap.String("domain", c.WebPublicUrl.Hostname()))
|
logger.Info("TLS is enabled with ACME", zap.String("domain", c.PublicUrl.Hostname()))
|
||||||
logger.Info("Server is running", fields...)
|
logger.Info("Server is running", fields...)
|
||||||
} else if !c.Tls.Disable {
|
} else if !c.Tls.Disable {
|
||||||
logger.Info("TLS is enabled", zap.String("cert", c.Tls.CertFile))
|
logger.Info("TLS is enabled", zap.String("cert", c.Tls.CertFile))
|
||||||
@@ -286,14 +286,14 @@ func setupAuthProvider(config config.Auth) (auth.Provider, *domain.IAMPolicy, er
|
|||||||
|
|
||||||
func webListener(config *config.Config) (net.Listener, error) {
|
func webListener(config *config.Config) (net.Listener, error) {
|
||||||
if config.Tls.Disable {
|
if config.Tls.Disable {
|
||||||
return net.Listen("tcp", config.WebListenAddr)
|
return net.Listen("tcp", config.ListenAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Tls.AcmeEnabled {
|
if config.Tls.AcmeEnabled {
|
||||||
cfg := certmagic.NewDefault()
|
cfg := certmagic.NewDefault()
|
||||||
tlsConfig := cfg.TLSConfig()
|
tlsConfig := cfg.TLSConfig()
|
||||||
tlsConfig.NextProtos = append([]string{"h2", "http/1.1"}, tlsConfig.NextProtos...)
|
tlsConfig.NextProtos = append([]string{"h2", "http/1.1"}, tlsConfig.NextProtos...)
|
||||||
return tls.Listen("tcp", config.WebListenAddr, tlsConfig)
|
return tls.Listen("tcp", config.ListenAddr, tlsConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
certPEMBlock, err := os.ReadFile(config.Tls.CertFile)
|
certPEMBlock, err := os.ReadFile(config.Tls.CertFile)
|
||||||
@@ -312,7 +312,7 @@ func webListener(config *config.Config) (net.Listener, error) {
|
|||||||
|
|
||||||
tlsConfig := &tls.Config{Certificates: []tls.Certificate{cer}}
|
tlsConfig := &tls.Config{Certificates: []tls.Certificate{cer}}
|
||||||
|
|
||||||
return tls.Listen("tcp", config.WebListenAddr, tlsConfig)
|
return tls.Listen("tcp", config.ListenAddr, tlsConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
func metricsListener(config *config.Config) (net.Listener, error) {
|
func metricsListener(config *config.Config) (net.Listener, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user