1
1
# -*- coding: utf-8 -*-
2
2
import asyncio
3
3
import errno
4
- import inspect
5
4
import logging
6
5
import mimetypes
7
6
import os
31
30
from aiobotocore .config import AioConfig
32
31
from botocore .exceptions import ClientError , HTTPClientError , ParamValidationError
33
32
from botocore .parsers import ResponseParserError
34
- from botocore .credentials import create_credential_resolver
35
33
36
34
from s3fs .errors import translate_boto_error
37
35
from s3fs .utils import S3BucketRegionCache , ParamKwargsHelper , _get_brange , FileExpired
@@ -139,18 +137,6 @@ async def _error_wrapper(func, *, args=(), kwargs=None, retries):
139
137
except Exception as e :
140
138
err = e
141
139
err = translate_boto_error (err )
142
-
143
- if inspect .ismethod (func ):
144
- s3 = func .__self__
145
- try :
146
- is_anon = s3 ._client_config .signature_version == botocore .UNSIGNED
147
- except AttributeError :
148
- is_anon = False
149
- if isinstance (err , PermissionError ) and is_anon :
150
- raise PermissionError (
151
- "Access failed in anonymous mode. You may need to provide credentials."
152
- ) from err
153
-
154
140
raise err
155
141
156
142
@@ -478,36 +464,6 @@ async def set_session(self, refresh=False, kwargs={}):
478
464
return self ._s3
479
465
logger .debug ("Setting up s3fs instance" )
480
466
481
- if self .session is None :
482
- self .session = aiobotocore .session .AioSession (** self .kwargs )
483
-
484
- drop_keys = {
485
- "aws_access_key_id" ,
486
- "aws_secret_access_key" ,
487
- "aws_session_token" ,
488
- }
489
- if (
490
- not self .anon
491
- and (self .key or self .secret or self .token ) is None
492
- and not drop_keys .intersection (set (self .client_kwargs ))
493
- ):
494
- # creating credentials resolver which enables loading credentials from configs/environment variables see
495
- # https://github.com/boto/botocore/blob/develop/botocore/credentials.py#L2043
496
- # tests whether any creds are available at all; if not, default to anonymous
497
- cred_resolver = create_credential_resolver (
498
- self .session , region_name = self .session ._last_client_region_used
499
- )
500
- credentials = cred_resolver .load_credentials ()
501
-
502
- if credentials is None :
503
- logger .debug ("No credentials given/found, setting `anon` to True." )
504
- self .anon = True
505
- else :
506
- # by stashing these, we avoid doing the lookup again
507
- self .key = getattr (credentials , "access_key" , None )
508
- self .secret = getattr (credentials , "secret_key" , None )
509
- self .token = getattr (credentials , "token" , None )
510
-
511
467
client_kwargs = self .client_kwargs .copy ()
512
468
init_kwargs = dict (
513
469
aws_access_key_id = self .key ,
@@ -523,10 +479,14 @@ async def set_session(self, refresh=False, kwargs={}):
523
479
if "use_ssl" not in client_kwargs .keys ():
524
480
init_kwargs ["use_ssl" ] = self .use_ssl
525
481
config_kwargs = self ._prepare_config_kwargs ()
526
-
527
482
if self .anon :
528
483
from botocore import UNSIGNED
529
484
485
+ drop_keys = {
486
+ "aws_access_key_id" ,
487
+ "aws_secret_access_key" ,
488
+ "aws_session_token" ,
489
+ }
530
490
init_kwargs = {
531
491
key : value for key , value in init_kwargs .items () if key not in drop_keys
532
492
}
@@ -538,6 +498,8 @@ async def set_session(self, refresh=False, kwargs={}):
538
498
config_kwargs ["signature_version" ] = UNSIGNED
539
499
540
500
conf = AioConfig (** config_kwargs )
501
+ if self .session is None :
502
+ self .session = aiobotocore .session .AioSession (** self .kwargs )
541
503
542
504
for parameters in (config_kwargs , self .kwargs , init_kwargs , client_kwargs ):
543
505
for option in ("region_name" , "endpoint_url" ):
0 commit comments