INNER CODE UNIT · Python
get_prometheus_auth
pab1it0/prometheus-mcp-server · src/prometheus_mcp_server/server.py:181
def get_prometheus_auth():
"""Get authentication for Prometheus based on provided credentials."""
if config.token:
return {"Authorization": f"Bearer {config.token}"}
elif config.username and config.password:
return requests.auth.HTTPBasicAuth(config.username, config.password)
return None
def make_prometheus_request(endpoint, params=None):
"""Make a request to the Prometheus API with proper authentication and headers."""
if not config.url:
logger.error("Prometheus configuration missing", error="PROMETHEUS_URL not set")
raise ValueError("Prometheus configuration is missing. Please set PROMETHEUS_URL environment variable.")
if not config.url_ssl_verify:
logger.warning("SSL certificate verification is disabled. This is insecure and should not be used in production environments.", endpoint=endpoint)
url = f"{config.url.rstrip('/')}/api/v1/{endpoint}"
url_ssl_verify = config.url_ssl_verify