Repository: canonical/snapcraft

Issue:
Make 'price' field optional (or remove it)
### What needs to get done

From what I can see, the snapcraft legacy client, in `snapcraft_legacy/_store.py`, requires that the 'price' field be present in the response from the dashboard's `/dev/api/account` endpoint:
```
def list_registered():
    account_info = StoreClientCLI().get_account_information()
    snaps = [
        (
            name,
            info["since"],
            "private" if info["private"] else "public",
            info["price"] or "-",  # would lead to a KeyError if 'price' is removed
            "-",
        )
        for name, info in account_info["snaps"].get(DEFAULT_SERIES, {}).items()
        # Presenting only approved snap registrations, which means name
        # disputes will be displayed/sorted some other way.
        if info["status"] == "Approved"
    ]
```

Changing the line from `info["price"] or "-"` to `info.get("price") or "-"` should take care of this. Adding a test for a missing 'price' field response from the dashboard would also be great. 

Another option would be to remove this field entirely, but I'm not sure about this with regards to backwards-compatibility considerations of legacy client.

### Why it needs to get done

The aforementioned API currently always returns 'price' as `null` since the feature is deprecated. This change will enable a removal path for the 'price' field altogether from the Dashboard API endpoint `/dev/api/account` in the future.


Discussion:
Do the fix for `snapcraft_legacy` and also check whether we need to fix `craft-store`

Resolving patch:
diff --git a/snapcraft_legacy/__init__.py b/snapcraft_legacy/__init__.py
--- a/snapcraft_legacy/__init__.py
+++ b/snapcraft_legacy/__init__.py
@@ -355,7 +355,6 @@ def _get_version():
     download,
     gated,
     list_keys,
-    list_registered,
     login,
     register,
     register_key,
diff --git a/snapcraft_legacy/_store.py b/snapcraft_legacy/_store.py
--- a/snapcraft_legacy/_store.py
+++ b/snapcraft_legacy/_store.py
@@ -17,7 +17,6 @@
 import contextlib
 import json
 import logging
-import operator
 import os
 import re
 import subprocess
@@ -369,34 +368,6 @@ def register(
         super().register(snap_name=snap_name, is_private=is_private, store_id=store_id)
 
 
-def list_registered():
-    account_info = StoreClientCLI().get_account_information()
-    snaps = [
-        (
-            name,
-            info["since"],
-            "private" if info["private"] else "public",
-            info["price"] or "-",
-            "-",
-        )
-        for name, info in account_info["snaps"].get(DEFAULT_SERIES, {}).items()
-        # Presenting only approved snap registrations, which means name
-        # disputes will be displayed/sorted some other way.
-        if info["status"] == "Approved"
-    ]
-
-    if not snaps:
-        echo.warning("There are no registered snaps.")
-        return
-
-    tabulated_snaps = tabulate(
-        sorted(snaps, key=operator.itemgetter(0)),
-        headers=["Name", "Since", "Visibility", "Price", "Notes"],
-        tablefmt="plain",
-    )
-    print(tabulated_snaps)
-
-
 def _get_usable_keys(name=None):
     snap_path = get_host_tool_path(command_name="snap", package_name="snapd")
     keys = json.loads(


Test patch:
diff --git a/tests/legacy/fake_servers/api.py b/tests/legacy/fake_servers/api.py
--- a/tests/legacy/fake_servers/api.py
+++ b/tests/legacy/fake_servers/api.py
@@ -1119,63 +1119,54 @@ def account(self, request):
                 "snap-id": "snap-id",
                 "status": "Approved",
                 "private": False,
-                "price": None,
                 "since": "2016-12-12T01:01:01Z",
             },
             "test-snap-with-no-validations": {
                 "snap-id": "test-snap-id-with-no-validations",
                 "status": "Approved",
                 "private": False,
-                "price": None,
                 "since": "2016-12-12T01:01:01Z",
             },
             "test-snap-with-dev": {
                 "snap-id": "test-snap-id-with-dev",
                 "status": "Approved",
                 "private": False,
-                "price": None,
                 "since": "2016-12-12T01:01:01Z",
             },
             "core": {
                 "snap-id": "good",
                 "status": "Approved",
                 "private": False,
-                "price": None,
                 "since": "2016-12-12T01:01:01Z",
             },
             "core-no-dev": {
                 "snap-id": "no-dev",
                 "status": "Approved",
                 "private": False,
-                "price": None,
                 "since": "2016-12-12T01:01:01Z",
             },
             "badrequest": {
                 "snap-id": "badrequest",
                 "status": "Approved",
                 "private": False,
-                "price": None,
                 "since": "2016-12-12T01:01:01Z",
             },
             "revoked": {
                 "snap-id": "revoked",
                 "status": "Approved",
                 "private": False,
-                "price": None,
                 "since": "2016-12-12T01:01:01Z",
             },
             "no-revoked": {
                 "snap-id": "no-revoked",
                 "status": "Approved",
                 "private": False,
-                "price": None,
                 "since": "2016-12-12T01:01:01Z",
             },
             "no-id": {
                 "snap-id": None,
                 "status": "Approved",
                 "private": False,
-                "price": None,
                 "since": "2016-12-12T01:01:01Z",
             },
         }
@@ -1185,7 +1176,6 @@ def account(self, request):
                     "snap-id": snap_data["snap_id"],
                     "status": "Approved",
                     "private": snap_data["private"],
-                    "price": None,
                     "since": "2016-12-12T01:01:01Z",
                 }
                 for name, snap_data in self.registered_names.items()
diff --git a/tests/legacy/unit/store/test_store_client.py b/tests/legacy/unit/store/test_store_client.py
--- a/tests/legacy/unit/store/test_store_client.py
+++ b/tests/legacy/unit/store/test_store_client.py
@@ -185,53 +185,45 @@ def test_get_account_information_successfully(self):
                                 "snap-id": "snap-id",
                                 "status": "Approved",
                                 "private": False,
-                                "price": None,
                                 "since": "2016-12-12T01:01:01Z",
                             },
                             "core": {
                                 "snap-id": "good",
                                 "status": "Approved",
                                 "private": False,
-                                "price": None,
                                 "since": "2016-12-12T01:01:01Z",
                             },
                             "core-no-dev": {
                                 "snap-id": "no-dev",
                                 "status": "Approved",
                                 "private": False,
-                                "price": None,
                                 "since": "2016-12-12T01:01:01Z",
                             },
                             "badrequest": {
                                 "snap-id": "badrequest",
                                 "status": "Approved",
                                 "private": False,
-                                "price": None,
                                 "since": "2016-12-12T01:01:01Z",
                             },
                             "no-revoked": {
                                 "snap-id": "no-revoked",
                                 "status": "Approved",
                                 "private": False,
-                                "price": None,
                                 "since": "2016-12-12T01:01:01Z",
                             },
                             "revoked": {
                                 "snap-id": "revoked",
                                 "status": "Approved",
                                 "private": False,
-                                "price": None,
                                 "since": "2016-12-12T01:01:01Z",
                             },
                             "test-snap-with-dev": {
-                                "price": None,
                                 "private": False,
                                 "since": "2016-12-12T01:01:01Z",
                                 "snap-id": "test-snap-id-with-dev",
                                 "status": "Approved",
                             },
                             "test-snap-with-no-validations": {
-                                "price": None,
                                 "private": False,
                                 "since": "2016-12-12T01:01:01Z",
                                 "snap-id": "test-snap-id-with-no-validations",
@@ -241,7 +233,6 @@ def test_get_account_information_successfully(self):
                                 "snap-id": None,
                                 "status": "Approved",
                                 "private": False,
-                                "price": None,
                                 "since": "2016-12-12T01:01:01Z",
                             },
                         }