Skip to content

Commit

Permalink
config: fix typo on configuration variable
Browse files Browse the repository at this point in the history
* Fix typo on `S3_ACCCESS_KEY_ID`, (too many Cs) and add a deprecation
  warning for the old key. (closes #3)
  • Loading branch information
egabancho committed Oct 6, 2019
1 parent cca73e8 commit 5bad54f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
2 changes: 1 addition & 1 deletion invenio_s3/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<https://boto3.readthedocs.io/en/latest/reference/core/session.html#boto3.session.Session.client>`_.
"""

S3_ACCCESS_KEY_ID = None
S3_ACCESS_KEY_ID = None
"""The access key to use when creating the client.
This is entirely optional, and if not provided, the credentials configured for
Expand Down
14 changes: 13 additions & 1 deletion invenio_s3/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from __future__ import absolute_import, print_function

import warnings

import boto3
from flask import current_app
from werkzeug.utils import cached_property
Expand All @@ -26,8 +28,18 @@ def __init__(self, app=None):
@cached_property
def init_s3f3_info(self):
"""Gather all the information needed to start the S3FSFileSystem."""
if 'S3_ACCCESS_KEY_ID' in current_app.config:
current_app.config['S3_ACCESS_KEY_ID'] = current_app.config[
'S3_ACCCESS_KEY_ID']
warnings.warn(
'Key S3_ACCCESS_KEY_ID contained a typo and has been '
'corrected to S3_ACCESS_KEY_ID, support for the '
'flawed version will be removed.',
DeprecationWarning
)

info = dict(
key=current_app.config.get('S3_ACCCESS_KEY_ID', ''),
key=current_app.config.get('S3_ACCESS_KEY_ID', ''),
secret=current_app.config.get('S3_SECRECT_ACCESS_KEY', ''),
client_kwargs={},
config_kwargs={
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def app_config(app_config):
app_config[
'FILES_REST_STORAGE_FACTORY'] = 'invenio_s3.s3fs_storage_factory'
app_config['S3_ENDPOINT_URL'] = None
app_config['S3_ACCCESS_KEY_ID'] = 'test'
app_config['S3_ACCESS_KEY_ID'] = 'test'
app_config['S3_SECRECT_ACCESS_KEY'] = 'test'
return app_config

Expand All @@ -42,7 +42,7 @@ def s3_bucket(appctx):
"""S3 bucket fixture."""
with mock_s3():
session = boto3.Session(
aws_access_key_id=current_app.config.get('S3_ACCCESS_KEY_ID'),
aws_access_key_id=current_app.config.get('S3_ACCESS_KEY_ID'),
aws_secret_access_key=current_app.config.get(
'S3_SECRECT_ACCESS_KEY'),
)
Expand Down
27 changes: 19 additions & 8 deletions tests/test_invenio_s3.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2018 Esteban J. G. Gabancho.
# Copyright (C) 2018, 2019 Esteban J. G. Gabancho.
#
# Invenio-S3 is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand All @@ -17,12 +17,23 @@ def test_version():
assert __version__


def test_init(base_app):
def test_init(appctx):
"""Test extension initialization."""
assert 'invenio-s3' in base_app.extensions
assert 'invenio-s3' in appctx.extensions

with base_app.app_context():
base_app.config['S3_ENDPOINT_URL'] = 'https://example.com:1234'
s3_connection_info = base_app.extensions['invenio-s3'].init_s3f3_info
assert s3_connection_info['client_kwargs'][
'endpoint_url'] == 'https://example.com:1234'
appctx.config['S3_ENDPOINT_URL'] = 'https://example.com:1234'
s3_connection_info = appctx.extensions['invenio-s3'].init_s3f3_info
assert s3_connection_info['client_kwargs'][
'endpoint_url'] == 'https://example.com:1234'


def test_access_key(appctx):
"""Test correct access key works together with flawed one."""
appctx.config['S3_ACCCESS_KEY_ID'] = 'secret'
try:
# Delete the cached value in case it's there already
del appctx.extensions['invenio-s3'].__dict__['init_s3f3_info']
except KeyError:
pass
s3_connection_info = appctx.extensions['invenio-s3'].init_s3f3_info
assert s3_connection_info['key'] == 'secret'

0 comments on commit 5bad54f

Please sign in to comment.