-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cookie updated by NetworkToCode Cookie Drift Manager Tool (#730)
* Cookie updated by NetworkToCode Cookie Drift Manager Tool Template: ``` { "template": "https://github.com/nautobot/cookiecutter-nautobot-app.git", "dir": "nautobot-app", "ref": "refs/tags/nautobot-app-v2.2.0", "path": null } ``` Cookie: ``` { "remote": "https://github.com/nautobot/nautobot-app-golden-config.git", "path": "/tmp/tmptjpgbanq/nautobot-app-golden-config", "repository_path": "/tmp/tmptjpgbanq/nautobot-app-golden-config", "dir": "", "branch_prefix": "drift-manager", "context": { "codeowner_github_usernames": "@itdependsnetworks @jeffkala @nkallergis", "full_name": "Network to Code, LLC", "email": "[email protected]", "github_org": "nautobot", "app_name": "nautobot_golden_config", "verbose_name": "Golden Config", "app_slug": "nautobot-golden-config", "project_slug": "nautobot-app-golden-config", "repo_url": "https://github.com/nautobot/nautobot-app-golden-config", "base_url": "golden-config", "min_nautobot_version": "2.0.0", "max_nautobot_version": "2.9999", "camel_name": "NautobotGoldenConfig", "project_short_description": "An app for configuration on nautobot", "model_class_name": "None", "open_source_license": "Apache-2.0", "docs_base_url": "https://docs.nautobot.com", "docs_app_url": "https://docs.nautobot.com/projects/golden-config/en/latest", "_template": "https://github.com/nautobot/cookiecutter-nautobot-app.git", "_output_dir": "/tmp/tmptjpgbanq", "_repo_dir": "/github/home/.cookiecutters/cookiecutter-nautobot-app/nautobot-app", "_checkout": "refs/tags/nautobot-app-v2.2.0" }, "base_branch": "develop", "remote_name": "origin", "pull_request_strategy": "PullRequestStrategy.CREATE", "post_actions": [ "PostAction.BLACK" ], "baked_commit_ref": "c9dce46b70f0154a56974587202e71e82ef08bae", "draft": true } ``` CLI Arguments: ``` { "cookie_dir": "", "input": false, "json_filename": "", "output_dir": "", "push": true, "template": "", "template_dir": "", "template_ref": "refs/tags/nautobot-app-v2.2.0", "pull_request": null, "post_action": [], "disable_post_actions": false, "draft": null } ``` --------- Co-authored-by: bakebot <[email protected]> Co-authored-by: Jan Snasel <[email protected]>
- Loading branch information
1 parent
5fbee9f
commit d018661
Showing
16 changed files
with
199 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Re-baked from the latest template. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
"""App Config Schema Generator and Validator.""" | ||
import json | ||
from importlib import import_module | ||
from os import getenv | ||
from pathlib import Path | ||
from urllib.parse import urlparse | ||
|
||
import jsonschema | ||
import toml | ||
from django.conf import settings | ||
from to_json_schema.to_json_schema import SchemaBuilder | ||
|
||
|
||
def _enrich_object_schema(schema, defaults, required): | ||
schema["additionalProperties"] = False | ||
for key, value in schema["properties"].items(): | ||
if required and key in required: | ||
value["required"] = True | ||
default_value = defaults and defaults.get(key, None) | ||
if value["type"] == "object" and "properties" in value: | ||
_enrich_object_schema(value, default_value, None) | ||
elif default_value is not None: | ||
value["default"] = default_value | ||
|
||
|
||
def _main(): | ||
pyproject = toml.loads(Path("pyproject.toml").read_text()) | ||
url = urlparse(pyproject["tool"]["poetry"]["repository"]) | ||
_, owner, repository = url.path.split("/") | ||
package_name = pyproject["tool"]["poetry"]["packages"][0]["include"] | ||
app_config = settings.PLUGINS_CONFIG[package_name] # type: ignore | ||
schema_path = Path(package_name) / "app-config-schema.json" | ||
command = getenv("APP_CONFIG_SCHEMA_COMMAND", "") | ||
if command == "generate": | ||
schema = { | ||
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"$id": f"https://raw.githubusercontent.com/{owner}/{repository}/develop/{package_name}/app-config-schema.json", | ||
"$comment": "TBD: Update $id, replace `develop` with the future release tag", | ||
**SchemaBuilder().to_json_schema(app_config), # type: ignore | ||
} | ||
app_config = import_module(package_name).config | ||
_enrich_object_schema(schema, app_config.default_settings, app_config.required_settings) | ||
schema_path.write_text(json.dumps(schema, indent=4) + "\n") | ||
print(f"\n==================\nGenerated schema:\n\n{schema_path}\n") | ||
print( | ||
"WARNING: Review and edit the generated file before committing.\n" | ||
"\n" | ||
"Its content is inferred from:\n" | ||
"\n" | ||
"- The current configuration in `PLUGINS_CONFIG`\n" | ||
"- `NautobotAppConfig.default_settings`\n" | ||
"- `NautobotAppConfig.required_settings`" | ||
) | ||
elif command == "validate": | ||
schema = json.loads(schema_path.read_text()) | ||
jsonschema.validate(app_config, schema) | ||
print( | ||
f"\n==================\nValidated configuration using the schema:\n{schema_path}\nConfiguration is valid." | ||
) | ||
else: | ||
raise RuntimeError(f"Unknown command: {command}") | ||
|
||
|
||
_main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.