mirror of
https://github.com/openziti/zrok.git
synced 2024-12-22 23:02:52 +01:00
disable; working (#30)
This commit is contained in:
parent
c59f3cd722
commit
e2c376e5ca
50
cmd/zrok/disable.go
Normal file
50
cmd/zrok/disable.go
Normal file
@ -0,0 +1,50 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
httptransport "github.com/go-openapi/runtime/client"
|
||||
"github.com/openziti-test-kitchen/zrok/rest_client_zrok/identity"
|
||||
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
|
||||
"github.com/openziti-test-kitchen/zrok/zrokdir"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(newDisableCommand().cmd)
|
||||
}
|
||||
|
||||
type disableCommand struct {
|
||||
cmd *cobra.Command
|
||||
}
|
||||
|
||||
func newDisableCommand() *disableCommand {
|
||||
cmd := &cobra.Command{
|
||||
Use: "disable",
|
||||
Short: "Disable (and clean up) the enabled zrok environment",
|
||||
Args: cobra.NoArgs,
|
||||
}
|
||||
command := &disableCommand{cmd: cmd}
|
||||
cmd.Run = command.run
|
||||
return command
|
||||
}
|
||||
|
||||
func (cmd *disableCommand) run(_ *cobra.Command, args []string) {
|
||||
env, err := zrokdir.LoadEnvironment()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
zrok := newZrokClient()
|
||||
auth := httptransport.APIKeyAuth("X-TOKEN", "header", env.ZrokToken)
|
||||
req := identity.NewDisableParams()
|
||||
req.Body = &rest_model_zrok.DisableRequest{
|
||||
Identity: env.ZitiIdentityId,
|
||||
}
|
||||
_, err = zrok.Identity.Disable(req, auth)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := zrokdir.Delete(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
logrus.Infof("environment disabled")
|
||||
}
|
@ -35,7 +35,7 @@ func (self *disableHandler) Handle(params identity.DisableParams, principal *res
|
||||
logrus.Errorf("identity check failed: %v", err)
|
||||
return identity.NewDisableUnauthorized()
|
||||
}
|
||||
if err := self.removeEnvironment(envId, tx); err == nil {
|
||||
if err := self.removeEnvironment(envId, tx); err != nil {
|
||||
logrus.Errorf("error removing environment: %v", err)
|
||||
return identity.NewDisableInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
|
||||
}
|
||||
|
@ -13,6 +13,17 @@ type Environment struct {
|
||||
ZitiIdentityId string `json:"ziti_identity"`
|
||||
}
|
||||
|
||||
func Delete() error {
|
||||
path, err := zrokDir()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.RemoveAll(path); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func LoadEnvironment() (*Environment, error) {
|
||||
ef, err := environmentFile()
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user