Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0a40a3b
Refactor YAML parameters and improve variable handling across multipl…
sathiya-nhs May 11, 2026
3fe7ce1
Refactor YAML scripts for improved variable handling and consistency
sathiya-nhs May 11, 2026
ab194ed
Refactor environment variable handling in YAML files for consistency
sathiya-nhs May 11, 2026
039bbd4
Fix variable assignment syntax for Python version in apigee-build.yml
sathiya-nhs May 11, 2026
632dc77
Refactor variable usage in deploy-service.yml for consistency and cla…
sathiya-nhs May 11, 2026
dac4c6d
Refactor YAML scripts for improved consistency and clarity in variabl…
sathiya-nhs May 11, 2026
90af4e9
Enhance manifest validation to conditionally update spec paths based …
sathiya-nhs May 11, 2026
4e622d7
Refactor function signatures in env_cleaner.py to remove unused param…
sathiya-nhs May 11, 2026
7075189
Fix formatting in add_policy_to_pre_flow.py and update type hint in a…
sathiya-nhs May 11, 2026
c25f7ba
Refactor type hints in product.py and rate_limiting_config.py to use …
sathiya-nhs May 11, 2026
a4eb823
Refactor code for improved readability and consistency in update_sche…
sathiya-nhs May 11, 2026
1fea385
Refactor code for improved readability and consistency in calculate_v…
sathiya-nhs May 11, 2026
1737b63
Refactor prepend_dist_dir_to_spec_paths in validate_manifest.py for c…
sathiya-nhs May 11, 2026
55390cf
Remove unused min_age parameter from clean_specs function in env_clea…
sathiya-nhs May 11, 2026
62a5bdf
Add environment variable for service_name in apigee-build.yml check w…
sathiya-nhs May 11, 2026
3cc6eb5
Debug
sathiya-nhs May 11, 2026
212e214
Refactor deploy-service.yml to remove redundant variable declarations…
sathiya-nhs May 12, 2026
076124b
Fix formatting inconsistencies in deploy-stage.yml and update display…
sathiya-nhs May 12, 2026
611eaf6
Refactor code for consistency and clarity across multiple files, incl…
sathiya-nhs May 12, 2026
8524fba
Update s3-cache-action version to 1.3.4 in multiple YAML files for co…
sathiya-nhs May 12, 2026
243b081
Update display_name field to use alias displayName for consistency wi…
sathiya-nhs May 12, 2026
dfa5be4
Refactor display_name field to displayName for consistency with API s…
sathiya-nhs May 12, 2026
e25ceaa
Merge branch 'master' into APM-7323-Sonarqube-fix
sathiya-nhs May 18, 2026
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def run(self, tmp=None, task_vars=None):
proxies_dir = args.dist_dir.joinpath(
"proxies", args.proxy_dir, "apiproxy/proxies"
)
proxies_files = [f for f in proxies_dir.glob("*.xml")]
proxies_files = list(proxies_dir.glob("*.xml"))

if len(proxies_files) != 1:
return {
Expand All @@ -57,13 +57,12 @@ def run(self, tmp=None, task_vars=None):
name = step.find("Name")
if name.text == args.policy_name:
return {"changed": False}
break

result = {"changed": True}
if diff_mode:
result["diff"] = {
"before": etree.tostring(tree, pretty_print=True).decode(),
"before_header": str(proxies_file)
"before_header": str(proxies_file),
}

step = etree.Element("Step")
Expand All @@ -76,8 +75,8 @@ def run(self, tmp=None, task_vars=None):
result["diff"].update(
{
"after": etree.tostring(tree, pretty_print=True).decode(),
"after_header": str(proxies_file)
}
"after_header": str(proxies_file),
}
)

if check_mode or result["changed"] is False:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@


class ApigeeAction(ansible.plugins.action.ActionBase):
def validate_args(self, Validator: pydantic.BaseModel):
def validate_args(self, validator: type[pydantic.BaseModel]):
"""Returns two-length tuple of validated_args and errors dicts."""
try:
args = Validator(**self._task.args)
args = validator(**self._task.args)
return args, {}
except pydantic.ValidationError as e:
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ def check_service_name(cls, service_name, values):
def prepend_dist_dir_to_spec_paths(cls, manifest, values):
dist_dir = values.get("dist_dir")
print(dist_dir)
if not dist_dir:
return manifest
apigee = manifest["apigee"]
for env_dict in apigee["environments"]:
for spec_dict in env_dict["specs"]:
path = spec_dict.get("path")
if path is not None:
spec_dict["path"] = os.path.join(dist_dir, path)
if dist_dir:
apigee = manifest["apigee"]
for env_dict in apigee["environments"]:
for spec_dict in env_dict["specs"]:
path = spec_dict.get("path")
if path is not None:
spec_dict["path"] = os.path.join(dist_dir, path)

return manifest

@pydantic.validator("manifest")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from typing import Union, Literal, List, Dict, Any, Type
from typing import Optional, Union, Literal, List, Dict, Any, Type
from typing_extensions import Annotated
from pydantic import (
Field,
Expand Down Expand Up @@ -110,29 +110,34 @@ def _literal_name(class_):
+ ")$)"
)


class ApigeeProductAttributeOther(BaseModel):
name: constr(regex=PRODUCT_ATTRIBUTE_REGEX)
value: str


ApigeeProductAttributeSpecial = Annotated[
Union [
Union[
ApigeeProductAttributeAccess,
ApigeeProductAttributeRateLimit,
ApigeeProductAttributeRateLimiting,
],
Field(discriminator="name")
Field(discriminator="name"),
]


def _count_cls(items: List[Any], cls: Type):
return sum(isinstance(item, cls) for item in items)


class ApigeeProduct(BaseModel):
name: str
approvalType: Literal["auto", "manual"] = "manual"
attributes: List[Union[ApigeeProductAttributeSpecial, ApigeeProductAttributeOther]] = [{"name": "access", "value": "private"}]
description: str = None
displayName: str = None
attributes: List[
Union[ApigeeProductAttributeSpecial, ApigeeProductAttributeOther]
] = [{"name": "access", "value": "private"}]
description: Optional[str] = None
displayName: Optional[str] = None

# Note: This value is manually inserted by apigee_environment
# object that contains this product. So if you do not provide a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
Pydantic class for the rateliming config JSON, attached to products
and apps to control the ApplyRateLimiting shared flow.
"""
from typing import Literal

from typing import Literal, Optional

from pydantic import BaseModel, conint, constr, Extra


class ExcludeNoneModel(BaseModel):

"""
Providing default values for ratelimiting here would mean that
changing defaults required a redeploy for all proxies.
Expand All @@ -21,26 +21,27 @@ class ExcludeNoneModel(BaseModel):
update the defaults for everyone by just by updating the shared
flow.
"""

def dict(self, **kwargs):
kwargs["exclude_none"] = True
return super().dict(**kwargs)

class Config:
extra=Extra.forbid
extra = Extra.forbid


class QuotaConfig(ExcludeNoneModel):
enabled: bool = None
enabled: Optional[bool] = None
interval: conint(gt=0) = None
limit: conint(gt=0) = None
timeunit: Literal["minute", "hour", "day", "week", "month"] = None


class SpikeArrestConfig(ExcludeNoneModel):
enabled: bool = None
ratelimit: constr(regex=r"^[1-9][0-9]*(ps|pm)$") = None
enabled: Optional[bool] = None
ratelimit: Optional[constr(regex=r"^[1-9][0-9]*(ps|pm)$")] = None


class RateLimitingConfig(ExcludeNoneModel):
quota: QuotaConfig = None
spikeArrest: SpikeArrestConfig = None
quota: Optional[QuotaConfig] = None
spikeArrest: Optional[SpikeArrestConfig] = None
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
_REGISTRY_DATA = {}



class ManifestMetaApi(pydantic.BaseModel):
name: pydantic.constr(regex=r"^[a-z][a-z0-9]*(-[a-z0-9]+)*$")
id: typing.Optional[pydantic.UUID4] = pydantic.Field(
Expand All @@ -29,7 +28,7 @@ def dict(self, **kwargs):
{
"guid": str(native["guid"]),
"spec_guids": [str(guid) for guid in spec_guids],
}
}
)
return native

Expand Down Expand Up @@ -58,7 +57,9 @@ def validate_guid(cls, guid, values):
guid = _REGISTRY_DATA[name]["guid"]
registered_guid = _REGISTRY_DATA[name]["guid"]
if str(guid) != registered_guid:
raise ValueError(f"Supplied guid {guid} does not match registered guid {registered_guid}")
raise ValueError(
f"Supplied guid {guid} does not match registered guid {registered_guid}"
)
return guid

@pydantic.validator("spec_guids")
Expand All @@ -78,11 +79,12 @@ def validate_spec_guids(cls, spec_guids, values):
if str(spec_guid) not in registered_spec_guids:
invalid.append(str(spec_guid))
if len(invalid) > 0:
raise ValueError(f"Supplied spec_guids {invalid} do not match registered spec_guids {registered_spec_guids}")
raise ValueError(
f"Supplied spec_guids {invalid} do not match registered spec_guids {registered_spec_guids}"
)
return spec_guids



class ManifestMeta(pydantic.BaseModel):
schema_version: pydantic.constr(regex=r"[1-9][0-9]*(\.[0-9]+){0,2}")
api: ManifestMetaApi
Expand All @@ -91,7 +93,7 @@ class ManifestMeta(pydantic.BaseModel):
def validate_schema_version(cls, schema_version):
semantic_parts = schema_version.split(".")

MAJOR, MINOR, PATCH = [int(x) for x in SCHEMA_VERSION.split(".")]
MAJOR, _, _ = [int(x) for x in SCHEMA_VERSION.split(".")]
major = int(semantic_parts[0])

# Checking against minor/patch would not allow to us deploy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
import typing

from ansible_collections.nhsd.apigee.plugins.module_utils.models.manifest import meta
from ansible_collections.nhsd.apigee.plugins.module_utils.models.manifest.manifest import Manifest
from ansible_collections.nhsd.apigee.plugins.module_utils.models.manifest.manifest import (
Manifest,
)


SCHEMA_VERSION_REGEX = re.compile(r"^([1-9][0-9]*)\.([0-9]+)\.([0-9]+)$")
SCHEMA_VERSION_REGEX = re.compile(r"^([1-9]\d*)\.(\d+)\.(\d+)$")


class SchemaString:
Expand All @@ -23,7 +24,9 @@ def __init__(self, schema_or_major: typing.Union[str, int], minor=None, patch=No
match = re.match(SCHEMA_VERSION_REGEX, schema_version)
if not match:
raise ValueError(f"Invalid SchemaString {schema_version}")
self.major, self.minor, self.patch = [int(match.group(x)) for x in range(1, 4)]
self.major, self.minor, self.patch = [
int(match.group(x)) for x in range(1, 4)
]
elif isinstance(schema_or_major, int):
if not isinstance(minor, int) and isinstance(patch, int):
raise ValueError("SchemaString.__init__ requires major, minor, patch")
Expand All @@ -47,41 +50,51 @@ def __lt__(self, other):
return (
self.major < other.major
or (self.major == other.major and self.minor < other.minor)
or (self.major == other.major and self.minor == other.minor and self.patch < other.patch)
or (
self.major == other.major
and self.minor == other.minor
and self.patch < other.patch
)
)

def __le__(self, other):
return self < other or self == other

def __gt__(self, other):
return not self <= other
return (self.major, self.minor, self.patch) > (
other.major,
other.minor,
other.patch,
)

def __ge__(self, other):
return not self < other
return (self.major, self.minor, self.patch) >= (
other.major,
other.minor,
other.patch,
)

def valid_increments(self):
return [
SchemaString(self.major + 1, 0, 0),
SchemaString(self.major, self.minor + 1, 0),
SchemaString(self.major, self.minor, self.patch + 1)
SchemaString(self.major, self.minor, self.patch + 1),
]


def main():
"""

"""
""" """
UPDATED_SCHEMA_VERSION = SchemaString(meta.SCHEMA_VERSION)

script_dir = pathlib.Path(__file__).parent
relative_schema_dir = script_dir.joinpath(f"../tests/unit/plugins/module_utils/models/manifest/schema_versions/")

# last_schema_file_name = pathlib.Path(f"v{}.json")
relative_schema_dir = script_dir.joinpath(
"../tests/unit/plugins/module_utils/models/manifest/schema_versions/"
)

schema_dir_glob = relative_schema_dir.glob("v*.json")

SCHEMA_VERSION = SchemaString("1.0.0")
SCHEMA_FILE_NAME_PATTERN = re.compile(r"v([1-9][0-9]*\.[0-9]+\.[0-9]+)\.json$")
SCHEMA_FILE_NAME_PATTERN = re.compile(r"v([1-9]\d*\.\d+\.\d+)\.json$")
for schema_file in schema_dir_glob:
match = re.match(SCHEMA_FILE_NAME_PATTERN, schema_file.name)
schema_version = SchemaString(match.group(1))
Expand All @@ -100,17 +113,22 @@ def main():
fromfile=str(SCHEMA_VERSION),
tofile=str(UPDATED_SCHEMA_VERSION),
)
deltas = [delta for delta in deltas]
deltas = list(deltas)

if not deltas:
raise ValueError(f"No difference between proposed {UPDATED_SCHEMA_VERSION} schema and current {meta.SCHEMA_VERSION}")
raise ValueError(
f"No difference between proposed {UPDATED_SCHEMA_VERSION} schema and current {meta.SCHEMA_VERSION}"
)

if UPDATED_SCHEMA_VERSION not in SCHEMA_VERSION.valid_increments():
raise ValueError(f"""{UPDATED_SCHEMA_VERSION} is invalid increment after current {SCHEMA_VERSION}.
raise ValueError(
f"""{UPDATED_SCHEMA_VERSION} is invalid increment after current {SCHEMA_VERSION}.
Please increment major, minor or patch integer, e.g:
""" + f"\n".join(str(x) for x in SCHEMA_VERSION.valid_increments()))
"""
+ "\n".join(str(x) for x in SCHEMA_VERSION.valid_increments())
)

print("-"*50)
print("-" * 50)
for delta in deltas:
if delta.startswith("+"):
col = colorama.Fore.GREEN
Expand All @@ -122,7 +140,7 @@ def main():
print(colorama.Fore.RESET)

_input = None
print("-"*50)
print("-" * 50)
print("Confirm spec changes? ", end="")
while _input not in ["y", "n"]:
if _input is not None:
Expand All @@ -139,8 +157,7 @@ def main():

with open(new_schema_file, "w") as f:
f.write(new_schema)
print(
f"""Wrote {new_schema_file}"
print(f"""Wrote {new_schema_file}"
Validate this file by executing
$ make test
in {script_dir.parent}""")
Expand Down
Loading