From cd802afa8949389d0dda190865256065a15323a1 Mon Sep 17 00:00:00 2001 From: Cecilia Stevens <63068179+ceciliastevens@users.noreply.github.com> Date: Tue, 15 Apr 2025 12:05:44 -0400 Subject: [PATCH 1/2] add agentGuid column header --- CHANGELOG.md | 6 ++++++ src/_incydr_cli/cmds/agents.py | 4 ++-- src/_incydr_cli/cmds/models.py | 8 +++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f16f3aa..c177b947 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,12 @@ how a consumer would use the library or CLI tool (e.g. adding unit tests, updating documentation, etc) are not captured here. +## Unreleased + +### Updated + +- CSV and JSON input for the CLI's bulk agent commands will now look for `agentGuid` as a column header, in addition to `agent_id`, `agentId`, and `guid`. + ## 2.3.0 - 2025-03-18 ### Added diff --git a/src/_incydr_cli/cmds/agents.py b/src/_incydr_cli/cmds/agents.py index 4c6dc932..ed59541a 100644 --- a/src/_incydr_cli/cmds/agents.py +++ b/src/_incydr_cli/cmds/agents.py @@ -140,7 +140,7 @@ def bulk_activate(file: Path, format_: str): Input files require a header (for CSV input) or JSON key for each object (for JSON-LINES input) to identify which agent ID to activate. - Header and JSON key values that are accepted are: agent_id, agentId, or guid + Header and JSON key values that are accepted are: agentGuid, agent_id, agentId, or guid """ chunk_size = ( environ.get("incydr_batch_size") or environ.get("INCYDR_BATCH_SIZE") or 50 @@ -190,7 +190,7 @@ def bulk_deactivate(file: Path, format_: str): Input files require a header (for CSV input) or JSON key for each object (for JSON-LINES input) to identify which agent ID to deactivate. - Header and JSON key values that are accepted are: agent_id, agentId, or guid + Header and JSON key values that are accepted are: agentGuid, agent_id, agentId, or guid """ chunk_size = ( environ.get("incydr_batch_size") or environ.get("INCYDR_BATCH_SIZE") or 50 diff --git a/src/_incydr_cli/cmds/models.py b/src/_incydr_cli/cmds/models.py index a5f95155..1ac41e9f 100644 --- a/src/_incydr_cli/cmds/models.py +++ b/src/_incydr_cli/cmds/models.py @@ -27,7 +27,7 @@ def user(self): class AgentCSV(CSVModel): - agent_id: str = Field(csv_aliases=["agent_id", "agentId", "guid"]) + agent_id: str = Field(csv_aliases=["agentGuid", "agent_id", "agentId", "guid"]) class AgentJSON(Model): @@ -35,7 +35,9 @@ class AgentJSON(Model): @root_validator(pre=True) def _validate(cls, values): # noqa - if "agent_id" in values: + if "agentGuid" in values: + return values["agent_id"] = values["agentGuid"] + elif "agent_id" in values: return values elif "agentId" in values: values["agent_id"] = values["agentId"] @@ -45,5 +47,5 @@ def _validate(cls, values): # noqa return values else: raise ValueError( - "A json key of 'agent_id', 'agentId', or 'guid' is required" + "A json key of 'agentGuid', 'agent_id', 'agentId', or 'guid' is required" ) From 5450fab4022119b88d81e3cd661da9a046e42335 Mon Sep 17 00:00:00 2001 From: Cecilia Stevens <63068179+ceciliastevens@users.noreply.github.com> Date: Tue, 15 Apr 2025 12:06:53 -0400 Subject: [PATCH 2/2] bugfix --- src/_incydr_cli/cmds/models.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/_incydr_cli/cmds/models.py b/src/_incydr_cli/cmds/models.py index 1ac41e9f..4a91e547 100644 --- a/src/_incydr_cli/cmds/models.py +++ b/src/_incydr_cli/cmds/models.py @@ -36,7 +36,8 @@ class AgentJSON(Model): @root_validator(pre=True) def _validate(cls, values): # noqa if "agentGuid" in values: - return values["agent_id"] = values["agentGuid"] + values["agent_id"] = values["agentGuid"] + return values elif "agent_id" in values: return values elif "agentId" in values: