diff --git a/providers/os/connection/docker_container.go b/providers/os/connection/docker_container.go index 0da495edab..6d76b564c3 100644 --- a/providers/os/connection/docker_container.go +++ b/providers/os/connection/docker_container.go @@ -372,3 +372,31 @@ func NewDockerContainerImageConnection(id uint32, conf *inventory.Config, asset tarConn.Metadata.Labels = ii.Labels return tarConn, nil } + +// based on the target, try and find out what kind of connection we are dealing with, this can be either a +// 1. a container, referenced by name or id +// 2. a locally present image, referenced by tag or digest +// 3. a remote image, referenced by tag or digest +func FetchConnectionType(target string) (string, error) { + ded, err := docker_discovery.NewDockerEngineDiscovery() + if err != nil { + return "", err + } + + if ded != nil { + _, err = ded.ContainerInfo(target) + if err == nil { + return "docker-container", nil + } + _, err = ded.ImageInfo(target) + if err == nil { + return "docker-image", nil + } + } + _, err = name.ParseReference(target, name.WeakValidation) + if err == nil { + return "docker-image", nil + } + + return "", errors.New("could not find container or image " + target) +} diff --git a/providers/os/provider/provider.go b/providers/os/provider/provider.go index 51a157f04d..aa8f7a7273 100644 --- a/providers/os/provider/provider.go +++ b/providers/os/provider/provider.go @@ -88,7 +88,31 @@ func (s *Service) ParseCLI(req *plugin.ParseCLIReq) (*plugin.ParseCLIRes, error) port = 5985 case "vagrant": conf.Type = "vagrant" - case "container", "docker": + case "docker": + if len(req.Args) > 1 { + switch req.Args[0] { + case "image": + conf.Type = "docker-image" + conf.Host = req.Args[1] + case "registry": + conf.Type = "docker-registry" + conf.Host = req.Args[1] + case "tar": + conf.Type = "docker-snapshot" + conf.Path = req.Args[1] + case "container": + conf.Type = "docker-container" + conf.Host = req.Args[1] + } + } else { + connType, err := connection.FetchConnectionType(req.Args[0]) + if err != nil { + return nil, err + } + conf.Type = connType + containerID = req.Args[0] + } + case "container": if len(req.Args) > 1 { switch req.Args[0] { case "image":