forked from aws/aws-lambda-runtime-interface-emulator
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsimple_bootstrap.go
More file actions
69 lines (56 loc) · 1.98 KB
/
simple_bootstrap.go
File metadata and controls
69 lines (56 loc) · 1.98 KB
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
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package main
import (
"fmt"
"os"
"path/filepath"
"go.amzn.com/lambda/fatalerror"
"go.amzn.com/lambda/interop"
"go.amzn.com/lambda/rapidcore/env"
)
// the type implement a simpler version of the Bootstrap
// this is useful in the Standalone Core implementation.
type simpleBootstrap struct {
cmd []string
workingDir string
}
func NewSimpleBootstrap(cmd []string, currentWorkingDir string) interop.Bootstrap {
if currentWorkingDir == "" {
// use the root directory as the default working directory
currentWorkingDir = "/"
}
// a single candidate command makes it automatically valid
return &simpleBootstrap{
cmd: cmd,
workingDir: currentWorkingDir,
}
}
func (b *simpleBootstrap) Cmd() ([]string, error) {
return b.cmd, nil
}
// Cwd returns the working directory of the bootstrap process
// The path is validated against the chroot identified by `root`
func (b *simpleBootstrap) Cwd() (string, error) {
if !filepath.IsAbs(b.workingDir) {
return "", fmt.Errorf("the working directory '%s' is invalid, it needs to be an absolute path", b.workingDir)
}
// evaluate the path relatively to the domain's mnt namespace root
if _, err := os.Stat(b.workingDir); os.IsNotExist(err) {
return "", fmt.Errorf("the working directory doesn't exist: %s", b.workingDir)
}
return b.workingDir, nil
}
// Env returns the environment variables available to
// the bootstrap process
func (b *simpleBootstrap) Env(e *env.Environment) map[string]string {
return e.RuntimeExecEnv()
}
// ExtraFiles returns the extra file descriptors apart from 1 & 2 to be passed to runtime
func (b *simpleBootstrap) ExtraFiles() []*os.File {
return make([]*os.File, 0)
}
func (b *simpleBootstrap) CachedFatalError(err error) (fatalerror.ErrorType, string, bool) {
// not implemented as it is not needed in Core but we need to fullfil the interface anyway
return fatalerror.ErrorType(""), "", false
}