mirror of
https://github.com/openziti/zrok.git
synced 2024-12-23 23:29:22 +01:00
'zrok agent release access' (#463)
This commit is contained in:
parent
fa8c39b177
commit
ccfe0df728
29
agent/releaseAccess.go
Normal file
29
agent/releaseAccess.go
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
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.ReleaseAccessReply, 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)
|
||||||
|
logrus.Infof("released access '%v'", acc.frontendToken)
|
||||||
|
} else {
|
||||||
|
return nil, errors.Errorf("agent has no access with frontend token '%v'", req.FrontendToken)
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
|
}
|
55
cmd/zrok/agentReleaseAccess.go
Normal file
55
cmd/zrok/agentReleaseAccess.go
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"github.com/openziti/zrok/agent/agentClient"
|
||||||
|
"github.com/openziti/zrok/agent/agentGrpc"
|
||||||
|
"github.com/openziti/zrok/environment"
|
||||||
|
"github.com/openziti/zrok/tui"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
agentReleaseCmd.AddCommand(newAgentReleaseAccessCommand().cmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
type agentReleaseAccessCommand struct {
|
||||||
|
cmd *cobra.Command
|
||||||
|
}
|
||||||
|
|
||||||
|
func newAgentReleaseAccessCommand() *agentReleaseAccessCommand {
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "access <frontendToken>",
|
||||||
|
Short: "Unbind an access from the zrok Agent",
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
}
|
||||||
|
command := &agentReleaseAccessCommand{cmd: cmd}
|
||||||
|
cmd.Run = command.run
|
||||||
|
return command
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cmd *agentReleaseAccessCommand) run(_ *cobra.Command, args []string) {
|
||||||
|
root, err := environment.LoadRoot()
|
||||||
|
if err != nil {
|
||||||
|
if !panicInstead {
|
||||||
|
tui.Error("unable to load environment", err)
|
||||||
|
}
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
client, conn, err := agentClient.NewClient(root)
|
||||||
|
if err != nil {
|
||||||
|
tui.Error("error connecting to agent", err)
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
_, err = client.ReleaseAccess(context.Background(), &agentGrpc.ReleaseAccessRequest{
|
||||||
|
FrontendToken: args[0],
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
tui.Error("error releasing access", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("success.")
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user