Skip to content

Commit 12c807c

Browse files
Revert "Tighten output file permissions (#10196)" (#10215)
This reverts commit 76e36cb.
1 parent e3180a7 commit 12c807c

4 files changed

Lines changed: 12 additions & 70 deletions

File tree

awscli/customizations/s3events.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
# language governing permissions and limitations under the License.
1313
"""Add S3 specific event streaming output arg."""
1414

15-
import os
16-
1715
from awscli.arguments import CustomArgument
1816

1917
STREAM_HELP_TEXT = 'Filename where the records will be saved'
@@ -61,7 +59,8 @@ def replace_event_stream_docs(help_command, **kwargs):
6159
# This should never happen, but in the rare case that it does
6260
# we should be raising something with a helpful error message.
6361
raise DocSectionNotFoundError(
64-
f'Could not find the "output" section for the command: {help_command}'
62+
'Could not find the "output" section for the command: %s'
63+
% help_command
6564
)
6665
doc.write('======\nOutput\n======\n')
6766
doc.write(
@@ -99,7 +98,7 @@ class S3SelectStreamOutputArgument(CustomArgument):
9998
_DOCUMENT_AS_REQUIRED = True
10099

101100
def __init__(self, stream_key, session, **kwargs):
102-
super().__init__(**kwargs)
101+
super(S3SelectStreamOutputArgument, self).__init__(**kwargs)
103102
# This is the key in the response body where we can find the
104103
# streamed contents.
105104
self._stream_key = stream_key
@@ -121,11 +120,7 @@ def save_file(self, parsed, **kwargs):
121120
if self._stream_key not in parsed:
122121
return
123122
event_stream = parsed[self._stream_key]
124-
fd = os.open(
125-
self._output_file, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600
126-
)
127-
os.chmod(self._output_file, 0o600)
128-
with os.fdopen(fd, 'wb') as fp:
123+
with open(self._output_file, 'wb') as fp:
129124
for event in event_stream:
130125
if 'Records' in event:
131126
fp.write(event['Records']['Payload'])

awscli/customizations/streamingoutputarg.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13-
import os
14-
1513
from botocore.model import Shape
1614

1715
from awscli.arguments import BaseCLIArgument
@@ -94,7 +92,7 @@ def add_to_params(self, parameters, value):
9492
service_id = self._operation_model.service_model.service_id.hyphenize()
9593
operation_name = self._operation_model.name
9694
self._session.register(
97-
f'after-call.{service_id}.{operation_name}', self.save_file
95+
'after-call.%s.%s' % (service_id, operation_name), self.save_file
9896
)
9997

10098
def save_file(self, parsed, **kwargs):
@@ -106,11 +104,7 @@ def save_file(self, parsed, **kwargs):
106104
return
107105
body = parsed[self._response_key]
108106
buffer_size = self._buffer_size
109-
fd = os.open(
110-
self._output_file, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600
111-
)
112-
os.chmod(self._output_file, 0o600)
113-
with os.fdopen(fd, 'wb') as fp:
107+
with open(self._output_file, 'wb') as fp:
114108
data = body.read(buffer_size)
115109
while data:
116110
fp.write(data)

tests/functional/s3api/test_select_object_content.py

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,19 @@
1515
import shutil
1616
import tempfile
1717

18-
from awscli.testutils import (
19-
BaseAWSCommandParamsTest,
20-
BaseAWSHelpOutputTest,
21-
skip_if_windows,
22-
)
18+
from awscli.testutils import BaseAWSCommandParamsTest, BaseAWSHelpOutputTest
2319

2420

2521
class TestGetObject(BaseAWSCommandParamsTest):
2622
prefix = ['s3api', 'select-object-content']
2723

2824
def setUp(self):
29-
super().setUp()
25+
super(TestGetObject, self).setUp()
3026
self.parsed_response = {'Payload': self.create_fake_payload()}
3127
self._tempdir = tempfile.mkdtemp()
3228

3329
def tearDown(self):
34-
super().tearDown()
30+
super(TestGetObject, self).tearDown()
3531
shutil.rmtree(self._tempdir)
3632

3733
def create_fake_payload(self):
@@ -86,28 +82,6 @@ def test_can_stream_to_file(self):
8682
contents = f.read()
8783
self.assertEqual(contents, ('a,b,c,d\n' 'e,f,g,h\n'))
8884

89-
@skip_if_windows('chmod is not supported on Windows')
90-
def test_output_file_permissions(self):
91-
filename = os.path.join(self._tempdir, 'outfile_perms')
92-
cmdline = self.prefix + [
93-
'--bucket',
94-
'mybucket',
95-
'--key',
96-
'mykey',
97-
'--expression',
98-
'SELECT * FROM S3Object',
99-
'--expression-type',
100-
'SQL',
101-
'--input-serialization',
102-
'{"CSV": {}}',
103-
'--output-serialization',
104-
'{"CSV": {}}',
105-
filename,
106-
]
107-
self.assert_params_for_cmd(cmdline, ignore_params=True)
108-
# Mask file type bits to isolate permission bits (rwxrwxrwx)
109-
self.assertEqual(os.stat(filename).st_mode & 0o777, 0o600)
110-
11185
def test_errors_are_propagated(self):
11286
self.http_response.status_code = 400
11387
self.parsed_response = {

tests/functional/test_streaming_output.py

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,17 @@
1111
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1212
# ANY KIND, either express or implied. See the License for the specific
1313
# language governing permissions and limitations under the License.
14-
import os
15-
1614
from awscli.compat import BytesIO
17-
from awscli.testutils import (
18-
BaseAWSCommandParamsTest,
19-
FileCreator,
20-
skip_if_windows,
21-
)
15+
from awscli.testutils import BaseAWSCommandParamsTest, FileCreator
2216

2317

2418
class TestStreamingOutput(BaseAWSCommandParamsTest):
2519
def setUp(self):
26-
super().setUp()
20+
super(TestStreamingOutput, self).setUp()
2721
self.files = FileCreator()
2822

2923
def tearDown(self):
30-
super().tearDown()
24+
super(TestStreamingOutput, self).tearDown()
3125
self.files.remove_all()
3226

3327
def test_get_media_streaming_output(self):
@@ -47,18 +41,3 @@ def test_get_media_streaming_output(self):
4741
self.assert_params_for_cmd(cmdline % outpath, params)
4842
with open(outpath, 'rb') as outfile:
4943
self.assertEqual(outfile.read(), b'testbody')
50-
51-
@skip_if_windows('chmod is not supported on Windows')
52-
def test_streaming_output_file_permissions(self):
53-
cmdline = (
54-
'kinesis-video-media get-media --stream-name test-stream '
55-
'--start-selector StartSelectorType=EARLIEST %s'
56-
)
57-
self.parsed_response = {
58-
'ContentType': 'video/webm',
59-
'Payload': BytesIO(b'testbody'),
60-
}
61-
outpath = self.files.full_path('outfile')
62-
self.assert_params_for_cmd(cmdline % outpath, ignore_params=True)
63-
# Mask file type bits to isolate permission bits (rwxrwxrwx)
64-
self.assertEqual(os.stat(outpath).st_mode & 0o777, 0o600)

0 commit comments

Comments
 (0)