Skip to content

Commit 77ddfc9

Browse files
Copilotphrocker
andcommitted
Add documentation and testing tools for JIRA proxy implementation
Co-authored-by: phrocker <[email protected]>
1 parent 8bce040 commit 77ddfc9

File tree

2 files changed

+224
-0
lines changed

2 files changed

+224
-0
lines changed

llm-proxy/JIRA_PROXY_API.md

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
# JIRA Proxy API Documentation
2+
3+
The JIRA Proxy Controller provides a secure interface to interact with JIRA instances through the Sentrius platform. It mirrors key JIRA REST API endpoints while maintaining the platform's authentication and authorization mechanisms.
4+
5+
## Overview
6+
7+
The JIRA proxy is implemented in the `llm-proxy` module and provides authenticated access to JIRA functionality for agents and compliance tools. It follows the same security patterns as the existing OpenAI proxy.
8+
9+
## Authentication
10+
11+
All endpoints require:
12+
- Valid JWT token in the `Authorization` header (format: `Bearer <token>`)
13+
- User must have `CAN_LOG_IN` application access
14+
- At least one JIRA integration must be configured in the system
15+
16+
## Endpoints
17+
18+
### 1. Search Issues
19+
20+
**GET** `/api/v1/jira/rest/api/3/search`
21+
22+
Search for JIRA issues using JQL or simple text queries.
23+
24+
**Parameters:**
25+
- `jql` (optional): JIRA Query Language string
26+
- `query` (optional): Simple text search query
27+
28+
**Example:**
29+
```bash
30+
curl -X GET \
31+
"https://your-instance/api/v1/jira/rest/api/3/search?query=bug" \
32+
-H "Authorization: Bearer <jwt-token>"
33+
```
34+
35+
**Response:** Array of TicketDTO objects containing issue information.
36+
37+
### 2. Get Issue
38+
39+
**GET** `/api/v1/jira/rest/api/3/issue/{issueKey}`
40+
41+
Retrieve information about a specific JIRA issue.
42+
43+
**Parameters:**
44+
- `issueKey` (path): JIRA issue key (e.g., "PROJECT-123")
45+
46+
**Example:**
47+
```bash
48+
curl -X GET \
49+
"https://your-instance/api/v1/jira/rest/api/3/issue/PROJECT-123" \
50+
-H "Authorization: Bearer <jwt-token>"
51+
```
52+
53+
**Response:** Issue status information.
54+
55+
### 3. Add Comment
56+
57+
**POST** `/api/v1/jira/rest/api/3/issue/{issueKey}/comment`
58+
59+
Add a comment to a JIRA issue.
60+
61+
**Parameters:**
62+
- `issueKey` (path): JIRA issue key
63+
- Request body: Comment object with `text` or `body` field
64+
65+
**Example:**
66+
```bash
67+
curl -X POST \
68+
"https://your-instance/api/v1/jira/rest/api/3/issue/PROJECT-123/comment" \
69+
-H "Authorization: Bearer <jwt-token>" \
70+
-H "Content-Type: application/json" \
71+
-d '{"text": "This is a comment from the compliance agent"}'
72+
```
73+
74+
**Response:** Success/failure message.
75+
76+
### 4. Assign Issue
77+
78+
**PUT** `/api/v1/jira/rest/api/3/issue/{issueKey}/assignee`
79+
80+
Assign a JIRA issue to a user.
81+
82+
**Parameters:**
83+
- `issueKey` (path): JIRA issue key
84+
- Request body: Assignee object with `accountId` field
85+
86+
**Example:**
87+
```bash
88+
curl -X PUT \
89+
"https://your-instance/api/v1/jira/rest/api/3/issue/PROJECT-123/assignee" \
90+
-H "Authorization: Bearer <jwt-token>" \
91+
-H "Content-Type: application/json" \
92+
-d '{"accountId": "user-account-id"}'
93+
```
94+
95+
**Response:** HTTP 204 (No Content) on success.
96+
97+
## Configuration
98+
99+
### JIRA Integration Setup
100+
101+
Before using the proxy, ensure a JIRA integration is configured:
102+
103+
1. Use the existing `/api/v1/integrations/jira/add` endpoint to add JIRA integration
104+
2. Provide required fields: `baseUrl`, `username`, `apiToken`
105+
106+
### Security Model
107+
108+
The proxy uses the existing security infrastructure:
109+
- JWT validation through Keycloak
110+
- User authentication via `BaseController.getOperatingUser()`
111+
- Access control through `@LimitAccess` annotations
112+
- OpenTelemetry tracing for monitoring
113+
114+
## Implementation Details
115+
116+
### Error Handling
117+
118+
- **401 Unauthorized**: Invalid or missing JWT token
119+
- **404 Not Found**: No JIRA integration configured
120+
- **400 Bad Request**: Missing required parameters
121+
- **500 Internal Server Error**: JIRA operation failed
122+
123+
### Integration Token Selection
124+
125+
Currently, the proxy uses the first available JIRA integration found for the connection type "jira". In production environments, you may want to extend this to allow users to specify which integration to use.
126+
127+
### Tracing
128+
129+
All operations are traced using OpenTelemetry with the tracer name `io.sentrius.sso`. Trace spans include:
130+
- Operation type (search, get-issue, add-comment, assign-issue)
131+
- Query parameters
132+
- Result counts
133+
- Success/failure status
134+
135+
## Future Enhancements
136+
137+
1. **Multi-integration Support**: Allow specifying which JIRA instance to use
138+
2. **Enhanced JQL Support**: Full JQL query validation and optimization
139+
3. **Bulk Operations**: Support for bulk issue updates and assignments
140+
4. **Webhook Support**: Real-time notifications from JIRA
141+
5. **Custom Field Support**: Access to JIRA custom fields
142+
6. **Project-specific Operations**: Project creation, configuration management
143+
144+
## Usage with Compliance Agents
145+
146+
This proxy is designed to support compliance agents that need to:
147+
- Search for compliance-related issues
148+
- Create comments with compliance findings
149+
- Assign issues to appropriate team members
150+
- Track compliance status across JIRA projects
151+
152+
Example agent workflow:
153+
1. Search for open compliance issues: `GET /api/v1/jira/rest/api/3/search?jql=project = COMPLIANCE AND status = Open`
154+
2. Add compliance assessment: `POST /api/v1/jira/rest/api/3/issue/COMPLIANCE-123/comment`
155+
3. Assign for remediation: `PUT /api/v1/jira/rest/api/3/issue/COMPLIANCE-123/assignee`
156+
157+
## Testing
158+
159+
Comprehensive test coverage is provided in `JiraProxyControllerTest.java`, including:
160+
- Authentication validation
161+
- Authorization checks
162+
- Error handling scenarios
163+
- Request/response validation

llm-proxy/test-jira-proxy.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
3+
# JIRA Proxy API Test Script
4+
# This script demonstrates how to interact with the JIRA proxy endpoints
5+
6+
# Configuration
7+
BASE_URL="http://localhost:8080"
8+
JWT_TOKEN="your-jwt-token-here"
9+
10+
echo "Testing JIRA Proxy API Endpoints"
11+
echo "================================="
12+
13+
# Test 1: Search for issues
14+
echo -e "\n1. Testing search endpoint..."
15+
curl -X GET \
16+
"${BASE_URL}/api/v1/jira/rest/api/3/search?query=test" \
17+
-H "Authorization: Bearer ${JWT_TOKEN}" \
18+
-H "Content-Type: application/json" \
19+
--silent --show-error || echo "Search test failed (expected if no auth)"
20+
21+
# Test 2: Get specific issue
22+
echo -e "\n2. Testing get issue endpoint..."
23+
curl -X GET \
24+
"${BASE_URL}/api/v1/jira/rest/api/3/issue/TEST-123" \
25+
-H "Authorization: Bearer ${JWT_TOKEN}" \
26+
-H "Content-Type: application/json" \
27+
--silent --show-error || echo "Get issue test failed (expected if no auth)"
28+
29+
# Test 3: Add comment
30+
echo -e "\n3. Testing add comment endpoint..."
31+
curl -X POST \
32+
"${BASE_URL}/api/v1/jira/rest/api/3/issue/TEST-123/comment" \
33+
-H "Authorization: Bearer ${JWT_TOKEN}" \
34+
-H "Content-Type: application/json" \
35+
-d '{"text": "Test comment from compliance agent"}' \
36+
--silent --show-error || echo "Add comment test failed (expected if no auth)"
37+
38+
# Test 4: Assign issue
39+
echo -e "\n4. Testing assign issue endpoint..."
40+
curl -X PUT \
41+
"${BASE_URL}/api/v1/jira/rest/api/3/issue/TEST-123/assignee" \
42+
-H "Authorization: Bearer ${JWT_TOKEN}" \
43+
-H "Content-Type: application/json" \
44+
-d '{"accountId": "test-user-id"}' \
45+
--silent --show-error || echo "Assign issue test failed (expected if no auth)"
46+
47+
echo -e "\n\nAPI endpoint testing completed."
48+
echo "Note: These tests will fail with authentication errors unless you have:"
49+
echo "1. A running instance of the llm-proxy service"
50+
echo "2. A valid JWT token"
51+
echo "3. A configured JIRA integration"
52+
53+
# Test with invalid token to verify security
54+
echo -e "\nTesting security with invalid token..."
55+
curl -X GET \
56+
"${BASE_URL}/api/v1/jira/rest/api/3/search?query=test" \
57+
-H "Authorization: Bearer invalid-token" \
58+
-H "Content-Type: application/json" \
59+
--include --silent --show-error | head -1
60+
61+
echo -e "\nExpected: HTTP 401 Unauthorized for invalid token"

0 commit comments

Comments
 (0)