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 the hook api #665

Draft
wants to merge 63 commits into
base: main
Choose a base branch
from

Conversation

mplsgrant
Copy link
Collaborator

@mplsgrant mplsgrant commented Nov 11, 2024

Overview

This hooks system is intended to allow the user to extend Warnet with python code plugins which will have hooks into key points in the Warnet workflow.

For the user

This hooks API lets users write plugins that look like this:

@pre_status
def thing_i_want_to_do():
    """When the user runs `warnet status`, this function will run first."""
    print("I just want to say hi")

The various decorators available to users can be found in the hooks_api.py file which is also found in the plugins directory.

To get a plugins directory, simply run warnet init, and warnet will generate one for you.

For the Warnet developers

This new hooks system lets us decorate our internal Warnet functions with @api like this:

@click.command()
@api
def status():
    ....

Doing so causes Warnet to produce the corresponding hooks_api.py file when the user runs warnet init

Feedback

I am looking for feedback on this approach. Earlier I had considered authoring an abstract class/interface. After implementing the hooks system using decorators, I noticed that it became much easier to get new API endpoints.

@bdp-DrahtBot
Copy link
Collaborator

bdp-DrahtBot commented Nov 11, 2024

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #659 (Add better namespace logic to warnet logs by mplsgrant)
  • #649 (speedy startup by willcl-ark)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@bdp-DrahtBot bdp-DrahtBot mentioned this pull request Nov 18, 2024
mplsgrant and others added 2 commits November 20, 2024 13:37
This is an attempt to prevent the namespace test from failing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants