Skip to content
This repository has been archived by the owner on May 27, 2021. It is now read-only.

Commit

Permalink
auth,server: get credentials from flag value
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Jul 8, 2018
1 parent e8a4979 commit 647f247
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion internal/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
package auth

import (
"github.com/gortc/stun"
"sync"

"github.com/gortc/stun"
)

type StaticCredential struct {
Expand Down
17 changes: 14 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ import (
"github.com/gortc/turn"
)

const defaultAuthList = "username:realm:secret,username2:realm:secret2"

var (
network = flag.String("net", "udp", "network to listen")
address = flag.String("addr", fmt.Sprintf("0.0.0.0:%d", stun.DefaultPort), "address to listen")
profile = flag.Bool("profile", false, "run pprof")
profileAddr = flag.String("profile.addr", "localhost:6060", "address to listen for pprof")
authList = flag.String("auth", defaultAuthList, "long-term credentials")
)

type authService interface {
Expand Down Expand Up @@ -328,15 +331,23 @@ func ListenUDPAndServe(serverNet, laddr string, logger *zap.Logger) error {
if err != nil {
return err
}

var credentials []auth.StaticCredential
for _, s := range strings.Split(*authList, ",") {
parts := strings.Split(s, ":")
credentials = append(credentials, auth.StaticCredential{
Username: parts[0],
Realm: parts[1],
Password: parts[2],
})
}
s := &Server{
log: logger,
ip: net.IPv4(0, 0, 0, 0),
currentPort: 50000,
conn: c,
allocs: allocator.NewAllocator(logger.Named("allocator"), netAlloc),
auth: auth.NewStatic([]auth.StaticCredential{
{Username: "username", Password: "secret", Realm: "realm"},
}),
auth: auth.NewStatic(credentials),
}
return s.Serve(c)
}
Expand Down

0 comments on commit 647f247

Please sign in to comment.