From 63ef223adaaaf39be888ce6a6a99dcdf67ead193 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Fri, 12 Jan 2024 13:11:11 -0500 Subject: [PATCH] missing access (#438) --- cmd/zrok/ls.go | 14 ++++++++++++++ cmd/zrok/md.go | 14 ++++++++++++++ cmd/zrok/mv.go | 14 ++++++++++++++ cmd/zrok/rm.go | 14 ++++++++++++++ 4 files changed, 56 insertions(+) diff --git a/cmd/zrok/ls.go b/cmd/zrok/ls.go index 3649f5d0..b76ab8e5 100644 --- a/cmd/zrok/ls.go +++ b/cmd/zrok/ls.go @@ -5,8 +5,10 @@ import ( "github.com/jedib0t/go-pretty/v6/table" "github.com/openziti/zrok/drives/sync" "github.com/openziti/zrok/environment" + "github.com/openziti/zrok/sdk/golang/sdk" "github.com/openziti/zrok/tui" "github.com/openziti/zrok/util" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" "net/url" "os" @@ -53,6 +55,18 @@ func (cmd *lsCommand) run(_ *cobra.Command, args []string) { tui.Error("error loading root", err) } + if targetUrl.Scheme == "zrok" { + access, err := sdk.CreateAccess(root, &sdk.AccessRequest{ShareToken: targetUrl.Host}) + if err != nil { + tui.Error("error creating access", err) + } + defer func() { + if err := sdk.DeleteAccess(root, access); err != nil { + logrus.Warningf("error freeing access: %v", err) + } + }() + } + target, err := sync.TargetForURL(targetUrl, root, cmd.basicAuth) if err != nil { tui.Error(fmt.Sprintf("error creating target for '%v'", targetUrl), err) diff --git a/cmd/zrok/md.go b/cmd/zrok/md.go index b065650e..02e36c3c 100644 --- a/cmd/zrok/md.go +++ b/cmd/zrok/md.go @@ -4,7 +4,9 @@ import ( "fmt" "github.com/openziti/zrok/drives/sync" "github.com/openziti/zrok/environment" + "github.com/openziti/zrok/sdk/golang/sdk" "github.com/openziti/zrok/tui" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" "net/url" "os" @@ -50,6 +52,18 @@ func (cmd *mdCommand) run(_ *cobra.Command, args []string) { tui.Error("error loading root", err) } + if targetUrl.Scheme == "zrok" { + access, err := sdk.CreateAccess(root, &sdk.AccessRequest{ShareToken: targetUrl.Host}) + if err != nil { + tui.Error("error creating access", err) + } + defer func() { + if err := sdk.DeleteAccess(root, access); err != nil { + logrus.Warningf("error freeing access: %v", err) + } + }() + } + target, err := sync.TargetForURL(targetUrl, root, cmd.basicAuth) if err != nil { tui.Error(fmt.Sprintf("error creating target for '%v'", targetUrl), err) diff --git a/cmd/zrok/mv.go b/cmd/zrok/mv.go index de0f0ecd..963239c2 100644 --- a/cmd/zrok/mv.go +++ b/cmd/zrok/mv.go @@ -4,7 +4,9 @@ import ( "fmt" "github.com/openziti/zrok/drives/sync" "github.com/openziti/zrok/environment" + "github.com/openziti/zrok/sdk/golang/sdk" "github.com/openziti/zrok/tui" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" "net/url" "os" @@ -50,6 +52,18 @@ func (cmd *mvCommand) run(_ *cobra.Command, args []string) { tui.Error("error loading root", err) } + if targetUrl.Scheme == "zrok" { + access, err := sdk.CreateAccess(root, &sdk.AccessRequest{ShareToken: targetUrl.Host}) + if err != nil { + tui.Error("error creating access", err) + } + defer func() { + if err := sdk.DeleteAccess(root, access); err != nil { + logrus.Warningf("error freeing access: %v", err) + } + }() + } + target, err := sync.TargetForURL(targetUrl, root, cmd.basicAuth) if err != nil { tui.Error(fmt.Sprintf("error creating target for '%v'", targetUrl), err) diff --git a/cmd/zrok/rm.go b/cmd/zrok/rm.go index 6f018ef9..25d4d5b8 100644 --- a/cmd/zrok/rm.go +++ b/cmd/zrok/rm.go @@ -4,7 +4,9 @@ import ( "fmt" "github.com/openziti/zrok/drives/sync" "github.com/openziti/zrok/environment" + "github.com/openziti/zrok/sdk/golang/sdk" "github.com/openziti/zrok/tui" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" "net/url" "os" @@ -50,6 +52,18 @@ func (cmd *rmCommand) run(_ *cobra.Command, args []string) { tui.Error("error loading root", err) } + if targetUrl.Scheme == "zrok" { + access, err := sdk.CreateAccess(root, &sdk.AccessRequest{ShareToken: targetUrl.Host}) + if err != nil { + tui.Error("error creating access", err) + } + defer func() { + if err := sdk.DeleteAccess(root, access); err != nil { + logrus.Warningf("error freeing access: %v", err) + } + }() + } + target, err := sync.TargetForURL(targetUrl, root, cmd.basicAuth) if err != nil { tui.Error(fmt.Sprintf("error creating target for '%v'", targetUrl), err)