2022-11-30 19:45:57 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
httptransport "github.com/go-openapi/runtime/client"
|
2023-07-13 20:26:35 +02:00
|
|
|
"github.com/openziti/zrok/environment"
|
2023-01-13 21:01:34 +01:00
|
|
|
"github.com/openziti/zrok/rest_client_zrok/share"
|
|
|
|
"github.com/openziti/zrok/rest_model_zrok"
|
|
|
|
"github.com/openziti/zrok/tui"
|
2022-11-30 19:45:57 +01:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rootCmd.AddCommand(newReleaseCommand().cmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
type releaseCommand struct {
|
|
|
|
cmd *cobra.Command
|
|
|
|
}
|
|
|
|
|
|
|
|
func newReleaseCommand() *releaseCommand {
|
|
|
|
cmd := &cobra.Command{
|
2023-01-04 20:42:58 +01:00
|
|
|
Use: "release <shareToken>",
|
|
|
|
Short: "Release a reserved share",
|
2022-11-30 19:45:57 +01:00
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
}
|
|
|
|
command := &releaseCommand{cmd: cmd}
|
|
|
|
cmd.Run = command.run
|
|
|
|
return command
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *releaseCommand) run(_ *cobra.Command, args []string) {
|
2023-01-04 20:42:58 +01:00
|
|
|
shrToken := args[0]
|
2023-07-13 20:26:35 +02:00
|
|
|
env, err := environment.LoadRoot()
|
2022-11-30 19:45:57 +01:00
|
|
|
if err != nil {
|
|
|
|
if !panicInstead {
|
2023-07-10 22:41:16 +02:00
|
|
|
tui.Error("unable to load environment", err)
|
2022-11-30 19:45:57 +01:00
|
|
|
}
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2023-07-13 20:26:35 +02:00
|
|
|
if !env.IsEnabled() {
|
2023-01-09 23:48:19 +01:00
|
|
|
tui.Error("unable to load environment; did you 'zrok enable'?", nil)
|
2023-01-09 20:16:08 +01:00
|
|
|
}
|
|
|
|
|
2023-07-13 20:26:35 +02:00
|
|
|
zrok, err := env.Client()
|
2022-11-30 19:45:57 +01:00
|
|
|
if err != nil {
|
|
|
|
if !panicInstead {
|
2023-01-09 23:48:19 +01:00
|
|
|
tui.Error("unable to create zrok client", err)
|
2022-11-30 19:45:57 +01:00
|
|
|
}
|
|
|
|
panic(err)
|
|
|
|
}
|
2023-01-09 20:16:08 +01:00
|
|
|
|
2023-07-13 20:26:35 +02:00
|
|
|
auth := httptransport.APIKeyAuth("X-TOKEN", "header", env.Environment().Token)
|
2023-01-04 19:43:37 +01:00
|
|
|
req := share.NewUnshareParams()
|
2022-11-30 19:45:57 +01:00
|
|
|
req.Body = &rest_model_zrok.UnshareRequest{
|
2023-07-13 20:26:35 +02:00
|
|
|
EnvZID: env.Environment().ZitiIdentity,
|
2023-01-04 20:42:58 +01:00
|
|
|
ShrToken: shrToken,
|
2022-11-30 19:45:57 +01:00
|
|
|
Reserved: true,
|
|
|
|
}
|
2023-01-04 19:43:37 +01:00
|
|
|
if _, err := zrok.Share.Unshare(req, auth); err != nil {
|
2022-11-30 20:38:49 +01:00
|
|
|
if !panicInstead {
|
2023-01-09 23:48:19 +01:00
|
|
|
tui.Error("error releasing share", err)
|
2022-11-30 20:38:49 +01:00
|
|
|
}
|
|
|
|
panic(err)
|
2022-11-30 19:45:57 +01:00
|
|
|
}
|
|
|
|
|
2023-01-04 20:42:58 +01:00
|
|
|
logrus.Infof("reserved share '%v' released", shrToken)
|
2022-11-30 19:45:57 +01:00
|
|
|
}
|