Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Python 3.13 CI #587

Merged
merged 47 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
70de9df
python 313 CI
waahm7 Aug 22, 2024
d2b0b27
wip test
waahm7 Aug 26, 2024
f4f6ea2
fix warnings
waahm7 Aug 26, 2024
d19acc8
new changes
waahm7 Sep 19, 2024
aaf07af
Merge branch 'main' into python3.13
waahm7 Sep 19, 2024
d7d4bf9
builder version
waahm7 Sep 19, 2024
d269cc9
try new creds
waahm7 Sep 19, 2024
d89746c
fix typo
waahm7 Sep 19, 2024
dce2f06
id token
waahm7 Sep 19, 2024
2555dbd
fix ci
waahm7 Sep 19, 2024
45119b1
copy paste ci fix
waahm7 Sep 19, 2024
f6abe3d
test that I have permissions
waahm7 Sep 19, 2024
7ddadf4
stupid me
waahm7 Sep 19, 2024
2266d9d
maybe something uses default region?
waahm7 Sep 19, 2024
2adb9d4
test-creds
waahm7 Sep 19, 2024
87ffaa1
disable other CIs
waahm7 Sep 19, 2024
f820bab
fix unused warning
waahm7 Sep 19, 2024
281d3c6
fix bugs
waahm7 Sep 19, 2024
e94ed91
reenable CI
waahm7 Sep 19, 2024
c5ff663
lint
waahm7 Sep 19, 2024
3577f75
fix freebsd
waahm7 Sep 19, 2024
5b38b52
fix openbsd
waahm7 Sep 19, 2024
0b598b0
fix default chain test
waahm7 Sep 19, 2024
3fc70f2
fix static
waahm7 Sep 19, 2024
dfcafc4
fix mqtt311
waahm7 Sep 19, 2024
c517439
fix something
waahm7 Sep 19, 2024
267a4b9
remove unneeded comment
waahm7 Sep 19, 2024
7801abe
builder fix
waahm7 Sep 19, 2024
2544616
move code duplication to a function
waahm7 Sep 23, 2024
9fa3ac2
warning fix
waahm7 Sep 23, 2024
0b7bd7f
blank lines
waahm7 Sep 23, 2024
b3d571e
fix doc
waahm7 Sep 23, 2024
0d591fa
fix return type
waahm7 Sep 23, 2024
5b960e8
Update continuous-delivery/build-wheels-manylinux2014-x86_64.sh
waahm7 Sep 23, 2024
ef9ddd1
Update continuous-delivery/build-wheels-manylinux2014-aarch64.sh
waahm7 Sep 23, 2024
9d3c674
Update continuous-delivery/build-wheels-musllinux-1-1-aarch64.sh
waahm7 Sep 23, 2024
d5c0226
Update continuous-delivery/build-wheels-musllinux-1-1-x86_64.sh
waahm7 Sep 23, 2024
bfb523b
Update continuous-delivery/build-wheels-osx.sh
waahm7 Sep 23, 2024
634cccf
Update setup.py
waahm7 Sep 23, 2024
fdf644c
Update setup.py
waahm7 Sep 23, 2024
80de4fc
Update setup.py
waahm7 Sep 23, 2024
171843e
Update continuous-delivery/build-wheels-win32.bat
waahm7 Sep 23, 2024
7848649
Update continuous-delivery/build-wheels-win64.bat
waahm7 Sep 23, 2024
76df344
do incref for pre 3.13
waahm7 Sep 23, 2024
4b68a14
Return NULL instead of Py_NONE (so it works better with Py_XDECREF)
graebm Sep 24, 2024
af82781
remove AWS_FATAL_ASSERT
graebm Sep 24, 2024
9277ac2
fix warning
waahm7 Sep 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
207 changes: 147 additions & 60 deletions .github/workflows/ci.yml

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions continuous-delivery/build-wheels-manylinux2014-aarch64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ auditwheel repair --plat manylinux2014_aarch64 dist/awscrt-*cp311*.whl
# Don't need to build wheels for Python 3.12 and later.
waahm7 marked this conversation as resolved.
Show resolved Hide resolved
# The 3.11 wheel uses the stable ABI, so it works with newer versions too.

# We are using the Python 3.13 stable ABI from Python 3.13 onwards because of deprecated functions.
/opt/python/cp313-cp313/bin/python setup.py sdist bdist_wheel
auditwheel repair --plat manylinux2014_aarch64 dist/awscrt-*cp313*.whl

rm dist/*.whl
cp -rv wheelhouse/* dist/

Expand Down
4 changes: 4 additions & 0 deletions continuous-delivery/build-wheels-manylinux2014-x86_64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ auditwheel repair --plat manylinux2014_x86_64 dist/awscrt-*cp311*.whl
# Don't need to build wheels for Python 3.12 and later.
waahm7 marked this conversation as resolved.
Show resolved Hide resolved
# The 3.11 wheel uses the stable ABI, so it works with newer versions too.

# We are using the Python 3.13 stable ABI from Python 3.13 onwards because of deprecated functions.
/opt/python/cp313-cp313/bin/python setup.py sdist bdist_wheel
auditwheel repair --plat manylinux2014_x86_64 dist/awscrt-*cp313*.whl

rm dist/*.whl
cp -rv wheelhouse/* dist/

Expand Down
4 changes: 4 additions & 0 deletions continuous-delivery/build-wheels-musllinux-1-1-aarch64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ auditwheel repair --plat musllinux_1_1_aarch64 dist/awscrt-*cp311*.whl
# Don't need to build wheels for Python 3.12 and later.
waahm7 marked this conversation as resolved.
Show resolved Hide resolved
# The 3.11 wheel uses the stable ABI, so it works with newer versions too.

# We are using the Python 3.13 stable ABI from Python 3.13 onwards because of deprecated functions.
/opt/python/cp313-cp313/bin/python setup.py sdist bdist_wheel
auditwheel repair --plat musllinux_1_1_aarch64 dist/awscrt-*cp313*.whl

rm dist/*.whl
cp -rv wheelhouse/* dist/

Expand Down
4 changes: 4 additions & 0 deletions continuous-delivery/build-wheels-musllinux-1-1-x86_64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ auditwheel repair --plat musllinux_1_1_x86_64 dist/awscrt-*cp311*.whl
# Don't need to build wheels for Python 3.12 and later.
waahm7 marked this conversation as resolved.
Show resolved Hide resolved
# The 3.11 wheel uses the stable ABI, so it works with newer versions too.

# We are using the Python 3.13 stable ABI from Python 3.13 onwards because of deprecated functions.
/opt/python/cp313-cp313/bin/python setup.py sdist bdist_wheel
auditwheel repair --plat musllinux_1_1_x86_64 dist/awscrt-*cp313*.whl

rm dist/*.whl
cp -rv wheelhouse/* dist/

Expand Down
3 changes: 3 additions & 0 deletions continuous-delivery/build-wheels-osx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ set -ex
# Don't need to build wheels for Python 3.12 and later.
waahm7 marked this conversation as resolved.
Show resolved Hide resolved
# The 3.11 wheel uses the stable ABI, so it works with newer versions too.

# We are using the Python 3.13 stable ABI from Python 3.13 onwards because of deprecated functions.
/Library/Frameworks/Python.framework/Versions/3.13/bin/python3 setup.py sdist bdist_wheel

#now you just need to run twine (that's in a different script)
6 changes: 6 additions & 0 deletions continuous-delivery/build-wheels-win32.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
"C:\Program Files (x86)\Python310-32\python.exe" setup.py sdist bdist_wheel || goto error
"C:\Program Files (x86)\Python311-32\python.exe" setup.py sdist bdist_wheel || goto error

:: Don't need to build wheels for Python 3.12 and later.
waahm7 marked this conversation as resolved.
Show resolved Hide resolved
:: The 3.11 wheel uses the stable ABI, so it works with newer versions too.

:: We are using the 3.13 stable ABI from 3.13 onwards because of deprecated functions.
"C:\Program Files (x86)\Python313-32\python.exe" setup.py sdist bdist_wheel || goto error

goto :EOF

:error
Expand Down
6 changes: 6 additions & 0 deletions continuous-delivery/build-wheels-win64.bat
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
"C:\Program Files\Python310\python.exe" setup.py sdist bdist_wheel || goto error
"C:\Program Files\Python311\python.exe" setup.py sdist bdist_wheel || goto error

:: Don't need to build wheels for Python 3.12 and later.
waahm7 marked this conversation as resolved.
Show resolved Hide resolved
:: The 3.11 wheel uses the stable ABI, so it works with newer versions too.

:: We are using the 3.13 stable ABI from 3.13 onwards because of deprecated functions.
"C:\Program Files\Python313\python.exe" setup.py sdist bdist_wheel || goto error

goto :EOF

:error
Expand Down
2 changes: 1 addition & 1 deletion crt/aws-c-mqtt
Submodule aws-c-mqtt updated 45 files
+12 −3 .github/workflows/ci.yml
+4 −6 .github/workflows/clang-format.yml
+2 −0 CMakeLists.txt
+29 −0 bin/elastishadow/CMakeLists.txt
+1,272 −0 bin/elastishadow/main.c
+47 −0 format-check.py
+0 −24 format-check.sh
+9 −0 include/aws/mqtt/mqtt.h
+54 −0 include/aws/mqtt/private/client_impl.h
+24 −0 include/aws/mqtt/private/client_impl_shared.h
+204 −0 include/aws/mqtt/private/mqtt311_listener.h
+220 −0 include/aws/mqtt/private/request-response/protocol_adapter.h
+23 −0 include/aws/mqtt/private/request-response/request_response_client.h
+264 −0 include/aws/mqtt/private/request-response/subscription_manager.h
+2 −0 include/aws/mqtt/private/shared.h
+274 −0 include/aws/mqtt/request-response/request_response_client.h
+3 −0 include/aws/mqtt/v5/mqtt5_client.h
+176 −58 source/client.c
+6 −0 source/client_channel_handler.c
+9 −0 source/client_impl_shared.c
+25 −0 source/mqtt.c
+329 −0 source/mqtt311_listener.c
+2 −3 source/packets.c
+964 −0 source/request-response/protocol_adapter.c
+2,276 −0 source/request-response/request_response_client.c
+822 −0 source/request-response/subscription_manager.c
+1 −1 source/shared.c
+1 −1 source/v5/mqtt5_client.c
+1 −0 source/v5/mqtt5_listener.c
+14 −0 source/v5/mqtt5_to_mqtt3_adapter.c
+135 −3 tests/CMakeLists.txt
+1,784 −0 tests/request-response/protocol_adapter_tests.c
+3,151 −0 tests/request-response/request_response_client_tests.c
+2,877 −0 tests/request-response/subscription_manager_tests.c
+739 −998 tests/v3/connection_state_test.c
+488 −0 tests/v3/mqtt311_listener_test.c
+582 −0 tests/v3/mqtt311_testing_utils.c
+155 −0 tests/v3/mqtt311_testing_utils.h
+51 −2 tests/v3/mqtt_mock_server_handler.c
+18 −0 tests/v3/mqtt_mock_server_handler.h
+22 −42 tests/v5/mqtt5_client_tests.c
+26 −0 tests/v5/mqtt5_testing_utils.c
+20 −0 tests/v5/mqtt5_testing_utils.h
+0 −4 tests/v5/mqtt5_to_mqtt3_adapter_tests.c
+2 −1 tests/v5/mqtt5_topic_alias_tests.c
2 changes: 1 addition & 1 deletion crt/aws-lc
2 changes: 1 addition & 1 deletion crt/s2n
Submodule s2n updated from 87f4a0 to 08d413
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,10 @@ def awscrt_ext():
else:
extra_link_args += ['-Wl,--fatal-warnings']

if sys.version_info >= (3, 11):
if sys.version_info >= (3, 13):
waahm7 marked this conversation as resolved.
Show resolved Hide resolved
define_macros.append(('Py_LIMITED_API', '0x030D0000'))
waahm7 marked this conversation as resolved.
Show resolved Hide resolved
py_limited_api = True
elif sys.version_info >= (3, 11):
define_macros.append(('Py_LIMITED_API', '0x030B0000'))
waahm7 marked this conversation as resolved.
Show resolved Hide resolved
py_limited_api = True

Expand Down
4 changes: 3 additions & 1 deletion source/http_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ static void s_on_stream_complete(struct aws_http_stream *native_stream, int erro
}

/* DECREF python self, we don't need to force it to stay alive any longer. */
Py_DECREF(PyWeakref_GetObject(stream->self_proxy));
PyObject *self = aws_py_weakref_get_ref(stream->self_proxy);
Py_XDECREF(self);
aws_py_weakref_release_ref(self);

PyGILState_Release(state);
/*************** GIL RELEASE ***************/
Expand Down
21 changes: 21 additions & 0 deletions source/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,27 @@ PyObject *aws_py_memory_view_from_byte_buffer(struct aws_byte_buf *buf) {
return PyMemoryView_FromMemory(mem_start, mem_size, PyBUF_WRITE);
}

PyObject *aws_py_weakref_get_ref(PyObject *object) {
PyObject *self = Py_None;
#if PY_VERSION_HEX >= 0x030D0000 /* Check if Python version is 3.13 or higher */
if (PyWeakref_GetRef(object, &self) < 0) { /* strong reference */
return Py_None;
}
#else
/* PyWeakref_GetObject is deprecated since python 3.13 */
self = PyWeakref_GetObject(object); /* borrowed reference */
graebm marked this conversation as resolved.
Show resolved Hide resolved
#endif
return self;
}

void aws_py_weakref_release_ref(PyObject *object) {
(void)object;
/* Python versions before 3.13 returns a borrowed reference */
#if PY_VERSION_HEX >= 0x030D0000
Py_XDECREF(object);
#endif
}
graebm marked this conversation as resolved.
Show resolved Hide resolved

int aws_py_gilstate_ensure(PyGILState_STATE *out_state) {
if (AWS_LIKELY(Py_IsInitialized())) {
*out_state = PyGILState_Ensure();
Expand Down
6 changes: 6 additions & 0 deletions source/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ PyObject *aws_py_get_error_message(PyObject *self, PyObject *args);
/* Create a write-only memoryview from the remaining free space in an aws_byte_buf */
PyObject *aws_py_memory_view_from_byte_buffer(struct aws_byte_buf *buf);

/* Python 3.13+ changed the function to get a reference from WeakRef. This function is an abstraction over two different
* APIs since we support Python versions before 3.13.*/
PyObject *aws_py_weakref_get_ref(PyObject *object);
/* Release the weakwef provided by the `aws_py_weakref_get_ref`. */
void aws_py_weakref_release_ref(PyObject *object);

/* Allocator that calls into PyObject_[Malloc|Free|Realloc] */
struct aws_allocator *aws_py_get_allocator(void);

Expand Down
20 changes: 13 additions & 7 deletions source/mqtt_client_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ static void s_on_connection_success(
return; /* Python has shut down. Nothing matters anymore, but don't crash */
}

PyObject *self = PyWeakref_GetObject(py_connection->self_proxy); /* borrowed reference */
PyObject *self = aws_py_weakref_get_ref(py_connection->self_proxy);
if (self != Py_None) {
PyObject *success_result =
PyObject_CallMethod(self, "_on_connection_success", "(iN)", return_code, PyBool_FromLong(session_present));
Expand All @@ -151,6 +151,7 @@ static void s_on_connection_success(
}
}

aws_py_weakref_release_ref(self);
PyGILState_Release(state);
}

Expand All @@ -167,7 +168,7 @@ static void s_on_connection_failure(struct aws_mqtt_client_connection *connectio
return; /* Python has shut down. Nothing matters anymore, but don't crash */
}

PyObject *self = PyWeakref_GetObject(py_connection->self_proxy); /* borrowed reference */
PyObject *self = aws_py_weakref_get_ref(py_connection->self_proxy);
if (self != Py_None) {
PyObject *success_result = PyObject_CallMethod(self, "_on_connection_failure", "(i)", error_code);
if (success_result) {
Expand All @@ -177,6 +178,7 @@ static void s_on_connection_failure(struct aws_mqtt_client_connection *connectio
}
}

aws_py_weakref_release_ref(self);
PyGILState_Release(state);
}

Expand All @@ -194,7 +196,7 @@ static void s_on_connection_interrupted(struct aws_mqtt_client_connection *conne
}

/* Ensure that python class is still alive */
PyObject *self = PyWeakref_GetObject(py_connection->self_proxy); /* borrowed reference */
PyObject *self = aws_py_weakref_get_ref(py_connection->self_proxy);
if (self != Py_None) {
PyObject *result = PyObject_CallMethod(self, "_on_connection_interrupted", "(i)", error_code);
if (result) {
Expand All @@ -204,6 +206,7 @@ static void s_on_connection_interrupted(struct aws_mqtt_client_connection *conne
}
}

aws_py_weakref_release_ref(self);
PyGILState_Release(state);
}

Expand All @@ -227,7 +230,7 @@ static void s_on_connection_resumed(
}

/* Ensure that python class is still alive */
PyObject *self = PyWeakref_GetObject(py_connection->self_proxy); /* borrowed reference */
PyObject *self = aws_py_weakref_get_ref(py_connection->self_proxy);
if (self != Py_None) {
PyObject *result =
PyObject_CallMethod(self, "_on_connection_resumed", "(iN)", return_code, PyBool_FromLong(session_present));
Expand All @@ -237,7 +240,7 @@ static void s_on_connection_resumed(
PyErr_WriteUnraisable(PyErr_Occurred());
}
}

aws_py_weakref_release_ref(self);
PyGILState_Release(state);
}

Expand All @@ -258,7 +261,7 @@ static void s_on_connection_closed(

struct mqtt_connection_binding *py_connection = userdata;
/* Ensure that python class is still alive */
PyObject *self = PyWeakref_GetObject(py_connection->self_proxy); /* borrowed reference */
PyObject *self = aws_py_weakref_get_ref(py_connection->self_proxy);
if (self != Py_None) {
PyObject *result = PyObject_CallMethod(self, "_on_connection_closed", "()");
if (result) {
Expand All @@ -268,6 +271,7 @@ static void s_on_connection_closed(
}
}

aws_py_weakref_release_ref(self);
PyGILState_Release(state);
}

Expand Down Expand Up @@ -535,7 +539,8 @@ static void s_ws_handshake_transform(
}

/* Ensure python mqtt connection object is still alive */
PyObject *connection_py = PyWeakref_GetObject(connection_binding->self_proxy); /* borrowed reference */

PyObject *connection_py = aws_py_weakref_get_ref(connection_binding->self_proxy);
if (connection_py == Py_None) {
aws_raise_error(AWS_ERROR_INVALID_STATE);
goto done;
Expand Down Expand Up @@ -593,6 +598,7 @@ static void s_ws_handshake_transform(
done:;
/* Save off error code, so it doesn't got stomped before we pass it to callback*/
int error_code = aws_last_error();
aws_py_weakref_release_ref(connection_py);

if (ws_transform_capsule) {
Py_DECREF(ws_transform_capsule);
Expand Down
45 changes: 10 additions & 35 deletions test/test_mqtt5_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,40 +197,6 @@ def test_mqtt5_ws_cred_static(self):
input_role_secret_access_key,
input_role_session_token
)
credentials = auth.AwsCredentialsProvider.new_default_chain()

def sign_function(transform_args, **kwargs):
signing_config = auth.AwsSigningConfig(
algorithm=auth.AwsSigningAlgorithm.V4,
signature_type=auth.AwsSignatureType.HTTP_REQUEST_QUERY_PARAMS,
credentials_provider=credentials,
region=input_region,
service="iotdevicegateway",
omit_session_token=True
)
signing_future = auth.aws_sign_request(
http_request=transform_args.http_request,
signing_config=signing_config)
signing_future.add_done_callback(lambda x: transform_args.set_done(x.exception()))
client_options.websocket_handshake_transform = sign_function
client_options.tls_ctx = io.ClientTlsContext(io.TlsContextOptions())

callbacks = Mqtt5TestCallbacks()
client = self._create_client(client_options=client_options, callbacks=callbacks)
client.start()
callbacks.future_connection_success.result(TIMEOUT)
client.stop()
callbacks.future_stopped.result(TIMEOUT)

def test_mqtt5_ws_cred_default(self):
input_host_name = _get_env_variable("AWS_TEST_MQTT5_IOT_CORE_HOST")
input_region = _get_env_variable("AWS_TEST_MQTT5_IOT_CORE_REGION")

client_options = mqtt5.ClientOptions(
host_name=input_host_name,
port=443
)
credentials = auth.AwsCredentialsProvider.new_default_chain()

def sign_function(transform_args, **kwargs):
signing_config = auth.AwsSigningConfig(
Expand Down Expand Up @@ -380,6 +346,12 @@ def sign_function(transform_args, **kwargs):
callbacks.future_stopped.result(TIMEOUT)

def test_mqtt5_ws_cred_environment(self):
self._test_mqtt5_ws_cred_environment(use_default_chain=False)

def test_mqtt5_ws_cred_default_chain(self):
self._test_mqtt5_ws_cred_environment(use_default_chain=True)

def _test_mqtt5_ws_cred_environment(self, use_default_chain):
input_host_name = _get_env_variable("AWS_TEST_MQTT5_IOT_CORE_HOST")
input_access_key = _get_env_variable("AWS_TEST_MQTT5_ROLE_CREDENTIAL_ACCESS_KEY")
input_secret_access_key = _get_env_variable("AWS_TEST_MQTT5_ROLE_CREDENTIAL_SECRET_ACCESS_KEY")
Expand All @@ -399,7 +371,10 @@ def test_mqtt5_ws_cred_environment(self):
os.environ["AWS_SECRET_ACCESS_KEY"] = input_secret_access_key
os.environ["AWS_SESSION_TOKEN"] = input_session_token
# This should load the environment variables we just set
credentials = auth.AwsCredentialsProvider.new_environment()
if use_default_chain:
credentials = auth.AwsCredentialsProvider.new_default_chain()
else:
credentials = auth.AwsCredentialsProvider.new_environment()

def sign_function(transform_args, **kwargs):
signing_config = auth.AwsSigningConfig(
Expand Down
47 changes: 11 additions & 36 deletions test/test_mqtt_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,40 +136,6 @@ def sign_function(transform_args, **kwargs):
connection.connect().result(TIMEOUT)
connection.disconnect().result(TIMEOUT)

def test_mqtt311_ws_cred_default(self):
input_host_name = _get_env_variable("AWS_TEST_MQTT311_IOT_CORE_HOST")
input_region = _get_env_variable("AWS_TEST_MQTT311_IOT_CORE_REGION")

credentials = auth.AwsCredentialsProvider.new_default_chain()

def sign_function(transform_args, **kwargs):
signing_config = auth.AwsSigningConfig(
algorithm=auth.AwsSigningAlgorithm.V4,
signature_type=auth.AwsSignatureType.HTTP_REQUEST_QUERY_PARAMS,
credentials_provider=credentials,
region=input_region,
service="iotdevicegateway",
omit_session_token=True
)
signing_future = auth.aws_sign_request(
http_request=transform_args.http_request,
signing_config=signing_config)
signing_future.add_done_callback(lambda x: transform_args.set_done(x.exception()))

elg = EventLoopGroup()
resolver = DefaultHostResolver(elg)
bootstrap = ClientBootstrap(elg, resolver)
client = Client(bootstrap, ClientTlsContext(TlsContextOptions()))
connection = Connection(
client=client,
client_id=create_client_id(),
host_name=input_host_name,
port=int(443),
use_websockets=True,
websocket_handshake_transform=sign_function)
connection.connect().result(TIMEOUT)
connection.disconnect().result(TIMEOUT)

def test_mqtt311_ws_cred_cognito(self):
input_cognito_endpoint = _get_env_variable("AWS_TEST_MQTT311_COGNITO_ENDPOINT")
input_cognito_identity = _get_env_variable("AWS_TEST_MQTT311_COGNITO_IDENTITY")
Expand Down Expand Up @@ -300,6 +266,12 @@ def sign_function(transform_args, **kwargs):
connection.disconnect().result(TIMEOUT)

def test_mqtt311_ws_cred_environment(self):
self._test_mqtt311_ws_cred_environment(use_default_chain=False)

def test_mqtt311_ws_cred_default(self):
self._test_mqtt311_ws_cred_environment(use_default_chain=True)

def _test_mqtt311_ws_cred_environment(self, use_default_chain):
input_access_key = _get_env_variable("AWS_TEST_MQTT311_ROLE_CREDENTIAL_ACCESS_KEY")
input_secret_access_key = _get_env_variable("AWS_TEST_MQTT311_ROLE_CREDENTIAL_SECRET_ACCESS_KEY")
input_session_token = _get_env_variable("AWS_TEST_MQTT311_ROLE_CREDENTIAL_SESSION_TOKEN")
Expand All @@ -314,8 +286,11 @@ def test_mqtt311_ws_cred_environment(self):
os.environ["AWS_ACCESS_KEY_ID"] = input_access_key
os.environ["AWS_SECRET_ACCESS_KEY"] = input_secret_access_key
os.environ["AWS_SESSION_TOKEN"] = input_session_token
# This should load the environment variables we just set
credentials = auth.AwsCredentialsProvider.new_environment()
if use_default_chain:
credentials = auth.AwsCredentialsProvider.new_default_chain()
else:
# This should load the environment variables we just set
credentials = auth.AwsCredentialsProvider.new_environment()
signing_config = auth.AwsSigningConfig(
algorithm=auth.AwsSigningAlgorithm.V4,
signature_type=auth.AwsSignatureType.HTTP_REQUEST_QUERY_PARAMS,
Expand Down
Loading