diff --git a/autoinstall-schema.json b/autoinstall-schema.json index 5e27b33b..0e89c79c 100644 --- a/autoinstall-schema.json +++ b/autoinstall-schema.json @@ -260,6 +260,18 @@ } ] }, + "ubuntu-advantage": { + "type": "object", + "properties": { + "token": { + "type": "string", + "minLength": 24, + "maxLength": 30, + "pattern": "^C[1-9A-HJ-NP-Za-km-z]+$", + "description": "A valid token starts with a C and is followed by 23 to 29 Base58 characters.\nSee https://pkg.go.dev/github.com/btcsuite/btcutil/base58#CheckEncode" + } + } + }, "proxy": { "type": [ "string", diff --git a/examples/autoinstall.yaml b/examples/autoinstall.yaml index 51aff9e2..4685f3b9 100644 --- a/examples/autoinstall.yaml +++ b/examples/autoinstall.yaml @@ -42,6 +42,9 @@ snaps: channel: 3.2/stable updates: all timezone: Pacific/Guam +ubuntu-advantage: + # Token that passes the basic format checking but is invalid (i.e. contains more than 16 bytes of random data) + token: C1NWcZTHLteJXGVMM6YhvHDpGrhyy7 storage: config: - {type: disk, ptable: gpt, path: /dev/vdb, wipe: superblock, preserve: false, grub_device: true, id: disk-1} diff --git a/scripts/runtests.sh b/scripts/runtests.sh index 53786239..a295b49a 100755 --- a/scripts/runtests.sh +++ b/scripts/runtests.sh @@ -173,6 +173,7 @@ python3 scripts/check-yaml-fields.py .subiquity/var/log/installer/subiquity-curt python3 scripts/check-yaml-fields.py <(python3 scripts/check-yaml-fields.py .subiquity/etc/cloud/cloud.cfg.d/99-installer.cfg datasource.None.userdata_raw) \ locale='"en_GB.UTF-8"' \ timezone='"Pacific/Guam"' \ + ubuntu_advantage.token='"C1NWcZTHLteJXGVMM6YhvHDpGrhyy7"' \ 'snap.commands=[snap install --channel=3.2/stable etcd]' grep -q 'finish: subiquity/Install/install/postinstall/install_package1: SUCCESS: installing package1' \ .subiquity/subiquity-server-debug.log diff --git a/subiquity/server/controllers/ubuntu_advantage.py b/subiquity/server/controllers/ubuntu_advantage.py index 025c10aa..c91cec47 100644 --- a/subiquity/server/controllers/ubuntu_advantage.py +++ b/subiquity/server/controllers/ubuntu_advantage.py @@ -22,6 +22,10 @@ from subiquity.server.controller import SubiquityController log = logging.getLogger("subiquity.server.controllers.ubuntu_advantage") +TOKEN_DESC = """\ +A valid token starts with a C and is followed by 23 to 29 Base58 characters. +See https://pkg.go.dev/github.com/btcsuite/btcutil/base58#CheckEncode""" + class UbuntuAdvantageController(SubiquityController): """ Represent the server-side Ubuntu Advantage controller. """ @@ -29,6 +33,33 @@ class UbuntuAdvantageController(SubiquityController): endpoint = API.ubuntu_advantage model_name = "ubuntu_advantage" + autoinstall_key = "ubuntu-advantage" + autoinstall_schema = { + "type": "object", + "properties": { + "token": { + "type": "string", + "minLength": 24, + "maxLength": 30, + "pattern": "^C[1-9A-HJ-NP-Za-km-z]+$", + "description": TOKEN_DESC, + }, + }, + } + + def load_autoinstall_data(self, data: dict) -> None: + """ Load autoinstall data and update the model. """ + if data is None: + return + self.model.token = data.get("token", "") + + def make_autoinstall(self) -> dict: + """ Return a dictionary that can be used as an autoinstall snippet for + Ubuntu Advantage. + """ + return { + "token": self.model.token + } def serialize(self) -> str: """ Save the current state of the model so it can be loaded later.