From 756fcba6040cd3498176ce8c15c110e5c2e3dedd Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 11 May 2015 11:30:01 -0700 Subject: [PATCH] Update godeps with 0.1.2 --- Godeps/Godeps.json | 18 ++--- .../github.com/hashicorp/consul/api/lock.go | 9 ++- .../hashicorp/consul/api/lock_test.go | 67 +++++++++++++++++++ .../src/github.com/mitchellh/cli/ui.go | 48 ++++++++++--- .../github.com/mitchellh/cli/ui_colored.go | 4 ++ .../github.com/mitchellh/cli/ui_concurrent.go | 7 ++ .../src/github.com/mitchellh/cli/ui_mock.go | 4 ++ .../src/github.com/mitchellh/cli/ui_test.go | 27 ++++++++ .../github.com/samuel/go-zookeeper/.gitignore | 1 - .../samuel/go-zookeeper/.travis.yml | 21 ------ .../github.com/samuel/go-zookeeper/LICENSE | 25 ------- .../github.com/samuel/go-zookeeper/README.md | 11 --- .../samuel/go-zookeeper/examples/basic.go | 22 ------ .../samuel/go-zookeeper/tracer/main.go | 9 --- 14 files changed, 165 insertions(+), 108 deletions(-) delete mode 100644 Godeps/_workspace/src/github.com/samuel/go-zookeeper/.gitignore delete mode 100644 Godeps/_workspace/src/github.com/samuel/go-zookeeper/.travis.yml delete mode 100644 Godeps/_workspace/src/github.com/samuel/go-zookeeper/LICENSE delete mode 100644 Godeps/_workspace/src/github.com/samuel/go-zookeeper/README.md delete mode 100644 Godeps/_workspace/src/github.com/samuel/go-zookeeper/examples/basic.go delete mode 100644 Godeps/_workspace/src/github.com/samuel/go-zookeeper/tracer/main.go diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 98e772ba8..0ccb77b50 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -48,8 +48,8 @@ }, { "ImportPath": "github.com/hashicorp/consul/api", - "Comment": "v0.5.0-199-g205af6b", - "Rev": "205af6ba750b88863e6ee50c7c3d19edc180a6f6" + "Comment": "v0.5.0-253-g7062ecc", + "Rev": "7062ecc50fef9307e532c4a188da7ce1dd759dde" }, { "ImportPath": "github.com/hashicorp/errwrap", @@ -86,7 +86,7 @@ }, { "ImportPath": "github.com/mitchellh/cli", - "Rev": "afc399c273e70173826fb6f518a48edff23fe897" + "Rev": "6cc8bc522243675a2882b81662b0b0d2e04b99c9" }, { "ImportPath": "github.com/mitchellh/copystructure", @@ -109,6 +109,10 @@ "Comment": "v2.0.1-6-g44cb478", "Rev": "44cb4788b2ec3c3d158dd3d1b50aba7d66f4b59a" }, + { + "ImportPath": "github.com/samuel/go-zookeeper/zk", + "Rev": "d0e0d8e11f318e000a8cc434616d69e329edc374" + }, { "ImportPath": "github.com/vanackere/asn1-ber", "Rev": "295c7b21db5d9525ad959e3382610f3aff029663" @@ -123,19 +127,15 @@ }, { "ImportPath": "golang.org/x/crypto/ssh/terminal", - "Rev": "c84e1f8e3a7e322d497cd16c0e8a13c7e127baf3" + "Rev": "59435533c88bd0b1254c738244da1fe96b59d05d" }, { "ImportPath": "golang.org/x/net/context", - "Rev": "ff8eb9a34a5cbb9941ffc6f84a19a8014c2646ad" + "Rev": "a8c61998a557a37435f719980da368469c10bfed" }, { "ImportPath": "golang.org/x/oauth2", "Rev": "ec6d5d770f531108a6464462b2201b74fcd09314" - }, - { - "ImportPath": "github.com/samuel/go-zookeeper/zk", - "Rev": "d0e0d8e11f318e000a8cc434616d69e329edc374" } ] } diff --git a/Godeps/_workspace/src/github.com/hashicorp/consul/api/lock.go b/Godeps/_workspace/src/github.com/hashicorp/consul/api/lock.go index f6fdbbb16..4b694789c 100644 --- a/Godeps/_workspace/src/github.com/hashicorp/consul/api/lock.go +++ b/Godeps/_workspace/src/github.com/hashicorp/consul/api/lock.go @@ -165,14 +165,18 @@ WAIT: if pair != nil && pair.Flags != LockFlagValue { return nil, ErrLockConflict } + locked := false + if pair != nil && pair.Session == l.lockSession { + goto HELD + } if pair != nil && pair.Session != "" { qOpts.WaitIndex = meta.LastIndex goto WAIT } // Try to acquire the lock - lockEnt := l.lockEntry(l.lockSession) - locked, _, err := kv.Acquire(lockEnt, nil) + pair = l.lockEntry(l.lockSession) + locked, _, err = kv.Acquire(pair, nil) if err != nil { return nil, fmt.Errorf("failed to acquire lock: %v", err) } @@ -187,6 +191,7 @@ WAIT: } } +HELD: // Watch to ensure we maintain leadership leaderCh := make(chan struct{}) go l.monitorLock(l.lockSession, leaderCh) diff --git a/Godeps/_workspace/src/github.com/hashicorp/consul/api/lock_test.go b/Godeps/_workspace/src/github.com/hashicorp/consul/api/lock_test.go index 0350e8058..163372fe4 100644 --- a/Godeps/_workspace/src/github.com/hashicorp/consul/api/lock_test.go +++ b/Godeps/_workspace/src/github.com/hashicorp/consul/api/lock_test.go @@ -287,3 +287,70 @@ func TestLock_Conflict(t *testing.T) { t.Fatalf("err: %v", err) } } + +func TestLock_ReclaimLock(t *testing.T) { + c, s := makeClient(t) + defer s.Stop() + + session, _, err := c.Session().Create(&SessionEntry{}, nil) + if err != nil { + t.Fatalf("err: %v", err) + } + + lock, err := c.LockOpts(&LockOptions{Key: "test/lock", Session: session}) + if err != nil { + t.Fatalf("err: %v", err) + } + + // Should work + leaderCh, err := lock.Lock(nil) + if err != nil { + t.Fatalf("err: %v", err) + } + if leaderCh == nil { + t.Fatalf("not leader") + } + defer lock.Unlock() + + l2, err := c.LockOpts(&LockOptions{Key: "test/lock", Session: session}) + if err != nil { + t.Fatalf("err: %v", err) + } + + reclaimed := make(chan (<-chan struct{}), 1) + go func() { + l2Ch, err := l2.Lock(nil) + if err != nil { + t.Fatalf("not locked: %v", err) + } + reclaimed <- l2Ch + }() + + // Should reclaim the lock + var leader2Ch <-chan struct{} + + select { + case leader2Ch = <-reclaimed: + case <-time.After(time.Second): + t.Fatalf("should have locked") + } + + // unlock should work + err = l2.Unlock() + if err != nil { + t.Fatalf("err: %v", err) + } + + //Both locks should see the unlock + select { + case <-leader2Ch: + case <-time.After(time.Second): + t.Fatalf("should not be leader") + } + + select { + case <-leaderCh: + case <-time.After(time.Second): + t.Fatalf("should not be leader") + } +} diff --git a/Godeps/_workspace/src/github.com/mitchellh/cli/ui.go b/Godeps/_workspace/src/github.com/mitchellh/cli/ui.go index 56e468e6a..33c126387 100644 --- a/Godeps/_workspace/src/github.com/mitchellh/cli/ui.go +++ b/Godeps/_workspace/src/github.com/mitchellh/cli/ui.go @@ -8,6 +8,8 @@ import ( "os" "os/signal" "strings" + + "golang.org/x/crypto/ssh/terminal" ) // Ui is an interface for interacting with the terminal, or "interface" @@ -18,6 +20,10 @@ type Ui interface { // returned as the given string, or an error. Ask(string) (string, error) + // AskSecret asks the user for input using the given query, but does not echo + // the keystrokes to the terminal. + AskSecret(string) (string, error) + // Output is called for normal standard output. Output(string) @@ -45,6 +51,14 @@ type BasicUi struct { } func (u *BasicUi) Ask(query string) (string, error) { + return u.ask(query, false) +} + +func (u *BasicUi) AskSecret(query string) (string, error) { + return u.ask(query, true) +} + +func (u *BasicUi) ask(query string, secret bool) (string, error) { if _, err := fmt.Fprint(u.Writer, query+" "); err != nil { return "", err } @@ -59,8 +73,17 @@ func (u *BasicUi) Ask(query string) (string, error) { errCh := make(chan error, 1) lineCh := make(chan string, 1) go func() { - r := bufio.NewReader(u.Reader) - line, err := r.ReadString('\n') + var line string + var err error + stdin := int(os.Stdin.Fd()) + if secret && terminal.IsTerminal(stdin) { + var lineBytes []byte + lineBytes, err = terminal.ReadPassword(stdin) + line = string(lineBytes) + } else { + r := bufio.NewReader(u.Reader) + line, err = r.ReadString('\n') + } if err != nil { errCh <- err return @@ -108,12 +131,13 @@ func (u *BasicUi) Warn(message string) { // PrefixedUi is an implementation of Ui that prefixes messages. type PrefixedUi struct { - AskPrefix string - OutputPrefix string - InfoPrefix string - ErrorPrefix string - WarnPrefix string - Ui Ui + AskPrefix string + AskSecretPrefix string + OutputPrefix string + InfoPrefix string + ErrorPrefix string + WarnPrefix string + Ui Ui } func (u *PrefixedUi) Ask(query string) (string, error) { @@ -124,6 +148,14 @@ func (u *PrefixedUi) Ask(query string) (string, error) { return u.Ui.Ask(query) } +func (u *PrefixedUi) AskSecret(query string) (string, error) { + if query != "" { + query = fmt.Sprintf("%s%s", u.AskSecretPrefix, query) + } + + return u.Ui.AskSecret(query) +} + func (u *PrefixedUi) Error(message string) { if message != "" { message = fmt.Sprintf("%s%s", u.ErrorPrefix, message) diff --git a/Godeps/_workspace/src/github.com/mitchellh/cli/ui_colored.go b/Godeps/_workspace/src/github.com/mitchellh/cli/ui_colored.go index 3bc1beea8..e3d5131d1 100644 --- a/Godeps/_workspace/src/github.com/mitchellh/cli/ui_colored.go +++ b/Godeps/_workspace/src/github.com/mitchellh/cli/ui_colored.go @@ -35,6 +35,10 @@ func (u *ColoredUi) Ask(query string) (string, error) { return u.Ui.Ask(u.colorize(query, u.OutputColor)) } +func (u *ColoredUi) AskSecret(query string) (string, error) { + return u.Ui.AskSecret(u.colorize(query, u.OutputColor)) +} + func (u *ColoredUi) Output(message string) { u.Ui.Output(u.colorize(message, u.OutputColor)) } diff --git a/Godeps/_workspace/src/github.com/mitchellh/cli/ui_concurrent.go b/Godeps/_workspace/src/github.com/mitchellh/cli/ui_concurrent.go index 0da35919e..b4f4dbfaa 100644 --- a/Godeps/_workspace/src/github.com/mitchellh/cli/ui_concurrent.go +++ b/Godeps/_workspace/src/github.com/mitchellh/cli/ui_concurrent.go @@ -18,6 +18,13 @@ func (u *ConcurrentUi) Ask(query string) (string, error) { return u.Ui.Ask(query) } +func (u *ConcurrentUi) AskSecret(query string) (string, error) { + u.l.Lock() + defer u.l.Unlock() + + return u.Ui.AskSecret(query) +} + func (u *ConcurrentUi) Error(message string) { u.l.Lock() defer u.l.Unlock() diff --git a/Godeps/_workspace/src/github.com/mitchellh/cli/ui_mock.go b/Godeps/_workspace/src/github.com/mitchellh/cli/ui_mock.go index 7d48d4f4d..c46772855 100644 --- a/Godeps/_workspace/src/github.com/mitchellh/cli/ui_mock.go +++ b/Godeps/_workspace/src/github.com/mitchellh/cli/ui_mock.go @@ -29,6 +29,10 @@ func (u *MockUi) Ask(query string) (string, error) { return result, nil } +func (u *MockUi) AskSecret(query string) (string, error) { + return u.Ask(query) +} + func (u *MockUi) Error(message string) { u.once.Do(u.init) diff --git a/Godeps/_workspace/src/github.com/mitchellh/cli/ui_test.go b/Godeps/_workspace/src/github.com/mitchellh/cli/ui_test.go index ac15c4f0a..ac795ba84 100644 --- a/Godeps/_workspace/src/github.com/mitchellh/cli/ui_test.go +++ b/Godeps/_workspace/src/github.com/mitchellh/cli/ui_test.go @@ -37,6 +37,33 @@ func TestBasicUi_Ask(t *testing.T) { } } +func TestBasicUi_AskSecret(t *testing.T) { + in_r, in_w := io.Pipe() + defer in_r.Close() + defer in_w.Close() + + writer := new(bytes.Buffer) + ui := &BasicUi{ + Reader: in_r, + Writer: writer, + } + + go in_w.Write([]byte("foo bar\nbaz\n")) + + result, err := ui.AskSecret("Name?") + if err != nil { + t.Fatalf("err: %s", err) + } + + if writer.String() != "Name? " { + t.Fatalf("bad: %#v", writer.String()) + } + + if result != "foo bar" { + t.Fatalf("bad: %#v", result) + } +} + func TestBasicUi_Error(t *testing.T) { writer := new(bytes.Buffer) ui := &BasicUi{Writer: writer} diff --git a/Godeps/_workspace/src/github.com/samuel/go-zookeeper/.gitignore b/Godeps/_workspace/src/github.com/samuel/go-zookeeper/.gitignore deleted file mode 100644 index e43b0f988..000000000 --- a/Godeps/_workspace/src/github.com/samuel/go-zookeeper/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.DS_Store diff --git a/Godeps/_workspace/src/github.com/samuel/go-zookeeper/.travis.yml b/Godeps/_workspace/src/github.com/samuel/go-zookeeper/.travis.yml deleted file mode 100644 index f7247ca41..000000000 --- a/Godeps/_workspace/src/github.com/samuel/go-zookeeper/.travis.yml +++ /dev/null @@ -1,21 +0,0 @@ -language: go -go: - - 1.4 - -sudo: false - -branches: - only: - - master - -before_install: - - wget http://apache.claz.org/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz - - tar -zxvf zookeeper*tar.gz - -script: - - go build ./... - - go fmt ./... - - go get golang.org/x/tools/cmd/vet - - go vet ./... - - go test -i -race ./... - - go test -v -race ./... diff --git a/Godeps/_workspace/src/github.com/samuel/go-zookeeper/LICENSE b/Godeps/_workspace/src/github.com/samuel/go-zookeeper/LICENSE deleted file mode 100644 index bc00498c5..000000000 --- a/Godeps/_workspace/src/github.com/samuel/go-zookeeper/LICENSE +++ /dev/null @@ -1,25 +0,0 @@ -Copyright (c) 2013, Samuel Stauffer -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -* Neither the name of the author nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/Godeps/_workspace/src/github.com/samuel/go-zookeeper/README.md b/Godeps/_workspace/src/github.com/samuel/go-zookeeper/README.md deleted file mode 100644 index 15579014f..000000000 --- a/Godeps/_workspace/src/github.com/samuel/go-zookeeper/README.md +++ /dev/null @@ -1,11 +0,0 @@ -Native Go Zookeeper Client Library -=================================== - -[![Build Status](https://travis-ci.org/samuel/go-zookeeper.png)](https://travis-ci.org/samuel/go-zookeeper) - -Documentation: http://godoc.org/github.com/samuel/go-zookeeper/zk - -License -------- - -3-clause BSD. See LICENSE file. diff --git a/Godeps/_workspace/src/github.com/samuel/go-zookeeper/examples/basic.go b/Godeps/_workspace/src/github.com/samuel/go-zookeeper/examples/basic.go deleted file mode 100644 index 28dfa633f..000000000 --- a/Godeps/_workspace/src/github.com/samuel/go-zookeeper/examples/basic.go +++ /dev/null @@ -1,22 +0,0 @@ -package main - -import ( - "fmt" - "time" - - "github.com/samuel/go-zookeeper/zk" -) - -func main() { - c, _, err := zk.Connect([]string{"127.0.0.1"}, time.Second) //*10) - if err != nil { - panic(err) - } - children, stat, ch, err := c.ChildrenW("/") - if err != nil { - panic(err) - } - fmt.Printf("%+v %+v\n", children, stat) - e := <-ch - fmt.Printf("%+v\n", e) -} diff --git a/Godeps/_workspace/src/github.com/samuel/go-zookeeper/tracer/main.go b/Godeps/_workspace/src/github.com/samuel/go-zookeeper/tracer/main.go deleted file mode 100644 index 3255755e5..000000000 --- a/Godeps/_workspace/src/github.com/samuel/go-zookeeper/tracer/main.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -import ( - "github.com/samuel/go-zookeeper/zk" -) - -func main() { - zk.StartTracer("127.0.0.1:2182", "127.0.0.1:2181") -}