Skip to content

Commit 49b3ed7

Browse files
committed
addressing code comments
1 parent 9aaa262 commit 49b3ed7

File tree

4 files changed

+16
-57
lines changed

4 files changed

+16
-57
lines changed

nodestream/pipeline/extractors/credential_utils.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,19 @@
77
import pytz
88
from botocore.credentials import RefreshableCredentials
99
from botocore.session import Session
10-
from nodestream.file_io import LazyLoadedArgument
1110

1211

1312
class AwsClientFactory:
1413
def __init__(
1514
self,
16-
assume_role_arn: Optional[Union[LazyLoadedArgument,str]] = None,
17-
assume_role_external_id: Optional[Union[LazyLoadedArgument,str]] = None,
15+
assume_role_arn: Optional[str] = None,
16+
assume_role_external_id: Optional[str] = None,
1817
session_ttl: int = 3000,
1918
**boto_session_args
2019
) -> None:
21-
if isinstance(assume_role_arn, LazyLoadedArgument):
22-
self.assume_role_arn = assume_role_arn.get_value()
23-
else:
24-
self.assume_role_arn = assume_role_arn
25-
if isinstance(assume_role_external_id, LazyLoadedArgument):
26-
self.assume_role_external_id = assume_role_external_id.get_value()
27-
else:
28-
self.assume_role_external_id = assume_role_external_id
2920

21+
self.assume_role_arn = assume_role_arn
22+
self.assume_role_external_id = assume_role_external_id
3023
self.session_args = self._init_session_args(**boto_session_args)
3124
self.session_ttl = session_ttl
3225

nodestream/project/storage.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ class StoreConfiguration:
1212
hmac_key: Optional[Union[LazyLoadedArgument,str]] = None
1313

1414
def initialize(self) -> ObjectStore:
15-
store = ObjectStore.from_file_arguments(self.storage_type, **self.arguments)
15+
args = LazyLoadedArgument.resolve_if_needed(self.arguments)
16+
store = ObjectStore.from_file_arguments(self.storage_type, **args)
1617
if self.hmac_key:
17-
if isinstance(self.hmac_key, LazyLoadedArgument):
18-
resolved_key = self.hmac_key.get_value()
19-
return store.signed(Signer.hmac(resolved_key))
20-
else:
21-
return store.signed(Signer.hmac(self.hmac_key))
18+
resolved_key = LazyLoadedArgument.resolve_if_needed(self.hmac_key)
19+
return store.signed(Signer.hmac(resolved_key))
2220
return store
2321

2422
def to_file_data(self):
@@ -40,10 +38,10 @@ def from_file_data(data):
4038

4139
@staticmethod
4240
def describe_yaml_schema():
43-
from schema import Optional, Schema
41+
from schema import Optional, Schema, Or
4442

4543
return Schema(
46-
{"name": str, "type": str, Optional("hmac_key"): LazyLoadedArgument, Optional(str): object}
44+
{"name": str, "type": str, Optional("hmac_key"): Or(LazyLoadedArgument, str, only_one=True), Optional(str): object}
4745
)
4846

4947

tests/unit/pipeline/extractors/stores/aws/test_credential_utils.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
from freezegun import freeze_time
77
from hamcrest import assert_that, equal_to, has_key, not_
88

9-
from nodestream.file_io import LazyLoadedArgument
10-
from unittest.mock import Mock
119

1210

1311
@pytest.fixture
@@ -148,37 +146,3 @@ def test_make_client(mocker, client_without_role):
148146
return_value=session
149147
)
150148
client_without_role.make_client("s3")
151-
152-
def create_mock_lazy_loaded_argument(value):
153-
mock = Mock(spec=LazyLoadedArgument)
154-
mock.get_value.return_value = value
155-
return mock
156-
157-
def test_init_with_lazy_loaded_role_arn():
158-
from nodestream.pipeline.extractors.credential_utils import AwsClientFactory
159-
160-
lazy_role_arn = create_mock_lazy_loaded_argument("arn:aws:iam::123456789012:role/test")
161-
client = AwsClientFactory(assume_role_arn=lazy_role_arn)
162-
163-
assert_that(client.assume_role_arn, equal_to("arn:aws:iam::123456789012:role/test"))
164-
165-
def test_init_with_lazy_loaded_external_id():
166-
from nodestream.pipeline.extractors.credential_utils import AwsClientFactory
167-
168-
lazy_external_id = create_mock_lazy_loaded_argument("test-external-id")
169-
client = AwsClientFactory(assume_role_external_id=lazy_external_id)
170-
171-
assert_that(client.assume_role_external_id, equal_to("test-external-id"))
172-
173-
def test_init_with_both_lazy_loaded_arguments():
174-
from nodestream.pipeline.extractors.credential_utils import AwsClientFactory
175-
176-
lazy_role_arn = create_mock_lazy_loaded_argument("arn:aws:iam::123456789012:role/test")
177-
lazy_external_id = create_mock_lazy_loaded_argument("test-external-id")
178-
client = AwsClientFactory(
179-
assume_role_arn=lazy_role_arn,
180-
assume_role_external_id=lazy_external_id
181-
)
182-
183-
assert_that(client.assume_role_arn, equal_to("arn:aws:iam::123456789012:role/test"))
184-
assert_that(client.assume_role_external_id, equal_to("test-external-id"))

tests/unit/project/test_storage.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,18 @@ def test_storage_configuration_to_file_data(store_config):
9696
assert_that(file_data, equal_to(expected_data))
9797

9898

99-
def test_store_configuration_initialize_with_lazy_hmac(tmp_path):
99+
def test_store_configuration_initialize_with_lazy_hmac():
100100
expected_hmac = "dvHdCrVbRPp1HcmWX78Ryw=="
101101
mock_lazy_hmac = Mock(spec=LazyLoadedArgument)
102102
mock_lazy_hmac.get_value.return_value = expected_hmac
103+
expected_arg = "testarglol"
104+
mock_lazy_arg = Mock(spec=LazyLoadedArgument)
105+
mock_lazy_arg.get_value.return_value = expected_arg
103106

104107
store_config = StoreConfiguration(
105108
name="test-store",
106109
storage_type="local",
107-
arguments={"root": tmp_path},
110+
arguments={"root": mock_lazy_arg},
108111
hmac_key=mock_lazy_hmac
109112
)
110113

@@ -113,4 +116,5 @@ def test_store_configuration_initialize_with_lazy_hmac(tmp_path):
113116
base64.b64encode(store.signer.key).decode(),
114117
equal_to(expected_hmac)
115118
)
119+
assert_that(store.store.root, equal_to(expected_arg))
116120
mock_lazy_hmac.get_value.assert_called_once()

0 commit comments

Comments
 (0)