Skip to content

Dump & Load User API Tokens#230

Merged
wardi merged 10 commits into
ckan:masterfrom
JVickery-TBS:feature/user-api-tokens
May 23, 2026
Merged

Dump & Load User API Tokens#230
wardi merged 10 commits into
ckan:masterfrom
JVickery-TBS:feature/user-api-tokens

Conversation

@JVickery-TBS
Copy link
Copy Markdown
Contributor

@JVickery-TBS JVickery-TBS commented May 7, 2026

Allows dumping and loading of user api tokens.

req: ckan/ckan#9339

cc: @wardi

- Dump and load user api tokens.
Comment thread ckanapi/cli/dump.py Outdated
Comment thread ckanapi/cli/load.py Outdated
Comment thread ckanapi/cli/load.py Outdated
Comment thread ckanapi/cli/main.py
- Dump and load user api tokens.
@JVickery-TBS
Copy link
Copy Markdown
Contributor Author

@wardi okay I think this makes more sense now. I also adding in a pop on the api_token_list so that it does not get sent to the user_update or user_create actions.

@JVickery-TBS JVickery-TBS requested a review from wardi May 11, 2026 14:27
- Added new options to tests.
@JVickery-TBS
Copy link
Copy Markdown
Contributor Author

Tests updated now too

- Added new options to tests.
Comment thread ckanapi/cli/dump.py Outdated
Comment thread ckanapi/cli/load.py
@wardi
Copy link
Copy Markdown
Contributor

wardi commented May 15, 2026

A small test with mocked actions would be good to make sure this feature keeps working

- Added new options to tests.
@JVickery-TBS
Copy link
Copy Markdown
Contributor Author

@wardi okay I have tests from dumping users, dumping users w/ api tokens, and loading users. I could not figure out coverage for loading users with tokens as the create api token action does model.User.get instead of user_show action so not sure how to mock that up

- Added new options to tests.
- Added new options to tests.
- Added new options to tests.
- Added new options to tests.
@JVickery-TBS
Copy link
Copy Markdown
Contributor Author

@wardi okay I did the load api tokens test. And now log out the loaded tokens by name. Which I guess begs a new question, should I be handling the tokens that could not load and list them as skipped tokens? Like for ValidationErrors on token name already existing?

- Added new options to tests.
@JVickery-TBS JVickery-TBS requested a review from wardi May 22, 2026 18:21
Comment thread ckanapi/cli/dump.py
Comment on lines +261 to +264
except CKANAPIError:
return
except NotFound:
return # with localckan we'll get the real CKAN exception not a CKANAPIError subclass
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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
except CKANAPIError:
return
except NotFound:
return # with localckan we'll get the real CKAN exception not a CKANAPIError subclass
except NotFound:
return # with localckan we'll get the real CKAN exception not a CKANAPIError subclass

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@wardi wardi merged commit 4d32f14 into ckan:master May 23, 2026
6 checks passed
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.

2 participants