mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-01-25 02:08:11 +00:00
chore: set an appropiate User-Agent in requests (#8724)
This commit is contained in:
committed by
GitHub
parent
0286de7ce2
commit
cb4a5dec79
@@ -4,9 +4,11 @@ Prowler Hub MCP module
|
|||||||
Provides access to Prowler Hub API for security checks and compliance frameworks.
|
Provides access to Prowler Hub API for security checks and compliance frameworks.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from typing import Optional, Any
|
from typing import Any, Optional
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
from fastmcp import FastMCP
|
from fastmcp import FastMCP
|
||||||
|
from prowler_mcp_server import __version__
|
||||||
|
|
||||||
# Initialize FastMCP for Prowler Hub
|
# Initialize FastMCP for Prowler Hub
|
||||||
hub_mcp_server = FastMCP("prowler-hub")
|
hub_mcp_server = FastMCP("prowler-hub")
|
||||||
@@ -15,8 +17,13 @@ hub_mcp_server = FastMCP("prowler-hub")
|
|||||||
BASE_URL = "https://hub.prowler.com/api"
|
BASE_URL = "https://hub.prowler.com/api"
|
||||||
|
|
||||||
# HTTP client configuration
|
# HTTP client configuration
|
||||||
client = httpx.Client(
|
prowler_hub_client = httpx.Client(
|
||||||
base_url=BASE_URL, timeout=30.0, headers={"Accept": "application/json"}
|
base_url=BASE_URL,
|
||||||
|
timeout=30.0,
|
||||||
|
headers={
|
||||||
|
"Accept": "application/json",
|
||||||
|
"User-Agent": f"prowler-mcp-server/{__version__}",
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
# GitHub raw content base URL for Prowler checks
|
# GitHub raw content base URL for Prowler checks
|
||||||
@@ -26,11 +33,11 @@ GITHUB_RAW_BASE = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Separate HTTP client for GitHub raw content
|
# Separate HTTP client for GitHub raw content
|
||||||
github_client = httpx.Client(
|
github_raw_client = httpx.Client(
|
||||||
timeout=30.0,
|
timeout=30.0,
|
||||||
headers={
|
headers={
|
||||||
"Accept": "*/*",
|
"Accept": "*/*",
|
||||||
"User-Agent": "prowler-mcp-server/1.0",
|
"User-Agent": f"prowler-mcp-server/{__version__}",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -58,7 +65,7 @@ async def get_check_filters() -> dict[str, Any]:
|
|||||||
categories, and compliance frameworks with their respective counts
|
categories, and compliance frameworks with their respective counts
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
response = client.get("/check/filters")
|
response = prowler_hub_client.get("/check/filters")
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
filters = response.json()
|
filters = response.json()
|
||||||
|
|
||||||
@@ -133,7 +140,7 @@ async def get_checks(
|
|||||||
params["fields"] = fields
|
params["fields"] = fields
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = client.get("/check", params=params)
|
response = prowler_hub_client.get("/check", params=params)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
checks = response.json()
|
checks = response.json()
|
||||||
|
|
||||||
@@ -178,7 +185,7 @@ async def get_check_raw_metadata(
|
|||||||
if provider_id and check_id:
|
if provider_id and check_id:
|
||||||
url = github_check_path(provider_id, check_id, ".metadata.json")
|
url = github_check_path(provider_id, check_id, ".metadata.json")
|
||||||
try:
|
try:
|
||||||
resp = github_client.get(url)
|
resp = github_raw_client.get(url)
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
return resp.json()
|
return resp.json()
|
||||||
except httpx.HTTPStatusError as e:
|
except httpx.HTTPStatusError as e:
|
||||||
@@ -218,7 +225,7 @@ async def get_check_code(
|
|||||||
if provider_id and check_id:
|
if provider_id and check_id:
|
||||||
url = github_check_path(provider_id, check_id, ".py")
|
url = github_check_path(provider_id, check_id, ".py")
|
||||||
try:
|
try:
|
||||||
resp = github_client.get(url)
|
resp = github_raw_client.get(url)
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
return {
|
return {
|
||||||
"content": resp.text,
|
"content": resp.text,
|
||||||
@@ -260,7 +267,7 @@ async def get_check_fixer(
|
|||||||
if provider_id and check_id:
|
if provider_id and check_id:
|
||||||
url = github_check_path(provider_id, check_id, "_fixer.py")
|
url = github_check_path(provider_id, check_id, "_fixer.py")
|
||||||
try:
|
try:
|
||||||
resp = github_client.get(url)
|
resp = github_raw_client.get(url)
|
||||||
if resp.status_code == 404:
|
if resp.status_code == 404:
|
||||||
return {
|
return {
|
||||||
"error": f"Fixer not found for check {check_id}",
|
"error": f"Fixer not found for check {check_id}",
|
||||||
@@ -300,7 +307,7 @@ async def search_checks(term: str) -> dict[str, Any]:
|
|||||||
List of checks matching the search term
|
List of checks matching the search term
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
response = client.get("/check/search", params={"term": term})
|
response = prowler_hub_client.get("/check/search", params={"term": term})
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
checks = response.json()
|
checks = response.json()
|
||||||
|
|
||||||
@@ -357,7 +364,7 @@ async def get_compliance_frameworks(
|
|||||||
params["fields"] = fields
|
params["fields"] = fields
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = client.get("/compliance", params=params)
|
response = prowler_hub_client.get("/compliance", params=params)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
frameworks = response.json()
|
frameworks = response.json()
|
||||||
|
|
||||||
@@ -397,7 +404,7 @@ async def search_compliance_frameworks(term: str) -> dict[str, Any]:
|
|||||||
List of compliance frameworks matching the search term
|
List of compliance frameworks matching the search term
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
response = client.get("/compliance/search", params={"term": term})
|
response = prowler_hub_client.get("/compliance/search", params={"term": term})
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
frameworks = response.json()
|
frameworks = response.json()
|
||||||
|
|
||||||
@@ -433,7 +440,7 @@ async def list_providers() -> dict[str, Any]:
|
|||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
response = client.get("/providers")
|
response = prowler_hub_client.get("/providers")
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
providers = response.json()
|
providers = response.json()
|
||||||
|
|
||||||
@@ -463,7 +470,7 @@ async def get_artifacts_count() -> dict[str, Any]:
|
|||||||
Total number of artifacts in the Prowler Hub.
|
Total number of artifacts in the Prowler Hub.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
response = client.get("/n_artifacts")
|
response = prowler_hub_client.get("/n_artifacts")
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
data = response.json()
|
data = response.json()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user