Skip to content

Commit 39f673d

Browse files
committed
added credentials to s3 opener
1 parent 9d9440e commit 39f673d

4 files changed

Lines changed: 19 additions & 21 deletions

File tree

fs/opener.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -551,9 +551,9 @@ def get_fs(cls, registry, fs_name, fs_name_params, fs_path, writeable, create_d
551551

552552
class TempOpener(Opener):
553553
names = ['temp']
554-
desc = """Creates a temporary filesystem, that is erased on exit.
554+
desc = """Creates a temporary filesystem that is erased on exit.
555555
Probably only useful for mounting or serving.
556-
NB: If you user fscp or fsmv to copy/move files here, you are effectively deleting them!
556+
NB: If you use fscp or fsmv to copy/move files here, you are effectively deleting them!
557557
558558
example:
559559
* temp://"""
@@ -565,20 +565,24 @@ def get_fs(cls, registry, fs_name, fs_name_params, fs_path, writeable, create_d
565565
fs = LazyFS((TempFS,(),{"identifier":fs_name_params}))
566566
return fs, fs_path
567567

568+
568569
class S3Opener(Opener):
569570
names = ['s3']
570571
desc = """Opens a filesystem stored on Amazon S3 storage
571572
The environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY should be set"""
573+
572574
@classmethod
573575
def get_fs(cls, registry, fs_name, fs_name_params, fs_path, writeable, create_dir):
574576
from fs.s3fs import S3FS
575577

576-
bucket = fs_path
577-
path =''
578-
if '/' in fs_path:
578+
username, password, bucket = _parse_credentials(fs_path)
579+
path = ''
580+
if '/' in bucket:
579581
bucket, path = fs_path.split('/', 1)
580582

581-
fs = S3FS(bucket)
583+
fs = S3FS(bucket,
584+
aws_access_key=username or None,
585+
aws_secret_key=password or None)
582586

583587
if path:
584588
dirpath, resourcepath = pathsplit(path)
@@ -588,6 +592,7 @@ def get_fs(cls, registry, fs_name, fs_name_params, fs_path, writeable, create_di
588592

589593
return fs, path
590594

595+
591596
class TahoeOpener(Opener):
592597
names = ['tahoe']
593598
desc = """Opens a Tahoe-LAFS filesystem

fs/osfs/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def __init__(self, root_path, thread_synchronize=_thread_synchronize_default, en
115115
"""
116116

117117
super(OSFS, self).__init__(thread_synchronize=thread_synchronize)
118-
self.encoding = encoding or sys.getfilesystemencoding()
118+
self.encoding = encoding or sys.getfilesystemencoding() or 'utf-8'
119119
self.dir_mode = dir_mode
120120
self.use_long_paths = use_long_paths
121121
root_path = os.path.expanduser(os.path.expandvars(root_path))
@@ -228,6 +228,8 @@ def getmeta(self, meta_name, default=NoDefaultMeta):
228228
def open(self, path, mode='r', buffering=-1, encoding=None, errors=None, newline=None, line_buffering=False, **kwargs):
229229
mode = ''.join(c for c in mode if c in 'rwabt+')
230230
sys_path = self.getsyspath(path)
231+
if not encoding and 'b' not in mode:
232+
encoding = encoding or 'utf-8'
231233
try:
232234
return io.open(sys_path, mode=mode, buffering=buffering, encoding=encoding, errors=errors, newline=newline)
233235
except EnvironmentError, e:

fs/s3fs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,8 @@ def makedir(self,path,recursive=False,allow_recreate=False):
487487
msg = "Parent directory does not exist: %(path)s"
488488
raise ParentDirectoryMissingError(path, msg=msg)
489489
# Create an empty file representing the directory
490-
self._sync_set_contents(s3pathD,"")
490+
if s3pathD not in ('/', ''):
491+
self._sync_set_contents(s3pathD,"")
491492

492493
def remove(self,path):
493494
"""Remove the file at the given path."""

tox.ini

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py26,py27,py31,py32,py33,pypy
2+
envlist = py27,py34,py35,pypy
33
sitepackages = False
44

55
[testenv]
@@ -15,17 +15,7 @@ changedir=.tox
1515
commands = nosetests fs.tests -v \
1616
[]
1717

18-
19-
[testenv:py31]
20-
commands = nosetests fs.tests -v \
21-
[]
22-
deps = distribute
23-
six
24-
dexml
25-
nose
26-
winpdb
27-
28-
[testenv:py32]
18+
[testenv:py34]
2919
commands = nosetests fs.tests -v \
3020
[]
3121
deps = distribute
@@ -34,7 +24,7 @@ deps = distribute
3424
nose
3525
winpdb
3626

37-
[testenv:py33]
27+
[testenv:py35]
3828
commands = nosetests fs.tests -v \
3929
[]
4030
deps = distribute

0 commit comments

Comments
 (0)