Revert "Merge pull request 'clan-cli: secrets: Add support for PGP keys with sops-nix' (#2186) from lopter/clan-core:lo-sops-nix-pgp-support into main"

This reverts commit b956b94039, reversing
changes made to b1af3d5d6d.

Reverting for now as Dave's recent change conflicts with this change.
This commit is contained in:
Jörg Thalheim
2024-10-04 17:54:17 +02:00
parent 66a94c91ae
commit d134d94a1e
11 changed files with 131 additions and 361 deletions

View File

@@ -32,7 +32,6 @@ Note: This module assumes the presence of other modules and classes such as `Cla
import dataclasses
import json
from dataclasses import dataclass, fields, is_dataclass
from enum import Enum
from pathlib import Path
from types import UnionType
from typing import (
@@ -180,31 +179,25 @@ def construct_value(
# Nested types
# list
# dict
origin = get_origin(t)
if origin is list:
if get_origin(t) is list:
if not isinstance(field_value, list):
msg = f"Expected list, got {field_value}"
raise ClanError(msg, location=f"{loc}")
return [construct_value(get_args(t)[0], item) for item in field_value]
if origin is dict and isinstance(field_value, dict):
if get_origin(t) is dict and isinstance(field_value, dict):
return {
key: construct_value(get_args(t)[1], value)
for key, value in field_value.items()
}
if origin is Literal:
if get_origin(t) is Literal:
valid_values = get_args(t)
if field_value not in valid_values:
msg = f"Expected one of {', '.join(valid_values)}, got {field_value}"
msg = f"Expected one of {valid_values}, got {field_value}"
raise ClanError(msg, location=f"{loc}")
return field_value
if origin is Enum:
if field_value not in origin.__members__:
msg = f"Expected one of {', '.join(origin.__members__)}, got {field_value}"
raise ClanError(msg, location=f"{loc}")
if origin is Annotated:
if get_origin(t) is Annotated:
(base_type,) = get_args(t)
return construct_value(base_type, field_value)

View File

@@ -2,7 +2,6 @@ import copy
import dataclasses
import pathlib
from dataclasses import MISSING
from enum import EnumType
from types import NoneType, UnionType
from typing import (
Annotated,
@@ -78,16 +77,13 @@ def type_to_dict(
if dataclasses.is_dataclass(t):
fields = dataclasses.fields(t)
properties = {}
for f in fields:
if f.name.startswith("_"):
continue
assert not isinstance(
f.type, str
), f"Expected field type to be a type, got {f.type}, Have you imported `from __future__ import annotations`?"
properties[f.metadata.get("alias", f.name)] = type_to_dict(
properties = {
f.metadata.get("alias", f.name): type_to_dict(
f.type, f"{scope} {t.__name__}.{f.name}", type_map
)
for f in fields
if not f.name.startswith("_")
}
required = set()
for pn, pv in properties.items():
@@ -196,11 +192,6 @@ def type_to_dict(
return {"type": "boolean"}
if t is object:
return {"type": "object"}
if type(t) is EnumType:
return {
"type": "string",
"enum": list(t.__members__),
}
if t is Any:
msg = f"{scope} - Usage of the Any type is not supported for API functions. In: {scope}"
raise JSchemaTypeError(msg)
@@ -217,7 +208,7 @@ def type_to_dict(
if t is NoneType:
return {"type": "null"}
msg = f"{scope} - Basic type '{t!s}' is not supported"
msg = f"{scope} - Error primitive type not supported {t!s}"
raise JSchemaTypeError(msg)
msg = f"{scope} - Type '{t!s}' is not supported"
msg = f"{scope} - Error type not supported {t!s}"
raise JSchemaTypeError(msg)