Handle macaroon-authorization-required error response

Bug #1930592 reported by Natalia Bidart
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Snapcraft
Triaged
Undecided
Unassigned

Bug Description

When issuing snapcraft whoami on a system without credentials or with expired ones, as a user I get an error instead of a prompt to re-authenticate:

nessita@dali:~$ snapcraft whoami
Store Error: whoami failed.

nessita@dali:~$ export SNAPCRAFT_ENABLE_DEVELOPER_DEBUG=1

nessita@dali:~$ snapcraft whoami
Starting snapcraft 4.8 from /snap/snapcraft/6512/lib/python3.6/site-packages/snapcraft/cli.
configure_requests_ca: using '/etc/ssl/certs/ca-certificates.crt' for certificate verification
Candid forced: False. Candid crendendials: False.
Calling https://dashboard.snapcraft.io/api/v2/tokens/whoami with params None and headers {'Content-Type': 'application/json', 'Accept': 'application/json', 'Authorization': None, 'User-Agent': 'snapcraft/4.8 Ubuntu/20.04 (amd64)'}
Store error response: {'_content': b'{"error-list": [{"message": "The request is missing an Authorization header field containing a valid macaroon", "code": "macaroon-authorization-required", "extra": {"realm": "Developer Portal"}}]}', '_content_consumed': True, '_next': None, 'status_code': 401, 'headers': {'Date': 'Wed, 02 Jun 2021 13:32:10 GMT', 'Server': 'gunicorn/19.7.0', 'Content-Type': 'application/json', 'WWW-Authenticate': 'Macaroon realm="Developer Portal"', 'Expires': 'Wed, 02 Jun 2021 13:32:10 GMT', 'Cache-Control': 'max-age=0, no-cache, no-store, must-revalidate', 'X-View-Name': 'api-tokens-whoami', 'Vary': 'Accept-Language,Cookie', 'Content-Language': 'en', 'Content-Length': '196', 'X-VCS-Revision': 'b143b7791b', 'X-Request-Id': 'YLeIWn8AAQEAADi5H34AAAPd1', 'X-Cache': 'MISS from juju-08138e-prod-scasnap-xenial-4', 'X-Cache-Lookup': 'MISS from juju-08138e-prod-scasnap-xenial-4:3128', 'Via': '1.1 juju-08138e-prod-scasnap-xenial-4 (squid/3.5.12)', 'Strict-Transport-Security': 'max-age=2592000', 'Keep-Alive': 'timeout=5, max=100', 'Connection': 'Keep-Alive'}, 'raw': <urllib3.response.HTTPResponse object at 0x7f8439ce8f60>, 'url': 'https://dashboard.snapcraft.io/api/v2/tokens/whoami', 'encoding': 'utf-8', 'history': [], 'reason': 'Unauthorized', 'cookies': <RequestsCookieJar[]>, 'elapsed': datetime.timedelta(0, 0, 932062), 'request': <PreparedRequest [GET]>, 'connection': <requests.adapters.HTTPAdapter object at 0x7f8439ce82b0>}
Sorry, an error occurred in Snapcraft:
Store Error: whoami failed.
Traceback (most recent call last):
  File "/snap/snapcraft/6512/bin/snapcraft", line 33, in <module>
    sys.exit(load_entry_point('snapcraft==4.8', 'console_scripts', 'snapcraft')())
  File "/snap/snapcraft/6512/lib/python3.6/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/snap/snapcraft/6512/lib/python3.6/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/snap/snapcraft/6512/lib/python3.6/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/snap/snapcraft/6512/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/snap/snapcraft/6512/lib/python3.6/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/snap/snapcraft/6512/lib/python3.6/site-packages/snapcraft/cli/store.py", line 840, in whoami
    account = StoreClientCLI().whoami().account
  File "/snap/snapcraft/6512/lib/python3.6/site-packages/snapcraft/storeapi/_store_client.py", line 97, in whoami
    return self.dashboard.whoami()
  File "/snap/snapcraft/6512/lib/python3.6/site-packages/snapcraft/storeapi/_dashboard_api.py", line 367, in whoami
    raise errors.GeneralStoreError(message="whoami failed.", response=response)
snapcraft.storeapi.errors.GeneralStoreError: Store Error: whoami failed.
You can find the traceback in file '/tmp/tmpsgqh5y34/trace.txt'.

Tags: craft-339
Chris Patterson (cjp256)
Changed in snapcraft:
status: New → Confirmed
tags: added: craft-339
Changed in snapcraft:
status: Confirmed → Triaged
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.