Skip to content

Commit c92e19d

Browse files
Merge pull request #20 from keitaroinc/config-declaration
Config declaration
2 parents caf88c0 + c123ba0 commit c92e19d

File tree

8 files changed

+124
-97
lines changed

8 files changed

+124
-97
lines changed

.github/workflows/ci.yml

Lines changed: 58 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,16 @@ on:
88
pull_request:
99
branches: main
1010

11-
env:
12-
CKANVERSION: 2.9
13-
1411
jobs:
1512
code_quality:
1613
runs-on: ubuntu-latest
1714
steps:
18-
- uses: actions/checkout@v2
15+
- uses: actions/checkout@v4
1916

2017
- name: Setup Python
21-
uses: actions/setup-python@v2
18+
uses: actions/setup-python@v4
2219
with:
23-
python-version: '3.8'
20+
python-version: '3.10'
2421

2522
- name: Install flake8
2623
run: |
@@ -29,107 +26,83 @@ jobs:
2926
3027
- name: Lint with flake8
3128
run: |
32-
flake8 . --count --max-complexity=12 --max-line-length=127 --statistics --exclude ckan,ckanext-s3filestore
29+
flake8 . --count --max-complexity=13 --max-line-length=127 --statistics
3330
3431
test:
35-
runs-on: ubuntu-latest
3632
strategy:
3733
matrix:
38-
python-version: [ '3.8' ]
39-
name: Python ${{ matrix.python-version }} extension test
34+
python-version: ["3.9", "3.10"]
35+
ckan-version: ["2.10", "2.11"]
36+
fail-fast: false
4037

38+
name: CKAN ${{ matrix.ckan-version }} Python ${{ matrix.python-version }}
39+
runs-on: ubuntu-latest
40+
container:
41+
image: ckan/ckan-dev:${{ matrix.ckan-version }}
42+
options: --user root
4143
services:
42-
postgresql:
43-
image: postgres
44+
solr:
45+
image: ckan/ckan-solr:${{ matrix.ckan-version }}-solr9
46+
postgres:
47+
image: ckan/ckan-postgres-dev:${{ matrix.ckan-version }}
4448
env:
49+
POSTGRES_USER: postgres
4550
POSTGRES_PASSWORD: postgres
51+
POSTGRES_DB: postgres
4652
options: >-
4753
--health-cmd pg_isready
4854
--health-interval 10s
4955
--health-timeout 5s
5056
--health-retries 5
51-
ports:
52-
- 5432:5432
53-
5457
redis:
55-
image: redis
58+
image: redis:3
59+
moto:
60+
image: motoserver/moto:latest
61+
ports:
62+
- 9000:5000
5663
options: >-
57-
--health-cmd "redis-cli ping"
58-
--health-interval 10s
59-
--health-timeout 5s
64+
--health-cmd "curl -f http://localhost:5000 || exit 1"
65+
--health-interval 5s
66+
--health-timeout 2s
6067
--health-retries 5
61-
ports:
62-
- 6379:6379
6368
64-
ckan-solr:
65-
# Workflow level env variables are not addressable on job level, only on steps level
66-
# image: ghcr.io/keitaroinc/ckan-solr-dev:{{ env.CKANVERSION }}
67-
image: ghcr.io/keitaroinc/ckan-solr-dev:2.9
68-
ports:
69-
- 8983:8983
69+
env:
70+
CKAN_SQLALCHEMY_URL: postgresql://ckan_default:pass@postgres/ckan_test
71+
CKAN_DATASTORE_WRITE_URL: postgresql://datastore_write:pass@postgres/datastore_test
72+
CKAN_DATASTORE_READ_URL: postgresql://datastore_read:pass@postgres/datastore_test
73+
CKAN_SOLR_URL: http://solr:8983/solr/ckan
74+
CKAN_REDIS_URL: redis://redis:6379/1
75+
CKANEXT_S3FILESTORE__HOST_NAME: http://moto:5000
76+
AWS_ACCESS_KEY_ID: test-access-key
77+
AWS_SECRET_ACCESS_KEY: test-secret-key
78+
AWS_DEFAULT_REGION: us-east-1
7079

7180
steps:
72-
- uses: actions/checkout@v2
73-
74-
- name: Setup Python
75-
uses: actions/setup-python@v2
76-
with:
77-
python-version: ${{ matrix.python-version }}
78-
architecture: x64
81+
- uses: actions/checkout@v4
7982

80-
- name: Install pytest
83+
- name: Install requirements
8184
run: |
82-
python -m pip install --upgrade pip
83-
pip install pytest
85+
pip install -e .
86+
pip install boto3
87+
# Replace default path to CKAN core config file with the one on the container
88+
sed -i -e 's/use = config:.*/use = config:\/srv\/app\/src\/ckan\/test-core.ini/' test.ini
8489
85-
- name: Setup CKAN
86-
env:
87-
PGPASSWORD: postgres
90+
- name: Create S3 bucket in Moto
8891
run: |
89-
bash bin/setup-ckan.bash
92+
python - <<'EOF'
93+
import boto3, os
94+
s3 = boto3.client(
95+
"s3",
96+
endpoint_url=os.environ["CKANEXT_S3FILESTORE__HOST_NAME"],
97+
aws_access_key_id=os.environ["AWS_ACCESS_KEY_ID"],
98+
aws_secret_access_key=os.environ["AWS_SECRET_ACCESS_KEY"],
99+
region_name=os.environ["AWS_DEFAULT_REGION"],
100+
)
101+
s3.create_bucket(Bucket="test-bucket")
102+
print("✅ Created test-bucket in Moto")
103+
EOF
104+
105+
- name: Run all tests
106+
run: pytest --ckan-ini=test.ini --disable-warnings ckanext/s3filestore/tests
90107

91-
- name: Test with pytest
92-
run: |
93-
pytest --ckan-ini=subdir/test.ini --cov=ckanext.s3filestore --disable-warnings ckanext/s3filestore/tests
94108

95-
- name: Coveralls
96-
uses: AndreMiras/coveralls-python-action@develop
97-
with:
98-
parallel: true
99-
flag-name: Python ${{ matrix.python-version }} Unit Test
100-
101-
publish:
102-
needs: test
103-
runs-on: ubuntu-latest
104-
steps:
105-
- uses: actions/checkout@v2
106-
107-
- name: Setup Python
108-
uses: actions/setup-python@v2
109-
with:
110-
python-version: '3.8'
111-
112-
- name: Install setup requirements
113-
run: |
114-
python -m pip install --upgrade setuptools wheel twine
115-
116-
- name: Build and package
117-
run: |
118-
python setup.py sdist bdist_wheel
119-
twine check dist/*
120-
121-
- name: Publish package
122-
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
123-
uses: pypa/gh-action-pypi-publish@release/v1
124-
with:
125-
user: __token__
126-
password: ${{ secrets.PYPI_API_TOKEN }}
127-
128-
coveralls_finish:
129-
needs: test
130-
runs-on: ubuntu-latest
131-
steps:
132-
- name: Coveralls Finished
133-
uses: AndreMiras/coveralls-python-action@develop
134-
with:
135-
parallel-finished: true

README.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
.. image:: https://coveralls.io/repos/github/keitaroinc/ckanext-s3filestore/badge.svg?branch=main
1010
:target: https://coveralls.io/github/keitaroinc/ckanext-s3filestore?branch=main
1111

12-
.. image:: https://img.shields.io/badge/python-3.8-blue.svg
13-
:target: https://www.python.org/downloads/release/python-384/
12+
.. image:: https://img.shields.io/badge/python-3.8%20|%203.9%20|%203.10%20-blue
13+
:target: https://www.python.org/downloads/
14+
15+
.. image:: https://img.shields.io/badge/ckan-2.9%20|%202.10%20|%202.11-yellow
16+
:target: https://www.ckan.org/
1417

15-
.. image:: https://img.shields.io/pypi/v/ckanext-s3filestore
16-
:target: https://pypi.org/project/ckanext-s3filestore
1718

1819

1920

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
version: 1
2+
groups:
3+
- annotation: ckanext-s3filestore settings
4+
options:
5+
- key: ckanext.s3filestore.aws_bucket_name
6+
example: s3-filestore-test
7+
default:
8+
description: |
9+
Defines the name of the S3 bucket that serves as the CKAN storage
10+
backend, used for persisting and managing all uploaded files
11+
required: true
12+
- key: ckanext.s3filestore.aws_access_key_id
13+
example: Your-Access-Key-ID
14+
default:
15+
description: |
16+
Specifies the AWS Access Key ID used for
17+
authenticating requests to the S3 bucket
18+
required: true
19+
- key: ckanext.s3filestore.aws_secret_access_key
20+
example: Your-Secret-Access-Key
21+
default:
22+
description: |
23+
Specifies the AWS Secret Access Key associated with the IAM
24+
credentials used to authenticate access to the S3 bucket.
25+
required: true
26+
- key: ckanext.s3filestore.region_name
27+
example: us-east-2
28+
default:
29+
description: |
30+
Specifies the AWS region in which the target
31+
S3 bucket is provisioned
32+
required: true
33+
- key: ckanext.s3filestore.signature_version
34+
example: s3v4
35+
default:
36+
description: |
37+
Defines the AWS Signature Version to be used for request authentication
38+
when accessing the S3 bucket
39+
required: true
40+
- key: ckanext.s3filestore.aws_use_ami_role
41+
example: true
42+
type: bool
43+
default:
44+
description: |
45+
Indicates whether the S3 client should use the IAM role
46+
attached to the Amazon EC2 instance or authentication
47+
instead of explicit AWS credentials

ckanext/s3filestore/plugin.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,7 @@ def get_blueprint(self):
7272

7373
def get_commands(self):
7474
return [upload_resources, upload_assets]
75+
76+
77+
if toolkit.check_ckan_version(min_version="2.10"):
78+
S3FileStorePlugin = toolkit.blanket.config_declarations(S3FileStorePlugin)

ckanext/s3filestore/tests/test_blueprints.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from ckantoolkit import config
88
import ckan.tests.factories as factories
99
from ckan.lib.helpers import url_for
10+
import re
1011

1112

1213
@pytest.mark.usefixtures(u'clean_db', u'clean_index')
@@ -19,12 +20,12 @@ def setup_class(cls):
1920
def test_resource_download_url(self, resource_with_upload):
2021
u'''The resource url is expected for uploaded resource file.'''
2122

22-
expected_url = u'http://test.ckan.net/dataset/{0}/' \
23+
expected_url = u'/dataset/{0}/' \
2324
u'resource/{1}/download/test.csv'.\
2425
format(resource_with_upload[u'package_id'],
2526
resource_with_upload[u'id'])
2627

27-
assert resource_with_upload['url'] == expected_url
28+
assert re.sub(r'^https?://[^/]+', '', resource_with_upload['url']) == expected_url
2829

2930
def test_resource_download(self, app, resource_with_upload):
3031
u'''When trying to download resource

ckanext/s3filestore/tests/test_fix_for_webpageview_plugin.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ def test_view_shown_for_url_type_upload(app, create_with_upload):
4949

5050
response = app.get(url)
5151

52-
assert (u'/dataset/{0}/resource/{1}/download?preview=True'
53-
.format(dataset[u'id'], resource[u'id'])
54-
in response)
52+
formatted_url = (
53+
'/dataset/{0}/resource/{1}/download'.format(dataset['id'], resource['id'])
54+
)
55+
assert formatted_url in response.body, f"{formatted_url} not found in response"
5556

5657
resource_view_src = app.get(resource_view_src_url,
5758
follow_redirects=False)

conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
pytest_plugins = [
44
u'ckanext.s3filestore.tests.fixtures',
5-
u'ckan.tests.pytest_ckan.ckan_setup',
6-
u'ckan.tests.pytest_ckan.fixtures',
5+
# 'ckan.tests.pytest_ckan.ckan_setup',
6+
# u'ckan.tests.pytest_ckan.fixtures',
77
]

test.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ckan.plugins = s3filestore
2323
ckanext.s3filestore.aws_access_key_id = test-access-key
2424
ckanext.s3filestore.aws_secret_access_key = test-secret-key
2525
ckanext.s3filestore.aws_bucket_name = test-bucket
26-
ckanext.s3filestore.host_name = http://127.0.0.1:9000
26+
ckanext.s3filestore.host_name = http://moto:5000
2727
ckanext.s3filestore.region_name = us-east-1
2828
ckanext.s3filestore.signature_version = s3v4
2929
ckanext.s3filestore.acl = private

0 commit comments

Comments
 (0)