Passing --store has weird syntax/requirements and user-facing error is not informative

Bug #1899033 reported by Daniel Manrique
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Snapcraft
Incomplete
Medium
Sergio Schvezov

Bug Description

Trying to register a snap on a brand store for which I am a publisher (I have obfuscated the store ID and snap names).

$ snap run snapcraft register --store ​gltNg0wohVae8aY4 --yes does-this-look-correct
Registering does-this-look-correct.
Registration failed.

Let's look at what the HTTP dialog shows (macaroon elided). First problem: this requires hacking snapcraft as there doesn't seem to be a switch to enable this verbose debugging (SNAPCRAFT_ENABLE_DEVELOPER_DEBUG=yes --debug don't do the trick).

$ cp /snap/snapcraft/current/bin/snapcraft /tmp/snapcraft
$ sed -i '5iimport http.client\nhttp.client.HTTPConnection.debuglevel = 1\n' /tmp/snapcraft
$ sudo mount -o bind /tmp/snapcraft /snap/snapcraft/current/bin/snapcraft

$ snap run snapcraft register --store ​gltNg0wohVae8aY4 --yes does-this-look-correct
Registering does-this-look-correct.
send: b'POST /dev/api/register-name/ HTTP/1.1\r\nHost: dashboard.snapcraft.io\r\nUser-Agent: snapcraft/4.3 Ubuntu/18.04 (amd64)\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nAuthorization: Macaroon root=<my root macaroon>, discharge=<my discharge>\r\nContent-Type: application/json\r\nContent-Length: 130\r\n\r\n'
send: b'{"snap_name": "does-this-look-correct", "is_private": false, "series": "16", "store": "\\u200bgltNg0wohVae8aY4"}'
reply: 'HTTP/1.1 400 Bad Request\r\n'
header: Date: Thu, 08 Oct 2020 13:13:31 GMT
header: Server: gunicorn/19.7.0
header: Content-Type: application/json
<boring headers>
header: Connection: close
header: Transfer-Encoding: chunked
Registration failed.

Second problem: Snapcraft's response on a 400 reply from the store is too terse to be useful.

OK, so looking at the post payload, the store name is borked:

"store": "\\u200bgltNg0wohVae8aY4"

Looks like snapcraft is not properly parsing the --store command-line parameter value. Let's try this:

$ snap run snapcraft register --store=gltNg0wohVae8aY4 --yes does-this-look-correct
Registering does-this-look-correct.
send: b'POST /dev/api/register-name/ HTTP/1.1\r\nHost: dashboard.snapcraft.io\r\nUser-Agent: snapcraft/4.3 Ubuntu/18.04 (amd64)\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nAuthorization: Macaroon root=<root>, discharge=<disch>\r\nContent-Type: application/json\r\nContent-Length: 124\r\n\r\n'
send: b'{"snap_name": "does-this-look-correct", "is_private": false, "series": "16", "store": "gltNg0wohVae8aY4"}'
reply: 'HTTP/1.1 201 Created\r\n'
header: Date: Thu, 08 Oct 2020 13:14:35 GMT
header: Content-Language: en
header: Content-Type: application/json
header: X-VCS-Revision: 8ee7d2f
< A bunch of boring headers elided>
Congrats! You are now the publisher of 'does-this-look-correct'.

This is the third issue. It's workaroundable by using --store=, we can use that in the meanwhile but it would be great if snapcraft would properly parse command-line options.

I realize in hindsight this is an omnibug. Let me know if you'd prefer I file all 3 issues separately, I can gladly do it.

Changed in snapcraft:
importance: Undecided → Critical
assignee: nobody → Sergio Schvezov (sergiusens)
status: New → Triaged
Revision history for this message
Sergio Schvezov (sergiusens) wrote :

OK, so there is a difference between

    snap run snapcraft register --store ​gltNg0wohVae8aY4 --yes does-this-look-correct

and

    snap run snapcraft register --store gltNg0wohVae8aY4 --yes does-this-look-correct

(copy paste each and see the results).

What terminal/shell is being used to issue the commands?
Was this a copy paste from some document?

We can strip this, but maybe this is exactly what you want.
I can add a "Registering 'does-this-look-correct' on store 'gltNg0wohVae8aY4'." to make this more obvious (and would be catched early if not using --yes)

Changed in snapcraft:
importance: Critical → Medium
status: Triaged → Incomplete
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.