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

Feature/custom xloader site url rebased #243

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

duttonw
Copy link
Collaborator

@duttonw duttonw commented Mar 3, 2025

supersedes: pwalsh:feature/custom-xloader-site-url #234

We want to be able to communicate within a docker network without using the public site_url. This is a minimal proof of concept for achieving this.

Update: There are 2 scenario's where XLoader communicates to CKAN

Scenario 1: When it downloads the resource file from CKAN ie: in _download_resource_data()
Scenario 2: When it updates the status of the XLoader job ie: in callback_xloader_hook()

If the config option ckanext.xloader.site_url is set then all communication from XLoader to CKAN will use this URL. In scenario 1, if it's not set then the ckan.site_url config option will be used unless the download ie: _download_resource_data() original_url is different to ckan_url (ie: ckan.site_url) and in that case the _download_resource_data() download will use the original_url but all other communication back to CKAN (ie: scenario 2) will use the ckan.site_url option

@duttonw duttonw requested review from ThrawnCA and kowh-ai March 3, 2025 01:22
@duttonw duttonw self-assigned this Mar 3, 2025
@@ -76,14 +76,6 @@ def configure(self, config_):
else:
self.ignore_hash = False

for config_option in ("ckan.site_url",):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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.

…m which picks up job (which could have different ckan.ini config)



def test_modify_input_url_no_xloader_site():
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this a separate test instead of just another set of parameterised inputs?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it's also in the parameterised, but it may still be nice to keep seperate for 'clarity'

 - provide better error messaging on incorrect api_key setup
 - user creation for testing to mimic real life 2.10+ environment
chore: use cleaner pytest for setting variables
run: pytest --ckan-ini=test.ini --cov=ckanext.xloader --disable-warnings ckanext/xloader/tests
needs: validateVersion
name: Test
uses: ./.github/workflows/test.yml # Call the reusable workflow
Copy link
Collaborator Author

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.

@@ -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 }}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

duplicate from another repo to give info that its 'ignoring' errors.

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')"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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.

@@ -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')"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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

required: false
apikey of the site_user.
default: 'NOT_SET'
required: true
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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)

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}):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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'

Copy link
Collaborator

Choose a reason for hiding this comment

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

For dynamic token values this approach does make sense.

return api_token
raise p.toolkit.ValidationError({u'ckanext.xloader.api_token': u'NOT_SET, please provide valid api token'})
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hope this change catches miss configurations where xloader does it upload into the datastore but never 'completes' the job.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants