Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit 8fe31bb

Browse files
authored
Add CORS Config API (#460)
1 parent 173ccbd commit 8fe31bb

27 files changed

+1632
-142
lines changed

cmd/event-gateway/main.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ func main() {
9292
EventTypeStore: intstore.NewPrefixed("/serverless-event-gateway/eventtypes", kvstore),
9393
FunctionStore: intstore.NewPrefixed("/serverless-event-gateway/functions", kvstore),
9494
SubscriptionStore: intstore.NewPrefixed("/serverless-event-gateway/subscriptions", kvstore),
95+
CORSStore: intstore.NewPrefixed("/serverless-event-gateway/cors", kvstore),
9596
Log: log,
9697
}
9798

@@ -114,7 +115,7 @@ func main() {
114115
ShutdownGuard: shutdownGuard,
115116
})
116117

117-
httpapi.StartConfigAPI(service, service, service, httpapi.ServerConfig{
118+
httpapi.StartConfigAPI(service, service, service, service, httpapi.ServerConfig{
118119
TLSCrt: configTLSCrt,
119120
TLSKey: configTLSKey,
120121
Port: *configPort,

docs/api.md

+134
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This document contains the API documentation for both Events and Configuration A
99
1. [Event Definition](#event-definition)
1010
1. [How To Emit an Event](#how-to-emit-an-event)
1111
1. [HTTP Request Event](#http-request-event)
12+
1. [CORS](#cors)
1213
1. [Legacy Mode](#legacy-mode)
1314
1. [Configuration API](#configuration-api)
1415
1. [Event Types](#event-types)
@@ -29,6 +30,11 @@ This document contains the API documentation for both Events and Configuration A
2930
1. [Delete Subscription](#delete-subscription)
3031
1. [Get Subscriptions](#get-subscriptions)
3132
1. [Get Subscription](#get-subscription)
33+
1. [CORS](#cors-1)
34+
1. [Create CORS Configuration](#create-cors-configuration)
35+
1. [Update CORS Configuration](#update-cors-configuration)
36+
1. [Delete CORS Configuration](#delete-cors-configuration)
37+
1. [Get CORS Configuration](#get-cors-configuration)
3238
1. [Prometheus Metrics](#prometheus-metrics)
3339
1. [Status](#status)
3440

@@ -86,6 +92,14 @@ CloudEvent created by Event Gateway where `data` field has the following structu
8692
* `params` - `object` - matched path parameters
8793
* `body` - depends on `Content-Type` header - request payload
8894

95+
### CORS
96+
97+
By default cross-origin resource sharing (CORS) is disabled. CORS is configured per-method/path basis using
98+
[CORS Configuration API](#cors-1).
99+
100+
Event Gateway handles preflight `OPTIONS` requests for you. You don't need to setup subscription for `OPTIONS` method
101+
because the Event Gateway will respond with all appropriate headers.
102+
89103
### Legacy Mode
90104

91105
*Legacy mode is deprecated and will be removed in upcoming releases.*
@@ -200,6 +214,8 @@ JSON object:
200214
* `name` - `string` - event type name
201215
* `authorizerId` - `string` - authorizer function ID
202216

217+
---
218+
203219
#### Get Event Type
204220

205221
**Endpoint**
@@ -350,6 +366,8 @@ JSON object:
350366
* `functionId` - `string` - function ID
351367
* `provider` - `object` - provider specific information about a function
352368

369+
---
370+
353371
#### Get Function
354372

355373
**Endpoint**
@@ -478,6 +496,8 @@ JSON object:
478496
* `method` - `string` - HTTP method that accepts requests
479497
* `path` - `string` - path that accepts requests, starts with `/`
480498

499+
---
500+
481501
#### Get Subscription
482502

483503
**Endpoint**
@@ -501,6 +521,120 @@ JSON object:
501521
* `method` - `string` - HTTP method that accepts requests
502522
* `path` - `string` - path that accepts requests, starts with `/`
503523

524+
### CORS
525+
526+
#### Create CORS Configuration
527+
528+
**Endpoint**
529+
530+
`POST <Configuration API URL>/v1/spaces/<space>/cors`
531+
532+
**Request**
533+
534+
* `method` - `string` - endpoint method
535+
* `path` - `string` - endpoint path
536+
* `allowedOrigins` - `array` of `string` - list of allowed origins. An origin may contain a wildcard (\*) to replace 0 or more characters (i.e.: http://\*.domain.com), default: `*`
537+
* `allowedMethods` - `array` of `string` - list of allowed methods, default: `HEAD`, `GET`, `POST`
538+
* `allowedHeaders` - `array` of `string` - list of allowed headers, default: `Origin`, `Accept`, `Content-Type`
539+
* `allowCredentials` - `bool` - allow credentials, default: false
540+
541+
**Response**
542+
543+
Status code:
544+
545+
* `201 Created` on success
546+
* `400 Bad Request` on validation error
547+
548+
JSON object:
549+
550+
* `space` - `string` - space name
551+
* `corsId` - `string` - CORS configuration ID
552+
* `method` - `string` - endpoint method
553+
* `path` - `string` - endpoint path
554+
* `allowedOrigins` - `array` of `string` - list of allowed origins
555+
* `allowedMethods` - `array` of `string` - list of allowed methods
556+
* `allowedHeaders` - `array` of `string` - list of allowed headers
557+
* `allowCredentials` - `boolean` - allow credentials
558+
559+
---
560+
561+
#### Update CORS Configuration
562+
563+
**Endpoint**
564+
565+
`PUT <Configuration API URL>/v1/spaces/<space>/cors/<CORS ID>`
566+
567+
**Request**
568+
569+
_Note that `method`, and `path` may not be updated in an UpdateCORS call._
570+
571+
* `method` - `string` - endpoint method
572+
* `path` - `string` - endpoint path
573+
* `allowedOrigins` - `array` of `string` - list of allowed origins
574+
* `allowedMethods` - `array` of `string` - list of allowed methods
575+
* `allowedHeaders` - `array` of `string` - list of allowed headers
576+
* `allowCredentials` - `boolean` - allow credentials
577+
578+
**Response**
579+
580+
Status code:
581+
582+
* `200 Created` on success
583+
* `400 Bad Request` on validation error
584+
* `404 Not Found` if CORS configuration doesn't exist
585+
586+
JSON object:
587+
588+
* `space` - `string` - space name
589+
* `corsId` - `string` - CORS configuration ID
590+
* `method` - `string` - endpoint method
591+
* `path` - `string` - endpoint path
592+
* `allowedOrigins` - `array` of `string` - allowed origins
593+
* `allowedMethods` - `array` of `string` - allowed methods
594+
* `allowedHeaders` - `array` of `string` - allowed headers
595+
* `allowCredentials` - `boolean` - allow credentials
596+
597+
---
598+
599+
#### Delete CORS Configuration
600+
601+
**Endpoint**
602+
603+
`DELETE <Configuration API URL>/v1/spaces/<space>/cors/<CORS ID>`
604+
605+
**Response**
606+
607+
Status code:
608+
609+
* `204 No Content` on success
610+
* `404 Not Found` if CORS configuration doesn't exist
611+
612+
---
613+
614+
#### Get CORS Configuration
615+
616+
**Endpoint**
617+
618+
`GET <Configuration API URL>/v1/spaces/<space>/cors/<CORS ID>`
619+
620+
**Response**
621+
622+
Status code:
623+
624+
* `200 OK` on success
625+
* `404 NotFound` if CORS configuration doesn't exist
626+
627+
JSON object:
628+
629+
* `space` - `string` - space name
630+
* `corsId` - `string` - CORS configuration ID
631+
* `method` - `string` - endpoint method
632+
* `path` - `string` - endpoint path
633+
* `allowedOrigins` - `array` of `string` - allowed origins
634+
* `allowedMethods` - `array` of `string` - allowed methods
635+
* `allowedHeaders` - `array` of `string` - allowed headers
636+
* `allowCredentials` - `boolean` - allow credentials
637+
504638
### Prometheus Metrics
505639

506640
Endpoint exposing [Prometheus metrics](./prometheus-metrics.md).

0 commit comments

Comments
 (0)