Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #828 from cisco-open/feature-profile-api
Browse files Browse the repository at this point in the history
dev: Add update method to service api. Move to literals for variable, global and default
  • Loading branch information
jpkrajewski authored Sep 17, 2024
2 parents 096ad0f + 7df0acd commit 310aabf
Show file tree
Hide file tree
Showing 20 changed files with 1,027 additions and 952 deletions.
141 changes: 73 additions & 68 deletions ENDPOINTS.md

Large diffs are not rendered by default.

35 changes: 10 additions & 25 deletions catalystwan/api/configuration_groups/parcel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Copyright 2024 Cisco Systems, Inc. and its affiliates

from enum import Enum
from typing import Any, Dict, Generic, List, Literal, Optional, Tuple, TypeVar

from pydantic import (
Expand All @@ -13,6 +12,7 @@
SerializerFunctionWrapHandler,
model_serializer,
)
from pydantic.alias_generators import to_camel
from typing_extensions import get_origin

from catalystwan.exceptions import CatalystwanException
Expand Down Expand Up @@ -81,24 +81,11 @@ def _get_parcel_type(cls) -> str:
raise CatalystwanException(f"{cls.__name__} field parcel type is not set.")


class OptionType(str, Enum):
GLOBAL = "global"
DEFAULT = "default"
VARIABLE = "variable"


class ParcelAttribute(BaseModel):
model_config = ConfigDict(extra="forbid")
option_type: OptionType = Field(serialization_alias="optionType", validation_alias="optionType")


# https://github.com/pydantic/pydantic/discussions/6090
# Usage: Global[str](value="test")
class Global(ParcelAttribute, Generic[T]):
model_config = ConfigDict(populate_by_name=True)
option_type: OptionType = Field(
default=OptionType.GLOBAL, serialization_alias="optionType", validation_alias="optionType"
)
class Global(BaseModel, Generic[T]):
model_config = ConfigDict(populate_by_name=True, alias_generator=to_camel)
option_type: Literal["global"] = "global"
value: T

def __bool__(self) -> bool:
Expand All @@ -121,17 +108,15 @@ def __le__(self, other: Any) -> bool:
return False


class Variable(ParcelAttribute):
option_type: OptionType = Field(
default=OptionType.VARIABLE, serialization_alias="optionType", validation_alias="optionType"
)
class Variable(BaseModel):
model_config = ConfigDict(populate_by_name=True, alias_generator=to_camel)
option_type: Literal["variable"] = "variable"
value: str = Field(pattern=r"^\{\{[.\/\[\]a-zA-Z0-9_-]+\}\}$", min_length=1, max_length=64)


class Default(ParcelAttribute, Generic[T]):
option_type: OptionType = Field(
default=OptionType.DEFAULT, serialization_alias="optionType", validation_alias="optionType"
)
class Default(BaseModel, Generic[T]):
model_config = ConfigDict(populate_by_name=True, alias_generator=to_camel)
option_type: Literal["default"] = "default"
value: Optional[T] = None


Expand Down
Loading

0 comments on commit 310aabf

Please sign in to comment.