@@ -2,12 +2,14 @@ package cli
22
33import (
44 "fmt"
5+ "os"
56
67 "github.com/spf13/cobra"
78 "helm.sh/helm/v4/pkg/action"
89
910 "hauler.dev/go/hauler/v2/cmd/hauler/cli/store"
1011 "hauler.dev/go/hauler/v2/internal/flags"
12+ "hauler.dev/go/hauler/v2/pkg/consts"
1113 "hauler.dev/go/hauler/v2/pkg/log"
1214)
1315
@@ -71,6 +73,24 @@ func addStoreSync(rso *flags.StoreRootOpts, ro *flags.CliRootOpts) *cobra.Comman
7173 Short : "Sync content to the content store" ,
7274 Args : cobra .ExactArgs (0 ),
7375 PreRunE : func (cmd * cobra.Command , args []string ) error {
76+ // Check for ca-file & insecure-skip-tls-verify env variables
77+ if o .CaFile == "" {
78+ o .CaFile = os .Getenv (consts .CaFile )
79+ }
80+
81+ // record which precedence-carrying flags the user explicitly set, so
82+ // the resolvers can let an explicit CLI value win over per-item/annotation
83+ o .TlogChanged = cmd .Flags ().Changed ("use-tlog-verify" )
84+ o .ExcludeExtrasChanged = cmd .Flags ().Changed ("exclude-extras" )
85+ o .InsecureChanged = cmd .Flags ().Changed ("insecure-skip-tls-verify" )
86+ o .StoreChanged = cmd .Flags ().Changed ("store" )
87+ o .RetriesChanged = cmd .Flags ().Changed ("retries" )
88+
89+ // env var only applies when the flag wasn't set, so an explicit --insecure-skip-tls-verify=false still wins
90+ if ! o .InsecureChanged && os .Getenv (consts .InsecureSkipTLSVerify ) == "true" {
91+ o .InsecureSkipTLSVerify = true
92+ }
93+
7494 // --dry-run requires --products
7595 if o .DryRun && len (o .Products ) == 0 {
7696 return fmt .Errorf ("--dry-run requires --products" )
@@ -146,9 +166,8 @@ func addStoreLoad(rso *flags.StoreRootOpts, ro *flags.CliRootOpts) *cobra.Comman
146166 if err != nil {
147167 return err
148168 }
149- _ = s
150169
151- return store .LoadCmd (ctx , o , rso , ro )
170+ return store .LoadCmd (ctx , o , s , rso , ro )
152171 },
153172 }
154173 o .AddFlags (cmd )
@@ -232,9 +251,8 @@ func addStoreSave(rso *flags.StoreRootOpts, ro *flags.CliRootOpts) *cobra.Comman
232251 if err != nil {
233252 return err
234253 }
235- _ = s
236254
237- return store .SaveCmd (ctx , o , rso , ro )
255+ return store .SaveCmd (ctx , o , s , rso , ro )
238256 },
239257 }
240258 o .AddFlags (cmd )
@@ -292,8 +310,8 @@ func addStoreCopy(rso *flags.StoreRootOpts, ro *flags.CliRootOpts) *cobra.Comman
292310 Use : "copy" ,
293311 Short : "Copy all store content to another location" ,
294312 Example : ` # supported copy target prefixes
295- registry:// | reg:// | oci:// - Pushes the store to an OCI registry
296- directory:// | dir:// - Extracts the store to a directory` ,
313+ registry:// | reg:// | oci:// - Pushes the store to an OCI registry
314+ directory:// | dir:// - Extracts the store to a directory` ,
297315 Args : cobra .ExactArgs (1 ),
298316 RunE : func (cmd * cobra.Command , args []string ) error {
299317 ctx := cmd .Context ()
@@ -336,13 +354,13 @@ func addStoreAddFile(rso *flags.StoreRootOpts, ro *flags.CliRootOpts) *cobra.Com
336354 Use : "file" ,
337355 Short : "Add a file to the store" ,
338356 Example : ` # fetch local file
339- hauler store add file file.txt
357+ hauler store add file file.txt
340358
341- # fetch remote file
342- hauler store add file https://get.rke2.io/install.sh
359+ # fetch remote file
360+ hauler store add file https://get.rke2.io/install.sh
343361
344- # fetch remote file and assign new name
345- hauler store add file https://get.hauler.dev --name hauler-install.sh` ,
362+ # fetch remote file and assign new name
363+ hauler store add file https://get.hauler.dev --name hauler-install.sh` ,
346364 Args : cobra .ExactArgs (1 ),
347365 RunE : func (cmd * cobra.Command , args []string ) error {
348366 ctx := cmd .Context ()
@@ -366,28 +384,39 @@ func addStoreAddImage(rso *flags.StoreRootOpts, ro *flags.CliRootOpts) *cobra.Co
366384 cmd := & cobra.Command {
367385 Use : "image" ,
368386 Short : "Add a image to the store" ,
369- Example : ` # fetch image
370- hauler store add image busybox
387+ Example : ` # fetch image
388+ hauler store add image busybox
371389
372- # fetch image with repository and tag
373- hauler store add image library/busybox:stable
390+ # fetch image with repository and tag
391+ hauler store add image library/busybox:stable
374392
375- # fetch image with full image reference and specific platform
376- hauler store add image ghcr.io/hauler-dev/hauler-debug:v1.2.0 --platform linux/amd64
393+ # fetch image with full image reference and specific platform
394+ hauler store add image ghcr.io/hauler-dev/hauler-debug:v1.2.0 --platform linux/amd64
377395
378- # fetch image with full image reference via digest
379- hauler store add image gcr.io/distroless/base@sha256:7fa7445dfbebae4f4b7ab0e6ef99276e96075ae42584af6286ba080750d6dfe5
396+ # fetch image with full image reference via digest
397+ hauler store add image gcr.io/distroless/base@sha256:7fa7445dfbebae4f4b7ab0e6ef99276e96075ae42584af6286ba080750d6dfe5
380398
381- # fetch image with full image reference, specific platform, and signature verification
382- curl -sfOL https://raw.githubusercontent.com/rancherfederal/carbide-releases/main/carbide-key.pub
383- hauler store add image rgcrprod.azurecr.us/rancher/rke2-runtime:v1.31.5-rke2r1 --platform linux/amd64 --key carbide-key.pub
399+ # fetch image with full image reference, specific platform, and signature verification
400+ curl -sfOL https://raw.githubusercontent.com/rancherfederal/carbide-releases/main/carbide-key.pub
401+ hauler store add image rgcrprod.azurecr.us/rancher/rke2-runtime:v1.31.5-rke2r1 --platform linux/amd64 --key carbide-key.pub
384402
385- # fetch image and rewrite path
386- hauler store add image busybox --rewrite custom-path/busybox:latest
403+ # fetch image and rewrite path
404+ hauler store add image busybox --rewrite custom-path/busybox:latest
387405
388- # add image from local Docker daemon
389- hauler store add image my-local-app:latest --local` ,
406+ # add image from local Docker daemon
407+ hauler store add image my-local-app:latest --local` ,
390408 Args : cobra .ExactArgs (1 ),
409+ PreRunE : func (cmd * cobra.Command , args []string ) error {
410+ // Check for ca-file & insecure-skip-tls-verify env variables
411+ if o .CaFile == "" {
412+ o .CaFile = os .Getenv (consts .CaFile )
413+ }
414+ // env var only applies when the flag wasn't set, so an explicit --insecure-skip-tls-verify=false still wins
415+ if ! cmd .Flags ().Changed ("insecure-skip-tls-verify" ) && os .Getenv (consts .InsecureSkipTLSVerify ) == "true" {
416+ o .InsecureSkipTLSVerify = true
417+ }
418+ return nil
419+ },
391420 RunE : func (cmd * cobra.Command , args []string ) error {
392421 ctx := cmd .Context ()
393422
@@ -410,26 +439,26 @@ func addStoreAddChart(rso *flags.StoreRootOpts, ro *flags.CliRootOpts) *cobra.Co
410439 cmd := & cobra.Command {
411440 Use : "chart" ,
412441 Short : "Add a helm chart to the store" ,
413- Example : ` # fetch local helm chart
414- hauler store add chart path/to/chart/directory --repo .
442+ Example : ` # fetch local helm chart
443+ hauler store add chart path/to/chart/directory --repo .
415444
416- # fetch local compressed helm chart
417- hauler store add chart path/to/chart.tar.gz --repo .
445+ # fetch local compressed helm chart
446+ hauler store add chart path/to/chart.tar.gz --repo .
418447
419- # fetch remote oci helm chart
420- hauler store add chart hauler-helm --repo oci://ghcr.io/hauler-dev
448+ # fetch remote oci helm chart
449+ hauler store add chart hauler-helm --repo oci://ghcr.io/hauler-dev
421450
422- # fetch remote oci helm chart with version
423- hauler store add chart hauler-helm --repo oci://ghcr.io/hauler-dev --version 1.2.0
451+ # fetch remote oci helm chart with version
452+ hauler store add chart hauler-helm --repo oci://ghcr.io/hauler-dev --version 1.2.0
424453
425- # fetch remote helm chart
426- hauler store add chart rancher --repo https://releases.rancher.com/server-charts/stable
454+ # fetch remote helm chart
455+ hauler store add chart rancher --repo https://releases.rancher.com/server-charts/stable
427456
428- # fetch remote helm chart with specific version
429- hauler store add chart rancher --repo https://releases.rancher.com/server-charts/latest --version 2.10.1
457+ # fetch remote helm chart with specific version
458+ hauler store add chart rancher --repo https://releases.rancher.com/server-charts/latest --version 2.10.1
430459
431- # fetch remote helm chart and rewrite path
432- hauler store add chart hauler-helm --repo oci://ghcr.io/hauler-dev --rewrite custom-path/hauler-chart:latest` ,
460+ # fetch remote helm chart and rewrite path
461+ hauler store add chart hauler-helm --repo oci://ghcr.io/hauler-dev --rewrite custom-path/hauler-chart:latest` ,
433462 Args : cobra .ExactArgs (1 ),
434463 PreRunE : func (cmd * cobra.Command , args []string ) error {
435464 n , err := flags .ResolveConcurrency (cmd .Flags ().Changed ("concurrency" ), o .Concurrency )
@@ -471,25 +500,25 @@ func addStoreRemove(rso *flags.StoreRootOpts, ro *flags.CliRootOpts) *cobra.Comm
471500 Use : "remove <artifact-ref>" ,
472501 Short : "Remove an artifact from the content store" ,
473502 Example : ` # remove an image using full store reference
474- hauler store info
475- hauler store remove index.docker.io/library/busybox:stable
503+ hauler store info
504+ hauler store remove index.docker.io/library/busybox:stable
476505
477- # remove a chart using full store reference
478- hauler store info
479- hauler store remove hauler/rancher:2.8.4
506+ # remove a chart using full store reference
507+ hauler store info
508+ hauler store remove hauler/rancher:2.8.4
480509
481- # remove a file using full store reference
482- hauler store info
483- hauler store remove hauler/rke2-install.sh
510+ # remove a file using full store reference
511+ hauler store info
512+ hauler store remove hauler/rke2-install.sh
484513
485- # remove any artifact with the latest tag
486- hauler store remove :latest
514+ # remove any artifact with the latest tag
515+ hauler store remove :latest
487516
488- # remove any artifact with 'busybox' in the reference
489- hauler store remove busybox
517+ # remove any artifact with 'busybox' in the reference
518+ hauler store remove busybox
490519
491- # force remove without verification
492- hauler store remove busybox:latest --force` ,
520+ # force remove without verification
521+ hauler store remove busybox:latest --force` ,
493522 Args : cobra .ExactArgs (1 ),
494523 RunE : func (cmd * cobra.Command , args []string ) error {
495524 ctx := cmd .Context ()
0 commit comments