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

initial commit of chatops #55

Merged
merged 5 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .yamllint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ ignore: |
.venv/
nautobot-app/{{ cookiecutter.project_slug }}/invoke.mysql.yml
nautobot-app/{{ cookiecutter.project_slug }}/invoke.example.yml
nautobot-app-chatops/{{ cookiecutter.project_slug }}/invoke.mysql.yml
nautobot-app-chatops/{{ cookiecutter.project_slug }}/invoke.example.yml
nautobot-app-chatops/{{ cookiecutter.project_slug }}/invoke.mattermost.yml
nautobot-app-ssot/{{ cookiecutter.project_slug }}/invoke.mysql.yml
nautobot-app-ssot/{{ cookiecutter.project_slug }}/invoke.example.yml
28 changes: 28 additions & 0 deletions nautobot-app-chatops/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"codeowner_github_usernames": "",
"full_name": "Network to Code, LLC",
"email": "[email protected]",
"github_org": "nautobot",
"chatops_interactive_command": "my_app",
"app_name": "nautobot_chatops_{{ cookiecutter.chatops_interactive_command.lower().replace('-', '_') }}",
"verbose_name": "{{ cookiecutter.app_name.title().replace('_', ' ') }}",
"app_slug": "{{ cookiecutter.app_name.lower().replace('_', '-') }}",
"project_slug": "nautobot-app-chatops-{{ cookiecutter.chatops_interactive_command.lower().replace('_', '-') }}",
"repo_url": "https://github.com/{{ cookiecutter.github_org }}/{{ cookiecutter.project_slug }}",
"base_url": "{{ cookiecutter.chatops_interactive_command.lower().replace(' ', '-').replace('_', '-') }}",
"min_nautobot_version": "2.0.0",
"max_nautobot_version": "2.9999",
"camel_name": "{{ cookiecutter.app_slug.title().replace(' ', '').replace('-', '') }}",
"project_short_description": "{{ cookiecutter.verbose_name }}",
"setup_local_mattermost_dev_env": [
"Yes",
"No"
],
"model_class_name": "None",
"open_source_license": [
"Apache-2.0",
"Not open source"
],
"docs_base_url": "https://docs.nautobot.com",
"docs_app_url": "{{ cookiecutter.docs_base_url }}/projects/{{ cookiecutter.app_slug }}/en/latest"
}
76 changes: 76 additions & 0 deletions nautobot-app-chatops/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import json
from collections import OrderedDict
from pathlib import Path

_PROJECT_PATH = Path.cwd()
_ADDONS_PATH = _PROJECT_PATH / "{{ cookiecutter.app_name }}"

_CONGRATS = f"""
Congratulations! Your cookie has now been baked. It is located at {_PROJECT_PATH}.

⚠️⚠️ Before you start using your cookie you must run the following commands inside your cookie:

* poetry lock
* cp development/creds.example.env development/creds.env
* poetry shell
* invoke makemigrations
* black . # this will ensure all python files are formatted correctly, may require `sudo chown -R <my local username> ./` as migrations may be owned by root

The file `creds.env` will be ignored by git and can be used to override default environment variables.
"""

if __name__ == "__main__":
if "Not open source" == "{{ cookiecutter.open_source_license }}":
(_PROJECT_PATH / "LICENSE").unlink()

if "No" == "{{ cookiecutter.setup_local_mattermost_dev_env }}":
files_to_remove = [
"development/mattermost/docker-compose.yml",
"development/mattermost/nautobot_bootstrap.py",
"development/mattermost/Dockerfile",
]
for file in files_to_remove:
(_ADDONS_PATH / file).unlink()

(_ADDONS_PATH / "development/mattermost").rmdir()

if "{{ cookiecutter.model_class_name }}" == "None":
files_to_remove = [
"api/__init__.py",
"api/serializers.py",
"api/urls.py",
"api/views.py",
"filters.py",
"forms.py",
"migrations/__init__.py",
"models.py",
"navigation.py",
"tables.py",
"templates/{{ cookiecutter.app_name }}/{{ cookiecutter.model_class_name.lower() }}_retrieve.html",
"tests/fixtures.py",
"tests/test_api_views.py",
"tests/test_filter_{{ cookiecutter.model_class_name.lower() }}.py",
"tests/test_form_{{ cookiecutter.model_class_name.lower() }}.py",
"tests/test_model_{{ cookiecutter.model_class_name.lower() }}.py",
"tests/test_views.py",
"urls.py",
"views.py",
]
for file in files_to_remove:
(_ADDONS_PATH / file).unlink()
folders_to_remove = [
"api",
"migrations",
"templates/{{ cookiecutter.app_name }}",
"templates",
]
for folder in folders_to_remove:
(_ADDONS_PATH / folder).rmdir()

# Persist the baked cookie parameters in-repo for future usage as a replay file or for the drift management.
cookie = {{ cookiecutter }}
(_PROJECT_PATH / ".cookiecutter.json").write_text(
json.dumps({"cookiecutter": cookie}, indent=4) + "\n", encoding="utf-8"
)

print(_CONGRATS)
1 change: 1 addition & 0 deletions nautobot-app-chatops/hooks/pre_gen_project.py
60 changes: 60 additions & 0 deletions nautobot-app-chatops/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# pylint: disable=duplicate-code
"""Cookie tests configuration"""
import shutil
from os import environ
from pathlib import Path

from pytest import fixture


def init_examples_project(project_name):
"""Initialize the examples project folder (by deleting and reconstructing it if
already created, or just create).
Args:
project_name (str): Cookiecutter example project name
Returns:
examples_project (Path): Created example project
"""
# Set examples folder to cookiecutter level directory
examples_project = (Path(__file__) / "../../examples" / project_name).resolve()

# Clean examples project
if examples_project.is_dir():
shutil.rmtree(examples_project)
else:
examples_project.parent.mkdir(parents=True, exist_ok=True)
return examples_project


@fixture
def cookies_baked_nautobot_app_chatops(cookies):
"""Sets up an example cookiecutter project
Args:
cookies: wrapper for cookiecutter API when generating project
Return:
results (dict): of (cookies.bake) cookies baked project with execution results indexed by prod_env
examples_project (dict[Path]): created example project indexed by prod_env
"""
examples_projects = {}
results = {}
extra_contexts = {
"nautobot-app-chatops-platform1": {
"open_source_license": "Not open source",
"chatops_interactive_command": "platform1",
},
"nautobot-app-chatops-platform2": {
"open_source_license": "Apache-2.0",
"chatops_interactive_command": "platform2",
},
}
# pylint: disable-next=protected-access
environ["COOKIECUTTER_CONFIG"] = str(cookies._config_file)
for app_slug, extra_context in extra_contexts.items():
results[app_slug] = cookies.bake(extra_context=extra_context, template="nautobot-app-chatops")

assert results[app_slug].exception is None

examples_projects[app_slug] = init_examples_project(app_slug)
shutil.move(results[app_slug].project_path, examples_projects[app_slug])

return results, examples_projects
29 changes: 29 additions & 0 deletions nautobot-app-chatops/tests/test_bake_nautobot_app_chatops.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# pylint: disable=duplicate-code
"""Cookie tests"""
from os import environ


def test_bake_project(cookies):
# pylint: disable-next=protected-access
environ["COOKIECUTTER_CONFIG"] = str(cookies._config_file)
result = cookies.bake(template="nautobot-app-chatops")

assert result.exit_code == 0
assert result.exception is None
assert result.project_path.is_dir()

found_toplevel_files = [item.name for item in result.project_path.iterdir() if item.is_file()]
assert "pyproject.toml" in found_toplevel_files
assert "README.md" in found_toplevel_files
assert "LICENSE" in found_toplevel_files


def test_bake_nautobot_execution(cookies_baked_nautobot_app_chatops):
"""
Tests creation of example nautobot with the cookiecutter default values
"""
results, examples_projects = cookies_baked_nautobot_app_chatops
app_slug = "nautobot-app-chatops-platform1"
assert results[app_slug].exit_code == 0
assert results[app_slug].exception is None
assert examples_projects[app_slug].is_dir()
Validating CODEOWNERS rules …
68 changes: 68 additions & 0 deletions nautobot-app-chatops/{{ cookiecutter.project_slug }}/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# {{ cookiecutter.verbose_name }}

An app for [Nautobot](https://github.com/nautobot/nautobot).

<!--
Developer Note - Remove Me!

The README will have certain links/images broken until the PR is merged into `develop`. Update the GitHub links with whichever branch you're using (main etc.) if different.

The logo of the project is a placeholder (docs/images/icon-{{ cookiecutter.app_slug }}.png) - please replace it with your app icon, making sure it's at least 200x200px and has a transparent background!

To avoid extra work and temporary links, make sure that publishing docs (or merging a PR) is done at the same time as setting up the docs site on RTD, then test everything.
-->

<p align="center">
<img src="https://raw.githubusercontent.com/{{ cookiecutter.github_org }}/{{ cookiecutter.project_slug }}/develop/docs/images/icon-{{ cookiecutter.app_slug }}.png" class="logo" height="200px">
<br>
<a href="{{ cookiecutter.repo_url }}/actions"><img src="{{ cookiecutter.repo_url }}/actions/workflows/ci.yml/badge.svg?branch=main"></a>
<a href="{{ cookiecutter.docs_app_url }}"><img src="https://readthedocs.org/projects/{{ cookiecutter.project_slug }}/badge/"></a>
<a href="https://pypi.org/project/{{ cookiecutter.app_slug }}/"><img src="https://img.shields.io/pypi/v/{{ cookiecutter.app_slug }}"></a>
<a href="https://pypi.org/project/{{ cookiecutter.app_slug }}/"><img src="https://img.shields.io/pypi/dm/{{ cookiecutter.app_slug }}"></a>
<br>
An <a href="https://www.networktocode.com/nautobot/apps/">App</a> for <a href="https://nautobot.com/">Nautobot</a>.
</p>

## Overview

> Developer Note: Add a long (2-3 paragraphs) description of what the App does, what problems it solves, what functionality it adds to Nautobot, what external systems it works with etc.

### Screenshots

> Developer Note: Add any representative screenshots of the App in action. These images should also be added to the `docs/user/app_use_cases.md` section.

> Developer Note: Place the files in the `docs/images/` folder and link them using only full URLs from GitHub, for example: `![Overview](https://raw.githubusercontent.com/{{ cookiecutter.github_org }}/{{ cookiecutter.project_slug }}/develop/docs/images/app-overview.png)`. This absolute static linking is required to ensure the README renders properly in GitHub, the docs site, and any other external sites like PyPI.

More screenshots can be found in the [Using the App]({{ cookiecutter.docs_app_url }}/user/app_use_cases/) page in the documentation. Here's a quick overview of some of the app's added functionality:

![](https://raw.githubusercontent.com/{{ cookiecutter.github_org }}/{{ cookiecutter.project_slug }}/develop/docs/images/placeholder.png)

## Try it out!

> Developer Note: Only keep this section if appropriate. Update link to correct sandbox.

This App is installed in the Nautobot Community Sandbox found over at [demo.nautobot.com](https://demo.nautobot.com/)!

> For a full list of all the available always-on sandbox environments, head over to the main page on [networktocode.com](https://www.networktocode.com/nautobot/sandbox-environments/).

## Documentation

Full documentation for this App can be found over on the [Nautobot Docs]({{ cookiecutter.docs_base_url }}) website:

- [User Guide]({{ cookiecutter.docs_app_url }}/user/app_overview/) - Overview, Using the App, Getting Started.
- [Administrator Guide]({{ cookiecutter.docs_app_url }}/admin/install/) - How to Install, Configure, Upgrade, or Uninstall the App.
- [Developer Guide]({{ cookiecutter.docs_app_url }}/dev/contributing/) - Extending the App, Code Reference, Contribution Guide.
- [Release Notes / Changelog]({{ cookiecutter.docs_app_url }}/admin/release_notes/).
- [Frequently Asked Questions]({{ cookiecutter.docs_app_url }}/user/faq/).

### Contributing to the Documentation

You can find all the Markdown source for the App documentation under the [`docs`]({{ cookiecutter.repo_url }}/tree/develop/docs) folder in this repository. For simple edits, a Markdown capable editor is sufficient: clone the repository and edit away.

If you need to view the fully-generated documentation site, you can build it with [MkDocs](https://www.mkdocs.org/). A container hosting the documentation can be started using the `invoke` commands (details in the [Development Environment Guide]({{ cookiecutter.docs_app_url }}/dev/dev_environment/#docker-development-environment)) on [http://localhost:8001](http://localhost:8001). Using this container, as your changes to the documentation are saved, they will be automatically rebuilt and any pages currently being viewed will be reloaded in your browser.

Any PRs with fixes or improvements are very welcome!

## Questions

For any questions or comments, please check the [FAQ]({{ cookiecutter.docs_app_url }}/user/faq/) first. Feel free to also swing by the [Network to Code Slack](https://networktocode.slack.com/) (channel `#nautobot`), sign up [here](http://slack.networktocode.com/) if you don't have an account.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
################################################################################
# CREDS File: Store private information. Copied to creds.env and always ignored
################################################################################
# Nautobot Configuration Secret Items
NAUTOBOT_CREATE_SUPERUSER=true
NAUTOBOT_DB_PASSWORD=changeme
NAUTOBOT_NAPALM_USERNAME=''
NAUTOBOT_NAPALM_PASSWORD=''
NAUTOBOT_REDIS_PASSWORD=changeme
NAUTOBOT_SECRET_KEY='changeme'
NAUTOBOT_SUPERUSER_NAME=admin
[email protected]
NAUTOBOT_SUPERUSER_PASSWORD=admin
NAUTOBOT_SUPERUSER_API_TOKEN=0123456789abcdef0123456789abcdef01234567

# Postgres
POSTGRES_PASSWORD=${NAUTOBOT_DB_PASSWORD}
PGPASSWORD=${NAUTOBOT_DB_PASSWORD}

# MySQL Credentials
MYSQL_ROOT_PASSWORD=${NAUTOBOT_DB_PASSWORD}
MYSQL_PASSWORD=${NAUTOBOT_DB_PASSWORD}

# Use these to override values in development.env
# NAUTOBOT_DB_HOST=localhost
# NAUTOBOT_REDIS_HOST=localhost
# NAUTOBOT_CONFIG=development/nautobot_config.py

ENABLE_SLACK=false
# SLACK_API_TOKEN=foobar
# SLACK_SIGNING_SECRET=foobar
# SLACK_SLASH_COMMAND_PREFIX=foobar

ENABLE_WEBEX=false
# WEBEX_TOKEN=foobar
# WEBEX_SIGNING_SECRET=foobar

ENABLE_MATTERMOST={% if cookiecutter.setup_local_mattermost_dev_env %}true{% else %}false{% endif %}
{% if not cookiecutter.setup_local_mattermost_dev_env %}# {% endif %}MATTERMOST_API_TOKEN="nsutx44ibbd69r5hjjmd3hx4sw"
{% if not cookiecutter.setup_local_mattermost_dev_env %}# {% endif %}MATTERMOST_URL="http://mattermost:8065"

ENABLE_MS_TEAMS=false
# MICROSOFT_APP_ID=foobar
# MICROSOFT_APP_PASSWORD=foobar
Loading