mirror of
https://github.com/openziti/zrok.git
synced 2025-06-23 19:22:19 +02:00
code polish and naming lint (#463)
This commit is contained in:
parent
1d012b849a
commit
9492f93a1d
@ -22,14 +22,14 @@ type access struct {
|
|||||||
bootComplete chan struct{}
|
bootComplete chan struct{}
|
||||||
bootErr error
|
bootErr error
|
||||||
|
|
||||||
a *Agent
|
agent *Agent
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *access) monitor() {
|
func (a *access) monitor() {
|
||||||
if err := proctree.WaitChild(a.process); err != nil {
|
if err := proctree.WaitChild(a.process); err != nil {
|
||||||
pfxlog.ChannelLogger(a.token).Error(err)
|
pfxlog.ChannelLogger(a.token).Error(err)
|
||||||
}
|
}
|
||||||
a.a.outAccesses <- a
|
a.agent.rmAccess <- a
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *access) tail(data []byte) {
|
func (a *access) tail(data []byte) {
|
||||||
|
@ -26,7 +26,7 @@ func (i *agentGrpcImpl) AccessPrivate(_ context.Context, req *agentGrpc.AccessPr
|
|||||||
bindAddress: req.BindAddress,
|
bindAddress: req.BindAddress,
|
||||||
responseHeaders: req.ResponseHeaders,
|
responseHeaders: req.ResponseHeaders,
|
||||||
bootComplete: make(chan struct{}),
|
bootComplete: make(chan struct{}),
|
||||||
a: i.a,
|
agent: i.agent,
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Infof("executing '%v'", accCmd)
|
logrus.Infof("executing '%v'", accCmd)
|
||||||
@ -40,7 +40,7 @@ func (i *agentGrpcImpl) AccessPrivate(_ context.Context, req *agentGrpc.AccessPr
|
|||||||
<-acc.bootComplete
|
<-acc.bootComplete
|
||||||
|
|
||||||
if acc.bootErr == nil {
|
if acc.bootErr == nil {
|
||||||
i.a.inAccesses <- acc
|
i.agent.addAccess <- acc
|
||||||
return &agentGrpc.AccessPrivateResponse{FrontendToken: acc.frontendToken}, nil
|
return &agentGrpc.AccessPrivateResponse{FrontendToken: acc.frontendToken}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,11 +16,11 @@ type Agent struct {
|
|||||||
root env_core.Root
|
root env_core.Root
|
||||||
agentSocket string
|
agentSocket string
|
||||||
shares map[string]*share
|
shares map[string]*share
|
||||||
inShares chan *share
|
addShare chan *share
|
||||||
outShares chan *share
|
rmShare chan *share
|
||||||
accesses map[string]*access
|
accesses map[string]*access
|
||||||
inAccesses chan *access
|
addAccess chan *access
|
||||||
outAccesses chan *access
|
rmAccess chan *access
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAgent(root env_core.Root) (*Agent, error) {
|
func NewAgent(root env_core.Root) (*Agent, error) {
|
||||||
@ -28,13 +28,13 @@ func NewAgent(root env_core.Root) (*Agent, error) {
|
|||||||
return nil, errors.Errorf("unable to load environment; did you 'zrok enable'?")
|
return nil, errors.Errorf("unable to load environment; did you 'zrok enable'?")
|
||||||
}
|
}
|
||||||
return &Agent{
|
return &Agent{
|
||||||
root: root,
|
root: root,
|
||||||
shares: make(map[string]*share),
|
shares: make(map[string]*share),
|
||||||
inShares: make(chan *share),
|
addShare: make(chan *share),
|
||||||
outShares: make(chan *share),
|
rmShare: make(chan *share),
|
||||||
accesses: make(map[string]*access),
|
accesses: make(map[string]*access),
|
||||||
inAccesses: make(chan *access),
|
addAccess: make(chan *access),
|
||||||
outAccesses: make(chan *access),
|
rmAccess: make(chan *access),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ func (a *Agent) Run() error {
|
|||||||
a.agentSocket = agentSocket
|
a.agentSocket = agentSocket
|
||||||
|
|
||||||
srv := grpc.NewServer()
|
srv := grpc.NewServer()
|
||||||
agentGrpc.RegisterAgentServer(srv, &agentGrpcImpl{a: a})
|
agentGrpc.RegisterAgentServer(srv, &agentGrpcImpl{agent: a})
|
||||||
if err := srv.Serve(l); err != nil {
|
if err := srv.Serve(l); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -73,11 +73,11 @@ func (a *Agent) Shutdown() {
|
|||||||
}
|
}
|
||||||
for _, shr := range a.shares {
|
for _, shr := range a.shares {
|
||||||
logrus.Debugf("stopping share '%v'", shr.token)
|
logrus.Debugf("stopping share '%v'", shr.token)
|
||||||
a.outShares <- shr
|
a.rmShare <- shr
|
||||||
}
|
}
|
||||||
for _, acc := range a.accesses {
|
for _, acc := range a.accesses {
|
||||||
logrus.Debugf("stopping access '%v'", acc.token)
|
logrus.Debugf("stopping access '%v'", acc.token)
|
||||||
a.outAccesses <- acc
|
a.rmAccess <- acc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,11 +87,11 @@ func (a *Agent) manager() {
|
|||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case inShare := <-a.inShares:
|
case inShare := <-a.addShare:
|
||||||
logrus.Infof("adding new share '%v'", inShare.token)
|
logrus.Infof("adding new share '%v'", inShare.token)
|
||||||
a.shares[inShare.token] = inShare
|
a.shares[inShare.token] = inShare
|
||||||
|
|
||||||
case outShare := <-a.outShares:
|
case outShare := <-a.rmShare:
|
||||||
if shr, found := a.shares[outShare.token]; found {
|
if shr, found := a.shares[outShare.token]; found {
|
||||||
logrus.Infof("removing share '%v'", shr.token)
|
logrus.Infof("removing share '%v'", shr.token)
|
||||||
if err := proctree.StopChild(shr.process); err != nil {
|
if err := proctree.StopChild(shr.process); err != nil {
|
||||||
@ -110,11 +110,11 @@ func (a *Agent) manager() {
|
|||||||
logrus.Debug("skipping unidentified (orphaned) share removal")
|
logrus.Debug("skipping unidentified (orphaned) share removal")
|
||||||
}
|
}
|
||||||
|
|
||||||
case inAccess := <-a.inAccesses:
|
case inAccess := <-a.addAccess:
|
||||||
logrus.Infof("adding new access '%v'", inAccess.frontendToken)
|
logrus.Infof("adding new access '%v'", inAccess.frontendToken)
|
||||||
a.accesses[inAccess.frontendToken] = inAccess
|
a.accesses[inAccess.frontendToken] = inAccess
|
||||||
|
|
||||||
case outAccess := <-a.outAccesses:
|
case outAccess := <-a.rmAccess:
|
||||||
if acc, found := a.accesses[outAccess.frontendToken]; found {
|
if acc, found := a.accesses[outAccess.frontendToken]; found {
|
||||||
logrus.Infof("removing access '%v'", acc.frontendToken)
|
logrus.Infof("removing access '%v'", acc.frontendToken)
|
||||||
if err := proctree.StopChild(acc.process); err != nil {
|
if err := proctree.StopChild(acc.process); err != nil {
|
||||||
@ -152,5 +152,5 @@ func (a *Agent) deleteAccess(token, frontendToken string) error {
|
|||||||
|
|
||||||
type agentGrpcImpl struct {
|
type agentGrpcImpl struct {
|
||||||
agentGrpc.UnimplementedAgentServer
|
agentGrpc.UnimplementedAgentServer
|
||||||
a *Agent
|
agent *Agent
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (i *agentGrpcImpl) ReleaseAccess(_ context.Context, req *agentGrpc.ReleaseAccessRequest) (*agentGrpc.ReleaseAccessResponse, error) {
|
func (i *agentGrpcImpl) ReleaseAccess(_ context.Context, req *agentGrpc.ReleaseAccessRequest) (*agentGrpc.ReleaseAccessResponse, error) {
|
||||||
if acc, found := i.a.accesses[req.FrontendToken]; found {
|
if acc, found := i.agent.accesses[req.FrontendToken]; found {
|
||||||
i.a.outAccesses <- acc
|
i.agent.rmAccess <- acc
|
||||||
logrus.Infof("released access '%v'", acc.frontendToken)
|
logrus.Infof("released access '%v'", acc.frontendToken)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -8,8 +8,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (i *agentGrpcImpl) ReleaseShare(_ context.Context, req *agentGrpc.ReleaseShareRequest) (*agentGrpc.ReleaseShareResponse, error) {
|
func (i *agentGrpcImpl) ReleaseShare(_ context.Context, req *agentGrpc.ReleaseShareRequest) (*agentGrpc.ReleaseShareResponse, error) {
|
||||||
if shr, found := i.a.shares[req.Token]; found {
|
if shr, found := i.agent.shares[req.Token]; found {
|
||||||
i.a.outShares <- shr
|
i.agent.rmShare <- shr
|
||||||
logrus.Infof("released share '%v'", shr.token)
|
logrus.Infof("released share '%v'", shr.token)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -34,14 +34,14 @@ type share struct {
|
|||||||
bootComplete chan struct{}
|
bootComplete chan struct{}
|
||||||
bootErr error
|
bootErr error
|
||||||
|
|
||||||
a *Agent
|
agent *Agent
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *share) monitor() {
|
func (s *share) monitor() {
|
||||||
if err := proctree.WaitChild(s.process); err != nil {
|
if err := proctree.WaitChild(s.process); err != nil {
|
||||||
pfxlog.ChannelLogger(s.token).Error(err)
|
pfxlog.ChannelLogger(s.token).Error(err)
|
||||||
}
|
}
|
||||||
s.a.outShares <- s
|
s.agent.rmShare <- s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *share) tail(data []byte) {
|
func (s *share) tail(data []byte) {
|
||||||
|
@ -26,7 +26,7 @@ func (i *agentGrpcImpl) SharePrivate(_ context.Context, req *agentGrpc.SharePriv
|
|||||||
shareMode: sdk.PrivateShareMode,
|
shareMode: sdk.PrivateShareMode,
|
||||||
backendMode: sdk.BackendMode(req.BackendMode),
|
backendMode: sdk.BackendMode(req.BackendMode),
|
||||||
bootComplete: make(chan struct{}),
|
bootComplete: make(chan struct{}),
|
||||||
a: i.a,
|
agent: i.agent,
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Insecure {
|
if req.Insecure {
|
||||||
@ -58,7 +58,7 @@ func (i *agentGrpcImpl) SharePrivate(_ context.Context, req *agentGrpc.SharePriv
|
|||||||
<-shr.bootComplete
|
<-shr.bootComplete
|
||||||
|
|
||||||
if shr.bootErr == nil {
|
if shr.bootErr == nil {
|
||||||
i.a.inShares <- shr
|
i.agent.addShare <- shr
|
||||||
return &agentGrpc.SharePrivateResponse{Token: shr.token}, nil
|
return &agentGrpc.SharePrivateResponse{Token: shr.token}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ func (i *agentGrpcImpl) SharePublic(_ context.Context, req *agentGrpc.SharePubli
|
|||||||
shareMode: sdk.PublicShareMode,
|
shareMode: sdk.PublicShareMode,
|
||||||
backendMode: sdk.BackendMode(req.BackendMode),
|
backendMode: sdk.BackendMode(req.BackendMode),
|
||||||
bootComplete: make(chan struct{}),
|
bootComplete: make(chan struct{}),
|
||||||
a: i.a,
|
agent: i.agent,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, basicAuth := range req.BasicAuth {
|
for _, basicAuth := range req.BasicAuth {
|
||||||
@ -82,7 +82,7 @@ func (i *agentGrpcImpl) SharePublic(_ context.Context, req *agentGrpc.SharePubli
|
|||||||
<-shr.bootComplete
|
<-shr.bootComplete
|
||||||
|
|
||||||
if shr.bootErr == nil {
|
if shr.bootErr == nil {
|
||||||
i.a.inShares <- shr
|
i.agent.addShare <- shr
|
||||||
return &agentGrpc.SharePublicResponse{
|
return &agentGrpc.SharePublicResponse{
|
||||||
Token: shr.token,
|
Token: shr.token,
|
||||||
FrontendEndpoints: shr.frontendEndpoints,
|
FrontendEndpoints: shr.frontendEndpoints,
|
||||||
|
@ -23,7 +23,7 @@ func (i *agentGrpcImpl) ShareReserved(_ context.Context, req *agentGrpc.ShareRes
|
|||||||
shr := &share{
|
shr := &share{
|
||||||
reserved: true,
|
reserved: true,
|
||||||
bootComplete: make(chan struct{}),
|
bootComplete: make(chan struct{}),
|
||||||
a: i.a,
|
agent: i.agent,
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.OverrideEndpoint != "" {
|
if req.OverrideEndpoint != "" {
|
||||||
@ -47,7 +47,7 @@ func (i *agentGrpcImpl) ShareReserved(_ context.Context, req *agentGrpc.ShareRes
|
|||||||
<-shr.bootComplete
|
<-shr.bootComplete
|
||||||
|
|
||||||
if shr.bootErr == nil {
|
if shr.bootErr == nil {
|
||||||
i.a.inShares <- shr
|
i.agent.addShare <- shr
|
||||||
return &agentGrpc.ShareReservedResponse{
|
return &agentGrpc.ShareReservedResponse{
|
||||||
Token: shr.token,
|
Token: shr.token,
|
||||||
BackendMode: string(shr.backendMode),
|
BackendMode: string(shr.backendMode),
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
|
|
||||||
func (i *agentGrpcImpl) Status(_ context.Context, _ *agentGrpc.StatusRequest) (*agentGrpc.StatusResponse, error) {
|
func (i *agentGrpcImpl) Status(_ context.Context, _ *agentGrpc.StatusRequest) (*agentGrpc.StatusResponse, error) {
|
||||||
var accesses []*agentGrpc.AccessDetail
|
var accesses []*agentGrpc.AccessDetail
|
||||||
for feToken, acc := range i.a.accesses {
|
for feToken, acc := range i.agent.accesses {
|
||||||
accesses = append(accesses, &agentGrpc.AccessDetail{
|
accesses = append(accesses, &agentGrpc.AccessDetail{
|
||||||
FrontendToken: feToken,
|
FrontendToken: feToken,
|
||||||
Token: acc.token,
|
Token: acc.token,
|
||||||
@ -17,7 +17,7 @@ func (i *agentGrpcImpl) Status(_ context.Context, _ *agentGrpc.StatusRequest) (*
|
|||||||
}
|
}
|
||||||
|
|
||||||
var shares []*agentGrpc.ShareDetail
|
var shares []*agentGrpc.ShareDetail
|
||||||
for token, shr := range i.a.shares {
|
for token, shr := range i.agent.shares {
|
||||||
shares = append(shares, &agentGrpc.ShareDetail{
|
shares = append(shares, &agentGrpc.ShareDetail{
|
||||||
Token: token,
|
Token: token,
|
||||||
ShareMode: string(shr.shareMode),
|
ShareMode: string(shr.shareMode),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user