launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #31043
[Merge] ~jugmac00/launchpad:expose-build-metadata-via-api into launchpad:master
Jürgen Gmach has proposed merging ~jugmac00/launchpad:expose-build-metadata-via-api into launchpad:master.
Commit message:
Expose the URL to download the metadata file of the fetch service via API
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~jugmac00/launchpad/+git/launchpad/+merge/464639
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~jugmac00/launchpad:expose-build-metadata-via-api into launchpad:master.
diff --git a/lib/lp/snappy/interfaces/snapbuild.py b/lib/lp/snappy/interfaces/snapbuild.py
index 52019bf..46bd205 100644
--- a/lib/lp/snappy/interfaces/snapbuild.py
+++ b/lib/lp/snappy/interfaces/snapbuild.py
@@ -17,6 +17,7 @@ import http.client
from lazr.enum import EnumeratedType, Item
from lazr.restful.declarations import (
error_status,
+ export_operation_as,
export_read_operation,
export_write_operation,
exported,
@@ -370,6 +371,14 @@ class ISnapBuildView(IPackageBuildView, IPrivacy):
:return: A collection of URLs for this build."""
+ @export_operation_as("build_metadata_url")
+ @export_read_operation()
+ @operation_for_version("devel")
+ def getBuildMetadataUrl():
+ """URLs for all the files produced by this build.
+
+ :return: A collection of URLs for this build."""
+
class ISnapBuildEdit(IBuildFarmJobEdit):
"""`ISnapBuild` attributes that require launchpad.Edit."""
diff --git a/lib/lp/snappy/model/snapbuild.py b/lib/lp/snappy/model/snapbuild.py
index df2e2c2..13a52b8 100644
--- a/lib/lp/snappy/model/snapbuild.py
+++ b/lib/lp/snappy/model/snapbuild.py
@@ -425,6 +425,11 @@ class SnapBuild(PackageBuildMixin, StormBase):
def getFileUrls(self):
return [self.lfaUrl(lfa) for _, lfa, _ in self.getFiles()]
+ def getBuildMetadataUrl(self):
+ for url in self.getFileUrls:
+ if url.endswith("metadata.json"):
+ return url
+
@cachedproperty
def eta(self):
"""The datetime when the build job is estimated to complete.
diff --git a/lib/lp/snappy/tests/test_snapbuild.py b/lib/lp/snappy/tests/test_snapbuild.py
index d8b7758..edc917e 100644
--- a/lib/lp/snappy/tests/test_snapbuild.py
+++ b/lib/lp/snappy/tests/test_snapbuild.py
@@ -1009,6 +1009,21 @@ class TestSnapBuildWebservice(TestCaseWithFactory):
for file_url in file_urls:
self.assertCanOpenRedirectedUrl(browser, file_url)
+ def test_getBuildMetadataUrl(self):
+ # API clients can fetch the metadata from the build, generated by the
+ # fetch service
+ db_build = self.factory.makeSnapBuild(requester=self.person)
+ metadata_file = self.factory.makeFileAlias(
+ content="some_json",
+ filename="xxx-metadata.json",
+ )
+ db_build.addFile(metadata_file)
+
+ build_url = api_url(db_build)
+ logout()
+ response = self.webservice.named_get(build_url, "build_metadata_url")
+ self.assertEndsWith(response.jsonBody(), "metadata.json")
+
class TestSnapBuildMacaroonIssuer(MacaroonTestMixin, TestCaseWithFactory):
"""Test SnapBuild macaroon issuing and verification."""
Follow ups