Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6b86d40

Browse files
committedMay 19, 2023
add docstring
1 parent 12150e2 commit 6b86d40

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
 

‎aws_lambda_powertools/shared/user_agent.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,47 @@
2222

2323

2424
def _initializer_botocore_session(session):
25+
"""
26+
Pass in Botocore session and register _create_feature_function to append user-agent, for more details see
27+
https://github.com/boto/botocore/pull/2682
28+
29+
session.register:
30+
https://github.com/boto/botocore/blob/develop/botocore/session.py#L703
31+
32+
Parameters
33+
----------
34+
session: Botocore.session.Session
35+
A botocore session passed in to register user-agent function
36+
37+
"""
2538
try:
2639
session.register(TARGET_SDK_EVENT, _create_feature_function(DEFAULT_FEATURE))
2740
except Exception:
2841
logger.debug("Can't add extra header User-Agent")
2942

3043

3144
def _create_feature_function(feature):
45+
"""
46+
Create a add_powertools_feature function using the given feature paramter
47+
add_powertools_feature will be returned and to be regiestered in boto3's event system
48+
once registered, add_powertools_feature will append the given feature string to user-agent of AWS SDK's request
49+
50+
Parameters
51+
----------
52+
feature: str
53+
54+
Returns:
55+
-------
56+
add_powertools_feature: Callable
57+
58+
"""
59+
3260
def add_powertools_feature(request, **kwargs):
61+
"""
62+
Signiture of this function is required at Boto3's event system. See:
63+
https://boto3.amazonaws.com/v1/documentation/api/latest/guide/events.html
64+
65+
"""
3366
try:
3467
headers = request.headers
3568
header_user_agent: str = (
@@ -51,6 +84,18 @@ def add_powertools_feature(request, **kwargs):
5184

5285
# Add feature user-agent to given sdk boto3.session
5386
def register_feature_to_session(session, feature):
87+
"""
88+
Register the given feature string given session's event system
89+
When this session makes an api request, the given feature will be appended to request's user-agent
90+
91+
Parameters
92+
----------
93+
session: boto3.session.Session
94+
session to register
95+
feature: str
96+
the feature string in Powertools, e.g.:streaming
97+
98+
"""
5499
try:
55100
session.events.register(TARGET_SDK_EVENT, _create_feature_function(feature))
56101
except AttributeError as e:
@@ -59,6 +104,18 @@ def register_feature_to_session(session, feature):
59104

60105
# Add feature user-agent to given sdk boto3.client
61106
def register_feature_to_client(client, feature):
107+
"""
108+
Register the given feature string given client's event system
109+
When this client makes an api request, the given feature will be appended to request's user-agent
110+
111+
Parameters
112+
----------
113+
client: boto3.session.Session.client
114+
client to register
115+
feature: str
116+
the feature string in Powertools, e.g.:streaming
117+
118+
"""
62119
try:
63120
client.meta.events.register(TARGET_SDK_EVENT, _create_feature_function(feature))
64121
except AttributeError as e:
@@ -67,6 +124,18 @@ def register_feature_to_client(client, feature):
67124

68125
# Add feature user-agent to given sdk boto3.resource
69126
def register_feature_to_resource(resource, feature):
127+
"""
128+
Register the given feature string given resource's event system
129+
When this resource makes an api request, the given feature will be appended to request's user-agent
130+
131+
Parameters
132+
----------
133+
resource: boto3.session.Session.resource
134+
resource to register
135+
feature: str
136+
the feature string in Powertools, e.g.:streaming
137+
138+
"""
70139
try:
71140
resource.meta.client.meta.events.register(TARGET_SDK_EVENT, _create_feature_function(feature))
72141
except AttributeError as e:

0 commit comments

Comments
 (0)
Please sign in to comment.