Skip to content

Fix Artifactory store and improve store documentation - #2038

Merged
Andriy Knysh (aknysh) merged 6 commits into
mainfrom
osterman/store-docs-improve
Jan 29, 2026
Merged

Andriy Knysh (aknysh) merged 6 commits into
mainfrom
osterman/store-docs-improve

Conversation

@osterman

@osterman Erik Osterman (Cloud Posse) (osterman) commented Jan 29, 2026 •

Copy link
Copy Markdown
Member

what

  • Fixed Artifactory store integration by adding Flat=true parameter to JFrog SDK downloads and proper directory path handling
  • Corrected store documentation to match actual implementation: fixed field names, store type names, and removed unsupported backends
  • Added comprehensive integration tests for Artifactory store with mock HTTP server
  • Added blog post announcing the fix

why

Customer reported retrieval issues with Artifactory store. Investigation revealed two problems:

  1. Store code was missing JFrog SDK configuration needed for proper file downloads
  2. Documentation contained errors that did not match the actual implementation (unsupported backends, incorrect field names)

The Artifactory GetKey method lacked the same configuration that the Get method had, causing downloads to fail. Documentation had outdated examples with unsupported stores (Vault, AWS Secrets Manager) and wrong field names (backend/config instead of type/options).

Customer-reported issue

Customer logs showed the exact problem this PR fixes:

[Info] Downloading "atmos_store/dev/myapp/private_ip" to "/tmp/atmos-artifactory.../dev/myapp/private_ip"
...
Error: failed to read file: open /tmp/atmos-artifactory.../private_ip: no such file or directory

Root cause: Without Flat=true, the JFrog SDK preserves the directory structure when downloading:

  • SDK downloads to: /tmp/atmos-artifactory.../dev/myapp/private_ip (nested path)
  • Code expects: /tmp/atmos-artifactory.../private_ip (flat path)

The fix: Adding downloadParams.Flat = true tells the SDK to download files directly to the temp directory with just the base filename, matching what the code expects.

The Get method already had this configuration (which is why !store with stack/component/key worked), but GetKey was missing it.

references

  • All Artifactory store integration tests now pass
  • Documentation is consistent with actual supported backends: aws-ssm-parameter-store, azure-key-vault, google-secret-manager, redis, artifactory
  • Mock server properly validates JFrog SDK integration patterns including AQL search, checksum validation, and file path handling

Summary by CodeRabbit

  • Bug Fixes

    • Fixed Artifactory retrieval to correctly handle nested paths and ensure consistent download behavior for Get/GetKey.
  • Documentation

    • Updated Artifactory store guidance, repository recommendations, store backend identifiers, tutorials, examples, and added a blog post describing the fix and configuration guidance.
  • Tests

    • Added comprehensive Artifactory integration tests and a deterministic Artifactory mock server for testing.

✏️ Tip: You can customize this high-level summary in your review settings.

@github-actions github-actions Bot added the size/l Large size PR label Jan 29, 2026
@github-actions

github-actions Bot commented Jan 29, 2026 •

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues found.

Scanned Files

None

@osterman Erik Osterman (Cloud Posse) (osterman) added the patch A minor, backward compatible change label Jan 29, 2026
@codecov

codecov Bot commented Jan 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.55%. Comparing base (34ef473) to head (83591fe).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2038      +/-   ##
==========================================
+ Coverage   75.50%   75.55%   +0.05%     
==========================================
  Files         793      793              
  Lines       73713    73718       +5     
==========================================
+ Hits        55657    55699      +42     
+ Misses      14562    14524      -38     
- Partials     3494     3495       +1     
Flag Coverage Δ
unittests 75.55% <100.00%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
pkg/store/artifactory_store.go 67.41% <100.00%> (+19.43%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Replace unsafe string formatting with struct-based JSON marshaling
to address CodeQL security alert about potentially unsafe quoting.

Uses struct field ordering to ensure "results" comes before "range"
in the JSON output, which is required by the JFrog SDK's ContentReader.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Jan 29, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Set download params to flatten results and normalize temporary download directories in Artifactory store Get/GetKey; add an Artifactory mock server and integration tests; update documentation and examples to use new store type names and Artifactory guidance.

Changes

Cohort / File(s) Summary
Core Store Fix
pkg/store/artifactory_store.go
Set downloadParams.Flat = true in Get and GetKey; normalize and Clean tempDir and ensure trailing path separator; switch URL path construction to path.Join where appropriate (nolint noted).
Artifactory Mock & Unit Tests
tests/testhelpers/httpmock/artifactory_mock.go, tests/testhelpers/httpmock/artifactory_mock_test.go
Add ArtifactoryMockServer with thread-safe in-memory file store, upload (PUT), download (GET), and AQL search (POST) handlers; add tests for upload/download, AQL, ListFiles, and Clear.
Store Integration Tests
tests/store_artifactory_test.go
Add integration-style tests exercising Set/Get, GetKey, nested paths, error cases, and JSON storage/retrieval using the mock server.
Documentation & Blog
website/blog/2026-01-29-artifactory-store-fix.mdx, website/docs/cli/configuration/stores.mdx, website/docs/stacks/hooks.mdx, website/docs/tutorials/sharing-state/stores.mdx
Document the Artifactory store fix and configuration; update examples and store identifiers (e.g., aws-ssm-parameter-store), remove Vault examples, add Artifactory/Redis guidance and env-var access_token recommendation.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant Client
participant ArtifactoryStore
participant ArtifactoryAPI
participant Filesystem
Client->>ArtifactoryStore: Request Get/GetKey(key, tempDir)
note right of ArtifactoryStore: normalize tempDir (Clean + trailing sep)
ArtifactoryStore->>ArtifactoryAPI: AQL search or direct GET (query path)
ArtifactoryAPI-->>ArtifactoryStore: Metadata / file list
ArtifactoryStore->>ArtifactoryAPI: Download files (Flat = true)
ArtifactoryAPI-->>ArtifactoryStore: File archive/contents
ArtifactoryStore->>Filesystem: Unpack/write to normalized tempDir
Filesystem-->>ArtifactoryStore: Files available
ArtifactoryStore-->>Client: Return path / contents

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • add artifactory store #921: Updates to the Artifactory store implementation affecting Get/GetKey download behavior and related tests.

Suggested reviewers

  • osterman
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the two main changes: fixing Artifactory store functionality and improving store documentation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch osterman/store-docs-improve

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Focus on the user-facing problem (Artifactory retrieval failing with
nested paths) rather than internal implementation details.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Jan 29, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

The head commit changed during the review from fc6779b to 40efc16.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch osterman/store-docs-improve

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jan 29, 2026
On Windows, filepath.Join uses backslashes which breaks Artifactory
API paths. Use path.Join which always uses forward slashes for URL paths.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Erik Osterman (Cloud Posse) (osterman) added a commit that referenced this pull request Jan 29, 2026
Allow users to test Atmos features from PRs without installing Go or manually
downloading artifacts from GitHub Actions UI. Extend --use-version to support
PR numbers using the pr:NNNN format (e.g., --use-version pr:2038).

Key features:
- Smart GitHub token detection (ATMOS_GITHUB_TOKEN, GITHUB_TOKEN, or gh CLI)
- Automatic platform detection for Linux/macOS/Windows
- Download and extract artifacts from successful PR CI runs
- Caching of downloaded binaries for reuse
- Clear error messages for missing tokens, failed CI, unsupported platforms

New packages:
- pkg/github/: GitHub API integration for PR artifact retrieval
- toolchain/pr_artifact.go: PR artifact download and installation logic

Modified:
- pkg/version/reexec.go: Added PR version detection in version switching
- toolchain/install.go: Added PR version detection in tool installation

Implements #2038.

Co-Authored-By: Claude Haiku 4.5 <[email protected]>
@aknysh
Andriy Knysh (aknysh) merged commit fb80cbe into main Jan 29, 2026
92 of 93 checks passed
@aknysh
Andriy Knysh (aknysh) deleted the osterman/store-docs-improve branch January 29, 2026 20:59
@github-actions

Copy link
Copy Markdown

These changes were released in v1.205.1-rc.0.

Erik Osterman (Cloud Posse) (osterman) added a commit that referenced this pull request Jan 30, 2026
Allow users to test Atmos features from PRs without installing Go or manually
downloading artifacts from GitHub Actions UI. Extend --use-version to support
PR numbers using the pr:NNNN format (e.g., --use-version pr:2038).

Key features:
- Smart GitHub token detection (ATMOS_GITHUB_TOKEN, GITHUB_TOKEN, or gh CLI)
- Automatic platform detection for Linux/macOS/Windows
- Download and extract artifacts from successful PR CI runs
- Caching of downloaded binaries for reuse
- Clear error messages for missing tokens, failed CI, unsupported platforms

New packages:
- pkg/github/: GitHub API integration for PR artifact retrieval
- toolchain/pr_artifact.go: PR artifact download and installation logic

Modified:
- pkg/version/reexec.go: Added PR version detection in version switching
- toolchain/install.go: Added PR version detection in tool installation

Implements #2038.

Co-Authored-By: Claude Haiku 4.5 <[email protected]>
Andriy Knysh (aknysh) added a commit that referenced this pull request Feb 18, 2026
* feat: add support for PR artifacts in --use-version flag

Allow users to test Atmos features from PRs without installing Go or manually
downloading artifacts from GitHub Actions UI. Extend --use-version to support
PR numbers using the pr:NNNN format (e.g., --use-version pr:2038).

Key features:
- Smart GitHub token detection (ATMOS_GITHUB_TOKEN, GITHUB_TOKEN, or gh CLI)
- Automatic platform detection for Linux/macOS/Windows
- Download and extract artifacts from successful PR CI runs
- Caching of downloaded binaries for reuse
- Clear error messages for missing tokens, failed CI, unsupported platforms

New packages:
- pkg/github/: GitHub API integration for PR artifact retrieval
- toolchain/pr_artifact.go: PR artifact download and installation logic

Modified:
- pkg/version/reexec.go: Added PR version detection in version switching
- toolchain/install.go: Added PR version detection in tool installation

Implements #2038.

Co-Authored-By: Claude Haiku 4.5 <[email protected]>

* chore: improve PR artifact installation UX

- Add SHA and timestamp to "Found workflow run" message
- Use spinner pattern for download+install (replaces separate messages)
- Format timestamp in user-friendly format (e.g., "Jan 29, 2025 at 3:04 PM")
- Show short SHA (7 chars) with markdown backticks for styling
- Extract downloadAndInstallArtifact helper for cleaner code

New output format:
✓ Found workflow run #21489525938 (sha: `ceb7526`) from Jan 29, 2026 at 12:11 PM
✓ Installed to ~/.local/share/atmos/toolchain/bin/cloudposse/atmos/pr-2040/atmos

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* refactor: remove SHA version support and add semver validation

- Remove SHA version support (sha:XXXXXXX and auto-detected SHAs)
- Add semver validation - reject invalid inputs like 'abc', 'abc123'
- Delete toolchain/sha_artifact.go
- Update ParseVersionSpec to return error for invalid formats
- Add isValidSemver() function for version validation
- Remove GetSHAArtifactInfo from pkg/github/artifacts.go
- Update blog post and PR description to not mention SHA

Invalid version formats now show helpful error:
  ✗ Error: invalid version format 'abc'
    💡 Version must be a PR number, pr:NNNN, or semver (e.g., 1.2.3)

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* security: fix Zip Slip vulnerability in artifact extraction (CodeQL)

Add proper path sanitization to prevent Zip Slip attacks when extracting
downloaded PR artifacts. The `sanitizeZipPath()` function now:

- Rejects absolute paths (Unix and Windows style)
- Rejects paths containing backslash (Windows-style traversal on Unix)
- Rejects paths containing ".." traversal components
- Verifies the final path stays within the destination directory

Added comprehensive tests for all attack patterns.

Fixes CodeQL alert: "Arbitrary file access during archive extraction"

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* fix: prevent panic on short HeadSHA and update roadmap PR link

- Add length check before slicing HeadSHA to prevent potential panic
  (CodeRabbit suggestion)
- Add PR number (2040) to roadmap milestone entry

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* docs: update roadmap to show PR number auto-detection

The `pr:` prefix is optional - just use the PR number directly.

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* feat: add SHA-based artifact installation support

Add support for installing Atmos from a specific commit SHA's build
artifact, similar to PR-based installation.

Changes:
- Add SHAArtifactInfo type and GetSHAArtifactInfo function to github pkg
- Add error checking helper functions (IsNotFoundError, etc.)
- Add toolchain/sha_artifact.go for SHA-based installation
- Update version_spec to support SHA version parsing
- Fix Windows test failures: use platform-specific binary name in tests

The SHA installation allows users to install a specific commit's build:
  atmos --use-version sha:ceb7526

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* docs: update blog post and roadmap for PR artifact installation

Update documentation to reflect the SHA-based installation support
and fix any remaining content in the PR artifact installation blog post.

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* fix: add PR number validation and download timeout for artifact installation

- Add 5-minute timeout for artifact downloads to prevent hanging
- Validate PR numbers must be positive integers (reject 0, negative, non-numeric)
- Add tests for invalid PR format edge cases

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* fix: address PR review comments and lint issues

- Add sha: prefix validation in ParseVersionSpec using isValidSHA()
- Extract parsePRPrefix/parseSHAPrefix helpers to reduce cyclomatic complexity
- Add inline filepath.Rel() Zip Slip guard to satisfy CodeQL scanner
- Wrap 5 error sites in reexec.go with errUtils.Build() and sentinels
- Add 5 invalid sha: test cases and errors.Is assertions in tests
- Fix missing comment periods for godot linter compliance
- Refactor cli_utils.go: table-driven terraform two-word commands,
  extract helpers to fix nestif/err113/revive lint issues

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* test: add comprehensive tests for artifact installation and error handling

- Add tests for IsNotFoundError, artifact URL construction, and platform support
- Add tests for PR artifact installation flow, zip extraction, and Zip Slip protection
- Add SHA artifact test suite with installation, cache status, and error paths
- Improve error assertions to use errors.Is with sentinel errors

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* test: add mock-based unit tests for GitHub artifact functions

Introduce PullRequestService and ActionsService interfaces following the
established ratelimit.go pattern, enabling deterministic unit tests without
network calls. Export ArtifactFetcher struct with NewArtifactFetcher
constructor for test injection. Refactor private helpers to accept interfaces
and generate mocks via mockgen.

Adds 21 new unit tests covering getPRHeadSHA, findSuccessfulWorkflowRun,
findArtifactByName, GetArtifactDownloadURL, GetPRArtifactInfo, and
GetSHAArtifactInfo with success, error propagation, and sentinel error cases.

Also fixes a minor grammar issue in a trailing comment.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* fix: add nil-safety guards and godot linter fixes for GitHub artifacts

Guard against nil responses from ListRepositoryWorkflowRuns and
ListWorkflowRunArtifacts to prevent panics. Add trailing periods to
section-divider comments to satisfy the godot linter.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* feat: add tests, fix CodeRabbit feedback, and update docs for PR/SHA artifact installation

Add comprehensive mock-based unit tests for PR and SHA artifact installation
paths across pkg/version, pkg/toolchain, and pkg/github packages. Fix
end-of-flags delimiter (--) handling in root command for --use-version and
--chdir flags. Address CodeRabbit review feedback including interface-based
DI for GitHub API clients, improved error messages, and token detection
chain fixes. Update PRD and blog post to reflect fully-implemented status
with current architecture details.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

---------

Co-authored-by: Claude Haiku 4.5 <[email protected]>
Co-authored-by: Andriy Knysh <[email protected]>
Co-authored-by: aknysh <[email protected]>

This branch was successfully deployed

1 active deployment
preview — 83591fe7 Deployed Jan 29, 2026 by github-actions[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch A minor, backward compatible change size/l Large size PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants