1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Engine: fix a bug when encoding a job environment to json

This commit is contained in:
Solomon Hykes 2013-10-27 07:15:22 +00:00
parent 5a85456d48
commit 434f06d03d
2 changed files with 17 additions and 2 deletions

3
api.go
View file

@ -644,6 +644,9 @@ func postContainersStart(srv *Server, version float64, w http.ResponseWriter, r
}
name := vars["name"]
job := srv.Eng.Job("start", name)
if err := job.ImportEnv(HostConfig{}); err != nil {
return fmt.Errorf("Couldn't initialize host configuration")
}
// allow a nil body for backwards compatibility
if r.Body != nil {
if matchesContentType(r.Header.Get("Content-Type"), "application/json") {

View file

@ -149,10 +149,22 @@ func (job *Job) DecodeEnv(src io.Reader) error {
}
func (job *Job) EncodeEnv(dst io.Writer) error {
return json.NewEncoder(dst).Encode(job.Environ())
m := make(map[string]interface{})
for k, v := range job.Environ() {
var val interface{}
if err := json.Unmarshal([]byte(v), &val); err == nil {
m[k] = val
} else {
m[k] = v
}
}
if err := json.NewEncoder(dst).Encode(&m); err != nil {
return err
}
return nil
}
func (job *Job) ExportEnv(dst interface{}) error {
func (job *Job) ExportEnv(dst interface{}) (err error) {
var buf bytes.Buffer
if err := job.EncodeEnv(&buf); err != nil {
return err