Commit fd105434 authored by Adrian Pino's avatar Adrian Pino
Browse files

Refactors i2Edge payload handling

Simplifies payload handling by directly passing the Pydantic model.

Ensures that 'None' values are excluded from the JSON payload sent to i2Edge. This prevents unexpected behavior related to default values not being properly handled by the i2Edge API.
parent 30e66d0f
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -255,9 +255,7 @@ class EdgeApplicationManager(EdgeCloudManagementInterface):
            # Call i2Edge API
            i2edge_response = i2edge_post(
                f"{self.base_url}/application/onboarding",
                model_payload=i2edge_payload.model_dump(
                    mode="json", exclude_defaults=True
                ),
                model_payload=i2edge_payload,
            )
            # OpenAPI specifies 201 for successful application onboarding
            if i2edge_response.status_code == 201:
+1 −6
Original line number Diff line number Diff line
@@ -42,12 +42,7 @@ def i2edge_post(url: str, model_payload: BaseModel) -> dict:
        "Content-Type": "application/json",
        "accept": "application/json",
    }
    if isinstance(model_payload, BaseModel):
        json_payload = json.dumps(model_payload.model_dump(mode="json"))
    elif isinstance(model_payload, dict):
        json_payload = json.dumps(model_payload)
    else:
        raise TypeError("Payload must be a Pydantic model or a dict.")
    json_payload = json.dumps(model_payload.model_dump(mode="json", exclude_none=True))
    try:
        response = requests.post(url, data=json_payload, headers=headers)
        response.raise_for_status()