2014-02-24 19:48:14 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2014-05-12 22:26:23 +00:00
|
|
|
"mime"
|
|
|
|
"strings"
|
|
|
|
|
2014-07-24 22:19:50 +00:00
|
|
|
"github.com/docker/docker/engine"
|
|
|
|
"github.com/docker/docker/pkg/version"
|
|
|
|
"github.com/docker/docker/utils"
|
2014-02-24 19:48:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2014-07-08 18:37:08 +00:00
|
|
|
APIVERSION version.Version = "1.14"
|
2014-04-01 22:46:52 +00:00
|
|
|
DEFAULTHTTPHOST = "127.0.0.1"
|
|
|
|
DEFAULTUNIXSOCKET = "/var/run/docker.sock"
|
2014-02-24 19:48:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func ValidateHost(val string) (string, error) {
|
|
|
|
host, err := utils.ParseHost(DEFAULTHTTPHOST, DEFAULTUNIXSOCKET, val)
|
|
|
|
if err != nil {
|
|
|
|
return val, err
|
|
|
|
}
|
|
|
|
return host, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO remove, used on < 1.5 in getContainersJSON
|
2014-03-28 22:59:29 +00:00
|
|
|
func DisplayablePorts(ports *engine.Table) string {
|
2014-02-24 19:48:14 +00:00
|
|
|
result := []string{}
|
2014-03-16 16:28:13 +00:00
|
|
|
ports.SetKey("PublicPort")
|
|
|
|
ports.Sort()
|
2014-02-24 19:48:14 +00:00
|
|
|
for _, port := range ports.Data {
|
|
|
|
if port.Get("IP") == "" {
|
2014-05-12 22:26:23 +00:00
|
|
|
result = append(result, fmt.Sprintf("%d/%s", port.GetInt("PrivatePort"), port.Get("Type")))
|
2014-02-24 19:48:14 +00:00
|
|
|
} else {
|
|
|
|
result = append(result, fmt.Sprintf("%s:%d->%d/%s", port.Get("IP"), port.GetInt("PublicPort"), port.GetInt("PrivatePort"), port.Get("Type")))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return strings.Join(result, ", ")
|
|
|
|
}
|
|
|
|
|
|
|
|
func MatchesContentType(contentType, expectedType string) bool {
|
|
|
|
mimetype, _, err := mime.ParseMediaType(contentType)
|
|
|
|
if err != nil {
|
|
|
|
utils.Errorf("Error parsing media type: %s error: %s", contentType, err.Error())
|
|
|
|
}
|
|
|
|
return err == nil && mimetype == expectedType
|
|
|
|
}
|