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

Add support for remote validation schemas #731

Merged
merged 19 commits into from
Oct 30, 2024
Merged

Add support for remote validation schemas #731

merged 19 commits into from
Oct 30, 2024

Conversation

haitham911
Copy link
Collaborator

@haitham911 haitham911 commented Oct 20, 2024

What

  • Add support for remote schemas in atmos for manifest validation
  • Updated schemas configuration to allow referencing remote schema files, e.g.:
    schemas:
      atmos:
        manifest: "https://atmos.tools/schemas/atmos/atmos-manifest/1.0/atmos-manifest.json"

Why

  • This reduces redundancy as, in previous demos, the manifest file had to be copied multiple times. Now, it can be referenced remotely .

References


Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Users can now specify remote schema URLs for validation in the atmos.yaml configuration file.
    • Enhanced stack validation to support downloading schema files directly from a URL.
    • Introduced utility functions to validate URLs and extract file names from URLs.
  • Documentation

    • Updated the "JSON Schema Validation" document to include instructions for specifying remote schemas, along with an example configuration.
  • Bug Fixes

    • Improved error messages to inform users about the option to download schema files from URLs if they do not exist locally.

@haitham911 haitham911 requested review from a team as code owners October 20, 2024 00:21
Copy link
Contributor

coderabbitai bot commented Oct 20, 2024

Warning

Rate limit exceeded

@aknysh has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 52 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Files that changed from the base of the PR and between eebb3ee and 493579d.

📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request involve updates to the atmos.yaml configuration file and enhancements to the ValidateStacks function in validate_stacks.go. The atmos.yaml file's manifest URL was changed from a local path to an absolute URL. Additionally, the ValidateStacks function was modified to support downloading the Atmos manifest JSON Schema from a URL, with new error handling and utility functions added to facilitate URL validation and file name extraction.

Changes

File Change Summary
examples/demo-context/atmos.yaml Updated manifest URL from local path to absolute URL.
internal/exec/validate_stacks.go Enhanced ValidateStacks function to support downloading manifest from a URL; added error handling.
pkg/utils/file_utils.go Added IsURL and GetFileNameFromURL functions for URL handling; included import for net/url.
website/docs/core-concepts/validate/json-schema.mdx Added new section on specifying remote schemas in validation; included example configuration.

Possibly related PRs

  • get atmos config and vendor from .yaml or .yml #736: This PR enhances the Atmos configuration by allowing retrieval of configuration files from both .yaml and .yml, which is directly related to the changes made in the main PR that updates the atmos.yaml configuration file's manifest URL.
  • WIP: Document helmfile, template imports #741: This PR documents the helmfile configuration options in Atmos, which includes updates to the atmos.yaml file structure. The changes in the main PR regarding the manifest URL in atmos.yaml are relevant to the broader context of configuring components like helmfile.

Suggested labels

minor

Suggested reviewers

  • osterman

Poem

In the meadow, where rabbits play,
A new URL leads the way.
With stacks validated, oh what a treat,
Downloading schemas, oh so neat!
Hops of joy, we celebrate,
Changes made, oh isn’t it great! 🐇✨


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 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 to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@haitham911 haitham911 requested a review from aknysh October 20, 2024 00:21
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: 5

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between c866ab5 and f27f4d5.

📒 Files selected for processing (3)
  • examples/demo-context/atmos.yaml (1 hunks)
  • internal/exec/validate_stacks.go (2 hunks)
  • pkg/utils/file_utils.go (2 hunks)
🧰 Additional context used
🔇 Additional comments (5)
examples/demo-context/atmos.yaml (1)

5-5: Approved: Remote schema support implemented as intended.

This change aligns well with the PR objectives by enabling remote schema support, which should help reduce redundancy in manifest file management. Great job!

A few suggestions to ensure robustness and usability:

  1. Please verify that the URL is accessible and returns the expected schema.
  2. Consider implementing a fallback mechanism (e.g., local cache) in case the remote URL is temporarily unavailable.
  3. Update the user documentation to reflect this new capability and provide guidance on using remote schemas securely.

To verify the URL accessibility and content, you can run the following script:

✅ Verification successful

Verified: Remote schema URL is accessible and contains valid JSON.

The remote schema URL https://atmos.tools/schemas/atmos/atmos-manifest/1.0/atmos-manifest.json is accessible and returns valid JSON as expected.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the accessibility and content of the remote schema URL

# Test: Check if the URL is accessible and returns a valid JSON schema
curl -sSf "https://atmos.tools/schemas/atmos/atmos-manifest/1.0/atmos-manifest.json" | jq empty

# If the above command succeeds (exit code 0), the URL is accessible and contains valid JSON
if [ $? -eq 0 ]; then
    echo "URL is accessible and contains valid JSON"
else
    echo "Error: URL is either inaccessible or does not contain valid JSON"
fi

Length of output: 206

pkg/utils/file_utils.go (3)

5-5: LGTM: Import addition is correct and necessary.

The addition of the net/url package import is appropriate for the new URL-related functions introduced in this file.


179-182: LGTM: IsURL function is well-implemented.

The IsURL function correctly checks if a string is a valid URL by verifying the presence of both a scheme and a host. The implementation is concise and handles potential errors from url.Parse.


Line range hint 1-195: Overall assessment: Changes align well with PR objectives.

The additions to this file, namely the IsURL and GetFileNameFromURL functions, provide essential utility for handling remote URLs. These changes directly support the PR's objective of adding support for remote schemas in manifest validation.

The implementations are correct and follow good coding practices. They lay a solid foundation for the broader changes required to support remote schema references in the atmos tool.

A minor suggestion was made to improve error handling in the GetFileNameFromURL function for edge cases involving trailing slashes in URLs. Implementing this suggestion would further enhance the robustness of the remote schema support.

internal/exec/validate_stacks.go (1)

4-6: Imports are appropriate and necessary

The added imports for "context", "os", and "github.com/hashicorp/go-getter" are necessary for the new functionality of downloading the schema from a URL and have been correctly included.

Also applies to: 11-11

pkg/utils/file_utils.go Outdated Show resolved Hide resolved
internal/exec/validate_stacks.go Outdated Show resolved Hide resolved
internal/exec/validate_stacks.go Outdated Show resolved Hide resolved
internal/exec/validate_stacks.go Outdated Show resolved Hide resolved
internal/exec/validate_stacks.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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between f27f4d5 and d0e1ec9.

📒 Files selected for processing (1)
  • internal/exec/validate_stacks.go (2 hunks)
🧰 Additional context used
📓 Learnings (1)
internal/exec/validate_stacks.go (1)
Learnt from: haitham911
PR: cloudposse/atmos#731
File: internal/exec/validate_stacks.go:93-98
Timestamp: 2024-10-20T00:41:57.135Z
Learning: When downloading schema files in `internal/exec/validate_stacks.go`, use a consistent temporary file name to overwrite the file each time and avoid creating multiple temporary files.

internal/exec/validate_stacks.go Outdated Show resolved Hide resolved
@haitham911 haitham911 changed the title Dev 2331 Added support for remote schemas Oct 20, 2024
Copy link
Member

@aknysh aknysh left a comment

Choose a reason for hiding this comment

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

@haitham911 please resolve the conflicts

@osterman
Copy link
Member

@aknysh what do you think about making this the default location for the schema? That way atmos validate always works, even if no schema installed locally.

@aknysh
Copy link
Member

aknysh commented Oct 21, 2024

@aknysh what do you think about making this the default location for the schema? That way atmos validate always works, even if no schema installed locally.

I think yes, we can do it
We need to think if we always use the remote location and always validate.
In which case we need to allow the user to opt-out

@osterman
Copy link
Member

In which case we need to allow the user to opt-out

I think they can set the path to /dev/null to "opt out" =)

But at a very least, we should document how to disable it. And also update the documentation to indicate what is the default behavior.

@osterman
Copy link
Member

@haitham911 also please update docs here: https://atmos.tools/core-concepts/validate/json-schema

with how to specify remote schemas

@osterman
Copy link
Member

@haitham911 please post screenshot of this in action. Please confirm that using files as well as remote URLs both work. Also, this PR is conflicted.

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: 5

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between d0e1ec9 and 34a7079.

📒 Files selected for processing (3)
  • internal/exec/validate_stacks.go (2 hunks)
  • pkg/utils/file_utils.go (2 hunks)
  • website/docs/core-concepts/validate/json-schema.mdx (1 hunks)
🧰 Additional context used
📓 Learnings (1)
internal/exec/validate_stacks.go (2)
Learnt from: haitham911
PR: cloudposse/atmos#731
File: internal/exec/validate_stacks.go:93-98
Timestamp: 2024-10-20T00:41:57.135Z
Learning: When downloading schema files in `internal/exec/validate_stacks.go`, use a consistent temporary file name to overwrite the file each time and avoid creating multiple temporary files.
Learnt from: haitham911
PR: cloudposse/atmos#731
File: internal/exec/validate_stacks.go:0-0
Timestamp: 2024-10-20T00:57:53.500Z
Learning: In `internal/exec/validate_stacks.go`, when downloading the Atmos JSON Schema file to the temp directory, the temporary file is overwritten each time, so explicit removal is not necessary.
🔇 Additional comments (2)
pkg/utils/file_utils.go (1)

204-218: Great job implementing the suggested improvement!

The GetFileNameFromURL function has been implemented correctly, addressing the concerns raised in the previous review. Specifically:

  1. It properly handles URL parsing and extraction of the file name.
  2. It now includes a check for edge cases where the extracted file name is "/" or ".", returning an error in these cases.

This implementation ensures robust handling of various URL formats and edge cases. Well done!

internal/exec/validate_stacks.go (1)

94-119: Security considerations when downloading remote schemas

The previous comment regarding adding security measures when downloading remote schemas is still applicable to this code segment.

website/docs/core-concepts/validate/json-schema.mdx Outdated Show resolved Hide resolved
pkg/utils/file_utils.go Outdated Show resolved Hide resolved
internal/exec/validate_stacks.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: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 34a7079 and 1c59c05.

📒 Files selected for processing (1)
  • website/docs/core-concepts/validate/json-schema.mdx (1 hunks)
🧰 Additional context used
🔇 Additional comments (1)
website/docs/core-concepts/validate/json-schema.mdx (1)

49-54: LGTM! The schema URL is correctly specified.

The example uses the correct production URL for the Atmos manifest schema, which aligns with the standardization goals.

website/docs/core-concepts/validate/json-schema.mdx Outdated Show resolved Hide resolved
website/docs/core-concepts/validate/json-schema.mdx 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: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between ed3b63f and f99133d.

📒 Files selected for processing (3)
  • internal/exec/validate_stacks.go (3 hunks)
  • pkg/utils/file_utils.go (2 hunks)
  • website/docs/core-concepts/validate/json-schema.mdx (1 hunks)
🧰 Additional context used
📓 Learnings (1)
pkg/utils/file_utils.go (1)
Learnt from: osterman
PR: cloudposse/atmos#731
File: pkg/utils/file_utils.go:198-202
Timestamp: 2024-10-23T20:13:23.054Z
Learning: In `pkg/utils/file_utils.go`, the current implementation of the `IsURL` function is considered sufficient; avoid suggesting more complex URL validation in future reviews.
🔇 Additional comments (2)
pkg/utils/file_utils.go (2)

216-233: LGTM! Well-implemented URL filename extraction.

The function is well-structured with proper error handling and edge cases:

  • Empty URL validation
  • URL parsing error handling
  • Edge cases for "/" and "." filenames

198-214: ⚠️ Potential issue

Reorder error handling in IsURL function.

The error check should be performed immediately after url.Parse to prevent potential nil pointer dereference when accessing url.Scheme.

Apply this diff to fix the error handling order:

 func IsURL(s string) bool {
 	url, err := url.Parse(s)
+	if err != nil {
+		return false
+	}
 	validSchemes := []string{"http", "https"}
 	schemeValid := false
 	for _, scheme := range validSchemes {
 		if url.Scheme == scheme {
 			schemeValid = true
 			break
 		}
 	}
-	if err != nil {
-		return false
-	}
 	return schemeValid
 }
⛔ Skipped due to learnings
Learnt from: osterman
PR: cloudposse/atmos#731
File: pkg/utils/file_utils.go:198-202
Timestamp: 2024-10-23T20:13:23.054Z
Learning: In `pkg/utils/file_utils.go`, the current implementation of the `IsURL` function is considered sufficient; avoid suggesting more complex URL validation in future reviews.

internal/exec/validate_stacks.go 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: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between f99133d and eebb3ee.

📒 Files selected for processing (1)
  • examples/demo-context/atmos.yaml (1 hunks)

examples/demo-context/atmos.yaml Show resolved Hide resolved
examples/demo-context/atmos.yaml Show resolved Hide resolved
@aknysh aknysh added minor New features that do not break anything and removed no-release Do not create a new release (wait for additional code changes) labels Oct 30, 2024
@aknysh aknysh changed the title Added support for remote schemas Added support for remote validation schemas Oct 30, 2024
@aknysh aknysh changed the title Added support for remote validation schemas Add support for remote validation schemas Oct 30, 2024
@aknysh aknysh merged commit e8b4fb9 into main Oct 30, 2024
11 of 18 checks passed
@aknysh aknysh deleted the DEV-2331 branch October 30, 2024 12:38
Copy link

These changes were released in v1.97.0.

@osterman
Copy link
Member

osterman commented Nov 1, 2024

@haitham911 we haven't set a default schema.

If you run: atmos describe config, you'll see JSON schema is not set:

  "schemas": {
    "jsonschema": {},
    "cue": {},
    "opa": {},
    "atmos": {}
  },

Full output

atmos describe config   
{
  "base_path": "./",
  "components": {
    "terraform": {
      "base_path": "components/terraform",
      "apply_auto_approve": false,
      "append_user_agent": "Atmos/1.99.0 (Cloud Posse; +https://atmos.tools)",
      "deploy_run_init": true,
      "init_run_reconfigure": true,
      "auto_generate_backend_file": false,
      "command": ""
    },
    "helmfile": {
      "base_path": "",
      "use_eks": true,
      "kubeconfig_path": "",
      "helm_aws_profile_pattern": "",
      "cluster_name_pattern": "",
      "command": ""
    }
  },
  "stacks": {
    "base_path": "stacks",
    "included_paths": [
      "deploy/**/*"
    ],
    "excluded_paths": [
      "**/_defaults.yaml"
    ],
    "name_pattern": "{stage}",
    "name_template": ""
  },
  "workflows": {
    "base_path": ""
  },
  "logs": {
    "file": "/dev/stderr",
    "level": "Info"
  },
  "integrations": {
    "atlantis": {}
  },
  "schemas": {
    "jsonschema": {},
    "cue": {},
    "opa": {},
    "atmos": {}
  },
  "templates": {
    "settings": {
      "enabled": false,
      "sprig": {
        "enabled": false
      },
      "gomplate": {
        "enabled": false,
        "timeout": 0,
        "datasources": null
      }
    }
  },
  "settings": {
    "list_merge_strategy": ""
  },
  "initialized": true,
  "stacksBaseAbsolutePath": "/Users/erik/Dev/cloudposse/tools/atmos/examples/quick-start-simple/stacks",
  "includeStackAbsolutePaths": [
    "/Users/erik/Dev/cloudposse/tools/atmos/examples/quick-start-simple/stacks/deploy/**/*"
  ],
  "excludeStackAbsolutePaths": [
    "/Users/erik/Dev/cloudposse/tools/atmos/examples/quick-start-simple/stacks/**/_defaults.yaml"
  ],
  "terraformDirAbsolutePath": "/Users/erik/Dev/cloudposse/tools/atmos/examples/quick-start-simple/components/terraform",
  "helmfileDirAbsolutePath": "/Users/erik/Dev/cloudposse/tools/atmos/examples/quick-start-simple",
  "default": false
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor New features that do not break anything
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants