storage: add GET endpoint to generate a recovery key
Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
This commit is contained in:
parent
dd620b40b3
commit
67d22a67a2
|
@ -331,6 +331,10 @@ class API:
|
||||||
def GET() -> List[Disk]:
|
def GET() -> List[Disk]:
|
||||||
...
|
...
|
||||||
|
|
||||||
|
class generate_recovery_key:
|
||||||
|
def GET() -> str:
|
||||||
|
...
|
||||||
|
|
||||||
class v2:
|
class v2:
|
||||||
def GET(
|
def GET(
|
||||||
wait: bool = False,
|
wait: bool = False,
|
||||||
|
|
|
@ -22,6 +22,7 @@ import math
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
import platform
|
import platform
|
||||||
|
import secrets
|
||||||
import tempfile
|
import tempfile
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from typing import List, Optional, Set, Tuple, Union
|
from typing import List, Optional, Set, Tuple, Union
|
||||||
|
@ -2047,3 +2048,10 @@ class FilesystemModel(object):
|
||||||
if self.reset_partition is not None:
|
if self.reset_partition is not None:
|
||||||
during.add("efibootmgr")
|
during.add("efibootmgr")
|
||||||
return (before, during)
|
return (before, during)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def generate_recovery_key() -> str:
|
||||||
|
"""Return a new recovery key suitable for LUKS encryption. The key will
|
||||||
|
consist of 48 decimal digits."""
|
||||||
|
digits = 48
|
||||||
|
return str(secrets.randbelow(10**digits)).zfill(digits)
|
||||||
|
|
|
@ -932,6 +932,9 @@ class FilesystemController(SubiquityController, FilesystemManipulator):
|
||||||
install_minimum_size=minsize,
|
install_minimum_size=minsize,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def generate_recovery_key_GET(self) -> str:
|
||||||
|
return self.model.generate_recovery_key()
|
||||||
|
|
||||||
async def v2_GET(
|
async def v2_GET(
|
||||||
self,
|
self,
|
||||||
wait: bool = False,
|
wait: bool = False,
|
||||||
|
|
Loading…
Reference in New Issue