Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add comment
  • Loading branch information
Emyrk committed Nov 12, 2025
commit e8bf6def01bfcafc6e7ea7bf69aeebd10ab89ccd
14 changes: 11 additions & 3 deletions provisionersdk/tfpath/tfpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,17 @@ const (
sessionDirPrefix = "Session"
)

func Session(parent, sessionID string) Layout {
return Layout(filepath.Join(parent, sessionDirPrefix+sessionID))
// Session creates a directory structure layout for terraform execution. The
// SessionID is a unique value for creating an ephemeral working directory inside
// the parentDirPath. All helper functions will return paths for various
// terraform asserts inside this working directory.
func Session(parentDirPath, sessionID string) Layout {
return Layout(filepath.Join(parentDirPath, sessionDirPrefix+sessionID))
}

// Layout is the terraform execution working directory structure.
// It also contains some methods for common file operations within that layout.
// Such as "Cleanup" and "ExtractArchive".
// TODO: Maybe we should include the afero.FS here as well, then all operations
// would be on the same FS?
type Layout string
Expand Down Expand Up @@ -96,7 +103,8 @@ func (l Layout) ExtractArchive(ctx context.Context, logger slog.Logger, fs afero
if !filepath.IsLocal(header.Name) {
return xerrors.Errorf("refusing to extract to non-local path")
}
// nolint: gosec

// nolint: gosec // TODO: Use relative paths inside the workdir only.
headerPath := filepath.Join(l.WorkDirectory(), header.Name)
if !strings.HasPrefix(headerPath, filepath.Clean(l.WorkDirectory())) {
return xerrors.New("tar attempts to target relative upper directory")
Expand Down
Loading