From 3f5673adb9aac27d67981c6630e06eb553c6fce1 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Mon, 19 Sep 2016 15:44:09 +1200 Subject: [PATCH] Pass through license field from the store --- daemon/api_test.go | 1 + daemon/snap.go | 2 ++ snap/info.go | 1 + store/details.go | 1 + store/store.go | 1 + store/store_test.go | 10 +++++++--- 6 files changed, 13 insertions(+), 3 deletions(-) diff --git a/daemon/api_test.go b/daemon/api_test.go index adae8a4..35a4232 100644 --- a/daemon/api_test.go +++ b/daemon/api_test.go @@ -298,6 +298,7 @@ func (s *apiSuite) TestSnapInfoOneIntegration(c *check.C) { "trymode": false, "apps": []appJSON{}, "broken": "", + "license": "", }, Meta: meta, } diff --git a/daemon/snap.go b/daemon/snap.go index 20f1a3e..44bd0d7 100644 --- a/daemon/snap.go +++ b/daemon/snap.go @@ -146,6 +146,7 @@ func mapLocal(localSnap *snap.Info, snapst *snapstate.SnapState) map[string]inte "private": localSnap.Private, "apps": apps, "broken": localSnap.Broken, + "license": localSnap.License, } } @@ -175,6 +176,7 @@ func mapRemote(remoteSnap *snap.Info) map[string]interface{} { "channel": remoteSnap.Channel, "private": remoteSnap.Private, "confinement": confinement, + "license": remoteSnap.License, } if len(remoteSnap.Prices) > 0 { diff --git a/snap/info.go b/snap/info.go index 47b2c84..6d5b425 100644 --- a/snap/info.go +++ b/snap/info.go @@ -126,6 +126,7 @@ type Info struct { Environment map[string]string + License string LicenseAgreement string LicenseVersion string Epoch string diff --git a/store/details.go b/store/details.go index d3ee425..e31890b 100644 --- a/store/details.go +++ b/store/details.go @@ -35,6 +35,7 @@ type snapDetails struct { DownloadURL string `json:"download_url,omitempty"` IconURL string `json:"icon_url"` LastUpdated string `json:"last_updated,omitempty"` + License string `json:"license"` Name string `json:"package_name"` Prices map[string]float64 `json:"prices,omitempty"` Publisher string `json:"publisher,omitempty"` diff --git a/store/store.go b/store/store.go index 9a715a6..b1bdcbe 100644 --- a/store/store.go +++ b/store/store.go @@ -95,6 +95,7 @@ func infoFromRemote(d snapDetails) *snap.Info { info.Prices = d.Prices info.Private = d.Private info.Confinement = snap.ConfinementType(d.Confinement) + info.License = d.License return info } diff --git a/store/store_test.go b/store/store_test.go index 90f539b..6e19dbc 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -528,7 +528,7 @@ const ( /* acquired via -http --pretty=format --print b https://search.apps.ubuntu.com/api/v1/snaps/details/hello-world X-Ubuntu-Series:16 fields==anon_download_url,architecture,channel,download_sha3_384,summary,description,binary_filesize,download_url,icon_url,last_updated,package_name,prices,publisher,ratings_average,revision,snap_id,support_url,title,content,version,origin,developer_id,private,confinement channel==edge | xsel -b +http --pretty=format --print b https://search.apps.ubuntu.com/api/v1/snaps/details/hello-world X-Ubuntu-Series:16 fields==anon_download_url,architecture,channel,download_sha3_384,summary,description,binary_filesize,download_url,icon_url,last_updated,license,package_name,prices,publisher,ratings_average,revision,snap_id,support_url,title,content,version,origin,developer_id,private,confinement channel==edge | xsel -b on 2016-07-03. Then, by hand: * set prices to {"EUR": 0.99, "USD": 1.23}. @@ -564,6 +564,7 @@ const MockDetailsJSON = `{ "download_url": "https://public.apps.ubuntu.com/download-snap/buPKUD3TKqCOgLEjjHx5kSiCpIs5cMuQ_27.snap", "icon_url": "https://myapps.developer.ubuntu.com/site_media/appmedia/2015/03/hello.svg_NZLfWbh.png", "last_updated": "2016-07-12T16:37:23.960632Z", + "license": "MIT/X/Expat License", "origin": "canonical", "package_name": "hello-world", "prices": {"EUR": 0.99, "USD": 1.23}, @@ -699,6 +700,7 @@ func (t *remoteRepoTestSuite) TestUbuntuStoreRepositoryDetails(c *C) { c.Check(result.Channel, Equals, "edge") c.Check(result.Description(), Equals, "This is a simple hello world example.") c.Check(result.Summary(), Equals, "The 'hello-world' of snaps") + c.Check(result.License, Equals, "MIT/X/Expat License") c.Assert(result.Prices, DeepEquals, map[string]float64{"EUR": 0.99, "USD": 1.23}) c.Check(result.MustBuy, Equals, true) @@ -933,7 +935,7 @@ func (t *remoteRepoTestSuite) TestStructFields(c *C) { } /* acquired via: -curl -s -H "accept: application/hal+json" -H "X-Ubuntu-Release: 16" -H "X-Ubuntu-Device-Channel: edge" -H "X-Ubuntu-Wire-Protocol: 1" -H "X-Ubuntu-Architecture: amd64" 'https://search.apps.ubuntu.com/api/v1/search?fields=anon_download_url%2Carchitecture%2Cchannel%2Cdownload_sha512%2Csummary%2Cdescription%2Cbinary_filesize%2Cdownload_url%2Cicon_url%2Clast_updated%2Cpackage_name%2Cprices%2Cpublisher%2Cratings_average%2Crevision%2Csnap_id%2Csupport_url%2Ctitle%2Ccontent%2Cversion%2Corigin&q=hello' | python -m json.tool | xsel -b +curl -s -H "accept: application/hal+json" -H "X-Ubuntu-Release: 16" -H "X-Ubuntu-Device-Channel: edge" -H "X-Ubuntu-Wire-Protocol: 1" -H "X-Ubuntu-Architecture: amd64" 'https://search.apps.ubuntu.com/api/v1/search?fields=anon_download_url%2Carchitecture%2Cchannel%2Cdownload_sha512%2Csummary%2Cdescription%2Cbinary_filesize%2Cdownload_url%2Cicon_url%2Clast_updated%2Clicense%2Cpackage_name%2Cprices%2Cpublisher%2Cratings_average%2Crevision%2Csnap_id%2Csupport_url%2Ctitle%2Ccontent%2Cversion%2Corigin&q=hello' | python -m json.tool | xsel -b */ const MockSearchJSON = `{ "_embedded": { @@ -956,6 +958,7 @@ const MockSearchJSON = `{ "download_url": "https://public.apps.ubuntu.com/download-snap/buPKUD3TKqCOgLEjjHx5kSiCpIs5cMuQ_25.snap", "icon_url": "https://myapps.developer.ubuntu.com/site_media/appmedia/2015/03/hello.svg_NZLfWbh.png", "last_updated": "2016-04-19T19:50:50.435291Z", + "license": "GNU GPL v3", "origin": "canonical", "package_name": "hello-world", "prices": {"EUR": 2.99, "USD": 3.49}, @@ -1218,7 +1221,7 @@ func (t *remoteRepoTestSuite) TestUbuntuStoreFindAuthFailed(c *C) { /* acquired via: (against production "hello-world") -$ curl -s --data-binary '{"snaps":[{"snap_id":"buPKUD3TKqCOgLEjjHx5kSiCpIs5cMuQ","channel":"stable","revision":25,"epoch":"0","confinement":"strict"}],"fields":["anon_download_url","architecture","channel","download_sha512","summary","description","binary_filesize","download_url","icon_url","last_updated","package_name","prices","publisher","ratings_average","revision","snap_id","support_url","title","content","version","origin","developer_id","private","confinement"]}' -H 'content-type: application/json' -H 'X-Ubuntu-Release: 16' -H 'X-Ubuntu-Wire-Protocol: 1' -H "accept: application/hal+json" https://search.apps.ubuntu.com/api/v1/snaps/metadata | python3 -m json.tool --sort-keys | xsel -b +$ curl -s --data-binary '{"snaps":[{"snap_id":"buPKUD3TKqCOgLEjjHx5kSiCpIs5cMuQ","channel":"stable","revision":25,"epoch":"0","confinement":"strict"}],"fields":["anon_download_url","architecture","channel","download_sha512","summary","description","binary_filesize","download_url","icon_url","last_updated","license","package_name","prices","publisher","ratings_average","revision","snap_id","support_url","title","content","version","origin","developer_id","private","confinement"]}' -H 'content-type: application/json' -H 'X-Ubuntu-Release: 16' -H 'X-Ubuntu-Wire-Protocol: 1' -H "accept: application/hal+json" https://search.apps.ubuntu.com/api/v1/snaps/metadata | python3 -m json.tool --sort-keys | xsel -b */ var MockUpdatesJSON = ` { @@ -1244,6 +1247,7 @@ var MockUpdatesJSON = ` "download_url": "https://public.apps.ubuntu.com/download-snap/buPKUD3TKqCOgLEjjHx5kSiCpIs5cMuQ_26.snap", "icon_url": "https://myapps.developer.ubuntu.com/site_media/appmedia/2015/03/hello.svg_NZLfWbh.png", "last_updated": "2016-05-31T07:02:32.586839Z", + "license": "MIT/X/Expat License", "origin": "canonical", "package_name": "hello-world", "prices": {}, -- 2.9.3