Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: fix typo on configuration variable #6

Merged
merged 2 commits into from
Nov 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 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 All @@ -29,7 +29,7 @@
for more information.
"""

S3_SECRECT_ACCESS_KEY = None
S3_SECRET_ACCESS_KEY = None
"""The secret key to use when creating the client.

This is entirely optional, and if not provided, the credentials configured for
Expand Down
26 changes: 24 additions & 2 deletions 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,9 +28,29 @@ 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
)

if 'S3_SECRECT_ACCESS_KEY' in current_app.config:
current_app.config['S3_SECRET_ACCESS_KEY'] = current_app.config[
'S3_SECRECT_ACCESS_KEY']
warnings.warn(
'Key S3_SECRECT_ACCESS_KEY contained a typo and has been '
'corrected to S3_SECRET_ACCESS_KEY, support for the '
'flawed version will be removed.',
DeprecationWarning
)

info = dict(
key=current_app.config.get('S3_ACCCESS_KEY_ID', ''),
secret=current_app.config.get('S3_SECRECT_ACCESS_KEY', ''),
key=current_app.config.get('S3_ACCESS_KEY_ID', ''),
secret=current_app.config.get('S3_SECRET_ACCESS_KEY', ''),
client_kwargs={},
config_kwargs={
's3': {
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
install_requires = [
'boto3>=1.9.83',
'invenio-files-rest>=1.0.0a23',
's3fs>=0.1.5',
's3fs>=0.1.5,<0.3.0', # Newer versions only allow python >= 3.5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove python 2 support if you like. Since this module won't be in production until after January 2020.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is nothing I would love more than removing python 2.7 support, but I know at least one production system using it, I'll check with them what python version they are using and fix this accordingly

]

packages = find_packages()
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
39 changes: 31 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,35 @@ 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'


def test_secret_key(appctx):
"""Test correct secret key works together with flawed one."""
appctx.config['S3_SECRECT_ACCESS_KEY'] = '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['secret'] == 'secret'