Techdebt: add typing to AMIS (#6063)
This commit is contained in:
parent
6da5855dcf
commit
30a3df58f7
@ -1,7 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
from os import environ
|
from os import environ
|
||||||
from typing import Any, Dict, List, Iterable, Optional, Set
|
from typing import Any, Dict, List, Iterable, Optional, Set, cast
|
||||||
from moto.utilities.utils import load_resource
|
from moto.utilities.utils import load_resource
|
||||||
from ..exceptions import (
|
from ..exceptions import (
|
||||||
InvalidAMIIdError,
|
InvalidAMIIdError,
|
||||||
@ -21,7 +21,7 @@ from ..utils import (
|
|||||||
|
|
||||||
if "MOTO_AMIS_PATH" in environ:
|
if "MOTO_AMIS_PATH" in environ:
|
||||||
with open(environ["MOTO_AMIS_PATH"], "r", encoding="utf-8") as f:
|
with open(environ["MOTO_AMIS_PATH"], "r", encoding="utf-8") as f:
|
||||||
AMIS = json.load(f)
|
AMIS: List[Dict[str, Any]] = json.load(f)
|
||||||
else:
|
else:
|
||||||
AMIS = load_resource(__name__, "../resources/amis.json")
|
AMIS = load_resource(__name__, "../resources/amis.json")
|
||||||
|
|
||||||
@ -161,8 +161,11 @@ class AmiBackend:
|
|||||||
if "MOTO_AMIS_PATH" not in environ:
|
if "MOTO_AMIS_PATH" not in environ:
|
||||||
for path in ["latest_amis", "ecs/optimized_amis"]:
|
for path in ["latest_amis", "ecs/optimized_amis"]:
|
||||||
try:
|
try:
|
||||||
latest_amis = load_resource(
|
latest_amis = cast(
|
||||||
|
List[Dict[str, Any]],
|
||||||
|
load_resource(
|
||||||
__name__, f"../resources/{path}/{self.region_name}.json" # type: ignore[attr-defined]
|
__name__, f"../resources/{path}/{self.region_name}.json" # type: ignore[attr-defined]
|
||||||
|
),
|
||||||
)
|
)
|
||||||
for ami in latest_amis:
|
for ami in latest_amis:
|
||||||
ami_id = ami["ami_id"]
|
ami_id = ami["ami_id"]
|
||||||
|
@ -14,7 +14,7 @@ def str2bool(v: Any) -> Optional[bool]:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def load_resource(package: str, resource: str) -> Dict[str, Any]:
|
def load_resource(package: str, resource: str) -> Any:
|
||||||
"""
|
"""
|
||||||
Open a file, and return the contents as JSON.
|
Open a file, and return the contents as JSON.
|
||||||
Usage:
|
Usage:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user