Skip to content

Commit 629cb39

Browse files
authored
Extend user agent with aws-gate version information (#245)
1 parent e9ccc38 commit 629cb39

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

aws_gate/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import boto3
99
import botocore
1010

11+
from aws_gate import __version__
1112
from aws_gate.constants import DEFAULT_GATE_BIN_PATH, PLUGIN_NAME
1213
from aws_gate.exceptions import AWSConnectionError
1314

@@ -55,6 +56,10 @@ def _create_aws_session(region_name=None, profile_name=None):
5556

5657
session = boto3.session.Session(**kwargs)
5758

59+
# Add aws-gate version to the client user-agent
60+
# pylint: disable=protected-access
61+
session._session.user_agent_extra += " " + "aws-gate/{}".format(__version__)
62+
5863
return session
5964

6065

tests/unit/test_utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from hypothesis import given
88
from hypothesis.strategies import lists, text
99

10+
from aws_gate import __version__
1011
from aws_gate.exceptions import AWSConnectionError
1112
from aws_gate.utils import (
1213
is_existing_profile,
@@ -50,6 +51,13 @@ def test_create_aws_session(mocker):
5051
assert session_mock.Session.call_args == mocker.call(region_name="eu-west-1")
5152

5253

54+
def test_create_aws_session_user_agent():
55+
session = _create_aws_session(region_name="eu-west-1")
56+
57+
# pylint: disable=protected-access
58+
assert "aws-gate/{}".format(__version__) in session._session.user_agent()
59+
60+
5361
def test_create_aws_session_with_profile(mocker):
5462
session_mock = mocker.patch(
5563
"aws_gate.utils.boto3.session", return_value=mocker.MagicMock()

0 commit comments

Comments
 (0)