Skip to content

Commit

Permalink
chore: update dependencies, incorporates srtgo fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
iSchluff committed Nov 6, 2023
1 parent 3683d2f commit 990271f
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 29 deletions.
18 changes: 14 additions & 4 deletions auth/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,30 @@ type httpAuth struct {
client *http.Client
}

type Duration time.Duration

func (d *Duration) UnmarshalText(b []byte) error {
x, err := time.ParseDuration(string(b))
if err != nil {
return err
}
*d = Duration(x)
return nil
}

type HTTPAuthConfig struct {
URL string
Application string
Timeout time.Duration // Timeout for Auth request
PasswordParam string // POST Parameter containing stream passphrase
Timeout Duration // Timeout for Auth request
PasswordParam string // POST Parameter containing stream passphrase
}

// NewHttpAuth creates an Authenticator with a HTTP backend
func NewHTTPAuth(config HTTPAuthConfig) *httpAuth {
return &httpAuth{
config: config,
client: &http.Client{
Timeout: config.Timeout,
Timeout: time.Duration(config.Timeout),
},
}
}
Expand All @@ -44,7 +55,6 @@ func (h *httpAuth) Authenticate(streamid stream.StreamID) bool {
"name": {streamid.Name()},
h.config.PasswordParam: {streamid.Password()},
})

if err != nil {
log.Println("http-auth:", err)
return false
Expand Down
17 changes: 8 additions & 9 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package config

import (
"fmt"
"io/ioutil"
"log"
"os"
"strings"
"time"

"github.com/Showmax/go-fqdn"
"github.com/pelletier/go-toml"
"github.com/pelletier/go-toml/v2"
"github.com/voc/srtrelay/auth"
)

Expand Down Expand Up @@ -75,12 +74,12 @@ func Parse(paths []string) (*Config, error) {
// set defaults
config := Config{
App: AppConfig{
Addresses: []string{"localhost:1337"},
Latency: 200,
Addresses: []string{"localhost:1337"},
Latency: 200,
ListenTimeout: 3000,
LossMaxTTL: 0,
Buffersize: 384000,
SyncClients: false,
LossMaxTTL: 0,
Buffersize: 384000,
SyncClients: false,
},
Auth: AuthConfig{
Type: "static",
Expand All @@ -90,7 +89,7 @@ func Parse(paths []string) (*Config, error) {
},
HTTP: auth.HTTPAuthConfig{
URL: "http://localhost:8080/publish",
Timeout: time.Second,
Timeout: auth.Duration(time.Second),
Application: "stream",
PasswordParam: "auth",
},
Expand All @@ -106,7 +105,7 @@ func Parse(paths []string) (*Config, error) {

// try to read file from given paths
for _, path := range paths {
data, err = ioutil.ReadFile(path)
data, err = os.ReadFile(path)
if err == nil {
log.Println("Read config from", path)
break
Expand Down
30 changes: 30 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package config

import (
"testing"
"time"

"github.com/voc/srtrelay/auth"
"gotest.tools/v3/assert"
)

func TestConfig(t *testing.T) {
conf, err := Parse([]string{"testfiles/config_test.toml"})
if err != nil {
t.Error(err)
}
assert.Equal(t, conf.App.Addresses[0], "127.0.0.1:5432")
assert.Equal(t, conf.App.Latency, uint(1337))
assert.Equal(t, conf.App.Buffersize, uint(123000))
assert.Equal(t, conf.App.SyncClients, true)

assert.Equal(t, conf.API.Enabled, false)
assert.Equal(t, conf.API.Address, ":1234")

assert.Equal(t, conf.Auth.Type, "http")
assert.Equal(t, conf.Auth.Static.Allow[0], "play/*")
assert.Equal(t, conf.Auth.HTTP.URL, "http://localhost:1235/publish")
assert.Equal(t, conf.Auth.HTTP.Timeout, auth.Duration(time.Second*5))
assert.Equal(t, conf.Auth.HTTP.Application, "foo")
assert.Equal(t, conf.Auth.HTTP.PasswordParam, "pass")
}
21 changes: 21 additions & 0 deletions config/testfiles/config_test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[app]
addresses = ["127.0.0.1:5432"]
latency = 1337
buffersize = 123000
syncClients = true

[api]
enabled = false
address = ":1234"

[auth]
type = "http"

[auth.static]
allow = ["play/*"]

[auth.http]
url = "http://localhost:1235/publish"
timeout = "5s"
application = "foo"
passwordParam = "pass"
10 changes: 6 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ module github.com/voc/srtrelay
go 1.13

require (
github.com/Showmax/go-fqdn v1.0.0 // indirect
github.com/haivision/srtgo v0.0.0-20210708214141-ea719a26f9f2
github.com/Showmax/go-fqdn v1.0.0
github.com/haivision/srtgo v0.0.0-20230627061225-a70d53fcd618
github.com/minio/minio v0.0.0-20201124200415-f96ed3769f87
github.com/pelletier/go-toml v1.9.3
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
github.com/pelletier/go-toml/v2 v2.1.0
golang.org/x/sys v0.14.0 // indirect
google.golang.org/protobuf v1.22.0
gotest.tools/v3 v3.5.1
)
Loading

0 comments on commit 990271f

Please sign in to comment.