Skip to content

Commit aca417d

Browse files
authored
Merge pull request #131 from seveas/fuzzy-attrs
Show attributes a bit clearer in debug output
2 parents 000f91e + 198faf4 commit aca417d

6 files changed

Lines changed: 19 additions & 8 deletions

File tree

matcher.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,17 @@ type MatchAttribute struct {
1717

1818
func (m MatchAttribute) String() string {
1919
c1, c2 := '=', '='
20+
f := ""
2021
if m.FuzzyTyping {
21-
c1, c2 = '≈', '≈'
22+
f = " (≈)"
2223
}
2324
if m.Negate {
2425
c1 = '!'
2526
}
2627
if m.Regex {
2728
c2 = '~'
2829
}
29-
return fmt.Sprintf("%v %c%c %v", m.Name, c1, c2, m.Value)
30+
return fmt.Sprintf("%v %c%c %v%s", m.Name, c1, c2, m.Value, f)
3031
}
3132

3233
func (m MatchAttribute) Match(value interface{}) (matches bool) {

pager.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package herd
22

33
import (
4+
"context"
45
"fmt"
56
"io"
67
"os"
@@ -14,6 +15,7 @@ type pager struct {
1415
}
1516

1617
func (p *pager) start() error {
18+
ctx := context.Background()
1719
if p == nil || p.process != nil {
1820
return nil
1921
}
@@ -27,9 +29,9 @@ func (p *pager) start() error {
2729
if strings.HasSuffix(pager, "less") {
2830
args = append(args, "-R")
2931
}
30-
cmd = exec.Command(pager, args...)
32+
cmd = exec.CommandContext(ctx, pager, args...)
3133
} else {
32-
cmd = exec.Command("sh", "-c", pager)
34+
cmd = exec.CommandContext(ctx, "sh", "-c", pager)
3335
}
3436
cmd.Stdout = os.Stdout
3537
cmd.Stderr = os.Stderr

provider/consul/provider.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"sort"
99
"strings"
10+
"time"
1011

1112
"github.com/seveas/herd"
1213
"github.com/seveas/herd/provider/cache"
@@ -45,7 +46,9 @@ func newProvider(name string) herd.HostProvider {
4546
func magicProvider() herd.HostProvider {
4647
addr, _ := os.LookupEnv("CONSUL_HTTP_ADDR")
4748
if addr == "" {
48-
_, err := net.LookupHost("consul.service.consul")
49+
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
50+
defer cancel()
51+
_, err := net.DefaultResolver.LookupHost(ctx, "consul.service.consul")
4952
if err == nil {
5053
addr = "http://consul.service.consul:8500"
5154
}

provider/plugin/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func (p *pluginProvider) connect() error {
133133
Managed: true,
134134
HandshakeConfig: common.Handshake,
135135
Plugins: pluginMap,
136-
Cmd: exec.Command(p.config.Command), // #nosec G204 -- Cmd is user-supplied by design
136+
Cmd: exec.CommandContext(context.Background(), p.config.Command), // #nosec G204 -- Cmd is user-supplied by design
137137
Logger: common.NewLogrusLogger(logrus.StandardLogger(), fmt.Sprintf("plugin-%s", p.name)),
138138
SyncStdout: os.Stdout,
139139
SyncStderr: os.Stderr,

registry.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"sort"
1313
"strings"
1414
"syscall"
15+
"time"
1516

1617
"github.com/hashicorp/go-plugin"
1718
"github.com/seveas/scattergather"
@@ -280,7 +281,9 @@ func (r *Registry) Search(hostnameGlob string, attributes MatchAttributes, sampl
280281

281282
ret = ret.Search(hostnameGlob, attributes)
282283
if len(ret.hosts) == 0 && attributes != nil && len(attributes) == 0 {
283-
if _, err := net.LookupHost(hostnameGlob); err == nil {
284+
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
285+
defer cancel()
286+
if _, err := net.DefaultResolver.LookupHost(ctx, hostnameGlob); err == nil {
284287
ret = &HostSet{hosts: []*Host{NewHost(hostnameGlob, "", HostAttributes{})}}
285288
}
286289
}

ssh/agent_pool.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package ssh
22

33
import (
44
"bytes"
5+
"context"
56
"fmt"
67
"io"
78
"net"
@@ -161,7 +162,8 @@ func (ap *agentPool) SignersForPath(path string) []ssh.Signer {
161162

162163
func agentConnection() (io.ReadWriter, error) {
163164
if sockPath, ok := os.LookupEnv("SSH_AUTH_SOCK"); ok {
164-
return net.Dial("unix", sockPath)
165+
var d net.Dialer
166+
return d.DialContext(context.Background(), "unix", sockPath)
165167
} else if sock := findPageant(); sock != nil {
166168
return sock, nil
167169
}

0 commit comments

Comments
 (0)