feat: integrate MinIO-backed user filesystem
This commit is contained in:
@ -46,6 +46,21 @@ def _normalize_record(record: dict[str, Any]) -> dict[str, Any]:
|
||||
return normalized
|
||||
|
||||
|
||||
def read_registry(path: Path) -> dict[str, Any]:
|
||||
if not path.exists():
|
||||
return _default_data()
|
||||
try:
|
||||
data = json.loads(path.read_text(encoding="utf-8"))
|
||||
except json.JSONDecodeError:
|
||||
return _default_data()
|
||||
if not isinstance(data, dict):
|
||||
return _default_data()
|
||||
if not isinstance(data.get("instances"), list):
|
||||
data["instances"] = []
|
||||
data["instances"] = [_normalize_record(item) for item in data["instances"] if isinstance(item, dict)]
|
||||
return data
|
||||
|
||||
|
||||
@contextmanager
|
||||
def locked_registry(path: Path):
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
@ -118,8 +133,8 @@ def _get_record(
|
||||
|
||||
def cmd_list(args: argparse.Namespace) -> int:
|
||||
path = Path(args.registry).expanduser()
|
||||
with locked_registry(path) as data:
|
||||
instances = list(data["instances"])
|
||||
data = read_registry(path)
|
||||
instances = list(data["instances"])
|
||||
if args.json:
|
||||
json.dump({"instances": instances}, sys.stdout, indent=2, ensure_ascii=False)
|
||||
sys.stdout.write("\n")
|
||||
@ -143,15 +158,15 @@ def cmd_list(args: argparse.Namespace) -> int:
|
||||
|
||||
def cmd_get(args: argparse.Namespace) -> int:
|
||||
path = Path(args.registry).expanduser()
|
||||
with locked_registry(path) as data:
|
||||
record = _get_record(
|
||||
data,
|
||||
instance_id=args.instance_id,
|
||||
slug=args.slug,
|
||||
container_name=args.container_name,
|
||||
username=args.username,
|
||||
instance_host=args.instance_host,
|
||||
)
|
||||
data = read_registry(path)
|
||||
record = _get_record(
|
||||
data,
|
||||
instance_id=args.instance_id,
|
||||
slug=args.slug,
|
||||
container_name=args.container_name,
|
||||
username=args.username,
|
||||
instance_host=args.instance_host,
|
||||
)
|
||||
if record is None:
|
||||
return 1
|
||||
json.dump(record, sys.stdout, indent=2, ensure_ascii=False)
|
||||
|
||||
Reference in New Issue
Block a user