-
Notifications
You must be signed in to change notification settings - Fork 54
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
[Draft] Proof of concept for xloader site url #234
base: master
Are you sure you want to change the base?
Changes from all commits
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 | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -2,6 +2,12 @@ version: 1 | |||||||
groups: | ||||||||
- annotation: ckanext-xloader settings | ||||||||
options: | ||||||||
- key: ckanext.xloader.site_url | ||||||||
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. | ||||||||
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.
Suggested change
|
||||||||
required: false | ||||||||
- key: ckanext.xloader.jobs_db.uri | ||||||||
default: sqlite:////tmp/xloader_jobs.db | ||||||||
description: | | ||||||||
|
@@ -152,5 +158,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 |
---|---|---|
|
@@ -61,13 +61,11 @@ def configure(self, config_): | |
else: | ||
self.ignore_hash = False | ||
|
||
for config_option in ("ckan.site_url",): | ||
if not config_.get(config_option): | ||
raise Exception( | ||
"Config option `{0}` must be set to use ckanext-xloader.".format( | ||
config_option | ||
) | ||
) | ||
site_url_configs = ("ckan.site_url", "ckanext.xloader.site_url") | ||
if not any(site_url_configs): | ||
raise Exception( | ||
f"One of config options {site_url_configs} must be set to use ckanext-xloader." | ||
) | ||
Comment on lines
+64
to
+68
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 will refuse to start if a site_url isn't provided, so this code would never get executed 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. @wardi here, I'm just extending the existing check for that. I prefer not to remove existing behavior, but just to provide the minimal new behavior required for the PR https://github.com/ckan/ckanext-xloader/blob/master/ckanext/xloader/plugin.py#L64 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. If you did not cleanup the error message, this would not have been commented upon ;) I'm fine leaving this in as its a belts and braces approach, better to fail early (if it does occur which is very very remote) |
||
|
||
# IDomainObjectModification | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,17 +59,18 @@ def data(create_with_upload, apikey): | |
"api.action", ver=3, logic_function="xloader_hook", qualified=True | ||
) | ||
return { | ||
'api_key': apikey, | ||
'job_type': 'xloader_to_datastore', | ||
'result_url': callback_url, | ||
'metadata': { | ||
'ignore_hash': True, | ||
'ckan_url': toolkit.config.get('ckan.site_url'), | ||
'resource_id': resource["id"], | ||
'set_url_type': False, | ||
'task_created': datetime.utcnow().isoformat(), | ||
'original_url': resource["url"], | ||
} | ||
"api_key": apikey, | ||
"job_type": "xloader_to_datastore", | ||
"result_url": callback_url, | ||
"metadata": { | ||
"ignore_hash": True, | ||
"ckan_url": toolkit.config.get("ckanext.xloader.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. going to need more tests created to set these two values for proper validation. |
||
or toolkit.config.get("ckan.site_url"), | ||
"resource_id": resource["id"], | ||
"set_url_type": False, | ||
"task_created": datetime.utcnow().isoformat(), | ||
"original_url": resource["url"], | ||
}, | ||
} | ||
|
||
|
||
|
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.
I think we don't need an empty string default, it's normal for optional settings to be not present if not provided
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.
instead of the
toolkit.config.get("ckanext.xloader.site_url") or toolkit.config.get("ckan.site_url")
logic below we should be able to use justtoolkit.config.get("ckanext.xloader.site_url")
along with: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.
@wardi ok I see. so that default is just set in the config yaml, and then, any code can assume that fallback default for the
ckanext.xloader.site_url
setting?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.
yeah, this validator will set
ckanext.xloader.site_url
to the same asckan.site_url
when it's not given. Another one of @smotornyuk 's clever ideas.