added env variables for haulerDir/tempDir

This commit is contained in:
Zack Brady
2024-11-02 13:58:30 -04:00
parent fb100a27ac
commit 78a42665a3
5 changed files with 21 additions and 13 deletions

View File

@@ -11,8 +11,9 @@ var ro = &flags.CliRootOpts{}
func New() *cobra.Command {
cmd := &cobra.Command{
Use: "hauler",
Short: "Airgap Swiss Army Knife",
Use: "hauler",
Short: "Airgap Swiss Army Knife",
Example: " View the Docs: https://docs.hauler.dev\n Environment Variables: HAULER_DIR | HAULER_TEMP_DIR",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
l := log.FromContext(cmd.Context())
l.SetLevel(ro.LogLevel)

View File

@@ -30,17 +30,21 @@ func LoadCmd(ctx context.Context, o *flags.LoadOpts, archiveRefs ...string) erro
// unarchiveLayoutTo accepts an archived oci layout and extracts the contents to an existing oci layout, preserving the index
func unarchiveLayoutTo(ctx context.Context, archivePath string, dest string, tempOverride string) error {
tmpdir, err := os.MkdirTemp(tempOverride, "hauler")
if tempOverride == "" {
tempOverride = os.Getenv("HAULER_TEMP_DIR")
}
tempDir, err := os.MkdirTemp(tempOverride, "hauler")
if err != nil {
return err
}
defer os.RemoveAll(tmpdir)
defer os.RemoveAll(tempDir)
if err := archiver.Unarchive(archivePath, tmpdir); err != nil {
if err := archiver.Unarchive(archivePath, tempDir); err != nil {
return err
}
s, err := store.NewLayout(tmpdir)
s, err := store.NewLayout(tempDir)
if err != nil {
return err
}

View File

@@ -14,11 +14,11 @@ import (
)
func TestNewChart(t *testing.T) {
tmpdir, err := os.MkdirTemp("", "hauler")
tempDir, err := os.MkdirTemp("", "hauler")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpdir)
defer os.RemoveAll(tempDir)
type args struct {
name string
@@ -53,7 +53,7 @@ func TestNewChart(t *testing.T) {
// {
// name: "should create from a chart directory",
// args: args{
// path: filepath.Join(tmpdir, "podinfo"),
// path: filepath.Join(tempDir, "podinfo"),
// },
// want: want,
// wantErr: false,

View File

@@ -256,7 +256,10 @@ func getCosignPath() (string, error) {
homeDir := currentUser.HomeDir
// Construct the path to the .hauler directory
haulerDir := filepath.Join(homeDir, ".hauler")
haulerDir := os.Getenv("HAULER_DIR")
if haulerDir == "" {
haulerDir = filepath.Join(homeDir, ".hauler")
}
// Create the .hauler directory if it doesn't exist
if _, err := os.Stat(haulerDir); os.IsNotExist(err) {

View File

@@ -63,16 +63,16 @@ func TestLayout_AddOCI(t *testing.T) {
}
func setup(t *testing.T) func() error {
tmpdir, err := os.MkdirTemp("", "hauler")
tempDir, err := os.MkdirTemp("", "hauler")
if err != nil {
t.Fatal(err)
}
root = tmpdir
root = tempDir
ctx = context.Background()
return func() error {
os.RemoveAll(tmpdir)
os.RemoveAll(tempDir)
return nil
}
}