Skip to content

Commit

Permalink
support etcd auth with env args (#2184)
Browse files Browse the repository at this point in the history
* support etcd auth with env args
set default registry address with env arg instead of 127.0.0.1

* fixing MICRO_REGISTRY_ADDRESS may empty issue
  • Loading branch information
xpunch authored Jun 23, 2021
1 parent 8dc9bf4 commit 212df8e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion plugins/registry/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/json"
"errors"
"net"
"os"
"path"
"sort"
"strings"
Expand All @@ -18,7 +19,7 @@ import (
"github.com/asim/go-micro/v3/registry"
hash "github.com/mitchellh/hashstructure"
"go.etcd.io/etcd/api/v3/v3rpc/rpctypes"
"go.etcd.io/etcd/client/v3"
clientv3 "go.etcd.io/etcd/client/v3"
"go.uber.org/zap"
)

Expand All @@ -45,6 +46,14 @@ func NewRegistry(opts ...registry.Option) registry.Registry {
register: make(map[string]uint64),
leases: make(map[string]clientv3.LeaseID),
}
username, password := os.Getenv("ETCD_USERNAME"), os.Getenv("ETCD_PASSWORD")
if len(username) > 0 && len(password) > 0 {
opts = append(opts, Auth(username, password))
}
address := os.Getenv("MICRO_REGISTRY_ADDRESS")
if len(address) > 0 {
opts = append(opts, registry.Addrs(address))
}
configure(e, opts...)
return e
}
Expand Down

0 comments on commit 212df8e

Please sign in to comment.