Skip to content

Commit 05f0ea3

Browse files
committed
Implement gateway API key validation
1 parent 1667435 commit 05f0ea3

File tree

7 files changed

+673
-0
lines changed

7 files changed

+673
-0
lines changed

gateway/gateway-controller/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ help: ## Show this help message
3939
generate: ## Generate API server code from OpenAPI spec
4040
@echo "Generating API server code from OpenAPI spec..."
4141
@go run github.com/oapi-codegen/oapi-codegen/v2/cmd/[email protected] --config=oapi-codegen.yaml api/openapi.yaml
42+
@echo "Generating internal API server code from OpenAPI spec..."
43+
@go run github.com/oapi-codegen/oapi-codegen/v2/cmd/[email protected] --config=oapi-codegen-internal-api.yaml api/gateway-controller-internal-api.yaml
4244

4345
test: ## Run unit and integration tests
4446
@echo "Running tests..."
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
openapi: 3.0.3
2+
info:
3+
title: Gateway Controller Internal API
4+
description: |
5+
Internal REST API for Gateway Controller operations that are not exposed to external clients.
6+
7+
This API provides internal functionality for validation, monitoring, and administration
8+
purposes within the Gateway Controller ecosystem.
9+
version: 1.0.0
10+
contact:
11+
name: WSO2 API Platform Team
12+
servers:
13+
- url: http://localhost:9090
14+
description: Local development
15+
- url: http://gateway-controller:9090
16+
description: Docker/Kubernetes deployment
17+
18+
paths:
19+
/api/internal/v1/apis/{name}/{version}/validate/{apikey}:
20+
get:
21+
summary: Validate API key for a specific API
22+
description: |
23+
Validates whether the provided API key is valid for accessing the specified API name and version.
24+
Returns a boolean response indicating the validation result.
25+
operationId: validateApiKey
26+
tags:
27+
- Internal API Validation
28+
parameters:
29+
- name: name
30+
in: path
31+
required: true
32+
description: The name of the API
33+
schema:
34+
type: string
35+
example: "petstore"
36+
- name: version
37+
in: path
38+
required: true
39+
description: The version of the API
40+
schema:
41+
type: string
42+
example: "1.0.0"
43+
- name: apikey
44+
in: path
45+
required: true
46+
description: The API key to validate
47+
schema:
48+
type: string
49+
example: "abc123xyz789"
50+
responses:
51+
"200":
52+
description: API key validation result
53+
content:
54+
application/json:
55+
schema:
56+
$ref: '#/components/schemas/ApiKeyValidationResponse'
57+
"400":
58+
description: Bad request - invalid parameters
59+
content:
60+
application/json:
61+
schema:
62+
$ref: '#/components/schemas/ErrorResponse'
63+
"404":
64+
description: API not found
65+
content:
66+
application/json:
67+
schema:
68+
$ref: '#/components/schemas/ErrorResponse'
69+
"500":
70+
description: Internal server error
71+
content:
72+
application/json:
73+
schema:
74+
$ref: '#/components/schemas/ErrorResponse'
75+
76+
components:
77+
schemas:
78+
ApiKeyValidationResponse:
79+
type: object
80+
required:
81+
- isValid
82+
properties:
83+
isValid:
84+
type: boolean
85+
description: Whether the API key is valid for the specified API
86+
example: true
87+
additionalProperties: false
88+
89+
ErrorResponse:
90+
type: object
91+
required:
92+
- status
93+
- message
94+
properties:
95+
status:
96+
type: string
97+
example: error
98+
message:
99+
type: string
100+
description: High-level error description
101+
example: Configuration validation failed
102+
errors:
103+
type: array
104+
description: Detailed validation errors
105+
items:
106+
$ref: "#/components/schemas/ValidationError"
107+
108+
ValidationError:
109+
type: object
110+
properties:
111+
field:
112+
type: string
113+
description: Field that failed validation
114+
example: name
115+
message:
116+
type: string
117+
description: Human-readable error message
118+
example: Name is required

gateway/gateway-controller/cmd/controller/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"flag"
66
"fmt"
7+
internalapihandler "github.com/wso2/api-platform/gateway/gateway-controller/pkg/internalapi/handlers"
78
"net/http"
89
"os"
910
"os/signal"
@@ -16,6 +17,7 @@ import (
1617
"github.com/wso2/api-platform/gateway/gateway-controller/pkg/api/middleware"
1718
"github.com/wso2/api-platform/gateway/gateway-controller/pkg/config"
1819
"github.com/wso2/api-platform/gateway/gateway-controller/pkg/controlplane"
20+
internalapi "github.com/wso2/api-platform/gateway/gateway-controller/pkg/internalapi/generated"
1921
"github.com/wso2/api-platform/gateway/gateway-controller/pkg/logger"
2022
"github.com/wso2/api-platform/gateway/gateway-controller/pkg/models"
2123
"github.com/wso2/api-platform/gateway/gateway-controller/pkg/policyxds"
@@ -252,6 +254,10 @@ func main() {
252254
// Register API routes (includes certificate management endpoints from OpenAPI spec)
253255
api.RegisterHandlers(router, apiServer)
254256

257+
// Initialize and register internal API server
258+
internalAPIServer := internalapihandler.NewInternalAPIServer(configStore, db, log)
259+
internalapi.RegisterHandlers(router, internalAPIServer)
260+
255261
// Start REST API server
256262
log.Info("Starting REST API server", zap.Int("port", cfg.Server.APIPort))
257263

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package: internalapi
2+
output: pkg/internalapi/generated/generated.go
3+
generate:
4+
gin-server: true
5+
models: true
6+
embedded-spec: true
7+
strict-server: false
8+
output-options:
9+
yaml-tags: true
10+

gateway/gateway-controller/pkg/internalapi/generated/generated.go

Lines changed: 226 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)