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

Commit

Permalink
Add support for Metadata field in all resources. Closes #435 (#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
mthenw authored Jun 26, 2018
1 parent 28ded18 commit 73ba4a3
Show file tree
Hide file tree
Showing 27 changed files with 353 additions and 44 deletions.
40 changes: 40 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ JSON object:

* `name` - `string` - required, event type name
* `authorizerId` - `string` - authorizer function ID
* `metadata` - `object` - arbitrary metadata

**Response**

Expand All @@ -147,6 +148,7 @@ JSON object:
* `space` - `string` - space name
* `name` - `string` - event type name
* `authorizerId` - `string` - authorizer function ID
* `metadata` - `object` - arbitrary metadata

---

Expand All @@ -161,6 +163,7 @@ JSON object:
JSON object:

* `authorizerId` - `string` - authorizer function ID
* `metadata` - `object` - arbitrary metadata

**Response**

Expand All @@ -175,6 +178,7 @@ JSON object:
* `space` - `string` - space name
* `name` - `string` - event type name
* `authorizerId` - `string` - authorizer function ID
* `metadata` - `object` - arbitrary metadata

---

Expand Down Expand Up @@ -202,6 +206,10 @@ Status code:

`GET <Configuration API URL>/v1/spaces/<space>/eventtypes`

**Query Parameters**

Endpoint allows filtering list of returned object with filters passed as query parameters. Currently, filters can only use metadata properties e.g. `metadata.service=usersService`.

**Response**

Status code:
Expand All @@ -214,6 +222,7 @@ JSON object:
* `space` - `string` - space name
* `name` - `string` - event type name
* `authorizerId` - `string` - authorizer function ID
* `metadata` - `object` - arbitrary metadata

---

Expand All @@ -235,6 +244,7 @@ JSON object:
* `space` - `string` - space name
* `name` - `string` - event type name
* `authorizerId` - `string` - authorizer function ID
* `metadata` - `object` - arbitrary metadata


### Functions
Expand Down Expand Up @@ -278,6 +288,7 @@ JSON object:
* `awsAccessKeyId` - `string` - optional, AWS API key ID. By default credentials from the [environment](http://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html#specifying-credentials) are used.
* `awsSecretAccessKey` - `string` - optional, AWS API access key. By default credentials from the [environment](http://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html#specifying-credentials) are used.
* `awsSessionToken` - `string` - optional, AWS session token
* `metadata` - `object` - arbitrary metadata

**Response**

Expand All @@ -291,6 +302,7 @@ JSON object:
* `space` - `string` - space name
* `functionId` - `string` - function ID
* `provider` - `object` - provider specific information about a function
* `metadata` - `object` - arbitrary metadata

---

Expand All @@ -314,6 +326,7 @@ JSON object:
* `awsSessionToken` - `string` - optional, AWS session token
* for HTTP function:
* `url` - `string` - required, the URL of an http or https remote endpoint
* `metadata` - `object` - arbitrary metadata

**Response**

Expand All @@ -328,6 +341,7 @@ JSON object:
* `space` - `string` - space name
* `functionId` - `string` - function ID
* `provider` - `object` - provider specific information about a function
* `metadata` - `object` - arbitrary metadata

---

Expand All @@ -354,6 +368,10 @@ Status code:

`GET <Configuration API URL>/v1/spaces/<space>/functions`

**Query Parameters**

Endpoint allows filtering list of returned object with filters passed as query parameters. Currently, filters can only use metadata properties e.g. `metadata.service=usersService`.

**Response**

Status code:
Expand All @@ -366,6 +384,7 @@ JSON object:
* `space` - `string` - space name
* `functionId` - `string` - function ID
* `provider` - `object` - provider specific information about a function
* `metadata` - `object` - arbitrary metadata

---

Expand All @@ -387,6 +406,7 @@ JSON object:
* `space` - `string` - space name
* `functionId` - `string` - function ID
* `provider` - `object` - provider specific information about a function
* `metadata` - `object` - arbitrary metadata

### Subscriptions

Expand All @@ -403,6 +423,7 @@ JSON object:
* `functionId` - `string` - ID of function to receive events
* `path` - `string` - optional, URL path under which events (HTTP requests) are accepted, default: `/`
* `method` - `string` - optional, HTTP method that accepts requests, default: `POST`
* `metadata` - `object` - arbitrary metadata

**Response**

Expand All @@ -420,6 +441,7 @@ JSON object:
* `functionId` - function ID
* `method` - `string` - HTTP method that accepts requests
* `path` - `string` - path that accepts requests, starts with `/`
* `metadata` - `object` - arbitrary metadata

---

Expand All @@ -438,6 +460,7 @@ _Note that `type`, `eventType`, `functionId`, `path`, and `method` may not be up
* `functionId` - `string` - ID of function to receive events
* `path` - `string` - optional, URL path under which events (HTTP requests) are accepted, default: `/`
* `method` - `string` - optional, HTTP method that accepts requests, default: `POST`
* `metadata` - `object` - arbitrary metadata

**Response**

Expand All @@ -456,6 +479,7 @@ JSON object:
* `functionId` - function ID
* `method` - `string` - HTTP method that accepts requests
* `path` - `string` - path that accepts requests, starts with `/`
* `metadata` - `object` - arbitrary metadata

---

Expand All @@ -480,6 +504,10 @@ Status code:

`GET <Configuration API URL>/v1/spaces/<space>/subscriptions`

**Query Parameters**

Endpoint allows filtering list of returned object with filters passed as query parameters. Currently, filters can only use metadata properties e.g. `metadata.service=usersService`.

**Response**

Status code:
Expand All @@ -496,6 +524,7 @@ JSON object:
* `functionId` - function ID
* `method` - `string` - HTTP method that accepts requests
* `path` - `string` - path that accepts requests, starts with `/`
* `metadata` - `object` - arbitrary metadata

---

Expand All @@ -521,6 +550,7 @@ JSON object:
* `functionId` - function ID
* `method` - `string` - HTTP method that accepts requests
* `path` - `string` - path that accepts requests, starts with `/`
* `metadata` - `object` - arbitrary metadata

### CORS

Expand All @@ -538,6 +568,7 @@ JSON object:
* `allowedMethods` - `array` of `string` - list of allowed methods, default: `HEAD`, `GET`, `POST`
* `allowedHeaders` - `array` of `string` - list of allowed headers, default: `Origin`, `Accept`, `Content-Type`
* `allowCredentials` - `bool` - allow credentials, default: false
* `metadata` - `object` - arbitrary metadata

**Response**

Expand All @@ -556,6 +587,7 @@ JSON object:
* `allowedMethods` - `array` of `string` - list of allowed methods
* `allowedHeaders` - `array` of `string` - list of allowed headers
* `allowCredentials` - `boolean` - allow credentials
* `metadata` - `object` - arbitrary metadata

---

Expand All @@ -575,6 +607,7 @@ _Note that `method`, and `path` may not be updated in an UpdateCORS call._
* `allowedMethods` - `array` of `string` - list of allowed methods
* `allowedHeaders` - `array` of `string` - list of allowed headers
* `allowCredentials` - `boolean` - allow credentials
* `metadata` - `object` - arbitrary metadata

**Response**

Expand All @@ -594,6 +627,7 @@ JSON object:
* `allowedMethods` - `array` of `string` - allowed methods
* `allowedHeaders` - `array` of `string` - allowed headers
* `allowCredentials` - `boolean` - allow credentials
* `metadata` - `object` - arbitrary metadata

---

Expand All @@ -618,6 +652,10 @@ Status code:

`GET <Configuration API URL>/v1/spaces/<space>/cors`

**Query Parameters**

Endpoint allows filtering list of returned object with filters passed as query parameters. Currently, filters can only use metadata properties e.g. `metadata.service=usersService`.

**Response**

Status code:
Expand All @@ -635,6 +673,7 @@ JSON object:
* `allowedMethods` - `array` of `string` - allowed methods
* `allowedHeaders` - `array` of `string` - allowed headers
* `allowCredentials` - `boolean` - allow credentials
* `metadata` - `object` - arbitrary metadata

---

Expand All @@ -661,6 +700,7 @@ JSON object:
* `allowedMethods` - `array` of `string` - allowed methods
* `allowedHeaders` - `array` of `string` - allowed headers
* `allowCredentials` - `boolean` - allow credentials
* `metadata` - `object` - arbitrary metadata

### Prometheus Metrics

Expand Down
15 changes: 15 additions & 0 deletions docs/openapi/openapi-config-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ paths:
operationId: "ListEventTypes"
parameters:
- $ref: "#/components/parameters/Space"
- $ref: "#/components/parameters/Filters"
responses:
200:
description: "event types returned"
Expand Down Expand Up @@ -138,6 +139,7 @@ paths:
operationId: "ListFunctions"
parameters:
- $ref: "#/components/parameters/Space"
- $ref: "#/components/parameters/Filters"
responses:
200:
description: "functions returned"
Expand Down Expand Up @@ -239,6 +241,7 @@ paths:
operationId: "ListSubscriptions"
parameters:
- $ref: "#/components/parameters/Space"
- $ref: "#/components/parameters/Filters"
responses:
200:
description: "subscriptions returned"
Expand Down Expand Up @@ -338,6 +341,7 @@ paths:
operationId: "ListCORS"
parameters:
- $ref: "#/components/parameters/Space"
- $ref: "#/components/parameters/Filters"
responses:
200:
description: "CORS configurations returned"
Expand Down Expand Up @@ -704,6 +708,17 @@ components:
required: true
schema:
$ref: "#/components/schemas/CORSID"
Filters:
in: "query"
name: "filters"
description: filter out returned list of objects. Currently, filters can only use metadata properties e.g. `metadata.service=usersService`.
style: form
example:
"metadata.service": usersService
schema:
type: object
additionalProperties:
type: string
requestBodies:
CreateEventType:
description: "event type create request body"
Expand Down
4 changes: 3 additions & 1 deletion event/service.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package event

import "github.com/serverless/event-gateway/metadata"

// Service represents service for managing event types.
type Service interface {
GetEventType(space string, name TypeName) (*Type, error)
ListEventTypes(space string) (Types, error)
ListEventTypes(space string, filters ...metadata.Filter) (Types, error)
CreateEventType(eventType *Type) (*Type, error)
UpdateEventType(newEventType *Type) (*Type, error)
DeleteEventType(space string, name TypeName) error
Expand Down
3 changes: 3 additions & 0 deletions event/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package event

import (
"github.com/serverless/event-gateway/function"
"github.com/serverless/event-gateway/metadata"
"go.uber.org/zap/zapcore"
)

Expand All @@ -18,6 +19,8 @@ type Type struct {
Space string `json:"space" validate:"required,min=3,space"`
Name TypeName `json:"name" validate:"required"`
AuthorizerID *function.ID `json:"authorizerId,omitempty"`

Metadata metadata.Metadata `json:"metadata,omitempty"`
}

// Types is an array of subscriptions.
Expand Down
5 changes: 5 additions & 0 deletions function/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"

"github.com/serverless/event-gateway/metadata"
"go.uber.org/zap/zapcore"
)

Expand All @@ -17,6 +18,8 @@ type Function struct {
ProviderType ProviderType `json:"type"`
ProviderConfig *json.RawMessage `json:"provider"`
Provider Provider `json:"-" validate:"-"`

Metadata metadata.Metadata `json:"metadata,omitempty"`
}

// Functions is an array of functions.
Expand Down Expand Up @@ -53,6 +56,7 @@ func (f *Function) MarshalJSON() ([]byte, error) {
ID: f.ID,
ProviderType: f.ProviderType,
ProviderConfig: &rawConfig,
Metadata: f.Metadata,
}

return json.Marshal(fn)
Expand All @@ -74,6 +78,7 @@ func (f *Function) UnmarshalJSON(data []byte) error {

f.ID = rawFunction.ID
f.Space = rawFunction.Space
f.Metadata = rawFunction.Metadata
f.ProviderType = rawFunction.ProviderType

if loader, ok := providers[rawFunction.ProviderType]; ok {
Expand Down
4 changes: 3 additions & 1 deletion function/service.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package function

import "github.com/serverless/event-gateway/metadata"

// Service represents service for managing functions.
type Service interface {
GetFunction(space string, id ID) (*Function, error)
ListFunctions(space string) (Functions, error)
ListFunctions(space string, filters ...metadata.Filter) (Functions, error)
CreateFunction(fn *Function) (*Function, error)
UpdateFunction(fn *Function) (*Function, error)
DeleteFunction(space string, id ID) error
Expand Down
Loading

0 comments on commit 73ba4a3

Please sign in to comment.