diff --git a/integrations/snyk/.port/spec.yaml b/integrations/snyk/.port/spec.yaml index 2f1b485835..3305db8b8f 100644 --- a/integrations/snyk/.port/spec.yaml +++ b/integrations/snyk/.port/spec.yaml @@ -28,7 +28,7 @@ configurations: - name: organizationId type: string required: false - description: The unique identifier for the specific organization. When provided, the integration fetches data for a single organization. To find the organization id, see the Snyk documentation + description: A comma-separated list of the unique identifier for specific organization(s). When provided, the integration fetches data for the specific organization(s). To find the organization id, see the Snyk documentation - name: groups type: string required: false diff --git a/integrations/snyk/CHANGELOG.md b/integrations/snyk/CHANGELOG.md index 4acd24bc28..61c3cd5d57 100644 --- a/integrations/snyk/CHANGELOG.md +++ b/integrations/snyk/CHANGELOG.md @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 +## 0.1.85 (2024-09-04) + + +### Features + +- Allowed users to provide multiple organization IDs to the integration using the existing `organizationId` param in the spec.yaml file + + ## 0.1.84 (2024-09-04) diff --git a/integrations/snyk/main.py b/integrations/snyk/main.py index 7e5892e5f4..3eeee5167e 100644 --- a/integrations/snyk/main.py +++ b/integrations/snyk/main.py @@ -1,7 +1,7 @@ import asyncio import hashlib import hmac -from typing import Any, cast +from typing import Any, cast, Optional from enum import StrEnum from fastapi import Request from loguru import logger @@ -36,12 +36,15 @@ def generate_signature(payload: bytes, secret: str) -> str: def init_client() -> SnykClient: + def parse_list(value: str) -> Optional[list[str]]: + return [item.strip() for item in value.split(",")] if value else None + return SnykClient( ocean.integration_config["token"], ocean.integration_config["api_url"], ocean.integration_config.get("app_host"), - ocean.integration_config.get("organization_id"), - ocean.integration_config.get("groups"), + parse_list(ocean.integration_config.get("organization_id", "")), + parse_list(ocean.integration_config.get("groups", "")), ocean.integration_config.get("webhook_secret"), ) diff --git a/integrations/snyk/pyproject.toml b/integrations/snyk/pyproject.toml index 41b8098a3d..114b65de61 100644 --- a/integrations/snyk/pyproject.toml +++ b/integrations/snyk/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "snyk" -version = "0.1.84" +version = "0.1.85" description = "Snyk integration powered by Ocean" authors = ["Isaac Coffie "] diff --git a/integrations/snyk/snyk/client.py b/integrations/snyk/snyk/client.py index 3e4fcb98a3..13c158c5af 100644 --- a/integrations/snyk/snyk/client.py +++ b/integrations/snyk/snyk/client.py @@ -28,14 +28,14 @@ def __init__( token: str, api_url: str, app_host: str | None, - organization_id: str | None, - group_ids: str | None, + organization_ids: list[str] | None, + group_ids: list[str] | None, webhook_secret: str | None, ): self.token = token self.api_url = f"{api_url}/v1" self.app_host = app_host - self.organization_id = organization_id + self.organization_ids = organization_ids self.group_ids = group_ids self.rest_api_url = f"{api_url}/rest" self.webhook_secret = webhook_secret @@ -407,32 +407,31 @@ async def get_organizations_in_groups(self) -> list[Any]: all_organizations = await self.get_all_organizations() - if self.organization_id: - logger.info(f"Specified organization ID: {self.organization_id}") + if self.organization_ids: + logger.info(f"Specified organization ID(s): {self.organization_ids}") matching_organization = [ - org for org in all_organizations if org["id"] == self.organization_id + org for org in all_organizations if org["id"] in self.organization_ids ] - + logger.info( + f"Fetched {len(matching_organization)} organizations for the given organization ID(s)." + ) if matching_organization: event.attributes[CacheKeys.GROUP] = matching_organization return matching_organization else: logger.warning( - f"Specified organization ID '{self.organization_id}' not found in the fetched organizations." + f"Specified organization ID(s) '{self.organization_ids}' not found in the fetched organizations." ) return [] - elif self.group_ids: - groups = self.group_ids.split(",") - logger.info( - f"Found {len(groups)} groups to filter. Group IDs: {str(groups)}. Getting all organizations associated with these groups" + f"Found {len(self.group_ids)} groups to filter. Group IDs: {str(self.group_ids)}. Getting all organizations associated with these groups" ) - matching_organizations_in_groups = [ org for org in all_organizations - if org.get("attributes") and org["attributes"].get("group_id") in groups + if org.get("attributes") + and org["attributes"].get("group_id") in self.group_ids ] logger.info(