diff --git a/agent/model.go b/agent/model.go index 093fa729..bba1014e 100644 --- a/agent/model.go +++ b/agent/model.go @@ -7,7 +7,7 @@ import ( ) type share struct { - token string + shr *sdk.Share target string basicAuth []string diff --git a/agent/publicShare.go b/agent/publicShare.go index 5b7be474..a4bdb471 100644 --- a/agent/publicShare.go +++ b/agent/publicShare.go @@ -66,7 +66,7 @@ func (i *agentGrpcImpl) PublicShare(_ context.Context, req *agentGrpc.PublicShar } agentShr := &share{ - token: shr.Token, + shr: shr, target: req.Target, basicAuth: req.BasicAuth, frontendSelection: shr.FrontendEndpoints, diff --git a/agent/releaseShare.go b/agent/releaseShare.go index 9b826101..048cf526 100755 --- a/agent/releaseShare.go +++ b/agent/releaseShare.go @@ -3,18 +3,34 @@ package agent import ( "context" "github.com/openziti/zrok/agent/agentGrpc" + "github.com/openziti/zrok/environment" + "github.com/openziti/zrok/sdk/golang/sdk" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) func (i *agentGrpcImpl) ReleaseShare(_ context.Context, req *agentGrpc.ReleaseShareRequest) (*agentGrpc.ReleaseShareReply, error) { if shr, found := i.a.shares[req.Token]; found { - logrus.Infof("stopping share '%v'", shr.token) + logrus.Infof("stopping share '%v'", shr.shr.Token) if err := shr.handler.Stop(); err != nil { - logrus.Error(err) + logrus.Errorf("error stopping share '%v': %v", shr.shr.Token, err) } - delete(i.a.shares, shr.token) - logrus.Infof("released share '%v'", shr.token) + + root, err := environment.LoadRoot() + if err != nil { + return nil, err + } + + if !root.IsEnabled() { + return nil, errors.New("unable to load environment; did you 'zrok enable'?") + } + + if err := sdk.DeleteShare(root, shr.shr); err != nil { + logrus.Errorf("error releasing share '%v': %v", shr.shr.Token, err) + } + + delete(i.a.shares, shr.shr.Token) + logrus.Infof("released share '%v'", shr.shr.Token) } else { return nil, errors.Errorf("agent has no share with token '%v'", req.Token) }