Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions gen_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ def process_specs(self):
for spec_file in core_dir.glob("**/*.json"):
api_name = "core"
# core api has a v0.0.1 in the spec but that will change
# for now use v1alpha1
api_version = "v1alpha1"
# for now use the version provided by a user from the cmd
api_version = self.version
logger.debug(f"API name: {api_name}, API version: {api_version}")
self.sanitize_schema_objects(spec_file, api_name, api_version)
self.generate_classes_for_spec(spec_file, api_name, api_version)
Expand Down Expand Up @@ -142,7 +142,9 @@ def generate_classes_for_spec(
"--collapse-root-models",
"--disable-timestamp",
"--reuse-model",
"--keep-model-order",
# can't use model order, since Topologies are defined before Topology
# maybe worth fixing the order in the model
# "--keep-model-order",
"--use-schema-description",
"--enum-field-as-literal",
"all",
Expand Down Expand Up @@ -184,16 +186,6 @@ def sanitize_schema_objects(self, spec_file: Path, api_name: str, api_version: s
# when flipped to true it means we need to write the in-mem file to disk in the output dir
modified = False

# Check and fix the info.title field if it has a trailing dot
# if "info" in spec_data and "title" in spec_data["info"]:
# title = spec_data["info"]["title"]
# if title.endswith("."):
# spec_data["info"]["title"] = title.rstrip(".")
# logger.debug(
# f"Removed trailing dot from title: {title} -> {spec_data['info']['title']}"
# )
# modified = True

schemas = spec_data["components"]["schemas"]
new_schemas = {}

Expand Down
222 changes: 111 additions & 111 deletions pydantic_eda/apps/aaa/v1alpha1/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@
from pydantic import BaseModel, Field, RootModel


class AppGroup(BaseModel):
apiVersion: Optional[str] = None
kind: Optional[str] = None
name: Optional[str] = None
preferredVersion: Optional[AppGroupVersion] = None
versions: Optional[List[AppGroupVersion]] = None


class AppGroupVersion(BaseModel):
groupVersion: Optional[str] = None
version: Optional[str] = None
Expand Down Expand Up @@ -83,60 +75,80 @@ class K8SPatchOp(BaseModel):
x_permissive: Annotated[Optional[bool], Field(alias="x-permissive")] = None


class NodeGroup(BaseModel):
"""
NodeGroup is the Schema for the nodegroups API
"""
class Patch(RootModel[List[K8SPatchOp]]):
root: List[K8SPatchOp]

apiVersion: str
kind: str
metadata: NodeGroupMetadata
spec: Annotated[
NodeGroupSpec,
Field(
description="NodeGroup is a representation of a group on a node, including the services it has access to, any RBAC, and TACACS configuration.\nNodeGroups are deployed to nodes by NodeUser or other permission-consuming resources.",
title="Specification",
),
]
status: Annotated[
Optional[NodeGroupStatus],
Field(description="Deployment status of this NodeGroup.", title="Status"),
] = None

class Resource(BaseModel):
kind: Optional[str] = None
name: Optional[str] = None
namespaced: Optional[bool] = None
readOnly: Optional[bool] = None
singularName: Optional[str] = None
uiCategory: Optional[str] = None

class NodeGroupDeletedResourceEntry(BaseModel):

class ResourceHistoryEntry(BaseModel):
author: Optional[str] = None
changeType: Optional[str] = None
commitTime: Optional[str] = None
hash: Optional[str] = None
name: Optional[str] = None
namespace: Optional[str] = None
message: Optional[str] = None
transactionId: Optional[int] = None


class NodeGroupDeletedResources(RootModel[List[NodeGroupDeletedResourceEntry]]):
root: List[NodeGroupDeletedResourceEntry]
class ResourceList(BaseModel):
apiVersion: Optional[str] = None
groupVersion: Optional[str] = None
kind: Optional[str] = None
resources: Optional[List[Resource]] = None


class NodeGroupList(BaseModel):
"""
NodeGroupList is a list of nodegroups
"""
class StatusDetails(BaseModel):
group: Optional[str] = None
kind: Optional[str] = None
name: Optional[str] = None

apiVersion: str
items: Optional[List[NodeGroup]] = None
kind: str

class UIResult(RootModel[str]):
root: str


class NodeGroupMetadata(BaseModel):
annotations: Optional[Dict[str, str]] = None
labels: Optional[Dict[str, str]] = None
name: Annotated[
str,
class NodeGroupSpecRule(BaseModel):
action: Annotated[
Literal["Deny", "ReadWrite", "Read"],
Field(description="Set the action for this entry.", title="Action"),
]
match: Annotated[
Optional[str],
Field(
max_length=253,
pattern="^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$",
description='Set the match for this entry. This is a string to match input against - for example "interface" for srl or "configure port" for sros.\nRules here should be specified in the target specific format.',
title="Match",
),
] = None
operatingSystem: Annotated[
Literal["srl", "sros"],
Field(
description="Operating system to match against for this rule.\nOperating system to deploy this rule to.",
title="Operating System",
),
]
namespace: str


class NodeGroupSpecTacacs(BaseModel):
"""
TACACS configuration.
"""

privilegeLevel: Annotated[
Optional[int],
Field(
description="Set the privilege level for this group.",
ge=0,
le=15,
title="Privilege Level",
),
] = None


class NodeGroupSpec(BaseModel):
Expand Down Expand Up @@ -182,43 +194,6 @@ class NodeGroupSpec(BaseModel):
] = None


class NodeGroupSpecRule(BaseModel):
action: Annotated[
Literal["Deny", "ReadWrite", "Read"],
Field(description="Set the action for this entry.", title="Action"),
]
match: Annotated[
Optional[str],
Field(
description='Set the match for this entry. This is a string to match input against - for example "interface" for srl or "configure port" for sros.\nRules here should be specified in the target specific format.',
title="Match",
),
] = None
operatingSystem: Annotated[
Literal["srl", "sros"],
Field(
description="Operating system to match against for this rule.\nOperating system to deploy this rule to.",
title="Operating System",
),
]


class NodeGroupSpecTacacs(BaseModel):
"""
TACACS configuration.
"""

privilegeLevel: Annotated[
Optional[int],
Field(
description="Set the privilege level for this group.",
ge=0,
le=15,
title="Privilege Level",
),
] = None


class NodeGroupStatus(BaseModel):
"""
Deployment status of this NodeGroup.
Expand All @@ -232,37 +207,41 @@ class NodeGroupStatus(BaseModel):
] = None


class Patch(RootModel[List[K8SPatchOp]]):
root: List[K8SPatchOp]


class Resource(BaseModel):
kind: Optional[str] = None
class NodeGroupDeletedResourceEntry(BaseModel):
commitTime: Optional[str] = None
hash: Optional[str] = None
name: Optional[str] = None
namespaced: Optional[bool] = None
readOnly: Optional[bool] = None
singularName: Optional[str] = None
uiCategory: Optional[str] = None
namespace: Optional[str] = None
transactionId: Optional[int] = None


class ResourceHistory(RootModel[List[ResourceHistoryEntry]]):
root: List[ResourceHistoryEntry]
class NodeGroupDeletedResources(RootModel[List[NodeGroupDeletedResourceEntry]]):
root: List[NodeGroupDeletedResourceEntry]


class ResourceHistoryEntry(BaseModel):
author: Optional[str] = None
changeType: Optional[str] = None
commitTime: Optional[str] = None
hash: Optional[str] = None
message: Optional[str] = None
transactionId: Optional[int] = None
class NodeGroupMetadata(BaseModel):
annotations: Optional[Dict[str, str]] = None
labels: Optional[Dict[str, str]] = None
name: Annotated[
str,
Field(
max_length=253,
pattern="^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$",
),
]
namespace: str


class ResourceList(BaseModel):
class AppGroup(BaseModel):
apiVersion: Optional[str] = None
groupVersion: Optional[str] = None
kind: Optional[str] = None
resources: Optional[List[Resource]] = None
name: Optional[str] = None
preferredVersion: Optional[AppGroupVersion] = None
versions: Optional[List[AppGroupVersion]] = None


class ResourceHistory(RootModel[List[ResourceHistoryEntry]]):
root: List[ResourceHistoryEntry]


class Status(BaseModel):
Expand All @@ -272,11 +251,32 @@ class Status(BaseModel):
string: Optional[str] = None


class StatusDetails(BaseModel):
group: Optional[str] = None
kind: Optional[str] = None
name: Optional[str] = None
class NodeGroup(BaseModel):
"""
NodeGroup is the Schema for the nodegroups API
"""

apiVersion: str
kind: str
metadata: NodeGroupMetadata
spec: Annotated[
NodeGroupSpec,
Field(
description="NodeGroup is a representation of a group on a node, including the services it has access to, any RBAC, and TACACS configuration.\nNodeGroups are deployed to nodes by NodeUser or other permission-consuming resources.",
title="Specification",
),
]
status: Annotated[
Optional[NodeGroupStatus],
Field(description="Deployment status of this NodeGroup.", title="Status"),
] = None

class UIResult(RootModel[str]):
root: str

class NodeGroupList(BaseModel):
"""
NodeGroupList is a list of nodegroups
"""

apiVersion: str
items: Optional[List[NodeGroup]] = None
kind: str
Loading