diff --git a/.github/actions/golang/action.yaml b/.github/actions/golang/action.yaml index 6af2b62065..890c4bb3cd 100644 --- a/.github/actions/golang/action.yaml +++ b/.github/actions/golang/action.yaml @@ -6,5 +6,5 @@ runs: steps: - uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 with: - go-version: 1.21.x + go-version-file: 'go.mod' cache: true diff --git a/go.mod b/go.mod index f3df371a78..f5f78a9c2c 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/defenseunicorns/zarf -go 1.21.6 +go 1.21.8 // TODO (@AABRO): Pending merge into github.com/gojsonschema/gojsonschema (https://github.com/gojsonschema/gojsonschema/pull/5) replace github.com/xeipuuv/gojsonschema => github.com/defenseunicorns/gojsonschema v0.0.0-20231116163348-e00f069122d6 @@ -14,6 +14,7 @@ require ( github.com/anchore/clio v0.0.0-20240301210832-abcb7197da84 github.com/anchore/stereoscope v0.0.1 github.com/anchore/syft v0.100.0 + github.com/defenseunicorns/pkg/helpers v0.0.2 github.com/derailed/k9s v0.31.7 github.com/distribution/reference v0.5.0 github.com/docker/cli v24.0.9+incompatible @@ -29,8 +30,7 @@ require ( github.com/gosuri/uitable v0.0.4 github.com/mholt/archiver/v3 v3.5.1 github.com/moby/moby v24.0.9+incompatible - github.com/opencontainers/image-spec v1.1.0-rc6 - github.com/otiai10/copy v1.14.0 + github.com/opencontainers/image-spec v1.1.0 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.18.0 github.com/pterm/pterm v0.12.78 @@ -55,7 +55,7 @@ require ( k8s.io/component-base v0.29.1 k8s.io/klog/v2 v2.120.1 k8s.io/kubectl v0.29.1 - oras.land/oras-go/v2 v2.4.0 + oras.land/oras-go/v2 v2.5.0 sigs.k8s.io/kustomize/api v0.16.0 sigs.k8s.io/kustomize/kyaml v0.16.0 sigs.k8s.io/yaml v1.4.0 @@ -199,7 +199,7 @@ require ( github.com/digitorus/timestamp v0.0.0-20231217203849-220c5c2851b7 // indirect github.com/dimchansky/utfbom v1.1.1 // indirect github.com/docker/distribution v2.8.3+incompatible // indirect - github.com/docker/docker v24.0.7+incompatible // indirect + github.com/docker/docker v24.0.9+incompatible // indirect github.com/docker/docker-credential-helpers v0.8.0 // indirect github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c // indirect @@ -372,6 +372,7 @@ require ( github.com/opencontainers/selinux v1.11.0 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect github.com/openvex/go-vex v0.2.5 // indirect + github.com/otiai10/copy v1.14.0 // indirect github.com/owenrumney/go-sarif v1.1.2-0.20231003122901-1000f5e05554 // indirect github.com/package-url/packageurl-go v0.1.1 // indirect github.com/pborman/indent v1.2.1 // indirect diff --git a/go.sum b/go.sum index 66624c76ab..9d0186ef86 100644 --- a/go.sum +++ b/go.sum @@ -592,6 +592,8 @@ github.com/daviddengcn/go-colortext v1.0.0 h1:ANqDyC0ys6qCSvuEK7l3g5RaehL/Xck9EX github.com/daviddengcn/go-colortext v1.0.0/go.mod h1:zDqEI5NVUop5QPpVJUxE9UO10hRnmkD5G4Pmri9+m4c= github.com/defenseunicorns/gojsonschema v0.0.0-20231116163348-e00f069122d6 h1:gwevOZ0fxT2nzM9hrtdPbsiOHjFqDRIYMzJHba3/G6Q= github.com/defenseunicorns/gojsonschema v0.0.0-20231116163348-e00f069122d6/go.mod h1:StKLYMmPj1R5yIs6CK49EkcW1TvUYuw5Vri+LRk7Dy8= +github.com/defenseunicorns/pkg/helpers v0.0.2 h1:Axfk96vWkYQpya7E/JkghzwITu2F4GocpGm+mqEVcEg= +github.com/defenseunicorns/pkg/helpers v0.0.2/go.mod h1:F4S5VZLDrlNWQKklzv4v9tFWjjZNhxJ1gT79j4XiLwk= github.com/deitch/magic v0.0.0-20230404182410-1ff89d7342da h1:ZOjWpVsFZ06eIhnh4mkaceTiVoktdU67+M7KDHJ268M= github.com/deitch/magic v0.0.0-20230404182410-1ff89d7342da/go.mod h1:B3tI9iGHi4imdLi4Asdha1Sc6feLMTfPLXh9IUYmysk= github.com/depcheck-test/depcheck-test v0.0.0-20220607135614-199033aaa936 h1:foGzavPWwtoyBvjWyKJYDYsyzy+23iBV7NKTwdk+LRY= @@ -628,8 +630,8 @@ github.com/docker/cli v24.0.9+incompatible h1:OxbimnP/z+qVjDLpq9wbeFU3Nc30XhSe+L github.com/docker/cli v24.0.9+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8= github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk= github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= -github.com/docker/docker v24.0.7+incompatible h1:Wo6l37AuwP3JaMnZa226lzVXGA3F9Ig1seQen0cKYlM= -github.com/docker/docker v24.0.7+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/docker v24.0.9+incompatible h1:HPGzNmwfLZWdxHqK9/II92pyi1EpYKsAqcl4G0Of9v0= +github.com/docker/docker v24.0.9+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/docker-credential-helpers v0.8.0 h1:YQFtbBQb4VrpoPxhFuzEBPQ9E16qz5SpHLS+uswaCp8= github.com/docker/docker-credential-helpers v0.8.0/go.mod h1:UGFXcuoQ5TxPiB54nHOZ32AWRqQdECoh/Mg0AlEYb40= github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= @@ -1353,8 +1355,8 @@ github.com/open-policy-agent/opa v0.61.0 h1:nhncQ2CAYtQTV/SMBhDDPsCpCQsUW+zO/1j+ github.com/open-policy-agent/opa v0.61.0/go.mod h1:7OUuzJnsS9yHf8lw0ApfcbrnaRG1EkN3J2fuuqi4G/E= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= -github.com/opencontainers/image-spec v1.1.0-rc6 h1:XDqvyKsJEbRtATzkgItUqBA7QHk58yxX1Ov9HERHNqU= -github.com/opencontainers/image-spec v1.1.0-rc6/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM= +github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug= +github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM= github.com/opencontainers/runtime-spec v1.1.0 h1:HHUyrt9mwHUjtasSbXSMvs4cyFxh+Bll4AjJ9odEGpg= github.com/opencontainers/runtime-spec v1.1.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= github.com/opencontainers/selinux v1.11.0 h1:+5Zbo97w3Lbmb3PeqQtpmTkMwsW5nRI3YaLpt7tQ7oU= @@ -2449,8 +2451,8 @@ modernc.org/sqlite v1.28.0 h1:Zx+LyDDmXczNnEQdvPuEfcFVA2ZPyaD7UCZDjef3BHQ= modernc.org/sqlite v1.28.0/go.mod h1:Qxpazz0zH8Z1xCFyi5GSL3FzbtZ3fvbjmywNogldEW0= oras.land/oras-go v1.2.4 h1:djpBY2/2Cs1PV87GSJlxv4voajVOMZxqqtq9AB8YNvY= oras.land/oras-go v1.2.4/go.mod h1:DYcGfb3YF1nKjcezfX2SNlDAeQFKSXmf+qrFmrh4324= -oras.land/oras-go/v2 v2.4.0 h1:i+Wt5oCaMHu99guBD0yuBjdLvX7Lz8ukPbwXdR7uBMs= -oras.land/oras-go/v2 v2.4.0/go.mod h1:osvtg0/ClRq1KkydMAEu/IxFieyjItcsQ4ut4PPF+f8= +oras.land/oras-go/v2 v2.5.0 h1:o8Me9kLY74Vp5uw07QXPiitjsw7qNXi8Twd+19Zf02c= +oras.land/oras-go/v2 v2.5.0/go.mod h1:z4eisnLP530vwIOUOJeBIj0aGI0L1C3d53atvCBqZHg= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/src/cmd/destroy.go b/src/cmd/destroy.go index b0825af632..bc9dbe7d61 100644 --- a/src/cmd/destroy.go +++ b/src/cmd/destroy.go @@ -9,13 +9,13 @@ import ( "os" "regexp" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/config/lang" "github.com/defenseunicorns/zarf/src/internal/packager/helm" "github.com/defenseunicorns/zarf/src/pkg/cluster" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/utils/exec" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/spf13/cobra" ) diff --git a/src/cmd/dev.go b/src/cmd/dev.go index 9bc12a2b1c..92a46e3bcf 100644 --- a/src/cmd/dev.go +++ b/src/cmd/dev.go @@ -12,6 +12,7 @@ import ( "strings" "github.com/AlecAivazis/survey/v2" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/cmd/common" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/config/lang" @@ -20,7 +21,6 @@ import ( "github.com/defenseunicorns/zarf/src/pkg/packager/lint" "github.com/defenseunicorns/zarf/src/pkg/transform" "github.com/defenseunicorns/zarf/src/pkg/utils" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" "github.com/mholt/archiver/v3" "github.com/spf13/cobra" diff --git a/src/cmd/initialize.go b/src/cmd/initialize.go index db3f790466..cdb6ad05f6 100644 --- a/src/cmd/initialize.go +++ b/src/cmd/initialize.go @@ -13,6 +13,7 @@ import ( "strings" "github.com/AlecAivazis/survey/v2" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/cmd/common" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/config/lang" @@ -21,7 +22,6 @@ import ( "github.com/defenseunicorns/zarf/src/pkg/packager" "github.com/defenseunicorns/zarf/src/pkg/packager/sources" "github.com/defenseunicorns/zarf/src/pkg/utils" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/pkg/zoci" "github.com/defenseunicorns/zarf/src/types" diff --git a/src/cmd/internal.go b/src/cmd/internal.go index 68e512d1c6..213385e8e3 100644 --- a/src/cmd/internal.go +++ b/src/cmd/internal.go @@ -10,13 +10,13 @@ import ( "os" "github.com/alecthomas/jsonschema" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/cmd/common" "github.com/defenseunicorns/zarf/src/config/lang" "github.com/defenseunicorns/zarf/src/internal/agent" "github.com/defenseunicorns/zarf/src/internal/packager/git" "github.com/defenseunicorns/zarf/src/pkg/cluster" "github.com/defenseunicorns/zarf/src/pkg/message" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" "github.com/spf13/cobra" "github.com/spf13/cobra/doc" diff --git a/src/cmd/package.go b/src/cmd/package.go index b113c94e67..e3fb00b48a 100644 --- a/src/cmd/package.go +++ b/src/cmd/package.go @@ -19,10 +19,10 @@ import ( "oras.land/oras-go/v2/registry" "github.com/AlecAivazis/survey/v2" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/pkg/cluster" "github.com/defenseunicorns/zarf/src/pkg/packager" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/spf13/cobra" "github.com/spf13/viper" ) diff --git a/src/cmd/tools/helm/repo_add.go b/src/cmd/tools/helm/repo_add.go index c8c0be61d0..d053689000 100644 --- a/src/cmd/tools/helm/repo_add.go +++ b/src/cmd/tools/helm/repo_add.go @@ -30,7 +30,7 @@ import ( "strings" "time" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" + "github.com/defenseunicorns/pkg/helpers" "github.com/gofrs/flock" "github.com/pkg/errors" "github.com/spf13/cobra" diff --git a/src/cmd/tools/helm/repo_index.go b/src/cmd/tools/helm/repo_index.go index f1199746ab..a84a3af74c 100644 --- a/src/cmd/tools/helm/repo_index.go +++ b/src/cmd/tools/helm/repo_index.go @@ -26,7 +26,7 @@ import ( "os" "path/filepath" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" + "github.com/defenseunicorns/pkg/helpers" "github.com/pkg/errors" "github.com/spf13/cobra" diff --git a/src/cmd/tools/helm/repo_remove.go b/src/cmd/tools/helm/repo_remove.go index a4c350a232..00f5cd45d4 100644 --- a/src/cmd/tools/helm/repo_remove.go +++ b/src/cmd/tools/helm/repo_remove.go @@ -27,7 +27,7 @@ import ( "os" "path/filepath" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" + "github.com/defenseunicorns/pkg/helpers" "github.com/pkg/errors" "github.com/spf13/cobra" diff --git a/src/cmd/tools/zarf.go b/src/cmd/tools/zarf.go index 5f8da77706..7cec63379d 100644 --- a/src/cmd/tools/zarf.go +++ b/src/cmd/tools/zarf.go @@ -11,6 +11,7 @@ import ( "slices" "github.com/AlecAivazis/survey/v2" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/cmd/common" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/config/lang" @@ -21,7 +22,6 @@ import ( "github.com/defenseunicorns/zarf/src/pkg/oci" "github.com/defenseunicorns/zarf/src/pkg/packager/sources" "github.com/defenseunicorns/zarf/src/pkg/pki" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/pkg/zoci" "github.com/defenseunicorns/zarf/src/types" "github.com/sigstore/cosign/v2/pkg/cosign" diff --git a/src/extensions/bigbang/bigbang.go b/src/extensions/bigbang/bigbang.go index 50da7a9fe4..9445354046 100644 --- a/src/extensions/bigbang/bigbang.go +++ b/src/extensions/bigbang/bigbang.go @@ -13,11 +13,11 @@ import ( "time" "github.com/Masterminds/semver/v3" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/internal/packager/helm" "github.com/defenseunicorns/zarf/src/pkg/layout" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/utils" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" "github.com/defenseunicorns/zarf/src/types/extensions" fluxHelmCtrl "github.com/fluxcd/helm-controller/api/v2beta1" diff --git a/src/extensions/bigbang/flux.go b/src/extensions/bigbang/flux.go index 8189eae591..6b7f8ebc6e 100644 --- a/src/extensions/bigbang/flux.go +++ b/src/extensions/bigbang/flux.go @@ -10,9 +10,9 @@ import ( "path" "path/filepath" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/internal/packager/kustomize" "github.com/defenseunicorns/zarf/src/pkg/utils" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" "github.com/defenseunicorns/zarf/src/types/extensions" fluxHelmCtrl "github.com/fluxcd/helm-controller/api/v2beta1" diff --git a/src/internal/agent/hooks/argocd-application.go b/src/internal/agent/hooks/argocd-application.go index 2f4d4b6dc0..260b1d53a3 100644 --- a/src/internal/agent/hooks/argocd-application.go +++ b/src/internal/agent/hooks/argocd-application.go @@ -8,12 +8,12 @@ import ( "encoding/json" "fmt" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config/lang" "github.com/defenseunicorns/zarf/src/internal/agent/operations" "github.com/defenseunicorns/zarf/src/internal/agent/state" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/transform" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" v1 "k8s.io/api/admission/v1" ) diff --git a/src/internal/agent/hooks/argocd-repository.go b/src/internal/agent/hooks/argocd-repository.go index 4e4c0c5ef3..a9b74cd72f 100644 --- a/src/internal/agent/hooks/argocd-repository.go +++ b/src/internal/agent/hooks/argocd-repository.go @@ -9,12 +9,12 @@ import ( "encoding/json" "fmt" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config/lang" "github.com/defenseunicorns/zarf/src/internal/agent/operations" "github.com/defenseunicorns/zarf/src/internal/agent/state" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/transform" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" v1 "k8s.io/api/admission/v1" ) diff --git a/src/internal/agent/hooks/flux.go b/src/internal/agent/hooks/flux.go index 2594524238..c4efce1846 100644 --- a/src/internal/agent/hooks/flux.go +++ b/src/internal/agent/hooks/flux.go @@ -8,13 +8,13 @@ import ( "encoding/json" "fmt" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/config/lang" "github.com/defenseunicorns/zarf/src/internal/agent/operations" "github.com/defenseunicorns/zarf/src/internal/agent/state" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/transform" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" v1 "k8s.io/api/admission/v1" ) diff --git a/src/internal/packager/helm/chart.go b/src/internal/packager/helm/chart.go index 8aa353f949..0e10c0ef99 100644 --- a/src/internal/packager/helm/chart.go +++ b/src/internal/packager/helm/chart.go @@ -9,7 +9,7 @@ import ( "fmt" "time" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" + "github.com/defenseunicorns/pkg/helpers" "github.com/Masterminds/semver/v3" "github.com/defenseunicorns/zarf/src/config" diff --git a/src/internal/packager/helm/images.go b/src/internal/packager/helm/images.go index 9991582c94..14c3c65e07 100644 --- a/src/internal/packager/helm/images.go +++ b/src/internal/packager/helm/images.go @@ -1,8 +1,8 @@ package helm import ( + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/pkg/message" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/goccy/go-yaml" "helm.sh/helm/v3/pkg/chart/loader" "helm.sh/helm/v3/pkg/chartutil" diff --git a/src/internal/packager/helm/post-render.go b/src/internal/packager/helm/post-render.go index 7e9561ee3b..ed3dec5d9f 100644 --- a/src/internal/packager/helm/post-render.go +++ b/src/internal/packager/helm/post-render.go @@ -11,11 +11,11 @@ import ( "path/filepath" "reflect" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/internal/packager/template" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/utils" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" "helm.sh/helm/v3/pkg/releaseutil" corev1 "k8s.io/api/core/v1" diff --git a/src/internal/packager/helm/repo.go b/src/internal/packager/helm/repo.go index 459c6a3bd2..d91349a5c6 100644 --- a/src/internal/packager/helm/repo.go +++ b/src/internal/packager/helm/repo.go @@ -10,13 +10,13 @@ import ( "path/filepath" "strings" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/config/lang" "github.com/defenseunicorns/zarf/src/internal/packager/git" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/transform" "github.com/defenseunicorns/zarf/src/pkg/utils" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" "helm.sh/helm/v3/pkg/action" "helm.sh/helm/v3/pkg/chart" diff --git a/src/internal/packager/helm/utils.go b/src/internal/packager/helm/utils.go index 3a6b789330..2f3b11035a 100644 --- a/src/internal/packager/helm/utils.go +++ b/src/internal/packager/helm/utils.go @@ -7,8 +7,8 @@ package helm import ( "fmt" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/pkg/message" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "helm.sh/helm/v3/pkg/action" "helm.sh/helm/v3/pkg/chart" "helm.sh/helm/v3/pkg/chartutil" diff --git a/src/internal/packager/images/pull.go b/src/internal/packager/images/pull.go index 8f38a27964..de5ab03ff2 100644 --- a/src/internal/packager/images/pull.go +++ b/src/internal/packager/images/pull.go @@ -13,12 +13,12 @@ import ( "path/filepath" "strings" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/pkg/layout" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/transform" "github.com/defenseunicorns/zarf/src/pkg/utils" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/google/go-containerregistry/pkg/crane" "github.com/google/go-containerregistry/pkg/logs" "github.com/google/go-containerregistry/pkg/name" diff --git a/src/internal/packager/images/push.go b/src/internal/packager/images/push.go index 8ff33b1b8c..5daff0a14f 100644 --- a/src/internal/packager/images/push.go +++ b/src/internal/packager/images/push.go @@ -9,13 +9,13 @@ import ( "net/http" "time" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/pkg/cluster" "github.com/defenseunicorns/zarf/src/pkg/k8s" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/transform" "github.com/defenseunicorns/zarf/src/pkg/utils" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/google/go-containerregistry/pkg/crane" "github.com/google/go-containerregistry/pkg/logs" v1 "github.com/google/go-containerregistry/pkg/v1" diff --git a/src/internal/packager/kustomize/build.go b/src/internal/packager/kustomize/build.go index 8c045fe45c..29f05281e0 100644 --- a/src/internal/packager/kustomize/build.go +++ b/src/internal/packager/kustomize/build.go @@ -8,7 +8,7 @@ import ( "fmt" "os" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" + "github.com/defenseunicorns/pkg/helpers" "sigs.k8s.io/kustomize/api/krusty" krustytypes "sigs.k8s.io/kustomize/api/types" "sigs.k8s.io/kustomize/kyaml/filesys" diff --git a/src/internal/packager/sbom/catalog.go b/src/internal/packager/sbom/catalog.go index a2a6618622..3fba53bb2d 100755 --- a/src/internal/packager/sbom/catalog.go +++ b/src/internal/packager/sbom/catalog.go @@ -23,12 +23,12 @@ import ( "github.com/anchore/syft/syft/pkg/cataloger" "github.com/anchore/syft/syft/sbom" "github.com/anchore/syft/syft/source" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/pkg/layout" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/transform" "github.com/defenseunicorns/zarf/src/pkg/utils" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" v1 "github.com/google/go-containerregistry/pkg/v1" ) diff --git a/src/internal/packager/template/template.go b/src/internal/packager/template/template.go index f7e669ef58..19eed3e93c 100644 --- a/src/internal/packager/template/template.go +++ b/src/internal/packager/template/template.go @@ -14,10 +14,10 @@ import ( "github.com/defenseunicorns/zarf/src/types" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/utils" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" ) // TextTemplate represents a value to be templated into a text file. diff --git a/src/internal/packager/template/yaml.go b/src/internal/packager/template/yaml.go index 07fe500b38..47c2db56f1 100644 --- a/src/internal/packager/template/yaml.go +++ b/src/internal/packager/template/yaml.go @@ -7,7 +7,7 @@ package template import ( "regexp" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/types" ) diff --git a/src/internal/packager/validate/validate.go b/src/internal/packager/validate/validate.go index fe5577901f..83eba2dd07 100644 --- a/src/internal/packager/validate/validate.go +++ b/src/internal/packager/validate/validate.go @@ -10,9 +10,9 @@ import ( "regexp" "slices" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/config/lang" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" ) diff --git a/src/pkg/cluster/data.go b/src/pkg/cluster/data.go index ec78cd2768..d2724c0d1f 100644 --- a/src/pkg/cluster/data.go +++ b/src/pkg/cluster/data.go @@ -12,13 +12,13 @@ import ( "strings" "sync" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/pkg/k8s" "github.com/defenseunicorns/zarf/src/pkg/layout" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/utils" "github.com/defenseunicorns/zarf/src/pkg/utils/exec" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" corev1 "k8s.io/api/core/v1" ) diff --git a/src/pkg/cluster/injector.go b/src/pkg/cluster/injector.go index b35f2f7f02..7403c567aa 100644 --- a/src/pkg/cluster/injector.go +++ b/src/pkg/cluster/injector.go @@ -12,13 +12,13 @@ import ( "regexp" "time" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/pkg/k8s" "github.com/defenseunicorns/zarf/src/pkg/layout" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/transform" "github.com/defenseunicorns/zarf/src/pkg/utils" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/google/go-containerregistry/pkg/crane" "github.com/mholt/archiver/v3" corev1 "k8s.io/api/core/v1" diff --git a/src/pkg/cluster/state.go b/src/pkg/cluster/state.go index d9f7aee483..ebac18fbd3 100644 --- a/src/pkg/cluster/state.go +++ b/src/pkg/cluster/state.go @@ -16,10 +16,10 @@ import ( "github.com/defenseunicorns/zarf/src/types" "github.com/fatih/color" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/pkg/k8s" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/pki" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) diff --git a/src/pkg/k8s/configmap.go b/src/pkg/k8s/configmap.go index ca2f3e0188..626b8b30b5 100644 --- a/src/pkg/k8s/configmap.go +++ b/src/pkg/k8s/configmap.go @@ -8,7 +8,7 @@ import ( "context" "fmt" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" + "github.com/defenseunicorns/pkg/helpers" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/src/pkg/k8s/namespace.go b/src/pkg/k8s/namespace.go index 2a0e8baddb..25d9abdf01 100644 --- a/src/pkg/k8s/namespace.go +++ b/src/pkg/k8s/namespace.go @@ -9,7 +9,7 @@ import ( "time" "cuelang.org/go/pkg/strings" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" + "github.com/defenseunicorns/pkg/helpers" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/src/pkg/k8s/pods.go b/src/pkg/k8s/pods.go index e4853034e0..6d0a1e2121 100644 --- a/src/pkg/k8s/pods.go +++ b/src/pkg/k8s/pods.go @@ -9,7 +9,7 @@ import ( "sort" "time" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" + "github.com/defenseunicorns/pkg/helpers" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/src/pkg/k8s/secrets.go b/src/pkg/k8s/secrets.go index 0019b0745d..30965caa0c 100644 --- a/src/pkg/k8s/secrets.go +++ b/src/pkg/k8s/secrets.go @@ -9,7 +9,7 @@ import ( "crypto/tls" "fmt" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" + "github.com/defenseunicorns/pkg/helpers" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/src/pkg/k8s/services.go b/src/pkg/k8s/services.go index 929ba88830..9b14f9a0d3 100644 --- a/src/pkg/k8s/services.go +++ b/src/pkg/k8s/services.go @@ -11,7 +11,7 @@ import ( "regexp" "strconv" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" + "github.com/defenseunicorns/pkg/helpers" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) diff --git a/src/pkg/k8s/tunnel.go b/src/pkg/k8s/tunnel.go index 116db22ab7..a4b910fccf 100644 --- a/src/pkg/k8s/tunnel.go +++ b/src/pkg/k8s/tunnel.go @@ -13,7 +13,7 @@ import ( "sync" "time" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" + "github.com/defenseunicorns/pkg/helpers" "k8s.io/client-go/tools/portforward" "k8s.io/client-go/transport/spdy" ) diff --git a/src/pkg/layout/component.go b/src/pkg/layout/component.go index 383c8c48c3..e8da0de72a 100644 --- a/src/pkg/layout/component.go +++ b/src/pkg/layout/component.go @@ -10,8 +10,8 @@ import ( "os" "path/filepath" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/pkg/message" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" "github.com/mholt/archiver/v3" ) diff --git a/src/pkg/layout/package.go b/src/pkg/layout/package.go index f04bf5c0d9..3949f4fcc2 100644 --- a/src/pkg/layout/package.go +++ b/src/pkg/layout/package.go @@ -12,11 +12,11 @@ import ( "strings" "github.com/Masterminds/semver/v3" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/pkg/interactive" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/packager/deprecated" "github.com/defenseunicorns/zarf/src/pkg/utils" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" "github.com/google/go-containerregistry/pkg/crane" "github.com/mholt/archiver/v3" diff --git a/src/pkg/layout/sbom.go b/src/pkg/layout/sbom.go index 7ea416317c..8cfaaae6a0 100644 --- a/src/pkg/layout/sbom.go +++ b/src/pkg/layout/sbom.go @@ -10,7 +10,7 @@ import ( "os" "path/filepath" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" + "github.com/defenseunicorns/pkg/helpers" "github.com/mholt/archiver/v3" ) diff --git a/src/pkg/oci/common.go b/src/pkg/oci/common.go index dacfa2d2db..e097427b53 100644 --- a/src/pkg/oci/common.go +++ b/src/pkg/oci/common.go @@ -10,7 +10,7 @@ import ( "net/http" "strings" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" + "github.com/defenseunicorns/pkg/helpers" "github.com/docker/cli/cli/config" "github.com/docker/cli/cli/config/configfile" ocispec "github.com/opencontainers/image-spec/specs-go/v1" diff --git a/src/pkg/oci/copier.go b/src/pkg/oci/copier.go index 99545449ae..6f2578f700 100644 --- a/src/pkg/oci/copier.go +++ b/src/pkg/oci/copier.go @@ -11,7 +11,7 @@ import ( "io" "time" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" + "github.com/defenseunicorns/pkg/helpers" ocispec "github.com/opencontainers/image-spec/specs-go/v1" "golang.org/x/sync/errgroup" "golang.org/x/sync/semaphore" diff --git a/src/pkg/oci/manifest.go b/src/pkg/oci/manifest.go index 6da4f6afff..b2d9b8865a 100644 --- a/src/pkg/oci/manifest.go +++ b/src/pkg/oci/manifest.go @@ -8,7 +8,7 @@ import ( "encoding/json" "path/filepath" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" + "github.com/defenseunicorns/pkg/helpers" ocispec "github.com/opencontainers/image-spec/specs-go/v1" ) diff --git a/src/pkg/oci/progress.go b/src/pkg/oci/progress.go index d245831ec4..e377bd6e13 100644 --- a/src/pkg/oci/progress.go +++ b/src/pkg/oci/progress.go @@ -8,7 +8,7 @@ import ( "context" "fmt" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" + "github.com/defenseunicorns/pkg/helpers" ocispec "github.com/opencontainers/image-spec/specs-go/v1" ) diff --git a/src/pkg/oci/pull.go b/src/pkg/oci/pull.go index e47f4711f0..fba8cdbbc1 100644 --- a/src/pkg/oci/pull.go +++ b/src/pkg/oci/pull.go @@ -10,7 +10,7 @@ import ( "os" "path/filepath" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" + "github.com/defenseunicorns/pkg/helpers" ocispec "github.com/opencontainers/image-spec/specs-go/v1" "oras.land/oras-go/v2" ) diff --git a/src/pkg/packager/actions/actions.go b/src/pkg/packager/actions/actions.go index 2b3019b4cf..372feeb39e 100644 --- a/src/pkg/packager/actions/actions.go +++ b/src/pkg/packager/actions/actions.go @@ -12,11 +12,11 @@ import ( "strings" "time" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/internal/packager/template" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/utils" "github.com/defenseunicorns/zarf/src/pkg/utils/exec" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" ) diff --git a/src/pkg/packager/composer/list.go b/src/pkg/packager/composer/list.go index 3b2e6cda94..6b290203ea 100644 --- a/src/pkg/packager/composer/list.go +++ b/src/pkg/packager/composer/list.go @@ -10,11 +10,11 @@ import ( "path/filepath" "strings" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/internal/packager/validate" "github.com/defenseunicorns/zarf/src/pkg/layout" "github.com/defenseunicorns/zarf/src/pkg/packager/deprecated" "github.com/defenseunicorns/zarf/src/pkg/utils" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/pkg/zoci" "github.com/defenseunicorns/zarf/src/types" ) diff --git a/src/pkg/packager/composer/oci.go b/src/pkg/packager/composer/oci.go index d8e136a9f5..4dedc47c50 100644 --- a/src/pkg/packager/composer/oci.go +++ b/src/pkg/packager/composer/oci.go @@ -11,12 +11,12 @@ import ( "os" "path/filepath" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/pkg/layout" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/oci" "github.com/defenseunicorns/zarf/src/pkg/utils" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/pkg/zoci" "github.com/mholt/archiver/v3" ocispec "github.com/opencontainers/image-spec/specs-go/v1" diff --git a/src/pkg/packager/composer/pathfixer.go b/src/pkg/packager/composer/pathfixer.go index c3f7954fb8..a37dfe47f2 100644 --- a/src/pkg/packager/composer/pathfixer.go +++ b/src/pkg/packager/composer/pathfixer.go @@ -7,7 +7,7 @@ package composer import ( "path/filepath" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/types" ) diff --git a/src/pkg/packager/create.go b/src/pkg/packager/create.go index 5005b4626f..9ef4523fca 100755 --- a/src/pkg/packager/create.go +++ b/src/pkg/packager/create.go @@ -8,12 +8,12 @@ import ( "fmt" "os" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/internal/packager/validate" "github.com/defenseunicorns/zarf/src/pkg/layout" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/packager/creator" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" ) // Create generates a Zarf package tarball for a given PackageConfig and optional base directory. diff --git a/src/pkg/packager/creator/normal.go b/src/pkg/packager/creator/normal.go index dad3ebb23a..9581f873ac 100644 --- a/src/pkg/packager/creator/normal.go +++ b/src/pkg/packager/creator/normal.go @@ -14,6 +14,7 @@ import ( "strings" "time" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/config/lang" "github.com/defenseunicorns/zarf/src/extensions/bigbang" @@ -29,7 +30,6 @@ import ( "github.com/defenseunicorns/zarf/src/pkg/packager/sources" "github.com/defenseunicorns/zarf/src/pkg/transform" "github.com/defenseunicorns/zarf/src/pkg/utils" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/pkg/zoci" "github.com/defenseunicorns/zarf/src/types" "github.com/mholt/archiver/v3" diff --git a/src/pkg/packager/creator/skeleton.go b/src/pkg/packager/creator/skeleton.go index faf8487f03..74dc19fd35 100644 --- a/src/pkg/packager/creator/skeleton.go +++ b/src/pkg/packager/creator/skeleton.go @@ -11,6 +11,7 @@ import ( "strconv" "strings" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/config/lang" "github.com/defenseunicorns/zarf/src/extensions/bigbang" @@ -19,7 +20,6 @@ import ( "github.com/defenseunicorns/zarf/src/pkg/layout" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/utils" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/pkg/zoci" "github.com/defenseunicorns/zarf/src/types" "github.com/mholt/archiver/v3" diff --git a/src/pkg/packager/deploy.go b/src/pkg/packager/deploy.go index feb59498ee..7ec050fd4f 100644 --- a/src/pkg/packager/deploy.go +++ b/src/pkg/packager/deploy.go @@ -14,6 +14,7 @@ import ( "sync" "time" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/config/lang" "github.com/defenseunicorns/zarf/src/internal/packager/git" @@ -28,7 +29,6 @@ import ( "github.com/defenseunicorns/zarf/src/pkg/packager/filters" "github.com/defenseunicorns/zarf/src/pkg/packager/variables" "github.com/defenseunicorns/zarf/src/pkg/transform" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" corev1 "k8s.io/api/core/v1" ) diff --git a/src/pkg/packager/dev.go b/src/pkg/packager/dev.go index 6f0992cfca..1679933cfe 100644 --- a/src/pkg/packager/dev.go +++ b/src/pkg/packager/dev.go @@ -9,6 +9,7 @@ import ( "os" "runtime" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/internal/packager/validate" "github.com/defenseunicorns/zarf/src/pkg/layout" @@ -16,7 +17,6 @@ import ( "github.com/defenseunicorns/zarf/src/pkg/packager/creator" "github.com/defenseunicorns/zarf/src/pkg/packager/filters" "github.com/defenseunicorns/zarf/src/pkg/packager/variables" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" ) diff --git a/src/pkg/packager/filters/deploy.go b/src/pkg/packager/filters/deploy.go index 51b4bf074c..d98b9c93f2 100644 --- a/src/pkg/packager/filters/deploy.go +++ b/src/pkg/packager/filters/deploy.go @@ -10,8 +10,8 @@ import ( "strings" "github.com/agnivade/levenshtein" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/pkg/interactive" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" ) diff --git a/src/pkg/packager/filters/deploy_test.go b/src/pkg/packager/filters/deploy_test.go index e8c3ea3fe7..310ed6286b 100644 --- a/src/pkg/packager/filters/deploy_test.go +++ b/src/pkg/packager/filters/deploy_test.go @@ -10,7 +10,7 @@ import ( "strings" "testing" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/types" "github.com/stretchr/testify/require" ) diff --git a/src/pkg/packager/filters/select.go b/src/pkg/packager/filters/select.go index 36ab641636..457643a3c6 100644 --- a/src/pkg/packager/filters/select.go +++ b/src/pkg/packager/filters/select.go @@ -5,7 +5,7 @@ package filters import ( - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/types" ) diff --git a/src/pkg/packager/generate.go b/src/pkg/packager/generate.go index 23535fc0c9..072c1f566b 100644 --- a/src/pkg/packager/generate.go +++ b/src/pkg/packager/generate.go @@ -10,11 +10,11 @@ import ( "path/filepath" "strings" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/internal/packager/validate" "github.com/defenseunicorns/zarf/src/pkg/layout" "github.com/defenseunicorns/zarf/src/pkg/message" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" goyaml "github.com/goccy/go-yaml" ) diff --git a/src/pkg/packager/lint/lint.go b/src/pkg/packager/lint/lint.go index 94e6f21242..9f68150c3b 100644 --- a/src/pkg/packager/lint/lint.go +++ b/src/pkg/packager/lint/lint.go @@ -12,6 +12,7 @@ import ( "regexp" "strings" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/config/lang" "github.com/defenseunicorns/zarf/src/pkg/layout" @@ -19,7 +20,6 @@ import ( "github.com/defenseunicorns/zarf/src/pkg/packager/creator" "github.com/defenseunicorns/zarf/src/pkg/transform" "github.com/defenseunicorns/zarf/src/pkg/utils" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" "github.com/xeipuuv/gojsonschema" ) diff --git a/src/pkg/packager/lint/validator.go b/src/pkg/packager/lint/validator.go index 830ac21ff2..619947c591 100644 --- a/src/pkg/packager/lint/validator.go +++ b/src/pkg/packager/lint/validator.go @@ -8,8 +8,8 @@ import ( "fmt" "path/filepath" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/pkg/message" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" "github.com/fatih/color" ) diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index 0ee4dec22a..96bbe10ac8 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -14,6 +14,7 @@ import ( "github.com/goccy/go-yaml" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/config/lang" "github.com/defenseunicorns/zarf/src/internal/packager/helm" @@ -24,7 +25,6 @@ import ( "github.com/defenseunicorns/zarf/src/pkg/packager/creator" "github.com/defenseunicorns/zarf/src/pkg/packager/variables" "github.com/defenseunicorns/zarf/src/pkg/utils" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" "github.com/google/go-containerregistry/pkg/crane" v1 "k8s.io/api/apps/v1" diff --git a/src/pkg/packager/publish.go b/src/pkg/packager/publish.go index 2f5cd892ce..49e13f5dbd 100644 --- a/src/pkg/packager/publish.go +++ b/src/pkg/packager/publish.go @@ -10,6 +10,7 @@ import ( "os" "strings" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/pkg/layout" "github.com/defenseunicorns/zarf/src/pkg/message" @@ -18,7 +19,6 @@ import ( "github.com/defenseunicorns/zarf/src/pkg/packager/filters" "github.com/defenseunicorns/zarf/src/pkg/packager/sources" "github.com/defenseunicorns/zarf/src/pkg/utils" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/pkg/zoci" "github.com/defenseunicorns/zarf/src/types" ocispec "github.com/opencontainers/image-spec/specs-go/v1" diff --git a/src/pkg/packager/remove.go b/src/pkg/packager/remove.go index 1204ec4f19..122e811b10 100644 --- a/src/pkg/packager/remove.go +++ b/src/pkg/packager/remove.go @@ -12,6 +12,7 @@ import ( "slices" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/internal/packager/helm" "github.com/defenseunicorns/zarf/src/pkg/cluster" @@ -19,7 +20,6 @@ import ( "github.com/defenseunicorns/zarf/src/pkg/packager/actions" "github.com/defenseunicorns/zarf/src/pkg/packager/filters" "github.com/defenseunicorns/zarf/src/pkg/packager/sources" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" "helm.sh/helm/v3/pkg/storage/driver" corev1 "k8s.io/api/core/v1" diff --git a/src/pkg/packager/sources/cluster.go b/src/pkg/packager/sources/cluster.go index daa0d54ad0..1d506c6937 100644 --- a/src/pkg/packager/sources/cluster.go +++ b/src/pkg/packager/sources/cluster.go @@ -7,12 +7,12 @@ package sources import ( "fmt" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/internal/packager/validate" "github.com/defenseunicorns/zarf/src/pkg/cluster" "github.com/defenseunicorns/zarf/src/pkg/layout" "github.com/defenseunicorns/zarf/src/pkg/packager/filters" "github.com/defenseunicorns/zarf/src/pkg/utils" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" ) diff --git a/src/pkg/packager/sources/new.go b/src/pkg/packager/sources/new.go index e77c99dd25..a54b9f388b 100644 --- a/src/pkg/packager/sources/new.go +++ b/src/pkg/packager/sources/new.go @@ -9,12 +9,12 @@ import ( "net/url" "strings" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/pkg/layout" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/oci" "github.com/defenseunicorns/zarf/src/pkg/packager/filters" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/pkg/zoci" "github.com/defenseunicorns/zarf/src/types" ) diff --git a/src/pkg/packager/sources/split.go b/src/pkg/packager/sources/split.go index ad9be2ba5c..fe4e9fbade 100644 --- a/src/pkg/packager/sources/split.go +++ b/src/pkg/packager/sources/split.go @@ -13,10 +13,10 @@ import ( "sort" "strings" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/pkg/layout" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/packager/filters" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" ) diff --git a/src/pkg/packager/sources/tarball.go b/src/pkg/packager/sources/tarball.go index 33a52713ea..55ba0c6b2e 100644 --- a/src/pkg/packager/sources/tarball.go +++ b/src/pkg/packager/sources/tarball.go @@ -12,10 +12,10 @@ import ( "os" "path/filepath" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/pkg/layout" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/packager/filters" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/pkg/zoci" "github.com/defenseunicorns/zarf/src/types" "github.com/mholt/archiver/v3" diff --git a/src/pkg/packager/sources/url.go b/src/pkg/packager/sources/url.go index 4185b7fb97..384be49668 100644 --- a/src/pkg/packager/sources/url.go +++ b/src/pkg/packager/sources/url.go @@ -10,11 +10,11 @@ import ( "path/filepath" "strings" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/pkg/layout" "github.com/defenseunicorns/zarf/src/pkg/packager/filters" "github.com/defenseunicorns/zarf/src/pkg/utils" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" ) diff --git a/src/pkg/packager/sources/utils.go b/src/pkg/packager/sources/utils.go index 0e2bcf9436..280e940930 100644 --- a/src/pkg/packager/sources/utils.go +++ b/src/pkg/packager/sources/utils.go @@ -11,9 +11,9 @@ import ( "path/filepath" "strings" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/pkg/layout" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/pkg/zoci" "github.com/defenseunicorns/zarf/src/types" goyaml "github.com/goccy/go-yaml" diff --git a/src/pkg/packager/sources/validate.go b/src/pkg/packager/sources/validate.go index 6768b22137..cddf34d816 100644 --- a/src/pkg/packager/sources/validate.go +++ b/src/pkg/packager/sources/validate.go @@ -13,11 +13,11 @@ import ( "path/filepath" "strings" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/pkg/layout" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/utils" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" ) var ( diff --git a/src/pkg/pki/pki.go b/src/pkg/pki/pki.go index 818926256c..68373d3f81 100644 --- a/src/pkg/pki/pki.go +++ b/src/pkg/pki/pki.go @@ -14,9 +14,9 @@ import ( "net" "time" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/pkg/k8s" "github.com/defenseunicorns/zarf/src/pkg/message" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" ) // Based off of https://github.com/dmcgowan/quicktls/blob/master/main.go diff --git a/src/pkg/transform/artifact.go b/src/pkg/transform/artifact.go index 0b122c5420..96a295e4c6 100644 --- a/src/pkg/transform/artifact.go +++ b/src/pkg/transform/artifact.go @@ -10,7 +10,7 @@ import ( "regexp" "strings" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" + "github.com/defenseunicorns/pkg/helpers" ) const ( diff --git a/src/pkg/transform/git.go b/src/pkg/transform/git.go index c3b1cb306b..3710579ab2 100644 --- a/src/pkg/transform/git.go +++ b/src/pkg/transform/git.go @@ -9,7 +9,7 @@ import ( "net/url" "regexp" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" + "github.com/defenseunicorns/pkg/helpers" ) // For further explanation: https://regex101.com/r/YxpfhC/5 diff --git a/src/pkg/transform/image.go b/src/pkg/transform/image.go index 7cff153c34..3b5de1d920 100644 --- a/src/pkg/transform/image.go +++ b/src/pkg/transform/image.go @@ -8,7 +8,7 @@ import ( "fmt" "strings" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" + "github.com/defenseunicorns/pkg/helpers" "github.com/distribution/reference" ) diff --git a/src/pkg/utils/bytes.go b/src/pkg/utils/bytes.go index 8c7fdf2316..d5fd24e5c6 100644 --- a/src/pkg/utils/bytes.go +++ b/src/pkg/utils/bytes.go @@ -11,8 +11,8 @@ import ( "strconv" "time" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/pkg/message" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" ) // RoundUp rounds a float64 to the given number of decimal places. diff --git a/src/pkg/utils/cosign.go b/src/pkg/utils/cosign.go index 8a929eecab..5883495fd0 100644 --- a/src/pkg/utils/cosign.go +++ b/src/pkg/utils/cosign.go @@ -12,10 +12,10 @@ import ( "os" "strings" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/config/lang" "github.com/defenseunicorns/zarf/src/pkg/message" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/google/go-containerregistry/pkg/authn" "github.com/google/go-containerregistry/pkg/name" "github.com/google/go-containerregistry/pkg/v1/remote" diff --git a/src/pkg/utils/helpers/concurrency.go b/src/pkg/utils/helpers/concurrency.go deleted file mode 100644 index 9058e4adc4..0000000000 --- a/src/pkg/utils/helpers/concurrency.go +++ /dev/null @@ -1,86 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2021-Present The Zarf Authors -// forked from https://www.socketloop.com/tutorials/golang-byte-format-example - -// Package helpers provides generic helper functions with no external imports -package helpers - -import ( - "context" -) - -// ConcurrencyTools is a struct that contains channels and a context for use in concurrent routines -type ConcurrencyTools[P any, E any] struct { - ProgressChan chan P - ErrorChan chan E - context context.Context - Cancel context.CancelFunc - routineCount int -} - -// NewConcurrencyTools creates a new ConcurrencyTools struct -// -// Length is the number of iterations that will be performed concurrently -func NewConcurrencyTools[P any, E any](length int) *ConcurrencyTools[P, E] { - ctx, cancel := context.WithCancel(context.TODO()) - - progressChan := make(chan P, length) - - errorChan := make(chan E, length) - - concurrencyTools := ConcurrencyTools[P, E]{ - ProgressChan: progressChan, - ErrorChan: errorChan, - context: ctx, - Cancel: cancel, - routineCount: length, - } - - return &concurrencyTools -} - -// IsDone returns true if the context is done. -func (ct *ConcurrencyTools[P, E]) IsDone() bool { - ctx := ct.context - select { - case <-ctx.Done(): - return true - default: - return false - } -} - -// WaitWithProgress waits for all routines to finish -// -// onProgress is a callback function that is called when a routine sends a progress update -// -// onError is a callback function that is called when a routine sends an error -func (ct *ConcurrencyTools[P, E]) WaitWithProgress(onProgress func(P, int), onError func(E) error) error { - for i := 0; i < ct.routineCount; i++ { - select { - case err := <-ct.ErrorChan: - ct.Cancel() - errResult := onError(err) - return errResult - case progress := <-ct.ProgressChan: - onProgress(progress, i) - } - } - return nil -} - -// WaitWithoutProgress waits for all routines to finish without a progress callback -// -// onError is a callback function that is called when a routine sends an error -func (ct *ConcurrencyTools[P, E]) WaitWithoutProgress(onError func(E) error) error { - for i := 0; i < ct.routineCount; i++ { - select { - case err := <-ct.ErrorChan: - ct.Cancel() - errResult := onError(err) - return errResult - case <-ct.ProgressChan: - } - } - return nil -} diff --git a/src/pkg/utils/helpers/files.go b/src/pkg/utils/helpers/files.go deleted file mode 100644 index 673cb8472e..0000000000 --- a/src/pkg/utils/helpers/files.go +++ /dev/null @@ -1,298 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2021-Present The Zarf Authors - -// Package helpers provides generic helper functions with no external imports -package helpers - -import ( - "archive/tar" - "crypto/sha256" - "fmt" - "io" - "io/fs" - "os" - "path/filepath" - "regexp" - "strings" - "time" - - "github.com/otiai10/copy" -) - -const dotCharacter = 46 - -// CreateDirectory creates a directory for the given path and file mode. -func CreateDirectory(path string, mode os.FileMode) error { - if InvalidPath(path) { - return os.MkdirAll(path, mode) - } - return nil -} - -// CreateFile creates an empty file at the given path. -func CreateFile(filepath string) error { - if InvalidPath(filepath) { - f, err := os.Create(filepath) - f.Close() - return err - } - - return nil - -} - -// InvalidPath checks if the given path is valid (if it is a permissions error it is there we just don't have access) -func InvalidPath(path string) bool { - _, err := os.Stat(path) - return !os.IsPermission(err) && err != nil -} - -// ListDirectories returns a list of directories in the given directory. -func ListDirectories(directory string) ([]string, error) { - var directories []string - paths, err := os.ReadDir(directory) - if err != nil { - return directories, fmt.Errorf("unable to load the directory %s: %w", directory, err) - } - - for _, entry := range paths { - if entry.IsDir() { - directories = append(directories, filepath.Join(directory, entry.Name())) - } - } - - return directories, nil -} - -// RecursiveFileList walks a path with an optional regex pattern and returns a slice of file paths. -// If skipHidden is true, hidden directories will be skipped. -func RecursiveFileList(dir string, pattern *regexp.Regexp, skipHidden bool) (files []string, err error) { - err = filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error { - - // Return errors - if err != nil { - return err - } - - info, err := d.Info() - - if err != nil { - return err - } - - if info.Mode().IsRegular() { - if pattern != nil { - if len(pattern.FindStringIndex(path)) > 0 { - files = append(files, path) - } - } else { - files = append(files, path) - } - // Skip hidden directories - } else if skipHidden && IsHidden(d.Name()) { - return filepath.SkipDir - } - - return nil - }) - return files, err -} - -// CreateParentDirectory creates the parent directory for the given file path. -func CreateParentDirectory(destination string) error { - parentDest := filepath.Dir(destination) - return CreateDirectory(parentDest, ReadWriteExecuteUser) -} - -// CreatePathAndCopy creates the parent directory for the given file path and copies the source file to the destination. -func CreatePathAndCopy(source string, destination string) error { - if err := CreateParentDirectory(destination); err != nil { - return err - } - - // Copy all the source data into the destination location - if err := copy.Copy(source, destination); err != nil { - return err - } - - // If the path doesn't exist yet then this is an empty file and we should create it - return CreateFile(destination) -} - -// ReadFileByChunks reads a file into multiple chunks by the given size. -func ReadFileByChunks(path string, chunkSizeBytes int) (chunks [][]byte, sha256sum string, err error) { - var file []byte - - // Open the created archive for io.Copy - if file, err = os.ReadFile(path); err != nil { - return chunks, sha256sum, err - } - - //Calculate the sha256sum of the file before we split it up - sha256sum = fmt.Sprintf("%x", sha256.Sum256(file)) - - // Loop over the tarball breaking it into chunks based on the payloadChunkSize - for { - if len(file) == 0 { - break - } - - // don't bust slice length - if len(file) < chunkSizeBytes { - chunkSizeBytes = len(file) - } - - chunks = append(chunks, file[0:chunkSizeBytes]) - file = file[chunkSizeBytes:] - } - - return chunks, sha256sum, nil -} - -// IsTrashBin checks if the given directory path corresponds to an operating system's trash bin. -func IsTrashBin(dirPath string) bool { - dirPath = filepath.Clean(dirPath) - - // Check if the directory path matches a Linux trash bin - if strings.HasSuffix(dirPath, "/Trash") || strings.HasSuffix(dirPath, "/.Trash-1000") { - return true - } - - // Check if the directory path matches a macOS trash bin - if strings.HasSuffix(dirPath, "./Trash") || strings.HasSuffix(dirPath, "/.Trashes") { - return true - } - - // Check if the directory path matches a Windows trash bin - if strings.HasSuffix(dirPath, "\\$RECYCLE.BIN") { - return true - } - - return false -} - -// IsHidden returns true if the given file name starts with a dot. -func IsHidden(name string) bool { - return name[0] == dotCharacter -} - -// GetDirSize walks through all files and directories in the provided path and returns the total size in bytes. -func GetDirSize(path string) (int64, error) { - dirSize := int64(0) - - // Walk all files in the path - err := filepath.Walk(path, func(_ string, info os.FileInfo, err error) error { - if err != nil { - return err - } - if !info.IsDir() { - dirSize += info.Size() - } - return nil - }) - - return dirSize, err -} - -// IsDir returns true if the given path is a directory. -func IsDir(path string) bool { - info, err := os.Stat(filepath.Clean(path)) - if os.IsNotExist(err) { - return false - } - return info.IsDir() -} - -// GetSHA256OfFile returns the SHA256 hash of the provided file. -func GetSHA256OfFile(filePath string) (string, error) { - f, err := os.Open(filePath) - if err != nil { - return "", err - } - defer f.Close() - - return GetSHA256Hash(f) -} - -// SHAsMatch returns an error if the SHA256 hash of the provided file does not match the expected hash. -func SHAsMatch(path, expected string) error { - sha, err := GetSHA256OfFile(path) - if err != nil { - return err - } - if sha != expected { - return fmt.Errorf("expected sha256 of %s to be %s, found %s", path, expected, sha) - } - return nil -} - -// CreateReproducibleTarballFromDir creates a tarball from a directory with stripped headers -func CreateReproducibleTarballFromDir(dirPath, dirPrefix, tarballPath string) error { - tb, err := os.Create(tarballPath) - if err != nil { - return fmt.Errorf("error creating tarball: %w", err) - } - defer tb.Close() - - tw := tar.NewWriter(tb) - defer tw.Close() - - // Walk through the directory and process each file - return filepath.Walk(dirPath, func(filePath string, info os.FileInfo, err error) error { - if err != nil { - return err - } - - link := "" - if info.Mode().Type() == os.ModeSymlink { - link, err = os.Readlink(filePath) - if err != nil { - return fmt.Errorf("error reading symlink: %w", err) - } - } - - // Create a new header - header, err := tar.FileInfoHeader(info, link) - if err != nil { - return fmt.Errorf("error creating tar header: %w", err) - } - - // Strip non-deterministic header data - header.ModTime = time.Time{} - header.AccessTime = time.Time{} - header.ChangeTime = time.Time{} - header.Uid = 0 - header.Gid = 0 - header.Uname = "" - header.Gname = "" - - // Ensure the header's name is correctly set relative to the base directory - name, err := filepath.Rel(dirPath, filePath) - if err != nil { - return fmt.Errorf("error getting relative path: %w", err) - } - name = filepath.Join(dirPrefix, name) - name = filepath.ToSlash(name) - header.Name = name - - // Write the header to the tarball - if err := tw.WriteHeader(header); err != nil { - return fmt.Errorf("error writing header: %w", err) - } - - // If it's a file, write its content - if info.Mode().IsRegular() { - file, err := os.Open(filePath) - if err != nil { - return fmt.Errorf("error opening file: %w", err) - } - defer file.Close() - - if _, err := io.Copy(tw, file); err != nil { - return fmt.Errorf("error writing file to tarball: %w", err) - } - } - - return nil - }) -} diff --git a/src/pkg/utils/helpers/hash.go b/src/pkg/utils/helpers/hash.go deleted file mode 100644 index a39cbff5b9..0000000000 --- a/src/pkg/utils/helpers/hash.go +++ /dev/null @@ -1,33 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2021-Present The Zarf Authors - -// Package helpers provides generic helper functions with no external imports -package helpers - -import ( - "crypto" - "encoding/hex" - "hash/crc32" - "io" -) - -// GetCryptoHash returns the computed SHA256 Sum of a given file -func GetCryptoHash(data io.ReadCloser, hashName crypto.Hash) (string, error) { - hash := hashName.New() - if _, err := io.Copy(hash, data); err != nil { - return "", err - } - - return hex.EncodeToString(hash.Sum(nil)), nil -} - -// GetCRCHash returns the computed CRC32 Sum of a given string -func GetCRCHash(text string) uint32 { - table := crc32.MakeTable(crc32.IEEE) - return crc32.Checksum([]byte(text), table) -} - -// GetSHA256Hash returns the computed SHA256 Sum of a given file -func GetSHA256Hash(data io.ReadCloser) (string, error) { - return GetCryptoHash(data, crypto.SHA256) -} diff --git a/src/pkg/utils/helpers/io.go b/src/pkg/utils/helpers/io.go deleted file mode 100644 index 996d643e52..0000000000 --- a/src/pkg/utils/helpers/io.go +++ /dev/null @@ -1,18 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2021-Present The Zarf Authors - -// Package helpers provides generic helper functions with no external imports -package helpers - -const ( - // ReadUser is used for any internal file to be read only - ReadUser = 0400 - // ReadWriteUser is used for any internal file not normally used by the end user or containing sensitive data - ReadWriteUser = 0600 - // ReadAllWriteUser is used for any non sensitive file intended to be consumed by the end user - ReadAllWriteUser = 0644 - // ReadWriteExecuteUser is used for any directory or executable not normally used by the end user or containing sensitive data - ReadWriteExecuteUser = 0700 - // ReadExecuteAllWriteUser is used for any non sensitive directory or executable intended to be consumed by the end user - ReadExecuteAllWriteUser = 0755 -) diff --git a/src/pkg/utils/helpers/misc.go b/src/pkg/utils/helpers/misc.go deleted file mode 100644 index e421c9509e..0000000000 --- a/src/pkg/utils/helpers/misc.go +++ /dev/null @@ -1,149 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2021-Present The Zarf Authors - -// Package helpers provides generic helper functions with no external imports -package helpers - -import ( - "fmt" - "math" - "reflect" - "regexp" - "time" -) - -// BoolPtr returns a pointer to a bool. -func BoolPtr(b bool) *bool { - return &b -} - -// Retry will retry a function until it succeeds or the timeout is reached. timeout == 2^attempt * delay. -func Retry(fn func() error, retries int, delay time.Duration, logger func(format string, args ...any)) error { - var err error - for r := 0; r < retries; r++ { - err = fn() - if err == nil { - break - } - - pow := math.Pow(2, float64(r)) - backoff := delay * time.Duration(pow) - - logger("Retrying (%d/%d) in %s: %s", r+1, retries, backoff, err.Error()) - - time.Sleep(backoff) - } - - return err -} - -// MergeMap merges map m2 with m1 overwriting common values with m2's values. -func MergeMap[T any](m1, m2 map[string]T) (r map[string]T) { - r = map[string]T{} - - for key, value := range m1 { - r[key] = value - } - - for key, value := range m2 { - r[key] = value - } - - return r -} - -// TransformMapKeys takes a map and transforms its keys using the provided function. -func TransformMapKeys[T any](m map[string]T, transform func(string) string) (r map[string]T) { - r = map[string]T{} - - for key, value := range m { - r[transform(key)] = value - } - - return r -} - -// TransformAndMergeMap transforms keys in both maps then merges map m2 with m1 overwriting common values with m2's values. -func TransformAndMergeMap[T any](m1, m2 map[string]T, transform func(string) string) (r map[string]T) { - mt1 := TransformMapKeys(m1, transform) - mt2 := TransformMapKeys(m2, transform) - r = MergeMap(mt1, mt2) - - return r -} - -// MergeMapRecursive recursively (nestedly) merges map m2 with m1 overwriting common values with m2's values. -func MergeMapRecursive(m1, m2 map[string]interface{}) (r map[string]interface{}) { - r = map[string]interface{}{} - - for key, value := range m1 { - r[key] = value - } - - for key, value := range m2 { - if value, ok := value.(map[string]interface{}); ok { - if nestedValue, ok := r[key]; ok { - if nestedValue, ok := nestedValue.(map[string]interface{}); ok { - r[key] = MergeMapRecursive(nestedValue, value) - continue - } - } - } - r[key] = value - } - - return r -} - -// MatchRegex wraps a get function around a substring match. -func MatchRegex(regex *regexp.Regexp, str string) (func(string) string, error) { - // Validate the string. - matches := regex.FindStringSubmatch(str) - - // Parse the string into its components. - get := func(name string) string { - return matches[regex.SubexpIndex(name)] - } - - if len(matches) == 0 { - return get, fmt.Errorf("unable to match against %s", str) - } - - return get, nil -} - -// IsNotZeroAndNotEqual is used to test if a struct has zero values or is equal values with another struct -func IsNotZeroAndNotEqual[T any](given T, equal T) bool { - givenValue := reflect.ValueOf(given) - equalValue := reflect.ValueOf(equal) - - if givenValue.NumField() != equalValue.NumField() { - return true - } - - for i := 0; i < givenValue.NumField(); i++ { - if !givenValue.Field(i).IsZero() && - givenValue.Field(i).CanInterface() && - givenValue.Field(i).Interface() != equalValue.Field(i).Interface() { - - return true - } - } - return false -} - -// MergeNonZero is used to merge non-zero overrides from one struct into another of the same type -func MergeNonZero[T any](original T, overrides T) T { - originalValue := reflect.ValueOf(&original) - overridesValue := reflect.ValueOf(&overrides) - - for i := 0; i < originalValue.Elem().NumField(); i++ { - if !overridesValue.Elem().Field(i).IsZero() && - overridesValue.Elem().Field(i).CanSet() { - - overrideField := overridesValue.Elem().Field(i) - originalValue.Elem().Field(i).Set(overrideField) - } - } - return originalValue.Elem().Interface().(T) -} diff --git a/src/pkg/utils/helpers/misc_test.go b/src/pkg/utils/helpers/misc_test.go deleted file mode 100644 index 4942cdab64..0000000000 --- a/src/pkg/utils/helpers/misc_test.go +++ /dev/null @@ -1,202 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2021-Present The Zarf Authors - -// Package helpers provides generic helper functions with no external imports -package helpers - -import ( - "errors" - "strings" - "testing" - - "github.com/stretchr/testify/require" - "github.com/stretchr/testify/suite" -) - -type TestMiscSuite struct { - suite.Suite - *require.Assertions - map1 map[string]interface{} - map2 map[string]interface{} -} - -type TestMiscStruct struct { - Field1 string - Field2 int - field3 string -} - -func (suite *TestMiscSuite) SetupSuite() { - suite.Assertions = require.New(suite.T()) - suite.map1 = map[string]interface{}{ - "hello": "world", - "unique": "value", - "nested": map[string]interface{}{ - "values": "kitteh", - "unique": "value", - }, - } - suite.map2 = map[string]interface{}{ - "hello": "it's me", - "different": "value", - "nested": map[string]interface{}{ - "values": "doggo", - "different": "value", - }, - } -} - -func (suite *TestMiscSuite) TestRetry() { - var count int - countFn := func() error { - count++ - if count < 4 { - return errors.New("count exceeded") - } - return nil - } - var logCount int - loggerFn := func(_ string, _ ...any) { - logCount++ - } - - count = 0 - logCount = 0 - err := Retry(countFn, 3, 0, loggerFn) - suite.Error(err) - suite.Equal(3, count) - suite.Equal(3, logCount) - - count = 0 - logCount = 0 - err = Retry(countFn, 4, 0, loggerFn) - suite.NoError(err) - suite.Equal(4, count) - suite.Equal(3, logCount) -} - -func (suite *TestMiscSuite) TestMergeMap() { - expected := map[string]interface{}{ - "different": "value", - "hello": "it's me", - "unique": "value", - "nested": map[string]interface{}{ - "values": "doggo", - "different": "value", - }, - } - - result := MergeMap(suite.map1, suite.map2) - suite.Equal(expected, result) -} - -func (suite *TestMiscSuite) TestTransformMapKeys() { - expected := map[string]interface{}{ - "HELLO": "world", - "UNIQUE": "value", - "NESTED": map[string]interface{}{ - "values": "kitteh", - "unique": "value", - }, - } - - result := TransformMapKeys(suite.map1, strings.ToUpper) - suite.Equal(expected, result) -} - -func (suite *TestMiscSuite) TestTransformAndMergeMap() { - expected := map[string]interface{}{ - "DIFFERENT": "value", - "HELLO": "it's me", - "UNIQUE": "value", - "NESTED": map[string]interface{}{ - "values": "doggo", - "different": "value", - }, - } - - result := TransformAndMergeMap(suite.map1, suite.map2, strings.ToUpper) - suite.Equal(expected, result) -} - -func (suite *TestMiscSuite) TestMergeMapRecursive() { - expected := map[string]interface{}{ - "different": "value", - "hello": "it's me", - "unique": "value", - "nested": map[string]interface{}{ - "values": "doggo", - "different": "value", - "unique": "value", - }, - } - - result := MergeMapRecursive(suite.map1, suite.map2) - suite.Equal(expected, result) -} - -func (suite *TestMiscSuite) TestIsNotZeroAndNotEqual() { - original := TestMiscStruct{ - Field1: "hello", - Field2: 100, - field3: "world", - } - zero := TestMiscStruct{} - equal := TestMiscStruct{ - Field1: "hello", - } - notEqual := TestMiscStruct{ - Field1: "kitteh", - } - - result := IsNotZeroAndNotEqual(original, original) - suite.Equal(false, result) - result = IsNotZeroAndNotEqual(zero, original) - suite.Equal(false, result) - result = IsNotZeroAndNotEqual(equal, original) - suite.Equal(false, result) - result = IsNotZeroAndNotEqual(notEqual, original) - suite.Equal(true, result) -} - -func (suite *TestMiscSuite) TestMergeNonZero() { - original := TestMiscStruct{ - Field1: "hello", - Field2: 100, - field3: "world", - } - overrides := TestMiscStruct{ - Field1: "kitteh", - Field2: 300, - // field 3 is private and shouldn't be set (but also shouldn't panic) - field3: "doggo", - } - - result := MergeNonZero(original, overrides) - suite.Equal("kitteh", result.Field1) - suite.Equal(300, result.Field2) - suite.Equal("world", result.field3) - - withZero := TestMiscStruct{ - Field1: "kitteh", - } - - result = MergeNonZero(original, withZero) - suite.Equal("kitteh", result.Field1) - suite.Equal(100, result.Field2) - suite.Equal("world", result.field3) -} - -func (suite *TestMiscSuite) TestBoolPtr() { - suite.Equal(true, *BoolPtr(true)) - suite.Equal(false, *BoolPtr(false)) - a := BoolPtr(true) - b := BoolPtr(true) - // This is a pointer comparison, not a value comparison - suite.False(a == b) - suite.True(*a == *b) -} - -func TestMisc(t *testing.T) { - suite.Run(t, new(TestMiscSuite)) -} diff --git a/src/pkg/utils/helpers/progress.go b/src/pkg/utils/helpers/progress.go deleted file mode 100644 index 35b416b755..0000000000 --- a/src/pkg/utils/helpers/progress.go +++ /dev/null @@ -1,26 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2021-Present The Zarf Authors - -// Package helpers provides generic helper functions with no external imports -package helpers - -import "io" - -// Write doesn't do anything but satisfy implementation -func (DiscardProgressWriter) Write(p []byte) (int, error) { - return len(p), nil -} - -// UpdateTitle doesn't do anything but satisfy implementation -func (DiscardProgressWriter) UpdateTitle(_ string) {} - -// DiscardProgressWriter is a ProgressWriter in which all calls succeed without doing anything -// Use this or nil or if you don't care about writing progress -type DiscardProgressWriter struct{} - -// ProgressWriter wraps io.Writer, but also includes an updateTitle function to give the user -// additional context on what's going on. Useful in OCI for tracking layers -type ProgressWriter interface { - UpdateTitle(string) - io.Writer -} diff --git a/src/pkg/utils/helpers/random.go b/src/pkg/utils/helpers/random.go deleted file mode 100644 index d06700ad7f..0000000000 --- a/src/pkg/utils/helpers/random.go +++ /dev/null @@ -1,28 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2021-Present The Zarf Authors - -// Package helpers provides generic helper functions with no external imports -package helpers - -import ( - "crypto/rand" -) - -// Very limited special chars for git / basic auth -// https://owasp.org/www-community/password-special-characters has complete list of safe chars. -const randomStringChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!~-" - -// RandomString generates a secure random string of the specified length. -func RandomString(length int) (string, error) { - bytes := make([]byte, length) - - if _, err := rand.Read(bytes); err != nil { - return "", err - } - - for i, b := range bytes { - bytes[i] = randomStringChars[b%byte(len(randomStringChars))] - } - - return string(bytes), nil -} diff --git a/src/pkg/utils/helpers/slice.go b/src/pkg/utils/helpers/slice.go deleted file mode 100644 index 93dbbd774e..0000000000 --- a/src/pkg/utils/helpers/slice.go +++ /dev/null @@ -1,98 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2021-Present The Zarf Authors - -// Package helpers provides generic helper functions with no external imports -package helpers - -import "strings" - -// Unique returns a new slice with only unique elements. -func Unique[T comparable](s []T) (r []T) { - exists := make(map[T]bool) - for _, str := range s { - if _, ok := exists[str]; !ok { - exists[str] = true - r = append(r, str) - } - } - return r -} - -// Reverse returns a new slice with the elements in reverse order. -func Reverse[T any](s []T) (r []T) { - for i := len(s) - 1; i >= 0; i-- { - r = append(r, s[i]) - } - return r -} - -// Filter returns a new slice with only the elements that pass the test. -func Filter[T any](ss []T, test func(T) bool) (r []T) { - if test == nil { - return ss - } - for _, s := range ss { - if test(s) { - r = append(r, s) - } - } - return r -} - -// Find returns the first element that passes the test. -func Find[T any](ss []T, test func(T) bool) (r T) { - for _, s := range ss { - if test(s) { - return s - } - } - return r -} - -// RemoveMatches removes the given element from the slice that matches the test. -func RemoveMatches[T any](ss []T, test func(T) bool) (r []T) { - for _, s := range ss { - if !test(s) { - r = append(r, s) - } - } - return r -} - -// StringToSlice converts a comma-separated string to a slice of lowercase strings. -func StringToSlice(s string) []string { - if s != "" { - split := strings.Split(s, ",") - for idx, element := range split { - split[idx] = strings.ToLower(strings.TrimSpace(element)) - } - return split - } - - return []string{} -} - -// EqualFunc defines a type for a function that determines equality between two elements of type T. -type EqualFunc[T any] func(a, b T) bool - -// MergeSlices merges two slices, s1 and s2, and returns a new slice containing all elements from s1 -// and only those elements from s2 that do not exist in s1 based on the provided equal function. -func MergeSlices[T any](s1, s2 []T, equals EqualFunc[T]) []T { - merged := make([]T, 0, len(s1)+len(s2)) - merged = append(merged, s1...) - - for _, v2 := range s2 { - exists := false - for _, v1 := range s1 { - if equals(v1, v2) { - exists = true - break - } - } - if !exists { - merged = append(merged, v2) - } - } - - return merged -} diff --git a/src/pkg/utils/helpers/string.go b/src/pkg/utils/helpers/string.go deleted file mode 100644 index ab6c69913f..0000000000 --- a/src/pkg/utils/helpers/string.go +++ /dev/null @@ -1,14 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2021-Present The Zarf Authors - -// Package helpers provides generic helper functions with no external imports -package helpers - -// First30last30 returns the source string that has been trimmed to 30 characters at the beginning and end. -func First30last30(s string) string { - if len(s) > 60 { - return s[0:27] + "..." + s[len(s)-26:] - } - - return s -} diff --git a/src/pkg/utils/helpers/text.go b/src/pkg/utils/helpers/text.go deleted file mode 100644 index 071faa099a..0000000000 --- a/src/pkg/utils/helpers/text.go +++ /dev/null @@ -1,75 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2021-Present The Zarf Authors - -// Package helpers provides generic helper functions with no external imports -package helpers - -import ( - "io" - "net/http" - "os" - "strings" -) - -// Truncate truncates provided text to the requested length -func Truncate(text string, length int, invert bool) string { - // Remove newlines and replace with semicolons - textEscaped := strings.ReplaceAll(text, "\n", "; ") - // Truncate the text if it is longer than length so it isn't too long. - if len(textEscaped) > length { - if invert { - start := len(textEscaped) - length + 3 - textEscaped = "..." + textEscaped[start:] - } else { - end := length - 3 - textEscaped = textEscaped[:end] + "..." - } - } - return textEscaped -} - -// IsTextFile returns true if the given file is a text file. -func IsTextFile(path string) (bool, error) { - // Open the file - f, err := os.Open(path) - if err != nil { - return false, err - } - defer f.Close() // Make sure to close the file when we're done - - // Get file stat - stat, err := f.Stat() - if err != nil { - return false, err - } - - // Clip offset to minimum of 0 - lastOffset := max(0, stat.Size()-512) - - // Take two passes checking front and back of the file - offsetPasses := []int64{0, lastOffset} - isTextCheck := []bool{false, false} - for idx, offset := range offsetPasses { - // Create 512 byte buffer - data := make([]byte, 512) - - n, err := f.ReadAt(data, offset) - if err != nil && err != io.EOF { - return false, err - } - - // Use http.DetectContentType to determine the MIME type of the file - mimeType := http.DetectContentType(data[:n]) - - // Check if the MIME type indicates that the file is text - hasText := strings.HasPrefix(mimeType, "text/") - hasJSON := strings.Contains(mimeType, "json") - hasXML := strings.Contains(mimeType, "xml") - - // Save result - isTextCheck[idx] = hasText || hasJSON || hasXML - } - - // Returns true if both front and back show they are text - return isTextCheck[0] && isTextCheck[1], nil -} diff --git a/src/pkg/utils/helpers/transport.go b/src/pkg/utils/helpers/transport.go deleted file mode 100644 index 5fa452ec10..0000000000 --- a/src/pkg/utils/helpers/transport.go +++ /dev/null @@ -1,98 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2021-Present The Zarf Authors - -// Package helpers provides generic utility functions. -package helpers - -import ( - "io" - "net/http" - "time" - - "oras.land/oras-go/v2/registry/remote/retry" -) - -// Transport is an http.RoundTripper that keeps track of the in-flight -// request and add hooks to report upload progress. -type Transport struct { - Base http.RoundTripper - ProgressBar ProgressWriter -} - -// NewTransport returns a custom transport that tracks an http.RoundTripper and a message.ProgressBar. -func NewTransport(base http.RoundTripper, bar ProgressWriter) *Transport { - return &Transport{ - Base: base, - ProgressBar: bar, - } -} - -// RoundTrip is mirrored from retry, but instead of calling retry's private t.roundTrip(), this uses -// our own which has interactions w/ message.ProgressBar -// -// https://github.com/oras-project/oras-go/blob/main/registry/remote/retry/client.go -func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) { - ctx := req.Context() - policy := retry.DefaultPolicy - attempt := 0 - for { - resp, respErr := t.roundTrip(req) - duration, err := policy.Retry(attempt, resp, respErr) - if err != nil { - if respErr == nil { - resp.Body.Close() - } - return nil, err - } - if duration < 0 { - return resp, respErr - } - - // rewind the body if possible - if req.Body != nil { - if req.GetBody == nil { - // body can't be rewound, so we can't retry - return resp, respErr - } - body, err := req.GetBody() - if err != nil { - // failed to rewind the body, so we can't retry - return resp, respErr - } - req.Body = body - } - - // close the response body if needed - if respErr == nil { - resp.Body.Close() - } - - timer := time.NewTimer(duration) - select { - case <-ctx.Done(): - timer.Stop() - return nil, ctx.Err() - case <-timer.C: - } - attempt++ - } -} - -// roundTrip calls base roundtrip while keeping track of the current request. -// this is currently only used to track the progress of publishes, not pulls. -func (t *Transport) roundTrip(req *http.Request) (resp *http.Response, err error) { - if req.Method != http.MethodHead && req.Body != nil && t.ProgressBar != nil { - req.Body = io.NopCloser(io.TeeReader(req.Body, t.ProgressBar)) - } - - resp, err = t.Base.RoundTrip(req) - - if resp != nil && req.Method == http.MethodHead && err == nil && t.ProgressBar != nil { - if resp.ContentLength > 0 { - contentLength := int(resp.ContentLength) - b := make([]byte, contentLength) - t.ProgressBar.Write(b) - } - } - return resp, err -} diff --git a/src/pkg/utils/helpers/url.go b/src/pkg/utils/helpers/url.go deleted file mode 100644 index d98ceb9f5b..0000000000 --- a/src/pkg/utils/helpers/url.go +++ /dev/null @@ -1,112 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2021-Present The Zarf Authors - -// Package helpers provides generic helper functions with no external imports -package helpers - -import ( - "fmt" - "net" - "net/url" - "os" - "path" - "regexp" - "strconv" -) - -// Nonstandard URL schemes or prefixes -const ( - OCIURLPrefix = "oci://" - - SGETURLPrefix = "sget://" - SGETURLScheme = "sget" - - IPV4Localhost = "127.0.0.1" -) - -// IsURL is a helper function to check if a URL is valid. -func IsURL(source string) bool { - parsedURL, err := url.Parse(source) - return err == nil && parsedURL.Scheme != "" && parsedURL.Host != "" -} - -// IsOCIURL returns true if the given URL is an OCI URL. -func IsOCIURL(source string) bool { - parsedURL, err := url.Parse(source) - return err == nil && parsedURL.Scheme == "oci" -} - -// DoHostnamesMatch returns a boolean indicating if the hostname of two different URLs are the same. -func DoHostnamesMatch(url1 string, url2 string) (bool, error) { - parsedURL1, err := url.Parse(url1) - if err != nil { - return false, fmt.Errorf("unable to parse the url (%s): %w", url1, err) - } - parsedURL2, err := url.Parse(url2) - if err != nil { - return false, fmt.Errorf("unable to parse the url (%s): %w", url2, err) - } - - return parsedURL1.Hostname() == parsedURL2.Hostname(), nil -} - -// ExtractBasePathFromURL returns filename from URL string -func ExtractBasePathFromURL(urlStr string) (string, error) { - if !IsURL(urlStr) { - return "", fmt.Errorf("%s is not a valid URL", urlStr) - } - parsedURL, err := url.Parse(urlStr) - if err != nil { - return "", err - } - - filename := path.Base(parsedURL.Path) - return filename, nil -} - -// IsValidHostName returns a boolean indicating if the hostname of the host machine is valid according to https://www.ietf.org/rfc/rfc1123.txt. -func IsValidHostName() bool { - // Quick & dirty character validation instead of a complete RFC validation since the OS is already allowing it - hostname, err := os.Hostname() - - if err != nil { - return false - } - - return validHostname(hostname) -} - -func validHostname(hostname string) bool { - // Explanation: https://regex101.com/r/zUGqjP/1/ - rfcDomain := regexp.MustCompile(`^[a-zA-Z0-9\-.]+$`) - // Explanation: https://regex101.com/r/vPGnzR/1/ - localhost := regexp.MustCompile(`\.?localhost$`) - isValid := rfcDomain.MatchString(hostname) - if isValid { - isValid = !localhost.MatchString(hostname) - } - return isValid -} - -// GetAvailablePort retrieves an available port on the host machine. This delegates the port selection to the golang net -// library by starting a server and then checking the port that the server is using. -func GetAvailablePort() (int, error) { - l, err := net.Listen("tcp", ":0") - if err != nil { - return 0, err - } - defer func(l net.Listener) { - // ignore this error because it won't help us to tell the user - _ = l.Close() - }(l) - - _, p, err := net.SplitHostPort(l.Addr().String()) - if err != nil { - return 0, err - } - port, err := strconv.Atoi(p) - if err != nil { - return 0, err - } - return port, err -} diff --git a/src/pkg/utils/helpers/url_test.go b/src/pkg/utils/helpers/url_test.go deleted file mode 100644 index bbcae85a18..0000000000 --- a/src/pkg/utils/helpers/url_test.go +++ /dev/null @@ -1,158 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2021-Present The Zarf Authors - -// Package helpers provides generic helper functions with no external imports -package helpers - -import ( - "fmt" - "testing" - - "github.com/stretchr/testify/require" - "github.com/stretchr/testify/suite" -) - -type TestURLSuite struct { - suite.Suite - *require.Assertions - urls testURLs -} - -type testURLs struct { - good []string - oci []string - paths []string -} - -func (suite *TestURLSuite) SetupSuite() { - suite.Assertions = require.New(suite.T()) - suite.urls.good = []string{ - "https://zarf.dev", - "https://docs.zarf.dev", - "https://zarf.dev/docs", - "https://defenseunicorns.com", - "https://google.com", - "https://user:pass@hello.world?foo=bar", - "https://zarf.dev?foo=bar&bar=baz", - } - suite.urls.oci = []string{ - "oci://zarf.dev", - "oci://defenseunicorns.com", - "oci://google.com", - } - suite.urls.paths = []string{ - "./hello.txt", - "../hello.txt", - "/tmp/hello.txt", - } -} - -func (suite *TestURLSuite) Test_0_IsURL() { - all := append(suite.urls.good, suite.urls.oci...) - for _, url := range all { - suite.True(IsURL(url), "Expected %s to be a valid URL", url) - } - for _, url := range suite.urls.paths { - suite.False(IsURL(url), "Expected %s to be an invalid URL", url) - } -} - -func (suite *TestURLSuite) Test_1_IsOCIURL() { - for _, url := range suite.urls.good { - suite.False(IsOCIURL(url), "Expected %s to be an invalid OCI URL", url) - } - for _, url := range suite.urls.oci { - suite.True(IsOCIURL(url), "Expected %s to be a valid OCI URL", url) - } - for _, url := range suite.urls.paths { - suite.False(IsOCIURL(url), "Expected %s to be an invalid OCI URL", url) - } -} - -func (suite *TestURLSuite) Test_2_DoHostnamesMatch() { - - b, err := DoHostnamesMatch("https://zarf.dev", "https://zarf.dev") - suite.NoError(err) - suite.True(b) - b, err = DoHostnamesMatch("https://zarf.dev", "https://docs.zarf.dev") - suite.NoError(err) - suite.False(b) - b, err = DoHostnamesMatch("https://zarf.dev", "https://zarf.dev/docs") - suite.NoError(err) - suite.True(b) - b, err = DoHostnamesMatch("https://zarf.dev", "https://user:pass@zarf.dev") - suite.NoError(err) - suite.True(b) - b, err = DoHostnamesMatch("https://zarf.dev", "") - suite.NoError(err) - suite.False(b) - b, err = DoHostnamesMatch("", "https://zarf.dev") - suite.NoError(err) - suite.False(b) -} - -func (suite *TestURLSuite) Test_3_ExtractBasePathFromURL() { - goodURLs := []string{ - "https://zarf.dev/file.txt", - "https://docs.zarf.dev/file.txt", - "https://zarf.dev/docs/file.tar.gz", - "https://defenseunicorns.com/file.yaml", - "https://google.com/file.md", - } - badURLs := []string{ - "invalid-url", - "am", - "not", - "a url", - "info@defenseunicorns.com", - "12345", - "kubernetes.svc.default.svc.cluster.local", - } - expectations := []string{ - "file.txt", - "file.txt", - "file.tar.gz", - "file.yaml", - "file.md", - } - - for idx, url := range goodURLs { - actualURL, err := ExtractBasePathFromURL(url) - suite.NoError(err) - suite.Equal(actualURL, expectations[idx]) - } - for _, url := range badURLs { - url, err := ExtractBasePathFromURL(url) - fmt.Println(url) - suite.Error(err) - } - -} - -func (suite *TestURLSuite) Test_4_IsValidHostname() { - goodHostnames := []string{ - "singlehost", - "host.domain.com", - "host.domain-dash.com", - "127.0.0.1", - "I.lIKe.Pi3", - } - badHostnames := []string{ - "invalid_hostname", - "localhost", - "something.localhost", - } - - for _, hostname := range goodHostnames { - isValid := validHostname(hostname) - suite.Equal(isValid, true) - } - for _, hostname := range badHostnames { - isValid := validHostname(hostname) - suite.Equal(isValid, false) - } -} - -func TestURL(t *testing.T) { - suite.Run(t, new(TestURLSuite)) -} diff --git a/src/pkg/utils/image.go b/src/pkg/utils/image.go index 0154953117..5a05d987df 100644 --- a/src/pkg/utils/image.go +++ b/src/pkg/utils/image.go @@ -10,8 +10,8 @@ import ( "os" "path/filepath" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/pkg/transform" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" v1 "github.com/google/go-containerregistry/pkg/v1" "github.com/google/go-containerregistry/pkg/v1/layout" ocispec "github.com/opencontainers/image-spec/specs-go/v1" diff --git a/src/pkg/utils/io.go b/src/pkg/utils/io.go index 9a711bfa5e..55c60fc1dc 100755 --- a/src/pkg/utils/io.go +++ b/src/pkg/utils/io.go @@ -12,9 +12,9 @@ import ( "os" "path/filepath" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/pkg/message" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" ) diff --git a/src/pkg/utils/network.go b/src/pkg/utils/network.go index b21876224e..036d4fe57c 100644 --- a/src/pkg/utils/network.go +++ b/src/pkg/utils/network.go @@ -14,9 +14,9 @@ import ( "path/filepath" "strings" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config/lang" "github.com/defenseunicorns/zarf/src/pkg/message" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" ) func parseChecksum(src string) (string, string, error) { diff --git a/src/pkg/utils/network_test.go b/src/pkg/utils/network_test.go index 31e4adc0e5..fdcf47b043 100644 --- a/src/pkg/utils/network_test.go +++ b/src/pkg/utils/network_test.go @@ -9,8 +9,8 @@ import ( "path/filepath" "testing" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/pkg/message" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" ) diff --git a/src/pkg/zoci/pull.go b/src/pkg/zoci/pull.go index 1724127ebc..6b89c58cb4 100644 --- a/src/pkg/zoci/pull.go +++ b/src/pkg/zoci/pull.go @@ -9,11 +9,11 @@ import ( "fmt" "path/filepath" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/pkg/layout" "github.com/defenseunicorns/zarf/src/pkg/oci" "github.com/defenseunicorns/zarf/src/pkg/transform" "github.com/defenseunicorns/zarf/src/pkg/utils" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" ocispec "github.com/opencontainers/image-spec/specs-go/v1" "oras.land/oras-go/v2/content/file" diff --git a/src/pkg/zoci/push.go b/src/pkg/zoci/push.go index 54b2c6c6cc..e6397a0ee8 100644 --- a/src/pkg/zoci/push.go +++ b/src/pkg/zoci/push.go @@ -8,10 +8,10 @@ import ( "context" "fmt" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/pkg/layout" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/oci" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" ocispec "github.com/opencontainers/image-spec/specs-go/v1" "oras.land/oras-go/v2" diff --git a/src/pkg/zoci/utils.go b/src/pkg/zoci/utils.go index c0a8fc944a..968db5f591 100644 --- a/src/pkg/zoci/utils.go +++ b/src/pkg/zoci/utils.go @@ -9,7 +9,7 @@ import ( "fmt" "strings" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/types" "oras.land/oras-go/v2/registry" ) diff --git a/src/test/common.go b/src/test/common.go index eab1f58fde..35d6820d28 100644 --- a/src/test/common.go +++ b/src/test/common.go @@ -16,8 +16,8 @@ import ( "slices" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/pkg/utils/exec" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/stretchr/testify/require" ) diff --git a/src/test/e2e/00_use_cli_test.go b/src/test/e2e/00_use_cli_test.go index 5a4df32e8f..f6acc4840e 100644 --- a/src/test/e2e/00_use_cli_test.go +++ b/src/test/e2e/00_use_cli_test.go @@ -12,7 +12,7 @@ import ( "strings" "testing" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" + "github.com/defenseunicorns/pkg/helpers" "github.com/stretchr/testify/require" ) diff --git a/src/test/e2e/05_tarball_test.go b/src/test/e2e/05_tarball_test.go index 4d29edae77..23eb39a7df 100644 --- a/src/test/e2e/05_tarball_test.go +++ b/src/test/e2e/05_tarball_test.go @@ -11,10 +11,10 @@ import ( "path/filepath" "testing" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/pkg/layout" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/utils" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" "github.com/stretchr/testify/require" ) diff --git a/src/test/e2e/51_oci_compose_test.go b/src/test/e2e/51_oci_compose_test.go index be89bc8b97..052c5a1ee4 100644 --- a/src/test/e2e/51_oci_compose_test.go +++ b/src/test/e2e/51_oci_compose_test.go @@ -12,10 +12,10 @@ import ( "strings" "testing" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/pkg/layout" "github.com/defenseunicorns/zarf/src/pkg/transform" "github.com/defenseunicorns/zarf/src/pkg/utils" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" diff --git a/src/test/external/ext_out_cluster_test.go b/src/test/external/ext_out_cluster_test.go index eb42a49676..7d086bc137 100644 --- a/src/test/external/ext_out_cluster_test.go +++ b/src/test/external/ext_out_cluster_test.go @@ -15,9 +15,9 @@ import ( "path/filepath" "testing" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/pkg/utils" "github.com/defenseunicorns/zarf/src/pkg/utils/exec" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" "helm.sh/helm/v3/pkg/repo" diff --git a/src/types/k8s.go b/src/types/k8s.go index b34b10a211..581b02e947 100644 --- a/src/types/k8s.go +++ b/src/types/k8s.go @@ -8,9 +8,9 @@ import ( "fmt" "time" + "github.com/defenseunicorns/pkg/helpers" "github.com/defenseunicorns/zarf/src/config/lang" "github.com/defenseunicorns/zarf/src/pkg/k8s" - "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" ) // WebhookStatus defines the status of a Component Webhook operating on a Zarf package secret.