Changeset View
Changeset View
Standalone View
Standalone View
swh/web/ui/views/api.py
Show All 19 Lines | Returns: | ||||
SWH storage's statistics. | SWH storage's statistics. | ||||
""" | """ | ||||
return service.stat_counters() | return service.stat_counters() | ||||
@app.route('/api/1/search/') | @app.route('/api/1/search/') | ||||
@app.route('/api/1/search/<string:q>/') | @app.route('/api/1/search/<string:q>/') | ||||
def api_search(q='sha1:bd819b5b28fcde3bf114d16a44ac46250da94ee5'): | def api_search(q): | ||||
"""Search a content per hash. | """Search a content per hash. | ||||
Args: | Args: | ||||
q is of the form algo_hash:hash with algo_hash in | q is of the form algo_hash:hash with algo_hash in | ||||
(sha1, sha1_git, sha256). | (sha1, sha1_git, sha256). | ||||
Returns: | Returns: | ||||
Dictionary with 'found' key and the associated result. | Dictionary with 'found' key and the associated result. | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | if isinstance(res, (map, list, GeneratorType)): | ||||
for e in res: | for e in res: | ||||
enriched_data.append(enrich_fn(e)) | enriched_data.append(enrich_fn(e)) | ||||
return enriched_data | return enriched_data | ||||
return enrich_fn(res) | return enrich_fn(res) | ||||
@app.route('/api/1/origin/') | @app.route('/api/1/origin/') | ||||
@app.route('/api/1/origin/<int:origin_id>/') | @app.route('/api/1/origin/<int:origin_id>/') | ||||
def api_origin(origin_id=1): | def api_origin(origin_id): | ||||
"""Return information about origin with id origin_id. | """Return information about origin with id origin_id. | ||||
Args: | Args: | ||||
origin_id: the origin's identifier. | origin_id: the origin's identifier. | ||||
Returns: | Returns: | ||||
Information on the origin if found. | Information on the origin if found. | ||||
Raises: | Raises: | ||||
NotFoundExc if the origin is not found. | NotFoundExc if the origin is not found. | ||||
Example: | Example: | ||||
GET /api/1/origin/1/ | GET /api/1/origin/1/ | ||||
""" | """ | ||||
return _api_lookup( | return _api_lookup( | ||||
origin_id, lookup_fn=service.lookup_origin, | origin_id, lookup_fn=service.lookup_origin, | ||||
error_msg_if_not_found='Origin with id %s not found.' % origin_id) | error_msg_if_not_found='Origin with id %s not found.' % origin_id) | ||||
@app.route('/api/1/person/') | @app.route('/api/1/person/') | ||||
@app.route('/api/1/person/<int:person_id>/') | @app.route('/api/1/person/<int:person_id>/') | ||||
def api_person(person_id=1): | def api_person(person_id): | ||||
"""Return information about person with identifier person_id. | """Return information about person with identifier person_id. | ||||
Args: | Args: | ||||
person_id: the person's identifier. | person_id: the person's identifier. | ||||
Returns: | Returns: | ||||
Information on the person if found. | Information on the person if found. | ||||
Raises: | Raises: | ||||
NotFoundExc if the person is not found. | NotFoundExc if the person is not found. | ||||
Example: | Example: | ||||
GET /api/1/person/1/ | GET /api/1/person/1/ | ||||
""" | """ | ||||
return _api_lookup( | return _api_lookup( | ||||
person_id, lookup_fn=service.lookup_person, | person_id, lookup_fn=service.lookup_person, | ||||
error_msg_if_not_found='Person with id %s not found.' % person_id) | error_msg_if_not_found='Person with id %s not found.' % person_id) | ||||
@app.route('/api/1/release/') | @app.route('/api/1/release/') | ||||
@app.route('/api/1/release/<string:sha1_git>/') | @app.route('/api/1/release/<string:sha1_git>/') | ||||
def api_release(sha1_git='1e951912027ea6873da6985b91e50c47f645ae1a'): | def api_release(sha1_git): | ||||
"""Return information about release with id sha1_git. | """Return information about release with id sha1_git. | ||||
Args: | Args: | ||||
sha1_git: the release's hash. | sha1_git: the release's hash. | ||||
Returns: | Returns: | ||||
Information on the release if found. | Information on the release if found. | ||||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | @app.route('/api/1/revision' | ||||
'/branch/<path:branch_name>' | '/branch/<path:branch_name>' | ||||
'/ts/<string:ts>' | '/ts/<string:ts>' | ||||
'/directory/') | '/directory/') | ||||
@app.route('/api/1/revision' | @app.route('/api/1/revision' | ||||
'/origin/<int:origin_id>' | '/origin/<int:origin_id>' | ||||
'/branch/<path:branch_name>' | '/branch/<path:branch_name>' | ||||
'/ts/<string:ts>' | '/ts/<string:ts>' | ||||
'/directory/<path:path>/') | '/directory/<path:path>/') | ||||
def api_directory_through_revision_origin(origin_id=1, | def api_directory_through_revision_origin(origin_id, | ||||
branch_name="refs/heads/master", | branch_name="refs/heads/master", | ||||
ts=None, | ts=None, | ||||
path=None, | path=None, | ||||
with_data=False): | with_data=False): | ||||
"""Display directory or content information through a revision identified | """Display directory or content information through a revision identified | ||||
by origin/branch/timestamp. | by origin/branch/timestamp. | ||||
Args: | Args: | ||||
Show All 35 Lines | @app.route('/api/1/revision' | ||||
'/origin/<int:origin_id>' | '/origin/<int:origin_id>' | ||||
'/branch/<path:branch_name>' | '/branch/<path:branch_name>' | ||||
'/history/<sha1_git>/') | '/history/<sha1_git>/') | ||||
@app.route('/api/1/revision' | @app.route('/api/1/revision' | ||||
'/origin/<int:origin_id>' | '/origin/<int:origin_id>' | ||||
'/branch/<path:branch_name>' | '/branch/<path:branch_name>' | ||||
'/ts/<string:ts>' | '/ts/<string:ts>' | ||||
'/history/<sha1_git>/') | '/history/<sha1_git>/') | ||||
def api_revision_history_through_origin(origin_id=1, | def api_revision_history_through_origin(origin_id, | ||||
branch_name="refs/heads/master", | branch_name="refs/heads/master", | ||||
ts=None, | ts=None, | ||||
sha1_git=None): | sha1_git=None): | ||||
""" | """ | ||||
Return information about revision sha1_git, limited to the | Return information about revision sha1_git, limited to the | ||||
sub-graph of all transitive parents of the revision root identified | sub-graph of all transitive parents of the revision root identified | ||||
by (origin_id, branch_name, ts). | by (origin_id, branch_name, ts). | ||||
Given sha1_git_root such root revision's identifier, in other words, | Given sha1_git_root such root revision's identifier, in other words, | ||||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | @app.route('/api/1/revision' | ||||
'/directory/') | '/directory/') | ||||
@app.route('/api/1/revision' | @app.route('/api/1/revision' | ||||
'/origin/<int:origin_id>' | '/origin/<int:origin_id>' | ||||
'/branch/<path:branch_name>' | '/branch/<path:branch_name>' | ||||
'/ts/<string:ts>' | '/ts/<string:ts>' | ||||
'/history/<sha1_git>' | '/history/<sha1_git>' | ||||
'/directory/<path:path>/') | '/directory/<path:path>/') | ||||
def api_directory_through_revision_with_origin_history( | def api_directory_through_revision_with_origin_history( | ||||
origin_id=1, | origin_id, | ||||
branch_name="refs/heads/master", | branch_name="refs/heads/master", | ||||
ts=None, | ts=None, | ||||
sha1_git=None, | sha1_git=None, | ||||
path=None, | path=None, | ||||
with_data=False): | with_data=False): | ||||
"""Return information about directory or content pointed to by the | """Return information about directory or content pointed to by the | ||||
revision defined as: revision sha1_git, limited to the sub-graph | revision defined as: revision sha1_git, limited to the sub-graph | ||||
of all transitive parents of sha1_git_root (being the identified | of all transitive parents of sha1_git_root (being the identified | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | @app.route('/api/1/revision' | ||||
'/branch/<path:branch_name>/') | '/branch/<path:branch_name>/') | ||||
@app.route('/api/1/revision' | @app.route('/api/1/revision' | ||||
'/origin/<int:origin_id>' | '/origin/<int:origin_id>' | ||||
'/branch/<path:branch_name>' | '/branch/<path:branch_name>' | ||||
'/ts/<string:ts>/') | '/ts/<string:ts>/') | ||||
@app.route('/api/1/revision' | @app.route('/api/1/revision' | ||||
'/origin/<int:origin_id>' | '/origin/<int:origin_id>' | ||||
'/ts/<string:ts>/') | '/ts/<string:ts>/') | ||||
def api_revision_with_origin(origin_id=1, | def api_revision_with_origin(origin_id, | ||||
branch_name="refs/heads/master", | branch_name="refs/heads/master", | ||||
ts=None): | ts=None): | ||||
"""Instead of having to specify a (root) revision by SHA1_GIT, users | """Instead of having to specify a (root) revision by SHA1_GIT, users | ||||
might want to specify a place and a time. In SWH a "place" is an | might want to specify a place and a time. In SWH a "place" is an | ||||
origin; a "time" is a timestamp at which some place has been | origin; a "time" is a timestamp at which some place has been | ||||
observed by SWH crawlers. | observed by SWH crawlers. | ||||
Args: | Args: | ||||
Show All 23 Lines | return _api_lookup( | ||||
ts), | ts), | ||||
utils.enrich_revision, | utils.enrich_revision, | ||||
branch_name, | branch_name, | ||||
ts) | ts) | ||||
@app.route('/api/1/revision/') | @app.route('/api/1/revision/') | ||||
@app.route('/api/1/revision/<string:sha1_git>/') | @app.route('/api/1/revision/<string:sha1_git>/') | ||||
def api_revision(sha1_git='a585d2b738bfa26326b3f1f40f0f1eda0c067ccf'): | def api_revision(sha1_git): | ||||
"""Return information about revision with id sha1_git. | """Return information about revision with id sha1_git. | ||||
Args: | Args: | ||||
sha1_git: the revision's hash. | sha1_git: the revision's hash. | ||||
Returns: | Returns: | ||||
Information on the revision if found. | Information on the revision if found. | ||||
Show All 10 Lines | return _api_lookup( | ||||
lookup_fn=service.lookup_revision, | lookup_fn=service.lookup_revision, | ||||
error_msg_if_not_found='Revision with sha1_git %s not' | error_msg_if_not_found='Revision with sha1_git %s not' | ||||
' found.' % sha1_git, | ' found.' % sha1_git, | ||||
enrich_fn=utils.enrich_revision) | enrich_fn=utils.enrich_revision) | ||||
@app.route('/api/1/revision/<string:sha1_git>/directory/') | @app.route('/api/1/revision/<string:sha1_git>/directory/') | ||||
@app.route('/api/1/revision/<string:sha1_git>/directory/<path:dir_path>/') | @app.route('/api/1/revision/<string:sha1_git>/directory/<path:dir_path>/') | ||||
def api_revision_directory(sha1_git='a585d2b738bfa26326b3f1f40f0f1eda0c067ccf', | def api_revision_directory(sha1_git, | ||||
dir_path=None, | dir_path=None, | ||||
with_data=False): | with_data=False): | ||||
"""Return information on directory pointed by revision with sha1_git. | """Return information on directory pointed by revision with sha1_git. | ||||
If dir_path is not provided, display top level directory. | If dir_path is not provided, display top level directory. | ||||
Otherwise, display the directory pointed by dir_path (if it exists). | Otherwise, display the directory pointed by dir_path (if it exists). | ||||
Args: | Args: | ||||
sha1_git: revision's hash. | sha1_git: revision's hash. | ||||
▲ Show 20 Lines • Show All 143 Lines • ▼ Show 20 Lines | return _api_lookup(sha1_git, | ||||
lookup_fn=lookup_revision_log_with_limit, | lookup_fn=lookup_revision_log_with_limit, | ||||
error_msg_if_not_found=error_msg, | error_msg_if_not_found=error_msg, | ||||
enrich_fn=utils.enrich_revision) | enrich_fn=utils.enrich_revision) | ||||
@app.route('/api/1/directory/') | @app.route('/api/1/directory/') | ||||
@app.route('/api/1/directory/<string:sha1_git>/') | @app.route('/api/1/directory/<string:sha1_git>/') | ||||
@app.route('/api/1/directory/<string:sha1_git>/<path:path>/') | @app.route('/api/1/directory/<string:sha1_git>/<path:path>/') | ||||
def api_directory(sha1_git='dcf3289b576b1c8697f2a2d46909d36104208ba3', | def api_directory(sha1_git, | ||||
path=None): | path=None): | ||||
"""Return information about release with id sha1_git. | """Return information about release with id sha1_git. | ||||
Args: | Args: | ||||
sha1_git: Directory's sha1_git. If path exists: starting directory for | sha1_git: Directory's sha1_git. If path exists: starting directory for | ||||
relative navigation. | relative navigation. | ||||
path: The path to the queried directory | path: The path to the queried directory | ||||
Show All 21 Lines | else: | ||||
sha1_git, | sha1_git, | ||||
service.lookup_directory, | service.lookup_directory, | ||||
error_msg_nopath, | error_msg_nopath, | ||||
utils.enrich_directory) | utils.enrich_directory) | ||||
# @app.route('/api/1/browse/') | # @app.route('/api/1/browse/') | ||||
# @app.route('/api/1/browse/<string:q>/') | # @app.route('/api/1/browse/<string:q>/') | ||||
def api_content_checksum_to_origin(q='sha1_git:26ac0281bc74e9bd8a4a4aab1c7c7a' | def api_content_checksum_to_origin(q): | ||||
'0c19d4436c'): | |||||
"""Return content information up to one of its origin if the content | """Return content information up to one of its origin if the content | ||||
is found. | is found. | ||||
Args: | Args: | ||||
q is of the form algo_hash:hash with algo_hash in | q is of the form algo_hash:hash with algo_hash in | ||||
(sha1, sha1_git, sha256). | (sha1, sha1_git, sha256). | ||||
Returns: | Returns: | ||||
Show All 38 Lines | def api_content_raw(q): | ||||
if not content: | if not content: | ||||
raise NotFoundExc('Content with %s not found.' % q) | raise NotFoundExc('Content with %s not found.' % q) | ||||
return Response(generate(content), mimetype='application/octet-stream') | return Response(generate(content), mimetype='application/octet-stream') | ||||
@app.route('/api/1/content/') | @app.route('/api/1/content/') | ||||
@app.route('/api/1/content/<string:q>/') | @app.route('/api/1/content/<string:q>/') | ||||
def api_content_metadata(q='sha256:e2c76e40866bb6b28916387bdfc8649beceb' | def api_content_metadata(q): | ||||
'523015738ec6d4d540c7fe65232b'): | |||||
"""Return content information if content is found. | """Return content information if content is found. | ||||
Args: | Args: | ||||
q is of the form (algo_hash:)hash with algo_hash in | q is of the form (algo_hash:)hash with algo_hash in | ||||
(sha1, sha1_git, sha256). | (sha1, sha1_git, sha256). | ||||
When algo_hash is not provided, 'hash' is considered sha1. | When algo_hash is not provided, 'hash' is considered sha1. | ||||
Returns: | Returns: | ||||
Show All 12 Lines | return _api_lookup( | ||||
q, | q, | ||||
lookup_fn=service.lookup_content, | lookup_fn=service.lookup_content, | ||||
error_msg_if_not_found='Content with %s not found.' % q, | error_msg_if_not_found='Content with %s not found.' % q, | ||||
enrich_fn=utils.enrich_content) | enrich_fn=utils.enrich_content) | ||||
@app.route('/api/1/entity/') | @app.route('/api/1/entity/') | ||||
@app.route('/api/1/entity/<string:uuid>/') | @app.route('/api/1/entity/<string:uuid>/') | ||||
def api_entity_by_uuid(uuid='5f4d4c51-498a-4e28-88b3-b3e4e8396cba'): | def api_entity_by_uuid(uuid): | ||||
"""Return content information if content is found. | """Return content information if content is found. | ||||
Args: | Args: | ||||
q is of the form (algo_hash:)hash with algo_hash in | q is of the form (algo_hash:)hash with algo_hash in | ||||
(sha1, sha1_git, sha256). | (sha1, sha1_git, sha256). | ||||
When algo_hash is not provided, 'hash' is considered sha1. | When algo_hash is not provided, 'hash' is considered sha1. | ||||
Returns: | Returns: | ||||
Show All 39 Lines |