Skip to content

Commit 1b6c7ac

Browse files
dpageclaude
andcommitted
Address additional CodeRabbit review comments
- Remove dead code: _generate_security_report_llm function that is never called (reporting uses pipeline-based generate_report_sync instead) - Guard checkLLMEnabled against showing misleading "disabled" message before async status check completes - Add null check for docker handler in _showReport to prevent TypeError if getDockerHandler returns undefined Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 31f915f commit 1b6c7ac

2 files changed

Lines changed: 24 additions & 106 deletions

File tree

web/pgadmin/llm/__init__.py

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,110 +1041,6 @@ def _gather_security_config(conn, manager):
10411041
return security_info
10421042

10431043

1044-
def _generate_security_report_llm(client, security_info):
1045-
"""
1046-
Use the LLM to analyze the security configuration and generate a report.
1047-
"""
1048-
from pgadmin.llm.models import Message
1049-
1050-
# Build the system prompt
1051-
system_prompt = (
1052-
"You are a PostgreSQL security expert. Your task is to analyze "
1053-
"the security configuration of a PostgreSQL database server and "
1054-
"generate a comprehensive security report in Markdown format.\n\n"
1055-
"Focus ONLY on server-level security configuration, not database "
1056-
"objects or data.\n\n"
1057-
"IMPORTANT: Do NOT include a report title, header block, or "
1058-
"generation date at the top of your response. The title and "
1059-
"metadata are added separately by the application. Start "
1060-
"directly with the Executive Summary section.\n\n"
1061-
"The report should include:\n"
1062-
"1. **Executive Summary** - Brief overview of the security posture\n"
1063-
"2. **Critical Issues** - Vulnerabilities needing "
1064-
"immediate attention\n"
1065-
"3. **Warnings** - Important security concerns to be addressed\n"
1066-
"4. **Recommendations** - Best practices to improve security\n"
1067-
"5. **Configuration Review** - Analysis of key security settings\n\n"
1068-
"Use severity indicators:\n"
1069-
"- 🔴 Critical - Immediate action required\n"
1070-
"- 🟠 Warning - Should be addressed soon\n"
1071-
"- 🟡 Advisory - Recommended improvement\n"
1072-
"- 🟢 Good - Configuration is secure\n\n"
1073-
"Be specific and actionable in your recommendations. Include the "
1074-
"current setting values when discussing issues. Format the output "
1075-
"as well-structured Markdown."
1076-
)
1077-
1078-
# Build the user message with the security configuration
1079-
settings_json = json.dumps(
1080-
security_info.get('settings', []), indent=2, default=str
1081-
)
1082-
hba_json = json.dumps(
1083-
security_info.get('hba_rules', []), indent=2, default=str
1084-
)
1085-
superusers_json = json.dumps(
1086-
security_info.get('superusers', []), indent=2, default=str
1087-
)
1088-
privileged_json = json.dumps(
1089-
security_info.get('privileged_roles', []), indent=2, default=str
1090-
)
1091-
no_expiry_json = json.dumps(
1092-
security_info.get('roles_no_expiry', []), indent=2, default=str
1093-
)
1094-
extensions_json = json.dumps(
1095-
security_info.get('extensions', []), indent=2, default=str
1096-
)
1097-
1098-
user_message = f"""Please analyze this PostgreSQL server security config.
1099-
1100-
## Server Information
1101-
- Server Version: {security_info.get('server_version', 'Unknown')}
1102-
1103-
## Security Settings
1104-
```json
1105-
{settings_json}
1106-
```
1107-
1108-
## pg_hba.conf Rules
1109-
{security_info.get('hba_note', '')}
1110-
```json
1111-
{hba_json}
1112-
```
1113-
1114-
## Superuser Roles
1115-
```json
1116-
{superusers_json}
1117-
```
1118-
1119-
## Roles with Special Privileges
1120-
```json
1121-
{privileged_json}
1122-
```
1123-
1124-
## Login Roles Without Password Expiry
1125-
```json
1126-
{no_expiry_json}
1127-
```
1128-
1129-
## Installed Extensions
1130-
```json
1131-
{extensions_json}
1132-
```
1133-
1134-
Generate a comprehensive security report analyzing this configuration."""
1135-
1136-
# Call the LLM
1137-
messages = [Message.user(user_message)]
1138-
response = client.chat(
1139-
messages=messages,
1140-
system_prompt=system_prompt,
1141-
max_tokens=4096,
1142-
temperature=0.3 # Lower temperature for more consistent analysis
1143-
)
1144-
1145-
return response.content
1146-
1147-
11481044
# =============================================================================
11491045
# Database Security Report
11501046
# =============================================================================

web/pgadmin/llm/static/js/ai_tools.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,16 +191,31 @@ define([
191191

192192
// Common LLM enablement check
193193
checkLLMEnabled: function(data) {
194+
if (!this.llmStatusChecked) {
195+
if (data) {
196+
data.data_disabled = gettext(
197+
'Checking AI configuration...'
198+
);
199+
}
200+
return false;
201+
}
202+
194203
if (!this.llmSystemEnabled) {
195204
if (data) {
196-
data.data_disabled = gettext('AI features are disabled in the server configuration.');
205+
data.data_disabled = gettext(
206+
'AI features are disabled in the '
207+
+ 'server configuration.'
208+
);
197209
}
198210
return false;
199211
}
200212

201213
if (!this.llmEnabled) {
202214
if (data) {
203-
data.data_disabled = gettext('Please configure an LLM provider in Preferences > AI to enable this feature.');
215+
data.data_disabled = gettext(
216+
'Please configure an LLM provider in '
217+
+ 'Preferences > AI to enable this feature.'
218+
);
204219
}
205220
return false;
206221
}
@@ -400,6 +415,13 @@ define([
400415
BROWSER_PANELS.AI_REPORT_PREFIX,
401416
pgBrowser.docker.default_workspace
402417
);
418+
if (!handler) {
419+
pgBrowser.report_error(
420+
gettext('Report'),
421+
gettext('Unable to open the report panel.')
422+
);
423+
return;
424+
}
403425
handler.focus();
404426
handler.docker.openTab({
405427
id: panelId,

0 commit comments

Comments
 (0)