本文整理汇总了Golang中github.com/docker/docker/pkg/homedir.Get函数的典型用法代码示例。如果您正苦于以下问题:Golang Get函数的具体用法?Golang Get怎么用?Golang Get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Get函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: getDaemonConfDir
func getDaemonConfDir() string {
// TODO: update for Windows daemon
if runtime.GOOS == "windows" {
return filepath.Join(homedir.Get(), ".docker")
}
return "/etc/docker"
}
开发者ID:hgschmie,项目名称:docker,代码行数:7,代码来源:flags.go
示例2: LoadConfigFile
func (cli *DockerCli) LoadConfigFile() (err error) {
cli.configFile, err = registry.LoadConfig(homedir.Get())
if err != nil {
fmt.Fprintf(cli.err, "WARNING: %s\n", err)
}
return err
}
开发者ID:balagopalraj,项目名称:clearlinux,代码行数:7,代码来源:cli.go
示例3: NewHyperClient
func NewHyperClient(proto, addr string, tlsConfig *tls.Config) *HyperClient {
var (
inFd uintptr
outFd uintptr
isTerminalIn = false
isTerminalOut = false
)
clifile, err := cliconfig.Load(filepath.Join(homedir.Get(), ".docker"))
if err != nil {
fmt.Fprintf(os.Stdout, "WARNING: Error loading config file %v\n", err)
}
inFd, isTerminalIn = term.GetFdInfo(os.Stdin)
outFd, isTerminalOut = term.GetFdInfo(os.Stdout)
return &HyperClient{
client: api.NewClient(proto, addr, tlsConfig),
in: os.Stdin,
out: os.Stdout,
err: os.Stdout,
inFd: inFd,
outFd: outFd,
isTerminalIn: isTerminalIn,
isTerminalOut: isTerminalOut,
configFile: clifile,
}
}
开发者ID:thed00de,项目名称:hyperd,代码行数:28,代码来源:client.go
示例4: TestOldInvalidsAuth
func TestOldInvalidsAuth(t *testing.T) {
invalids := map[string]string{
`username = test`: "The Auth config file is empty",
`username
password`: "Invalid Auth config file",
`username = test
email`: "Invalid auth configuration file",
}
tmpHome, err := ioutil.TempDir("", "config-test")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpHome)
homeKey := homedir.Key()
homeVal := homedir.Get()
defer func() { os.Setenv(homeKey, homeVal) }()
os.Setenv(homeKey, tmpHome)
for content, expectedError := range invalids {
fn := filepath.Join(tmpHome, oldConfigfile)
if err := ioutil.WriteFile(fn, []byte(content), 0600); err != nil {
t.Fatal(err)
}
config, err := Load(tmpHome)
// Use Contains instead of == since the file name will change each time
if err == nil || !strings.Contains(err.Error(), expectedError) {
t.Fatalf("Should have failed\nConfig: %v\nGot: %v\nExpected: %v", config, err, expectedError)
}
}
}
开发者ID:docker,项目名称:docker,代码行数:35,代码来源:config_test.go
示例5: preload
// preload initializes any global options and configuration
// before the main or sub commands are run
func preload(c *cli.Context) (err error) {
if c.GlobalBool("debug") {
logrus.SetLevel(logrus.DebugLevel)
}
defaultGPGKey = c.GlobalString("keyid")
home := homedir.Get()
homeShort := homedir.GetShortcutString()
// set the filestore variable
filestore = strings.Replace(c.GlobalString("file"), homeShort, home, 1)
// set gpg path variables
gpgPath = strings.Replace(c.GlobalString("gpgpath"), homeShort, home, 1)
publicKeyring = filepath.Join(gpgPath, "pubring.gpg")
secretKeyring = filepath.Join(gpgPath, "secring.gpg")
// if they passed an arguement, run the prechecks
// TODO(jfrazelle): this will run even if the command they issue
// does not exist, which is kinda shitty
if len(c.Args()) > 0 {
preChecks()
}
// we need to read the secrets file for all commands
// might as well be dry about it
s, err = readSecretsFile(filestore)
if err != nil {
logrus.Fatal(err)
}
return nil
}
开发者ID:juliengk,项目名称:pony,代码行数:36,代码来源:main.go
示例6: TestOldJSONInvalid
func TestOldJSONInvalid(t *testing.T) {
tmpHome, err := ioutil.TempDir("", "config-test")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpHome)
homeKey := homedir.Key()
homeVal := homedir.Get()
defer func() { os.Setenv(homeKey, homeVal) }()
os.Setenv(homeKey, tmpHome)
fn := filepath.Join(tmpHome, oldConfigfile)
js := `{"https://index.docker.io/v1/":{"auth":"test","email":"[email protected]"}}`
if err := ioutil.WriteFile(fn, []byte(js), 0600); err != nil {
t.Fatal(err)
}
config, err := Load(tmpHome)
// Use Contains instead of == since the file name will change each time
if err == nil || !strings.Contains(err.Error(), "Invalid auth configuration file") {
t.Fatalf("Expected an error got : %v, %v", config, err)
}
}
开发者ID:docker,项目名称:docker,代码行数:25,代码来源:config_test.go
示例7: PrintDefaults
// PrintDefaults prints, to standard error unless configured
// otherwise, the default values of all defined flags in the set.
func (f *FlagSet) PrintDefaults() {
writer := tabwriter.NewWriter(f.Out(), 20, 1, 3, ' ', 0)
home := homedir.Get()
// Don't substitute when HOME is /
if runtime.GOOS != "windows" && home == "/" {
home = ""
}
f.VisitAll(func(flag *Flag) {
format := " -%s=%s"
names := []string{}
for _, name := range flag.Names {
if name[0] != '#' {
names = append(names, name)
}
}
if len(names) > 0 {
val := flag.DefValue
if home != "" && strings.HasPrefix(val, home) {
val = homedir.GetShortcutString() + val[len(home):]
}
fmt.Fprintf(writer, format, strings.Join(names, ", -"), val)
for i, line := range strings.Split(flag.Usage, "\n") {
if i != 0 {
line = " " + line
}
fmt.Fprintln(writer, "\t", line)
}
}
})
writer.Flush()
}
开发者ID:yckrasnodar,项目名称:docker,代码行数:36,代码来源:flag.go
示例8: getAuthConfig
func (s *executor) getAuthConfig(imageName string) (docker.AuthConfiguration, error) {
homeDir := homedir.Get()
if s.Shell().User != "" {
u, err := user.Lookup(s.Shell().User)
if err != nil {
return docker.AuthConfiguration{}, err
}
homeDir = u.HomeDir
}
if homeDir == "" {
return docker.AuthConfiguration{}, fmt.Errorf("Failed to get home directory")
}
indexName, _ := docker_helpers.SplitDockerImageName(imageName)
authConfigs, err := docker_helpers.ReadDockerAuthConfigs(homeDir)
if err != nil {
// ignore doesn't exist errors
if os.IsNotExist(err) {
err = nil
}
return docker.AuthConfiguration{}, err
}
authConfig := docker_helpers.ResolveDockerAuthConfig(indexName, authConfigs)
if authConfig != nil {
s.Debugln("Using", authConfig.Username, "to connect to", authConfig.ServerAddress, "in order to resolve", imageName, "...")
return *authConfig, nil
}
return docker.AuthConfiguration{}, fmt.Errorf("No credentials found for %v", indexName)
}
开发者ID:bssthu,项目名称:gitlab-ci-multi-runner,代码行数:32,代码来源:executor_docker.go
示例9: getDockerEnv
func getDockerEnv() (*dockerEnv, error) {
dockerHost := os.Getenv("DOCKER_HOST")
var err error
if dockerHost == "" {
dockerHost, err = getDefaultDockerHost()
if err != nil {
return nil, err
}
}
dockerTLSVerify := os.Getenv("DOCKER_TLS_VERIFY") != ""
var dockerCertPath string
if dockerTLSVerify {
dockerCertPath = os.Getenv("DOCKER_CERT_PATH")
if dockerCertPath == "" {
home := homedir.Get()
if home == "" {
return nil, errors.New("environment variable HOME must be set if DOCKER_CERT_PATH is not set")
}
dockerCertPath = filepath.Join(home, ".docker")
dockerCertPath, err = filepath.Abs(dockerCertPath)
if err != nil {
return nil, err
}
}
}
return &dockerEnv{
dockerHost: dockerHost,
dockerTLSVerify: dockerTLSVerify,
dockerCertPath: dockerCertPath,
}, nil
}
开发者ID:frewsxcv,项目名称:empire,代码行数:31,代码来源:client.go
示例10: setDefaultConfFlag
func setDefaultConfFlag(flag *string, def string) {
if *flag == "" {
if *flDaemon {
*flag = filepath.Join(getDaemonConfDir(), def)
} else {
*flag = filepath.Join(homedir.Get(), ".docker", def)
}
}
}
开发者ID:hgschmie,项目名称:docker,代码行数:9,代码来源:flags.go
示例11: CreateClient
// CreateClient creates a docker client based on the specified options.
func CreateClient(c ClientOpts) (*dockerclient.Client, error) {
if c.TLSOptions.CAFile == "" {
c.TLSOptions.CAFile = filepath.Join(dockerCertPath, defaultCaFile)
}
if c.TLSOptions.CertFile == "" {
c.TLSOptions.CertFile = filepath.Join(dockerCertPath, defaultCertFile)
}
if c.TLSOptions.KeyFile == "" {
c.TLSOptions.KeyFile = filepath.Join(dockerCertPath, defaultKeyFile)
}
if c.Host == "" {
defaultHost := os.Getenv("DOCKER_HOST")
if defaultHost == "" {
if runtime.GOOS != "windows" {
// If we do not have a host, default to unix socket
defaultHost = fmt.Sprintf("unix://%s", opts.DefaultUnixSocket)
} else {
// If we do not have a host, default to TCP socket on Windows
defaultHost = fmt.Sprintf("tcp://%s:%d", opts.DefaultHTTPHost, opts.DefaultHTTPPort)
}
}
defaultHost, err := opts.ValidateHost(defaultHost)
if err != nil {
return nil, err
}
c.Host = defaultHost
}
if c.TrustKey == "" {
c.TrustKey = filepath.Join(homedir.Get(), ".docker", defaultTrustKeyFile)
}
if c.TLSVerify {
c.TLS = true
}
if c.TLS {
c.TLSOptions.InsecureSkipVerify = !c.TLSVerify
}
apiVersion := c.APIVersion
if apiVersion == "" {
apiVersion = DefaultAPIVersion
}
if c.TLS {
client, err := dockerclient.NewVersionedTLSClient(c.Host, c.TLSOptions.CertFile, c.TLSOptions.KeyFile, c.TLSOptions.CAFile, apiVersion)
if err != nil {
return nil, err
}
if c.TLSOptions.InsecureSkipVerify {
client.TLSConfig.InsecureSkipVerify = true
}
return client, nil
}
return dockerclient.NewVersionedClient(c.Host, apiVersion)
}
开发者ID:pirater,项目名称:os,代码行数:58,代码来源:client.go
示例12: NewGpg
// NewGpg returns a new Gpg instance
func NewGpg(conf *config.Configuration) (KeyManager, error) {
home := homedir.Get()
publicKeyring := filepath.Join(home, defaultGPGPath, "pubring.gpg")
privateKeyring := filepath.Join(home, defaultGPGPath, "secring.gpg")
return &Gpg{
PublicKeyring: publicKeyring,
PrivateKeyring: privateKeyring,
Email: conf.Gpg.Email,
}, nil
}
开发者ID:nlamirault,项目名称:enigma,代码行数:11,代码来源:gpg.go
示例13: getDefaultConfigDir
func getDefaultConfigDir(confFile string) string {
confDir := filepath.Join(homedir.Get(), confFile)
// if the directory doesn't exist, maybe we called docker with sudo
if _, err := os.Stat(confDir); err != nil {
if os.IsNotExist(err) {
return filepath.Join(homedir.GetWithSudoUser(), confFile)
}
}
return confDir
}
开发者ID:lblackstone,项目名称:docker,代码行数:10,代码来源:config.go
示例14: NewHyperClient
func NewHyperClient(proto, addr string, tlsConfig *tls.Config) *HyperClient {
var (
inFd uintptr
outFd uintptr
isTerminalIn = false
isTerminalOut = false
scheme = "http"
)
if tlsConfig != nil {
scheme = "https"
}
// The transport is created here for reuse during the client session
tran := &http.Transport{
TLSClientConfig: tlsConfig,
}
// Why 32? See issue 8035
timeout := 32 * time.Second
if proto == "unix" {
// no need in compressing for local communications
tran.DisableCompression = true
tran.Dial = func(_, _ string) (net.Conn, error) {
return net.DialTimeout(proto, addr, timeout)
}
} else {
tran.Proxy = http.ProxyFromEnvironment
tran.Dial = (&net.Dialer{Timeout: timeout}).Dial
}
inFd, isTerminalIn = term.GetFdInfo(os.Stdin)
outFd, isTerminalOut = term.GetFdInfo(os.Stdout)
clifile, err := cliconfig.Load(filepath.Join(homedir.Get(), ".docker"))
if err != nil {
fmt.Fprintf(os.Stdout, "WARNING: Error loading config file %v\n", err)
}
return &HyperClient{
proto: proto,
addr: addr,
configFile: clifile,
in: os.Stdin,
out: os.Stdout,
err: os.Stdout,
inFd: inFd,
outFd: outFd,
isTerminalIn: isTerminalIn,
isTerminalOut: isTerminalOut,
scheme: scheme,
transport: tran,
}
}
开发者ID:m1911,项目名称:hyper,代码行数:54,代码来源:client.go
示例15: CreateClient
// CreateClient creates a docker client based on the specified options.
func CreateClient(c ClientOpts) (dockerclient.Client, error) {
if c.TLSOptions.CAFile == "" {
c.TLSOptions.CAFile = filepath.Join(dockerCertPath, defaultCaFile)
}
if c.TLSOptions.CertFile == "" {
c.TLSOptions.CertFile = filepath.Join(dockerCertPath, defaultCertFile)
}
if c.TLSOptions.KeyFile == "" {
c.TLSOptions.KeyFile = filepath.Join(dockerCertPath, defaultKeyFile)
}
if c.Host == "" {
defaultHost := os.Getenv("DOCKER_HOST")
if defaultHost == "" {
if runtime.GOOS != "windows" {
// If we do not have a host, default to unix socket
defaultHost = fmt.Sprintf("unix://%s", opts.DefaultUnixSocket)
} else {
// If we do not have a host, default to TCP socket on Windows
defaultHost = fmt.Sprintf("tcp://%s:%d", opts.DefaultHTTPHost, opts.DefaultHTTPPort)
}
}
defaultHost, err := opts.ValidateHost(defaultHost)
if err != nil {
return nil, err
}
c.Host = defaultHost
}
if c.TrustKey == "" {
c.TrustKey = filepath.Join(homedir.Get(), ".docker", defaultTrustKeyFile)
}
if c.TLSVerify {
c.TLS = true
}
if c.TLS {
c.TLSOptions.InsecureSkipVerify = !c.TLSVerify
}
var tlsConfig *tls.Config
if c.TLS {
var err error
tlsConfig, err = tlsconfig.Client(c.TLSOptions)
if err != nil {
return nil, err
}
}
return dockerclient.NewDockerClient(c.Host, tlsConfig)
}
开发者ID:alena1108,项目名称:rancher-compose-executor,代码行数:54,代码来源:client.go
示例16: NewDockerCli
// NewDockerCli returns a DockerCli instance with IO output and error streams set by in, out and err.
// The key file, protocol (i.e. unix) and address are passed in as strings, along with the tls.Config. If the tls.Config
// is set the client scheme will be set to https.
// The client will be given a 32-second timeout (see https://github.com/docker/docker/pull/8035).
func NewDockerCli(in io.ReadCloser, out, err io.Writer, keyFile string, proto, addr string, tlsConfig *tls.Config) *DockerCli {
var (
inFd uintptr
outFd uintptr
isTerminalIn = false
isTerminalOut = false
scheme = "http"
)
if tlsConfig != nil {
scheme = "https"
}
if in != nil {
inFd, isTerminalIn = term.GetFdInfo(in)
}
if out != nil {
outFd, isTerminalOut = term.GetFdInfo(out)
}
if err == nil {
err = out
}
// The transport is created here for reuse during the client session.
tr := &http.Transport{
TLSClientConfig: tlsConfig,
}
utils.ConfigureTCPTransport(tr, proto, addr)
configFile, e := cliconfig.Load(filepath.Join(homedir.Get(), ".docker"))
if e != nil {
fmt.Fprintf(err, "WARNING: Error loading config file:%v\n", e)
}
return &DockerCli{
proto: proto,
addr: addr,
configFile: configFile,
in: in,
out: out,
err: err,
keyFile: keyFile,
inFd: inFd,
outFd: outFd,
isTerminalIn: isTerminalIn,
isTerminalOut: isTerminalOut,
tlsConfig: tlsConfig,
scheme: scheme,
transport: tr,
}
}
开发者ID:fengbaicanhe,项目名称:docker,代码行数:56,代码来源:cli.go
示例17: TestConfigHttpHeader
func (s *DockerSuite) TestConfigHttpHeader(c *check.C) {
testRequires(c, UnixCli) // Can't set/unset HOME on windows right now
// We either need a level of Go that supports Unsetenv (for cases
// when HOME/USERPROFILE isn't set), or we need to be able to use
// os/user but user.Current() only works if we aren't statically compiling
var headers map[string][]string
server := httptest.NewServer(http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
headers = r.Header
}))
defer server.Close()
homeKey := homedir.Key()
homeVal := homedir.Get()
tmpDir, err := ioutil.TempDir("", "fake-home")
c.Assert(err, check.IsNil)
defer os.RemoveAll(tmpDir)
dotDocker := filepath.Join(tmpDir, ".docker")
os.Mkdir(dotDocker, 0600)
tmpCfg := filepath.Join(dotDocker, "config.json")
defer func() { os.Setenv(homeKey, homeVal) }()
os.Setenv(homeKey, tmpDir)
data := `{
"HttpHeaders": { "MyHeader": "MyValue" }
}`
err = ioutil.WriteFile(tmpCfg, []byte(data), 0600)
if err != nil {
c.Fatalf("Err creating file(%s): %v", tmpCfg, err)
}
cmd := exec.Command(dockerBinary, "-H="+server.URL[7:], "ps")
out, _, _ := runCommandWithOutput(cmd)
if headers["User-Agent"] == nil {
c.Fatalf("Missing User-Agent: %q\nout:%v", headers, out)
}
if headers["User-Agent"][0] != "Docker-Client/"+dockerversion.VERSION+" ("+runtime.GOOS+")" {
c.Fatalf("Badly formatted User-Agent: %q\nout:%v", headers, out)
}
if headers["Myheader"] == nil || headers["Myheader"][0] != "MyValue" {
c.Fatalf("Missing/bad header: %q\nout:%v", headers, out)
}
}
开发者ID:waterytowers,项目名称:global-hack-day-3,代码行数:51,代码来源:docker_cli_config_test.go
示例18: LoadCerts
// LoadCerts loads the certificates into c.Config, if TLS is enabled.
func (c *TLSConfig) LoadCerts() error {
if !c.IsEnabled() {
return nil
}
dockerCertPath := os.Getenv("DOCKER_CERT_PATH")
if dockerCertPath == "" {
dockerCertPath = filepath.Join(homedir.Get(), ".docker")
}
if c.CACert == "" {
c.CACert = filepath.Join(dockerCertPath, defaultCaFile)
}
if c.Cert == "" {
c.Cert = filepath.Join(dockerCertPath, defaultCertFile)
}
if c.Key == "" {
c.Key = filepath.Join(dockerCertPath, defaultKeyFile)
}
tlsConfig := &tls.Config{
NextProtos: []string{"http/1.1"},
// Avoid fallback on insecure SSL protocols
MinVersion: tls.VersionTLS10,
}
if c.Verify {
certPool := x509.NewCertPool()
file, err := ioutil.ReadFile(c.CACert)
if err != nil {
return fmt.Errorf("Couldn't read CA certificate: %v", err)
}
certPool.AppendCertsFromPEM(file)
tlsConfig.ClientAuth = tls.RequireAndVerifyClientCert
tlsConfig.ClientCAs = certPool
}
_, errCert := os.Stat(c.Cert)
_, errKey := os.Stat(c.Key)
if errCert == nil && errKey == nil {
cert, err := tls.LoadX509KeyPair(c.Cert, c.Key)
if err != nil {
return fmt.Errorf("Couldn't load X509 key pair: %q. Make sure the key is encrypted", err)
}
tlsConfig.Certificates = []tls.Certificate{cert}
}
c.Config = tlsConfig
return nil
}
开发者ID:codingbunch,项目名称:weave,代码行数:51,代码来源:tls.go
示例19: setupSharedDirs
func (d *Driver) setupSharedDirs() error {
shareDir := homedir.Get()
shareName := "Home"
if _, err := os.Stat(shareDir); err != nil && !os.IsNotExist(err) {
return err
} else if !os.IsNotExist(err) {
// add shared folder, create mountpoint and mount it.
vmrun("-gu", B2DUser, "-gp", B2DPass, "addSharedFolder", d.vmxPath(), shareName, shareDir)
vmrun("-gu", B2DUser, "-gp", B2DPass, "runScriptInGuest", d.vmxPath(), "/bin/sh", "sudo mkdir -p "+shareDir+" && sudo mount -t vmhgfs .host:/"+shareName+" "+shareDir)
}
return nil
}
开发者ID:phusl,项目名称:machine,代码行数:14,代码来源:fusion_darwin.go
示例20: TestOldValidAuth
func TestOldValidAuth(t *testing.T) {
tmpHome, err := ioutil.TempDir("", "config-test")
if err != nil {
t.Fatal(err)
}
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpHome)
homeKey := homedir.Key()
homeVal := homedir.Get()
defer func() { os.Setenv(homeKey, homeVal) }()
os.Setenv(homeKey, tmpHome)
fn := filepath.Join(tmpHome, oldConfigfile)
js := `username = am9lam9lOmhlbGxv
email = [email protected]`
if err := ioutil.WriteFile(fn, []byte(js), 0600); err != nil {
t.Fatal(err)
}
config, err := Load(tmpHome)
if err != nil {
t.Fatal(err)
}
// defaultIndexserver is https://index.docker.io/v1/
ac := config.AuthConfigs["https://index.docker.io/v1/"]
if ac.Username != "joejoe" || ac.Password != "hello" {
t.Fatalf("Missing data from parsing:\n%q", config)
}
// Now save it and make sure it shows up in new form
configStr := saveConfigAndValidateNewFormat(t, config, tmpHome)
expConfStr := `{
"auths": {
"https://index.docker.io/v1/": {
"auth": "am9lam9lOmhlbGxv"
}
}
}`
if configStr != expConfStr {
t.Fatalf("Should have save in new form: \n%s\n not \n%s", configStr, expConfStr)
}
}
开发者ID:docker,项目名称:docker,代码行数:49,代码来源:config_test.go
注:本文中的github.com/docker/docker/pkg/homedir.Get函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论