roughed in share release (#463)

This commit is contained in:
Michael Quigley 2024-09-10 13:54:38 -04:00
parent e7405cd9bb
commit 597776a835
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
3 changed files with 22 additions and 6 deletions

View File

@ -7,7 +7,7 @@ import (
)
type share struct {
token string
shr *sdk.Share
target string
basicAuth []string

View File

@ -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,

View File

@ -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)
}