From 4e77cf82d35795c221a3ccbc89f8fe226cd17a62 Mon Sep 17 00:00:00 2001 From: Mikhail Klementev Date: Sat, 13 May 2023 12:08:55 +0000 Subject: [PATCH] refactor: use one provider for default cache url --- cache/cache.go | 2 +- cache/cache_test.go | 1 - distro/debian/debian_test.go | 2 -- main.go | 8 ++++++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cache/cache.go b/cache/cache.go index 21dad0a..6c7522f 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -18,7 +18,7 @@ import ( "code.dumpstack.io/tools/out-of-tree/config" ) -var URL string +var URL = "https://out-of-tree.fra1.digitaloceanspaces.com/1.0.0/" func unpackTar(archive, destination string) (err error) { // NOTE: If you're change anything in tar command please check also diff --git a/cache/cache_test.go b/cache/cache_test.go index be11fbd..8c7b326 100644 --- a/cache/cache_test.go +++ b/cache/cache_test.go @@ -17,7 +17,6 @@ func TestDownloadQemuImage(t *testing.T) { } defer os.RemoveAll(tmp) - URL = "https://out-of-tree.fra1.digitaloceanspaces.com/1.0.0/" file := "out_of_tree_ubuntu_12__04.img" err = DownloadQemuImage(tmp, file) diff --git a/distro/debian/debian_test.go b/distro/debian/debian_test.go index 49fb735..4d6bd0e 100644 --- a/distro/debian/debian_test.go +++ b/distro/debian/debian_test.go @@ -3,12 +3,10 @@ package debian import ( "testing" - "code.dumpstack.io/tools/out-of-tree/cache" "code.dumpstack.io/tools/out-of-tree/config" ) func TestMatchImagePkg(t *testing.T) { - cache.URL = "https://out-of-tree.fra1.digitaloceanspaces.com/1.0.0/" t.Log("tested with cache by default") km := config.KernelMask{ diff --git a/main.go b/main.go index 08b0eb6..705be50 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ import ( "fmt" "io" "math/rand" + "net/url" "os" "os/exec" "os/user" @@ -33,7 +34,7 @@ type Globals struct { WorkDir string `help:"path to work directory" default:"./" type:"path"` - CacheURL string `default:"https://out-of-tree.fra1.digitaloceanspaces.com/1.0.0/" hidden:""` + CacheURL url.URL } type CLI struct { @@ -190,7 +191,10 @@ func main() { } container.Runtime = cli.ContainerRuntime - cache.URL = cli.Globals.CacheURL + if cli.Globals.CacheURL.String() != "" { + cache.URL = cli.Globals.CacheURL.String() + } + log.Debug().Msgf("set cache url to %s", cache.URL) err = ctx.Run(&cli.Globals) ctx.FatalIfErrorf(err)