nuropb.contexts.describe
Module Contents
Functions
This function checks if a method has been decorated with @publish_to_mesh |
|
Decorator to expose class methods to the service mesh |
|
Returns a description of the class methods that will be exposed to the service mesh |
Data
API
- nuropb.contexts.describe.logger
None
- nuropb.contexts.describe.AuthorizeFunc
None
- nuropb.contexts.describe.method_visible_on_mesh(method: Callable[..., Any]) bool
This function checks if a method has been decorated with @publish_to_mesh
- Parameters:
method – callable
- Returns:
bool
- nuropb.contexts.describe.publish_to_mesh(original_method: Optional[Callable[..., Any]] = None, *, hide_method: Optional[bool] = False, authorize_func: Optional[nuropb.contexts.describe.AuthorizeFunc] = None, context_token_key: Optional[str] = 'Authorization', requires_encryption: Optional[bool] = False, description: Optional[str] = None) Any
Decorator to expose class methods to the service mesh
When a service instance is connected to a service mesh via the service mesh client, all the standard public methods of the service instance is available to the service mesh. Methods that start with underscore will always remain hidden. methods that are explicitly marked as hidden by publish_to_mesh will also not be published.
When and authorise_func is specified, this function will be called with the contents of context[context_token_key]. if the token validation is unsuccessful, then a failed authorization exception is raised. If successful then ctx.user_claims is populated with claims attached to the token.
When requires_encryption is True, the service mesh will encrypt the payload of the service message request and response. It is the responsibility of the process making the request to ensure that it has the target service’s public key.
As illustrated by the example below, @nuropb_context must always be on top of @publish_to_mesh when both decorators are used.
@nuropb_context @publish_to_mesh(context_token_key="Authorization", authorise_func=authorise_token) def hello_requires_auth(...)
- Parameters:
original_method –
hide_method – bool, (False) if True then the method will not be published to the service mesh
authorize_func – callable(token: str) -> dict
context_token_key – str, (“Authorization”), incoming request context key containing the bearer token
requires_encryption – bool, (False) if True then the service mesh expect and encrypted payload
description – str, if present then override the methods doc string
- Returns:
- nuropb.contexts.describe.describe_service(class_instance: object) Dict[str, Any] | None
Returns a description of the class methods that will be exposed to the service mesh