Skip to content

Commit 11eefc4

Browse files
committed
🎨 [Backend] Refactor EC2InstanceBootSpecific fields to use Annotated with DEFAULT_FACTORY
1 parent 1450b18 commit 11eefc4

File tree

1 file changed

+27
-17
lines changed
  • packages/aws-library/src/aws_library/ec2

1 file changed

+27
-17
lines changed

packages/aws-library/src/aws_library/ec2/_models.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import Annotated, Final, TypeAlias
66

77
import sh # type: ignore[import-untyped]
8+
from common_library.basic_types import DEFAULT_FACTORY
89
from models_library.docker import DockerGenericTag
910
from pydantic import (
1011
BaseModel,
@@ -143,23 +144,32 @@ class EC2InstanceConfig:
143144

144145
class EC2InstanceBootSpecific(BaseModel):
145146
ami_id: AMIIdStr
146-
custom_boot_scripts: list[CommandStr] = Field(
147-
default_factory=list,
148-
description="script(s) to run on EC2 instance startup (be careful!), "
149-
"each entry is run one after the other using '&&' operator",
150-
)
151-
pre_pull_images: list[DockerGenericTag] = Field(
152-
default_factory=list,
153-
description="a list of docker image/tags to pull on instance cold start",
154-
)
155-
pre_pull_images_cron_interval: datetime.timedelta = Field(
156-
default=datetime.timedelta(minutes=30),
157-
description="time interval between pulls of images (minimum is 1 minute) "
158-
"(default to seconds, or see https://pydantic-docs.helpmanual.io/usage/types/#datetime-types for string formating)",
159-
)
160-
buffer_count: NonNegativeInt = Field(
161-
default=0, description="number of buffer EC2s to keep (defaults to 0)"
162-
)
147+
custom_boot_scripts: Annotated[
148+
list[CommandStr],
149+
Field(
150+
default_factory=list,
151+
description="script(s) to run on EC2 instance startup (be careful!), "
152+
"each entry is run one after the other using '&&' operator",
153+
),
154+
] = DEFAULT_FACTORY
155+
pre_pull_images: Annotated[
156+
list[DockerGenericTag],
157+
Field(
158+
default_factory=list,
159+
description="a list of docker image/tags to pull on instance cold start",
160+
),
161+
] = DEFAULT_FACTORY
162+
pre_pull_images_cron_interval: Annotated[
163+
datetime.timedelta,
164+
Field(
165+
description="time interval between pulls of images (minimum is 1 minute) "
166+
"(default to seconds, or see https://pydantic-docs.helpmanual.io/usage/types/#datetime-types for string formating)",
167+
),
168+
] = datetime.timedelta(minutes=30)
169+
buffer_count: Annotated[
170+
NonNegativeInt,
171+
Field(description="number of buffer EC2s to keep (defaults to 0)"),
172+
] = 0
163173

164174
@field_validator("custom_boot_scripts")
165175
@classmethod

0 commit comments

Comments
 (0)