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

Feat/index record alias api #248

Merged
merged 53 commits into from
Nov 7, 2019
Merged

Feat/index record alias api #248

merged 53 commits into from
Nov 7, 2019

Conversation

mpingram
Copy link
Contributor

@mpingram mpingram commented Oct 21, 2019

PXP-4353
Implement API to manipulate index_record_alias

  • Add ability to create, update and delete aliases for GUIDs. Aliases can be used to query the root endpoint for a record instead of that record's GUID. Aliases are associated with one GUID only.

  • API uses create and update Arborist permissions

  • Change IndexRecordAlias table -- add unique constraint to alias name column

New Features

  • Implement API to manipulate aliases for Indexd records.

Bug Fixes

  • Fix bug in Indexd DOS search (GET /ga4gh/dos/v1/dataobjects/<path:record>) preventing aliases from being returned when querying for a record's baseID.

* WIP design for adding /index/{GUID}/aliases endpoint to indexd
- Deprecate old '/alias' endpoint
- Add 'AliasInfo' JSON object description
- Remove DELETE /index/{GUID}/aliases/{ALIAS} endpoint
- Change behavior of DELETE /index/{GUID}/aliases/ endpoint -- delete
  only some aliases, not all aliases
- Update descriptions of all endpoints and parameters for /{GUID}/alias/
- Add 404 (GUID not found) error to GET /index/{GUID}/aliases
- Add 404 (GUID not found), 403 (Non-unique aliases) to PUT, POST /index/{GUID}/aliases
- Add 404 (GUID not found or alias not found) to DELETE /index/{GUID}/aliases
	- Specify behavior if subset of aliases to be deleted are
- Add error and response schema to /index/{GUID}/aliases
* Edit error response description to clarify that no
  records are deleted if a 400-Invalid Request error
  occurs.
* Removes constraint requiring aliases to not be duplicated
  in the request body.
* Reasoning: aliases must be globally unique, but aliases
  in the request body can be duplicates of each other
  and the server can still fullfil the request, so there
  is no need for the constraint that aliases must not
  be duplicated in the request.
* Allow random alias functions to be used by tests
* Separate 'guid_aliases' fixture into separate 'guid' and 'aliases'
  fixtures
* Change DELETE endpoint behavior for consistency with other
  gen3 APIs
- New API behavior:
	- DELETE `/index/{GUID}/aliases` (delete all)
	- DELETE `/index/{GUID}/aliases/{ALIAS}` (delete one)
* Correctly compare alias payloads
* Fix test fixtures not included in some tests
* Fix some typos
- Basic GET and POST: no validation or error handling, only direct db manipulation
- Reason: basic GET and POST required to bootstrap tests in `tests/test_aliases_endpoints.py`
* Validate results of good GET request, not just status code
- Add test for aliases with same name as GUID
- Add test for aliases with same name as app
    endpoints on root of API
    - Reason: Because of the `/{GUID|ALIAS}` endpoint, if an alias
        shared the name of an endpoint on the root of the API such as `/latest`,
        if an alias was named "latest" it would cause difficulty resolving the alias.
- Rename `get_random_guid` -> `create_random_record` to clarify it adds
  a record to the indexd db
- Fix some errors in tests
- [x] invalid_GUID
- [~] nonunique_aliases
- [ ] previously_used_valid_alias
- [ ] GUID_already_has_alias
- [ ] duplicate_aliases_in_request
- [ ] valid_GUID_empty_aliases
- [ ] alias_has_name_of_endpoint_on_root
- [ ] alias_has_name_of_existing_GUID

BRAINDUMP 5:04pm
- Was trying to figure out why test_PUT_aliases_nonunique_aliases wasn't
  working -- it seems like the alias IS being put into the table with
  the other_guid's value, but then the second write with the 'guid' value
  goes thru no problem. I think I might have misunderstood how the unique
  constraint on foreign keys works -- it looks like the insert might be
  updating the field instead ????? I figured it would fail....
- [x] invalid_GUID
- [x] nonunique_aliases
- [x] previously_used_valid_alias
- [x] GUID_already_has_alias
- [ ] duplicate_aliases_in_request
- [x] valid_GUID_empty_aliases
- [ ] alias_has_name_of_endpoint_on_root
- [ ] alias_has_name_of_existing_GUID
- invalid_GUID
- nonunique_aliases
- previously_used_valid_alias
- GUID_already_has_alias
- duplicate_aliases_in_request
- valid_GUID_empty_aliases
- alias_has_name_of_endpoint_on_root
- alias_has_name_of_existing_GUID

NOTE - 'aliases do not have name of existing GUID' requirement
    may conflict with feature implemented by [PR#123](#123)
- Add tests to POST and PUT for requests with emtpy body
- Reason: avoid error in blueprints due to behavior of flask.request.get_json()
  (returns None if request has content-type other than application/json)
- Write tests for DELETE all aliases endpoint
- Write tests for DELETE one alias endpoint
- URL encode aliases in request
- Fix bug caused by list.remove() mutating list
- To disambiguate the tests for the deprecated /alias/ endpoint
  from the tests for the /index/{GUID}/aliases endpoint
- Update docs to indicate no body in response to PUT and POST aliases
@mpingram mpingram marked this pull request as ready for review October 22, 2019 14:26
Copy link
Contributor

@paulineribeyre paulineribeyre left a comment

Choose a reason for hiding this comment

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

looks gooood

  • please check whether the README's mentions of aliases shoulb be updated
  • sheepdog creates aliases via the indexclient with endpoint "PUT /alias/" - we need to discuss how to handle that. should we update the alias creation in sheepdog or should we just remove it? and we should update indexclient either way

'/index/{GUID}/aliases':
get:
tags:
- index
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd argue that alias endpoints should still be tagged "alias", I like docs sections

but i could be convinced otherwise :p

tests/test_client.py Outdated Show resolved Hide resolved
indexd/index/blueprint.py Outdated Show resolved Hide resolved
indexd/index/drivers/alchemy.py Outdated Show resolved Hide resolved
indexd/index/drivers/alchemy.py Show resolved Hide resolved
tests/test_aliases_endpoints.py Show resolved Hide resolved
tests/test_aliases_endpoints.py Outdated Show resolved Hide resolved
tests/test_aliases_endpoints.py Outdated Show resolved Hide resolved
tests/test_aliases_endpoints.py Outdated Show resolved Hide resolved
indexd/index/blueprint.py Show resolved Hide resolved
@github-actions
Copy link

github-actions bot commented Nov 5, 2019

The style in this PR agrees with black. ✔️

This formatting comment was generated automatically by a script in uc-cdis/wool.

* Move some error handling from blueprint to driver for consistency
* Fix bug in test cases in which behavior of POST/PUT returning records
  was not tested
* Add spaces to aliases in test cases
* Move repeated 'get a record or None' logic into own function
* Use flask.request.get_json(force=True)
* Add statements to asserts in test code
* Small changes and fixes suggested by reviewers
* Move tests for deprecated alias endpoints to separate file
@mpingram
Copy link
Contributor Author

mpingram commented Nov 7, 2019

please check whether the README's mentions of aliases shoulb be updated

README looks good to me, it describes aliases as linking to GUIDs (which is the case with the changes from this PR)

- Update POST/PUT to return aliases on success, as per spec
- Update swagger documentation to reflect the spec

return flask.jsonify(ret), 200
aliases = blueprint.index_driver.get_aliases_for_did(record)
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of querying the db, replace_aliases_for_did can return the list

Copy link
Contributor

@paulineribeyre paulineribeyre left a comment

Choose a reason for hiding this comment

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

thank you for the docs :D
i will create a ticket to update indexclient and sheepdog

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.

None yet

3 participants