WaterButler is a Python web application for interacting with various file storage services via a single RESTful API, developed at Center for Open Science.
Apache License 2.0
62
stars
76
forks
source link
[No Ticket] Fix The Issue that Branch Name with Slash Breaks BB Repo Endpoints #377
The BB API 2.0 path endpoint /2.0/repositories/{username}/{repo_slug}/src/{node}/{path} WB uses returns HTTP 404 if the {node} segment is a branch of which the name contains a slash. This is either a limitation or a bug on several BB API 2.0 endpoints, which has nothing to do with encoding. More specifically, neither encoding / with %2F nor enclosing node with curly braces (%7B and %7D) works.
Here is the closest reference to this issue we have found as of May 2019 and here is another one without further discussion or solution.
Every time before a path.ref is used to build BB API URL, apply the following fix if the path does not have a commit SHA yet.
Making an extra request to fetch the commit SHA of the branch
Setting the path commit SHA
BB Unit Tests
Added one test for fetching the commit SHA of a branch
Added tests for fetching path metadata, w/ and w/o commit SHA
Updated the file meta test and fixed the folder meta test
Side effects
An extra request is made, which is unavoidable. However, this performance overhead is alright.
Locally I am not seeing visible delay during accessing the BB provider
This only happen when the commit SHA is not set before. For example, _fetch_dir_listing() never makes this extra request due to path_metadata() has always been called in advance which sets the commit SHA.
QA Notes
[ ] Please verify that all actions on BB works with a branch of which the name contains a slash.
Local Tests I Have Verified
[x] Switch branches and load the root-level contents
Coverage decreased (-0.03%) to 91.823% when pulling 80f4a10e535a858ca53c72a512318fc6f23ef1d5 on cslzchen:fix/bb-api-branch-name-with-slash into e708170c272665b3e6208ec02fe5310a10778734 on CenterForOpenScience:develop.
Ticket
No Ticket
Purpose
The BB API 2.0
path
endpoint /2.0/repositories/{username}/{repo_slug}/src/{node}/{path} WB uses returnsHTTP 404
if the{node}
segment is a branch of which the name contains a slash. This is either a limitation or a bug on several BB API 2.0 endpoints, which has nothing to do with encoding. More specifically, neither encoding / with %2F nor enclosingnode
with curly braces (%7B and %7D) works.Here is the closest reference to this issue we have found as of May 2019 and here is another one without further discussion or solution.
Note: this is an issue with BB API 2.0 only and was introduced to staging servers by https://github.com/CenterForOpenScience/waterbutler/pull/375 (ENG-303).
This PR fixes the above issue by making an extra request to fetch the commit SHA of the branch.
Changes
The BB Provider
_fetch_branch_commit_sha()
. It uses the /2.0/repositories/{username}/{repo_slug}/refs/branches/{name} endpoint to fetch the branch metadata which contians the commit SHA.path.ref
is used to build BB API URL, apply the following fix if thepath
does not have a commit SHA yet.path
commit SHABB Unit Tests
Side effects
An extra request is made, which is unavoidable. However, this performance overhead is alright.
_fetch_dir_listing()
never makes this extra request due topath_metadata()
has always been called in advance which sets the commit SHA.QA Notes
Local Tests I Have Verified
Deployment Notes
Not I can think of yet.