Page MenuHomeSoftware Heritage

api: Add /graph endpoint proxying Software Heritage Graph service
ClosedPublic

Authored by anlambert on Sep 29 2020, 2:10 PM.

Details

Summary

Add a new /graph endpoint to the Web API acting as a proxy for the Software
Heritage Graph service. It forwards graph queries to it and return its raw
responses.

The endpoint requires authentication and user special permission in order
to be able to query it.

It also adds an extra query parameter "resolve_origins" enabling to resolve
origin urls from their sha1 representations returned by the Graph service.

Closes T2589

Diff Detail

Repository
rDWAPPS Web applications
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

Build is green

Patch application report for D4077 (id=14389)

Rebasing onto 504f0db368...

Current branch diff-target is up to date.
Changes applied before test
commit a210df3f20748bfebfb3ec1ff6de2cab66b9765c
Author: Antoine Lambert <antoine.lambert@inria.fr>
Date:   Tue Sep 29 14:08:05 2020 +0200

    api: Add /graph endpoint proxying Software Heritage Graph service
    
    Add a new /graph endpoint to the Web API acting as a proxy for the Software
    Heritage Graph service. It forwards graph queries to it and return its raw
    responses.
    
    The endpoint requires authentication and user special permission in order
    to be able to query it.
    
    It also adds an extra query parameter "resolve_origins" enabling to resolve
    origin urls from their sha1 representations returned by the Graph service.
    
    Closes T2589

See https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/394/ for more details.

Build is green

Patch application report for D4077 (id=14391)

Rebasing onto 504f0db368...

Current branch diff-target is up to date.
Changes applied before test
commit 8ae5e23a7a38eab23f652379bc572e1d01f57fac
Author: Antoine Lambert <antoine.lambert@inria.fr>
Date:   Tue Sep 29 14:08:05 2020 +0200

    api: Add /graph endpoint proxying Software Heritage Graph service
    
    Add a new /graph endpoint to the Web API acting as a proxy for the Software
    Heritage Graph service. It forwards graph queries to it and return its raw
    responses.
    
    The endpoint requires authentication and user special permission in order
    to be able to query it.
    
    It also adds an extra query parameter "resolve_origins" enabling to resolve
    origin urls from their sha1 representations returned by the Graph service.
    
    Closes T2589

See https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/395/ for more details.

Build is green

Patch application report for D4077 (id=14395)

Rebasing onto 504f0db368...

Current branch diff-target is up to date.
Changes applied before test
commit 6b8fceaecd0c05d36e661de8d0d143d06f1a3f11
Author: Antoine Lambert <antoine.lambert@inria.fr>
Date:   Tue Sep 29 14:08:05 2020 +0200

    api: Add /graph endpoint proxying Software Heritage Graph service
    
    Add a new /graph endpoint to the Web API acting as a proxy for the Software
    Heritage Graph service. It forwards graph queries to it and return its raw
    responses.
    
    The endpoint requires authentication and user special permission in order
    to be able to query it.
    
    It also adds an extra query parameter "resolve_origins" enabling to resolve
    origin urls from their sha1 representations returned by the Graph service.
    
    Closes T2589

See https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/396/ for more details.

vlorentz added a subscriber: vlorentz.
vlorentz added inline comments.
swh/web/api/apidoc.py
217–219

why this change?

swh/web/api/views/graph.py
26

it could use a docstring (and/or a better name)

30

this line isn't covered, could you add a test?

63

same

127

don't need an f-string here

swh/web/tests/api/views/test_graph.py
55–71

alternatively, a trick I learned recently:

response_text = textwrap.dedent(
    """\
    swh:1:cnt:1d3dace0a825b0535c37c53ed669ef817e9c1b47
    ...
    swh:1:cnt:f045ee845c7f14d903a2c035b2691a7c400c01f0
    """
)

it spares the extra quotes and \n on each line.

But either way is fine

125–132

textwrap.dedent could be nice here too

This revision now requires changes to proceed.Sep 29 2020, 3:39 PM
swh/web/api/apidoc.py
217–219

To support multiple api url examples in endpoint description. Only one example was used in other endpoint docstrings until then.

swh/web/api/views/graph.py
30

Where can I see the detailed coverage report for Python code ? Jenkins only shows graphs to me on the coverage report page: https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/396/coverage/

127

yes it is (notice the ?)

swh/web/tests/api/views/test_graph.py
55–71

nice !

swh/web/api/apidoc.py
217–219

but I don't see why the old regexp didn't work for multiple examples. (.*) shouldn't match multiple lines by default

swh/web/api/views/graph.py
30

Phabricator shows it with colors on the right side of the diff

127

"?" + request.GET.urlencode(safe="/;:") is simpler IMO, but ok

swh/web/api/apidoc.py
217–219

Ok got it, this works:

examples_str = re.sub(".*`(.+)`.*", r"/api/1/\1", text)
self.data["examples"] += examples_str.split("\n")
swh/web/api/views/graph.py
30

Jeez ! Thanks, I never noticed it.

Build is green

Patch application report for D4077 (id=14403)

Rebasing onto 504f0db368...

Current branch diff-target is up to date.
Changes applied before test
commit 2d69cbc46a1655d88aed7a935e946a3cfa528899
Author: Antoine Lambert <antoine.lambert@inria.fr>
Date:   Tue Sep 29 14:08:05 2020 +0200

    api: Add /graph endpoint proxying Software Heritage Graph service
    
    Add a new /graph endpoint to the Web API acting as a proxy for the Software
    Heritage Graph service. It forwards graph queries to it and return its raw
    responses.
    
    The endpoint requires authentication and user special permission in order
    to be able to query it.
    
    It also adds an extra query parameter "resolve_origins" enabling to resolve
    origin urls from their sha1 representations returned by the Graph service.
    
    Closes T2589

See https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/397/ for more details.

This revision is now accepted and ready to land.Sep 29 2020, 6:16 PM