mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-09 00:00:00 +01:00
change WebRTC config format to the one of VILLASnode, add default values, update apispec #90
This commit is contained in:
parent
646ecfcc2a
commit
5e33e08393
5 changed files with 100 additions and 33 deletions
|
@ -83,9 +83,9 @@ func InitConfig() error {
|
|||
k8sRancherURL = flag.String("k8s-rancher-url", "https://rancher.k8s.eonerc.rwth-aachen.de", "URL of Rancher instance that is used to deploy the backend")
|
||||
k8sClusterName = flag.String("k8s-cluster-name", "local", "Name of the Kubernetes cluster where the backend is deployed")
|
||||
staleICTime = flag.String("stale-ic-time", "1h" /* 1 hour */, "Time after which an IC is considered stale")
|
||||
webRTCiceUsername = flag.String("webrtc-ice-user", "villas" /* */, "WebRTC ICE username")
|
||||
webRTCicePass = flag.String("webrtc-ice-pass", "villas" /* */, "WebRTC ICE password")
|
||||
webRTCiceUrls = flag.String("webrtc-ice-urls", "" /* */, "WebRTC ICE URLs (comma-separated list)")
|
||||
webRTCiceUrls = flag.String("webrtc-ice-urls",
|
||||
"stun:stun.l.google.com:19302,villas:villas@stun:stun.0l.de,villas:villas@turn:turn.0l.de?transport=udp,villas:villas@turn:turn.0l.de?transport=tcp",
|
||||
"WebRTC ICE URLs (comma-separated list, use username:password@url style for non-anonymous URLs)")
|
||||
)
|
||||
flag.Parse()
|
||||
|
||||
|
@ -122,8 +122,6 @@ func InitConfig() error {
|
|||
"k8s.rancher-url": *k8sRancherURL,
|
||||
"k8s.cluster-name": *k8sClusterName,
|
||||
"staleictime": *staleICTime,
|
||||
"webrtc.ice-username": *webRTCiceUsername,
|
||||
"webrtc.ice-pass": *webRTCicePass,
|
||||
"webrtc.ice-urls": *webRTCiceUrls,
|
||||
}
|
||||
|
||||
|
|
|
@ -3465,6 +3465,20 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"config.ICEServer": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"password": {
|
||||
"type": "string"
|
||||
},
|
||||
"url": {
|
||||
"type": "string"
|
||||
},
|
||||
"username": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"config.Kubernetes": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
@ -3479,14 +3493,11 @@ const docTemplate = `{
|
|||
"config.WebRTC": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"ice_password": {
|
||||
"type": "string"
|
||||
},
|
||||
"ice_urls": {
|
||||
"type": "string"
|
||||
},
|
||||
"ice_username": {
|
||||
"type": "string"
|
||||
"ice_servers": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/config.ICEServer"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -3457,6 +3457,20 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"config.ICEServer": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"password": {
|
||||
"type": "string"
|
||||
},
|
||||
"url": {
|
||||
"type": "string"
|
||||
},
|
||||
"username": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"config.Kubernetes": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
@ -3471,14 +3485,11 @@
|
|||
"config.WebRTC": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"ice_password": {
|
||||
"type": "string"
|
||||
},
|
||||
"ice_urls": {
|
||||
"type": "string"
|
||||
},
|
||||
"ice_username": {
|
||||
"type": "string"
|
||||
"ice_servers": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/config.ICEServer"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -122,6 +122,15 @@ definitions:
|
|||
name:
|
||||
type: string
|
||||
type: object
|
||||
config.ICEServer:
|
||||
properties:
|
||||
password:
|
||||
type: string
|
||||
url:
|
||||
type: string
|
||||
username:
|
||||
type: string
|
||||
type: object
|
||||
config.Kubernetes:
|
||||
properties:
|
||||
cluster_name:
|
||||
|
@ -131,12 +140,10 @@ definitions:
|
|||
type: object
|
||||
config.WebRTC:
|
||||
properties:
|
||||
ice_password:
|
||||
type: string
|
||||
ice_urls:
|
||||
type: string
|
||||
ice_username:
|
||||
type: string
|
||||
ice_servers:
|
||||
items:
|
||||
$ref: '#/definitions/config.ICEServer'
|
||||
type: array
|
||||
type: object
|
||||
dashboard.addDashboardRequest:
|
||||
properties:
|
||||
|
|
|
@ -20,6 +20,8 @@ package config
|
|||
import (
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
|
||||
"github.com/gin-gonic/gin"
|
||||
"log"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func RegisterConfigEndpoint(r *gin.RouterGroup) {
|
||||
|
@ -49,9 +51,13 @@ type Kubernetes struct {
|
|||
}
|
||||
|
||||
type WebRTC struct {
|
||||
ICEUsername string `json:"ice_username"`
|
||||
ICEPassword string `json:"ice_password"`
|
||||
ICEURLs string `json:"ice_urls"`
|
||||
ICEServers []ICEServer `json:"ice_servers"`
|
||||
}
|
||||
|
||||
type ICEServer struct {
|
||||
URL string `json:"url"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
|
@ -88,9 +94,43 @@ func getConfig(c *gin.Context) {
|
|||
resp.Contact.Mail, _ = cfg.String("contact.mail")
|
||||
resp.Kubernetes.RancherURL, _ = cfg.String("k8s.rancher-url")
|
||||
resp.Kubernetes.ClusterName, _ = cfg.String("k8s.cluster-name")
|
||||
resp.WebRTC.ICEUsername, _ = cfg.String("webrtc.ice-username")
|
||||
resp.WebRTC.ICEPassword, _ = cfg.String("webrtc.ice-pass")
|
||||
resp.WebRTC.ICEURLs, _ = cfg.String("webrtc.ice-urls")
|
||||
|
||||
var servers []ICEServer
|
||||
|
||||
// read config param webrtc.ice-urls and transform into data structure resp.WebRTC
|
||||
var ICEurlsRaw, err = cfg.String("webrtc.ice-urls")
|
||||
if err == nil {
|
||||
ICEurls := strings.Split(ICEurlsRaw, ",")
|
||||
|
||||
for _, url := range ICEurls {
|
||||
elements := strings.Split(url, "@")
|
||||
if len(elements) == 1 {
|
||||
// anonymous server, no username and password
|
||||
server := ICEServer{URL: elements[0], Username: "", Password: ""}
|
||||
servers = append(servers, server)
|
||||
|
||||
} else if len(elements) == 2 {
|
||||
// server requires username and password
|
||||
// split username and password
|
||||
credentials := strings.Split(elements[0], ":")
|
||||
if len(credentials) != 2 {
|
||||
// error
|
||||
log.Println("Error parsing WebRTC ICE URLs provided in config. Please check correct format of username and password of", url)
|
||||
break
|
||||
}
|
||||
server := ICEServer{URL: elements[1], Username: credentials[0], Password: credentials[1]}
|
||||
servers = append(servers, server)
|
||||
|
||||
} else {
|
||||
// error
|
||||
log.Println("Error parsing WebRTC ICE URLs provided in config. Please check correct format of", url)
|
||||
break
|
||||
}
|
||||
}
|
||||
resp.WebRTC.ICEServers = servers
|
||||
} else {
|
||||
log.Println("Error parsing WeRTC ICE URLs:", err)
|
||||
}
|
||||
|
||||
c.JSON(200, resp)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue