improve GetenvJson
Upstream-commit: d5f5ecb658c7a6a0f04939061494c9d404d393ce Component: engine
This commit is contained in:
@ -77,15 +77,12 @@ func (env *Env) GetList(key string) []string {
|
||||
return l
|
||||
}
|
||||
|
||||
func (env *Env) GetJson(key string) interface{} {
|
||||
func (env *Env) GetJson(key string, iface interface{}) error {
|
||||
sval := env.Get(key)
|
||||
if sval == "" {
|
||||
return nil
|
||||
}
|
||||
var m interface{}
|
||||
//Discard error on purpose
|
||||
json.Unmarshal([]byte(sval), &m)
|
||||
return m
|
||||
return json.Unmarshal([]byte(sval), iface)
|
||||
}
|
||||
|
||||
func (env *Env) SetJson(key string, value interface{}) error {
|
||||
|
||||
@ -126,8 +126,8 @@ func (job *Job) GetenvList(key string) []string {
|
||||
return job.env.GetList(key)
|
||||
}
|
||||
|
||||
func (job *Job) GetenvJson(key string) interface{} {
|
||||
return job.env.GetJson(key)
|
||||
func (job *Job) GetenvJson(key string, iface interface{}) error {
|
||||
return job.env.GetJson(key, iface)
|
||||
}
|
||||
|
||||
func (job *Job) SetenvJson(key string, value interface{}) error {
|
||||
|
||||
@ -785,13 +785,13 @@ func (srv *Server) ContainerCommit(job *engine.Job) engine.Status {
|
||||
job.Errorf("No such container: %s", name)
|
||||
return engine.StatusErr
|
||||
}
|
||||
var config *Config
|
||||
iConfig, ok := job.GetenvJson("config").(Config)
|
||||
if ok {
|
||||
config = &iConfig
|
||||
var config Config
|
||||
if err := job.GetenvJson("config", &config); err != nil {
|
||||
job.Error(err)
|
||||
return engine.StatusErr
|
||||
}
|
||||
|
||||
img, err := srv.runtime.Commit(container, job.Getenv("repo"), job.Getenv("tag"), job.Getenv("comment"), job.Getenv("author"), config)
|
||||
img, err := srv.runtime.Commit(container, job.Getenv("repo"), job.Getenv("tag"), job.Getenv("comment"), job.Getenv("author"), &config)
|
||||
if err != nil {
|
||||
job.Error(err)
|
||||
return engine.StatusErr
|
||||
|
||||
Reference in New Issue
Block a user