support turn cert itself in config

This commit is contained in:
Mathew Kamkar
2021-10-15 13:11:40 -07:00
parent 90e0a6b65a
commit 94aea85334
3 changed files with 24 additions and 2 deletions
+21
View File
@@ -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)
}
+1 -1
View File
@@ -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")
}
+2 -1
View File
@@ -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