Documentation
¶
Overview ¶
distro.go has functions for identifying Linux distribution type and version. Currently handles some CentOS, Ubuntu, and Debian versions.
imagedata.go has funcitons that deal with the contents of images, including Linux distribution identification and application package names, versions, and architectures.
metadata.go has functions to gather and save metadata about a Docker image, including its ID, Author, Parent, Creation time, etc.
registryauth.go has functions for Docker registry authentication and Docker Hub authentication and indexing.
Index ¶
- Constants
- Variables
- func GetImageAllData(pulledImages ImageSet) (outMapMap map[string]map[string]interface{})
- func GetImageMetadata(oldMetadataSet MetadataSet) (tagSlice []TagInfo, metadataSlice []ImageMetadataInfo)
- func GetImageMetadataTokenAuthV1(oldMetadataSet MetadataSet) (tagSlice []TagInfo, metadataSlice []ImageMetadataInfo)
- func GetImageToMDMap(imageMDs []ImageMetadataInfo) (imageToMDMap map[string][]ImageMetadataInfo)
- func GetNewImageMetadata(oldMetadataSet MetadataSet) (tagSlice []TagInfo, metadataSlice []ImageMetadataInfo, ...)
- func GetRegistryURL() (URL string, hubAPI bool, BasicAuth string, XRegistryAuth string)
- func NewDockerTransport(proto, addr string) (tr *http.Transport, e error)
- func NewTLSTransport(hostpath string, certfile, cafile, keyfile string) (transport *http.Transport, err error)
- func PullImage(metadata ImageMetadataInfo)
- func RegAuth(registry string) (basicAuth, fullRegistry, authConfig string)
- func RegistryQuery(client *http.Client, URL, basicAuth string) (response []byte, e error)
- func RegistryRequestWithToken(client *http.Client, URL string, dockerToken string) (response []byte, e error)
- func RemoveImages(PulledImages []ImageMetadataInfo, imageToMDMap map[string][]ImageMetadataInfo)
- func RemoveObsoleteMetadata(obsolete []ImageMetadataInfo)
- func SaveImageAllData(outMapMap map[string]map[string]interface{})
- func SaveImageMetadata(metadataSlice []ImageMetadataInfo)
- func ValidRepoName(name string) bool
- type AuthConfig
- type ByDateTime
- type Container
- type DockerAuth
- type DockerAuthSet
- type DockerConfigJSON
- type FileWriter
- type HTTPStatusCodeError
- type HostConfig
- type ImageDataInfo
- type ImageIDType
- type ImageMetadataAndAction
- type ImageMetadataInfo
- type ImageSet
- type ImageStruct
- type ImageToMetadataMap
- type IndexInfo
- type IndexInfoMap
- type MetadataSet
- type RepoTagType
- type RepoType
- type Script
- type ScriptInfo
- type TagInfo
- type TagType
- type V1Compat
- type V2Manifest
- type V2Tag
- type Writer
Constants ¶
const ( // HTTPTIMEOUT is the time to wait for an HTTP request to complete before giving up. HTTPTIMEOUT = 32 * time.Second // TARGETCONTAINERDIR is the path in the target container where the exported binaries and scripts are located. TARGETCONTAINERDIR = "/banyancollector" )
const (
PKGEXTRACTSCRIPT = "pkgextractscript.sh"
)
Variables ¶
var ( // DockerTransport points to the http transport used to connect to the docker unix socket DockerTransport *http.Transport DockerTLSVerify = true DockerProto = "unix" DockerAddr = dummydomain )
var ( ReposToProcess = make(map[RepoType]bool) ExcludeRepo = func() map[RepoType]bool { excludeList := []RepoType{} m := make(map[RepoType]bool) for _, r := range excludeList { m[r] = true } return m }() )
var ( // HubAPI indicates whether to use the Docker Hub API. HubAPI bool HTTPSRegistry = flag.Bool([]string{"-registryhttps"}, true, "Set to false if registry does not need HTTPS (SSL/TLS)") AuthRegistry = flag.Bool([]string{"-registryauth"}, true, "Set to false if registry does not need authentication") RegistryProto = flag.String([]string{"-registryproto"}, "v1", "Select the registry protocol to use: v1, v2, quay") RegistryTokenAuth = flag.Bool([]string{"-registrytokenauth"}, false, "Registry uses v1 Token Auth, e.g., Docker Hub, Google Container Registry") RegistryTLSNoVerify = flag.Bool([]string{"-registrytlsnoverify"}, false, "True to trust the registry without verifying certificate") // registryspec is the host.domainname of the registry RegistrySpec string // registryAPIURL is the http(s)://[user:password@]host.domainname of the registry RegistryAPIURL string // XRegistryAuth is the base64-encoded AuthConfig object (for X-Registry-Auth HTTP request header) XRegistryAuth string // BasicAuth is the base64-encoded Auth field read from $HOME/.dockercfg BasicAuth string // DockerConfig is the name of the config file containing registry authentication information. DockerConfig string )
var ( //userScriptsDir = flag.String([]string{"userscriptsdir"}, config.BANYANDIR()+"/hosttarget/userscripts", "Directory with all user-specified scripts") UserScriptStore = flag.String([]string{"u", "-userscriptstore"}, config.COLLECTORDIR()+"/data/userscripts", "Directory with all user-specified scripts") UserScriptsDir = config.BANYANDIR() + "/hosttarget/userscripts" DefaultScriptsDir = config.BANYANDIR() + "/hosttarget/defaultscripts" BinDir = config.BANYANDIR() + "/hosttarget/bin" )
var DistroMap = map[string]string{
"Ubuntu 15.10": "UBUNTU-wily",
"Ubuntu 15.04": "UBUNTU-vivid",
"Ubuntu 14.10": "UBUNTU-utopic",
"Ubuntu Utopic Unicorn (development branch)": "UBUNTU-utopic",
"Ubuntu 14.04.2 LTS": "UBUNTU-trusty",
"Ubuntu 14.04.1 LTS": "UBUNTU-trusty",
"Ubuntu 14.04 LTS": "UBUNTU-trusty",
"Ubuntu 12.04 LTS": "UBUNTU-precise",
"Ubuntu precise (12.04.5 LTS)": "UBUNTU-precise",
"Ubuntu precise (12.04.4 LTS)": "UBUNTU-precise",
"Ubuntu precise (12.04.3 LTS)": "UBUNTU-precise",
"Ubuntu precise (12.04.2 LTS)": "UBUNTU-precise",
"Ubuntu precise (12.04.1 LTS)": "UBUNTU-precise",
"Ubuntu 10.04.1 LTS": "UBUNTU-lucid",
"Ubuntu 10.04.2 LTS": "UBUNTU-lucid",
"Ubuntu 10.04.3 LTS": "UBUNTU-lucid",
"Ubuntu 10.04.4 LTS": "UBUNTU-lucid",
"Ubuntu 13.10": "UBUNTU-saucy",
"Ubuntu 13.04": "UBUNTU-raring",
"Ubuntu 12.10": "UBUNTU-quantal",
"Ubuntu 11.10": "UBUNTU-oneiric",
"Ubuntu 11.04": "UBUNTU-natty",
"Ubuntu 10.10": "UBUNTU-maverick",
"Ubuntu 10.04": "UBUNTU-lucid",
"CentOS Linux 7 (Core)": "REDHAT-7Server",
"Debian GNU/Linux 7 (wheezy)": "DEBIAN-wheezy",
"Debian 6.0.10": "DEBIAN-squeeze",
"Debian GNU/Linux 8 (jessie)": "DEBIAN-jessie",
"Debian GNU/Linux stretch/sid": "DEBIAN-stretch-sid",
}
DistroMap is a reference that maps each pretty name to the corresponding distribution name.
var (
WriterList []Writer
)
Functions ¶
func GetImageAllData ¶
GetImageAllData extracts content info from each pulled image. Currently it gets system package info.
func GetImageMetadata ¶
func GetImageMetadata(oldMetadataSet MetadataSet) (tagSlice []TagInfo, metadataSlice []ImageMetadataInfo)
GetImageMetadata returns repository/tag/image metadata queried from a Docker registry. If the user has specified the repositories to examine, then no other repositories are examined. If the user has not specified repositories, then the registry search API is used to get the list of all repositories in the registry.
func GetImageMetadataTokenAuthV1 ¶ added in v0.5.4
func GetImageMetadataTokenAuthV1(oldMetadataSet MetadataSet) (tagSlice []TagInfo, metadataSlice []ImageMetadataInfo)
GetImageMetadataTokenAuthV1 returns repositories/tags/image metadata from the Docker Hub or other registry using v1 token authorization. The user must have specified a set of repositories of interest. The function queries the index server, e.g., Docker Hub, to get the token and registry, and then uses the token to query the registry.
func GetImageToMDMap ¶
func GetImageToMDMap(imageMDs []ImageMetadataInfo) (imageToMDMap map[string][]ImageMetadataInfo)
GetImageToMDMap takes image metadata structs and produces a map of imageID to metadata struct.
func GetNewImageMetadata ¶
func GetNewImageMetadata(oldMetadataSet MetadataSet) (tagSlice []TagInfo, metadataSlice []ImageMetadataInfo, currentMetadataSet MetadataSet)
GetNewImageMetadata takes the set of existing images, queries the registry to find any changes, and then brings the Output Writer up to date by telling it the obsolete metadata to delete and the new metadata to add.
func GetRegistryURL ¶
GetRegistryURL determines the full URL, with or without HTTP Basic Auth, needed to access the registry or Docker Hub.
func NewDockerTransport ¶
NewDockerTransport creates an HTTP transport to the Docker unix/tcp socket.
func NewTLSTransport ¶
func PullImage ¶
func PullImage(metadata ImageMetadataInfo)
PullImage performs a docker pull on an image specified by repo/tag. TODO: Detect if the pulled image has a different imageID than the value retrieved from metadata, and if so correct the metadata, or at least skip processing the image.
func RegAuth ¶
RegAuth takes as input the name of a registry, and it parses the contents of $HOME/.dockercfg or $HOME/.docker/config.json to return the user authentication info and registry URL. TODO: Change this to return authConfig instead of user&password, and then use X-Registry-Auth in the HTTP request header.
func RegistryQuery ¶
RegistryQuery performs an HTTP GET operation from the registry and returns the response.
func RegistryRequestWithToken ¶
func RegistryRequestWithToken(client *http.Client, URL string, dockerToken string) (response []byte, e error)
RegistryRequestWithToken queries a Docker Registry that uses v1 Token Auth, e.g., Docker Hub.
func RemoveImages ¶
func RemoveImages(PulledImages []ImageMetadataInfo, imageToMDMap map[string][]ImageMetadataInfo)
RemoveImages removes least recently pulled docker images from the local docker host.
func RemoveObsoleteMetadata ¶
func RemoveObsoleteMetadata(obsolete []ImageMetadataInfo)
RemoveObsoleteMetadata removes obsolete metadata from the Banyan service.
func SaveImageAllData ¶
SaveImageAllData saves output of all the scripts.
func SaveImageMetadata ¶
func SaveImageMetadata(metadataSlice []ImageMetadataInfo)
SaveImageMetadata saves image metadata to selected storage location (standard output, Banyan service, etc.).
func ValidRepoName ¶
ValidRepoName verifies that the name of a repo is in a legal format.
Types ¶
type AuthConfig ¶
type AuthConfig struct { Username string `json:"username,omitempty"` Password string `json:"password,omitempty"` Auth string `json:"auth"` Email string `json:"email"` ServerAddress string `json:"serveraddress,omitempty"` }
AuthConfig is a Registry auth info type copied from docker package cliconfig config.go and needed to generate the Authorization header for the Docker Remote API.
type ByDateTime ¶
type ByDateTime []ImageMetadataInfo
ByDateTime is used to sort ImageMetadataInfo slices by image age from newest to oldest.
func (ByDateTime) Len ¶
func (a ByDateTime) Len() int
func (ByDateTime) Swap ¶
func (a ByDateTime) Swap(i int, j int)
type DockerAuth ¶
type DockerAuthSet ¶
type DockerAuthSet map[string]DockerAuth
DockerAuthSet contains authentication info parsed from $HOME/.dockercfg or $HOME/.docker/config.json
type DockerConfigJSON ¶ added in v0.5.2
type DockerConfigJSON struct {
Auths DockerAuthSet
}
DockerConfigJSON is used to decode $HOME/.docker/config.json
type FileWriter ¶
type FileWriter struct {
// contains filtered or unexported fields
}
func (*FileWriter) AppendImageMetadata ¶
func (f *FileWriter) AppendImageMetadata(imageMetadata []ImageMetadataInfo)
AppendImageMetadata appends image metadata to file
func (*FileWriter) RemoveImageMetadata ¶
func (f *FileWriter) RemoveImageMetadata(imageMetadata []ImageMetadataInfo)
RemoveImageMetadata removes image metadata from file
func (*FileWriter) WriteImageAllData ¶
func (f *FileWriter) WriteImageAllData(outMapMap map[string]map[string]interface{})
WriteImageAllData writes image (pkg and other) data into file
type HTTPStatusCodeError ¶
type HTTPStatusCodeError struct { StatusCode int // contains filtered or unexported fields }
func (*HTTPStatusCodeError) Error ¶
func (s *HTTPStatusCodeError) Error() string
type HostConfig ¶
type ImageDataInfo ¶
type ImageDataInfo struct { Image string //this has to be the first field (used in order by) DistroName string //e.g., ubuntu 14.04.02 Trusty.... DistroID string //e.g., Trusty Pkg string Version string Architecture string }
ImageDataInfo describes a package included in the contents of an image.
type ImageMetadataAndAction ¶
type ImageMetadataAndAction struct { Action string ImageMetadata []ImageMetadataInfo }
type ImageMetadataInfo ¶
type ImageMetadataInfo struct { Image string //this has to be the first field (used in order by) Datetime time.Time //created at Repo string Tag string Size uint64 Author string Checksum string Comment string Parent string }
ImageMetadataInfo records basic information about an image.
type ImageSet ¶
type ImageSet map[ImageIDType]bool
ImageSet is a set of image IDs.
func (ImageSet) Exists ¶ added in v0.5.5
func (is ImageSet) Exists(imageID ImageIDType) bool
func (ImageSet) Insert ¶ added in v0.5.5
func (is ImageSet) Insert(imageID ImageIDType)
type ImageStruct ¶
type ImageStruct struct { ID string Parent string Checksum string Created string // Container string Author string Size uint64 Comment string }
ImageStruct records information returned by the registry to describe an image. This information gets copied to an object of type ImageMetadataInfo.
type ImageToMetadataMap ¶
type ImageToMetadataMap map[ImageIDType]ImageMetadataInfo
ImageToMetadataMap maps image IDs to ImageMetadataInfo structs.
func NewImageToMetadataMap ¶
func NewImageToMetadataMap(s MetadataSet) ImageToMetadataMap
NewImageToMetadataMap is a constructor for ImageToMetadataMap.
func (ImageToMetadataMap) Exists ¶
func (m ImageToMetadataMap) Exists(imageID ImageIDType) bool
Exists checks whether an image ID is present in an ImageToMetadataMap.
func (ImageToMetadataMap) Insert ¶
func (m ImageToMetadataMap) Insert(imageID ImageIDType, metadata ImageMetadataInfo)
Insert adds an image ID to an Image ID Map.
func (ImageToMetadataMap) Metadata ¶
func (m ImageToMetadataMap) Metadata(imageID ImageIDType) (metadata ImageMetadataInfo, e error)
Metadata returns the ImageMetadataInfo corresponding to an image ID if that image is present in the input ImageToMetadataMap.
type IndexInfo ¶ added in v0.5.4
IndexInfo records the index and auth information provided by Docker Hub to access a repository.
type IndexInfoMap ¶ added in v0.5.4
IndexInfoMap maps repository name to the corresponding Docker Hub auth/index info.
func NewIndexInfoMap ¶ added in v0.5.4
func NewIndexInfoMap() IndexInfoMap
NewIndexInfoMap is a constructor for IndexInfoMap.
type MetadataSet ¶
type MetadataSet map[ImageMetadataInfo]bool
MetadataSet is a set of Image Metadata Info structures.
type RepoTagType ¶
RepoTagType represents a docker repository and tag.
type Script ¶
type Script interface { //We expect YAML output from scripts that needs parsing of output by Banyan service Run(imageID ImageIDType) ([]byte, error) Name() string }
Script is the common interface to run sripts inside a container
type ScriptInfo ¶
type ScriptInfo struct {
// contains filtered or unexported fields
}
Script info for all types (e.g., bash, python, etc.)
func (ScriptInfo) Run ¶
func (sh ScriptInfo) Run(imageID ImageIDType) (b []byte, err error)
Run handles running of a script inside an image
type TagInfo ¶
type TagInfo struct { Repo RepoType TagMap map[TagType]ImageIDType }
TagInfo records the tag-to-image mappings for a single Docker repository.
type V2Manifest ¶
type V2Manifest struct {
History []V1Compat
}
type Writer ¶
type Writer interface { // Write output obtained by all the scripts to the appropriate writer plugin // Note: outMapMap maps: ImageID -> Script -> Output WriteImageAllData(outMapMap map[string]map[string]interface{}) // Append Image metadata to the appropriate writer plugin AppendImageMetadata(imageMetadata []ImageMetadataInfo) // Remoe Image metadta from the appropriate writer plugin RemoveImageMetadata(imageMetadata []ImageMetadataInfo) }
This is a writer plugin interface. Currently supported plugins are: "fileWriter": writes to a file in desired format, and "banyanWriter": invokes banyan API to send data to SAAS dashboard
func NewFileWriter ¶
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
cmd
|
|
Package config has definitions about the overall configuration of Collector.
|
Package config has definitions about the overall configuration of Collector. |
Package fsutil provides filesystem utilities."
|
Package fsutil provides filesystem utilities." |