-
Notifications
You must be signed in to change notification settings - Fork 56
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
Feature/custom xloader site url rebased #243
Changes from all commits
954ec75
73779dd
32884b9
b69b9c5
b93ac14
944ce78
c8714ce
f12a988
c040a78
993cd00
cbfc55a
d42bf99
ad5ea42
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ jobs: | |
experimental: true # master is unstable, good to know if we are compatible or not | ||
fail-fast: false | ||
|
||
name: CKAN ${{ matrix.ckan-version }} | ||
name: ${{ matrix.experimental && '**Fail_Ignored** ' || '' }} CKAN ${{ matrix.ckan-version }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. duplicate from another repo to give info that its 'ignoring' errors. |
||
runs-on: ubuntu-latest | ||
container: | ||
image: ckan/ckan-dev:${{ matrix.ckan-image }} | ||
|
@@ -65,12 +65,7 @@ jobs: | |
- uses: actions/checkout@v4 | ||
continue-on-error: ${{ matrix.experimental }} | ||
|
||
- name: Pin setuptools for ckan 2.9 only | ||
if: ${{ matrix.ckan-version == 2.9 }} | ||
run: pip install "setuptools>=44.1.0,<71" | ||
continue-on-error: ${{ matrix.experimental }} | ||
|
||
- name: Install requirements | ||
- name: ${{ matrix.experimental && '**Fail_Ignored** ' || '' }} Install requirements | ||
continue-on-error: ${{ matrix.experimental }} | ||
run: | | ||
pip install -r requirements.txt | ||
|
@@ -80,16 +75,20 @@ jobs: | |
# Replace default path to CKAN core config file with the one on the container | ||
sed -i -e 's/use = config:.*/use = config:\/srv\/app\/src\/ckan\/test-core.ini/' test.ini | ||
|
||
- name: Setup extension | ||
- name: ${{ matrix.experimental && '**Fail_Ignored** ' || '' }} Setup extension | ||
continue-on-error: ${{ matrix.experimental }} | ||
run: | | ||
ckan -c test.ini db init | ||
ckan -c test.ini user add ckan_admin email=ckan_admin@localhost password="AbCdEf12345!@#%" | ||
ckan -c test.ini sysadmin add ckan_admin | ||
ckan config-tool test.ini "ckanext.xloader.api_token=$(ckan -c test.ini user token add ckan_admin xloader | tail -n 1 | tr -d '\t')" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. configure proper xloader api token for test based on what would be going into the docker container. |
||
ckan -c test.ini user list | ||
|
||
- name: Run tests | ||
- name: ${{ matrix.experimental && '**Fail_Ignored** ' || '' }} Run tests | ||
continue-on-error: ${{ matrix.experimental }} | ||
run: pytest --ckan-ini=test.ini --cov=ckanext.xloader --disable-warnings ckanext/xloader/tests --junit-xml=/tmp/artifacts/junit/results.xml | ||
|
||
- name: Test Summary | ||
- name: ${{ matrix.experimental && '**Fail_Ignored** ' || '' }} Test Summary | ||
uses: test-summary/action@v2 | ||
continue-on-error: ${{ matrix.experimental }} | ||
with: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,6 +151,7 @@ To install XLoader: | |
execute jobs against the server: | ||
|
||
ckanext.xloader.api_token = <your-CKAN-generated-API-Token> | ||
ckan config-tool test.ini "ckanext.xloader.api_token=$(ckan -c test.ini user token add ckan_admin xloader | tail -n 1 | tr -d '\t')" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. todo: readme update on new ckan config options for custom xloader site url |
||
|
||
6. If it is a production server, you'll want to store jobs info in a | ||
more robust database than the default sqlite file. It can happily | ||
|
@@ -220,8 +221,7 @@ ckanext.xloader.api_token = eyJ0eXAiOiJKV1QiLCJh.eyJqdGkiOiJ0M2VNUFlQWFg0VU.8QgV | |
|
||
Default value: none | ||
|
||
Uses a specific API token for the xloader_submit action instead of the | ||
apikey of the site_user. It's mandatory starting from CKAN 2.10. You can get one | ||
It's mandatory starting from CKAN 2.10. You can get one | ||
running the command `ckan user token add {USER_NAME} xloader -q` | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,22 @@ version: 1 | |
groups: | ||
- annotation: ckanext-xloader settings | ||
options: | ||
- key: ckanext.xloader.site_url | ||
example: http://ckan-dev:5000 | ||
default: | ||
description: | | ||
Provide an alternate site URL for the xloader_submit action. | ||
This is useful, for example, when the site is running within a docker network. | ||
Note: This setting will not alter path. i.e ckan.root_path | ||
required: false | ||
- key: ckanext.xloader.site_url_ignore_path_regex | ||
example: "(/PathToS3HostOriginIWantToGoDirectTo|/anotherPath)" | ||
default: | ||
description: | | ||
Provide the ability to ignore paths which can't be mapped to alternative site URL for resource access. | ||
This is useful, for example, when the site is running within a docker network and the cdn front door has | ||
Blob storage mapped to another path on the same domain. | ||
required: false | ||
- key: ckanext.xloader.jobs_db.uri | ||
default: sqlite:////tmp/xloader_jobs.db | ||
description: | | ||
|
@@ -14,9 +30,9 @@ groups: | |
example: eyJ0eXAiOiJKV1QiLCJh.eyJqdGkiOiJ0M2VNUFlQWFg0VU.8QgV8em4RA | ||
description: | | ||
Uses a specific API token for the xloader_submit action instead of the | ||
apikey of the site_user. Will be mandatory when dropping support for | ||
CKAN 2.9. | ||
required: false | ||
apikey of the site_user. | ||
default: 'NOT_SET' | ||
required: true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dropped 2.9, set to mandatory and give it a default we can throw validation errors on. (i.e. stop the chicken and egg problem that you need a running ckan to create the api key to reference in the config) |
||
- key: ckanext.xloader.formats | ||
example: csv application/csv xls application/vnd.ms-excel | ||
description: | | ||
|
@@ -171,5 +187,3 @@ groups: | |
they will also display "complete", "active", "inactive", and "unknown". | ||
type: bool | ||
required: false | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,13 +17,7 @@ | |
except ImportError: | ||
HAS_IPIPE_VALIDATION = False | ||
|
||
try: | ||
config_declarations = toolkit.blanket.config_declarations | ||
except AttributeError: | ||
# CKAN 2.9 does not have config_declarations. | ||
# Remove when dropping support. | ||
def config_declarations(cls): | ||
return cls | ||
config_declarations = toolkit.blanket.config_declarations | ||
|
||
if toolkit.check_ckan_version(min_version='2.11'): | ||
from ckanext.datastore.interfaces import IDataDictionaryForm | ||
|
@@ -76,14 +70,6 @@ def configure(self, config_): | |
else: | ||
self.ignore_hash = False | ||
|
||
for config_option in ("ckan.site_url",): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ckan.site_url is mandatory in 2.10+ and defaults to 127.0.0.1:5000 if not set, we don't need to config validate this. |
||
if not config_.get(config_option): | ||
raise Exception( | ||
"Config option `{0}` must be set to use ckanext-xloader.".format( | ||
config_option | ||
) | ||
) | ||
|
||
# IPipeValidation | ||
|
||
def receive_validation_report(self, validation_report): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import pytest | ||
from ckan.plugins import toolkit | ||
try: | ||
from unittest import mock | ||
except ImportError: | ||
|
@@ -117,10 +118,24 @@ def test_status(self): | |
|
||
assert status["status"] == "pending" | ||
|
||
def test_xloader_user_api_token_defaults_to_site_user_apikey(self): | ||
api_token = get_xloader_user_apitoken() | ||
site_user = helpers.call_action("get_site_user") | ||
assert api_token == site_user["apikey"] | ||
|
||
def test_xloader_user_api_token_from_config(self): | ||
sysadmin = factories.SysadminWithToken() | ||
apikey = sysadmin["token"] | ||
with mock.patch.dict(toolkit.config, {'ckanext.xloader.api_token': apikey}): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is to mimic what would be in the config. I ran out of time to work out how to look up a key inside pytest or hope that the db setup at the start was not 'cleansed' There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For dynamic token values this approach does make sense. |
||
api_token = get_xloader_user_apitoken() | ||
assert api_token == apikey | ||
|
||
@pytest.mark.ckan_config("ckanext.xloader.api_token", "NOT_SET") | ||
def test_xloader_user_api_token_from_config_should_throw_exceptio_when_not_set(self): | ||
|
||
hasNotThrownException = True | ||
try: | ||
get_xloader_user_apitoken() | ||
except Exception: | ||
hasNotThrownException = False | ||
|
||
assert not hasNotThrownException | ||
|
||
@pytest.mark.ckan_config("ckanext.xloader.api_token", "random-api-token") | ||
def test_xloader_user_api_token(self): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use test.yml so we don't need to duplicate how we test again.