nautobot / nautobot-app-chatops

Extensible ChatOps Framework to enable other chatbots and the Nautobot chat command.
https://docs.nautobot.com/projects/chatops/en/latest/
Other
51 stars 34 forks source link

Allow changing endpoint per user in the live chat #122

Open chadell opened 2 years ago

chadell commented 2 years ago

Proposed Functionality

Today, most of the chatops plugins define a custom endpoint in its configuration with some custom authentication configuration.

The idea would be that instead of solving only the multi-instance for one specific chatops, we could extend this nautobot_chatops configuration to support a new (optional) endpoints (or similar) key with a list of multiple endpoints (with a reference name), so the user would be able to switch between them in execution time using his own session.

For example:

PLUGINS_CONFIG = {
    "nautobot_chatops": {
        "endpoints": [
            {
                "name": "endpoint 1",
                "url": "...",
                "token": "...",
                "verify_ssl": true
            },
            {
                "name": "endpoint 2",
                "url": "...",
                "user": "...",
                "password": "...",
                "verify_ssl": false
            },

        ]

This change obviously doesn’t affect the previous chatops (it’s backwards compatible), so from the custom chatops plugins we can choose to use these new endpoints that will exposed via a wrapper on the current sessions methods, not on the specific chatops which will only focus on using the new methods to retrieve the URL and the proper authentication.

This feature will expose two methods: get_endpoint and set_endpoint, that will leverage on the user's session, to save the "active" endpoint.

Use Case

As a user of a Chatops integration, I would like to easily change from one endpoint to another, affecting only this specific user context.

So, having several endpoints defined, a user can jump from one to another, so all the commands executed will refer to the "active" endpoint:

> /ipfabric get-endpoint

> your current endpoint is endpoint_1

> /ipfabric set-endpoint endpoint_2

> /ipfabric get-endpoint

> your current endpoint is endpoint_2
smk4664 commented 2 years ago

I don't think this would belong in the nautobot-plugin-chatops itself. There are no endpoints in this plugin. If other plugins implement endpoints, they could likely implement this themselves. I believe there are already examples of something similar to this in another plugin, let me see if I can find that.

chadell commented 2 years ago

Thanks @smk4664 , it is a totally valid point. However, from another angle, almost all the Chatops rely on "endpoints", so if we don't implement it here, all the other plugins will need to reinvent the wheel every time. The point is that these feature would be "optional", so you don't need to define endpoints, it's just a helper if the specific chatops needs this feature (most likely) Open to review it and adapt as needed

jvanderaa commented 2 years ago

@chadell / @smk4664 what is the latest on this type of effort?

chadell commented 2 years ago

@jvanderaa

We had a sync with @smk4664 , considering the latest enhancements from Nautobot, and we could approach it creating a new model:

chatops_endpoints:
     -  name: "my fancy endpoint"
         slug: "my-fancy-endpoint"
         url: "https:/...."
         plugin: FK(nautobot-plugin)
         secret: FK(secrets)
         verify_ssl: True

With this, you can create you endpoints, for multiple chatops plugins, and the in the chat, define the actual endtpoint with each chatops command. So /ipfabric will look for the chatops_endpoints that has the ipfabric plugin related.

jvanderaa commented 2 years ago

Where would this be placed at?

chadell commented 2 years ago

I got in touch with Core to understand if this idea (URL Endpoints) could be an extensibility option for Core. I am trying to get a more complete understanding of different use-cases across plugins, not only chatops ones.

smk4664 commented 2 years ago

This is going to be put into a new Nautobot App to provide the Endpoints model, likely External API's.