This repository has been archived by the owner on Nov 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
/
types.go
124 lines (96 loc) · 3.85 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
///////////////////////////////////////////////////////////////////////
// Copyright (c) 2017 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
///////////////////////////////////////////////////////////////////////
package functions
import (
"context"
"github.com/pkg/errors"
)
// NO TESTS
// Context provides function context
type Context map[string]interface{}
// Message contains context and payload for function invocations and events
type Message struct {
Context Context `json:"context"`
Payload interface{} `json:"payload"`
}
// Runnable is a runnable representation of a function
type Runnable func(ctx Context, in interface{}) (interface{}, error)
// Middleware allows injecting extra steps for each function execution
type Middleware func(f Runnable) Runnable
// Schemas represent function validation schemas
type Schemas struct {
// SchemaIn is the function input validation schema data structure. Can be nil.
SchemaIn interface{}
// SchemaOut is the function output validation schema data structure. Can be nil.
SchemaOut interface{}
}
// FunctionExecution represents single instance of function execution
type FunctionExecution struct {
Context Context
OrganizationID string
RunID string
FunctionID string
FaasID string
Schemas *Schemas
Secrets []string
Services []string
Cookie string
}
//go:generate mockery -name FaaSDriver -case underscore -dir . -note "CLOSE THIS FILE AS QUICKLY AS POSSIBLE"
// FaaSDriver manages Serverless functions and allows to create or delete function,
// as well as to retrieve runnable representation of the function.
type FaaSDriver interface {
// Create creates (or updates, if is already exists) the function in the FaaS implementation.
// name is the name of the function.
// exec defines the function implementation.
Create(ctx context.Context, f *Function) error
// Delete deletes the function in the FaaS implementation.
// f is a reference to function defition.
Delete(ctx context.Context, f *Function) error
// GetRunnable returns a callable representation of a function.
// e is a reference to FunctionExecution.
GetRunnable(e *FunctionExecution) Runnable
}
//go:generate mockery -name ImageBuilder -case underscore -dir . -note "CLOSE THIS FILE AS QUICKLY AS POSSIBLE"
// ImageBuilder builds a docker image for a serverless function.
type ImageBuilder interface {
// BuildImage builds a function image and pushes it to the docker registry.
// Returns image full name.
BuildImage(ctx context.Context, f *Function) (string, error)
}
// Runner knows how to execute a function
type Runner interface {
Run(fn *FunctionExecution, in interface{}) (interface{}, error)
}
// Validator validates function input/output
type Validator interface {
GetMiddleware(schemas *Schemas) Middleware
}
//go:generate mockery -name SecretInjector -case underscore -dir . -note "CLOSE THIS FILE AS QUICKLY AS POSSIBLE"
// SecretInjector injects secrets into function execution
type SecretInjector interface {
GetMiddleware(organizationID string, secrets []string, cookie string) Middleware
}
//go:generate mockery -name ServiceInjector -case underscore -dir . -note "CLOSE THIS FILE AS QUICKLY AS POSSIBLE"
// ServiceInjector injects service bindings into function execution
type ServiceInjector interface {
GetMiddleware(organizationID string, services []string, cookie string) Middleware
}
// InputError represents user/input error
type InputError interface {
AsInputErrorObject() interface{}
}
// FunctionError represents error caused by the function
type FunctionError interface {
AsFunctionErrorObject() interface{}
}
// SystemError represents error in the Dispatch infrastructure
type SystemError interface {
AsSystemErrorObject() interface{}
}
// StackTracer is part of the errors pkg public API and returns the error stacktrace
type StackTracer interface {
StackTrace() errors.StackTrace
}