diff --git a/agent/agent.go b/agent/agent.go index 7eb87f75..9ecf750f 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -4,6 +4,7 @@ import ( "github.com/openziti/zrok/agent/agentGrpc" "github.com/openziti/zrok/agent/proctree" "github.com/openziti/zrok/environment/env_core" + "github.com/openziti/zrok/sdk/golang/sdk" "github.com/pkg/errors" "github.com/sirupsen/logrus" "google.golang.org/grpc" @@ -99,6 +100,11 @@ func (a *Agent) manager() { if err := proctree.WaitChild(outShare.process); err != nil { logrus.Errorf("error joining share '%v': %v", outShare.token, err) } + if !outShare.reserved { + if err := a.deleteShare(outShare.token); err != nil { + logrus.Errorf("error deleting share '%v': %v", outShare.token, err) + } + } delete(a.shares, outShare.token) } else { logrus.Debug("skipping unidentified (orphaned) share removal") @@ -117,6 +123,9 @@ func (a *Agent) manager() { if err := proctree.WaitChild(outAccess.process); err != nil { logrus.Errorf("error joining access '%v': %v", outAccess.frontendToken, err) } + if err := a.deleteAccess(outAccess.token, outAccess.frontendToken); err != nil { + logrus.Errorf("error deleting access '%v': %v", outAccess.frontendToken, err) + } delete(a.accesses, outAccess.frontendToken) } else { logrus.Debug("skipping unidentified (orphaned) access removal") @@ -125,6 +134,20 @@ func (a *Agent) manager() { } } +func (a *Agent) deleteShare(token string) error { + if err := sdk.DeleteShare(a.root, &sdk.Share{Token: token}); err != nil { + return err + } + return nil +} + +func (a *Agent) deleteAccess(token, frontendToken string) error { + if err := sdk.DeleteAccess(a.root, &sdk.Access{Token: frontendToken, ShareToken: token}); err != nil { + return err + } + return nil +} + type agentGrpcImpl struct { agentGrpc.UnimplementedAgentServer a *Agent diff --git a/agent/releaseAccess.go b/agent/releaseAccess.go index 5318b282..ba9d3445 100644 --- a/agent/releaseAccess.go +++ b/agent/releaseAccess.go @@ -3,25 +3,15 @@ package agent import ( "context" "github.com/openziti/zrok/agent/agentGrpc" - "github.com/openziti/zrok/agent/proctree" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) func (i *agentGrpcImpl) ReleaseAccess(_ context.Context, req *agentGrpc.ReleaseAccessRequest) (*agentGrpc.ReleaseAccessResponse, error) { if acc, found := i.a.accesses[req.FrontendToken]; found { - logrus.Infof("stopping access '%v'", acc.frontendToken) - - if err := proctree.StopChild(acc.process); err != nil { - logrus.Error(err) - } - - if err := proctree.WaitChild(acc.process); err != nil { - logrus.Error(err) - } - - delete(i.a.accesses, acc.frontendToken) + i.a.outAccesses <- acc logrus.Infof("released access '%v'", acc.frontendToken) + } else { return nil, errors.Errorf("agent has no access with frontend token '%v'", req.FrontendToken) } diff --git a/agent/releaseShare.go b/agent/releaseShare.go index 5db67811..0fd4d56e 100755 --- a/agent/releaseShare.go +++ b/agent/releaseShare.go @@ -3,25 +3,15 @@ package agent import ( "context" "github.com/openziti/zrok/agent/agentGrpc" - "github.com/openziti/zrok/agent/proctree" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) func (i *agentGrpcImpl) ReleaseShare(_ context.Context, req *agentGrpc.ReleaseShareRequest) (*agentGrpc.ReleaseShareResponse, error) { if shr, found := i.a.shares[req.Token]; found { - logrus.Infof("stopping share '%v'", shr.token) - - if err := proctree.StopChild(shr.process); err != nil { - logrus.Error(err) - } - - if err := proctree.WaitChild(shr.process); err != nil { - logrus.Error(err) - } - - delete(i.a.shares, shr.token) + i.a.outShares <- shr logrus.Infof("released share '%v'", shr.token) + } else { return nil, errors.Errorf("agent has no share with token '%v'", req.Token) }