forked from imjerrybao/apex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
env.go
35 lines (26 loc) · 744 Bytes
/
env.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
// Package env populates .env.json if the function has any environment variables defined.
package env
import (
"encoding/json"
"github.com/apex/apex/archive"
"github.com/apex/apex/function"
)
func init() {
function.RegisterPlugin("env", &Plugin{})
}
// FileName of file with environment variables.
const FileName = ".env.json"
// Plugin implementation.
type Plugin struct{}
// Build hook adds .env.json populate with Function.Enironment.
func (p *Plugin) Build(fn *function.Function, zip *archive.Zip) error {
if len(fn.Environment) == 0 {
return nil
}
fn.Log.WithField("env", fn.Environment).Debug("adding env")
env, err := json.Marshal(fn.Environment)
if err != nil {
return err
}
return zip.AddBytes(FileName, env)
}