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 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 ¶ added in v0.0.7
func DefaultFunctionCode ¶ added in v0.0.7
func NewLogHandler ¶ added in v0.3.0
func NewLogHandler(w io.Writer, opts *HandlerOptions) slog.Handler
Types ¶
type CFFContext ¶ added in v0.2.0
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 ¶ added in v0.2.0
type CFFCookieValue struct { Value string `json:"value"` Attributes string `json:"attributes,omitempty"` MultiValue []CFFCookieValue `json:"multiValue,omitempty"` }
type CFFEvent ¶ added in v0.2.0
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 ¶ added in v0.2.0
type CFFExpect struct { Request *CFFRequest `json:"request,omitempty"` Reponse *CFFResponse `json:"response,omitempty"` }
type CFFRequest ¶ added in v0.2.0
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 ¶ added in v0.2.0
func ParseRequest(text string) (CFFRequest, error)
func (*CFFRequest) UnmarshalJSON ¶ added in v0.2.0
func (r *CFFRequest) UnmarshalJSON(b []byte) error
type CFFResponse ¶ added in v0.2.0
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 ¶ added in v0.2.0
func ParseResponse(text string) (CFFResponse, error)
func (*CFFResponse) UnmarshalJSON ¶ added in v0.2.0
func (r *CFFResponse) UnmarshalJSON(b []byte) error
type CFFRunner ¶ added in v0.6.0
type CFFRunner struct {
// contains filtered or unexported fields
}
type CFFT ¶
type CFFT struct {
// contains filtered or unexported fields
}
func (*CFFT) DiffFunction ¶ added in v0.0.7
func (*CFFT) InitFunction ¶ added in v0.0.7
func (*CFFT) PublishFunction ¶ added in v0.0.8
func (app *CFFT) PublishFunction(ctx context.Context, opt *PublishCmd) error
func (*CFFT) RunTestCase ¶ added in v0.6.0
func (*CFFT) UtilParseRequest ¶ added in v0.2.0
func (app *CFFT) UtilParseRequest(ctx context.Context, opt ParseRequestCmd) error
func (*CFFT) UtilParseResponse ¶ added in v0.2.0
func (app *CFFT) UtilParseResponse(ctx context.Context, opt ParseResponseCmd) error
type CFFViewer ¶ added in v0.2.0
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 ¶ added in v0.0.5
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 }
func LoadConfig ¶ added in v0.0.5
func (*Config) FunctionCode ¶ added in v0.1.0
type ConfigFunction ¶ added in v0.6.0
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 ¶ added in v0.6.0
type ContextKey ¶ added in v0.8.1
type ContextKey string
type DiffCmd ¶ added in v0.0.7
type DiffCmd struct {
Live bool `cmd:"" help:"diff with LIVE stage"`
}
type FuncTemplateArgs ¶ added in v0.6.0
type FunctionRunner ¶ added in v0.6.0
type HandlerOptions ¶ added in v0.6.0
type HandlerOptions struct { slog.HandlerOptions Color bool }
type InitCmd ¶ added in v0.0.5
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 ¶ added in v0.1.0
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 ¶ added in v0.1.0
type KVSDeleteCmd struct {
Key string `arg:"" help:"key name" required:""`
}
type KVSGetCmd ¶ added in v0.1.0
type KVSGetCmd struct {
Key string `arg:"" help:"key name" required:""`
}
type KVSListCmd ¶ added in v0.2.0
type KVSListCmd struct {
MaxItems int32 `short:"m" help:"max items" default:"50"`
}
type KeyValueStoreConfig ¶ added in v0.1.0
type KeyValueStoreConfig struct {
Name string `json:"name" yaml:"name"`
}
type MainTemplateArgs ¶ added in v0.6.0
type ParseRequestCmd ¶ added in v0.2.0
type ParseRequestCmd struct{}
type ParseResponseCmd ¶ added in v0.2.0
type ParseResponseCmd struct{}
type PublishCmd ¶ added in v0.0.8
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 ¶ added in v0.2.0
func (*TestCase) ExpectBytes ¶ added in v0.2.0
func (*TestCase) Identifier ¶ added in v0.0.5
type TestCmd ¶ added in v0.0.5
type UtilCmd ¶ added in v0.2.0
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 ¶ added in v0.0.5
type VersionCmd struct{}