2014-03-07 20:36:47 -05:00
|
|
|
package image
|
2013-03-18 03:15:35 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2015-03-29 17:17:23 -04:00
|
|
|
"regexp"
|
2013-03-18 03:15:35 -04:00
|
|
|
"time"
|
2014-07-24 16:37:44 -04:00
|
|
|
|
|
|
|
"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})$`)
|
|
|
|
|
2013-03-18 03:15:35 -04:00
|
|
|
type Image struct {
|
2014-02-11 23:04:39 -05:00
|
|
|
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"`
|
2013-05-13 09:10:26 -04:00
|
|
|
Size int64
|
2014-08-14 20:43:12 -04:00
|
|
|
}
|
|
|
|
|
2013-05-14 21:41:39 -04:00
|
|
|
// Build an Image object from raw json data
|
2013-06-04 14:00:22 -04:00
|
|
|
func NewImgJSON(src []byte) (*Image, error) {
|
2013-05-14 21:41:39 -04:00
|
|
|
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
|
|
|
|
}
|