forked from rancher/cniglue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conf.go
43 lines (34 loc) · 970 Bytes
/
conf.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
package glue
import (
"encoding/json"
"os"
"path"
"github.com/docker/engine-api/types/container"
"github.com/opencontainers/specs/specs-go"
)
type DockerPluginState struct {
ContainerID string
State specs.State
Spec specs.Spec
HostConfig container.HostConfig
Config container.Config
}
func ReadState() (*DockerPluginState, error) {
pluginState := DockerPluginState{}
config := struct {
ID string
Config container.Config
}{}
if err := json.NewDecoder(os.Stdin).Decode(&pluginState.State); err != nil {
return nil, err
}
if err := readJSONFile(os.Getenv("DOCKER_HOST_CONFIG"), &pluginState.HostConfig); err != nil {
return nil, err
}
if err := readJSONFile(os.Getenv("DOCKER_CONFIG"), &config); err != nil {
return nil, err
}
pluginState.Config = config.Config
pluginState.ContainerID = config.ID
return &pluginState, readJSONFile(path.Join(pluginState.State.BundlePath, "config.json"), &pluginState.Spec)
}