zrok/agent/share.go

84 lines
1.9 KiB
Go
Raw Normal View History

2024-08-22 17:02:33 +02:00
package agent
2024-08-21 20:48:02 +02:00
import (
2024-09-13 20:40:55 +02:00
"errors"
"github.com/michaelquigley/pfxlog"
"github.com/openziti/zrok/agent/proctree"
"github.com/openziti/zrok/cmd/zrok/subordinate"
2024-08-21 20:48:02 +02:00
"github.com/openziti/zrok/sdk/golang/sdk"
"time"
)
type share struct {
2024-09-12 19:07:27 +02:00
token string
frontendEndpoints []string
2024-09-12 19:07:27 +02:00
target string
2024-08-21 20:48:02 +02:00
basicAuth []string
frontendSelection []string
shareMode sdk.ShareMode
2024-08-21 20:48:02 +02:00
backendMode sdk.BackendMode
reserved bool
2024-08-21 20:48:02 +02:00
insecure bool
oauthProvider string
oauthEmailAddressPatterns []string
oauthCheckInterval time.Duration
closed bool
accessGrants []string
process *proctree.Child
sub *subordinate.MessageHandler
2024-09-25 17:06:06 +02:00
agent *Agent
}
func (s *share) monitor() {
if err := proctree.WaitChild(s.process); err != nil {
pfxlog.ChannelLogger(s.token).Error(err)
}
2024-09-25 17:06:06 +02:00
s.agent.rmShare <- s
}
func (s *share) bootHandler(msgType string, msg subordinate.Message) error {
switch msgType {
case subordinate.BootMessage:
if v, found := msg["token"]; found {
if str, ok := v.(string); ok {
s.token = str
}
}
if v, found := msg["backend_mode"]; found {
if str, ok := v.(string); ok {
s.backendMode = sdk.BackendMode(str)
}
}
if v, found := msg["share_mode"]; found {
if str, ok := v.(string); ok {
s.shareMode = sdk.ShareMode(str)
}
}
if v, found := msg["frontend_endpoints"]; found {
if vArr, ok := v.([]interface{}); ok {
for _, v := range vArr {
if str, ok := v.(string); ok {
s.frontendEndpoints = append(s.frontendEndpoints, str)
}
}
}
}
if v, found := msg["target"]; found {
if str, ok := v.(string); ok {
s.target = str
}
}
case subordinate.ErrorMessage:
if v, found := msg[subordinate.ErrorMessage]; found {
if str, ok := v.(string); ok {
return errors.New(str)
2024-09-12 20:12:46 +02:00
}
}
}
return nil
2024-08-21 20:48:02 +02:00
}