39 Commits

Author SHA1 Message Date
Santiago Bautista
3c95be0fc5 fix some typos 2020-09-27 23:38:17 +02:00
Pawel Stolowski
36c0d677b2 store: support for search API v2
* Support for search API v2.

* Small renames. Avoid extra search.Private && user check in findV1 code (thanks pedronis).

* Check Snap-Store-Version when deciding about search v1 fallback.

* Added unit test for expected search fields with v2.

* Re-organized some unit tests to use apiV1 flag to drive test logic. Add extra checks to ensure v2 api was hit.

* Return an error if scope is anything but "wide" or empty string.

* Added extra test for 404 handling if store is new enough.

* Also request store-url, website and common-ids fields (now supported by the store).

* Update the test to check common ids with v2.

* Handle error-list with search v2. Remove obsolete XXX comments related to common-ids (thanks pedronis).

* Add a comment.

* Always decode the response if status is 200/201

* Remove unneeded copyNonZeroFrom (thanks pedronis).

* Updated the comments.

* Restore two v1 test checks (made them conditional instead of commented out) (thanks pedronis).

* Remove duplicated checks (thanks pedronis).

* Rename 500 tests (once -> Once). Removed unintended change to buy test related to content-type (thanks pedronis).

* Rename search v2 endpoint from /search to /find.

* Rename search v2-related names to find, e.g. searchV2Path -> findPath.

* Clarify and rename 500 tests.

* Bump store version check for find v1 fallback.

* Give the permanent 500 tests more elaborate names.

* Fix spelling.
2020-03-30 20:29:29 +02:00
John R. Lenton
6748f132ce daemon, store: better expose single action errors
When a snap action (that is, a POST to the store's refresh endpoint)
results in a single error for a single operation on a single snap, the
current code raises it as an InternalError.

This means a download of an unknown snap becomes an internal error; a
download of a snap from the wrong channel becomes an internal error,
etc.  This relatively minor issue becomes user-visible wackiness with
the switch to download being via snapd (and using the mentioned
endpoint).

This change fixes that, such that _if_ it's a single operation on a
single snap returning a single error, then the error raised is the
internal one.

More work could be done to coalesce things such that if it's the same
error for multiple snaps it's handled differently; this would simplify
the "no refreshes found" logging and reporting, I suspect (but haven't
checked).
2020-01-31 11:25:24 +00:00
Samuele Pedroni
fd20061bc4 move channel parsing to snap/channel 2019-08-21 17:12:27 +02:00
John R. Lenton
a38e28fd70 store: rename variables and add comments to improve readability
(thanks to @mvo5 for the review).
2018-08-02 10:47:03 +01:00
John R. Lenton
463bbf225a store: be less verbose in the common refresh case of "no updates"
Before this change, every snap refresh would log, even without DEBUG,
something like:

    Jul 17 08:03:16 fleet snapd[4819]: 2018/07/17 08:03:16.096014 storehelpers.go:398: cannot refresh:
    Jul 17 08:03:16 fleet snapd[4819]: snap "bofh": snap has no updates available
    Jul 17 08:03:16 fleet snapd[4819]: snap "interdenominational-counterintelligences": snap has no updates available
    Jul 17 08:03:16 fleet snapd[4819]: snap "shellcheck": snap has no updates available
    Jul 17 08:03:16 fleet snapd[4819]: snap "unifonter": snap has no updates available
    Jul 17 08:03:16 fleet snapd[4819]: snap "hello-world": snap has no updates available
    Jul 17 08:03:16 fleet snapd[4819]: snap "wethr": snap has no updates available
    Jul 17 08:03:16 fleet snapd[4819]: snap "cavestory": snap has no updates available
    Jul 17 08:03:16 fleet snapd[4819]: snap "nethack": snap has no updates available
    Jul 17 08:03:16 fleet snapd[4819]: snap "tmnationsforever": snap has no updates available
    Jul 17 08:03:16 fleet snapd[4819]: snap "flare-rpg": snap has no updates available
    Jul 17 08:03:16 fleet snapd[4819]: snap "xbill-xaw": snap has no updates available
    Jul 17 08:03:16 fleet snapd[4819]: snap "quake-shareware": snap has no updates available
    Jul 17 08:03:16 fleet snapd[4819]: snap "telegram-desktop": snap has no updates available
    Jul 17 08:03:16 fleet snapd[4819]: snap "bash-shell-rpg": snap has no updates available
    Jul 17 08:03:16 fleet snapd[4819]: snap "go": snap has no updates available
    Jul 17 08:03:16 fleet snapd[4819]: snap "shattered-pixel-dungeon": snap has no updates available
    Jul 17 08:03:16 fleet snapd[4819]: snap "xonotic": snap has no updates available
    Jul 17 08:03:16 fleet snapd[4819]: snap "youtube-dl-casept": snap has no updates available
    Jul 17 08:03:16 fleet snapd[4819]: snap "mosaic": snap has no updates available
    Jul 17 08:03:16 fleet snapd[4819]: snap "spotify": snap has no updates available
    Jul 17 08:03:16 fleet snapd[4819]: snap "firefox": snap has no updates available
    Jul 17 08:03:16 fleet snapd[4819]: snap "http": snap has no updates available
    Jul 17 08:03:16 fleet snapd[4819]: snap "minecraft": snap has no updates available
    Jul 17 08:03:16 fleet snapd[4819]: snap "vlc": snap has no updates available
    Jul 17 08:03:16 fleet snapd[4819]: snap "test-snapd-tools": snap has no updates available

this change turns things around, and instead you'll get

    Jul 17 16:02:49 fleet snapd[5123]: 2018/07/19 16:02:49.310941 storehelpers.go:398: cannot refresh: snap has no updates available: "atom", "bash-shell-rpg", "cavestory", "core", "firefox", "flare-rpg", "gnome-3-26-1604", "gnome-calculator", "go", "gtk-common-themes", "hello-world", "http", "interdenominational-counterintelligences", "minecraft", "mosaic", "nethack", "quake-shareware", "shattered-pixel-dungeon", "shellcheck", "spotify", "telegram-desktop", "test-snapd-tools", "tmnationsforever", "unifonter", "vlc", "wethr", "xbill-xaw", "xonotic", "youtube-dl-casept"

which is IMHO better.

It still goes multi-line if there's more than one "kind" of error
(still reversed, “error message: quoted list of snaps”, though).
2018-07-19 16:16:52 +01:00
Samuele Pedroni
22e8389ba2 many: use extra "releases" information on store "revision-not-found" errors to produce better errors (#5403)
This uses the new extra "releases" information on store "revision-not-found" errors to produce better errors when a revision is not available for the given channel or architecture.

The extra information when available is passed back over the snapd API using two new error kinds:

* snap-channel-not-available
* snap-architecture-not-available
2018-07-04 13:19:25 +02:00
John R. Lenton
65417d0f38 cmd/snap, image, store: address feedback (thank you @pedronis) 2018-06-12 09:30:01 +01:00
John R. Lenton
df41ccbb81 store, image: have 'snap download' use v2/refresh action=download
This moves 'snap download' (i.e. image/) to use the v2 store api, with
the ad-hoc 'download' action on the refresh endpoint.
2018-06-11 12:07:13 +01:00
Samuele Pedroni
d10562ed3b many: use the new install/refresh API by switching snapstate to use store.SnapAction (#4900)
This switches snapd to use the new /v2/snaps/refresh store API to handle both install and refreshes.
2018-04-06 14:03:35 +02:00
Samuele Pedroni
1dee38267a store: add Store.SnapAction to support the new install/refresh API endpoint
squashing #4896 and #4771
2018-03-28 22:41:57 +02:00
Michael Vogt
648504e7f3 daemon: return "bad-query" error kind for store.ErrBadQuery
This allows clients to distinguish bad queries and to do something
useful in their UI. This was requested in bug:
https://bugs.launchpad.net/snapd/+bug/1717573

This also removes the store.ErrEmptyQuery which is never created
in the current code.
2018-01-02 10:46:16 +01:00
James Henstridge
8ce7c5d474 store: forward on INVALID_CREDENTIALS error as ErrInvalidCredentials 2017-10-19 19:12:33 +08:00
Samuele Pedroni
97e3ef21a3 many: introduce asserts.NotFoundError replacing both ErrNotFound and store.AssertionNotFoundError (#3893)
This converts the singleton asserts.ErrNotFound to a richer asserts.NotFoundError struct carrying Type and optionally PrimaryKey, similar to store.AssertionNotFoundError which then gets folded with this.

This means code doesn't have to worry anymore which is which or to convert between the two. And when possible there is more information around. Though Backstores can continue to return minimal information (Type but not Headers in the new error).

A helper asserts.IsNotFound is also added to cover the simple old ==/!= asserts.ErrNotFound needs.

This also fixes/adjust some error handling to usually not repeat the richer information twice.
2017-09-12 16:34:53 +02:00
John R. Lenton
6ca84e3228 many: slight improvement of some snap error messaging
There's still *so* much to do in this area. Still, in this branch:
* added an error kind "snap-local" for when the store returns
  ErrLocalSnap
* added an error kind "snap-not-found", for 404s
* dropped the store.NoUpdateAvailableError type in favour of
  store.ErrNoUpdateAvailable; the snap name contained in the error
  type could be wrong or misleading, and the client alreayd knows the
  name of the snap.
* moved cmd/snap's clientErrorToCmdMessage to errorToCmdMessage, and
  put the type checking in the function itself, to avoid repeating it
  for every caller. Still some more work to be done there before I'm
  happy with that.
* made cmd/snap's errorToCmdMessage take a *client.SnapOptions, which
  it can then use to better explain SnapNotFound.
* lastly, errorToCmdMessage handles snap-local.
2017-06-05 12:38:44 +01:00
Samuele Pedroni
4705c0331d many: stop "snap refresh $x --channel invalid" from working
This splits LookupRefresh out of store's ListRefresh, and makes
snapstate's Update use the new one. The difference is that
LookupRefresh can tell the difference between "this snap does not
exist [in the channel you asked about]" and "there are no updates for
this snap"; ListRefresh confounds the two situations, leading to some
hilarity.

Also includes some incidental refactoring of ListRefresh in order to
avoid DRY.
2017-05-31 19:25:07 +02:00
John R. Lenton
df648c101f store: address review feedback
The neat thing about this one is probably that the new (private) store
method refreshForCandidate, called by both LookupRefresh and
ListRefresh to actually contact the store, has been made mockable. The
tests for LookupRefresh are done using this, and I'll be rewriting the
ListRefresh ones to do similarly once I'm happy with the coverage for
the helper funcs (which this branch also adds).
2017-05-30 16:10:17 +01:00
John R. Lenton
c5f08071ff many: error types should be called FooError, not ErrFoo.
ErrFoo is for error _values_.
2017-05-25 16:56:43 +01:00
John R. Lenton
c182f922ea many: stop "snap refresh $x --channel invalid" from working.
This splits LookupRefrsh out of store's ListRefresh, and makes
snapstate's Update use the new one. The difference is that
LookupRefresh can tell the difference between "this snap does not
exist [in the channel you asked about]" and "there are no updates for
this snap"; ListRefresh confounds the two situations, leading to some
hilarity.

Also includes some incidental refactoring of ListRefresh in order to
avoid DRY.
2017-05-25 11:23:07 +01:00
John R. Lenton
2e518deeb6 cmd/snap/error.go: drop case that is the same as default
store: s/stringish/stringList/g
2017-05-08 20:56:52 +01:00
John R. Lenton
de1e11f611 store, daemon, client, cmd/snap: handle PASSWORD_POLICY_ERROR code errors from sso, which are slightly different 2017-05-05 20:00:00 +01:00
Pete Woods
19bab0640e store: send correct JSON type of string for expected payment amount (#2103)
- The new store API takes the price as a string, so convert the float price.
- We avoid taking a string for the price on the snapd API, as the price is still a float in the store index API, and the existing properties on snaps from /v2/find, etc.
- Also handle one of the expected HTTP codes, 402, which appears to mean payment failed for unspecified reason.
- Refactor store.Buy tests into a table.
2016-10-06 06:49:41 -03:00
Pete Woods
1e02e614db Fix the camel-casing used for the Go types 2016-09-23 10:33:56 +01:00
Pete Woods
4e5e8f1578 respond to Gustavo's review comments
- Rename ErrNoPaymentMethod -> ErrNoPaymentMethods.
- storeErrors now just reports the first error.
2016-09-21 09:38:32 +01:00
Pete Woods
be5ecac71f respond to Gustavo's review comments
- Fix copy paste error.
- Remove the word "valid" from errors.
- Make storeErrors implement the Go error interface.
- Simply return the whole &errors list from ReadyToBuy.
- Compose the ReadyToBuy tests into a single test, with tabular input.
2016-09-20 13:15:17 +01:00