ubuntu-pro: add auto_enabled property for services

The JSON returned by uaclient for a status request contains the
auto_enabled property for each service. This property tells whether a
given service is enabled automatically when `ua attach` is done. We will
need this information going forward so we now include it in the success
response to /ubuntu_pro/check_token:

  {
    "status": "VALID_TOKEN",
    "services": [
      {
        "name": "esm-infra",
        "description": "UA Infra: Extended Security Maintenance (ESM)",
        "auto_enabled": true
      },
      {
        "name": "fips",
        "description": "NIST-certified core packages",
        "auto_enabled": false
      }
    ]
  }

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
This commit is contained in:
Olivier Gayot 2022-06-13 15:45:28 +02:00
parent 039f5d45c0
commit d67c71e0ba
3 changed files with 6 additions and 0 deletions

View File

@ -460,6 +460,7 @@ class UbuntuProCheckTokenStatus(enum.Enum):
class UbuntuProService:
name: str
description: str
auto_enabled: bool
@attr.s(auto_attribs=True)

View File

@ -191,18 +191,22 @@ class TestUAInterface(unittest.TestCase):
self.assertIn(UbuntuProService(
name="esm-infra",
description="UA Infra: Extended Security Maintenance (ESM)",
auto_enabled=True,
), services)
self.assertIn(UbuntuProService(
name="fips",
description="NIST-certified core packages",
auto_enabled=False,
), services)
self.assertNotIn(UbuntuProService(
name="esm-apps",
description="UA Apps: Extended Security Maintenance (ESM)",
auto_enabled=True,
), services)
self.assertNotIn(UbuntuProService(
name="cis",
description="Center for Internet Security Audit Tools",
auto_enabled=False,
), services)
# Test with "Z" suffix for the expiration date.

View File

@ -174,6 +174,7 @@ class UAInterface:
return UbuntuProService(
name=service["name"],
description=service["description"],
auto_enabled=service["auto_enabled"] == "yes",
)
activable_services: List[UbuntuProService] = []