nuropb-gw


Namenuropb-gw JSON
Version 0.1.4 PyPI version JSON
download
home_pagehttps://github.com/robertbetts/command
SummaryWebsocket gateway library for Nuropb Service Mesh
upload_time2023-09-21 21:43:23
maintainer
docs_urlNone
authorRobert Betts
requires_python>=3.9,<3.12
licenseApache-2.0
keywords python asynchrous api event rpc distributed websockets sevice-mesh
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # TCP(WebSocket) Service Mesh Gateway

Library for providing a TCP(WebSocket) gateway to the Nuropb service mesh. The
Library leverages the Tornado asynchronous networking framework, and can 
also be used as a template for other TCP connection handlers. In addition, it
can also be used as pattern to implement a WebSocket BFF (Backend For Frontend).

There are two primary classes that interact together in providing `consumer` access
to the services hosted on the Service Mesh. It's always tricky how to coordinate the 
dependencies between classes, especially when there are bidirectional flows and 
process between them.

Consumers are external to the service mesh, and are considered to be untrusted,
and the nature of the connections to be less reliable. The service mesh transport 
protocol is implemented AMQP over TCP and is more challenging for broad adoption,
and especially from browsers and mobile devices. The solution is to provide a 
WebSocket gateway interface to the service mesh.

The **HandlerManager** is responsible for incoming tcp (websocket) connections, and the 
**ServiceMeshManager**, which is responsible for proxying communications to the service 
mesh.

The final design is somewhat under consideration, with the options being:
* Having an overarching coordination class, i.e. a manager of managers
* or the current design where the ServiceMeshManager is both the service mesh proxy
  and the HandlerManager's manager.

It's acknowledge that the two classes are tightly coupled. The physical separation
helps with logical separation of responsibilities and the ability to test them.

It is important to **NOTE** that there's a one-to-one relationship between the
HandlerManager and ServiceMeshManager. The design requires that for each handler
type, there's a dedicated HandlerManager and by inference, a dedicated
ServiceMeshManager with its own connection to the service mesh.

### handler_manager.HandlerManager
The HandlerManager is responsible for TCP(WebSocket) connection handlers, and does 
the following:
* Registers handlers for incoming connections
* Unregistering handlers for closed connections
* Authorization validation of new connections
* Receiving messages from handlers
* Sending messages to handlers
* Sending messages to:
  * all registered handlers
  * one specific handler
  * all handlers registered to one user or a set of specific users

### service_mesh_manager.ServiceMeshManager
* Manages a (NuroPb API) connection to the service mesh.
* Passes messages between HandlerManager and the service mesh API
* Tracks the state of asynchronous requests from handlers and directs responses
  from the service mesh back to the originating handler.
* Is responsible for its and only its, connection authorisation to the service mesh
  transport layer and broker. NOT any on-behalf-of authorisation for handler
  connections.

### Authentication and Authorization

The HandlerManager is not responsible for authentication. It is designed to verify
that authentication has already been done through validating an authorization token 
provided when a new handler is registered. A bearer token is assumed, however there
is plenty of scope for other passwordless authentication mechanisms.

## Implementation instantiation and injection:

On ServiceMeshManager instantiation, and instance of the HandlerManager is passed in.
```python
handler_manager = HandlerManager(
    ...
)
service_mesh_manager = ServiceMeshManager(
    ...,
    handler_manager=handler_manager,
)
```

The challenge provide by this assembly, if forwarding incoming messages from the handlers
to the service mesh. the HandlerManager provides a callback function to be called when
a message is received, `on_handler_message_received`.

There are not many times when HandlerManager is initialised with on_handler_message_received, 
as it is instantiated before ServiceMeshManager. It is however set by the ServiceMeshManager
during its instantiation, as follows:
```python
self._handler_manager = handler_manager
self._handler_manager._on_handler_message_received = self._on_handler_message_received
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/robertbetts/command",
    "name": "nuropb-gw",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9,<3.12",
    "maintainer_email": "",
    "keywords": "python,asynchrous,api,event,rpc,distributed,websockets,sevice-mesh",
    "author": "Robert Betts",
    "author_email": "robert.betts@genoa.io",
    "download_url": "https://files.pythonhosted.org/packages/79/17/874366729fce0a54e0d69bef649b40dd40f6c88f7a887a5707fdd6059501/nuropb_gw-0.1.4.tar.gz",
    "platform": null,
    "description": "# TCP(WebSocket) Service Mesh Gateway\n\nLibrary for providing a TCP(WebSocket) gateway to the Nuropb service mesh. The\nLibrary leverages the Tornado asynchronous networking framework, and can \nalso be used as a template for other TCP connection handlers. In addition, it\ncan also be used as pattern to implement a WebSocket BFF (Backend For Frontend).\n\nThere are two primary classes that interact together in providing `consumer` access\nto the services hosted on the Service Mesh. It's always tricky how to coordinate the \ndependencies between classes, especially when there are bidirectional flows and \nprocess between them.\n\nConsumers are external to the service mesh, and are considered to be untrusted,\nand the nature of the connections to be less reliable. The service mesh transport \nprotocol is implemented AMQP over TCP and is more challenging for broad adoption,\nand especially from browsers and mobile devices. The solution is to provide a \nWebSocket gateway interface to the service mesh.\n\nThe **HandlerManager** is responsible for incoming tcp (websocket) connections, and the \n**ServiceMeshManager**, which is responsible for proxying communications to the service \nmesh.\n\nThe final design is somewhat under consideration, with the options being:\n* Having an overarching coordination class, i.e. a manager of managers\n* or the current design where the ServiceMeshManager is both the service mesh proxy\n  and the HandlerManager's manager.\n\nIt's acknowledge that the two classes are tightly coupled. The physical separation\nhelps with logical separation of responsibilities and the ability to test them.\n\nIt is important to **NOTE** that there's a one-to-one relationship between the\nHandlerManager and ServiceMeshManager. The design requires that for each handler\ntype, there's a dedicated HandlerManager and by inference, a dedicated\nServiceMeshManager with its own connection to the service mesh.\n\n### handler_manager.HandlerManager\nThe HandlerManager is responsible for TCP(WebSocket) connection handlers, and does \nthe following:\n* Registers handlers for incoming connections\n* Unregistering handlers for closed connections\n* Authorization validation of new connections\n* Receiving messages from handlers\n* Sending messages to handlers\n* Sending messages to:\n  * all registered handlers\n  * one specific handler\n  * all handlers registered to one user or a set of specific users\n\n### service_mesh_manager.ServiceMeshManager\n* Manages a (NuroPb API) connection to the service mesh.\n* Passes messages between HandlerManager and the service mesh API\n* Tracks the state of asynchronous requests from handlers and directs responses\n  from the service mesh back to the originating handler.\n* Is responsible for its and only its, connection authorisation to the service mesh\n  transport layer and broker. NOT any on-behalf-of authorisation for handler\n  connections.\n\n### Authentication and Authorization\n\nThe HandlerManager is not responsible for authentication. It is designed to verify\nthat authentication has already been done through validating an authorization token \nprovided when a new handler is registered. A bearer token is assumed, however there\nis plenty of scope for other passwordless authentication mechanisms.\n\n## Implementation instantiation and injection:\n\nOn ServiceMeshManager instantiation, and instance of the HandlerManager is passed in.\n```python\nhandler_manager = HandlerManager(\n    ...\n)\nservice_mesh_manager = ServiceMeshManager(\n    ...,\n    handler_manager=handler_manager,\n)\n```\n\nThe challenge provide by this assembly, if forwarding incoming messages from the handlers\nto the service mesh. the HandlerManager provides a callback function to be called when\na message is received, `on_handler_message_received`.\n\nThere are not many times when HandlerManager is initialised with on_handler_message_received, \nas it is instantiated before ServiceMeshManager. It is however set by the ServiceMeshManager\nduring its instantiation, as follows:\n```python\nself._handler_manager = handler_manager\nself._handler_manager._on_handler_message_received = self._on_handler_message_received\n```\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Websocket gateway library for Nuropb Service Mesh",
    "version": "0.1.4",
    "project_urls": {
        "Homepage": "https://github.com/robertbetts/command",
        "Repository": "https://github.com/robertbetts/command"
    },
    "split_keywords": [
        "python",
        "asynchrous",
        "api",
        "event",
        "rpc",
        "distributed",
        "websockets",
        "sevice-mesh"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4489eb54b9fe229a6276a78276c96125d52796b67805f2cad8394da63b98b828",
                "md5": "fce16a6ae5df06fe13b076f26538ab29",
                "sha256": "669d95fd7e4f6d375e6a4f0c3222cffd5af11f15e872c5520e965a9615433488"
            },
            "downloads": -1,
            "filename": "nuropb_gw-0.1.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fce16a6ae5df06fe13b076f26538ab29",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9,<3.12",
            "size": 21171,
            "upload_time": "2023-09-21T21:43:21",
            "upload_time_iso_8601": "2023-09-21T21:43:21.371259Z",
            "url": "https://files.pythonhosted.org/packages/44/89/eb54b9fe229a6276a78276c96125d52796b67805f2cad8394da63b98b828/nuropb_gw-0.1.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7917874366729fce0a54e0d69bef649b40dd40f6c88f7a887a5707fdd6059501",
                "md5": "0d8b6fe7ff41264504a0874982b34d01",
                "sha256": "9ea7c8130ebd1bf2da470ad7d886b1762dffc7d613b3a3b8ccc3173ab5d4a372"
            },
            "downloads": -1,
            "filename": "nuropb_gw-0.1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "0d8b6fe7ff41264504a0874982b34d01",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9,<3.12",
            "size": 18075,
            "upload_time": "2023-09-21T21:43:23",
            "upload_time_iso_8601": "2023-09-21T21:43:23.164250Z",
            "url": "https://files.pythonhosted.org/packages/79/17/874366729fce0a54e0d69bef649b40dd40f6c88f7a887a5707fdd6059501/nuropb_gw-0.1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-21 21:43:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "robertbetts",
    "github_project": "command",
    "github_not_found": true,
    "lcname": "nuropb-gw"
}
        
Elapsed time: 0.38367s