-
Notifications
You must be signed in to change notification settings - Fork 81
Dump & Load User API Tokens #230
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
Changes from 4 commits
5ed3718
2ce3ba6
baa0c7c
c0f4cb6
a3e80b2
d5d102a
dc06c41
2da12ec
61b3821
a15b0fc
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 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -204,8 +204,11 @@ def reply(error, record=None): | |||||||||||||
| if thing == 'datasets' and arguments['--resource-views']: | ||||||||||||||
| for res in obj.get('resources', []): | ||||||||||||||
| populate_res_views(ckan, res) | ||||||||||||||
| if thing == 'users' and arguments['--api-tokens']: | ||||||||||||||
| populate_api_tokens(ckan, obj) | ||||||||||||||
| reply(None, obj) | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| def _worker_command_line(thing, arguments): | ||||||||||||||
| """ | ||||||||||||||
| Create a worker command line suitable for Popen with only the | ||||||||||||||
|
|
@@ -227,6 +230,7 @@ def b(name): | |||||||||||||
| + b('--datastore-fields') | ||||||||||||||
| + b('--resource-views') | ||||||||||||||
| + b('--include-users') | ||||||||||||||
| + b('--api-tokens') | ||||||||||||||
| + ['value-here-to-make-docopt-happy'] | ||||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -248,3 +252,19 @@ def populate_res_views(ckan, res): | |||||||||||||
| return # return if the resource views list is empty | ||||||||||||||
| res['resource_views'] = views | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| def populate_api_tokens(ckan, user): | ||||||||||||||
| """ | ||||||||||||||
| Update user dict in-place with api_token_list | ||||||||||||||
| """ | ||||||||||||||
| try: | ||||||||||||||
| tokens = ckan.call_action('api_token_list', { | ||||||||||||||
| 'user_id': user['name'], | ||||||||||||||
| 'limit': 0}) | ||||||||||||||
| except CKANAPIError: | ||||||||||||||
| return | ||||||||||||||
| except NotFound: | ||||||||||||||
| return # with localckan we'll get the real CKAN exception not a CKANAPIError subclass | ||||||||||||||
|
Comment on lines
+261
to
+264
Contributor
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. The way this is written multiple exceptions would be caught in the RemoteCKAN case but only NotFound will be caught in the LocalCKAN case, that's strange.
Suggested change
But, would we ever expect a NotFound? Won't that only happen if the user doesn't exist? If so it's better to not catch and ignore any exceptions.
Contributor
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. But, I'll merge as-is and we can clean it up later. |
||||||||||||||
| if not tokens: | ||||||||||||||
| return # return if the user api token list is empty | ||||||||||||||
| user['api_token_list'] = tokens | ||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.