detail_item#
See DetailItem.
- class aws_resource_search.items.detail_item.T_DETAIL_ITEM_VARIABLES(*args, **kwargs)[source]#
Note
Copy is more common than url in detail item.
- class aws_resource_search.items.detail_item.DetailItem(title: str, subtitle: ~typing.Optional[str] = None, uid: str = <factory>, arg: ~typing.Optional[str] = None, autocomplete: ~typing.Optional[str] = None, variables: ~aws_resource_search.items.detail_item.T_DETAIL_ITEM_VARIABLES = <factory>)[source]#
Represent a detail information of an AWS resource in the dropdown menu.
Why this class
- We need to write logic to create
Itemin the aws_resource_search.res.${aws_service}.pysource code. This class provides utility methods to make the code clean and descriptive.
- We need to write logic to create
- An
Itemusually comes with user action. We need to store the user action argument in
variablesand then implement thexyz_handlerfunction to handle the user action. In this project, we have a very clear mind of user action patterns. This class provides utility methods to enable pre-defined user action smartly based on the input, so we no longer need to implementvariableslogics andxyz_handlerfunctions in most cases.
- An
- classmethod new(title: str, subtitle: Optional[str] = None, copy: Optional[str] = None, url: Optional[str] = None, uid: Optional[str] = None, arg: Optional[str] = None, autocomplete: Optional[str] = None)[source]#
The factory method to create a new
ArsBaseIteminstance.- Parameters:
title – first line of the item. It has a checkbox in front of it to indicate whether it is selected.
subtitle – second line of the item.
copy – the text to copy to clipboard.
url – the url to open in browser.
uid – item unique id. The UI use this to distinguish different items.
arg – argument that will be passed to the action.
autocomplete – the text that will be filled in the input box when user hits
TABkey.
- enter_handler(ui: UI)[source]#
Behavior:
- If we have a URL, it will be opened in the browser or print the url
to the terminal if the terminal device can not do so.
- If not, the Enter key will function similarly to the Tab key,
it will autocomplete.
- ctrl_a_handler(ui: UI)[source]#
Behavior:
- If we have a copy text, it will copy the text to clipboard or print the text
to the terminal if the terminal device can not do so.
If we don’t have copy text but have url, then treat url as copy text.
- ctrl_u_handler(ui: UI)[source]#
Behavior:
- If we have an url, it will copy the url to clipboard or print the url
to the terminal if the terminal device can not do so.
If we don’t have URL but have copy text, then treat copy text as url.
- classmethod from_detail(key: str, value: Any, key_text: Optional[str] = None, value_text: Optional[str] = None, url: Optional[str] = None, copy: Optional[str] = None, uid: Optional[str] = None)[source]#
A utility method to create :class`DetailItem` from structured detail information.
This method will be used in
aws_resource_search.searcher.base_document.BaseDocument.get_detailsmethod.A ‘detail’ is just a simple key value pair. For example, for S3 bucket. the ‘bucket_name’ is the key and the ‘your-bucket-name’ is the value.
- Parameters:
key – key of the detail, it’s the original data
value – value of the detail, it’s the original data. This is also the text that will be copied to clipboard when user tap Ctrl + A`.
key_text – the
${key} = ${value}text to display in the UI. if not provided, usekeyas the text.value_text – the
${key} = ${value}text to display in the UI. if not provided, usevalueas the text.url – if specified, user can hit Enter key to open the url in browser, and Ctrl + U to copy it.
uid – this is for uid
- classmethod from_env_vars(env_vars: Dict[str, str], url: Optional[str] = None) List[DetailItem][source]#
A utility method to create many :class`DetailItem` from environment variable key value pairs.
- classmethod from_tags(tags: Dict[str, str], url: Optional[str] = None) List[DetailItem][source]#
Create MANY
DetailItemfrom AWS resource tag key value pairs.
- classmethod get_initial_detail_items(doc: ResourceDocument, ars: ARS, arn_key: str = 'arn') List[DetailItem][source]#
Most AWS resource detail should have one ARN item that user can tap “Ctrl A” to copy and tap “Enter” to open url. Only a few AWS resource doesn’t support ARN (for example, glue job run).
Note
This method is to simplify the authoring of the
aws_resource_search.documents.resource_document.ResourceDocument.get_details()method.Usage example:
>>> class S3BucketDocument(ResourceDocument): ... def get_details(self, ars: ARS): ... detail_items = DetailItem.get_initial_detail_items(self, ars) ... ...
- static error_handling(detail_items: List[T_ARS_ITEM])[source]#
A context manager to add additional detail items to the list. It automatically captures exception and creates
ExceptionItemto explain what went wrong.Usage example:
>>> class S3BucketDocument(ResourceDocument): ... def get_details(self, ars: ARS): ... detail_items = DetailItem.get_initial_detail_items(self, ars) ... with DetailItem.error_handling(detail_items): ... res = ars.bsm.s3_client.get_bucket_policy(...) ... detail_items.append(DetailItem.from_detail(...))
Note
This method is to simplify the authoring of the
aws_resource_search.documents.resource_document.ResourceDocument.get_details()method.