Skip to content

Commit

Permalink
update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
waahm7 committed Jul 9, 2024
1 parent 88ce700 commit 4c923f2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
2 changes: 0 additions & 2 deletions awscrt/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,6 @@ def __init__(
assert isinstance(credential_provider, AwsCredentialsProvider) or credential_provider is None
assert isinstance(tls_connection_options, TlsConnectionOptions) or tls_connection_options is None
assert isinstance(part_size, int) or part_size is None
assert isinstance(network_interface_names, list) and all(isinstance(name, str)
for name in network_interface_names) or network_interface_names is None

assert isinstance(
throughput_target_gbps,
Expand Down
33 changes: 15 additions & 18 deletions source/s3_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ PyObject *aws_py_s3_client_new(PyObject *self, PyObject *args) {

struct aws_signing_config_aws *signing_config = NULL;
struct aws_credentials *anonymous_credentials = NULL;
struct aws_byte_cursor *network_interface_names = NULL;
int num_network_interface_names = 0;

if (signing_config_py != Py_None) {
signing_config = aws_py_get_signing_config(signing_config_py);
if (!signing_config) {
Expand All @@ -322,22 +325,9 @@ PyObject *aws_py_s3_client_new(PyObject *self, PyObject *args) {
signing_config = &default_signing_config;
}

struct aws_byte_cursor *network_interface_names = NULL;
int num_network_interface_names = 0;

if (network_interface_names_py != Py_None) {
if (!PyList_Check(network_interface_names_py)) {
PyErr_SetString(PyExc_TypeError, "Expected network_interface_names to be a list");
return NULL;
}
Py_ssize_t listSize = PyList_Size(network_interface_names_py);
num_network_interface_names = (size_t)listSize;
}

struct s3_client_binding *s3_client = aws_mem_calloc(allocator, 1, sizeof(struct s3_client_binding));

/* From hereon, we need to clean up if errors occur */
int result = AWS_OP_ERR;
bool success = false;
struct s3_client_binding *s3_client = aws_mem_calloc(allocator, 1, sizeof(struct s3_client_binding));

PyObject *capsule = PyCapsule_New(s3_client, s_capsule_name_s3_client, s_s3_client_capsule_destructor);
if (!capsule) {
Expand All @@ -351,7 +341,14 @@ PyObject *aws_py_s3_client_new(PyObject *self, PyObject *args) {

s3_client->py_core = py_core;
Py_INCREF(s3_client->py_core);
if (num_network_interface_names > 0) {

if (network_interface_names_py != Py_None) {
if (!PyList_Check(network_interface_names_py)) {
PyErr_SetString(PyExc_TypeError, "Expected network_interface_names to be a list");
goto cleanup;
}
Py_ssize_t listSize = PyList_Size(network_interface_names_py);
num_network_interface_names = (size_t)listSize;
network_interface_names =
aws_mem_calloc(allocator, num_network_interface_names, sizeof(struct aws_byte_cursor));
for (Py_ssize_t i = 0; i < num_network_interface_names; ++i) {
Expand Down Expand Up @@ -385,12 +382,12 @@ PyObject *aws_py_s3_client_new(PyObject *self, PyObject *args) {
PyErr_SetAwsLastError();
goto cleanup;
}
result = AWS_OP_SUCCESS;
success = true;

cleanup:
aws_credentials_release(anonymous_credentials);
aws_mem_release(allocator, network_interface_names);
if (result != AWS_OP_SUCCESS) {
if (!success) {
Py_DECREF(capsule);
return NULL;
}
Expand Down
8 changes: 7 additions & 1 deletion test/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@
import math
import shutil
import time
from sys import stdout

from test import NativeResourceTest
from concurrent.futures import Future
from multiprocessing import Process

from awscrt.http import HttpHeaders, HttpRequest
from awscrt.s3 import S3Client, S3RequestType, create_default_s3_signing_config
from awscrt.io import ClientBootstrap, ClientTlsContext, DefaultHostResolver, EventLoopGroup, TlsConnectionOptions, TlsContextOptions
from awscrt.io import ClientBootstrap, ClientTlsContext, DefaultHostResolver, EventLoopGroup, TlsConnectionOptions, \
TlsContextOptions, LogLevel
from awscrt.auth import AwsCredentials, AwsCredentialsProvider, AwsSignatureType, AwsSignedBodyHeaderType, AwsSignedBodyValue, AwsSigningAlgorithm, AwsSigningConfig
from awscrt.io import init_logging

from awscrt.s3 import (
S3ChecksumAlgorithm,
S3ChecksumConfig,
Expand Down Expand Up @@ -224,6 +229,7 @@ def test_sanity_secure(self):
self.assertIsNotNone(s3_client)

def test_sanity_network_interface_names(self):
init_logging(LogLevel.Debug, "stdout")
s3_client = s3_client_new(True, self.region, network_interface_names=["eth0", "eth1"])
self.assertIsNotNone(s3_client)

Expand Down

0 comments on commit 4c923f2

Please sign in to comment.