Skip to content

Commit 5025c12

Browse files
committed
fix: enable auth, use PascalCase operationIds, fix schemas and indexes
1 parent a772ad9 commit 5025c12

3 files changed

Lines changed: 30 additions & 56 deletions

File tree

docs/middleware.md

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ specs:
8787
- api/middleware_management.yaml
8888
add_operation_fields:
8989
x-openapi-router-controller: pro_tes.api.middlewares.controllers
90-
disable_auth: True
9190
connexion:
9291
strict_validation: True
9392
validate_responses: True
@@ -96,7 +95,7 @@ specs:
9695
This configuration tells FOCA to:
9796
- Load the OpenAPI spec from the api directory
9897
- Route requests to the middlewares controller module
99-
- Disable authentication for initial development (will be secured in Subtask 4)
98+
- Use existing authentication scheme for security
10099
- Enable strict validation of requests and responses
101100
102101
The FOCA framework uses Connexion under the hood, which automatically generates routing, parameter validation, and response serialization based on the OpenAPI specification.
@@ -110,30 +109,9 @@ pro_tes/
110109
└── config.yaml (FOCA integration)
111110

112111
docs/
113-
├── api/
114-
│ ├── middleware_management.md (API documentation)
115-
│ ├── middleware_management.postman_collection.json
116-
│ └── QUICK_REFERENCE.md
117-
├── architecture/
118-
│ └── middleware_api_design.md (Architecture decisions)
119112
└── middleware.md (This file)
120-
121-
scripts/
122-
└── validate_openapi.sh (Validation utility)
123113
```
124114

125-
## Documentation Deliverables
126-
127-
**API Documentation**: Comprehensive guide with request/response examples for each endpoint. Includes curl commands, common use cases, and troubleshooting tips.
128-
129-
**Architecture Decision Record**: Documents twelve major design decisions with rationale, alternatives considered, and consequences. Serves as reference for future development.
130-
131-
**Postman Collection**: Ready-to-use collection with fourteen pre-configured requests. Includes environment variables, test scripts, and example data for all scenarios.
132-
133-
**Quick Reference**: Single-page reference with essential endpoints, parameters, and response codes. Designed for daily development use.
134-
135-
**Validation Script**: Bash script that validates OpenAPI syntax using multiple tools. Checks for common errors like undefined schema references and invalid endpoint definitions.
136-
137115
## Testing Approach
138116

139117
This subtask focuses on specification validation rather than runtime testing since no executable code is implemented yet. Validation performed:
@@ -150,19 +128,21 @@ Runtime testing will occur in Subtask 2 when controllers are implemented.
150128

151129
## Security Considerations
152130

153-
While authentication is disabled for initial development, the specification includes security design:
131+
The specification includes comprehensive security design:
132+
133+
**Authentication Required**: All middleware management endpoints require authentication through the existing proTES security scheme.
154134

155-
**Input Validation**: All parameters include type, format, and constraint definitions. Connexion will automatically validate inputs before they reach controller code.
135+
**Input Validation**: All parameters include type, format, and constraint definitions. Connexion automatically validates inputs before they reach controller code.
156136

157137
**MongoDB ObjectId Pattern**: Enforces 24-character hex pattern preventing injection attacks through malformed IDs.
158138

159139
**Class Path Immutability**: Prevents code substitution attacks by making class paths unchangeable after creation.
160140

161-
**Code Validation**: Separate validation endpoint allows testing code safety before deployment.
141+
**Database Constraints**: Unique indexes on both name and class_path fields prevent duplicate middleware registration.
162142

163143
**Source Tracking**: Records code origin for audit and security review purposes.
164144

165-
Full security implementation including authentication, authorization, and rate limiting will be added in Subtask 4.
145+
Authorization controls and role-based access will be added in Subtask 4.
166146

167147
## Future Work
168148

pro_tes/api/middleware_management.yaml

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ paths:
2727
description: |
2828
Retrieve all configured middlewares with their order, metadata, and status.
2929
Results are sorted by execution order (ascending) by default.
30-
operationId: listMiddlewares
30+
operationId: ListMiddlewares
3131
tags:
3232
- Middleware Management
3333
parameters:
@@ -90,7 +90,7 @@ paths:
9090
local class paths or fetched from GitHub repositories. If order is not specified,
9191
the middleware is appended to the end of the stack. If order is specified,
9292
existing middlewares at that position or higher are shifted up by one.
93-
operationId: addMiddleware
93+
operationId: AddMiddleware
9494
tags:
9595
- Middleware Management
9696
requestBody:
@@ -147,7 +147,7 @@ paths:
147147
get:
148148
summary: Get middleware details
149149
description: Retrieve detailed information about a specific middleware by ID
150-
operationId: getMiddleware
150+
operationId: GetMiddleware
151151
tags:
152152
- Middleware Management
153153
parameters:
@@ -183,7 +183,7 @@ paths:
183183
description: |
184184
Update middleware configuration. Only name, order, config, and enabled fields
185185
can be updated. class_path and source cannot be modified for security reasons.
186-
operationId: updateMiddleware
186+
operationId: UpdateMiddleware
187187
tags:
188188
- Middleware Management
189189
parameters:
@@ -237,7 +237,7 @@ paths:
237237
description: |
238238
Remove a middleware from the execution stack. By default performs soft delete
239239
(sets enabled=false). Use force=true query parameter for hard deletion.
240-
operationId: deleteMiddleware
240+
operationId: DeleteMiddleware
241241
tags:
242242
- Middleware Management
243243
parameters:
@@ -277,7 +277,7 @@ paths:
277277
description: |
278278
Reorder the entire middleware execution stack by providing an ordered array
279279
of middleware IDs. All middleware IDs must be provided in the desired execution order.
280-
operationId: reorderMiddlewares
280+
operationId: ReorderMiddlewares
281281
tags:
282282
- Middleware Management
283283
requestBody:
@@ -321,7 +321,7 @@ paths:
321321
Validate middleware code without adding it to the stack. Performs static
322322
analysis to check if the code is valid and safe. Useful for testing before
323323
deploying middleware.
324-
operationId: validateMiddleware
324+
operationId: ValidateMiddleware
325325
tags:
326326
- Middleware Management
327327
requestBody:
@@ -572,12 +572,10 @@ components:
572572
ValidationRequest:
573573
type: object
574574
description: Request body for validating middleware code
575-
required:
576-
- class_path
577575
properties:
578576
class_path:
579577
type: string
580-
description: Class path or code to validate
578+
description: Class path to validate
581579
example: "pro_tes.plugins.middlewares.task_distribution.distance.TaskDistributionDistance"
582580
github_url:
583581
type: string
@@ -587,8 +585,11 @@ components:
587585
example: "https://raw.githubusercontent.com/user/repo/main/middleware.py"
588586
code:
589587
type: string
590-
description: Raw Python code to validate (alternative to class_path)
588+
description: Raw Python code to validate
591589
nullable: true
590+
oneOf:
591+
- required: [class_path]
592+
- required: [code]
592593

593594
ValidationResponse:
594595
type: object
@@ -648,25 +649,14 @@ components:
648649
type: object
649650
description: Standard error response
650651
required:
651-
- error
652+
- code
652653
- message
653654
properties:
654-
error:
655-
type: string
656-
description: Error type/code
657-
example: "MiddlewareNotFound"
655+
code:
656+
type: integer
657+
description: HTTP status code
658+
example: 404
658659
message:
659660
type: string
660661
description: Human-readable error message
661662
example: "Middleware with ID '507f1f77bcf86cd799439011' not found"
662-
details:
663-
type: object
664-
description: Additional error details
665-
nullable: true
666-
additionalProperties: true
667-
timestamp:
668-
type: string
669-
format: date-time
670-
description: Error timestamp
671-
example: "2026-01-24T10:30:00Z"
672-

pro_tes/config.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ db:
5151
indexes:
5252
- keys:
5353
name: 1
54+
options:
55+
"unique": True
56+
- keys:
57+
class_path: 1
58+
options:
59+
"unique": True
5460

5561
# API configuration
5662
# Cf. https://foca.readthedocs.io/en/latest/modules/foca.models.html#foca.models.config.APIConfig
@@ -79,7 +85,6 @@ api:
7985
- api/middleware_management.yaml
8086
add_operation_fields:
8187
x-openapi-router-controller: pro_tes.api.middlewares.controllers
82-
disable_auth: True
8388
connexion:
8489
strict_validation: True
8590
validate_responses: True
@@ -169,4 +174,3 @@ custom:
169174
middlewares:
170175
- - "pro_tes.plugins.middlewares.task_distribution.distance.TaskDistributionDistance"
171176
- "pro_tes.plugins.middlewares.task_distribution.random.TaskDistributionRandom"
172-

0 commit comments

Comments
 (0)