Skip to content

Commit

Permalink
[s3] remove redundant auth fetching methods (#1247)
Browse files Browse the repository at this point in the history
  • Loading branch information
jschneier committed May 18, 2023
1 parent cdad67b commit 705bdb7
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 39 deletions.
28 changes: 0 additions & 28 deletions storages/backends/s3boto3.py
Expand Up @@ -26,7 +26,6 @@
from storages.utils import clean_name
from storages.utils import get_available_overwrite_name
from storages.utils import is_seekable
from storages.utils import lookup_env
from storages.utils import safe_join
from storages.utils import setting
from storages.utils import to_bytes
Expand Down Expand Up @@ -252,12 +251,6 @@ class S3Boto3Storage(CompressStorageMixin, BaseStorage):
# If config provided in init, signature_version and addressing_style settings/args are ignored.
config = None

# used for looking up the access and secret key from env vars
access_key_names = ['AWS_S3_ACCESS_KEY_ID', 'AWS_ACCESS_KEY_ID']
secret_key_names = ['AWS_S3_SECRET_ACCESS_KEY', 'AWS_SECRET_ACCESS_KEY']
security_token_names = ['AWS_SESSION_TOKEN', 'AWS_SECURITY_TOKEN']
security_token = None

def __init__(self, **settings):
super().__init__(**settings)

Expand All @@ -266,9 +259,6 @@ def __init__(self, **settings):
self._bucket = None
self._connections = threading.local()

self.access_key, self.secret_key = self._get_access_keys()
self.security_token = self._get_security_token()

if not self.config:
self.config = Config(
s3={'addressing_style': self.addressing_style},
Expand Down Expand Up @@ -390,24 +380,6 @@ def bucket(self):
self._bucket = self.connection.Bucket(self.bucket_name)
return self._bucket

def _get_access_keys(self):
"""
Gets the access keys to use when accessing S3. If none is
provided in the settings then get them from the environment
variables.
"""
access_key = self.access_key or lookup_env(self.access_key_names)
secret_key = self.secret_key or lookup_env(self.secret_key_names)
return access_key, secret_key

def _get_security_token(self):
"""
Gets the security token to use when accessing S3. Get it from
the environment variables.
"""
security_token = self.security_token or lookup_env(self.security_token_names)
return security_token

def _normalize_name(self, name):
"""
Normalizes the name so that paths like /path/to/ignored/../something.txt
Expand Down
11 changes: 0 additions & 11 deletions storages/utils.py
Expand Up @@ -104,17 +104,6 @@ def check_location(storage):
)


def lookup_env(names):
"""
Look up for names in environment. Returns the first element
found.
"""
for name in names:
value = os.environ.get(name)
if value:
return value


def get_available_overwrite_name(name, max_length):
if max_length is None or len(name) <= max_length:
return name
Expand Down

0 comments on commit 705bdb7

Please sign in to comment.