add base url on json schema#408
Conversation
WalkthroughThe changes involve significant modifications to the Changes
Assessment against linked issues
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #408 +/- ##
==========================================
+ Coverage 72.08% 72.31% +0.23%
==========================================
Files 128 127 -1
Lines 13044 12944 -100
==========================================
- Hits 9402 9360 -42
+ Misses 3212 3158 -54
+ Partials 430 426 -4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (8)
examples/linux.toml (3)
Line range hint
11-22: Well-structured group and default configurations.The [groups] section allows for efficient management of multiple backup profiles, which is particularly useful for complex backup strategies.
The [default] section provides a comprehensive set of baseline configurations that can be inherited by other profiles, promoting consistency and reducing redundancy.
Consider adding a comment explaining the purpose of the 'all' group for better documentation.
Line range hint
24-52: Comprehensive and well-structured [src] configuration.The [src] section and its subsections provide a thorough configuration for backup management. The use of inheritance from the [default] section promotes code reuse and maintainability.
The retention policy is well-defined, which is crucial for managing backup storage efficiently. The inclusion of pre and post-backup commands, along with error handling, demonstrates good operational practices.
Consider adding comments to explain the purpose of less obvious settings, such as 'one-file-system = false', to improve configuration maintainability.
Line range hint
66-75: Well-structured [self] section for self-backup.The [self] section is properly configured to back up the tool's own directory, which is an excellent practice for self-preservation and disaster recovery. The use of inheritance from the [default] section ensures consistency with other backup configurations.
The use of specific tags for self backups is commendable, as it will aid in identifying and managing these particular backups.
Consider adding a comment explaining the purpose of this section to improve documentation for future maintainers.
examples/dev.toml (3)
Line range hint
22-25: Reconsider the default commandThe global default command is set to "version". Whilst this can be useful for checking the system version, it might not be the most practical default command for regular use. Consider setting it to a more commonly used command, such as "backup" or "snapshots".
Line range hint
51-60: Consider using an absolute path for the self-backup repositoryIn the [self] section, the repository is set to "../backup". Whilst this relative path works if the working directory is consistent, it could lead to errors if the script is run from different locations. Consider using an absolute path to ensure consistency regardless of the working directory.
Review Confirmation: Repository Path Unsuitable for Long-Term Storage
The repository is currently set to
"/Volumes/RAMDisk", which is ideal for testing purposes due to its speed. However, RAM disks are volatile and data will be lost on shutdown or reboot. Please consider setting the repository path to a more permanent storage location for reliable, long-term usage.🔗 Analysis chain
Line range hint
5-11: Consider revising the repository locationThe default repository is set to "/Volumes/RAMDisk". Whilst this might be useful for testing, it's not suitable for long-term storage as RAM disks are volatile. Consider using a more permanent storage location for the default setting.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Check if the repository path is used consistently across the file rg --type toml 'repository\s*=\s*"/Volumes/RAMDisk"' examples/dev.tomlLength of output: 106
Makefile (1)
248-252: Excellent refactoring of the JSON schema generation processThe introduction of a loop to generate JSON schemas for multiple Restic versions is a significant improvement. This change enhances maintainability and makes it easier to add support for new versions in the future.
A minor suggestion for clarity:
Consider adding a comment explaining the version formatting:
for version in 0.9 0.10 0.11 0.12 0.13 0.14 0.15 0.16 0.17 ; do \ + # Convert version number to format suitable for filename (e.g., 0.9 -> 0-9) name=$$(echo $$version | sed 's/\./-/g') ; \ $(abspath $(BINARY)) generate --json-schema --version $$version v1 > $(JSONSCHEMA_DIR)/config-1-restic-$$name.json ; \ $(abspath $(BINARY)) generate --json-schema --version $$version v2 > $(JSONSCHEMA_DIR)/config-2-restic-$$name.json ; \ doneThis change aligns well with the PR objectives by streamlining the process of generating JSON schemas, which likely facilitates the addition of a base URL as mentioned in the PR description.
config/jsonschema/model.go (1)
52-55: LGTM: Environment variable for base URLThe addition of environment variable support for the schema base URL is an excellent improvement. It allows for flexible configuration whilst maintaining backwards compatibility with the default URL.
Consider adding a comment explaining the purpose of the
SCHEMA_BASE_URLenvironment variable for better documentation.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (4)
- Makefile (1 hunks)
- config/jsonschema/model.go (3 hunks)
- examples/dev.toml (1 hunks)
- examples/linux.toml (1 hunks)
🔇 Additional comments (12)
examples/linux.toml (4)
Line range hint
1-9: Excellent job addressing the schema URL issue!The schema URL is now an absolute URI, which resolves the validation issues mentioned in the PR objectives. This change ensures compatibility with tools like the "Even Better TOML" VS Code extension and the boon validator.
The [global] section provides sensible default values for priority, initialization, and I/O nice settings, which should help in managing system resources during backup operations.
Line range hint
54-64: Well-configured [stdin] section for standard input backups.The [stdin] section is properly configured to handle backups from standard input, which is a valuable feature for specific use cases. The use of inheritance from the [default] section ensures consistency with other backup configurations.
The addition of specific tags for stdin backups is a good practice, as it will help in identifying and managing these particular backups in the future.
Line range hint
1-84: Excellent work on improving the configuration file!This updated
examples/linux.tomlfile addresses the main objective of the pull request by providing an absolute URI for the JSON schema. This change resolves the validation issues with tools like the "Even Better TOML" VS Code extension and the boon validator.The configuration file is well-structured, with clear sections for different backup scenarios (global, src, stdin, self, and repo-from-env). The use of inheritance, groups, and environment variables demonstrates good configuration management practices, promoting code reuse and flexibility.
The comprehensive settings for backup operations, including retention policies, pre/post-backup commands, and error handling, provide a robust framework for managing backups effectively.
Overall, these changes significantly improve the usability and correctness of the resticprofile configuration, addressing the issues raised in the original problem statement.
Line range hint
77-84: Good use of environment variables in [repo-from-env] section.The [repo-from-env] section demonstrates a flexible approach by using environment variables for the repository path. This practice enhances security and allows for easier configuration management across different environments.
However, the backup source is set to the entire home directory ('~/'), which might be too broad and resource-intensive for some use cases. Consider adding a comment to explain this choice or suggest using a more specific subdirectory if appropriate for the intended use case.
To ensure the environment variable is properly set and accessible, you may want to add a verification step in your deployment process. Here's a simple script to check this:
examples/dev.toml (5)
1-3: Excellent addition of the schema declaration!The absolute URI for the schema addresses the issue mentioned in the PR objectives. This change should resolve the validation problems with tools like the "Even Better TOML" VS Code extension and the boon validator.
Line range hint
13-20: Well-structured documents backup configurationThe [documents] section provides a clear and concise configuration for backing up user documents. The use of tags for snapshots is a good practice for organisation and future reference.
Line range hint
27-28: Effective use of backup groupsThe [groups] section demonstrates good use of profile grouping. The "full-backup" group combining "root" and "src" provides a convenient way to perform comprehensive system backups.
Line range hint
30-49: Comprehensive backup configurations for root and srcThe [root] and [src] sections provide detailed and well-structured backup configurations. The use of inheritance, tags, exclusions, and comprehensive retention policies demonstrates a thoughtful approach to backup management. These configurations should effectively balance backup coverage with storage management.
Also applies to: 62-85
Line range hint
87-96: Well-configured stdin backup profileThe [stdin] section provides a flexible configuration for backing up from standard input. The use of tags is consistent with other sections, maintaining a coherent organisational structure across different backup types.
config/jsonschema/model.go (3)
23-23: LGTM: Default base URL addedThe addition of a
defaultBaseURLconstant is a good practice. It provides a fallback URL for the JSON schema, ensuring that there's always a valid base URL available.
Line range hint
1-458: Summary: Flexible schema URL configuration implementedThe changes in this file successfully address the issue of invalid JSON schemas by:
- Introducing a configurable base URL through an environment variable.
- Providing a sensible default URL as a fallback.
- Ensuring the schema
$idis constructed as an absolute URI.These modifications should resolve the validation errors encountered by tools such as the "Even Better TOML" VS Code extension and the boon validator. The solution is flexible and maintains backwards compatibility.
58-58: LGTM: Dynamic base URL in schema IDThe modification to use the
baseURLvariable in theIdfield assignment is correct and addresses the core issue of invalid schemas. This change ensures that the$idfield will now be an absolute URI, as required by the JSON Schema specification.To ensure this change resolves the issue, please run the following verification script:
This script will generate a schema with a custom base URL and output its
$idfield. Verify that the output is an absolute URI starting with "https://example.com/schemas/".
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
docs/content/configuration/jsonschema/index.md (2)
31-35: Excellent addition of local schema generation information.The new notice block provides valuable information about generating schemas locally, which is a great alternative to using online schemas. The change in notice style from "hint" to "info" is appropriate for this content.
A minor suggestion to enhance clarity:
Consider adding a brief explanation of why a user might want to change the base URL. For example:
-You can prefix the command with the environment variable `SCHEMA_BASE_URL` to change the base URL (defaults to `https://creativeprojects.github.io/resticprofile/jsonschema/`) +You can prefix the command with the environment variable `SCHEMA_BASE_URL` to change the base URL (defaults to `https://creativeprojects.github.io/resticprofile/jsonschema/`). This can be useful if you're working in an offline environment or need to use a custom schema location.
69-69: Appropriate style change for the notice.The change from "hint" to "info" style is consistent with the earlier notice and suitable for this important information about YAML & TOML validation requirements.
To further improve this notice:
Consider adding examples of recommended extensions for YAML and TOML validation. For instance:
-YAML & TOML validation with JSON schema is not supported out of the box. Additional extensions are required. +YAML & TOML validation with JSON schema is not supported out of the box. Additional extensions are required, such as 'redhat.vscode-yaml' for YAML and 'tamasfe.even-better-toml' for TOML in Visual Studio Code.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- Makefile (1 hunks)
- docs/content/configuration/jsonschema/index.md (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- Makefile
🔇 Additional comments (1)
docs/content/configuration/jsonschema/index.md (1)
Line range hint
1-69: Clarify the relationship between these changes and the PR objectives.While the additions to this document are valuable, they don't directly address the main objective of the PR, which is to add a base URL to the JSON schema to fix validation issues.
To better align with the PR objectives:
- Explain how the
SCHEMA_BASE_URLenvironment variable relates to fixing the schema validation issues mentioned in the PR description.- Consider adding a note about the changes made to the actual schema files to address the
$idissue.To verify if these changes have been made elsewhere in the PR, we can run the following script:
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
examples/linux.yaml (2)
Line range hint
68-70: Approve addition of log processing, with a suggestion for improvementThe addition of the
run-finallycommand to process the backup log is a valuable enhancement. It filters out unchanged files, focusing on meaningful changes in each backup.Consider using the
--fixed-stringsoption withgrepto avoid potential issues with special characters in filenames:run-finally: - 'grep --fixed-strings --invert-match "unchanged " {{ tempFile "backup.log" }} > /tmp/backup-{{ .Profile.Name }}-{{ .Now.Format "2006-01-02_15-04" }}.log'This change ensures that the grep command only looks for the exact string "unchanged " and doesn't interpret it as a regular expression.
Line range hint
84-84: Approve addition of status file, with a suggestion for file locationThe addition of the
status-fileentry is a positive change that can enhance monitoring and integration capabilities for the backup system.Consider using a more permanent location for the status file instead of
/tmp. The/tmpdirectory is typically cleared on system reboot, which might lead to loss of status information. A directory like/var/log/resticprofile/or/var/lib/resticprofile/might be more suitable for persistent status information.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (5)
- codecov.yml (1 hunks)
- docs/content/configuration/jsonschema/index.md (2 hunks)
- examples/dev.toml (1 hunks)
- examples/linux.yaml (1 hunks)
- sonar-project.properties (1 hunks)
✅ Files skipped from review due to trivial changes (1)
- sonar-project.properties
🚧 Files skipped from review as they are similar to previous changes (2)
- docs/content/configuration/jsonschema/index.md
- examples/dev.toml
🔇 Additional comments (6)
codecov.yml (1)
11-11: Confirm the necessity of ignoringrun_profile.goThe addition of
run_profile.goto the ignore list will exclude this file from code coverage reporting. Whilst this change appears to be intentional, it's important to ensure that excluding this file aligns with the project's code quality objectives.To verify the impact of this change, please run the following script:
This script will help us understand the contents of
run_profile.goand its usage across the project, allowing us to better assess the impact of excluding it from coverage reports.examples/linux.yaml (5)
6-6: Approve change, but verify impact on default behaviourThe modification of the
default-commandfromversiontosnapshotsaligns with the PR objectives. However, this change may affect the system's default behaviour.Please ensure that this change is intentional and doesn't negatively impact existing workflows. You may want to update the documentation to reflect this new default behaviour.
Line range hint
29-30: Approve addition of snapshot taggingThe addition of the
snapshotskey withtag: documentsis a positive change. It enhances the organisation and searchability of snapshots for thedocumentsprofile.This change is consistent with the tagging approach used in other sections and will improve snapshot management.
Line range hint
41-41: Approve addition of schedule loggingThe addition of the
schedule-logentry for thetest1profile's backup configuration is a positive change. It enhances logging capabilities for scheduled backups, which will improve tracking and debugging of backup operations.This change will make it easier to monitor and troubleshoot the
test1profile's scheduled backups.
Line range hint
55-55: Approve addition of post-backup ownership change, but verify security implicationsThe addition of the
run-aftercommand to change ownership of directories post-backup is a noteworthy change. This could be a useful security measure or a way to ensure proper access rights after backup.Please ensure that:
- The use of
$SUDO_USERis appropriate and secure in this context.- The directories being modified (
$HOME/.cache/resticand/tmp/backup) are the correct targets for this operation.- This operation doesn't introduce any unintended security risks or permission issues.
Line range hint
134-134: Approve addition of stdin filename specificationThe addition of the
stdin-filenameentry in thestdinprofile's backup configuration is a positive change. It enhances the configurability of the stdin backup process and is consistent with the overall structure and naming conventions in the file.This change provides more control over how stdin backups are named and stored, which can improve organisation and manageability of backups from standard input.
Fixes #400