Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supported the atmos.d, allowing automatic inclusion of configuration files from the atmos.d directory #808

Open
wants to merge 57 commits into
base: main
Choose a base branch
from

Conversation

haitham911
Copy link
Collaborator

@haitham911 haitham911 commented Nov 24, 2024

what

  • Supported the atmos.d convention for atmos.yaml configuration, allowing automatic inclusion of configuration files from the atmos.d directory.
    Made the path to atmos.d configurable within atmos.yaml, enabling users to specify custom directories for additional configurations.
    Implemented deep merging of configurations in lexicographical order, recursively processing files within specified directories to ensure consistent and predictable configuration outcomes.
    Added support for the import key inside atmos.yaml, allowing users to define a list of locations (local files, directories using glob patterns, and remote URLs) to import configurations from.

  • expose env variable ATMOS_CLI_CONFIG_PATH and ATMOS_BASE_PATH before run terraform and helm cmd

  • demos :

    • examples/demo-env for expose env variable
    • demo-atmos-cli-imports for custom inclusion of configuration files from the atmos.d directory
    • demo-atmos.d for automatic inclusion of configuration files from the atmos.d directory

why

Simplifies configuration management by adopting the atmos.d directory convention, making it easier to include additional configurations without explicit declarations.

references

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced a new configuration file atmos.yaml for managing imports and settings.
    • Added a custom CLI command "test" for running all tests.
    • Enhanced logging configuration options for better monitoring and debugging.
    • New configuration sections for managing stacks and Terraform components.
    • Added support for remote and local import paths in CLI configuration.
    • New parameters for Helmfile configuration to enhance deployment flexibility.
    • Introduced new YAML configuration files for various environments (dev, prod, staging).
    • Added new configuration options for vendor management.
  • Bug Fixes

    • Improved error handling for configuration loading.
  • Tests

    • Added unit tests for configuration loading functionality, covering various scenarios.
  • Documentation

    • Updated documentation for atmos.yaml configuration file, including new import paths and usage guidelines.

Copy link
Contributor

coderabbitai bot commented Nov 24, 2024

📝 Walkthrough
📝 Walkthrough

The changes in this pull request introduce a comprehensive update to the configuration management of the Atmos CLI. A new configuration file, atmos.yaml, is added to facilitate the management of components, stacks, vendors, logging, and custom commands. The CLI configuration loading logic has been enhanced to prioritize environment variables and support importing configurations from various sources. Additionally, multiple new YAML files have been created to define specific settings for Terraform, stacks, and Helmfile components, along with improved logging configurations.

Changes

File Path Change Summary
examples/demo-atmos.d/atmos.yaml New configuration file added for Atmos CLI, detailing components, stacks, vendors, logging, and commands.
pkg/config/config.go Modified InitCliConfig to prioritize ATMOS_CLI_CONFIG_PATH, added processImports function for handling imports.
pkg/schema/schema.go New field Import added to CliConfiguration struct for specifying import paths.
pkg/utils/glob_utils.go Modified GetGlobMatches to include sorting functionality for matches.
pkg/config/config_test.go New unit tests for configuration loading functionality.
examples/demo-atmos.d/atmos.d/commands.yaml New command "test" added to run all tests.
examples/demo-atmos-cli-imports/atmos.yaml New custom import configuration file added for loading configurations from multiple sources.
examples/demo-atmos-cli-imports/configs.d/commands.yaml New command "test" added to run all tests.
examples/demo-atmos-cli-imports/configs.d/tools/stack.yml New configuration section for stack management added.
examples/demo-atmos-cli-imports/configs.d/tools/terraform.yaml New configuration section for Terraform components added.
examples/demo-atmos-cli-imports/configs.d/vendor.yaml New vendor configuration structure added.
examples/demo-atmos-cli-imports/logs.yaml New logging configuration added, directing logs to standard error with debug level.
examples/demo-atmos.d/atmos.d/logs.yaml New logging configuration added, directing logs to standard error with debug level.
examples/demo-atmos.d/atmos.d/tools/helmfile.yml New configuration section for Helmfile components added.
examples/demo-atmos.d/atmos.d/tools/stack.yaml New configuration section for stacks added.
examples/demo-atmos.d/atmos.d/tools/terraform.yaml New configuration section for Terraform components added.

Assessment against linked issues

Objective Addressed Explanation
Support "atmos.d" convention for atmos.yaml configuration (DEV-1534)
Configurations should deep merge in lexicographical order, recursively in the folder (DEV-1534)
Add support for imports in atmos.yaml (DEV-1534)
Non-existent paths should be logged as warnings (DEV-1534) Logging for non-existent paths not implemented.
It should support importing files from local files and directories using double star filesearch (DEV-1534)

Possibly related PRs

Suggested reviewers

  • Gowiem
  • aknysh

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or @auto-summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @auto-title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 9

🧹 Outside diff range and nitpick comments (7)
examples/demo-atmos.d/atmos.yaml (3)

4-11: Document security-sensitive settings

Critical settings like apply_auto_approve and auto_generate_backend_file would benefit from inline documentation explaining their security implications.

Consider adding comments:

 components:
   terraform:
     base_path: "components/terraform"
+    # Disable auto-approve for safety in production environments
     apply_auto_approve: false
     deploy_run_init: true
     init_run_reconfigure: true
+    # Disable auto-generation of backend files to prevent unauthorized state access
     auto_generate_backend_file: false

12-19: Consider expanding name pattern flexibility

The current name pattern only supports {stage}. Consider supporting additional variables for better organization.

Consider expanding:

-  name_pattern: "{stage}"
+  name_pattern: "{org}-{stage}-{component}"

20-29: Clean up formatting and enhance documentation

The vendor configuration contains helpful examples but needs formatting cleanup.

Apply these changes:

-vendor:  
+vendor:
   # Single file
-  base_path: "./vendor.yaml"
+  base_path: "./vendor.yaml"  # Default configuration
   
   # Directory with multiple files
   #base_path: "./vendor"
   
   # Absolute path
   #base_path: "vendor.d/vendor1.yaml"
🧰 Tools
🪛 yamllint (1.29.0-1)

[error] 20-20: trailing spaces

(trailing-spaces)


[error] 23-23: trailing spaces

(trailing-spaces)


[error] 26-26: trailing spaces

(trailing-spaces)

examples/demo-atmos.d/custom-import/atmos.yaml (2)

26-35: Consider moving configuration examples to documentation

While the commented examples are helpful, they might be better suited in the documentation, keeping the configuration file cleaner.

-  # Single file
   base_path: "./vendor.yaml"
-  
-  # Directory with multiple files
-  #base_path: "./vendor"
-  
-  # Absolute path
-  #base_path: "vendor.d/vendor1.yaml"
🧰 Tools
🪛 yamllint (1.29.0-1)

[error] 26-26: trailing spaces

(trailing-spaces)


[error] 29-29: trailing spaces

(trailing-spaces)


[error] 32-32: trailing spaces

(trailing-spaces)


36-38: Consider environment-specific log configurations

The current logging setup is good for development, but you might want to add environment-specific configurations for production use.

Example addition:

logs:
  file: "${ATMOS_LOG_FILE:-/dev/stderr}"
  level: "${ATMOS_LOG_LEVEL:-Info}"
pkg/schema/schema.go (1)

29-29: Add field documentation.

Consider adding a documentation comment to describe the purpose and usage of the Import field, following Go's documentation conventions.

Add this documentation above the field:

+	// Import specifies a list of paths from which to import additional configurations.
+	// Supports local files, directories (using glob patterns), and remote URLs.
 	Import                        []string       `yaml:"import" json:"import" mapstructure:"import"`
pkg/config/config.go (1)

231-232: Combine the return statement for clarity

The return statement is unnecessarily split across two lines.

Consider writing it on a single line:

-return cliConfig,
-    err
+return cliConfig, err
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4b30800 and 052673b.

📒 Files selected for processing (10)
  • examples/demo-atmos.d/atmos.d/configs.d/config1.yaml (1 hunks)
  • examples/demo-atmos.d/atmos.d/configs.d/sub/config2.yaml (1 hunks)
  • examples/demo-atmos.d/atmos.yaml (1 hunks)
  • examples/demo-atmos.d/custom-import/atmos.yaml (1 hunks)
  • examples/demo-atmos.d/custom-import/configs.d/config1.yaml (1 hunks)
  • examples/demo-atmos.d/custom-import/configs.d/sub/config2.yaml (1 hunks)
  • examples/demo-atmos.d/custom-import/extra-config.yaml (1 hunks)
  • pkg/config/config.go (3 hunks)
  • pkg/schema/schema.go (1 hunks)
  • pkg/utils/glob_utils.go (2 hunks)
✅ Files skipped from review due to trivial changes (5)
  • examples/demo-atmos.d/atmos.d/configs.d/config1.yaml
  • examples/demo-atmos.d/atmos.d/configs.d/sub/config2.yaml
  • examples/demo-atmos.d/custom-import/configs.d/config1.yaml
  • examples/demo-atmos.d/custom-import/configs.d/sub/config2.yaml
  • examples/demo-atmos.d/custom-import/extra-config.yaml
🧰 Additional context used
🪛 yamllint (1.29.0-1)
examples/demo-atmos.d/atmos.yaml

[error] 20-20: trailing spaces

(trailing-spaces)


[error] 23-23: trailing spaces

(trailing-spaces)


[error] 26-26: trailing spaces

(trailing-spaces)


[warning] 38-38: wrong indentation: expected 2 but found 0

(indentation)


[warning] 41-41: wrong indentation: expected 4 but found 2

(indentation)

examples/demo-atmos.d/custom-import/atmos.yaml

[error] 26-26: trailing spaces

(trailing-spaces)


[error] 29-29: trailing spaces

(trailing-spaces)


[error] 32-32: trailing spaces

(trailing-spaces)


[warning] 44-44: wrong indentation: expected 2 but found 0

(indentation)


[warning] 47-47: wrong indentation: expected 4 but found 2

(indentation)

🔇 Additional comments (6)
examples/demo-atmos.d/atmos.yaml (1)

30-33: Add validation for log levels

Consider adding validation to ensure only valid log levels (Debug, Info, Warning, Error) are accepted.

examples/demo-atmos.d/custom-import/atmos.yaml (3)

7-9: Consider adding URL validation for remote configurations

While loading from remote URLs provides flexibility, it could pose security risks. Consider implementing URL validation and HTTPS enforcement.

Would you like me to propose a validation pattern for secure URL handling?


18-24: Strong stack configuration, warrior! 💪

The stack configuration is well-structured with clear inclusion/exclusion patterns and a simple naming convention.


11-16: Verify backend file management strategy

Setting auto_generate_backend_file: false means you'll need to manage backend configurations manually. This is a valid choice but requires careful consideration.

Run this check to ensure consistent backend configuration across components:

✅ Verification successful

Setting auto_generate_backend_file: false is appropriate for this setup

The configuration choice is valid as there's no existing Terraform component directory at the specified path, indicating this is likely a new project setup. Manual backend management is a reasonable approach when starting fresh, allowing for more controlled and explicit backend configuration as the project evolves.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for existing backend configurations
fd -e tf -e hcl . components/terraform -x grep -l 'backend'

Length of output: 167


Script:

#!/bin/bash
# First, let's verify if the components/terraform directory exists and check the directory structure
fd --type d terraform

# Then, let's search for backend configurations across all Terraform files in the repository
fd -e tf -e hcl . -x grep -l 'backend'

# Also check for any Terraform component references in the atmos configuration
fd -g "*.yaml" -x grep -A 5 -B 5 "terraform:"

Length of output: 33961


Script:

#!/bin/bash
# Let's check for backend configurations in the actual Terraform components
fd -t f -e tf . examples/demo-atmos.d/custom-import/components/terraform -x grep -l 'backend'

# Also check for any backend configuration files
fd -t f -g "*.backend.tf" -g "backend.tf" examples/demo-atmos.d/custom-import/components/terraform

# Check if there are any existing backend configurations in the component directory
ls -la examples/demo-atmos.d/custom-import/components/terraform/

Length of output: 709

pkg/utils/glob_utils.go (2)

7-7: LGTM! Clean import addition, warrior!

The sort package import is well-placed and necessary for the new functionality.


Line range hint 19-48: Verify caching behavior for dynamic configurations, brave one!

The caching mechanism using sync.Map could prevent picking up new configuration files added to atmos.d during runtime. Additionally, we should verify that the error handling aligns with the requirement to log non-existent paths as warnings.

Let's verify the implementation:

✅ Verification successful

Cache invalidation is not a concern, brave warrior!

The caching mechanism in GetGlobMatches is pattern-based, which means:

  • Each unique glob pattern gets its own cache entry
  • When a new file is added that matches an existing pattern, it will be discovered on the next process restart
  • The cache is process-scoped (using sync.Map), so it's automatically cleared between runs
  • Error handling correctly returns both the error and logs the non-existent paths

The implementation aligns perfectly with the requirements:

  1. Cache is scoped to the current process, preventing stale state between runs
  2. Error handling returns descriptive errors for non-existent paths: failed to find a match for the import '%s' ('%s' + '%s')
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for warning logs related to non-existent paths and cache invalidation

# Search for warning log implementations
rg -A 2 "failed to find a match for the import" .

# Check if there's any cache invalidation mechanism
rg -A 5 "getGlobMatchesSyncMap" .

# Look for any warning level log statements
rg -A 2 "Warning|WARN|warn" .

Length of output: 47400

examples/demo-atmos.d/atmos.yaml Show resolved Hide resolved
examples/demo-atmos.d/atmos.yaml Outdated Show resolved Hide resolved
examples/demo-atmos.d/custom-import/atmos.yaml Outdated Show resolved Hide resolved
pkg/utils/glob_utils.go Outdated Show resolved Hide resolved
pkg/schema/schema.go Outdated Show resolved Hide resolved
pkg/config/config.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 63ffce1 and 4493540.

📒 Files selected for processing (2)
  • pkg/config/config.go (3 hunks)
  • pkg/schema/schema.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/schema/schema.go
🔇 Additional comments (1)
pkg/config/config.go (1)

231-232: LGTM! Clean error handling.

The multi-line error return improves readability.

pkg/config/config.go Outdated Show resolved Hide resolved
pkg/config/config.go Outdated Show resolved Hide resolved
pkg/config/config.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
examples/demo-atmos.d/custom-import/atmos.yaml (2)

26-34: Clean up trailing spaces

Remove trailing spaces from lines 26, 29, and 32 for better maintainability.

-vendor:  
+vendor:
 # Single file
-base_path: "./vendor.yaml"
+base_path: "./vendor.yaml"
 
 # Directory with multiple files
-#base_path: "./vendor"
+#base_path: "./vendor"
🧰 Tools
🪛 yamllint (1.29.0-1)

[error] 26-26: trailing spaces

(trailing-spaces)


[error] 29-29: trailing spaces

(trailing-spaces)


[error] 32-32: trailing spaces

(trailing-spaces)


36-38: Logging configuration is good but could be enhanced

Current configuration is solid. Consider adding:

  • Log rotation settings
  • Format specification
  • Additional log destinations for production environments
pkg/config/config.go (1)

401-444: Consider adding rate limiting and path validation

The import processing is robust, but consider these enhancements:

  1. Add rate limiting for remote downloads to prevent abuse
  2. Validate import paths before processing to ensure they're safe
 func processImports(cliConfig schema.CliConfiguration, v *viper.Viper) error {
+    // Add rate limiting for remote downloads
+    rateLimiter := time.NewTicker(time.Second)
+    defer rateLimiter.Stop()
+
     for _, importPath := range cliConfig.Import {
         if importPath == "" {
             continue
         }
+        // Basic path validation
+        if strings.Contains(importPath, "..") {
+            u.LogWarning(cliConfig, fmt.Sprintf("Warning: skipping potentially unsafe import path '%s'", importPath))
+            continue
+        }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4493540 and d9a3517.

📒 Files selected for processing (4)
  • examples/demo-atmos.d/atmos.d/config1.yaml (1 hunks)
  • examples/demo-atmos.d/atmos.d/sub/config2.yaml (1 hunks)
  • examples/demo-atmos.d/custom-import/atmos.yaml (1 hunks)
  • pkg/config/config.go (3 hunks)
✅ Files skipped from review due to trivial changes (2)
  • examples/demo-atmos.d/atmos.d/config1.yaml
  • examples/demo-atmos.d/atmos.d/sub/config2.yaml
🧰 Additional context used
🪛 yamllint (1.29.0-1)
examples/demo-atmos.d/custom-import/atmos.yaml

[error] 26-26: trailing spaces

(trailing-spaces)


[error] 29-29: trailing spaces

(trailing-spaces)


[error] 32-32: trailing spaces

(trailing-spaces)

🔇 Additional comments (7)
examples/demo-atmos.d/custom-import/atmos.yaml (4)

11-16: Terraform security settings look good!

The Terraform component configuration follows security best practices:

  • apply_auto_approve: false prevents unintended infrastructure changes
  • auto_generate_backend_file: false ensures explicit backend configuration

18-24: Stack configuration structure is well-organized!

Good use of:

  • Explicit path inclusions/exclusions
  • Clear naming pattern
  • Logical directory structure

43-47: Command configuration looks good!

The test command is well-defined with clear description and steps.


7-9: Verify security measures for remote configuration imports

The remote URL import capability could pose security risks. Ensure that:

  1. HTTPS is enforced for remote URLs
  2. URL validation is implemented
  3. Content verification is performed before applying configurations

Consider implementing:

  • URL allowlist/blocklist
  • SSL certificate validation
  • Content integrity checks (e.g., checksums)
pkg/config/config.go (3)

231-232: Clean error handling format!

The multi-line error return improves readability while maintaining functionality.


239-250: Validate path to prevent directory traversal

While the implementation correctly handles the atmos.d directory existence, consider adding path validation as suggested in the past review to prevent potential path traversal attacks.


446-464: Add safeguards to remote downloads

The download function needs the safeguards mentioned in the past review:

  1. Context timeout
  2. File size limits
  3. Temporary directory cleanup

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (4)
pkg/config/config.go (4)

231-232: Consider using idiomatic Go error handling.

While splitting the return statement improves readability, consider using the more idiomatic Go style:

-		return cliConfig,
-			err
+		return cliConfig, fmt.Errorf("failed to unmarshal config: %w", err)

239-256: Strong implementation with robust security measures!

The atmos.d directory support is well-implemented with proper path validation and error handling. The path traversal prevention is particularly noteworthy.

Consider adding more context to the error message:

-			return cliConfig, fmt.Errorf("invalid atmos.d path: attempted directory traversal")
+			return cliConfig, fmt.Errorf("invalid atmos.d path '%s': attempted directory traversal outside base path '%s'", atmosDPath, basePath)

257-269: Consider adding debug logging for configuration merging.

The import processing logic is sound, but adding debug logs would help troubleshoot configuration issues.

 		err = v.Unmarshal(&cliConfig)
 		if err != nil {
+			u.LogTrace(cliConfig, fmt.Sprintf("Failed to unmarshal merged config: %v", err))
 			return cliConfig, err
 		}
+		u.LogTrace(cliConfig, "Successfully merged and unmarshaled imported configurations")

407-459: Consider parallel processing for multiple imports.

The implementation is robust with proper error handling and path validation. However, processing imports sequentially might be slow for many imports.

Consider using a worker pool for parallel processing:

 func processImports(cliConfig schema.CliConfiguration, v *viper.Viper) error {
+	type importResult struct {
+		path string
+		err  error
+	}
+	workers := make(chan struct{}, 4) // Limit concurrent downloads
+	results := make(chan importResult)
+
 	for _, importPath := range cliConfig.Import {
-		if importPath == "" {
-			continue
-		}
+		go func(imp string) {
+			workers <- struct{}{} // Acquire worker
+			defer func() { <-workers }() // Release worker
+			
+			if imp == "" {
+				results <- importResult{"", nil}
+				return
+			}
+			// ... rest of the import processing logic ...
+		}(importPath)
 	}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d9a3517 and 089a82f.

📒 Files selected for processing (1)
  • pkg/config/config.go (3 hunks)
🔇 Additional comments (1)
pkg/config/config.go (1)

461-479: Past review comment about remote download safeguards is still applicable.

The previous review comment suggesting context timeout, file size limits, and temporary directory cleanup remains valid.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
pkg/config/config.go (1)

232-233: Combine the return statement into a single line

The return statement is split across two lines. Merging it into one line enhances readability.

Apply this diff:

-		return cliConfig,
-			err
+		return cliConfig, err
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 089a82f and c020d63.

📒 Files selected for processing (1)
  • pkg/config/config.go (3 hunks)
🔇 Additional comments (4)
pkg/config/config.go (4)

240-257: Good handling of the 'import' key and path security

The logic for setting the default Import path when it's empty is well-implemented. Ensuring the path doesn't escape the intended directory adds a valuable security check.


259-270: Import processing added effectively

The addition of import processing and re-unmarshalling is correctly handled. Error checks are appropriately placed.


417-426: Consider validating remote URLs for security

Currently, any URL starting with "http://" or "https://" is accepted. Validating these URLs against an allowlist can prevent unintended or malicious imports.


464-484: Add a file size limit check in downloadRemoteConfig

While the context timeout is set, the function lacks a file size limit check. This could allow the download of excessively large files, leading to resource exhaustion.

coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 24, 2024
@osterman
Copy link
Member

Update documentation for Atmos CLI Configuration schema and examples

@osterman
Copy link
Member

Update documentation for Atmos CLI Configuration

https://atmos.tools/cli/configuration/

coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 20, 2024
coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 20, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
website/docs/cli/configuration/configuration.mdx (2)

27-27: Add punctuation at the end of the preceding paragraph.

Add a period after "and so forth" to properly end the paragraph.

-you'd specify the command to run (e.g. [`opentofu`](/core-concepts/projects/configuration/opentofu)), the base path location of the components, and so forth
+you'd specify the command to run (e.g. [`opentofu`](/core-concepts/projects/configuration/opentofu)), the base path location of the components, and so forth.
🧰 Tools
🪛 LanguageTool

[grammar] ~27-~27: Please add a punctuation mark at the end of paragraph.
Context: ...f the components, and so forth. ## Base Path The base path defines the root directo...

(PUNCTUATION_PARAGRAPH_END)


31-31: Remove unnecessary comma before 'if'.

For better readability, remove the comma before the 'if' clause.

-When the `base_path` is explicitly defined, it will always be resolved to the absolute path relative to the current working directory, if an absolute path was not already set.
+When the `base_path` is explicitly defined, it will always be resolved to the absolute path relative to the current working directory if an absolute path was not already set.
🧰 Tools
🪛 LanguageTool

[typographical] ~31-~31: Usually, there’s no comma before “if”.
Context: ...elative to the current working directory, if an absolute path was not already set. ...

(IF_NO_COMMA)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6e4bc4d and b933331.

📒 Files selected for processing (1)
  • website/docs/cli/configuration/configuration.mdx (1 hunks)
🧰 Additional context used
🪛 LanguageTool
website/docs/cli/configuration/configuration.mdx

[grammar] ~27-~27: Please add a punctuation mark at the end of paragraph.
Context: ...f the components, and so forth. ## Base Path The base path defines the root directo...

(PUNCTUATION_PARAGRAPH_END)


[typographical] ~31-~31: Usually, there’s no comma before “if”.
Context: ...elative to the current working directory, if an absolute path was not already set. ...

(IF_NO_COMMA)


[style] ~32-~32: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... an absolute path was not already set. When the base_path is not explicitly provi...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

🔇 Additional comments (1)
website/docs/cli/configuration/configuration.mdx (1)

44-78: Well-structured documentation of configuration loading and imports!

The documentation clearly explains:

  • Configuration file loading order and precedence
  • Import capabilities and supported formats
  • Security considerations for remote imports


## Configuration File (`atmos.yaml`)
The base path defines the root directory for components, stacks, workflows, and Atmos configurations. It can be set using the `ATMOS_BASE_PATH` environment variable or by passing the `--base-path` command-line argument. If both are set, the `--base-path` will take precedence. Both absolute and relative paths are supported. When a relative path is provided, it will be expanded to an absolute path relative to the current working directory, as Atmos executes commands that may change the working directory (e.g., Terraform).
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
The base path defines the root directory for components, stacks, workflows, and Atmos configurations. It can be set using the `ATMOS_BASE_PATH` environment variable or by passing the `--base-path` command-line argument. If both are set, the `--base-path` will take precedence. Both absolute and relative paths are supported. When a relative path is provided, it will be expanded to an absolute path relative to the current working directory, as Atmos executes commands that may change the working directory (e.g., Terraform).
The base path defines the root directory for components, stacks, workflows, and Atmos configurations. It can be set using the `ATMOS_BASE_PATH` environment variable or by passing the `--base-path` command-line argument. If both are set, the `--base-path` will take precedence. Both absolute and relative paths are supported. When a relative path is provided, it will be expanded to an absolute path relative to the current working directory. This is because Atmos executes commands that may change the working directory (e.g., Terraform).

Copy link
Member

@osterman osterman Dec 20, 2024

Choose a reason for hiding this comment

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

It mostly affects the terraform-provider-utils which reads the atmos configs.

In geodesic, we put atmos.yaml in /usr/local/etc/atmos/atmos.yaml which is a predefined search order places we read from.

Copy link
Member

Choose a reason for hiding this comment

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

Any relative path is not compatible with the terraform-provider-utils, because terraform changes the directory.

Copy link
Member

Choose a reason for hiding this comment

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

We hope to remove the for the utils provider in the future versions of our components and refarch.

When the `base_path` is explicitly defined, it will always be resolved to the absolute path relative to the current working directory, if an absolute path was not already set.

When the `base_path` is not explicitly provided or is empty, Atmos will attempt to infer the appropriate path using the following strategy, in order of precedence:
1. If the current working directory contains any of the following files or directories: `atmos.yaml`, `.atmos.yaml`, `.github/atmos.yaml`, or `atmos.d/**/*`, Atmos will use the directory containing these files as the `base_path`.
Copy link
Member

Choose a reason for hiding this comment

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

To be clear, it's the prefix of the filename, not the dirname.

Copy link
Member

@osterman osterman Dec 20, 2024

Choose a reason for hiding this comment

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

I think .github/atmos.yaml and .atmos.yaml from the root of the repo, but not any subpath. I think this is moderately better from security standpoint as well.

When the `base_path` is not explicitly provided or is empty, Atmos will attempt to infer the appropriate path using the following strategy, in order of precedence:
1. If the current working directory contains any of the following files or directories: `atmos.yaml`, `.atmos.yaml`, `.github/atmos.yaml`, or `atmos.d/**/*`, Atmos will use the directory containing these files as the `base_path`.
2. If a Git repository is detected, Atmos uses the root of the Git repository as the `base_path`.
3. If neither of the above applies, Atmos defaults to the absolute path of `./` as the `base_path`.
Copy link
Member

Choose a reason for hiding this comment

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

Need to rewrite this for cli path, and when we do, and no config found, then use the default config. I think it would probably tie in to the go:embed file system, but need to look into it more.

## Configuration File (`atmos.yaml`)

The Atmos (CLI) configuration is loaded from the following locations, in order of precedence, and deep-merged: configurations listed earlier have higher priority, meaning they override any conflicting sections defined in subsequent locations:
- The `--config` parameter is the relative or absolute path to a valid configuration file or directory containing strictly atmos configuration file(s). It has the highest precedence, meaning it supersedes everything.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- The `--config` parameter is the relative or absolute path to a valid configuration file or directory containing strictly atmos configuration file(s). It has the highest precedence, meaning it supersedes everything.
- The `--config` flag is the relative or absolute path to a valid configuration file or directory containing strictly atmos configuration file(s). It has the highest precedence, meaning it supersedes everything.

Copy link
Member

Choose a reason for hiding this comment

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

When the --config is specified, all other search paths are ignored. It is the canonical configuration location. For example, no paths in XDG_CONFIG_HOME are loaded. We should be able to specify --config multiple times, and they are deep merged in the order. The first config specified is the lowest config, and the last one is the highest priority config.


The Atmos (CLI) configuration is loaded from the following locations, in order of precedence, and deep-merged: configurations listed earlier have higher priority, meaning they override any conflicting sections defined in subsequent locations:
- The `--config` parameter is the relative or absolute path to a valid configuration file or directory containing strictly atmos configuration file(s). It has the highest precedence, meaning it supersedes everything.
- The `$XDG_CONFIG_HOME/atmos/atmos.yaml` file (if `$XDG_CONFIG_HOME` is set) allows the user to specify their preferences and overrides. It is only superseded by the `--config` flag.
Copy link
Member

Choose a reason for hiding this comment

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

Let's see if there's a go XDG library so we support conventional usage.
https://github.com/adrg/xdg

- `.atmos.yaml`
- `.github/atmos.yaml`
- `atmos.d/**/*`
- `.atmos.d/**/*`
- Home directory (`~/.atmos/atmos.yaml`)
Copy link
Member

Choose a reason for hiding this comment

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

What happens on windows with this?

Copy link
Member

Choose a reason for hiding this comment

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

https://github.com/mitchellh/go-homedir (Archived, so look for maintained fork)

Comment on lines +49 to +53
- `atmos.yaml`
- `.atmos.yaml`
- `.github/atmos.yaml`
- `atmos.d/**/*`
- `.atmos.d/**/*`
Copy link
Member

Choose a reason for hiding this comment

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

The implied order here is highest to lowest presedence.

From the current directory:
- `atmos.yaml`
- `.atmos.yaml`
- `.github/atmos.yaml`
Copy link
Member

Choose a reason for hiding this comment

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

The .github/atmos.yaml maybe should have the lowest priority.

## Configuration File (`atmos.yaml`)
The base path defines the root directory for components, stacks, workflows, and Atmos configurations. It can be set using the `ATMOS_BASE_PATH` environment variable or by passing the `--base-path` command-line argument. If both are set, the `--base-path` will take precedence. Both absolute and relative paths are supported. When a relative path is provided, it will be expanded to an absolute path relative to the current working directory, as Atmos executes commands that may change the working directory (e.g., Terraform).

When the `base_path` is explicitly defined, it will always be resolved to the absolute path relative to the current working directory, if an absolute path was not already set.
Copy link
Member

Choose a reason for hiding this comment

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

This will be setting ATMOS_CLI_CONFIG_PATH

- The `--config` parameter is the relative or absolute path to a valid configuration file or directory containing strictly atmos configuration file(s). It has the highest precedence, meaning it supersedes everything.
- The `$XDG_CONFIG_HOME/atmos/atmos.yaml` file (if `$XDG_CONFIG_HOME` is set) allows the user to specify their preferences and overrides. It is only superseded by the `--config` flag.
- The environment variable `ATMOS_CLI_CONFIG_PATH` should point to a folder (or a specific file). This is mutually exclusive with the `--config` parameter. If `--config` is specified, then the `ATMOS_CLI_CONFIG_PATH` is ignored. Atmos will only search for the configuration file in the specified folder. Note that `.yaml` and `.yml` file extensions are treated interchangeably and are loaded in lexicographical order. Atmos will search for the following files, in order, relative to the `ATMOS_CLI_CONFIG_PATH` environment variable.
From the current directory:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
From the current directory:
From the current directory: (the first one found, wins)

- Home directory (`~/.atmos/atmos.yaml`)
- Current directory (`./atmos.yaml`)
- Environment variable `ATMOS_CLI_CONFIG_PATH` (the ENV var should point to a folder without specifying the file name)
- The `atmos.d/` directory is loaded relative to the `base_path`. For an example, see [`examples/demo-atmos.d`](https://github.com/cloudposse/atmos/tree/main/examples/demo-atmos.d)
Copy link
Member

Choose a reason for hiding this comment

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

Note, we discuss atmos.d above and define it here. There's some incongruence.

Copy link
Member

Choose a reason for hiding this comment

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

We should rewrite config handling to use https://github.com/spf13/viper

For example, we can import from multiple locations like this:

```yaml
import:
Copy link
Member

Choose a reason for hiding this comment

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

We do not intend to support templated imports at this time. Also, this syntax might change based on viper?

@mergify mergify bot closed this Dec 27, 2024
Copy link

mergify bot commented Dec 27, 2024

This PR was closed due to inactivity and merge conflicts. 😭
Please resolve the conflicts and reopen if necessary.

@mergify mergify bot removed the conflict This PR has conflicts label Dec 27, 2024
@osterman osterman reopened this Dec 27, 2024
Copy link

mergify bot commented Dec 27, 2024

💥 This pull request now has conflicts. Could you fix it @haitham911? 🙏

@mergify mergify bot added the conflict This PR has conflicts label Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conflict This PR has conflicts minor New features that do not break anything
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants