2014-03-07 20:36:47 -05:00
|
|
|
package image
|
2013-03-18 03:15:35 -04:00
|
|
|
|
|
|
|
import (
|
2015-07-20 13:57:15 -04:00
|
|
|
"encoding/json"
|
2013-03-18 03:15:35 -04:00
|
|
|
"fmt"
|
2015-03-29 17:17:23 -04:00
|
|
|
"regexp"
|
2015-07-20 13:57:15 -04:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/docker/docker/runconfig"
|
2013-03-18 03:15:35 -04:00
|
|
|
)
|
|
|
|
|
2015-05-13 14:42:45 -04:00
|
|
|
var validHex = regexp.MustCompile(`^([a-f0-9]{64})$`)
|
|
|
|
|
2015-07-20 13:57:15 -04:00
|
|
|
type Image struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
Parent string `json:"parent,omitempty"`
|
|
|
|
Comment string `json:"comment,omitempty"`
|
|
|
|
Created time.Time `json:"created"`
|
|
|
|
Container string `json:"container,omitempty"`
|
|
|
|
ContainerConfig runconfig.Config `json:"container_config,omitempty"`
|
|
|
|
DockerVersion string `json:"docker_version,omitempty"`
|
|
|
|
Author string `json:"author,omitempty"`
|
|
|
|
Config *runconfig.Config `json:"config,omitempty"`
|
|
|
|
Architecture string `json:"architecture,omitempty"`
|
|
|
|
OS string `json:"os,omitempty"`
|
|
|
|
Size int64
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build an Image object from raw json data
|
|
|
|
func NewImgJSON(src []byte) (*Image, error) {
|
|
|
|
ret := &Image{}
|
|
|
|
|
|
|
|
// FIXME: Is there a cleaner way to "purify" the input json?
|
|
|
|
if err := json.Unmarshal(src, ret); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return ret, nil
|
|
|
|
}
|
|
|
|
|
2015-03-29 17:17:23 -04:00
|
|
|
// Check wheather id is a valid image ID or not
|
|
|
|
func ValidateID(id string) error {
|
|
|
|
if ok := validHex.MatchString(id); !ok {
|
2015-04-26 12:50:25 -04:00
|
|
|
return fmt.Errorf("image ID '%s' is invalid", id)
|
2015-03-29 17:17:23 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|