mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
d942c59b69
When we use the engine/env object we can run into a situation where a string is passed in as the value but later on when we json serialize the name/value pairs, because the string is made up of just numbers it appears as an integer and not a string - meaning no quotes. This can cause parsing issues for clients. I tried to find all spots where we call env.Set() and the type of the name being set might end up having a value that could look like an int (like author). In those cases I switched it to use env.SetJson() instead because that will wrap it in quotes. One interesting thing to note about the testcase that I modified is that the escaped quotes should have been there all along and we were incorrectly letting it thru. If you look at the metadata stored for that resource you can see the quotes were escaped and we lost them during the serialization steps because of the env.Set() stuff. The use of env is probably not the best way to do all of this. Closes: #9602 Signed-off-by: Doug Davis <dug@us.ibm.com>
86 lines
2.4 KiB
Go
86 lines
2.4 KiB
Go
package daemon
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/docker/docker/engine"
|
|
"github.com/docker/docker/runconfig"
|
|
)
|
|
|
|
func (daemon *Daemon) ContainerInspect(job *engine.Job) engine.Status {
|
|
if len(job.Args) != 1 {
|
|
return job.Errorf("usage: %s NAME", job.Name)
|
|
}
|
|
name := job.Args[0]
|
|
if container := daemon.Get(name); container != nil {
|
|
container.Lock()
|
|
defer container.Unlock()
|
|
if job.GetenvBool("raw") {
|
|
b, err := json.Marshal(&struct {
|
|
*Container
|
|
HostConfig *runconfig.HostConfig
|
|
}{container, container.hostConfig})
|
|
if err != nil {
|
|
return job.Error(err)
|
|
}
|
|
job.Stdout.Write(b)
|
|
return engine.StatusOK
|
|
}
|
|
|
|
out := &engine.Env{}
|
|
out.SetJson("Id", container.ID)
|
|
out.SetAuto("Created", container.Created)
|
|
out.SetJson("Path", container.Path)
|
|
out.SetList("Args", container.Args)
|
|
out.SetJson("Config", container.Config)
|
|
out.SetJson("State", container.State)
|
|
out.SetJson("Image", container.Image)
|
|
out.SetJson("NetworkSettings", container.NetworkSettings)
|
|
out.Set("ResolvConfPath", container.ResolvConfPath)
|
|
out.Set("HostnamePath", container.HostnamePath)
|
|
out.Set("HostsPath", container.HostsPath)
|
|
out.SetJson("Name", container.Name)
|
|
out.SetInt("RestartCount", container.RestartCount)
|
|
out.Set("Driver", container.Driver)
|
|
out.Set("ExecDriver", container.ExecDriver)
|
|
out.Set("MountLabel", container.MountLabel)
|
|
out.Set("ProcessLabel", container.ProcessLabel)
|
|
out.SetJson("Volumes", container.Volumes)
|
|
out.SetJson("VolumesRW", container.VolumesRW)
|
|
out.SetJson("AppArmorProfile", container.AppArmorProfile)
|
|
|
|
if children, err := daemon.Children(container.Name); err == nil {
|
|
for linkAlias, child := range children {
|
|
container.hostConfig.Links = append(container.hostConfig.Links, fmt.Sprintf("%s:%s", child.Name, linkAlias))
|
|
}
|
|
}
|
|
|
|
out.SetJson("HostConfig", container.hostConfig)
|
|
|
|
container.hostConfig.Links = nil
|
|
if _, err := out.WriteTo(job.Stdout); err != nil {
|
|
return job.Error(err)
|
|
}
|
|
return engine.StatusOK
|
|
}
|
|
return job.Errorf("No such container: %s", name)
|
|
}
|
|
|
|
func (daemon *Daemon) ContainerExecInspect(job *engine.Job) engine.Status {
|
|
if len(job.Args) != 1 {
|
|
return job.Errorf("usage: %s ID", job.Name)
|
|
}
|
|
id := job.Args[0]
|
|
eConfig, err := daemon.getExecConfig(id)
|
|
if err != nil {
|
|
return job.Error(err)
|
|
}
|
|
|
|
b, err := json.Marshal(*eConfig)
|
|
if err != nil {
|
|
return job.Error(err)
|
|
}
|
|
job.Stdout.Write(b)
|
|
return engine.StatusOK
|
|
}
|