diff --git a/pkg/config/config.go b/pkg/config/config.go index 47bdd99a6..663ce233b 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -2,6 +2,7 @@ package config import ( "fmt" + "io/ioutil" "os" "time" @@ -100,6 +101,8 @@ type TURNConfig struct { Domain string `yaml:"domain"` CertFile string `yaml:"cert_file"` KeyFile string `yaml:"key_file"` + Cert string `yaml:"cert"` + Key string `yaml:"key"` TLSPort int `yaml:"tls_port"` UDPPort int `yaml:"udp_port"` } @@ -197,6 +200,14 @@ func NewConfig(confString string, c *cli.Context) (*Config, error) { return nil, err } } + + if conf.TURN.Cert != "" && conf.TURN.CertFile != "" { + writeToFile(conf.TURN.CertFile, conf.TURN.Cert, false) + } + if conf.TURN.Key != "" && conf.TURN.KeyFile != "" { + writeToFile(conf.TURN.KeyFile, conf.TURN.Key, false) + } + return conf, nil } @@ -257,3 +268,13 @@ func (conf *Config) unmarshalKeys(keys string) error { func GetAudioConfig(conf *Config) AudioConfig { return conf.Audio } + +func writeToFile(path, content string, overwrite bool) { + if !overwrite { + // check if file exists + if _, err := os.Stat(path); err == nil { + return + } + } + ioutil.WriteFile(path, []byte(content), 0600) +} diff --git a/pkg/service/turn.go b/pkg/service/turn.go index 2ab460fd1..bca37d235 100644 --- a/pkg/service/turn.go +++ b/pkg/service/turn.go @@ -50,7 +50,7 @@ func NewTurnServer(conf *config.Config, authHandler turn.AuthHandler) (*turn.Ser return nil, errors.New("TURN domain required") } - if IsValidDomain(turnConf.Domain) == false { + if !IsValidDomain(turnConf.Domain) { return nil, errors.New("TURN domain is not correct") } diff --git a/pkg/service/wire_gen.go b/pkg/service/wire_gen.go index 2f6762f94..76ccd581f 100644 --- a/pkg/service/wire_gen.go +++ b/pkg/service/wire_gen.go @@ -1,7 +1,8 @@ // Code generated by Wire. DO NOT EDIT. //go:generate go run github.com/google/wire/cmd/wire -//+build !wireinject +//go:build !wireinject +// +build !wireinject package service