-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli-proxy-tty.go
48 lines (42 loc) · 961 Bytes
/
cli-proxy-tty.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"context"
"fmt"
)
func (c *CliProxy) runTTY(ctx context.Context) (err error) {
peer, err := c.newWebRTCPeerConnection()
if err != nil {
return fmt.Errorf("create peer connection failed: %w", err)
}
switch {
case len(c.Allows) > 0:
i := &IngressProxy{
signal: NewSignalTTY(),
peer: peer,
epAuth: NewBasicEndpointAuthorizer(c.Allows),
}
if err := i.Start(ctx); err != nil {
return fmt.Errorf("start ingress proxy errored: %w", err)
}
case len(c.Forwards) > 0:
var eps []Endpoint
for _, pair := range c.Forwards {
ep, err := EndpointFromString(pair)
if err != nil {
return err
}
eps = append(eps, ep)
}
i := &EgressProxy{
signal: NewSignalTTY(),
peer: peer,
endpoints: eps,
}
if err := i.Start(ctx); err != nil {
return fmt.Errorf("start egress proxy errored: %w", err)
}
default:
return fmt.Errorf("either specify --forward or --allow")
}
return
}