github.com/r3labs/libcompose@v0.4.1-0.20171123133234-495fe0619cc3/docker/auth/auth.go (about)

     1  package auth
     2  
     3  import (
     4  	"github.com/docker/cli/cli/config/configfile"
     5  	"github.com/docker/docker/api/types"
     6  	"github.com/docker/docker/registry"
     7  )
     8  
     9  // Lookup defines a method for looking up authentication information
    10  type Lookup interface {
    11  	All() map[string]types.AuthConfig
    12  	Lookup(repoInfo *registry.RepositoryInfo) types.AuthConfig
    13  }
    14  
    15  // ConfigLookup implements AuthLookup by reading a Docker config file
    16  type ConfigLookup struct {
    17  	*configfile.ConfigFile
    18  }
    19  
    20  // NewConfigLookup creates a new ConfigLookup for a given context
    21  func NewConfigLookup(configfile *configfile.ConfigFile) *ConfigLookup {
    22  	return &ConfigLookup{
    23  		ConfigFile: configfile,
    24  	}
    25  }
    26  
    27  // Lookup uses a Docker config file to lookup authentication information
    28  func (c *ConfigLookup) Lookup(repoInfo *registry.RepositoryInfo) types.AuthConfig {
    29  	if c.ConfigFile == nil || repoInfo == nil || repoInfo.Index == nil {
    30  		return types.AuthConfig{}
    31  	}
    32  	return registry.ResolveAuthConfig(c.ConfigFile.AuthConfigs, repoInfo.Index)
    33  }
    34  
    35  // All uses a Docker config file to get all authentication information
    36  func (c *ConfigLookup) All() map[string]types.AuthConfig {
    37  	if c.ConfigFile == nil {
    38  		return map[string]types.AuthConfig{}
    39  	}
    40  	return c.ConfigFile.AuthConfigs
    41  }