Skip to content

feat: Add file:// URL scheme support for local release lists#609

Open
konan625 wants to merge 1 commit into
tofuutils:mainfrom
konan625:main
Open

feat: Add file:// URL scheme support for local release lists#609
konan625 wants to merge 1 commit into
tofuutils:mainfrom
konan625:main

Conversation

@konan625

Copy link
Copy Markdown

Description

Support offline version resolution by allowing file:// URLs in LIST_URL
environment variables. This enables air-gapped installations, restricted CI runners,
and enterprise networks to resolve versions from local files without network access.

Fixes #601

Changes

  • pkg/download/download.go: Detect file:// URLs and read from local filesystem
  • pkg/download/download_test.go: Add 4 tests for file:// URL handling
  • versionmanager/retriever/terraform/terraformretriever.go: Handle file:// URLs with filepath joining
  • README.md: Document feature with examples

Testing

✅ All unit tests pass
✅ Backward compatible - HTTP still works
✅ Manual E2E: Verified offline version resolution

Usage

export TFENV_LIST_URL=file:///opt/releases
tenv tf list-remote

Result

image

Support offline version resolution by allowing file:// URLs in LIST_URL
environment variables. This enables air-gapped installations, restricted
CI runners, and enterprise networks to resolve versions from local files
without network access.

Changes:
- pkg/download/download.go: Detect file:// URLs and read from local filesystem
- pkg/download/download_test.go: Add tests for file:// URL handling
- versionmanager/retriever/terraform/terraformretriever.go: Handle file:// URLs
  in path joining instead of url.JoinPath()
- README.md: Document file:// URL scheme support with examples

Fixes tofuutils#601

Signed-off-by: konan625 <aanchal625121@gmail.com>
Comment thread pkg/download/download.go
func Bytes(ctx context.Context, urlStr string, display func(string), checker ResponseChecker, requestOptions ...RequestOption) ([]byte, error) {
//Handle file:// URLs
//renaming urlstr to url to avoid shadowing the package name (net/url)
scheme, _, ok := strings.Cut(urlStr, "://")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe better to use CutPrefix

Comment thread pkg/download/download.go
return value, nil
}

func bytesFromFile(fileURL string) ([]byte, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you use CutPrefix in the caller, here you can have path directly as parameter and remove the TrimPrefix call

return nil, err
listURL := r.conf.Tf.GetListURL()
var baseURL string
if strings.HasPrefix(listURL, "file://") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here, HasPrefix and TrimPrefix can be replaced with CutPrefix too

// return nil, err
// }
var releasesURL string
if strings.HasPrefix(baseURL, "file://") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably better to store in a local var that it was a file scheme, instead of checking several times

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested improvements :

  • you can have a local var join typed func(string, string) (string, error) (wrap filepath.Join to match the signature in file use case)
  • concatenation of "file://" prefix should be done once at the end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support local file:// release lists for offline version resolution

2 participants